Mark Dickinson | b05dc00 | 2010-04-03 10:27:05 +0000 | [diff] [blame] | 1 | from _testcapi import _test_structmembersType, \ |
Martin v. Löwis | b5bc537 | 2006-10-27 06:16:31 +0000 | [diff] [blame] | 2 | CHAR_MAX, CHAR_MIN, UCHAR_MAX, \ |
| 3 | SHRT_MAX, SHRT_MIN, USHRT_MAX, \ |
| 4 | INT_MAX, INT_MIN, UINT_MAX, \ |
Martin v. Löwis | 6371cd8 | 2007-06-09 07:42:52 +0000 | [diff] [blame] | 5 | LONG_MAX, LONG_MIN, ULONG_MAX, \ |
| 6 | LLONG_MAX, LLONG_MIN, ULLONG_MAX |
Martin v. Löwis | b5bc537 | 2006-10-27 06:16:31 +0000 | [diff] [blame] | 7 | |
Georg Brandl | a4f46e1 | 2010-02-07 17:03:15 +0000 | [diff] [blame] | 8 | import unittest |
Martin v. Löwis | b5bc537 | 2006-10-27 06:16:31 +0000 | [diff] [blame] | 9 | from test import test_support |
| 10 | |
Mark Dickinson | b05dc00 | 2010-04-03 10:27:05 +0000 | [diff] [blame] | 11 | ts=_test_structmembersType(False, 1, 2, 3, 4, 5, 6, 7, 8, |
Benjamin Peterson | 1c7c11e | 2010-04-03 01:28:57 +0000 | [diff] [blame] | 12 | 9.99999, 10.1010101010, "hi") |
Martin v. Löwis | b5bc537 | 2006-10-27 06:16:31 +0000 | [diff] [blame] | 13 | |
| 14 | class ReadWriteTests(unittest.TestCase): |
Benjamin Peterson | 2b79fdf | 2010-04-03 01:08:34 +0000 | [diff] [blame] | 15 | |
| 16 | def test_bool(self): |
Georg Brandl | c09b94e | 2008-01-21 21:28:32 +0000 | [diff] [blame] | 17 | ts.T_BOOL = True |
Georg Brandl | 32a3fb5 | 2008-01-21 21:23:15 +0000 | [diff] [blame] | 18 | self.assertEquals(ts.T_BOOL, True) |
Georg Brandl | c09b94e | 2008-01-21 21:28:32 +0000 | [diff] [blame] | 19 | ts.T_BOOL = False |
Georg Brandl | 32a3fb5 | 2008-01-21 21:23:15 +0000 | [diff] [blame] | 20 | self.assertEquals(ts.T_BOOL, False) |
| 21 | self.assertRaises(TypeError, setattr, ts, 'T_BOOL', 1) |
| 22 | |
Benjamin Peterson | 2b79fdf | 2010-04-03 01:08:34 +0000 | [diff] [blame] | 23 | def test_byte(self): |
Georg Brandl | c09b94e | 2008-01-21 21:28:32 +0000 | [diff] [blame] | 24 | ts.T_BYTE = CHAR_MAX |
Martin v. Löwis | b5bc537 | 2006-10-27 06:16:31 +0000 | [diff] [blame] | 25 | self.assertEquals(ts.T_BYTE, CHAR_MAX) |
Georg Brandl | c09b94e | 2008-01-21 21:28:32 +0000 | [diff] [blame] | 26 | ts.T_BYTE = CHAR_MIN |
Martin v. Löwis | b5bc537 | 2006-10-27 06:16:31 +0000 | [diff] [blame] | 27 | self.assertEquals(ts.T_BYTE, CHAR_MIN) |
Georg Brandl | c09b94e | 2008-01-21 21:28:32 +0000 | [diff] [blame] | 28 | ts.T_UBYTE = UCHAR_MAX |
Martin v. Löwis | b5bc537 | 2006-10-27 06:16:31 +0000 | [diff] [blame] | 29 | self.assertEquals(ts.T_UBYTE, UCHAR_MAX) |
| 30 | |
Benjamin Peterson | 2b79fdf | 2010-04-03 01:08:34 +0000 | [diff] [blame] | 31 | def test_short(self): |
Georg Brandl | c09b94e | 2008-01-21 21:28:32 +0000 | [diff] [blame] | 32 | ts.T_SHORT = SHRT_MAX |
Martin v. Löwis | b5bc537 | 2006-10-27 06:16:31 +0000 | [diff] [blame] | 33 | self.assertEquals(ts.T_SHORT, SHRT_MAX) |
Georg Brandl | c09b94e | 2008-01-21 21:28:32 +0000 | [diff] [blame] | 34 | ts.T_SHORT = SHRT_MIN |
Martin v. Löwis | b5bc537 | 2006-10-27 06:16:31 +0000 | [diff] [blame] | 35 | self.assertEquals(ts.T_SHORT, SHRT_MIN) |
Georg Brandl | c09b94e | 2008-01-21 21:28:32 +0000 | [diff] [blame] | 36 | ts.T_USHORT = USHRT_MAX |
Martin v. Löwis | b5bc537 | 2006-10-27 06:16:31 +0000 | [diff] [blame] | 37 | self.assertEquals(ts.T_USHORT, USHRT_MAX) |
| 38 | |
Benjamin Peterson | 2b79fdf | 2010-04-03 01:08:34 +0000 | [diff] [blame] | 39 | def test_int(self): |
Georg Brandl | c09b94e | 2008-01-21 21:28:32 +0000 | [diff] [blame] | 40 | ts.T_INT = INT_MAX |
Martin v. Löwis | b5bc537 | 2006-10-27 06:16:31 +0000 | [diff] [blame] | 41 | self.assertEquals(ts.T_INT, INT_MAX) |
Georg Brandl | c09b94e | 2008-01-21 21:28:32 +0000 | [diff] [blame] | 42 | ts.T_INT = INT_MIN |
Martin v. Löwis | b5bc537 | 2006-10-27 06:16:31 +0000 | [diff] [blame] | 43 | self.assertEquals(ts.T_INT, INT_MIN) |
Georg Brandl | c09b94e | 2008-01-21 21:28:32 +0000 | [diff] [blame] | 44 | ts.T_UINT = UINT_MAX |
Martin v. Löwis | b5bc537 | 2006-10-27 06:16:31 +0000 | [diff] [blame] | 45 | self.assertEquals(ts.T_UINT, UINT_MAX) |
| 46 | |
Benjamin Peterson | 2b79fdf | 2010-04-03 01:08:34 +0000 | [diff] [blame] | 47 | def test_long(self): |
Georg Brandl | c09b94e | 2008-01-21 21:28:32 +0000 | [diff] [blame] | 48 | ts.T_LONG = LONG_MAX |
Martin v. Löwis | b5bc537 | 2006-10-27 06:16:31 +0000 | [diff] [blame] | 49 | self.assertEquals(ts.T_LONG, LONG_MAX) |
Georg Brandl | c09b94e | 2008-01-21 21:28:32 +0000 | [diff] [blame] | 50 | ts.T_LONG = LONG_MIN |
Martin v. Löwis | b5bc537 | 2006-10-27 06:16:31 +0000 | [diff] [blame] | 51 | self.assertEquals(ts.T_LONG, LONG_MIN) |
Georg Brandl | c09b94e | 2008-01-21 21:28:32 +0000 | [diff] [blame] | 52 | ts.T_ULONG = ULONG_MAX |
Martin v. Löwis | b5bc537 | 2006-10-27 06:16:31 +0000 | [diff] [blame] | 53 | self.assertEquals(ts.T_ULONG, ULONG_MAX) |
| 54 | |
Benjamin Peterson | 2b79fdf | 2010-04-03 01:08:34 +0000 | [diff] [blame] | 55 | @unittest.skipUnless(hasattr(ts, "T_LONGLONG"), "long long not present") |
| 56 | def test_longlong(self): |
| 57 | ts.T_LONGLONG = LLONG_MAX |
| 58 | self.assertEquals(ts.T_LONGLONG, LLONG_MAX) |
| 59 | ts.T_LONGLONG = LLONG_MIN |
| 60 | self.assertEquals(ts.T_LONGLONG, LLONG_MIN) |
Martin v. Löwis | 6371cd8 | 2007-06-09 07:42:52 +0000 | [diff] [blame] | 61 | |
Benjamin Peterson | 2b79fdf | 2010-04-03 01:08:34 +0000 | [diff] [blame] | 62 | ts.T_ULONGLONG = ULLONG_MAX |
| 63 | self.assertEquals(ts.T_ULONGLONG, ULLONG_MAX) |
Martin v. Löwis | 6371cd8 | 2007-06-09 07:42:52 +0000 | [diff] [blame] | 64 | |
Benjamin Peterson | 2b79fdf | 2010-04-03 01:08:34 +0000 | [diff] [blame] | 65 | ## make sure these will accept a plain int as well as a long |
| 66 | ts.T_LONGLONG = 3 |
| 67 | self.assertEquals(ts.T_LONGLONG, 3) |
| 68 | ts.T_ULONGLONG = 4 |
| 69 | self.assertEquals(ts.T_ULONGLONG, 4) |
Martin v. Löwis | 6371cd8 | 2007-06-09 07:42:52 +0000 | [diff] [blame] | 70 | |
Benjamin Peterson | 1c7c11e | 2010-04-03 01:28:57 +0000 | [diff] [blame] | 71 | def test_inplace_string(self): |
| 72 | self.assertEquals(ts.T_STRING_INPLACE, "hi") |
| 73 | self.assertRaises(TypeError, setattr, ts, "T_STRING_INPLACE", "s") |
| 74 | self.assertRaises(TypeError, delattr, ts, "T_STRING_INPLACE") |
| 75 | |
Martin v. Löwis | 6371cd8 | 2007-06-09 07:42:52 +0000 | [diff] [blame] | 76 | |
Walter Dörwald | e6dae6c | 2007-04-03 18:33:29 +0000 | [diff] [blame] | 77 | class TestWarnings(unittest.TestCase): |
Tim Peters | abd8a33 | 2006-11-03 02:32:46 +0000 | [diff] [blame] | 78 | |
Martin v. Löwis | b5bc537 | 2006-10-27 06:16:31 +0000 | [diff] [blame] | 79 | def test_byte_max(self): |
Florent Xicluna | 945a8ba | 2010-03-17 19:15:56 +0000 | [diff] [blame] | 80 | with test_support.check_warnings(('', RuntimeWarning)): |
Georg Brandl | c09b94e | 2008-01-21 21:28:32 +0000 | [diff] [blame] | 81 | ts.T_BYTE = CHAR_MAX+1 |
Tim Peters | abd8a33 | 2006-11-03 02:32:46 +0000 | [diff] [blame] | 82 | |
Martin v. Löwis | b5bc537 | 2006-10-27 06:16:31 +0000 | [diff] [blame] | 83 | def test_byte_min(self): |
Florent Xicluna | 945a8ba | 2010-03-17 19:15:56 +0000 | [diff] [blame] | 84 | with test_support.check_warnings(('', RuntimeWarning)): |
Georg Brandl | c09b94e | 2008-01-21 21:28:32 +0000 | [diff] [blame] | 85 | ts.T_BYTE = CHAR_MIN-1 |
Martin v. Löwis | b5bc537 | 2006-10-27 06:16:31 +0000 | [diff] [blame] | 86 | |
| 87 | def test_ubyte_max(self): |
Florent Xicluna | 945a8ba | 2010-03-17 19:15:56 +0000 | [diff] [blame] | 88 | with test_support.check_warnings(('', RuntimeWarning)): |
Georg Brandl | c09b94e | 2008-01-21 21:28:32 +0000 | [diff] [blame] | 89 | ts.T_UBYTE = UCHAR_MAX+1 |
Martin v. Löwis | b5bc537 | 2006-10-27 06:16:31 +0000 | [diff] [blame] | 90 | |
| 91 | def test_short_max(self): |
Florent Xicluna | 945a8ba | 2010-03-17 19:15:56 +0000 | [diff] [blame] | 92 | with test_support.check_warnings(('', RuntimeWarning)): |
Georg Brandl | c09b94e | 2008-01-21 21:28:32 +0000 | [diff] [blame] | 93 | ts.T_SHORT = SHRT_MAX+1 |
Martin v. Löwis | b5bc537 | 2006-10-27 06:16:31 +0000 | [diff] [blame] | 94 | |
| 95 | def test_short_min(self): |
Florent Xicluna | 945a8ba | 2010-03-17 19:15:56 +0000 | [diff] [blame] | 96 | with test_support.check_warnings(('', RuntimeWarning)): |
Georg Brandl | c09b94e | 2008-01-21 21:28:32 +0000 | [diff] [blame] | 97 | ts.T_SHORT = SHRT_MIN-1 |
Martin v. Löwis | b5bc537 | 2006-10-27 06:16:31 +0000 | [diff] [blame] | 98 | |
| 99 | def test_ushort_max(self): |
Florent Xicluna | 945a8ba | 2010-03-17 19:15:56 +0000 | [diff] [blame] | 100 | with test_support.check_warnings(('', RuntimeWarning)): |
Georg Brandl | c09b94e | 2008-01-21 21:28:32 +0000 | [diff] [blame] | 101 | ts.T_USHORT = USHRT_MAX+1 |
Tim Peters | abd8a33 | 2006-11-03 02:32:46 +0000 | [diff] [blame] | 102 | |
Martin v. Löwis | b5bc537 | 2006-10-27 06:16:31 +0000 | [diff] [blame] | 103 | |
| 104 | def test_main(verbose=None): |
Collin Winter | 68f525f | 2007-08-24 21:09:42 +0000 | [diff] [blame] | 105 | test_support.run_unittest(__name__) |
Martin v. Löwis | b5bc537 | 2006-10-27 06:16:31 +0000 | [diff] [blame] | 106 | |
| 107 | if __name__ == "__main__": |
| 108 | test_main(verbose=True) |