Adding NUnit test suite for Pipeline

git-svn-id: svn://anonsvn.mono-project.com/source/branches/abock/gstreamer-sharp@63337 e3ebcda4-bce8-0310-ba0a-eca2169e7518
This commit is contained in:
Khaled Mohammed 2006-08-04 04:08:13 +00:00
parent 0e15441c8c
commit 01cf9177ac
3 changed files with 177 additions and 1 deletions

View file

@ -6,6 +6,9 @@
DynamicSignal class. Got rid of DynamicSignalArgs and is using DynamicSignal class. Got rid of DynamicSignalArgs and is using
GLib.SignalArgs. GLib.SignalArgs.
* tests/PipelineTest.cs: NUnit Test Suite for Pipeline. Most of
the tests are duplicate of the c test suite.
2006-07-13 Aaron Bockover <aaron@abock.org> 2006-07-13 Aaron Bockover <aaron@abock.org>
* gstreamer-sharp/BindingHelper.cs: Static helper class to assist * gstreamer-sharp/BindingHelper.cs: Static helper class to assist

View file

@ -11,7 +11,7 @@ NUNIT_TESTER = $(NUNIT_TESTER_NAME).exe
NUNIT_TESTER_CSFILES = $(srcdir)/$(NUNIT_TESTER_NAME).cs NUNIT_TESTER_CSFILES = $(srcdir)/$(NUNIT_TESTER_NAME).cs
$(ASSEMBLY): $(ASSEMBLY_CSFILES) $(ASSEMBLY): $(ASSEMBLY_CSFILES)
$(CSC) $(MCS_FLAGS) $(NUNIT_FLAGS) -out:$@ -target:library -r:$(top_builddir)/gstreamer-sharp/gstreamer-sharp.dll $(ASSEMBLY_CSFILES) -r:glib-sharp-2.0 $(CSC) $(MCS_FLAGS) $(NUNIT_FLAGS) -out:$@ -target:library -r:$(top_builddir)/gstreamer-sharp/gstreamer-sharp.dll $(ASSEMBLY_CSFILES) -pkg:glib-sharp-2.0
$(NUNIT_TESTER): $(NUNIT_TESTER_CSFILES) $(NUNIT_TESTER): $(NUNIT_TESTER_CSFILES)
$(CSC) $(MCS_FLAGS) -out:$@ $(NUNIT_FLAGS) $(NUNIT_TESTER_CSFILES) $(CSC) $(MCS_FLAGS) -out:$@ $(NUNIT_FLAGS) $(NUNIT_TESTER_CSFILES)

173
tests/PipelineTest.cs Normal file
View file

