summaryrefslogtreecommitdiff
path: root/tests/PipelineTest.cs
blob: 40ebabf0ff82ac897b5951a1b5e09f37445410dd (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
//
// PipelineTest.cs: NUnit Test Suite for gstreamer-sharp
//
// Authors
//   Khaled Mohammed < khaled.mohammed@gmail.com >
// 
// (C) 2006
//

using System;
using NUnit.Framework;
using Gst;
using Gst.CorePlugins;

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

  [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);
  }

  [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.Add(src, sink);
    src.Link(sink);

    Assert.AreEqual(((Element)pipeline).SetState(State.Ready), StateChangeReturn.Success);
  }

  [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.Add(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;
      }
    }

    Assert.AreEqual(((Element)pipeline).SetState(State.Null), StateChangeReturn.Success);
  }

  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]
  [Ignore("This test does not terminate")]
  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.Add(src, sink);
    Assert.IsTrue(src.Link(sink), "Could not link between src and sink");

    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);
  }

  [Test]
  public void TestBaseTime() {
    Element pipeline = ElementFactory.Make("pipeline", "pipeline");
    FakeSrc fakesrc = FakeSrc.Make("fakesrc");
    FakeSink fakesink = FakeSink.Make("fakesink");

    Assert.IsNotNull(pipeline, "Could not create pipeline");
    Assert.IsNotNull(fakesrc, "Could not create fakesrc");
    Assert.IsNotNull(fakesink, "Could not create fakesink");

    fakesrc.IsLive = true;

    Bin bin = (Bin) pipeline;
    bin.Add(fakesrc, fakesink);
    Assert.IsTrue(fakesrc.Link(fakesink));

    Pad sink = fakesink.GetStaticPad("sink");
  }
}