1 # -*- Mode: Python; py-indent-offset: 4 -*-
3 # vim: tabstop=4 shiftwidth=4 expandtab
13 from io import StringIO, BytesIO
16 from gi.repository import GObject, GLib, Gio
18 from gi.repository import GIMarshallingTests
20 from compathelper import _bytes
22 if sys.version_info < (3, 0):
23 CONSTANT_UTF8 = "const \xe2\x99\xa5 utf8"
24 PY2_UNICODE_UTF8 = unicode(CONSTANT_UTF8, 'UTF-8')
27 CONSTANT_UTF8 = "const ♥ utf8"
28 CHAR_255 = bytes([255])
35 def __init__(self, value):
39 return int(self.value)
42 return float(self.value)
45 class Sequence(object):
47 def __init__(self, sequence):
48 self.sequence = sequence
51 return len(self.sequence)
53 def __getitem__(self, key):
54 return self.sequence[key]
57 class TestConstant(unittest.TestCase):
59 # Blocked by https://bugzilla.gnome.org/show_bug.cgi?id=595773
60 # def test_constant_utf8(self):
61 # self.assertEqual(CONSTANT_UTF8, GIMarshallingTests.CONSTANT_UTF8)
63 def test_constant_number(self):
64 self.assertEqual(CONSTANT_NUMBER, GIMarshallingTests.CONSTANT_NUMBER)
67 class TestBoolean(unittest.TestCase):
69 def test_boolean_return(self):
70 self.assertEqual(True, GIMarshallingTests.boolean_return_true())
71 self.assertEqual(False, GIMarshallingTests.boolean_return_false())
73 def test_boolean_in(self):
74 GIMarshallingTests.boolean_in_true(True)
75 GIMarshallingTests.boolean_in_false(False)
77 GIMarshallingTests.boolean_in_true(1)
78 GIMarshallingTests.boolean_in_false(0)
80 def test_boolean_out(self):
81 self.assertEqual(True, GIMarshallingTests.boolean_out_true())
82 self.assertEqual(False, GIMarshallingTests.boolean_out_false())
84 def test_boolean_inout(self):
85 self.assertEqual(False, GIMarshallingTests.boolean_inout_true_false(True))
86 self.assertEqual(True, GIMarshallingTests.boolean_inout_false_true(False))
89 class TestInt8(unittest.TestCase):
91 MAX = GObject.G_MAXINT8
92 MIN = GObject.G_MININT8
94 def test_int8_return(self):
95 self.assertEqual(self.MAX, GIMarshallingTests.int8_return_max())
96 self.assertEqual(self.MIN, GIMarshallingTests.int8_return_min())
98 def test_int8_in(self):
99 max = Number(self.MAX)
100 min = Number(self.MIN)
102 GIMarshallingTests.int8_in_max(max)
103 GIMarshallingTests.int8_in_min(min)
108 self.assertRaises(ValueError, GIMarshallingTests.int8_in_max, max)
109 self.assertRaises(ValueError, GIMarshallingTests.int8_in_min, min)
111 self.assertRaises(TypeError, GIMarshallingTests.int8_in_max, "self.MAX")
113 def test_int8_out(self):
114 self.assertEqual(self.MAX, GIMarshallingTests.int8_out_max())
115 self.assertEqual(self.MIN, GIMarshallingTests.int8_out_min())
117 def test_int8_inout(self):
118 self.assertEqual(self.MIN, GIMarshallingTests.int8_inout_max_min(Number(self.MAX)))
119 self.assertEqual(self.MAX, GIMarshallingTests.int8_inout_min_max(Number(self.MIN)))
122 class TestUInt8(unittest.TestCase):
124 MAX = GObject.G_MAXUINT8
126 def test_uint8_return(self):
127 self.assertEqual(self.MAX, GIMarshallingTests.uint8_return())
129 def test_uint8_in(self):
130 number = Number(self.MAX)
132 GIMarshallingTests.uint8_in(number)
133 GIMarshallingTests.uint8_in(CHAR_255)
136 self.assertRaises(ValueError, GIMarshallingTests.uint8_in, number)
137 self.assertRaises(ValueError, GIMarshallingTests.uint8_in, Number(-1))
139 self.assertRaises(TypeError, GIMarshallingTests.uint8_in, "self.MAX")
141 def test_uint8_out(self):
142 self.assertEqual(self.MAX, GIMarshallingTests.uint8_out())
144 def test_uint8_inout(self):
145 self.assertEqual(0, GIMarshallingTests.uint8_inout(Number(self.MAX)))
148 class TestInt16(unittest.TestCase):
150 MAX = GObject.G_MAXINT16
151 MIN = GObject.G_MININT16
153 def test_int16_return(self):
154 self.assertEqual(self.MAX, GIMarshallingTests.int16_return_max())
155 self.assertEqual(self.MIN, GIMarshallingTests.int16_return_min())
157 def test_int16_in(self):
158 max = Number(self.MAX)
159 min = Number(self.MIN)
161 GIMarshallingTests.int16_in_max(max)
162 GIMarshallingTests.int16_in_min(min)
167 self.assertRaises(ValueError, GIMarshallingTests.int16_in_max, max)
168 self.assertRaises(ValueError, GIMarshallingTests.int16_in_min, min)
170 self.assertRaises(TypeError, GIMarshallingTests.int16_in_max, "self.MAX")
172 def test_int16_out(self):
173 self.assertEqual(self.MAX, GIMarshallingTests.int16_out_max())
174 self.assertEqual(self.MIN, GIMarshallingTests.int16_out_min())
176 def test_int16_inout(self):
177 self.assertEqual(self.MIN, GIMarshallingTests.int16_inout_max_min(Number(self.MAX)))
178 self.assertEqual(self.MAX, GIMarshallingTests.int16_inout_min_max(Number(self.MIN)))
181 class TestUInt16(unittest.TestCase):
183 MAX = GObject.G_MAXUINT16
185 def test_uint16_return(self):
186 self.assertEqual(self.MAX, GIMarshallingTests.uint16_return())
188 def test_uint16_in(self):
189 number = Number(self.MAX)
191 GIMarshallingTests.uint16_in(number)
195 self.assertRaises(ValueError, GIMarshallingTests.uint16_in, number)
196 self.assertRaises(ValueError, GIMarshallingTests.uint16_in, Number(-1))
198 self.assertRaises(TypeError, GIMarshallingTests.uint16_in, "self.MAX")
200 def test_uint16_out(self):
201 self.assertEqual(self.MAX, GIMarshallingTests.uint16_out())
203 def test_uint16_inout(self):
204 self.assertEqual(0, GIMarshallingTests.uint16_inout(Number(self.MAX)))
207 class TestInt32(unittest.TestCase):
209 MAX = GObject.G_MAXINT32
210 MIN = GObject.G_MININT32
212 def test_int32_return(self):
213 self.assertEqual(self.MAX, GIMarshallingTests.int32_return_max())
214 self.assertEqual(self.MIN, GIMarshallingTests.int32_return_min())
216 def test_int32_in(self):
217 max = Number(self.MAX)
218 min = Number(self.MIN)
220 GIMarshallingTests.int32_in_max(max)
221 GIMarshallingTests.int32_in_min(min)
226 self.assertRaises(ValueError, GIMarshallingTests.int32_in_max, max)
227 self.assertRaises(ValueError, GIMarshallingTests.int32_in_min, min)
229 self.assertRaises(TypeError, GIMarshallingTests.int32_in_max, "self.MAX")
231 def test_int32_out(self):
232 self.assertEqual(self.MAX, GIMarshallingTests.int32_out_max())
233 self.assertEqual(self.MIN, GIMarshallingTests.int32_out_min())
235 def test_int32_inout(self):
236 self.assertEqual(self.MIN, GIMarshallingTests.int32_inout_max_min(Number(self.MAX)))
237 self.assertEqual(self.MAX, GIMarshallingTests.int32_inout_min_max(Number(self.MIN)))
240 class TestUInt32(unittest.TestCase):
242 MAX = GObject.G_MAXUINT32
244 def test_uint32_return(self):
245 self.assertEqual(self.MAX, GIMarshallingTests.uint32_return())
247 def test_uint32_in(self):
248 number = Number(self.MAX)
250 GIMarshallingTests.uint32_in(number)
254 self.assertRaises(ValueError, GIMarshallingTests.uint32_in, number)
255 self.assertRaises(ValueError, GIMarshallingTests.uint32_in, Number(-1))
257 self.assertRaises(TypeError, GIMarshallingTests.uint32_in, "self.MAX")
259 def test_uint32_out(self):
260 self.assertEqual(self.MAX, GIMarshallingTests.uint32_out())
262 def test_uint32_inout(self):
263 self.assertEqual(0, GIMarshallingTests.uint32_inout(Number(self.MAX)))
266 class TestInt64(unittest.TestCase):
271 def test_int64_return(self):
272 self.assertEqual(self.MAX, GIMarshallingTests.int64_return_max())
273 self.assertEqual(self.MIN, GIMarshallingTests.int64_return_min())
275 def test_int64_in(self):
276 max = Number(self.MAX)
277 min = Number(self.MIN)
279 GIMarshallingTests.int64_in_max(max)
280 GIMarshallingTests.int64_in_min(min)
285 self.assertRaises(ValueError, GIMarshallingTests.int64_in_max, max)
286 self.assertRaises(ValueError, GIMarshallingTests.int64_in_min, min)
288 self.assertRaises(TypeError, GIMarshallingTests.int64_in_max, "self.MAX")
290 def test_int64_out(self):
291 self.assertEqual(self.MAX, GIMarshallingTests.int64_out_max())
292 self.assertEqual(self.MIN, GIMarshallingTests.int64_out_min())
294 def test_int64_inout(self):
295 self.assertEqual(self.MIN, GIMarshallingTests.int64_inout_max_min(Number(self.MAX)))
296 self.assertEqual(self.MAX, GIMarshallingTests.int64_inout_min_max(Number(self.MIN)))
299 class TestUInt64(unittest.TestCase):
303 def test_uint64_return(self):
304 self.assertEqual(self.MAX, GIMarshallingTests.uint64_return())
306 def test_uint64_in(self):
307 number = Number(self.MAX)
309 GIMarshallingTests.uint64_in(number)
313 self.assertRaises(ValueError, GIMarshallingTests.uint64_in, number)
314 self.assertRaises(ValueError, GIMarshallingTests.uint64_in, Number(-1))
316 self.assertRaises(TypeError, GIMarshallingTests.uint64_in, "self.MAX")
318 def test_uint64_out(self):
319 self.assertEqual(self.MAX, GIMarshallingTests.uint64_out())
321 def test_uint64_inout(self):
322 self.assertEqual(0, GIMarshallingTests.uint64_inout(Number(self.MAX)))
325 class TestShort(unittest.TestCase):
327 MAX = GObject.constants.G_MAXSHORT
328 MIN = GObject.constants.G_MINSHORT
330 def test_short_return(self):
331 self.assertEqual(self.MAX, GIMarshallingTests.short_return_max())
332 self.assertEqual(self.MIN, GIMarshallingTests.short_return_min())
334 def test_short_in(self):
335 max = Number(self.MAX)
336 min = Number(self.MIN)
338 GIMarshallingTests.short_in_max(max)
339 GIMarshallingTests.short_in_min(min)
344 self.assertRaises(ValueError, GIMarshallingTests.short_in_max, max)
345 self.assertRaises(ValueError, GIMarshallingTests.short_in_min, min)
347 self.assertRaises(TypeError, GIMarshallingTests.short_in_max, "self.MAX")
349 def test_short_out(self):
350 self.assertEqual(self.MAX, GIMarshallingTests.short_out_max())
351 self.assertEqual(self.MIN, GIMarshallingTests.short_out_min())
353 def test_short_inout(self):
354 self.assertEqual(self.MIN, GIMarshallingTests.short_inout_max_min(Number(self.MAX)))
355 self.assertEqual(self.MAX, GIMarshallingTests.short_inout_min_max(Number(self.MIN)))
358 class TestUShort(unittest.TestCase):
360 MAX = GObject.constants.G_MAXUSHORT
362 def test_ushort_return(self):
363 self.assertEqual(self.MAX, GIMarshallingTests.ushort_return())
365 def test_ushort_in(self):
366 number = Number(self.MAX)
368 GIMarshallingTests.ushort_in(number)
372 self.assertRaises(ValueError, GIMarshallingTests.ushort_in, number)
373 self.assertRaises(ValueError, GIMarshallingTests.ushort_in, Number(-1))
375 self.assertRaises(TypeError, GIMarshallingTests.ushort_in, "self.MAX")
377 def test_ushort_out(self):
378 self.assertEqual(self.MAX, GIMarshallingTests.ushort_out())
380 def test_ushort_inout(self):
381 self.assertEqual(0, GIMarshallingTests.ushort_inout(Number(self.MAX)))
384 class TestInt(unittest.TestCase):
386 MAX = GObject.constants.G_MAXINT
387 MIN = GObject.constants.G_MININT
389 def test_int_return(self):
390 self.assertEqual(self.MAX, GIMarshallingTests.int_return_max())
391 self.assertEqual(self.MIN, GIMarshallingTests.int_return_min())
393 def test_int_in(self):
394 max = Number(self.MAX)
395 min = Number(self.MIN)
397 GIMarshallingTests.int_in_max(max)
398 GIMarshallingTests.int_in_min(min)
403 self.assertRaises(ValueError, GIMarshallingTests.int_in_max, max)
404 self.assertRaises(ValueError, GIMarshallingTests.int_in_min, min)
406 self.assertRaises(TypeError, GIMarshallingTests.int_in_max, "self.MAX")
408 def test_int_out(self):
409 self.assertEqual(self.MAX, GIMarshallingTests.int_out_max())
410 self.assertEqual(self.MIN, GIMarshallingTests.int_out_min())
412 def test_int_inout(self):
413 self.assertEqual(self.MIN, GIMarshallingTests.int_inout_max_min(Number(self.MAX)))
414 self.assertEqual(self.MAX, GIMarshallingTests.int_inout_min_max(Number(self.MIN)))
415 self.assertRaises(TypeError, GIMarshallingTests.int_inout_min_max, Number(self.MIN), CONSTANT_NUMBER)
418 class TestUInt(unittest.TestCase):
420 MAX = GObject.constants.G_MAXUINT
422 def test_uint_return(self):
423 self.assertEqual(self.MAX, GIMarshallingTests.uint_return())
425 def test_uint_in(self):
426 number = Number(self.MAX)
428 GIMarshallingTests.uint_in(number)
432 self.assertRaises(ValueError, GIMarshallingTests.uint_in, number)
433 self.assertRaises(ValueError, GIMarshallingTests.uint_in, Number(-1))
435 self.assertRaises(TypeError, GIMarshallingTests.uint_in, "self.MAX")
437 def test_uint_out(self):
438 self.assertEqual(self.MAX, GIMarshallingTests.uint_out())
440 def test_uint_inout(self):
441 self.assertEqual(0, GIMarshallingTests.uint_inout(Number(self.MAX)))
444 class TestLong(unittest.TestCase):
446 MAX = GObject.constants.G_MAXLONG
447 MIN = GObject.constants.G_MINLONG
449 def test_long_return(self):
450 self.assertEqual(self.MAX, GIMarshallingTests.long_return_max())
451 self.assertEqual(self.MIN, GIMarshallingTests.long_return_min())
453 def test_long_in(self):
454 max = Number(self.MAX)
455 min = Number(self.MIN)
457 GIMarshallingTests.long_in_max(max)
458 GIMarshallingTests.long_in_min(min)
463 self.assertRaises(ValueError, GIMarshallingTests.long_in_max, max)
464 self.assertRaises(ValueError, GIMarshallingTests.long_in_min, min)
466 self.assertRaises(TypeError, GIMarshallingTests.long_in_max, "self.MAX")
468 def test_long_out(self):
469 self.assertEqual(self.MAX, GIMarshallingTests.long_out_max())
470 self.assertEqual(self.MIN, GIMarshallingTests.long_out_min())
472 def test_long_inout(self):
473 self.assertEqual(self.MIN, GIMarshallingTests.long_inout_max_min(Number(self.MAX)))
474 self.assertEqual(self.MAX, GIMarshallingTests.long_inout_min_max(Number(self.MIN)))
477 class TestULong(unittest.TestCase):
479 MAX = GObject.constants.G_MAXULONG
481 def test_ulong_return(self):
482 self.assertEqual(self.MAX, GIMarshallingTests.ulong_return())
484 def test_ulong_in(self):
485 number = Number(self.MAX)
487 GIMarshallingTests.ulong_in(number)
491 self.assertRaises(ValueError, GIMarshallingTests.ulong_in, number)
492 self.assertRaises(ValueError, GIMarshallingTests.ulong_in, Number(-1))
494 self.assertRaises(TypeError, GIMarshallingTests.ulong_in, "self.MAX")
496 def test_ulong_out(self):
497 self.assertEqual(self.MAX, GIMarshallingTests.ulong_out())
499 def test_ulong_inout(self):
500 self.assertEqual(0, GIMarshallingTests.ulong_inout(Number(self.MAX)))
503 class TestSSize(unittest.TestCase):
505 MAX = GObject.constants.G_MAXLONG
506 MIN = GObject.constants.G_MINLONG
508 def test_ssize_return(self):
509 self.assertEqual(self.MAX, GIMarshallingTests.ssize_return_max())
510 self.assertEqual(self.MIN, GIMarshallingTests.ssize_return_min())
512 def test_ssize_in(self):
513 max = Number(self.MAX)
514 min = Number(self.MIN)
516 GIMarshallingTests.ssize_in_max(max)
517 GIMarshallingTests.ssize_in_min(min)
522 self.assertRaises(ValueError, GIMarshallingTests.ssize_in_max, max)
523 self.assertRaises(ValueError, GIMarshallingTests.ssize_in_min, min)
525 self.assertRaises(TypeError, GIMarshallingTests.ssize_in_max, "self.MAX")
527 def test_ssize_out(self):
528 self.assertEqual(self.MAX, GIMarshallingTests.ssize_out_max())
529 self.assertEqual(self.MIN, GIMarshallingTests.ssize_out_min())
531 def test_ssize_inout(self):
532 self.assertEqual(self.MIN, GIMarshallingTests.ssize_inout_max_min(Number(self.MAX)))
533 self.assertEqual(self.MAX, GIMarshallingTests.ssize_inout_min_max(Number(self.MIN)))
536 class TestSize(unittest.TestCase):
538 MAX = GObject.constants.G_MAXULONG
540 def test_size_return(self):
541 self.assertEqual(self.MAX, GIMarshallingTests.size_return())
543 def test_size_in(self):
544 number = Number(self.MAX)
546 GIMarshallingTests.size_in(number)
550 self.assertRaises(ValueError, GIMarshallingTests.size_in, number)
551 self.assertRaises(ValueError, GIMarshallingTests.size_in, Number(-1))
553 self.assertRaises(TypeError, GIMarshallingTests.size_in, "self.MAX")
555 def test_size_out(self):
556 self.assertEqual(self.MAX, GIMarshallingTests.size_out())
558 def test_size_inout(self):
559 self.assertEqual(0, GIMarshallingTests.size_inout(Number(self.MAX)))
562 class TestFloat(unittest.TestCase):
564 MAX = GObject.constants.G_MAXFLOAT
565 MIN = GObject.constants.G_MINFLOAT
567 def test_float_return(self):
568 self.assertAlmostEqual(self.MAX, GIMarshallingTests.float_return())
570 def test_float_in(self):
571 GIMarshallingTests.float_in(Number(self.MAX))
573 self.assertRaises(TypeError, GIMarshallingTests.float_in, "self.MAX")
575 def test_float_out(self):
576 self.assertAlmostEqual(self.MAX, GIMarshallingTests.float_out())
578 def test_float_inout(self):
579 self.assertAlmostEqual(self.MIN, GIMarshallingTests.float_inout(Number(self.MAX)))
582 class TestDouble(unittest.TestCase):
584 MAX = GObject.constants.G_MAXDOUBLE
585 MIN = GObject.constants.G_MINDOUBLE
587 def test_double_return(self):
588 self.assertAlmostEqual(self.MAX, GIMarshallingTests.double_return())
590 def test_double_in(self):
591 GIMarshallingTests.double_in(Number(self.MAX))
593 self.assertRaises(TypeError, GIMarshallingTests.double_in, "self.MAX")
595 def test_double_out(self):
596 self.assertAlmostEqual(self.MAX, GIMarshallingTests.double_out())
598 def test_double_inout(self):
599 self.assertAlmostEqual(self.MIN, GIMarshallingTests.double_inout(Number(self.MAX)))
602 class TestGType(unittest.TestCase):
604 def test_gtype_name(self):
605 self.assertEqual("void", GObject.TYPE_NONE.name)
606 self.assertEqual("gchararray", GObject.TYPE_STRING.name)
608 def check_readonly(gtype):
611 self.assertRaises(AttributeError, check_readonly, GObject.TYPE_NONE)
612 self.assertRaises(AttributeError, check_readonly, GObject.TYPE_STRING)
614 def test_gtype_return(self):
615 self.assertEqual(GObject.TYPE_NONE, GIMarshallingTests.gtype_return())
616 self.assertEqual(GObject.TYPE_STRING, GIMarshallingTests.gtype_string_return())
618 def test_gtype_in(self):
619 GIMarshallingTests.gtype_in(GObject.TYPE_NONE)
620 GIMarshallingTests.gtype_string_in(GObject.TYPE_STRING)
621 self.assertRaises(TypeError, GIMarshallingTests.gtype_in, "foo")
622 self.assertRaises(TypeError, GIMarshallingTests.gtype_string_in, "foo")
624 def test_gtype_out(self):
625 self.assertEqual(GObject.TYPE_NONE, GIMarshallingTests.gtype_out())
626 self.assertEqual(GObject.TYPE_STRING, GIMarshallingTests.gtype_string_out())
628 def test_gtype_inout(self):
629 self.assertEqual(GObject.TYPE_INT, GIMarshallingTests.gtype_inout(GObject.TYPE_NONE))
632 class TestUtf8(unittest.TestCase):
634 def test_utf8_none_return(self):
635 self.assertEqual(CONSTANT_UTF8, GIMarshallingTests.utf8_none_return())
637 def test_utf8_full_return(self):
638 self.assertEqual(CONSTANT_UTF8, GIMarshallingTests.utf8_full_return())
640 def test_utf8_none_in(self):
641 GIMarshallingTests.utf8_none_in(CONSTANT_UTF8)
642 if sys.version_info < (3, 0):
643 GIMarshallingTests.utf8_none_in(PY2_UNICODE_UTF8)
645 self.assertRaises(TypeError, GIMarshallingTests.utf8_none_in, CONSTANT_NUMBER)
646 self.assertRaises(TypeError, GIMarshallingTests.utf8_none_in, None)
648 def test_utf8_none_out(self):
649 self.assertEqual(CONSTANT_UTF8, GIMarshallingTests.utf8_none_out())
651 def test_utf8_full_out(self):
652 self.assertEqual(CONSTANT_UTF8, GIMarshallingTests.utf8_full_out())
654 def test_utf8_dangling_out(self):
655 GIMarshallingTests.utf8_dangling_out()
657 def test_utf8_none_inout(self):
658 self.assertEqual("", GIMarshallingTests.utf8_none_inout(CONSTANT_UTF8))
660 def test_utf8_full_inout(self):
661 self.assertEqual("", GIMarshallingTests.utf8_full_inout(CONSTANT_UTF8))
664 class TestArray(unittest.TestCase):
666 def test_array_fixed_int_return(self):
667 self.assertEqual([-1, 0, 1, 2], GIMarshallingTests.array_fixed_int_return())
669 def test_array_fixed_short_return(self):
670 self.assertEqual([-1, 0, 1, 2], GIMarshallingTests.array_fixed_short_return())
672 def test_array_fixed_int_in(self):
673 GIMarshallingTests.array_fixed_int_in(Sequence([-1, 0, 1, 2]))
675 self.assertRaises(TypeError, GIMarshallingTests.array_fixed_int_in, Sequence([-1, '0', 1, 2]))
677 self.assertRaises(TypeError, GIMarshallingTests.array_fixed_int_in, 42)
678 self.assertRaises(TypeError, GIMarshallingTests.array_fixed_int_in, None)
680 def test_array_fixed_short_in(self):
681 GIMarshallingTests.array_fixed_short_in(Sequence([-1, 0, 1, 2]))
683 def test_array_fixed_out(self):
684 self.assertEqual([-1, 0, 1, 2], GIMarshallingTests.array_fixed_out())
686 def test_array_fixed_inout(self):
687 self.assertEqual([2, 1, 0, -1], GIMarshallingTests.array_fixed_inout([-1, 0, 1, 2]))
689 def test_array_return(self):
690 self.assertEqual([-1, 0, 1, 2], GIMarshallingTests.array_return())
692 def test_array_in(self):
693 GIMarshallingTests.array_in(Sequence([-1, 0, 1, 2]))
695 def test_array_in_len_zero_terminated(self):
696 GIMarshallingTests.array_in_len_zero_terminated(Sequence([-1, 0, 1, 2]))
698 def test_array_uint8_in(self):
699 GIMarshallingTests.array_uint8_in(Sequence([97, 98, 99, 100]))
700 GIMarshallingTests.array_uint8_in(_bytes("abcd"))
702 def test_array_out(self):
703 self.assertEqual([-1, 0, 1, 2], GIMarshallingTests.array_out())
705 def test_array_inout(self):
706 self.assertEqual([-2, -1, 0, 1, 2], GIMarshallingTests.array_inout(Sequence([-1, 0, 1, 2])))
708 def test_method_array_in(self):
709 object_ = GIMarshallingTests.Object()
710 object_.method_array_in(Sequence([-1, 0, 1, 2]))
712 def test_method_array_out(self):
713 object_ = GIMarshallingTests.Object()
714 self.assertEqual([-1, 0, 1, 2], object_.method_array_out())
716 def test_method_array_inout(self):
717 object_ = GIMarshallingTests.Object()
718 self.assertEqual([-2, -1, 0, 1, 2], object_.method_array_inout(Sequence([-1, 0, 1, 2])))
720 def test_method_array_return(self):
721 object_ = GIMarshallingTests.Object()
722 self.assertEqual([-1, 0, 1, 2], object_.method_array_return())
724 def test_array_enum_in(self):
725 GIMarshallingTests.array_enum_in([GIMarshallingTests.Enum.VALUE1,
726 GIMarshallingTests.Enum.VALUE2,
727 GIMarshallingTests.Enum.VALUE3])
729 def test_array_boxed_struct_in(self):
730 struct1 = GIMarshallingTests.BoxedStruct()
732 struct2 = GIMarshallingTests.BoxedStruct()
734 struct3 = GIMarshallingTests.BoxedStruct()
737 GIMarshallingTests.array_struct_in([struct1, struct2, struct3])
739 def test_array_simple_struct_in(self):
740 struct1 = GIMarshallingTests.SimpleStruct()
742 struct2 = GIMarshallingTests.SimpleStruct()
744 struct3 = GIMarshallingTests.SimpleStruct()
747 GIMarshallingTests.array_simple_struct_in([struct1, struct2, struct3])
749 def test_array_multi_array_key_value_in(self):
750 GIMarshallingTests.multi_array_key_value_in(["one", "two", "three"],
753 def test_array_in_nonzero_nonlen(self):
754 GIMarshallingTests.array_in_nonzero_nonlen(1, b'abcd')
756 def test_array_fixed_out_struct(self):
757 struct1, struct2 = GIMarshallingTests.array_fixed_out_struct()
759 self.assertEqual(7, struct1.long_)
760 self.assertEqual(6, struct1.int8)
761 self.assertEqual(6, struct2.long_)
762 self.assertEqual(7, struct2.int8)
764 def test_array_zero_terminated_return(self):
765 self.assertEqual(['0', '1', '2'], GIMarshallingTests.array_zero_terminated_return())
767 def test_array_zero_terminated_return_null(self):
768 self.assertEqual([], GIMarshallingTests.array_zero_terminated_return_null())
770 def test_array_zero_terminated_in(self):
771 GIMarshallingTests.array_zero_terminated_in(Sequence(['0', '1', '2']))
773 def test_array_zero_terminated_out(self):
774 self.assertEqual(['0', '1', '2'], GIMarshallingTests.array_zero_terminated_out())
776 def test_array_zero_terminated_inout(self):
777 self.assertEqual(['-1', '0', '1', '2'], GIMarshallingTests.array_zero_terminated_inout(['0', '1', '2']))
780 class TestGStrv(unittest.TestCase):
782 def test_gstrv_return(self):
783 self.assertEqual(['0', '1', '2'], GIMarshallingTests.gstrv_return())
785 def test_gstrv_in(self):
786 GIMarshallingTests.gstrv_in(Sequence(['0', '1', '2']))
788 def test_gstrv_out(self):
789 self.assertEqual(['0', '1', '2'], GIMarshallingTests.gstrv_out())
791 def test_gstrv_inout(self):
792 self.assertEqual(['-1', '0', '1', '2'], GIMarshallingTests.gstrv_inout(['0', '1', '2']))
795 class TestArrayGVariant(unittest.TestCase):
797 def test_array_gvariant_none_in(self):
798 v = [GLib.Variant("i", 27), GLib.Variant("s", "Hello")]
799 returned = [GLib.Variant.unpack(r) for r in GIMarshallingTests.array_gvariant_none_in(v)]
800 self.assertEqual([27, "Hello"], returned)
802 def test_array_gvariant_container_in(self):
803 v = [GLib.Variant("i", 27), GLib.Variant("s", "Hello")]
804 returned = [GLib.Variant.unpack(r) for r in GIMarshallingTests.array_gvariant_container_in(v)]
805 self.assertEqual([27, "Hello"], returned)
807 def test_array_gvariant_full_in(self):
808 v = [GLib.Variant("i", 27), GLib.Variant("s", "Hello")]
809 returned = [GLib.Variant.unpack(r) for r in GIMarshallingTests.array_gvariant_full_in(v)]
810 self.assertEqual([27, "Hello"], returned)
812 def test_bytearray_gvariant(self):
813 v = GLib.Variant.new_bytestring(b"foo")
814 self.assertEqual(v.get_bytestring(), b"foo")
817 class TestGArray(unittest.TestCase):
819 def test_garray_int_none_return(self):
820 self.assertEqual([-1, 0, 1, 2], GIMarshallingTests.garray_int_none_return())
822 def test_garray_utf8_none_return(self):
823 self.assertEqual(['0', '1', '2'], GIMarshallingTests.garray_utf8_none_return())
825 def test_garray_utf8_container_return(self):
826 self.assertEqual(['0', '1', '2'], GIMarshallingTests.garray_utf8_container_return())
828 def test_garray_utf8_full_return(self):
829 self.assertEqual(['0', '1', '2'], GIMarshallingTests.garray_utf8_full_return())
831 def test_garray_int_none_in(self):
832 GIMarshallingTests.garray_int_none_in(Sequence([-1, 0, 1, 2]))
834 self.assertRaises(TypeError, GIMarshallingTests.garray_int_none_in, Sequence([-1, '0', 1, 2]))
836 self.assertRaises(TypeError, GIMarshallingTests.garray_int_none_in, 42)
837 self.assertRaises(TypeError, GIMarshallingTests.garray_int_none_in, None)
839 def test_garray_utf8_none_in(self):
840 GIMarshallingTests.garray_utf8_none_in(Sequence(['0', '1', '2']))
842 def test_garray_utf8_none_out(self):
843 self.assertEqual(['0', '1', '2'], GIMarshallingTests.garray_utf8_none_out())
845 def test_garray_utf8_container_out(self):
846 self.assertEqual(['0', '1', '2'], GIMarshallingTests.garray_utf8_container_out())
848 def test_garray_utf8_full_out(self):
849 self.assertEqual(['0', '1', '2'], GIMarshallingTests.garray_utf8_full_out())
851 def test_garray_utf8_none_inout(self):
852 self.assertEqual(['-2', '-1', '0', '1'], GIMarshallingTests.garray_utf8_none_inout(Sequence(('0', '1', '2'))))
854 def test_garray_utf8_container_inout(self):
855 self.assertEqual(['-2', '-1', '0', '1'], GIMarshallingTests.garray_utf8_container_inout(['0', '1', '2']))
857 def test_garray_utf8_full_inout(self):
858 self.assertEqual(['-2', '-1', '0', '1'], GIMarshallingTests.garray_utf8_full_inout(['0', '1', '2']))
861 class TestGPtrArray(unittest.TestCase):
863 def test_gptrarray_utf8_none_return(self):
864 self.assertEqual(['0', '1', '2'], GIMarshallingTests.gptrarray_utf8_none_return())
866 def test_gptrarray_utf8_container_return(self):
867 self.assertEqual(['0', '1', '2'], GIMarshallingTests.gptrarray_utf8_container_return())
869 def test_gptrarray_utf8_full_return(self):
870 self.assertEqual(['0', '1', '2'], GIMarshallingTests.gptrarray_utf8_full_return())
872 def test_gptrarray_utf8_none_in(self):
873 GIMarshallingTests.gptrarray_utf8_none_in(Sequence(['0', '1', '2']))
875 def test_gptrarray_utf8_none_out(self):
876 self.assertEqual(['0', '1', '2'], GIMarshallingTests.gptrarray_utf8_none_out())
878 def test_gptrarray_utf8_container_out(self):
879 self.assertEqual(['0', '1', '2'], GIMarshallingTests.gptrarray_utf8_container_out())
881 def test_gptrarray_utf8_full_out(self):
882 self.assertEqual(['0', '1', '2'], GIMarshallingTests.gptrarray_utf8_full_out())
884 def test_gptrarray_utf8_none_inout(self):
885 self.assertEqual(['-2', '-1', '0', '1'], GIMarshallingTests.gptrarray_utf8_none_inout(Sequence(('0', '1', '2'))))
887 def test_gptrarray_utf8_container_inout(self):
888 self.assertEqual(['-2', '-1', '0', '1'], GIMarshallingTests.gptrarray_utf8_container_inout(['0', '1', '2']))
890 def test_gptrarray_utf8_full_inout(self):
891 self.assertEqual(['-2', '-1', '0', '1'], GIMarshallingTests.gptrarray_utf8_full_inout(['0', '1', '2']))
894 class TestGList(unittest.TestCase):
896 def test_glist_int_none_return(self):
897 self.assertEqual([-1, 0, 1, 2], GIMarshallingTests.glist_int_none_return())
899 def test_glist_utf8_none_return(self):
900 self.assertEqual(['0', '1', '2'], GIMarshallingTests.glist_utf8_none_return())
902 def test_glist_utf8_container_return(self):
903 self.assertEqual(['0', '1', '2'], GIMarshallingTests.glist_utf8_container_return())
905 def test_glist_utf8_full_return(self):
906 self.assertEqual(['0', '1', '2'], GIMarshallingTests.glist_utf8_full_return())
908 def test_glist_int_none_in(self):
909 GIMarshallingTests.glist_int_none_in(Sequence((-1, 0, 1, 2)))
911 self.assertRaises(TypeError, GIMarshallingTests.glist_int_none_in, Sequence((-1, '0', 1, 2)))
913 self.assertRaises(TypeError, GIMarshallingTests.glist_int_none_in, 42)
914 self.assertRaises(TypeError, GIMarshallingTests.glist_int_none_in, None)
916 def test_glist_utf8_none_in(self):
917 GIMarshallingTests.glist_utf8_none_in(Sequence(('0', '1', '2')))
919 def test_glist_utf8_none_out(self):
920 self.assertEqual(['0', '1', '2'], GIMarshallingTests.glist_utf8_none_out())
922 def test_glist_utf8_container_out(self):
923 self.assertEqual(['0', '1', '2'], GIMarshallingTests.glist_utf8_container_out())
925 def test_glist_utf8_full_out(self):
926 self.assertEqual(['0', '1', '2'], GIMarshallingTests.glist_utf8_full_out())
928 def test_glist_utf8_none_inout(self):
929 self.assertEqual(['-2', '-1', '0', '1'], GIMarshallingTests.glist_utf8_none_inout(Sequence(('0', '1', '2'))))
931 def test_glist_utf8_container_inout(self):
932 self.assertEqual(['-2', '-1', '0', '1'], GIMarshallingTests.glist_utf8_container_inout(('0', '1', '2')))
934 def test_glist_utf8_full_inout(self):
935 self.assertEqual(['-2', '-1', '0', '1'], GIMarshallingTests.glist_utf8_full_inout(('0', '1', '2')))
938 class TestGSList(unittest.TestCase):
940 def test_gslist_int_none_return(self):
941 self.assertEqual([-1, 0, 1, 2], GIMarshallingTests.gslist_int_none_return())
943 def test_gslist_utf8_none_return(self):
944 self.assertEqual(['0', '1', '2'], GIMarshallingTests.gslist_utf8_none_return())
946 def test_gslist_utf8_container_return(self):
947 self.assertEqual(['0', '1', '2'], GIMarshallingTests.gslist_utf8_container_return())
949 def test_gslist_utf8_full_return(self):
950 self.assertEqual(['0', '1', '2'], GIMarshallingTests.gslist_utf8_full_return())
952 def test_gslist_int_none_in(self):
953 GIMarshallingTests.gslist_int_none_in(Sequence((-1, 0, 1, 2)))
955 self.assertRaises(TypeError, GIMarshallingTests.gslist_int_none_in, Sequence((-1, '0', 1, 2)))
957 self.assertRaises(TypeError, GIMarshallingTests.gslist_int_none_in, 42)
958 self.assertRaises(TypeError, GIMarshallingTests.gslist_int_none_in, None)
960 def test_gslist_utf8_none_in(self):
961 GIMarshallingTests.gslist_utf8_none_in(Sequence(('0', '1', '2')))
963 def test_gslist_utf8_none_out(self):
964 self.assertEqual(['0', '1', '2'], GIMarshallingTests.gslist_utf8_none_out())
966 def test_gslist_utf8_container_out(self):
967 self.assertEqual(['0', '1', '2'], GIMarshallingTests.gslist_utf8_container_out())
969 def test_gslist_utf8_full_out(self):
970 self.assertEqual(['0', '1', '2'], GIMarshallingTests.gslist_utf8_full_out())
972 def test_gslist_utf8_none_inout(self):
973 self.assertEqual(['-2', '-1', '0', '1'], GIMarshallingTests.gslist_utf8_none_inout(Sequence(('0', '1', '2'))))
975 def test_gslist_utf8_container_inout(self):
976 self.assertEqual(['-2', '-1', '0', '1'], GIMarshallingTests.gslist_utf8_container_inout(('0', '1', '2')))
978 def test_gslist_utf8_full_inout(self):
979 self.assertEqual(['-2', '-1', '0', '1'], GIMarshallingTests.gslist_utf8_full_inout(('0', '1', '2')))
982 class TestGHashTable(unittest.TestCase):
984 def test_ghashtable_int_none_return(self):
985 self.assertEqual({-1: 1, 0: 0, 1: -1, 2: -2}, GIMarshallingTests.ghashtable_int_none_return())
987 def test_ghashtable_int_none_return2(self):
988 self.assertEqual({'-1': '1', '0': '0', '1': '-1', '2': '-2'}, GIMarshallingTests.ghashtable_utf8_none_return())
990 def test_ghashtable_int_container_return(self):
991 self.assertEqual({'-1': '1', '0': '0', '1': '-1', '2': '-2'}, GIMarshallingTests.ghashtable_utf8_container_return())
993 def test_ghashtable_int_full_return(self):
994 self.assertEqual({'-1': '1', '0': '0', '1': '-1', '2': '-2'}, GIMarshallingTests.ghashtable_utf8_full_return())
996 def test_ghashtable_int_none_in(self):
997 GIMarshallingTests.ghashtable_int_none_in({-1: 1, 0: 0, 1: -1, 2: -2})
999 self.assertRaises(TypeError, GIMarshallingTests.ghashtable_int_none_in, {-1: 1, '0': 0, 1: -1, 2: -2})
1000 self.assertRaises(TypeError, GIMarshallingTests.ghashtable_int_none_in, {-1: 1, 0: '0', 1: -1, 2: -2})
1002 self.assertRaises(TypeError, GIMarshallingTests.ghashtable_int_none_in, '{-1: 1, 0: 0, 1: -1, 2: -2}')
1003 self.assertRaises(TypeError, GIMarshallingTests.ghashtable_int_none_in, None)
1005 def test_ghashtable_utf8_none_in(self):
1006 GIMarshallingTests.ghashtable_utf8_none_in({'-1': '1', '0': '0', '1': '-1', '2': '-2'})
1008 def test_ghashtable_utf8_none_out(self):
1009 self.assertEqual({'-1': '1', '0': '0', '1': '-1', '2': '-2'}, GIMarshallingTests.ghashtable_utf8_none_out())
1011 def test_ghashtable_utf8_container_out(self):
1012 self.assertEqual({'-1': '1', '0': '0', '1': '-1', '2': '-2'}, GIMarshallingTests.ghashtable_utf8_container_out())
1014 def test_ghashtable_utf8_full_out(self):
1015 self.assertEqual({'-1': '1', '0': '0', '1': '-1', '2': '-2'}, GIMarshallingTests.ghashtable_utf8_full_out())
1017 def test_ghashtable_utf8_none_inout(self):
1018 i = {'-1': '1', '0': '0', '1': '-1', '2': '-2'}
1019 self.assertEqual({'-1': '1', '0': '0', '1': '1'},
1020 GIMarshallingTests.ghashtable_utf8_none_inout(i))
1022 def test_ghashtable_utf8_container_inout(self):
1023 i = {'-1': '1', '0': '0', '1': '-1', '2': '-2'}
1024 self.assertEqual({'-1': '1', '0': '0', '1': '1'},
1025 GIMarshallingTests.ghashtable_utf8_container_inout(i))
1027 def test_ghashtable_utf8_full_inout(self):
1028 i = {'-1': '1', '0': '0', '1': '-1', '2': '-2'}
1029 self.assertEqual({'-1': '1', '0': '0', '1': '1'},
1030 GIMarshallingTests.ghashtable_utf8_full_inout(i))
1033 class TestGValue(unittest.TestCase):
1035 def test_gvalue_return(self):
1036 self.assertEqual(42, GIMarshallingTests.gvalue_return())
1038 def test_gvalue_in(self):
1039 GIMarshallingTests.gvalue_in(42)
1040 value = GObject.Value()
1041 value.init(GObject.TYPE_INT)
1043 GIMarshallingTests.gvalue_in(value)
1045 def test_gvalue_int64_in(self):
1046 value = GObject.Value()
1047 value.init(GObject.TYPE_INT64)
1048 value.set_int64(GObject.G_MAXINT64)
1049 GIMarshallingTests.gvalue_int64_in(value)
1051 def test_gvalue_out(self):
1052 self.assertEqual(42, GIMarshallingTests.gvalue_out())
1054 def test_gvalue_int64_out(self):
1055 self.assertEqual(GObject.G_MAXINT64, GIMarshallingTests.gvalue_int64_out())
1057 def test_gvalue_out_caller_allocates(self):
1058 self.assertEqual(42, GIMarshallingTests.gvalue_out_caller_allocates())
1060 def test_gvalue_inout(self):
1061 self.assertEqual('42', GIMarshallingTests.gvalue_inout(42))
1062 value = GObject.Value()
1063 value.init(GObject.TYPE_INT)
1065 self.assertEqual('42', GIMarshallingTests.gvalue_inout(value))
1067 def test_gvalue_flat_array_in(self):
1068 # the function already asserts the correct values
1069 GIMarshallingTests.gvalue_flat_array([42, "42", True])
1071 def test_gvalue_flat_array_out(self):
1072 values = GIMarshallingTests.return_gvalue_flat_array()
1073 self.assertEqual(values, [42, '42', True])
1076 class TestGClosure(unittest.TestCase):
1078 def test_gclosure_in(self):
1079 GIMarshallingTests.gclosure_in(lambda: 42)
1081 # test passing a closure between two C calls
1082 closure = GIMarshallingTests.gclosure_return()
1083 GIMarshallingTests.gclosure_in(closure)
1085 self.assertRaises(TypeError, GIMarshallingTests.gclosure_in, 42)
1086 self.assertRaises(TypeError, GIMarshallingTests.gclosure_in, None)
1089 class TestPointer(unittest.TestCase):
1090 def test_pointer_in_return(self):
1091 self.assertEqual(GIMarshallingTests.pointer_in_return(42), 42)
1094 class TestEnum(unittest.TestCase):
1097 def setUpClass(cls):
1098 '''Run tests under a test locale.
1100 Upper case conversion of member names should not be locale specific
1101 e. g. in Turkish, "i".upper() == "i", which gives results like "iNVALiD"
1103 Run test under a locale which defines toupper('a') == 'a'
1105 cls.locale_dir = tempfile.mkdtemp()
1106 src = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'te_ST@nouppera')
1107 dest = os.path.join(cls.locale_dir, 'te_ST.UTF-8@nouppera')
1108 subprocess.check_call(['localedef', '-i', src, '-c', '-f', 'UTF-8', dest])
1109 os.environ['LOCPATH'] = cls.locale_dir
1110 locale.setlocale(locale.LC_ALL, 'te_ST.UTF-8@nouppera')
1113 def tearDownClass(cls):
1114 locale.setlocale(locale.LC_ALL, 'C')
1115 shutil.rmtree(cls.locale_dir)
1117 del os.environ['LOCPATH']
1121 def test_enum(self):
1122 self.assertTrue(issubclass(GIMarshallingTests.Enum, int))
1123 self.assertTrue(isinstance(GIMarshallingTests.Enum.VALUE1, GIMarshallingTests.Enum))
1124 self.assertTrue(isinstance(GIMarshallingTests.Enum.VALUE2, GIMarshallingTests.Enum))
1125 self.assertTrue(isinstance(GIMarshallingTests.Enum.VALUE3, GIMarshallingTests.Enum))
1126 self.assertEqual(42, GIMarshallingTests.Enum.VALUE3)
1128 def test_value_nick_and_name(self):
1129 self.assertEqual(GIMarshallingTests.Enum.VALUE1.value_nick, 'value1')
1130 self.assertEqual(GIMarshallingTests.Enum.VALUE2.value_nick, 'value2')
1131 self.assertEqual(GIMarshallingTests.Enum.VALUE3.value_nick, 'value3')
1133 self.assertEqual(GIMarshallingTests.Enum.VALUE1.value_name, 'GI_MARSHALLING_TESTS_ENUM_VALUE1')
1134 self.assertEqual(GIMarshallingTests.Enum.VALUE2.value_name, 'GI_MARSHALLING_TESTS_ENUM_VALUE2')
1135 self.assertEqual(GIMarshallingTests.Enum.VALUE3.value_name, 'GI_MARSHALLING_TESTS_ENUM_VALUE3')
1137 def test_enum_in(self):
1138 GIMarshallingTests.enum_in(GIMarshallingTests.Enum.VALUE3)
1139 GIMarshallingTests.enum_in(42)
1141 self.assertRaises(TypeError, GIMarshallingTests.enum_in, 43)
1142 self.assertRaises(TypeError, GIMarshallingTests.enum_in, 'GIMarshallingTests.Enum.VALUE3')
1144 def test_enum_out(self):
1145 enum = GIMarshallingTests.enum_out()
1146 self.assertTrue(isinstance(enum, GIMarshallingTests.Enum))
1147 self.assertEqual(enum, GIMarshallingTests.Enum.VALUE3)
1149 def test_enum_inout(self):
1150 enum = GIMarshallingTests.enum_inout(GIMarshallingTests.Enum.VALUE3)
1151 self.assertTrue(isinstance(enum, GIMarshallingTests.Enum))
1152 self.assertEqual(enum, GIMarshallingTests.Enum.VALUE1)
1154 def test_enum_second(self):
1155 # check for the bug where different non-gtype enums share the same class
1156 self.assertNotEqual(GIMarshallingTests.Enum, GIMarshallingTests.SecondEnum)
1158 # check that values are not being shared between different enums
1159 self.assertTrue(hasattr(GIMarshallingTests.SecondEnum, "SECONDVALUE1"))
1160 self.assertRaises(AttributeError, getattr, GIMarshallingTests.Enum, "SECONDVALUE1")
1161 self.assertTrue(hasattr(GIMarshallingTests.Enum, "VALUE1"))
1162 self.assertRaises(AttributeError, getattr, GIMarshallingTests.SecondEnum, "VALUE1")
1165 class TestGEnum(unittest.TestCase):
1167 def test_genum(self):
1168 self.assertTrue(issubclass(GIMarshallingTests.GEnum, GObject.GEnum))
1169 self.assertTrue(isinstance(GIMarshallingTests.GEnum.VALUE1, GIMarshallingTests.GEnum))
1170 self.assertTrue(isinstance(GIMarshallingTests.GEnum.VALUE2, GIMarshallingTests.GEnum))
1171 self.assertTrue(isinstance(GIMarshallingTests.GEnum.VALUE3, GIMarshallingTests.GEnum))
1172 self.assertEqual(42, GIMarshallingTests.GEnum.VALUE3)
1174 def test_value_nick_and_name(self):
1175 self.assertEqual(GIMarshallingTests.GEnum.VALUE1.value_nick, 'value1')
1176 self.assertEqual(GIMarshallingTests.GEnum.VALUE2.value_nick, 'value2')
1177 self.assertEqual(GIMarshallingTests.GEnum.VALUE3.value_nick, 'value3')
1179 self.assertEqual(GIMarshallingTests.GEnum.VALUE1.value_name, 'GI_MARSHALLING_TESTS_GENUM_VALUE1')
1180 self.assertEqual(GIMarshallingTests.GEnum.VALUE2.value_name, 'GI_MARSHALLING_TESTS_GENUM_VALUE2')
1181 self.assertEqual(GIMarshallingTests.GEnum.VALUE3.value_name, 'GI_MARSHALLING_TESTS_GENUM_VALUE3')
1183 def test_genum_in(self):
1184 GIMarshallingTests.genum_in(GIMarshallingTests.GEnum.VALUE3)
1185 GIMarshallingTests.genum_in(42)
1187 self.assertRaises(TypeError, GIMarshallingTests.genum_in, 43)
1188 self.assertRaises(TypeError, GIMarshallingTests.genum_in, 'GIMarshallingTests.GEnum.VALUE3')
1190 def test_genum_out(self):
1191 genum = GIMarshallingTests.genum_out()
1192 self.assertTrue(isinstance(genum, GIMarshallingTests.GEnum))
1193 self.assertEqual(genum, GIMarshallingTests.GEnum.VALUE3)
1195 def test_genum_inout(self):
1196 genum = GIMarshallingTests.genum_inout(GIMarshallingTests.GEnum.VALUE3)
1197 self.assertTrue(isinstance(genum, GIMarshallingTests.GEnum))
1198 self.assertEqual(genum, GIMarshallingTests.GEnum.VALUE1)
1201 class TestGFlags(unittest.TestCase):
1203 def test_flags(self):
1204 self.assertTrue(issubclass(GIMarshallingTests.Flags, GObject.GFlags))
1205 self.assertTrue(isinstance(GIMarshallingTests.Flags.VALUE1, GIMarshallingTests.Flags))
1206 self.assertTrue(isinstance(GIMarshallingTests.Flags.VALUE2, GIMarshallingTests.Flags))
1207 self.assertTrue(isinstance(GIMarshallingTests.Flags.VALUE3, GIMarshallingTests.Flags))
1208 # __or__() operation should still return an instance, not an int.
1209 self.assertTrue(isinstance(GIMarshallingTests.Flags.VALUE1 | GIMarshallingTests.Flags.VALUE2,
1210 GIMarshallingTests.Flags))
1211 self.assertEqual(1 << 1, GIMarshallingTests.Flags.VALUE2)
1213 def test_value_nick_and_name(self):
1214 self.assertEqual(GIMarshallingTests.Flags.VALUE1.first_value_nick, 'value1')
1215 self.assertEqual(GIMarshallingTests.Flags.VALUE2.first_value_nick, 'value2')
1216 self.assertEqual(GIMarshallingTests.Flags.VALUE3.first_value_nick, 'value3')
1218 self.assertEqual(GIMarshallingTests.Flags.VALUE1.first_value_name, 'GI_MARSHALLING_TESTS_FLAGS_VALUE1')
1219 self.assertEqual(GIMarshallingTests.Flags.VALUE2.first_value_name, 'GI_MARSHALLING_TESTS_FLAGS_VALUE2')
1220 self.assertEqual(GIMarshallingTests.Flags.VALUE3.first_value_name, 'GI_MARSHALLING_TESTS_FLAGS_VALUE3')
1222 def test_flags_in(self):
1223 GIMarshallingTests.flags_in(GIMarshallingTests.Flags.VALUE2)
1224 # result of __or__() operation should still be valid instance, not an int.
1225 GIMarshallingTests.flags_in(GIMarshallingTests.Flags.VALUE2 | GIMarshallingTests.Flags.VALUE2)
1226 GIMarshallingTests.flags_in_zero(Number(0))
1228 self.assertRaises(TypeError, GIMarshallingTests.flags_in, 1 << 1)
1229 self.assertRaises(TypeError, GIMarshallingTests.flags_in, 'GIMarshallingTests.Flags.VALUE2')
1231 def test_flags_out(self):
1232 flags = GIMarshallingTests.flags_out()
1233 self.assertTrue(isinstance(flags, GIMarshallingTests.Flags))
1234 self.assertEqual(flags, GIMarshallingTests.Flags.VALUE2)
1236 def test_flags_inout(self):
1237 flags = GIMarshallingTests.flags_inout(GIMarshallingTests.Flags.VALUE2)
1238 self.assertTrue(isinstance(flags, GIMarshallingTests.Flags))
1239 self.assertEqual(flags, GIMarshallingTests.Flags.VALUE1)
1242 class TestNoTypeFlags(unittest.TestCase):
1244 def test_flags(self):
1245 self.assertTrue(issubclass(GIMarshallingTests.NoTypeFlags, GObject.GFlags))
1246 self.assertTrue(isinstance(GIMarshallingTests.NoTypeFlags.VALUE1, GIMarshallingTests.NoTypeFlags))
1247 self.assertTrue(isinstance(GIMarshallingTests.NoTypeFlags.VALUE2, GIMarshallingTests.NoTypeFlags))
1248 self.assertTrue(isinstance(GIMarshallingTests.NoTypeFlags.VALUE3, GIMarshallingTests.NoTypeFlags))
1249 # __or__() operation should still return an instance, not an int.
1250 self.assertTrue(isinstance(GIMarshallingTests.NoTypeFlags.VALUE1 | GIMarshallingTests.NoTypeFlags.VALUE2,
1251 GIMarshallingTests.NoTypeFlags))
1252 self.assertEqual(1 << 1, GIMarshallingTests.NoTypeFlags.VALUE2)
1254 def test_value_nick_and_name(self):
1255 self.assertEqual(GIMarshallingTests.NoTypeFlags.VALUE1.first_value_nick, 'value1')
1256 self.assertEqual(GIMarshallingTests.NoTypeFlags.VALUE2.first_value_nick, 'value2')
1257 self.assertEqual(GIMarshallingTests.NoTypeFlags.VALUE3.first_value_nick, 'value3')
1259 self.assertEqual(GIMarshallingTests.NoTypeFlags.VALUE1.first_value_name, 'GI_MARSHALLING_TESTS_NO_TYPE_FLAGS_VALUE1')
1260 self.assertEqual(GIMarshallingTests.NoTypeFlags.VALUE2.first_value_name, 'GI_MARSHALLING_TESTS_NO_TYPE_FLAGS_VALUE2')
1261 self.assertEqual(GIMarshallingTests.NoTypeFlags.VALUE3.first_value_name, 'GI_MARSHALLING_TESTS_NO_TYPE_FLAGS_VALUE3')
1263 def test_flags_in(self):
1264 GIMarshallingTests.no_type_flags_in(GIMarshallingTests.NoTypeFlags.VALUE2)
1265 GIMarshallingTests.no_type_flags_in(GIMarshallingTests.NoTypeFlags.VALUE2 | GIMarshallingTests.NoTypeFlags.VALUE2)
1266 GIMarshallingTests.no_type_flags_in_zero(Number(0))
1268 self.assertRaises(TypeError, GIMarshallingTests.no_type_flags_in, 1 << 1)
1269 self.assertRaises(TypeError, GIMarshallingTests.no_type_flags_in, 'GIMarshallingTests.NoTypeFlags.VALUE2')
1271 def test_flags_out(self):
1272 flags = GIMarshallingTests.no_type_flags_out()
1273 self.assertTrue(isinstance(flags, GIMarshallingTests.NoTypeFlags))
1274 self.assertEqual(flags, GIMarshallingTests.NoTypeFlags.VALUE2)
1276 def test_flags_inout(self):
1277 flags = GIMarshallingTests.no_type_flags_inout(GIMarshallingTests.NoTypeFlags.VALUE2)
1278 self.assertTrue(isinstance(flags, GIMarshallingTests.NoTypeFlags))
1279 self.assertEqual(flags, GIMarshallingTests.NoTypeFlags.VALUE1)
1282 class TestStructure(unittest.TestCase):
1284 def test_simple_struct(self):
1285 self.assertTrue(issubclass(GIMarshallingTests.SimpleStruct, GObject.GPointer))
1287 struct = GIMarshallingTests.SimpleStruct()
1288 self.assertTrue(isinstance(struct, GIMarshallingTests.SimpleStruct))
1290 self.assertEqual(0, struct.long_)
1291 self.assertEqual(0, struct.int8)
1296 self.assertEqual(6, struct.long_)
1297 self.assertEqual(7, struct.int8)
1301 def test_nested_struct(self):
1302 struct = GIMarshallingTests.NestedStruct()
1304 self.assertTrue(isinstance(struct.simple_struct, GIMarshallingTests.SimpleStruct))
1306 struct.simple_struct.long_ = 42
1307 self.assertEqual(42, struct.simple_struct.long_)
1311 def test_not_simple_struct(self):
1312 struct = GIMarshallingTests.NotSimpleStruct()
1313 self.assertEqual(None, struct.pointer)
1315 def test_simple_struct_return(self):
1316 struct = GIMarshallingTests.simple_struct_returnv()
1318 self.assertTrue(isinstance(struct, GIMarshallingTests.SimpleStruct))
1319 self.assertEqual(6, struct.long_)
1320 self.assertEqual(7, struct.int8)
1324 def test_simple_struct_in(self):
1325 struct = GIMarshallingTests.SimpleStruct()
1329 GIMarshallingTests.SimpleStruct.inv(struct)
1333 struct = GIMarshallingTests.NestedStruct()
1335 self.assertRaises(TypeError, GIMarshallingTests.SimpleStruct.inv, struct)
1339 self.assertRaises(TypeError, GIMarshallingTests.SimpleStruct.inv, None)
1341 def test_simple_struct_method(self):
1342 struct = GIMarshallingTests.SimpleStruct()
1350 self.assertRaises(TypeError, GIMarshallingTests.SimpleStruct.method)
1352 def test_pointer_struct(self):
1353 self.assertTrue(issubclass(GIMarshallingTests.PointerStruct, GObject.GPointer))
1355 struct = GIMarshallingTests.PointerStruct()
1356 self.assertTrue(isinstance(struct, GIMarshallingTests.PointerStruct))
1360 def test_pointer_struct_return(self):
1361 struct = GIMarshallingTests.pointer_struct_returnv()
1363 self.assertTrue(isinstance(struct, GIMarshallingTests.PointerStruct))
1364 self.assertEqual(42, struct.long_)
1368 def test_pointer_struct_in(self):
1369 struct = GIMarshallingTests.PointerStruct()
1376 def test_boxed_struct(self):
1377 self.assertTrue(issubclass(GIMarshallingTests.BoxedStruct, GObject.GBoxed))
1379 struct = GIMarshallingTests.BoxedStruct()
1380 self.assertTrue(isinstance(struct, GIMarshallingTests.BoxedStruct))
1382 self.assertEqual(0, struct.long_)
1383 self.assertEqual([], struct.g_strv)
1387 def test_boxed_struct_new(self):
1388 struct = GIMarshallingTests.BoxedStruct.new()
1389 self.assertTrue(isinstance(struct, GIMarshallingTests.BoxedStruct))
1393 def test_boxed_struct_copy(self):
1394 struct = GIMarshallingTests.BoxedStruct()
1396 new_struct = struct.copy()
1397 self.assertTrue(isinstance(new_struct, GIMarshallingTests.BoxedStruct))
1402 def test_boxed_struct_return(self):
1403 struct = GIMarshallingTests.boxed_struct_returnv()
1405 self.assertTrue(isinstance(struct, GIMarshallingTests.BoxedStruct))
1406 self.assertEqual(42, struct.long_)
1407 self.assertEqual(['0', '1', '2'], struct.g_strv)
1411 def test_boxed_struct_in(self):
1412 struct = GIMarshallingTests.BoxedStruct()
1419 def test_boxed_struct_out(self):
1420 struct = GIMarshallingTests.boxed_struct_out()
1422 self.assertTrue(isinstance(struct, GIMarshallingTests.BoxedStruct))
1423 self.assertEqual(42, struct.long_)
1427 def test_boxed_struct_inout(self):
1428 in_struct = GIMarshallingTests.BoxedStruct()
1429 in_struct.long_ = 42
1431 out_struct = GIMarshallingTests.boxed_struct_inout(in_struct)
1433 self.assertTrue(isinstance(out_struct, GIMarshallingTests.BoxedStruct))
1434 self.assertEqual(0, out_struct.long_)
1439 def test_union(self):
1440 union = GIMarshallingTests.Union()
1442 self.assertTrue(isinstance(union, GIMarshallingTests.Union))
1444 new_union = union.copy()
1445 self.assertTrue(isinstance(new_union, GIMarshallingTests.Union))
1450 def test_union_return(self):
1451 union = GIMarshallingTests.union_returnv()
1453 self.assertTrue(isinstance(union, GIMarshallingTests.Union))
1454 self.assertEqual(42, union.long_)
1458 def test_union_in(self):
1459 union = GIMarshallingTests.Union()
1466 def test_union_method(self):
1467 union = GIMarshallingTests.Union()
1474 self.assertRaises(TypeError, GIMarshallingTests.Union.method)
1477 class TestGObject(unittest.TestCase):
1479 def test_object(self):
1480 self.assertTrue(issubclass(GIMarshallingTests.Object, GObject.GObject))
1482 object_ = GIMarshallingTests.Object()
1483 self.assertTrue(isinstance(object_, GIMarshallingTests.Object))
1484 self.assertEqual(object_.__grefcount__, 1)
1486 def test_object_new(self):
1487 object_ = GIMarshallingTests.Object.new(42)
1488 self.assertTrue(isinstance(object_, GIMarshallingTests.Object))
1489 self.assertEqual(object_.__grefcount__, 1)
1491 def test_object_int(self):
1492 object_ = GIMarshallingTests.Object(int=42)
1493 self.assertEqual(object_.int_, 42)
1494 # FIXME: Don't work yet.
1496 # self.assertEqual(object_.int_, 0)
1498 def test_object_static_method(self):
1499 GIMarshallingTests.Object.static_method()
1501 def test_object_method(self):
1502 GIMarshallingTests.Object(int=42).method()
1503 self.assertRaises(TypeError, GIMarshallingTests.Object.method, GObject.GObject())
1504 self.assertRaises(TypeError, GIMarshallingTests.Object.method)
1506 def test_sub_object(self):
1507 self.assertTrue(issubclass(GIMarshallingTests.SubObject, GIMarshallingTests.Object))
1509 object_ = GIMarshallingTests.SubObject()
1510 self.assertTrue(isinstance(object_, GIMarshallingTests.SubObject))
1512 def test_sub_object_new(self):
1513 self.assertRaises(TypeError, GIMarshallingTests.SubObject.new, 42)
1515 def test_sub_object_static_method(self):
1516 object_ = GIMarshallingTests.SubObject()
1517 object_.static_method()
1519 def test_sub_object_method(self):
1520 object_ = GIMarshallingTests.SubObject(int=42)
1523 def test_sub_object_sub_method(self):
1524 object_ = GIMarshallingTests.SubObject()
1525 object_.sub_method()
1527 def test_sub_object_overwritten_method(self):
1528 object_ = GIMarshallingTests.SubObject()
1529 object_.overwritten_method()
1531 self.assertRaises(TypeError, GIMarshallingTests.SubObject.overwritten_method, GIMarshallingTests.Object())
1533 def test_sub_object_int(self):
1534 object_ = GIMarshallingTests.SubObject()
1535 self.assertEqual(object_.int_, 0)
1536 # FIXME: Don't work yet.
1538 # self.assertEqual(object_.int_, 42)
1540 def test_object_none_return(self):
1541 object_ = GIMarshallingTests.Object.none_return()
1542 self.assertTrue(isinstance(object_, GIMarshallingTests.Object))
1543 self.assertEqual(object_.__grefcount__, 2)
1545 def test_object_full_return(self):
1546 object_ = GIMarshallingTests.Object.full_return()
1547 self.assertTrue(isinstance(object_, GIMarshallingTests.Object))
1548 self.assertEqual(object_.__grefcount__, 1)
1550 def test_object_none_in(self):
1551 object_ = GIMarshallingTests.Object(int=42)
1552 GIMarshallingTests.Object.none_in(object_)
1553 self.assertEqual(object_.__grefcount__, 1)
1555 object_ = GIMarshallingTests.SubObject(int=42)
1556 GIMarshallingTests.Object.none_in(object_)
1558 object_ = GObject.GObject()
1559 self.assertRaises(TypeError, GIMarshallingTests.Object.none_in, object_)
1561 self.assertRaises(TypeError, GIMarshallingTests.Object.none_in, None)
1563 def test_object_none_out(self):
1564 object_ = GIMarshallingTests.Object.none_out()
1565 self.assertTrue(isinstance(object_, GIMarshallingTests.Object))
1566 self.assertEqual(object_.__grefcount__, 2)
1568 new_object = GIMarshallingTests.Object.none_out()
1569 self.assertTrue(new_object is object_)
1571 def test_object_full_out(self):
1572 object_ = GIMarshallingTests.Object.full_out()
1573 self.assertTrue(isinstance(object_, GIMarshallingTests.Object))
1574 self.assertEqual(object_.__grefcount__, 1)
1576 def test_object_none_inout(self):
1577 object_ = GIMarshallingTests.Object(int=42)
1578 new_object = GIMarshallingTests.Object.none_inout(object_)
1580 self.assertTrue(isinstance(new_object, GIMarshallingTests.Object))
1582 self.assertFalse(object_ is new_object)
1584 self.assertEqual(object_.__grefcount__, 1)
1585 self.assertEqual(new_object.__grefcount__, 2)
1587 new_new_object = GIMarshallingTests.Object.none_inout(object_)
1588 self.assertTrue(new_new_object is new_object)
1590 GIMarshallingTests.Object.none_inout(GIMarshallingTests.SubObject(int=42))
1592 def test_object_full_inout(self):
1593 object_ = GIMarshallingTests.Object(int=42)
1594 new_object = GIMarshallingTests.Object.full_inout(object_)
1596 self.assertTrue(isinstance(new_object, GIMarshallingTests.Object))
1598 self.assertFalse(object_ is new_object)
1600 self.assertEqual(object_.__grefcount__, 2)
1601 self.assertEqual(new_object.__grefcount__, 1)
1603 # FIXME: Doesn't actually return the same object.
1604 # def test_object_inout_same(self):
1605 # object_ = GIMarshallingTests.Object()
1606 # new_object = GIMarshallingTests.object_full_inout(object_)
1607 # self.assertTrue(object_ is new_object)
1608 # self.assertEqual(object_.__grefcount__, 1)
1611 class TestPythonGObject(unittest.TestCase):
1613 class Object(GIMarshallingTests.Object):
1614 def __init__(self, int):
1615 GIMarshallingTests.Object.__init__(self)
1619 # Don't call super, which asserts that self.int == 42.
1622 def do_method_int8_in(self, int8):
1625 def do_method_int8_out(self):
1628 def do_method_with_default_implementation(self, int8):
1629 GIMarshallingTests.Object.do_method_with_default_implementation(self, int8)
1630 self.props.int += int8
1632 def do_vfunc_return_value_only(self):
1635 def do_vfunc_one_out_parameter(self):
1638 def do_vfunc_multiple_out_parameters(self):
1639 return (42.42, 3.14)
1641 def do_vfunc_return_value_and_one_out_parameter(self):
1644 def do_vfunc_return_value_and_multiple_out_parameters(self):
1647 def do_vfunc_caller_allocated_out_parameter(self):
1650 class SubObject(GIMarshallingTests.SubObject):
1651 def __init__(self, int):
1652 GIMarshallingTests.SubObject.__init__(self)
1655 def do_method_with_default_implementation(self, int8):
1658 class Interface3Impl(GObject.Object, GIMarshallingTests.Interface3):
1660 GObject.Object.__init__(self)
1661 self.variants = None
1662 self.n_variants = None
1664 def do_test_variant_array_in(self, variants, n_variants):
1665 self.variants = variants
1666 self.n_variants = n_variants
1668 def test_object(self):
1669 self.assertTrue(issubclass(self.Object, GIMarshallingTests.Object))
1671 object_ = self.Object(int=42)
1672 self.assertTrue(isinstance(object_, self.Object))
1674 def test_object_method(self):
1675 self.Object(int=0).method()
1677 def test_object_vfuncs(self):
1678 object_ = self.Object(int=42)
1679 object_.method_int8_in(84)
1680 self.assertEqual(object_.val, 84)
1681 self.assertEqual(object_.method_int8_out(), 42)
1683 object_.method_with_default_implementation(42)
1684 self.assertEqual(object_.props.int, 84)
1686 self.assertEqual(object_.vfunc_return_value_only(), 4242)
1687 self.assertAlmostEqual(object_.vfunc_one_out_parameter(), 42.42, places=5)
1689 (a, b) = object_.vfunc_multiple_out_parameters()
1690 self.assertAlmostEqual(a, 42.42, places=5)
1691 self.assertAlmostEqual(b, 3.14, places=5)
1693 self.assertEqual(object_.vfunc_return_value_and_one_out_parameter(), (5, 42))
1694 self.assertEqual(object_.vfunc_return_value_and_multiple_out_parameters(), (5, 42, 99))
1696 self.assertEqual(object_.vfunc_caller_allocated_out_parameter(), 'hello')
1698 class ObjectWithoutVFunc(GIMarshallingTests.Object):
1699 def __init__(self, int):
1700 GIMarshallingTests.Object.__init__(self)
1702 object_ = ObjectWithoutVFunc(int=42)
1703 object_.method_with_default_implementation(84)
1704 self.assertEqual(object_.props.int, 84)
1706 def test_subobject_parent_vfunc(self):
1707 object_ = self.SubObject(int=81)
1708 object_.method_with_default_implementation(87)
1709 self.assertEqual(object_.val, 87)
1711 def test_dynamic_module(self):
1712 from gi.module import DynamicGObjectModule
1713 self.assertTrue(isinstance(GObject, DynamicGObjectModule))
1714 # compare the same enum from both the pygobject attrs and gi GObject attrs
1715 self.assertEqual(GObject.SIGNAL_ACTION, GObject.SignalFlags.ACTION)
1716 # compare a static gobject attr with a dynamic GObject attr
1718 self.assertEqual(GObject.GObject, gi._gobject.GObject)
1720 def test_subobject_non_vfunc_do_method(self):
1721 class PythonObjectWithNonVFuncDoMethod:
1722 def do_not_a_vfunc(self):
1725 class ObjectOverrideNonVFuncDoMethod(GIMarshallingTests.Object, PythonObjectWithNonVFuncDoMethod):
1726 def do_not_a_vfunc(self):
1727 value = super(ObjectOverrideNonVFuncDoMethod, self).do_not_a_vfunc()
1730 object_ = ObjectOverrideNonVFuncDoMethod()
1731 self.assertEqual(18, object_.do_not_a_vfunc())
1733 def test_native_function_not_set_in_subclass_dict(self):
1734 # Previously, GI was setting virtual functions on the class as well
1735 # as any *native* class that subclasses it. Here we check that it is only
1736 # set on the class that the method is originally from.
1737 self.assertTrue('do_method_with_default_implementation' in GIMarshallingTests.Object.__dict__)
1738 self.assertTrue('do_method_with_default_implementation' not in GIMarshallingTests.SubObject.__dict__)
1740 def test_subobject_with_interface_and_non_vfunc_do_method(self):
1741 # There was a bug for searching for vfuncs in interfaces. It was
1742 # triggered by having a do_* method that wasn't overriding
1743 # a native vfunc, as well as inheriting from an interface.
1744 class GObjectSubclassWithInterface(GObject.GObject, GIMarshallingTests.Interface):
1745 def do_method_not_a_vfunc(self):
1748 def test_subsubobject(self):
1749 class SubSubSubObject(GIMarshallingTests.SubSubObject):
1750 def do_method_deep_hierarchy(self, num):
1751 self.props.int = num * 2
1753 sub_sub_sub_object = SubSubSubObject()
1754 GIMarshallingTests.SubSubObject.do_method_deep_hierarchy(sub_sub_sub_object, 5)
1755 self.assertEqual(sub_sub_sub_object.props.int, 5)
1757 def test_interface3impl(self):
1758 iface3 = self.Interface3Impl()
1759 variants = [GLib.Variant('i', 27), GLib.Variant('s', 'Hello')]
1760 iface3.test_variant_array_in(variants)
1761 self.assertEqual(iface3.n_variants, 2)
1762 self.assertEqual(iface3.variants[0].unpack(), 27)
1763 self.assertEqual(iface3.variants[1].unpack(), 'Hello')
1765 def test_python_subsubobject_vfunc(self):
1766 class PySubObject(GIMarshallingTests.Object):
1768 GIMarshallingTests.Object.__init__(self)
1769 self.sub_method_int8_called = 0
1771 def do_method_int8_in(self, int8):
1772 self.sub_method_int8_called += 1
1774 class PySubSubObject(PySubObject):
1776 PySubObject.__init__(self)
1777 self.subsub_method_int8_called = 0
1779 def do_method_int8_in(self, int8):
1780 self.subsub_method_int8_called += 1
1783 so.method_int8_in(1)
1784 self.assertEqual(so.sub_method_int8_called, 1)
1786 # it should call the method on the SubSub object only
1787 sso = PySubSubObject()
1788 sso.method_int8_in(1)
1789 self.assertEqual(sso.subsub_method_int8_called, 1)
1790 self.assertEqual(sso.sub_method_int8_called, 0)
1792 def test_callback_in_vfunc(self):
1793 class SubObject(GIMarshallingTests.Object):
1795 GObject.GObject.__init__(self)
1798 def do_vfunc_with_callback(self, callback):
1799 self.worked = callback(42) == 42
1801 _object = SubObject()
1802 _object.call_vfunc_with_callback()
1803 self.assertTrue(_object.worked)
1804 _object.worked = False
1805 _object.call_vfunc_with_callback()
1806 self.assertTrue(_object.worked)
1809 class TestMultiOutputArgs(unittest.TestCase):
1811 def test_int_out_out(self):
1812 self.assertEqual((6, 7), GIMarshallingTests.int_out_out())
1814 def test_int_return_out(self):
1815 self.assertEqual((6, 7), GIMarshallingTests.int_return_out())
1818 class TestGErrorException(unittest.TestCase):
1819 def test_gerror_exception(self):
1820 self.assertRaises(GObject.GError, GIMarshallingTests.gerror)
1822 GIMarshallingTests.gerror()
1824 etype, e = sys.exc_info()[:2]
1825 self.assertEqual(e.domain, GIMarshallingTests.CONSTANT_GERROR_DOMAIN)
1826 self.assertEqual(e.code, GIMarshallingTests.CONSTANT_GERROR_CODE)
1827 self.assertEqual(e.message, GIMarshallingTests.CONSTANT_GERROR_MESSAGE)
1833 class TestInterfaces(unittest.TestCase):
1835 class TestInterfaceImpl(GObject.GObject, GIMarshallingTests.Interface):
1837 GObject.GObject.__init__(self)
1840 def do_test_int8_in(self, int8):
1844 self.instance = self.TestInterfaceImpl()
1846 def test_wrapper(self):
1847 self.assertTrue(issubclass(GIMarshallingTests.Interface, GObject.GInterface))
1848 self.assertEqual(GIMarshallingTests.Interface.__gtype__.name, 'GIMarshallingTestsInterface')
1849 self.assertRaises(NotImplementedError, GIMarshallingTests.Interface)
1851 def test_implementation(self):
1852 self.assertTrue(issubclass(self.TestInterfaceImpl, GIMarshallingTests.Interface))
1853 self.assertTrue(isinstance(self.instance, GIMarshallingTests.Interface))
1855 def test_int8_int(self):
1856 GIMarshallingTests.test_interface_test_int8_in(self.instance, 42)
1857 self.assertEqual(self.instance.val, 42)
1859 def test_subclass(self):
1860 class TestInterfaceImplA(self.TestInterfaceImpl):
1863 class TestInterfaceImplB(TestInterfaceImplA):
1866 instance = TestInterfaceImplA()
1867 GIMarshallingTests.test_interface_test_int8_in(instance, 42)
1868 self.assertEqual(instance.val, 42)
1871 # there was a problem with Python bailing out because of
1872 # http://en.wikipedia.org/wiki/Diamond_problem with interfaces,
1873 # which shouldn't really be a problem.
1875 class TestInterfaceImpl(GObject.GObject, GIMarshallingTests.Interface):
1878 class TestInterfaceImpl2(GIMarshallingTests.Interface,
1882 class TestInterfaceImpl3(self.TestInterfaceImpl,
1883 GIMarshallingTests.Interface2):
1886 def test_type_mismatch(self):
1887 obj = GIMarshallingTests.Object()
1889 # wrong type for first argument: interface
1890 enum = Gio.File.new_for_path('.').enumerate_children(
1891 '', Gio.FileQueryInfoFlags.NONE, None)
1894 self.fail('call with wrong type argument unexpectedly succeeded')
1895 except TypeError as e:
1896 # should have argument name
1897 self.assertTrue('cancellable' in str(e), e)
1898 # should have expected type
1899 self.assertTrue('xpected Gio.Cancellable' in str(e), e)
1900 # should have actual type
1901 self.assertTrue('GIMarshallingTests.Object' in str(e), e)
1903 # wrong type for self argument: interface
1905 Gio.FileEnumerator.next_file(obj, None)
1906 self.fail('call with wrong type argument unexpectedly succeeded')
1907 except TypeError as e:
1908 if sys.version_info < (3, 0):
1909 self.assertTrue('FileEnumerator' in str(e), e)
1910 self.assertTrue('Object' in str(e), e)
1912 # should have argument name
1913 self.assertTrue('self' in str(e), e)
1914 # should have expected type
1915 self.assertTrue('xpected Gio.FileEnumerator' in str(e), e)
1916 # should have actual type
1917 self.assertTrue('GIMarshallingTests.Object' in str(e), e)
1919 # wrong type for first argument: GObject
1920 var = GLib.Variant('s', 'mystring')
1921 action = Gio.SimpleAction.new('foo', var.get_type())
1923 action.activate(obj)
1924 self.fail('call with wrong type argument unexpectedly succeeded')
1925 except TypeError as e:
1926 # should have argument name
1927 self.assertTrue('parameter' in str(e), e)
1928 # should have expected type
1929 self.assertTrue('xpected GLib.Variant' in str(e), e)
1930 # should have actual type
1931 self.assertTrue('GIMarshallingTests.Object' in str(e), e)
1933 # wrong type for self argument: GObject
1935 Gio.SimpleAction.activate(obj, obj)
1936 self.fail('call with wrong type argument unexpectedly succeeded')
1937 except TypeError as e:
1938 if sys.version_info < (3, 0):
1939 self.assertTrue('SimpleAction' in str(e), e)
1940 self.assertTrue('Object' in str(e), e)
1942 # should have argument name
1943 self.assertTrue('self' in str(e), e)
1944 # should have expected type
1945 self.assertTrue('xpected Gio.Action' in str(e), e)
1946 # should have actual type
1947 self.assertTrue('GIMarshallingTests.Object' in str(e), e)
1950 class TestInterfaceClash(unittest.TestCase):
1952 def test_clash(self):
1954 class TestClash(GObject.GObject, GIMarshallingTests.Interface, GIMarshallingTests.Interface2):
1955 def do_test_int8_in(self, int8):
1959 self.assertRaises(TypeError, create_clash)
1962 class TestOverrides(unittest.TestCase):
1964 def test_constant(self):
1965 self.assertEqual(GIMarshallingTests.OVERRIDES_CONSTANT, 7)
1967 def test_struct(self):
1968 # Test that the constructor has been overridden.
1969 struct = GIMarshallingTests.OverridesStruct(42)
1971 self.assertTrue(isinstance(struct, GIMarshallingTests.OverridesStruct))
1973 # Test that the method has been overridden.
1974 self.assertEqual(6, struct.method())
1978 # Test that the overrides wrapper has been registered.
1979 struct = GIMarshallingTests.overrides_struct_returnv()
1981 self.assertTrue(isinstance(struct, GIMarshallingTests.OverridesStruct))
1985 def test_object(self):
1986 # Test that the constructor has been overridden.
1987 object_ = GIMarshallingTests.OverridesObject(42)
1989 self.assertTrue(isinstance(object_, GIMarshallingTests.OverridesObject))
1991 # Test that the alternate constructor has been overridden.
1992 object_ = GIMarshallingTests.OverridesObject.new(42)
1994 self.assertTrue(isinstance(object_, GIMarshallingTests.OverridesObject))
1996 # Test that the method has been overridden.
1997 self.assertEqual(6, object_.method())
1999 # Test that the overrides wrapper has been registered.
2000 object_ = GIMarshallingTests.OverridesObject.returnv()
2002 self.assertTrue(isinstance(object_, GIMarshallingTests.OverridesObject))
2004 def test_module_name(self):
2005 self.assertEqual(GIMarshallingTests.OverridesStruct.__module__, 'gi.overrides.GIMarshallingTests')
2006 self.assertEqual(GObject.InitiallyUnowned.__module__, 'gi.repository.GObject')
2009 class TestDir(unittest.TestCase):
2010 def test_members_list(self):
2011 list = dir(GIMarshallingTests)
2012 self.assertTrue('OverridesStruct' in list)
2013 self.assertTrue('BoxedStruct' in list)
2014 self.assertTrue('OVERRIDES_CONSTANT' in list)
2015 self.assertTrue('GEnum' in list)
2016 self.assertTrue('int32_return_max' in list)
2018 def test_modules_list(self):
2019 import gi.repository
2020 list = dir(gi.repository)
2021 self.assertTrue('GIMarshallingTests' in list)
2023 # FIXME: test to see if a module which was not imported is in the list
2024 # we should be listing every typelib we find, not just the ones
2025 # which are imported
2027 # to test this I recommend we compile a fake module which
2028 # our tests would never import and check to see if it is
2031 # self.assertTrue('DoNotImportDummyTests' in list)
2034 class TestGErrorArrayInCrash(unittest.TestCase):
2035 # Previously there was a bug in invoke, in which C arrays were unwrapped
2036 # from inside GArrays to be passed to the C function. But when a GError was
2037 # set, invoke would attempt to free the C array as if it were a GArray.
2038 # This crash is only for C arrays. It does not happen for C functions which
2039 # take in GArrays. See https://bugzilla.gnome.org/show_bug.cgi?id=642708
2040 def test_gerror_array_in_crash(self):
2041 self.assertRaises(GObject.GError, GIMarshallingTests.gerror_array_in, [1, 2, 3])
2044 class TestGErrorOut(unittest.TestCase):
2045 # See https://bugzilla.gnome.org/show_bug.cgi?id=666098
2046 def test_gerror_out(self):
2047 error, debug = GIMarshallingTests.gerror_out()
2049 self.assertIsInstance(error, GObject.GError)
2050 self.assertEqual(error.domain, GIMarshallingTests.CONSTANT_GERROR_DOMAIN)
2051 self.assertEqual(error.code, GIMarshallingTests.CONSTANT_GERROR_CODE)
2052 self.assertEqual(error.message, GIMarshallingTests.CONSTANT_GERROR_MESSAGE)
2053 self.assertEqual(debug, GIMarshallingTests.CONSTANT_GERROR_DEBUG_MESSAGE)
2056 class TestGErrorOutTransferNone(unittest.TestCase):
2057 # See https://bugzilla.gnome.org/show_bug.cgi?id=666098
2058 def test_gerror_out_transfer_none(self):
2059 error, debug = GIMarshallingTests.gerror_out_transfer_none()
2061 self.assertIsInstance(error, GObject.GError)
2062 self.assertEqual(error.domain, GIMarshallingTests.CONSTANT_GERROR_DOMAIN)
2063 self.assertEqual(error.code, GIMarshallingTests.CONSTANT_GERROR_CODE)
2064 self.assertEqual(error.message, GIMarshallingTests.CONSTANT_GERROR_MESSAGE)
2065 self.assertEqual(GIMarshallingTests.CONSTANT_GERROR_DEBUG_MESSAGE, debug)
2068 class TestGErrorReturn(unittest.TestCase):
2069 # See https://bugzilla.gnome.org/show_bug.cgi?id=666098
2070 def test_return_gerror(self):
2071 error = GIMarshallingTests.gerror_return()
2073 self.assertIsInstance(error, GObject.GError)
2074 self.assertEqual(error.domain, GIMarshallingTests.CONSTANT_GERROR_DOMAIN)
2075 self.assertEqual(error.code, GIMarshallingTests.CONSTANT_GERROR_CODE)
2076 self.assertEqual(error.message, GIMarshallingTests.CONSTANT_GERROR_MESSAGE)
2079 class TestParamSpec(unittest.TestCase):
2080 def test_param_spec_return(self):
2081 obj = GIMarshallingTests.param_spec_return()
2082 self.assertEqual(obj.name, 'test-param')
2083 self.assertEqual(obj.nick, 'test')
2084 self.assertEqual(obj.value_type, GObject.TYPE_STRING)
2086 def test_param_spec_out(self):
2087 obj = GIMarshallingTests.param_spec_out()
2088 self.assertEqual(obj.name, 'test-param')
2089 self.assertEqual(obj.nick, 'test')
2090 self.assertEqual(obj.value_type, GObject.TYPE_STRING)
2093 class TestKeywordArgs(unittest.TestCase):
2095 def test_calling(self):
2096 kw_func = GIMarshallingTests.int_three_in_three_out
2098 self.assertEqual(kw_func(1, 2, 3), (1, 2, 3))
2099 self.assertEqual(kw_func(**{'a': 4, 'b': 5, 'c': 6}), (4, 5, 6))
2100 self.assertEqual(kw_func(1, **{'b': 7, 'c': 8}), (1, 7, 8))
2101 self.assertEqual(kw_func(1, 7, **{'c': 8}), (1, 7, 8))
2102 self.assertEqual(kw_func(1, c=8, **{'b': 7}), (1, 7, 8))
2103 self.assertEqual(kw_func(2, c=4, b=3), (2, 3, 4))
2104 self.assertEqual(kw_func(a=2, c=4, b=3), (2, 3, 4))
2106 def assertRaisesMessage(self, exception, message, func, *args, **kwargs):
2108 func(*args, **kwargs)
2110 (e_type, e) = sys.exc_info()[:2]
2111 if message is not None:
2112 self.assertEqual(str(e), message)
2116 msg = "%s() did not raise %s" % (func.__name__, exception.__name__)
2117 raise AssertionError(msg)
2119 def test_type_errors(self):
2121 self.assertRaisesMessage(TypeError, "int_three_in_three_out() takes exactly 3 arguments (0 given)",
2122 GIMarshallingTests.int_three_in_three_out)
2123 self.assertRaisesMessage(TypeError, "int_three_in_three_out() takes exactly 3 arguments (1 given)",
2124 GIMarshallingTests.int_three_in_three_out, 1)
2125 self.assertRaisesMessage(TypeError, "int_three_in_three_out() takes exactly 3 arguments (0 given)",
2126 GIMarshallingTests.int_three_in_three_out, *())
2127 self.assertRaisesMessage(TypeError, "int_three_in_three_out() takes exactly 3 arguments (0 given)",
2128 GIMarshallingTests.int_three_in_three_out, *(), **{})
2129 self.assertRaisesMessage(TypeError, "int_three_in_three_out() takes exactly 3 non-keyword arguments (0 given)",
2130 GIMarshallingTests.int_three_in_three_out, *(), **{'c': 4})
2132 # test too many args
2133 self.assertRaisesMessage(TypeError, "int_three_in_three_out() takes exactly 3 arguments (4 given)",
2134 GIMarshallingTests.int_three_in_three_out, *(1, 2, 3, 4))
2135 self.assertRaisesMessage(TypeError, "int_three_in_three_out() takes exactly 3 non-keyword arguments (4 given)",
2136 GIMarshallingTests.int_three_in_three_out, *(1, 2, 3, 4), c=6)
2138 # test too many keyword args
2139 self.assertRaisesMessage(TypeError, "int_three_in_three_out() got multiple values for keyword argument 'a'",
2140 GIMarshallingTests.int_three_in_three_out, 1, 2, 3, **{'a': 4, 'b': 5})
2141 self.assertRaisesMessage(TypeError, "int_three_in_three_out() got an unexpected keyword argument 'd'",
2142 GIMarshallingTests.int_three_in_three_out, d=4)
2143 self.assertRaisesMessage(TypeError, "int_three_in_three_out() got an unexpected keyword argument 'e'",
2144 GIMarshallingTests.int_three_in_three_out, **{'e': 2})
2146 def test_kwargs_are_not_modified(self):
2149 GIMarshallingTests.int_three_in_three_out(1, c=4, **d)
2150 self.assertEqual(d, d2)
2153 class TestPropertiesObject(unittest.TestCase):
2156 self.obj = GIMarshallingTests.PropertiesObject()
2158 def test_boolean(self):
2159 self.assertEqual(self.obj.props.some_boolean, False)
2160 self.obj.props.some_boolean = True
2161 self.assertEqual(self.obj.props.some_boolean, True)
2163 obj = GIMarshallingTests.PropertiesObject(some_boolean=True)
2164 self.assertEqual(obj.props.some_boolean, True)
2166 @unittest.expectedFailure
2167 def test_char(self):
2168 # gobject-introspection thinks it has a guint8 type tag, which is
2169 # wrong; this will raise an assertion critical which we need to ignore
2170 old_mask = GLib.log_set_always_fatal(
2171 GLib.LogLevelFlags.LEVEL_WARNING | GLib.LogLevelFlags.LEVEL_ERROR)
2172 self.assertEqual(self.obj.props.some_char, 0)
2173 self.obj.props.some_char = GObject.G_MAXINT8
2174 self.assertEqual(self.obj.props.some_char, GObject.G_MAXINT8)
2176 GLib.log_set_always_fatal(old_mask)
2178 obj = GIMarshallingTests.PropertiesObject(some_char=-42)
2179 self.assertEqual(obj.props.some_char, -42)
2181 def test_uchar(self):
2182 self.assertEqual(self.obj.props.some_uchar, 0)
2183 self.obj.props.some_uchar = GObject.G_MAXUINT8
2184 self.assertEqual(self.obj.props.some_uchar, GObject.G_MAXUINT8)
2186 obj = GIMarshallingTests.PropertiesObject(some_uchar=42)
2187 self.assertEqual(obj.props.some_uchar, 42)
2190 self.assertEqual(self.obj.props.some_int, 0)
2191 self.obj.props.some_int = GObject.G_MAXINT
2192 self.assertEqual(self.obj.props.some_int, GObject.G_MAXINT)
2194 obj = GIMarshallingTests.PropertiesObject(some_int=-42)
2195 self.assertEqual(obj.props.some_int, -42)
2197 self.assertRaises(TypeError, setattr, self.obj.props, 'some_int', 'foo')
2198 self.assertRaises(TypeError, setattr, self.obj.props, 'some_int', None)
2200 self.assertEqual(obj.props.some_int, -42)
2202 def test_uint(self):
2203 self.assertEqual(self.obj.props.some_uint, 0)
2204 self.obj.props.some_uint = GObject.G_MAXUINT
2205 self.assertEqual(self.obj.props.some_uint, GObject.G_MAXUINT)
2207 obj = GIMarshallingTests.PropertiesObject(some_uint=42)
2208 self.assertEqual(obj.props.some_uint, 42)
2210 self.assertRaises(TypeError, setattr, self.obj.props, 'some_uint', 'foo')
2211 self.assertRaises(TypeError, setattr, self.obj.props, 'some_uint', None)
2213 self.assertEqual(obj.props.some_uint, 42)
2215 def test_long(self):
2216 self.assertEqual(self.obj.props.some_long, 0)
2217 self.obj.props.some_long = GObject.G_MAXLONG
2218 self.assertEqual(self.obj.props.some_long, GObject.G_MAXLONG)
2220 obj = GIMarshallingTests.PropertiesObject(some_long=-42)
2221 self.assertEqual(obj.props.some_long, -42)
2223 self.assertRaises(TypeError, setattr, self.obj.props, 'some_long', 'foo')
2224 self.assertRaises(TypeError, setattr, self.obj.props, 'some_long', None)
2226 self.assertEqual(obj.props.some_long, -42)
2228 def test_ulong(self):
2229 self.assertEqual(self.obj.props.some_ulong, 0)
2230 self.obj.props.some_ulong = GObject.G_MAXULONG
2231 self.assertEqual(self.obj.props.some_ulong, GObject.G_MAXULONG)
2233 obj = GIMarshallingTests.PropertiesObject(some_ulong=42)
2234 self.assertEqual(obj.props.some_ulong, 42)
2236 self.assertRaises(TypeError, setattr, self.obj.props, 'some_ulong', 'foo')
2237 self.assertRaises(TypeError, setattr, self.obj.props, 'some_ulong', None)
2239 self.assertEqual(obj.props.some_ulong, 42)
2241 def test_int64(self):
2242 self.assertEqual(self.obj.props.some_int64, 0)
2243 self.obj.props.some_int64 = GObject.G_MAXINT64
2244 self.assertEqual(self.obj.props.some_int64, GObject.G_MAXINT64)
2246 obj = GIMarshallingTests.PropertiesObject(some_int64=-4200000000000000)
2247 self.assertEqual(obj.props.some_int64, -4200000000000000)
2249 def test_uint64(self):
2250 self.assertEqual(self.obj.props.some_uint64, 0)
2251 self.obj.props.some_uint64 = GObject.G_MAXUINT64
2252 self.assertEqual(self.obj.props.some_uint64, GObject.G_MAXUINT64)
2254 obj = GIMarshallingTests.PropertiesObject(some_uint64=4200000000000000)
2255 self.assertEqual(obj.props.some_uint64, 4200000000000000)
2257 def test_float(self):
2258 self.assertEqual(self.obj.props.some_float, 0)
2259 self.obj.props.some_float = GObject.G_MAXFLOAT
2260 self.assertEqual(self.obj.props.some_float, GObject.G_MAXFLOAT)
2262 obj = GIMarshallingTests.PropertiesObject(some_float=42.42)
2263 self.assertAlmostEqual(obj.props.some_float, 42.42, 4)
2265 obj = GIMarshallingTests.PropertiesObject(some_float=42)
2266 self.assertAlmostEqual(obj.props.some_float, 42.0, 4)
2268 self.assertRaises(TypeError, setattr, self.obj.props, 'some_float', 'foo')
2269 self.assertRaises(TypeError, setattr, self.obj.props, 'some_float', None)
2271 self.assertAlmostEqual(obj.props.some_float, 42.0, 4)
2273 def test_double(self):
2274 self.assertEqual(self.obj.props.some_double, 0)
2275 self.obj.props.some_double = GObject.G_MAXDOUBLE
2276 self.assertEqual(self.obj.props.some_double, GObject.G_MAXDOUBLE)
2278 obj = GIMarshallingTests.PropertiesObject(some_double=42.42)
2279 self.assertAlmostEqual(obj.props.some_double, 42.42)
2281 obj = GIMarshallingTests.PropertiesObject(some_double=42)
2282 self.assertAlmostEqual(obj.props.some_double, 42.0)
2284 self.assertRaises(TypeError, setattr, self.obj.props, 'some_double', 'foo')
2285 self.assertRaises(TypeError, setattr, self.obj.props, 'some_double', None)
2287 self.assertAlmostEqual(obj.props.some_double, 42.0)
2289 def test_strv(self):
2290 self.assertEqual(self.obj.props.some_strv, [])
2291 self.obj.props.some_strv = ['hello', 'world']
2292 self.assertEqual(self.obj.props.some_strv, ['hello', 'world'])
2294 self.assertRaises(TypeError, setattr, self.obj.props, 'some_strv', 1)
2295 self.assertRaises(TypeError, setattr, self.obj.props, 'some_strv', 'foo')
2296 self.assertRaises(TypeError, setattr, self.obj.props, 'some_strv', [1, 2])
2297 self.assertRaises(TypeError, setattr, self.obj.props, 'some_strv', ['foo', 1])
2299 self.assertEqual(self.obj.props.some_strv, ['hello', 'world'])
2301 obj = GIMarshallingTests.PropertiesObject(some_strv=['hello', 'world'])
2302 self.assertEqual(obj.props.some_strv, ['hello', 'world'])
2304 def test_boxed_struct(self):
2305 self.assertEqual(self.obj.props.some_boxed_struct, None)
2308 __gtype__ = GObject.TYPE_STRV
2310 struct1 = GIMarshallingTests.BoxedStruct()
2313 self.obj.props.some_boxed_struct = struct1
2314 self.assertEqual(self.obj.props.some_boxed_struct.long_, 1)
2315 self.assertEqual(self.obj.some_boxed_struct.long_, 1)
2317 self.assertRaises(TypeError, setattr, self.obj.props, 'some_boxed_struct', 1)
2318 self.assertRaises(TypeError, setattr, self.obj.props, 'some_boxed_struct', 'foo')
2320 obj = GIMarshallingTests.PropertiesObject(some_boxed_struct=struct1)
2321 self.assertEqual(obj.props.some_boxed_struct.long_, 1)
2324 class TestKeywords(unittest.TestCase):
2325 def test_method(self):
2327 v = GLib.Variant('i', 1)
2328 self.assertEqual(v.print_(False), '1')
2330 def test_function(self):
2332 self.assertEqual(GLib.Thread.yield_(), None)
2334 def test_struct_method(self):
2335 # g_timer_continue()
2336 # we cannot currently instantiate GLib.Timer objects, so just ensure
2338 self.assertTrue(callable(GLib.Timer.continue_))
2340 def test_uppercase(self):
2341 self.assertEqual(GLib.IOCondition.IN.value_nicks, ['in'])
2344 class TestModule(unittest.TestCase):
2345 def test_path(self):
2346 self.assertTrue(GIMarshallingTests.__path__.endswith('GIMarshallingTests-1.0.typelib'),
2347 GIMarshallingTests.__path__)
2350 self.assertTrue("'GIMarshallingTests' from '" in str(GIMarshallingTests),
2351 str(GIMarshallingTests))
2354 _dir = dir(GIMarshallingTests)
2355 self.assertGreater(len(_dir), 10)
2357 self.assertTrue('SimpleStruct' in _dir)
2358 self.assertTrue('Interface2' in _dir)
2359 self.assertTrue('CONSTANT_GERROR_CODE' in _dir)
2360 self.assertTrue('array_zero_terminated_inout' in _dir)
2362 # assert that dir() does not contain garbage
2363 for item_name in _dir:
2364 item = getattr(GIMarshallingTests, item_name)
2365 self.assertTrue(hasattr(item, '__class__'))
2367 def test_help(self):
2368 orig_stdout = sys.stdout
2370 if sys.version_info < (3, 0):
2371 sys.stdout = BytesIO()
2373 sys.stdout = StringIO()
2374 help(GIMarshallingTests)
2375 output = sys.stdout.getvalue()
2377 sys.stdout = orig_stdout
2379 self.assertTrue('SimpleStruct' in output, output)
2380 self.assertTrue('Interface2' in output, output)
2381 self.assertTrue('method_array_inout' in output, output)
2384 class TestProjectVersion(unittest.TestCase):
2385 def test_version_str(self):
2386 self.assertGreaterEqual(gi.__version__, "3.3.5")
2388 def test_version_info(self):
2389 self.assertEqual(len(gi.version_info), 3)
2390 self.assertGreaterEqual(gi.version_info, (3, 3, 5))
2392 def test_check_version(self):
2393 self.assertRaises(ValueError, gi.check_version, (99, 0, 0))
2394 self.assertRaises(ValueError, gi.check_version, "99.0.0")
2395 gi.check_version((3, 3, 5))
2396 gi.check_version("3.3.5")
2399 class TestObjectInfo(unittest.TestCase):
2400 def test_get_abstract_with_abstract(self):
2401 repo = gi.gi.Repository.get_default()
2402 info = repo.find_by_name('GObject', 'TypeModule')
2403 self.assertTrue(info.get_abstract())
2405 def test_get_abstract_with_concrete(self):
2406 repo = gi.gi.Repository.get_default()
2407 info = repo.find_by_name('GObject', 'Object')
2408 self.assertFalse(info.get_abstract())