|
| 1 | +using System; |
| 2 | +using NFluent; |
| 3 | +using ReClassNET.Extensions; |
| 4 | +using Xunit; |
| 5 | + |
| 6 | +namespace ReClass.NET_Tests.Extensions |
| 7 | +{ |
| 8 | + public class IntPtrExtensionTest |
| 9 | + { |
| 10 | + public static TheoryData<IntPtr, bool> GetTestIsNullData => new TheoryData<IntPtr, bool> |
| 11 | + { |
| 12 | + { IntPtr.Zero, true }, |
| 13 | + { (IntPtr)1, false } |
| 14 | + }; |
| 15 | + |
| 16 | + [Theory] |
| 17 | + [MemberData(nameof(GetTestIsNullData))] |
| 18 | + public void TestIsNull(IntPtr ptr, bool expected) |
| 19 | + { |
| 20 | + Check.That(ptr.IsNull()).IsEqualTo(expected); |
| 21 | + } |
| 22 | + |
| 23 | + public static TheoryData<IntPtr, bool> GetTestMayBeValidData => new TheoryData<IntPtr, bool> |
| 24 | + { |
| 25 | + { IntPtr.Zero, false }, |
| 26 | + { (IntPtr)1, false }, |
| 27 | + { (IntPtr)0x10000, true }, |
| 28 | + { (IntPtr)int.MaxValue, true }, |
| 29 | +#if RECLASSNET64 |
| 30 | + { (IntPtr)long.MaxValue + 1, false } |
| 31 | +#else |
| 32 | + { (IntPtr)int.MaxValue + 1, false } |
| 33 | +#endif |
| 34 | + }; |
| 35 | + |
| 36 | + [Theory] |
| 37 | + [MemberData(nameof(GetTestMayBeValidData))] |
| 38 | + public void TestMayBeValid(IntPtr ptr, bool expected) |
| 39 | + { |
| 40 | + Check.That(ptr.MayBeValid()).IsEqualTo(expected); |
| 41 | + } |
| 42 | + |
| 43 | + public static TheoryData<IntPtr, IntPtr, IntPtr, bool> GetTestIsInRangeData => new TheoryData<IntPtr, IntPtr, IntPtr, bool> |
| 44 | + { |
| 45 | + { (IntPtr)10, (IntPtr)100, (IntPtr)1000, false }, |
| 46 | + { (IntPtr)100, (IntPtr)100, (IntPtr)1000, true }, |
| 47 | + { (IntPtr)500, (IntPtr)100, (IntPtr)1000, true }, |
| 48 | + { (IntPtr)1000, (IntPtr)100, (IntPtr)1000, true }, |
| 49 | + { (IntPtr)1500, (IntPtr)100, (IntPtr)1000, false } |
| 50 | + }; |
| 51 | + |
| 52 | + [Theory] |
| 53 | + [MemberData(nameof(GetTestIsInRangeData))] |
| 54 | + public void TestIsInRange(IntPtr ptr, IntPtr start, IntPtr end, bool expected) |
| 55 | + { |
| 56 | + Check.That(ptr.IsInRange(start, end)).IsEqualTo(expected); |
| 57 | + } |
| 58 | + |
| 59 | + public static TheoryData<IntPtr, IntPtr, int> GetTestCompareToData => new TheoryData<IntPtr, IntPtr, int> |
| 60 | + { |
| 61 | + { (IntPtr)10, (IntPtr)100, -1 }, |
| 62 | + { (IntPtr)100, (IntPtr)100, 0 }, |
| 63 | + { (IntPtr)500, (IntPtr)100, 1 } |
| 64 | + }; |
| 65 | + |
| 66 | + [Theory] |
| 67 | + [MemberData(nameof(GetTestCompareToData))] |
| 68 | + public void TestCompareTo(IntPtr ptr, IntPtr other, int expected) |
| 69 | + { |
| 70 | + Check.That(ptr.CompareTo(other)).IsEqualTo(expected); |
| 71 | + } |
| 72 | + |
| 73 | + public static TheoryData<IntPtr, IntPtr, IntPtr, int> GetTestCompareToRangeData => new TheoryData<IntPtr, IntPtr, IntPtr, int> |
| 74 | + { |
| 75 | + { (IntPtr)10, (IntPtr)100, (IntPtr)1000, -1 }, |
| 76 | + { (IntPtr)100, (IntPtr)100, (IntPtr)1000, 0 }, |
| 77 | + { (IntPtr)500, (IntPtr)100, (IntPtr)1000, 0 }, |
| 78 | + { (IntPtr)1000, (IntPtr)100, (IntPtr)1000, 0 }, |
| 79 | + { (IntPtr)1500, (IntPtr)100, (IntPtr)1000, 1 } |
| 80 | + }; |
| 81 | + |
| 82 | + [Theory] |
| 83 | + [MemberData(nameof(GetTestCompareToRangeData))] |
| 84 | + public void TestCompareToRange(IntPtr ptr, IntPtr start, IntPtr end, int expected) |
| 85 | + { |
| 86 | + Check.That(ptr.CompareToRange(start, end)).IsEqualTo(expected); |
| 87 | + } |
| 88 | + |
| 89 | + public static TheoryData<IntPtr, long> GetTestToInt64BitsData => new TheoryData<IntPtr, long> |
| 90 | + { |
| 91 | + { (IntPtr)0x10, 0x10L }, |
| 92 | + { (IntPtr)int.MaxValue, 0x7FFF_FFFFL }, |
| 93 | + { (IntPtr)int.MaxValue + 1, 0x8000_0000L } |
| 94 | + }; |
| 95 | + |
| 96 | + [Theory] |
| 97 | + [MemberData(nameof(GetTestToInt64BitsData))] |
| 98 | + public void TestToInt64Bits(IntPtr ptr, long expected) |
| 99 | + { |
| 100 | + Check.That(ptr.ToInt64Bits()).IsEqualTo(expected); |
| 101 | + } |
| 102 | + } |
| 103 | +} |
0 commit comments