1 | n/a | import sys |
---|
2 | n/a | import unittest |
---|
3 | n/a | |
---|
4 | n/a | from ctypes import * |
---|
5 | n/a | |
---|
6 | n/a | @unittest.skipUnless(sys.platform.startswith('win'), 'Windows-only test') |
---|
7 | n/a | class WinTypesTest(unittest.TestCase): |
---|
8 | n/a | def test_variant_bool(self): |
---|
9 | n/a | from ctypes import wintypes |
---|
10 | n/a | # reads 16-bits from memory, anything non-zero is True |
---|
11 | n/a | for true_value in (1, 32767, 32768, 65535, 65537): |
---|
12 | n/a | true = POINTER(c_int16)(c_int16(true_value)) |
---|
13 | n/a | value = cast(true, POINTER(wintypes.VARIANT_BOOL)) |
---|
14 | n/a | self.assertEqual(repr(value.contents), 'VARIANT_BOOL(True)') |
---|
15 | n/a | |
---|
16 | n/a | vb = wintypes.VARIANT_BOOL() |
---|
17 | n/a | self.assertIs(vb.value, False) |
---|
18 | n/a | vb.value = True |
---|
19 | n/a | self.assertIs(vb.value, True) |
---|
20 | n/a | vb.value = true_value |
---|
21 | n/a | self.assertIs(vb.value, True) |
---|
22 | n/a | |
---|
23 | n/a | for false_value in (0, 65536, 262144, 2**33): |
---|
24 | n/a | false = POINTER(c_int16)(c_int16(false_value)) |
---|
25 | n/a | value = cast(false, POINTER(wintypes.VARIANT_BOOL)) |
---|
26 | n/a | self.assertEqual(repr(value.contents), 'VARIANT_BOOL(False)') |
---|
27 | n/a | |
---|
28 | n/a | # allow any bool conversion on assignment to value |
---|
29 | n/a | for set_value in (65536, 262144, 2**33): |
---|
30 | n/a | vb = wintypes.VARIANT_BOOL() |
---|
31 | n/a | vb.value = set_value |
---|
32 | n/a | self.assertIs(vb.value, True) |
---|
33 | n/a | |
---|
34 | n/a | vb = wintypes.VARIANT_BOOL() |
---|
35 | n/a | vb.value = [2, 3] |
---|
36 | n/a | self.assertIs(vb.value, True) |
---|
37 | n/a | vb.value = [] |
---|
38 | n/a | self.assertIs(vb.value, False) |
---|
39 | n/a | |
---|
40 | n/a | if __name__ == "__main__": |
---|
41 | n/a | unittest.main() |
---|