summaryrefslogtreecommitdiff
path: root/tests/PadTest.cs
blob: d86d8432bacfa8df9f1a17c3c9d5fa62713a1baf (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
173
174
175
176
177
178
//
// PadTest.cs: NUnit Test Suite for gstreamer-sharp
//
// Authors:
//   Michael Dominic K. (michaldominik@gmail.com)
//   Khaled Mohammed (khaled.mohammed@gmail.com)
//   
// (C) 2006 Novell, Inc.
//

using System;
using NUnit.Framework;
using Gst;

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

	[Test]
	public void TestPlainCreation()
	{
		Pad src = new Pad("src", PadDirection.Src);
		Pad sink = new Pad("sink", PadDirection.Sink);

		Assert.IsNotNull(src);
		Assert.IsNotNull(sink);

		Assert.IsFalse(src.Handle == IntPtr.Zero, "Ooops, src pad has null handle");
		Assert.IsFalse(sink.Handle == IntPtr.Zero, "Ooops, sink pad has null handle");

		Assert.AreEqual(PadDirection.Src, src.Direction);
		Assert.AreEqual(PadDirection.Sink, sink.Direction);
	}

	public static Caps PadGetCapsStub(Pad pad)
	{
		return Caps.FromString("video/x-raw-yuv");
	}

	[Test]
	[Ignore("This test causes a crash")]
	public void TestFuncAssigning()
	{
		Pad src = new Pad("src", PadDirection.Src);
		src.GetCapsFunction = new PadGetCapsFunction(PadGetCapsStub);

		Caps caps = src.Caps;

		Assert.IsNotNull(caps, "Ooops, returned caps is null");
		Assert.IsFalse(caps.IsEmpty == true, "Ooops, returned caps are empty");
		Assert.AreEqual("video/x-raw-yuv", caps.ToString ());
	}

	[Test]
	public void TestElementPadAccessByName()
	{
		Element element = ElementFactory.Make("identity", null);
		Assert.IsNotNull(element);
		Assert.IsFalse(element.Handle == IntPtr.Zero, "Ooops, identity element has null handle");

		Pad src = element.GetStaticPad("src");
		Pad sink = element.GetStaticPad("sink");

		Assert.IsNotNull(src, "Ooops, src pad is null");
		Assert.IsNotNull(sink, "Ooops, sink pad is null");

		Assert.IsFalse(src.Handle == IntPtr.Zero, "Ooops, src pad has null handle");
		Assert.IsFalse(sink.Handle == IntPtr.Zero, "Ooops, sink pad has null handle");

		Caps srccaps = src.Caps;
		Assert.IsTrue(srccaps.IsAny, "How come src pad caps is not ANY?");

		Caps sinkcaps = sink.Caps;
		Assert.IsTrue(sinkcaps.IsAny, "How come sink pad caps is not ANY?");
	}

	[Test]
	public void TestElementPadAccessByList()
	{
		Element element = ElementFactory.Make("identity", null);
		Assert.IsNotNull(element);
		Assert.IsFalse(element.Handle == IntPtr.Zero, "Ooops, identity element has null handle");

		bool hassink = false;
		bool hassrc = false;

		foreach(Pad pad in element.Pads) {
			if (pad.Name == "src") 
				hassrc = true;
			else if (pad.Name == "sink")
				hassink = true;
		}

		Assert.IsTrue(hassink, "Sink pad not found in the list");
		Assert.IsTrue(hassrc, "Src pad not found in the list");
	}

	[Test]
	public void TestLink()
	{
		Pad src = new Pad("source", PadDirection.Src);
		Assert.IsNotNull(src, "Pad could not be created");

		string name = src.Name;
		Assert.AreEqual(name, "source");

		Pad sink = new Pad("sink", PadDirection.Sink);
		Assert.IsNotNull(sink, "Pad could not be created");

		Assert.AreEqual(src.Link(sink), PadLinkReturn.Noformat);
	}

	[Test]
	public void TestGetAllowedCaps()
	{
		/*
			 Gst.Buffer buffer = new Gst.Buffer();

			 try {
			 Pad pbuffer = (Pad) buffer;
			 Caps pcaps = pbuffer.AllowedCaps;
			 }
			 catch (Exception ex) {
			 Assert.Fail("buffer.AllowedCaps failed");
			 }
			 */
		Pad sink = new Pad("sink", PadDirection.Sink);
		//		try { Caps tcaps = sink.AllowedCaps; }
		//		catch (Exception) { Assert.Fail("sink.AllowedCaps failed"); }

		Pad src = new Pad("src", PadDirection.Src);
		Assert.IsNotNull(src);
		Caps caps = src.AllowedCaps;
		Assert.IsNull(caps);

		caps = Caps.FromString("foo/bar");

		src.SetCaps(caps);
		sink.SetCaps(caps);

		PadLinkReturn plr = src.Link(sink);
		Assert.AreEqual(plr, PadLinkReturn.Ok);

		Caps gotcaps = src.AllowedCaps;
		Assert.IsNotNull(gotcaps);
		Assert.IsTrue(gotcaps.IsEqual(caps));
	}

	bool ProbeHandler(Pad pad, Gst.Buffer buffer)
	{
		//Assert.Fail("event worked");
		return false;
	}

	[Test]
	public void TestPushUnlinked()
	{
		Pad src = new Pad("src", PadDirection.Src);
		Assert.IsNotNull(src, "Could not create src");
		Caps caps = src.AllowedCaps;
		Assert.IsNull(caps);

		caps = Caps.FromString("foo/bar");
		src.SetCaps(caps);

		Gst.Buffer buffer = new Gst.Buffer();
		Assert.AreEqual(src.Push(buffer), FlowReturn.NotLinked);

		ulong handler_id = src.AddBufferProbe(new PadBufferProbeCallback(ProbeHandler));
		buffer = new Gst.Buffer();
		Assert.AreEqual(src.Push(buffer), FlowReturn.Ok);
	}
}