summaryrefslogtreecommitdiffstats
path: root/Lib/ctypes
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2013-05-04 14:47:54 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2013-05-04 14:47:54 (GMT)
commit4e59af7abddc7c43a6f52b571fcd65fc55e5f861 (patch)
treeca003819c375963050f61fdc4cad1e60bd4aeb0c /Lib/ctypes
parenta8bc7fd559fa231729ade7bac04af64353ab09cd (diff)
parent28faf03d4474d184b30a8013c70845b6600d456d (diff)
downloadcpython-4e59af7abddc7c43a6f52b571fcd65fc55e5f861.zip
cpython-4e59af7abddc7c43a6f52b571fcd65fc55e5f861.tar.gz
cpython-4e59af7abddc7c43a6f52b571fcd65fc55e5f861.tar.bz2
#7855: merge with 3.3.
Diffstat (limited to 'Lib/ctypes')
-rw-r--r--Lib/ctypes/test/__init__.py2
-rw-r--r--Lib/ctypes/test/test_wintypes.py43
2 files changed, 44 insertions, 1 deletions
diff --git a/Lib/ctypes/test/__init__.py b/Lib/ctypes/test/__init__.py
index 82dc9e3..cc5fe02 100644
--- a/Lib/ctypes/test/__init__.py
+++ b/Lib/ctypes/test/__init__.py
@@ -62,7 +62,7 @@ def get_tests(package, mask, verbosity, exclude=()):
continue
try:
mod = __import__(modname, globals(), locals(), ['*'])
- except ResourceDenied as detail:
+ except (ResourceDenied, unittest.SkipTest) as detail:
skipped.append(modname)
if verbosity > 1:
print("Skipped %s: %s" % (modname, detail), file=sys.stderr)
diff --git a/Lib/ctypes/test/test_wintypes.py b/Lib/ctypes/test/test_wintypes.py
new file mode 100644
index 0000000..806fcce
--- /dev/null
+++ b/Lib/ctypes/test/test_wintypes.py
@@ -0,0 +1,43 @@
+import sys
+import unittest
+
+if not sys.platform.startswith('win'):
+ raise unittest.SkipTest('Windows-only test')
+
+from ctypes import *
+from ctypes import wintypes
+
+class WinTypesTest(unittest.TestCase):
+ def test_variant_bool(self):
+ # reads 16-bits from memory, anything non-zero is True
+ for true_value in (1, 32767, 32768, 65535, 65537):
+ true = POINTER(c_int16)(c_int16(true_value))
+ value = cast(true, POINTER(wintypes.VARIANT_BOOL))
+ self.assertEqual(repr(value.contents), 'VARIANT_BOOL(True)')
+
+ vb = wintypes.VARIANT_BOOL()
+ self.assertIs(vb.value, False)
+ vb.value = True
+ self.assertIs(vb.value, True)
+ vb.value = true_value
+ self.assertIs(vb.value, True)
+
+ for false_value in (0, 65536, 262144, 2**33):
+ false = POINTER(c_int16)(c_int16(false_value))
+ value = cast(false, POINTER(wintypes.VARIANT_BOOL))
+ self.assertEqual(repr(value.contents), 'VARIANT_BOOL(False)')
+
+ # allow any bool conversion on assignment to value
+ for set_value in (65536, 262144, 2**33):
+ vb = wintypes.VARIANT_BOOL()
+ vb.value = set_value
+ self.assertIs(vb.value, True)
+
+ vb = wintypes.VARIANT_BOOL()
+ vb.value = [2, 3]
+ self.assertIs(vb.value, True)
+ vb.value = []
+ self.assertIs(vb.value, False)
+
+if __name__ == "__main__":
+ unittest.main()