blob: 71442df8301affdbd65da31c8579f7694e34f924 [file] [log] [blame]
Ezio Melotti28faf032013-05-04 17:46:23 +03001import sys
2import unittest
3
Ezio Melotti28faf032013-05-04 17:46:23 +03004from ctypes import *
Ezio Melotti28faf032013-05-04 17:46:23 +03005
Zachary Ware9422df02014-06-13 13:44:39 -05006@unittest.skipUnless(sys.platform.startswith('win'), 'Windows-only test')
Ezio Melotti28faf032013-05-04 17:46:23 +03007class WinTypesTest(unittest.TestCase):
8 def test_variant_bool(self):
Zachary Ware9422df02014-06-13 13:44:39 -05009 from ctypes import wintypes
Ezio Melotti28faf032013-05-04 17:46:23 +030010 # reads 16-bits from memory, anything non-zero is True
11 for true_value in (1, 32767, 32768, 65535, 65537):
12 true = POINTER(c_int16)(c_int16(true_value))
13 value = cast(true, POINTER(wintypes.VARIANT_BOOL))
14 self.assertEqual(repr(value.contents), 'VARIANT_BOOL(True)')
15
16 vb = wintypes.VARIANT_BOOL()
17 self.assertIs(vb.value, False)
18 vb.value = True
19 self.assertIs(vb.value, True)
20 vb.value = true_value
21 self.assertIs(vb.value, True)
22
23 for false_value in (0, 65536, 262144, 2**33):
24 false = POINTER(c_int16)(c_int16(false_value))
25 value = cast(false, POINTER(wintypes.VARIANT_BOOL))
26 self.assertEqual(repr(value.contents), 'VARIANT_BOOL(False)')
27
28 # allow any bool conversion on assignment to value
29 for set_value in (65536, 262144, 2**33):
30 vb = wintypes.VARIANT_BOOL()
31 vb.value = set_value
32 self.assertIs(vb.value, True)
33
34 vb = wintypes.VARIANT_BOOL()
35 vb.value = [2, 3]
36 self.assertIs(vb.value, True)
37 vb.value = []
38 self.assertIs(vb.value, False)
39
40if __name__ == "__main__":
41 unittest.main()