gst-python: Add option to disable python plugin
[platform/upstream/gstreamer.git] / subprojects / gst-python / testsuite / test_gst.py
1 # -*- Mode: Python -*-
2 # vi:si:et:sw=4:sts=4:ts=4
3 #
4 # Copyright (C) 2009 Thomas Vander Stichele
5 #
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
10 #
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 # Lesser General Public License for more details.
15 #
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
19
20 import sys
21 import overrides_hack
22 overrides_hack
23 from common import TestCase, unittest
24
25 from gi.repository import Gst
26
27 class TimeArgsTest(TestCase):
28     def testNoneTime(self):
29         self.assertRaises(TypeError, Gst.TIME_ARGS, None)
30
31     def testStringTime(self):
32         self.assertRaises(TypeError, Gst.TIME_ARGS, "String")
33
34     def testClockTimeNone(self):
35         self.assertEquals(Gst.TIME_ARGS(Gst.CLOCK_TIME_NONE), 'CLOCK_TIME_NONE')
36
37     def testOneSecond(self):
38         self.assertEquals(Gst.TIME_ARGS(Gst.SECOND), '0:00:01.000000000')
39
40 class TestNotInitialized(TestCase):
41     def testNotInitialized(self):
42         if sys.version_info >= (3, 0):
43             assert_type = Gst.NotInitialized
44         else:
45             assert_type = TypeError
46
47         with self.assertRaises(assert_type):
48             Gst.Caps.from_string("audio/x-raw")
49
50         with self.assertRaises(assert_type):
51             Gst.Structure.from_string("audio/x-raw")
52
53         with self.assertRaises(assert_type):
54             Gst.ElementFactory.make("identity", None)
55
56     def testNotDeinitialized(self):
57         Gst.init(None)
58
59         assert(Gst.Caps.from_string("audio/x-raw"))
60         assert(Gst.Structure.from_string("audio/x-raw"))
61         assert(Gst.ElementFactory.make("identity", None))
62
63         Gst.deinit()
64         if sys.version_info >= (3, 0):
65             assert_type = Gst.NotInitialized
66         else:
67             assert_type = TypeError
68
69         with self.assertRaises(assert_type):
70             Gst.Caps.from_string("audio/x-raw")
71
72         with self.assertRaises(assert_type):
73             Gst.Structure.from_string("audio/x-raw")
74
75         with self.assertRaises(assert_type):
76             Gst.ElementFactory.make("identity", None)
77
78
79 class TestStructure(TestCase):
80
81     def test_new(self):
82         Gst.init(None)
83         test = Gst.Structure('test', test=1)
84         self.assertEqual(test['test'], 1)
85
86         test = Gst.Structure('test,test=1')
87         self.assertEqual(test['test'], 1)
88
89
90 class TestBin(TestCase):
91
92     def test_add_pad(self):
93         Gst.init(None)
94         self.assertEqual(Gst.ElementFactory.make("bin", None).sinkpads, [])
95
96 class TestBufferMap(TestCase):
97
98     def test_map_unmap_manual(self):
99         Gst.init(None)
100         buf = Gst.Buffer.new_wrapped([42])
101         info = buf.map(Gst.MapFlags.READ | Gst.MapFlags.WRITE)
102         self.assertEqual(info.data[0], 42)
103         buf.unmap(info)
104         with self.assertRaises(ValueError):
105             info.data[0]
106
107     def test_map_unmap_context(self):
108         Gst.init(None)
109         buf = Gst.Buffer.new_wrapped([42])
110         with buf.map(Gst.MapFlags.READ | Gst.MapFlags.WRITE) as info:
111             self.assertEqual(info.data[0], 42)
112         with self.assertRaises(ValueError):
113             info.data[0]
114
115 if __name__ == "__main__":
116     unittest.main()