summaryrefslogtreecommitdiff
path: root/tests/ElementTest.cs
blob: 0451827ca1b5f12d85f2b3087ad2389ace166c5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//
// ElementTest.cs: NUnit Test Suite for gstreamer-sharp
//
// Authors:
//   Khaled Mohammed (khaled.mohammed@gmail.com)
//
// (C) 2006 Novell, Inc.
//

using System;
using NUnit.Framework;

using Gst;

[TestFixture]
public class ElementTest 
{
	[TestFixtureSetUp]
	public void Init() 
	{
		Application.Init();
	}

	[TestFixtureTearDown]
	public void Deinit() 
	{
		Application.Deinit();
	}

	[Test]
	public void TestBinAdd() 
	{
		Element src = ElementFactory.Make("fakesrc", null);
		Element sink = ElementFactory.Make("fakesink", null);

		Assert.AreEqual(src.Refcount, 1, "fakesrc");
		Assert.AreEqual(sink.Refcount, 1, "fakesink");

		Element pipeline = new Pipeline(String.Empty);
	
		Assert.AreEqual(pipeline.Refcount, 1, "pipeline");

		Bin bin = (Bin) pipeline;
		Assert.AreEqual(bin.Refcount, 1, "bin");
		Assert.AreEqual(pipeline.Refcount, 1, "pipeline");

		bin.AddMany(src, sink);
		Assert.AreEqual(src.Refcount, 2, "src");
		Assert.AreEqual(sink.Refcount, 2, "sink");
		Assert.AreEqual(bin.Refcount, 1, "bin");
		Assert.AreEqual(pipeline.Refcount, 1, "pipeline");

		src.Link(sink);
		
		src.Dispose();
		sink.Dispose();
		pipeline.Dispose();
	}

	[Test]
	public void TestAddRemovePad() 
	{
		Element e = ElementFactory.Make("fakesrc", "source");
		Pad p = new Pad("source", PadDirection.Src);
		Assert.AreEqual(p.Refcount, 1, "pad");
		
		e.AddPad(p);
		Assert.AreEqual(p.Refcount, 2, "pad");

		e.RemovePad(p);

		p.Dispose();
		e.Dispose();
	}

	[Test]
	public void TestAddPadUnrefElement ()
	{
		Element e = ElementFactory.Make("fakesrc", "source");
		Assert.IsNotNull(e, "Could not create fakesrc");
		Assert.IsTrue(e.GetType() == typeof(Gst.Element));		
		Assert.AreEqual(e.Refcount, 1);

		Pad p = new Pad("source", PadDirection.Src);
		Assert.AreEqual(p.Refcount, 1, "pad");

		Gst.Object.Ref(p.Handle);
		Assert.AreEqual(p.Refcount, 2, "pad");

		e.AddPad(p);
		Assert.AreEqual(p.Refcount, 3, "pad");

		Gst.Object.Unref(p.Handle);
		Assert.AreEqual(p.Refcount, 2, "pad");		

		Assert.AreEqual(e.Refcount, 1);

		e.Dispose();
		Assert.AreEqual(p.Refcount, 1, "pad");

		p.Dispose();
	}

	[Test]
	public void TestErrorNoBus() 
	{
		Element e = ElementFactory.Make("fakesrc", "source");
		e.Dispose();
	}

/*
	[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.AreEqual(source.Refcount, 1, source.Name);
		Assert.AreEqual(sink.Refcount, 1, "sink");	
		Assert.IsTrue(source.LinkPads("src", sink, "sink"));
	
		sink.SetState(State.Paused);
		source.SetState(State.Paused);

		Assert.AreEqual(source.Refcount, 1, "src");
		Assert.AreEqual(sink.Refcount, 1, "sink");

		sink.GetState(out state, out pending, Clock.TimeNone);

		sink.SetState(State.Playing);
		source.SetState(State.Playing);

		// Sleep
		System.Threading.Thread.Sleep(500);

		sink.SetState(State.Paused);
		source.SetState(State.Paused);

		sink.GetState(out state, out pending, Clock.TimeNone);

		Assert.AreEqual(sink.Refcount, 1, "sink");
		Assert.AreEqual(source.Refcount, 1, "src");

		source.UnlinkPads("src", sink, "sink");

		Assert.AreEqual(sink.Refcount, 1, "sink");
		Assert.AreEqual(source.Refcount, 1, "src");

		source.Dispose();
		sink.Dispose();
	}
*/

	[Test]
	public void TestLinkNoPads() 
	{
		Element src = new Bin("src");
		Element sink = new Bin("sink");

		Assert.IsFalse(src.Link(sink));

		src.Dispose();
		sink.Dispose();
	}

}