~ubuntu-branches/ubuntu/saucy/python2.7/saucy-proposed

« back to all changes in this revision

Viewing changes to Lib/ctypes/test/test_wintypes.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-05-15 19:15:16 UTC
  • mto: (36.1.23 sid)
  • mto: This revision was merged to the branch mainline in revision 87.
  • Revision ID: package-import@ubuntu.com-20130515191516-zmv6to904wemey7s
Tags: upstream-2.7.5
ImportĀ upstreamĀ versionĀ 2.7.5

Show diffs side-by-side

added added

removed removed

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