@ -0,0 +1,173 @@
//
// PipelineTest.cs: NUnit Test Suite for gstreamer-sharp
//
// Authors
// Khaled Mohammed < khaled.mohammed@gmail.com >
//
// (C) 2006
//
using System;
using NUnit.Framework;
using Gst;
[TestFixture]
public class PipelineTest
{
[TestFixtureSetUp]
public void Init()
{
Application.Init();
}
[TestFixtureTearDown]
public void Deinit()
{
Application.Deinit();
}
[Test]
public void TestAsyncStateChangeEmpty()
{
Pipeline pipeline = new Pipeline(String.Empty);
Assert.IsNotNull(pipeline, "Could not create pipeline");
Assert.AreEqual(((Element)pipeline).SetState(State.Playing), StateChangeReturn.Success);
pipeline.Dispose();
}
[Test]
public void TestAsyncStateChangeFakeReady()
{
Pipeline pipeline = new Pipeline(String.Empty);
Element src = ElementFactory.Make("fakesrc", null);
Element sink = ElementFactory.Make("fakesink", null);
Bin bin = (Bin) pipeline;
bin.AddMany(src, sink);
src.Link(sink);
Assert.AreEqual(((Element)pipeline).SetState(State.Ready), StateChangeReturn.Success);
pipeline.Dispose();
}
/*
[Test]
public void TestAsyncStateChangeFake()
{
bool done = false;
Pipeline pipeline = new Pipeline(String.Empty);
Assert.IsNotNull(pipeline, "Could not create pipeline");
Element src = ElementFactory.Make("fakesrc", null);
Element sink = ElementFactory.Make("fakesink", null);
Bin bin = (Bin) pipeline;
bin.AddMany(src, sink);
src.Link(sink);
Bus bus = pipeline.Bus;
Assert.AreEqual(((Element) pipeline).SetState(State.Playing), StateChangeReturn.Async);
while(!done) {
State old, newState, pending;
Message message = bus.Poll(MessageType.StateChanged, -1);
if(message != null) {
message.ParseStateChanged(out old, out newState, out pending);
//Console.WriteLine("state change from {0} to {1}", old, newState);
if(message.Src == (Gst.Object) pipeline && newState == State.Playing)
done = true;
//message.Dispose();
}
}
Assert.AreEqual(((Element)pipeline).SetState(State.Null), StateChangeReturn.Success);
//bus.Dispose();
pipeline.Dispose();
}
*/
[Test]
public void TestGetBus()
{
Pipeline pipeline = new Pipeline(String.Empty);
Assert.IsNotNull(pipeline, "Could not create pipeline");
Assert.AreEqual(pipeline.Refcount, 1, "Refcount is not 1, it is " + pipeline.Refcount);
Bus bus = pipeline.Bus;
Assert.AreEqual(pipeline.Refcount, 1, "Refcount after .Bus");
Assert.AreEqual(bus.Refcount, 2, "bus.Refcount != 2, it is " + bus.Refcount);
pipeline.Dispose();
Assert.AreEqual(bus.Refcount, 1, "bus after unref pipeline");
bus.Dispose();
}
Element pipeline;
GLib.MainLoop loop;
bool MessageReceived(Bus bus, Message message) {
MessageType type = message.Type;
switch(type)
{
case MessageType.StateChanged:
{
State old, newState, pending;
message.ParseStateChanged(out old, out newState, out pending);
if(message.Src == (Gst.Object) pipeline && newState == State.Playing) {
loop.Quit();
}
break;
}
case MessageType.Error:
break;
default: break;
}
return true;
}
[Test]
public void TestBus()
{
pipeline = new Pipeline(String.Empty);
Assert.IsNotNull(pipeline, "Could not create pipeline");
Element src = ElementFactory.Make("fakesrc", null);
Assert.IsNotNull(src, "Could not create fakesrc");
Element sink = ElementFactory.Make("fakesink", null);
Assert.IsNotNull(sink, "Could not create fakesink");
Bin bin = (Bin) pipeline;
bin.AddMany(src, sink);
Assert.IsTrue(src.Link(sink), "Could not link between src and sink");
Bus bus = ((Pipeline)pipeline).Bus;
Assert.AreEqual(pipeline.Refcount, 1, "pipeline's refcount after .Bus");
Assert.AreEqual(bus.Refcount, 2, "bus");
uint id = bus.AddWatch(new BusFunc(MessageReceived));
Assert.AreEqual(pipeline.Refcount, 1, "pipeline after AddWatch");
Assert.AreEqual(bus.Refcount, 3, "bus after add_watch");
Assert.AreEqual(pipeline.SetState(State.Playing), StateChangeReturn.Async);
loop = new GLib.MainLoop();
loop.Run();
Assert.AreEqual(pipeline.SetState(State.Null), StateChangeReturn.Success);
State current, pending;
Assert.AreEqual(pipeline.GetState(out current, out pending, Clock.TimeNone), StateChangeReturn.Success);
Assert.AreEqual(current, State.Null, "state is not NULL but " + current);
Assert.AreEqual(pipeline.Refcount, 1, "pipeline at start of cleanup");
Assert.AreEqual(bus.Refcount, 3, "bus at start of cleanup");
pipeline.Dispose();
bus.Dispose();
}
}