Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 1 | from _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 Rossum | cd16bf6 | 2007-06-13 18:07:49 +0000 | [diff] [blame] | 5 | LONG_MAX, LONG_MIN, ULONG_MAX, \ |
| 6 | LLONG_MAX, LLONG_MIN, ULLONG_MAX |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 7 | |
Thomas Wouters | ed03b41 | 2007-08-28 21:37:11 +0000 | [diff] [blame] | 8 | import warnings, unittest, sys |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 9 | from test import support |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 10 | |
Christian Heimes | 1af737c | 2008-01-23 08:24:23 +0000 | [diff] [blame] | 11 | ts=test_structmembersType(False, 1, 2, 3, 4, 5, 6, 7, 8, |
| 12 | 9.99999, 10.1010101010) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 13 | |
| 14 | class ReadWriteTests(unittest.TestCase): |
| 15 | def test_types(self): |
Christian Heimes | 1af737c | 2008-01-23 08:24:23 +0000 | [diff] [blame] | 16 | ts.T_BOOL = True |
| 17 | self.assertEquals(ts.T_BOOL, True) |
| 18 | ts.T_BOOL = False |
| 19 | self.assertEquals(ts.T_BOOL, False) |
| 20 | self.assertRaises(TypeError, setattr, ts, 'T_BOOL', 1) |
| 21 | |
| 22 | ts.T_BYTE = CHAR_MAX |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 23 | self.assertEquals(ts.T_BYTE, CHAR_MAX) |
Christian Heimes | 1af737c | 2008-01-23 08:24:23 +0000 | [diff] [blame] | 24 | ts.T_BYTE = CHAR_MIN |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 25 | self.assertEquals(ts.T_BYTE, CHAR_MIN) |
Christian Heimes | 1af737c | 2008-01-23 08:24:23 +0000 | [diff] [blame] | 26 | ts.T_UBYTE = UCHAR_MAX |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 27 | self.assertEquals(ts.T_UBYTE, UCHAR_MAX) |
| 28 | |
Christian Heimes | 1af737c | 2008-01-23 08:24:23 +0000 | [diff] [blame] | 29 | ts.T_SHORT = SHRT_MAX |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 30 | self.assertEquals(ts.T_SHORT, SHRT_MAX) |
Christian Heimes | 1af737c | 2008-01-23 08:24:23 +0000 | [diff] [blame] | 31 | ts.T_SHORT = SHRT_MIN |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 32 | self.assertEquals(ts.T_SHORT, SHRT_MIN) |
Christian Heimes | 1af737c | 2008-01-23 08:24:23 +0000 | [diff] [blame] | 33 | ts.T_USHORT = USHRT_MAX |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 34 | self.assertEquals(ts.T_USHORT, USHRT_MAX) |
| 35 | |
Christian Heimes | 1af737c | 2008-01-23 08:24:23 +0000 | [diff] [blame] | 36 | ts.T_INT = INT_MAX |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 37 | self.assertEquals(ts.T_INT, INT_MAX) |
Christian Heimes | 1af737c | 2008-01-23 08:24:23 +0000 | [diff] [blame] | 38 | ts.T_INT = INT_MIN |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 39 | self.assertEquals(ts.T_INT, INT_MIN) |
Christian Heimes | 1af737c | 2008-01-23 08:24:23 +0000 | [diff] [blame] | 40 | ts.T_UINT = UINT_MAX |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 41 | self.assertEquals(ts.T_UINT, UINT_MAX) |
| 42 | |
Christian Heimes | 1af737c | 2008-01-23 08:24:23 +0000 | [diff] [blame] | 43 | ts.T_LONG = LONG_MAX |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 44 | self.assertEquals(ts.T_LONG, LONG_MAX) |
Christian Heimes | 1af737c | 2008-01-23 08:24:23 +0000 | [diff] [blame] | 45 | ts.T_LONG = LONG_MIN |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 46 | self.assertEquals(ts.T_LONG, LONG_MIN) |
Christian Heimes | 1af737c | 2008-01-23 08:24:23 +0000 | [diff] [blame] | 47 | ts.T_ULONG = ULONG_MAX |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 48 | self.assertEquals(ts.T_ULONG, ULONG_MAX) |
| 49 | |
Guido van Rossum | cd16bf6 | 2007-06-13 18:07:49 +0000 | [diff] [blame] | 50 | ## T_LONGLONG and T_ULONGLONG may not be present on some platforms |
| 51 | if hasattr(ts, 'T_LONGLONG'): |
Christian Heimes | 1af737c | 2008-01-23 08:24:23 +0000 | [diff] [blame] | 52 | ts.T_LONGLONG = LLONG_MAX |
Guido van Rossum | cd16bf6 | 2007-06-13 18:07:49 +0000 | [diff] [blame] | 53 | self.assertEquals(ts.T_LONGLONG, LLONG_MAX) |
Christian Heimes | 1af737c | 2008-01-23 08:24:23 +0000 | [diff] [blame] | 54 | ts.T_LONGLONG = LLONG_MIN |
Guido van Rossum | cd16bf6 | 2007-06-13 18:07:49 +0000 | [diff] [blame] | 55 | self.assertEquals(ts.T_LONGLONG, LLONG_MIN) |
| 56 | |
Christian Heimes | 1af737c | 2008-01-23 08:24:23 +0000 | [diff] [blame] | 57 | ts.T_ULONGLONG = ULLONG_MAX |
Guido van Rossum | cd16bf6 | 2007-06-13 18:07:49 +0000 | [diff] [blame] | 58 | self.assertEquals(ts.T_ULONGLONG, ULLONG_MAX) |
| 59 | |
| 60 | ## make sure these will accept a plain int as well as a long |
Christian Heimes | 1af737c | 2008-01-23 08:24:23 +0000 | [diff] [blame] | 61 | ts.T_LONGLONG = 3 |
Guido van Rossum | cd16bf6 | 2007-06-13 18:07:49 +0000 | [diff] [blame] | 62 | self.assertEquals(ts.T_LONGLONG, 3) |
Christian Heimes | 1af737c | 2008-01-23 08:24:23 +0000 | [diff] [blame] | 63 | ts.T_ULONGLONG = 4 |
Guido van Rossum | cd16bf6 | 2007-06-13 18:07:49 +0000 | [diff] [blame] | 64 | self.assertEquals(ts.T_ULONGLONG, 4) |
| 65 | |
| 66 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 67 | class TestWarnings(unittest.TestCase): |
| 68 | def has_warned(self, w): |
Thomas Wouters | ed03b41 | 2007-08-28 21:37:11 +0000 | [diff] [blame] | 69 | self.assertEqual(w.category, RuntimeWarning) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 70 | |
| 71 | def test_byte_max(self): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 72 | with support.catch_warning() as w: |
Christian Heimes | 1af737c | 2008-01-23 08:24:23 +0000 | [diff] [blame] | 73 | ts.T_BYTE = CHAR_MAX+1 |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 74 | self.has_warned(w) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 75 | |
| 76 | def test_byte_min(self): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 77 | with support.catch_warning() as w: |
Christian Heimes | 1af737c | 2008-01-23 08:24:23 +0000 | [diff] [blame] | 78 | ts.T_BYTE = CHAR_MIN-1 |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 79 | self.has_warned(w) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 80 | |
| 81 | def test_ubyte_max(self): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 82 | with support.catch_warning() as w: |
Christian Heimes | 1af737c | 2008-01-23 08:24:23 +0000 | [diff] [blame] | 83 | ts.T_UBYTE = UCHAR_MAX+1 |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 84 | self.has_warned(w) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 85 | |
| 86 | def test_short_max(self): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 87 | with support.catch_warning() as w: |
Christian Heimes | 1af737c | 2008-01-23 08:24:23 +0000 | [diff] [blame] | 88 | ts.T_SHORT = SHRT_MAX+1 |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 89 | self.has_warned(w) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 90 | |
| 91 | def test_short_min(self): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 92 | with support.catch_warning() as w: |
Christian Heimes | 1af737c | 2008-01-23 08:24:23 +0000 | [diff] [blame] | 93 | ts.T_SHORT = SHRT_MIN-1 |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 94 | self.has_warned(w) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 95 | |
| 96 | def test_ushort_max(self): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 97 | with support.catch_warning() as w: |
Christian Heimes | 1af737c | 2008-01-23 08:24:23 +0000 | [diff] [blame] | 98 | ts.T_USHORT = USHRT_MAX+1 |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 99 | self.has_warned(w) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 100 | |
| 101 | |
| 102 | |
| 103 | def test_main(verbose=None): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 104 | support.run_unittest(__name__) |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 105 | |
| 106 | if __name__ == "__main__": |
| 107 | test_main(verbose=True) |