blob: 93d7bfb1090f32f8359764aba237963da59c9f99 [file] [log] [blame]
Thomas Wouters89f507f2006-12-13 04:49:30 +00001from _testcapi import test_structmembersType, \
2 CHAR_MAX, CHAR_MIN, UCHAR_MAX, \
3 SHRT_MAX, SHRT_MIN, USHRT_MAX, \
4 INT_MAX, INT_MIN, UINT_MAX, \
Guido van Rossumcd16bf62007-06-13 18:07:49 +00005 LONG_MAX, LONG_MIN, ULONG_MAX, \
6 LLONG_MAX, LLONG_MIN, ULLONG_MAX
Thomas Wouters89f507f2006-12-13 04:49:30 +00007
Thomas Woutersed03b412007-08-28 21:37:11 +00008import warnings, unittest, sys
Thomas Wouters89f507f2006-12-13 04:49:30 +00009from test import test_support
10
11ts=test_structmembersType(1,2,3,4,5,6,7,8,9.99999,10.1010101010)
12
13class ReadWriteTests(unittest.TestCase):
14 def test_types(self):
15 ts.T_BYTE=CHAR_MAX
16 self.assertEquals(ts.T_BYTE, CHAR_MAX)
17 ts.T_BYTE=CHAR_MIN
18 self.assertEquals(ts.T_BYTE, CHAR_MIN)
19 ts.T_UBYTE=UCHAR_MAX
20 self.assertEquals(ts.T_UBYTE, UCHAR_MAX)
21
22 ts.T_SHORT=SHRT_MAX
23 self.assertEquals(ts.T_SHORT, SHRT_MAX)
24 ts.T_SHORT=SHRT_MIN
25 self.assertEquals(ts.T_SHORT, SHRT_MIN)
26 ts.T_USHORT=USHRT_MAX
27 self.assertEquals(ts.T_USHORT, USHRT_MAX)
28
29 ts.T_INT=INT_MAX
30 self.assertEquals(ts.T_INT, INT_MAX)
31 ts.T_INT=INT_MIN
32 self.assertEquals(ts.T_INT, INT_MIN)
33 ts.T_UINT=UINT_MAX
34 self.assertEquals(ts.T_UINT, UINT_MAX)
35
36 ts.T_LONG=LONG_MAX
37 self.assertEquals(ts.T_LONG, LONG_MAX)
38 ts.T_LONG=LONG_MIN
39 self.assertEquals(ts.T_LONG, LONG_MIN)
40 ts.T_ULONG=ULONG_MAX
41 self.assertEquals(ts.T_ULONG, ULONG_MAX)
42
Guido van Rossumcd16bf62007-06-13 18:07:49 +000043 ## T_LONGLONG and T_ULONGLONG may not be present on some platforms
44 if hasattr(ts, 'T_LONGLONG'):
45 ts.T_LONGLONG=LLONG_MAX
46 self.assertEquals(ts.T_LONGLONG, LLONG_MAX)
47 ts.T_LONGLONG=LLONG_MIN
48 self.assertEquals(ts.T_LONGLONG, LLONG_MIN)
49
50 ts.T_ULONGLONG=ULLONG_MAX
51 self.assertEquals(ts.T_ULONGLONG, ULLONG_MAX)
52
53 ## make sure these will accept a plain int as well as a long
54 ts.T_LONGLONG=3
55 self.assertEquals(ts.T_LONGLONG, 3)
56 ts.T_ULONGLONG=4
57 self.assertEquals(ts.T_ULONGLONG, 4)
58
59
Guido van Rossumd8faa362007-04-27 19:54:29 +000060class TestWarnings(unittest.TestCase):
61 def has_warned(self, w):
Thomas Woutersed03b412007-08-28 21:37:11 +000062 self.assertEqual(w.category, RuntimeWarning)
Thomas Wouters89f507f2006-12-13 04:49:30 +000063
64 def test_byte_max(self):
Guido van Rossumd8faa362007-04-27 19:54:29 +000065 with test_support.catch_warning() as w:
66 ts.T_BYTE=CHAR_MAX+1
67 self.has_warned(w)
Thomas Wouters89f507f2006-12-13 04:49:30 +000068
69 def test_byte_min(self):
Guido van Rossumd8faa362007-04-27 19:54:29 +000070 with test_support.catch_warning() as w:
71 ts.T_BYTE=CHAR_MIN-1
72 self.has_warned(w)
Thomas Wouters89f507f2006-12-13 04:49:30 +000073
74 def test_ubyte_max(self):
Guido van Rossumd8faa362007-04-27 19:54:29 +000075 with test_support.catch_warning() as w:
76 ts.T_UBYTE=UCHAR_MAX+1
77 self.has_warned(w)
Thomas Wouters89f507f2006-12-13 04:49:30 +000078
79 def test_short_max(self):
Guido van Rossumd8faa362007-04-27 19:54:29 +000080 with test_support.catch_warning() as w:
81 ts.T_SHORT=SHRT_MAX+1
82 self.has_warned(w)
Thomas Wouters89f507f2006-12-13 04:49:30 +000083
84 def test_short_min(self):
Guido van Rossumd8faa362007-04-27 19:54:29 +000085 with test_support.catch_warning() as w:
86 ts.T_SHORT=SHRT_MIN-1
87 self.has_warned(w)
Thomas Wouters89f507f2006-12-13 04:49:30 +000088
89 def test_ushort_max(self):
Guido van Rossumd8faa362007-04-27 19:54:29 +000090 with test_support.catch_warning() as w:
91 ts.T_USHORT=USHRT_MAX+1
92 self.has_warned(w)
Thomas Wouters89f507f2006-12-13 04:49:30 +000093
94
95
96def test_main(verbose=None):
Thomas Woutersed03b412007-08-28 21:37:11 +000097 # Obscure hack so that this test passes after reloads or repeated calls
98 # to test_main (regrtest -R).
99 if '__warningregistry__' in globals():
100 del globals()['__warningregistry__']
101 if hasattr(sys, '__warningregistry__'):
102 del sys.__warningregistry__
103 test_support.run_unittest(__name__)
Thomas Wouters89f507f2006-12-13 04:49:30 +0000104
105if __name__ == "__main__":
106 test_main(verbose=True)