From 1bf720556359089a86509ed8a292a7a3786b51cc Mon Sep 17 00:00:00 2001 From: Maarten Bosmans Date: Thu, 18 Jun 2009 18:07:53 +0200 Subject: [PATCH] Add some tests that where lost in Refcount cleanup --- tests/BinTest.cs | 46 ++++++++++++++++++++++++++++--------------- tests/BufferTest.cs | 19 ++++++++++++++++++ tests/ElementTest.cs | 46 +++++++++++++++++++++++++++++++++++++++++++ tests/PipelineTest.cs | 9 +++++++++ 4 files changed, 104 insertions(+), 16 deletions(-) diff --git a/tests/BinTest.cs b/tests/BinTest.cs index 2f5f95b2d9..de40698699 100644 --- a/tests/BinTest.cs +++ b/tests/BinTest.cs @@ -38,6 +38,32 @@ public class BinTest Assert.AreEqual(bin.ChildrenCount, 2); } + [Test] + public void TestAddRemove() + { + Bin bin = ElementFactory.Make("bin") as Bin; + Assert.IsNotNull(bin, "Could not create bin"); + + Element e1 = new FakeSrc("fakesrc"); + Element e2 = new Identity("identity"); + Element e3 = new FakeSink("fakesink"); + + Assert.IsNotNull(e1, "Could not create fakesrc"); + Assert.IsNotNull(e2, "Could not create identity"); + Assert.IsNotNull(e3, "Could not create fakesink"); + + bin.Add(e1, e2, e3); + Element.Link(e1, e2, e3); + + Assert.AreEqual(bin.ChildrenCount, 3); + bin.Remove(e2, e3); + Assert.AreEqual(bin.ChildrenCount, 1); + bin.Add(e2); + Assert.AreEqual(bin.ChildrenCount, 2); + bin.Remove(e1, e2); + Assert.AreEqual(bin.ChildrenCount, 0); + } + [Test] public void TestGetByName() { @@ -52,15 +78,15 @@ public class BinTest } [Test] - public void TestChildren() + public void TestGetChildByIndex() { Bin bin = new Bin("test-bin"); Element [] elements = new Element [] { ElementFactory.Make("fakesrc", "fakesrc"), - ElementFactory.Make("audioconvert", "audioconvert"), - ElementFactory.Make("wavenc", "wavenc"), - ElementFactory.Make("fakesink", "fakesink") + ElementFactory.Make("audioconvert", "audioconvert"), + ElementFactory.Make("wavenc", "wavenc"), + ElementFactory.Make("fakesink", "fakesink") }; foreach(Element element in elements) { @@ -73,16 +99,4 @@ public class BinTest Assert.AreEqual(elements[elements.Length - i - 1], bin.GetChildByIndex(i)); } } - - [Test] - public void TestInterface() - { - Bin bin = new Bin(String.Empty); - Assert.IsNotNull(bin, "Could not create bin"); - - Element filesrc = ElementFactory.Make("filesrc"); - Assert.IsNotNull(filesrc, "Could not create filesrc"); - - bin.Add(filesrc); - } } diff --git a/tests/BufferTest.cs b/tests/BufferTest.cs index fc4410bd8d..f5624aacf2 100644 --- a/tests/BufferTest.cs +++ b/tests/BufferTest.cs @@ -18,6 +18,25 @@ public class BufferTest Application.Init(); } + [Test] + public void TestCaps() + { + Gst.Buffer buffer = new Gst.Buffer(4); + Caps caps = Caps.FromString("audio/x-raw-int"); + + Assert.IsNull(buffer.Caps, "buffer.Caps should be null"); + buffer.Caps = caps; + Assert.IsNotNull(buffer.Caps, "buffer.Caps is null"); + + Caps caps2 = Caps.FromString("audio/x-raw-float"); + buffer.Caps = caps2; + Assert.AreNotEqual(buffer.Caps, caps); + Assert.AreEqual(buffer.Caps, caps2); + + buffer.Caps = null; + Assert.IsNull(buffer.Caps, "buffer.Caps should be null"); + } + [Test] public void TestSubbuffer() { diff --git a/tests/ElementTest.cs b/tests/ElementTest.cs index e190c5635a..c4a2350bf0 100644 --- a/tests/ElementTest.cs +++ b/tests/ElementTest.cs @@ -27,5 +27,51 @@ public class ElementTest Element sink = new Bin("sink"); Assert.IsFalse(src.Link(sink)); + Assert.IsFalse(Element.Link(src, sink)); + } + + [Test] + public void TestAddRemovePad() + { + Element e = ElementFactory.Make("fakesrc", "source"); + Pad pad = new Pad("source", PadDirection.Src); + + e.AddPad(pad); + Assert.AreEqual(pad, e.GetStaticPad("source")); + + e.RemovePad(pad); + Assert.IsNull(e.GetStaticPad("source")); + } + + [Test] + public void TestLink() + { + State state, pending; + + Element source = ElementFactory.Make("fakesrc", "source"); + Assert.IsNotNull(source); + Element sink = ElementFactory.Make("fakesink", "sink"); + Assert.IsNotNull(sink); + + Assert.IsTrue(source.LinkPads("src", sink, "sink")); + + sink.SetState(State.Paused); + source.SetState(State.Paused); + sink.GetState(out state, out pending, Clock.TimeNone); + Assert.AreEqual(state, State.Paused); + + sink.SetState(State.Playing); + source.SetState(State.Playing); + source.GetState(out state, out pending, Clock.TimeNone); + Assert.AreEqual(state, State.Playing); + + sink.SetState(State.Null); + source.SetState(State.Null); + sink.GetState(out state, out pending, Clock.TimeNone); + Assert.AreEqual(state, State.Null); + + Assert.AreEqual(source.GetStaticPad("src").Peer, sink.GetStaticPad("sink")); + source.Unlink(sink); + Assert.IsFalse(source.GetStaticPad("src").IsLinked); } } diff --git a/tests/PipelineTest.cs b/tests/PipelineTest.cs index e6ce228174..d837fbbd81 100644 --- a/tests/PipelineTest.cs +++ b/tests/PipelineTest.cs @@ -21,6 +21,15 @@ public class PipelineTest Application.Init(); } + [Test] + public void TestPipeline() + { + Pipeline pipeline = new Pipeline(String.Empty); + Assert.IsNotNull(pipeline, "Could not create pipeline"); + Assert.IsNotNull(pipeline.Bus, "Bus on pipeline is null"); + Assert.IsNotNull(pipeline.Clock, "Clock on pipeline is null"); + } + [Test] public void TestAsyncStateChangeEmpty() {