| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -682,20 +682,34 @@ def test_iconvertible_conversion(): | |||
| 682 | 682 | ||
| 683 | 683 | def test_intptr_construction(): | |
| 684 | 684 | from System import IntPtr, UIntPtr, Int64, UInt64 | |
| 685 | + from ctypes import sizeof, c_void_p | ||
| 686 | + | ||
| 687 | + ptr_size = sizeof(c_void_p) | ||
| 688 | + max_intptr = 2 ** (ptr_size * 8 - 1) - 1 | ||
| 689 | + min_intptr = -max_intptr - 1 | ||
| 690 | + max_uintptr = 2 ** (ptr_size * 8) - 1 | ||
| 691 | + min_uintptr = 0 | ||
| 685 | 692 | ||
| 686 | 693 | ob = ConversionTest() | |
| 687 | 694 | ||
| 688 | 695 | assert ob.IntPtrField == IntPtr.Zero | |
| 689 | 696 | assert ob.UIntPtrField == UIntPtr.Zero | |
| 690 | 697 | ||
| 691 | - ob.IntPtrField = IntPtr(Int64(-1)) | ||
| 692 | - assert ob.IntPtrField == IntPtr(-1) | ||
| 693 | - assert ob.IntPtrField.ToInt64() == -1 | ||
| 698 | + for v in [0, -1, 1024, max_intptr, min_intptr]: | ||
| 699 | + ob.IntPtrField = IntPtr(Int64(v)) | ||
| 700 | + assert ob.IntPtrField == IntPtr(v) | ||
| 701 | + assert ob.IntPtrField.ToInt64() == v | ||
| 702 | + | ||
| 703 | + for v in [min_intptr - 1, max_intptr + 1]: | ||
| 704 | + with pytest.raises(TypeError): | ||
| 705 | + IntPtr(v) | ||
| 706 | + | ||
| 707 | + for v in [0, 1024, min_uintptr, max_uintptr, max_intptr]: | ||
| 708 | + ob.UIntPtrField = UIntPtr(UInt64(v)) | ||
| 709 | + assert ob.UIntPtrField == UIntPtr(v) | ||
| 710 | + assert ob.UIntPtrField.ToUInt64() == v | ||
| 694 | 711 | ||
| 695 | - ob.IntPtrField = IntPtr(Int64(1024)) | ||
| 696 | - assert ob.IntPtrField == IntPtr(1024) | ||
| 697 | - assert ob.IntPtrField.ToInt64() == 1024 | ||
| 712 | + for v in [min_uintptr - 1, max_uintptr + 1, min_intptr]: | ||
| 713 | + with pytest.raises(TypeError): | ||
| 714 | + UIntPtr(v) | ||
| 698 | 715 | ||
| 699 | - ob.UIntPtrField = UIntPtr(UInt64(1024)) | ||
| 700 | - assert ob.UIntPtrField == UIntPtr(1024) | ||
| 701 | - assert ob.UIntPtrField.ToUInt64() == 1024 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments