mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-26 03:31:05 +00:00
tests: Test SDPMessage creation
https://bugzilla.gnome.org/show_bug.cgi?id=794349
This commit is contained in:
parent
11215be945
commit
5f63dac35e
5 changed files with 231 additions and 25 deletions
44
Tests/SdpTests.cs
Normal file
44
Tests/SdpTests.cs
Normal file
|
@ -0,0 +1,44 @@
|
|||
// Copyright (C) 2018 Thibault Saunier <tsaunier@igalia.com>
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
// 02110-1301 USA
|
||||
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using Gst;
|
||||
using Gst.Sdp;
|
||||
|
||||
namespace GstSharp.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public class SdpTests : TestBase
|
||||
{
|
||||
[Test]
|
||||
public void TesSdpMessage()
|
||||
{
|
||||
Gst.Application.Init();
|
||||
Gst.Sdp.SDPMessage msg;
|
||||
var res = Gst.Sdp.SDPMessage.New(out msg);
|
||||
|
||||
Assert.AreEqual(res, Gst.Sdp.SDPResult.Ok);
|
||||
|
||||
var uri = "udp://nothing.com";
|
||||
msg.SetUri(uri);
|
||||
Assert.AreEqual(msg.Uri, uri);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
53
Tests/TestBase.cs
Normal file
53
Tests/TestBase.cs
Normal file
|
@ -0,0 +1,53 @@
|
|||
// Copyright (C) 2018 Collabora Ltd.
|
||||
// Author: Justin Kim <justin.kim@collabora.com>
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
// 02110-1301 USA
|
||||
|
||||
using Gst;
|
||||
using System.Threading;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace GstSharp.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public abstract class TestBase
|
||||
{
|
||||
GLib.MainLoop mainLoop;
|
||||
Thread thread;
|
||||
|
||||
void Run(object o)
|
||||
{
|
||||
GLib.MainContext context = new GLib.MainContext();
|
||||
mainLoop = new GLib.MainLoop(context);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void BaseSetUp()
|
||||
{
|
||||
Assert.IsTrue(Application.InitCheck());
|
||||
|
||||
thread = new Thread(Run);
|
||||
thread.Start();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void BaseTearDown()
|
||||
{
|
||||
mainLoop.Quit();
|
||||
thread.Join();
|
||||
}
|
||||
}
|
||||
}
|
37
Tests/meson.build
Normal file
37
Tests/meson.build
Normal file
|
@ -0,0 +1,37 @@
|
|||
nunit_console = find_program('nunit-console', required: false)
|
||||
|
||||
if nunit_console.found()
|
||||
nunit_version = '3.10.1'
|
||||
get_nunit_res = run_command(nuget, 'get',
|
||||
'--builddir=NUnit',
|
||||
'--nuget-name=NUnit',
|
||||
'--nuget-version', nunit_version,
|
||||
'--csharp-version=net45',
|
||||
'--current-builddir', meson.current_build_dir(),
|
||||
'--builddir', meson.build_root(),
|
||||
)
|
||||
|
||||
if get_nunit_res.returncode() != 0
|
||||
message('Failed to get NUnit: ' + get_nunit_res.stderr())
|
||||
else
|
||||
foreach path: get_nunit_res.stdout().split()
|
||||
testsenv.prepend('MONO_PATH',
|
||||
join_paths(meson.build_root(), path.strip('-r:'), '..'))
|
||||
endforeach
|
||||
|
||||
nunit_dep = declare_dependency(link_args: get_nunit_res.stdout().split(),
|
||||
version: nunit_version)
|
||||
|
||||
foreach test: [
|
||||
# 'PipelineTests',
|
||||
'SdpTests'
|
||||
]
|
||||
lib = library(test, test + '.cs', 'TestBase.cs',
|
||||
cs_args: ['-nowarn:169', '-nowarn:108', '-nowarn:114'],
|
||||
dependencies: [gst_sharp_dep, nunit_dep])
|
||||
test(test, nunit_console, args: [lib.full_path()], env: testsenv)
|
||||
endforeach
|
||||
endif
|
||||
else
|
||||
message('Could not find nunit-console, can\'t run unitests')
|
||||
endif
|
|
@ -177,3 +177,4 @@ if bindinate.found()
|
|||
run_target('update-all', command: [find_program('update_sources.py'), 'bindinate'])
|
||||
endif
|
||||
|
||||
subdir('Tests')
|
121
nuget.py
121
nuget.py
|
@ -2,11 +2,14 @@
|
|||
import argparse
|
||||
import getpass
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
import subprocess
|
||||
from datetime import datetime
|
||||
from urllib.request import urlretrieve
|
||||
from zipfile import ZipFile
|
||||
|
||||
NUSPEC_TEMPLATE ="""<?xml version="1.0" encoding="utf-8"?>
|
||||
NUSPEC_TEMPLATE = """<?xml version="1.0" encoding="utf-8"?>
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>{package_name}</id>
|
||||
|
@ -45,10 +48,14 @@ class Nugetifier:
|
|||
self.nugetdir = os.path.join(self.builddir,
|
||||
self.package_name + 'nupkg')
|
||||
self.frameworkdir = 'net45'
|
||||
self.nuget_build_dir = os.path.join(self.nugetdir, 'build', self.frameworkdir)
|
||||
self.nuget_lib_dir = os.path.join(self.nugetdir, 'lib', self.frameworkdir)
|
||||
self.nuspecfile = os.path.join(self.nugetdir, '%s.nuspec' % self.package_name)
|
||||
self.nugettargets = os.path.join(self.nuget_build_dir, "%s.targets" % self.package_name)
|
||||
self.nuget_build_dir = os.path.join(
|
||||
self.nugetdir, 'build', self.frameworkdir)
|
||||
self.nuget_lib_dir = os.path.join(
|
||||
self.nugetdir, 'lib', self.frameworkdir)
|
||||
self.nuspecfile = os.path.join(
|
||||
self.nugetdir, '%s.nuspec' % self.package_name)
|
||||
self.nugettargets = os.path.join(
|
||||
self.nuget_build_dir, "%s.targets" % self.package_name)
|
||||
self.nuget = shutil.which('nuget')
|
||||
if not self.nuget:
|
||||
print("Could not find the `nuget` tool, install it and retry!")
|
||||
|
@ -71,8 +78,9 @@ class Nugetifier:
|
|||
return res
|
||||
|
||||
self.files = ''
|
||||
|
||||
def add_file(path, target="lib"):
|
||||
f = ' <file src="%s" target="%s"/>\n' % (
|
||||
f = ' <file src="%s" target="%s"/>\n' % (
|
||||
path, os.path.join(target, os.path.basename(path)))
|
||||
self.files += f
|
||||
|
||||
|
@ -100,25 +108,88 @@ class Nugetifier:
|
|||
cwd=self.builddir)
|
||||
|
||||
|
||||
class NugetDownloader:
|
||||
def reporthook(self, blocknum, blocksize, totalsize):
|
||||
readsofar = blocknum * blocksize
|
||||
if totalsize > 0:
|
||||
percent = readsofar * 1e2 / totalsize
|
||||
s = "\r%5.1f%% %*d / %d" % (
|
||||
percent, len(str(totalsize)), readsofar, totalsize)
|
||||
sys.stderr.write(s)
|
||||
if readsofar >= totalsize: # near the end
|
||||
sys.stderr.write("\n")
|
||||
else: # total size is unknown
|
||||
sys.stderr.write("read %d\n" % (readsofar,))
|
||||
|
||||
def run(self):
|
||||
url = "https://www.nuget.org/api/v2/package/{nuget_name}/{nuget_version}".format(
|
||||
**self.__dict__)
|
||||
workdir = os.path.join(self.current_builddir,
|
||||
self.nuget_name, self.nuget_version)
|
||||
os.makedirs(workdir, exist_ok=True)
|
||||
|
||||
try:
|
||||
with open(os.path.join(workdir, 'linkline'), 'r') as f:
|
||||
print(f.read())
|
||||
return
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
nugetpath = os.path.join(workdir, self.nuget_name) + '.zip'
|
||||
print("Downloading %s into %s" % (url, nugetpath), file=sys.stderr)
|
||||
urlretrieve(url, nugetpath, self.reporthook)
|
||||
|
||||
lib_path = os.path.join('lib', self.csharp_version)
|
||||
dll_path = os.path.join(self.nuget_name, self.nuget_version)
|
||||
extract_dir = os.path.join(self.current_builddir, dll_path)
|
||||
os.makedirs(extract_dir, exist_ok=True)
|
||||
linkline = ''
|
||||
|
||||
print("%s - %s" % (self.builddir, extract_dir), file=sys.stderr)
|
||||
with ZipFile(nugetpath) as zip:
|
||||
for f in zip.infolist():
|
||||
if f.filename.startswith(lib_path):
|
||||
zip.extract(f, path=extract_dir)
|
||||
if f.filename.endswith('.dll'):
|
||||
linkline += ' -r:' + \
|
||||
os.path.relpath(os.path.join(
|
||||
extract_dir, f.filename), self.builddir)
|
||||
|
||||
with open(os.path.join(workdir, 'linkline'), 'w') as f:
|
||||
print(linkline.strip(), file=f)
|
||||
|
||||
print(linkline.strip())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--builddir')
|
||||
parser.add_argument('--package-name')
|
||||
parser.add_argument('--author', default=getpass.getuser())
|
||||
parser.add_argument('--owner', default=getpass.getuser())
|
||||
parser.add_argument('--native', action='append', default=[])
|
||||
parser.add_argument('--assembly', action='append', default=[])
|
||||
parser.add_argument('--out')
|
||||
parser.add_argument('--description')
|
||||
parser.add_argument('--copyright')
|
||||
parser.add_argument('--version')
|
||||
parser.add_argument('--icon-url', default='')
|
||||
parser.add_argument('--project-url', default='')
|
||||
parser.add_argument('--license-url', default='')
|
||||
parser.add_argument('--tags', default='')
|
||||
parser.add_argument('--dependency', default=[], action='append')
|
||||
if "get" not in sys.argv:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--builddir')
|
||||
parser.add_argument('--package-name')
|
||||
parser.add_argument('--author', default=getpass.getuser())
|
||||
parser.add_argument('--owner', default=getpass.getuser())
|
||||
parser.add_argument('--native', action='append', default=[])
|
||||
parser.add_argument('--assembly', action='append', default=[])
|
||||
parser.add_argument('--out')
|
||||
parser.add_argument('--description')
|
||||
parser.add_argument('--copyright')
|
||||
parser.add_argument('--version')
|
||||
parser.add_argument('--icon-url', default='')
|
||||
parser.add_argument('--project-url', default='')
|
||||
parser.add_argument('--license-url', default='')
|
||||
parser.add_argument('--tags', default='')
|
||||
parser.add_argument('--dependency', default=[], action='append')
|
||||
|
||||
nugetifier = Nugetifier()
|
||||
options = parser.parse_args(namespace=nugetifier)
|
||||
runner = Nugetifier()
|
||||
else:
|
||||
sys.argv.remove('get')
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--builddir')
|
||||
parser.add_argument('--current-builddir')
|
||||
parser.add_argument('--nuget-name')
|
||||
parser.add_argument('--nuget-version')
|
||||
parser.add_argument('--csharp-version')
|
||||
|
||||
exit(nugetifier.run())
|
||||
runner = NugetDownloader()
|
||||
|
||||
options = parser.parse_args(namespace=runner)
|
||||
exit(runner.run())
|
||||
|
|
Loading…
Reference in a new issue