2 # vi:si:et:sw=4:sts=4:ts=4
4 # Copyright (C) 2009 Thomas Vander Stichele
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.
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.
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
23 from common import TestCase, unittest
25 from gi.repository import Gst
27 class TimeArgsTest(TestCase):
28 def testNoneTime(self):
29 self.assertRaises(TypeError, Gst.TIME_ARGS, None)
31 def testStringTime(self):
32 self.assertRaises(TypeError, Gst.TIME_ARGS, "String")
34 def testClockTimeNone(self):
35 self.assertEquals(Gst.TIME_ARGS(Gst.CLOCK_TIME_NONE), 'CLOCK_TIME_NONE')
37 def testOneSecond(self):
38 self.assertEquals(Gst.TIME_ARGS(Gst.SECOND), '0:00:01.000000000')
40 class TestNotInitialized(TestCase):
41 def testNotInitialized(self):
42 if sys.version_info >= (3, 0):
43 assert_type = Gst.NotInitialized
45 assert_type = TypeError
47 with self.assertRaises(assert_type):
48 Gst.Caps.from_string("audio/x-raw")
50 with self.assertRaises(assert_type):
51 Gst.Structure.from_string("audio/x-raw")
53 with self.assertRaises(assert_type):
54 Gst.ElementFactory.make("identity", None)
56 def testNotDeinitialized(self):
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))
64 if sys.version_info >= (3, 0):
65 assert_type = Gst.NotInitialized
67 assert_type = TypeError
69 with self.assertRaises(assert_type):
70 Gst.Caps.from_string("audio/x-raw")
72 with self.assertRaises(assert_type):
73 Gst.Structure.from_string("audio/x-raw")
75 with self.assertRaises(assert_type):
76 Gst.ElementFactory.make("identity", None)
79 class TestStructure(TestCase):
83 test = Gst.Structure('test', test=1)
84 self.assertEqual(test['test'], 1)
86 test = Gst.Structure('test,test=1')
87 self.assertEqual(test['test'], 1)
90 class TestBin(TestCase):
92 def test_add_pad(self):
94 self.assertEqual(Gst.ElementFactory.make("bin", None).sinkpads, [])
96 class TestBufferMap(TestCase):
98 def test_map_unmap_manual(self):
100 buf = Gst.Buffer.new_wrapped([42])
101 info = buf.map(Gst.MapFlags.READ | Gst.MapFlags.WRITE)
102 self.assertEqual(info.data[0], 42)
104 with self.assertRaises(ValueError):
107 def test_map_unmap_context(self):
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):
115 if __name__ == "__main__":