5
from pykd import numVariant
7
class IntBaseTest( unittest.TestCase ):
11
a = numVariant(0xFFFF)
12
a = numVariant(0xFFFFFFFF)
13
a = numVariant(0x8000000000000000)
14
a = numVariant(0xFFFFFFFFFFFFFFFF)
17
a = numVariant(-200000)
18
a = numVariant(-20000000000)
19
a = numVariant( True )
21
self.assertRaises(OverflowError, numVariant, -0xFFFFFFFFFFFFFFFF )
22
self.assertRaises(OverflowError, numVariant, 0x10000000000000000 )
26
self.assertTrue( 0xFF == numVariant(0xFF) and numVariant(0xFF) == 0xFF )
27
self.assertTrue( 0xFFFF == numVariant(0xFFFF) and 0xFFFF == numVariant(0xFFFF) )
28
self.assertTrue( 0xFFFFFFFF == numVariant(0xFFFFFFFF) and numVariant(0xFFFFFFFF) == 0xFFFFFFFF )
29
self.assertTrue( 0x8000000000000000 == numVariant(0x8000000000000000) )
30
self.assertTrue( 0xFFFFFFFFFFFFFFFF == numVariant(0xFFFFFFFFFFFFFFFF) )
31
self.assertTrue( -20 == numVariant(-20) )
32
self.assertTrue( -2000 == numVariant(-2000) )
33
self.assertTrue( -0x7FFFFFFF == numVariant(-0x7FFFFFFF) )
34
self.assertTrue( -20000000000 == numVariant(-20000000000) )
35
self.assertTrue( -0x7fffffffffffffff == numVariant(-0x7fffffffffffffff) )
36
#self.assertTrue( numVariant(0x20L) == numVariant(0x20) )
37
self.assertTrue( True == numVariant(True) )
38
self.assertTrue( False == numVariant(0) )
39
self.assertTrue( True == numVariant(1) )
40
self.assertTrue( numVariant(1) == numVariant(1) )
43
self.assertTrue( 0xFE != numVariant(0xFF) )
44
self.assertTrue( 0xFF00 != numVariant(0xFFFF) )
45
self.assertTrue( 0xFFFFFF88 != numVariant(0xFFFFFFFF) )
46
self.assertTrue( 0x8000000000000000 - 1 != numVariant(0x8000000000000000) )
47
self.assertTrue( 0xFFFFFFFFFFFFFFFF - 1 != numVariant(0xFFFFFFFFFFFFFFFF) )
48
self.assertTrue( -20 + 1 != numVariant(-20) )
49
self.assertTrue( -2000 + 1 != numVariant(-2000) )
50
self.assertTrue( -20000000000 + 1 != numVariant(-20000000000) )
51
self.assertTrue( -0x8000000000000000 - 1 != numVariant(-0x7fffffffffffffff) )
52
self.assertTrue( numVariant(1) != numVariant(2) )
55
self.assertTrue( 0xFE < numVariant(0xFF) and numVariant(0xFE) < 0xFF )
56
self.assertFalse( -99 < numVariant(-100) and numVariant(-99) < - 100 )
57
self.assertTrue( 0xFFFFFFFFFFFFFFFE < numVariant(0xFFFFFFFFFFFFFFFF) )
58
self.assertFalse(0xFFFFFFFFFFFFFFFF < numVariant(0xFFFFFFFFFFFFFFFE) )
59
self.assertTrue( numVariant(0xFFFFFFFFFFFFFFFE) < 0xFFFFFFFFFFFFFFFF )
60
self.assertTrue( numVariant(1) < numVariant(2) )
63
self.assertTrue( 0xFE <= numVariant(0xFF) and numVariant(0xFE) <= 0xFF )
64
self.assertTrue( 0xFF <= numVariant(0xFF) )
65
self.assertFalse( -99 <= numVariant(-100) and numVariant(-99) <= - 100 )
66
self.assertTrue( 0xFFFFFFFFFFFFFFFE <= numVariant(0xFFFFFFFFFFFFFFFF) )
67
self.assertFalse(0xFFFFFFFFFFFFFFFF <= numVariant(0xFFFFFFFFFFFFFFFE) )
68
self.assertTrue( numVariant(0xFFFFFFFFFFFFFFFF) <= 0xFFFFFFFFFFFFFFFF )
69
self.assertFalse( numVariant(1) >= numVariant(2) )
72
self.assertEqual( 10, numVariant(5) + 5 )
73
self.assertEqual( 10, 5 + numVariant(5) )
76
self.assertEqual( 20, a )
77
self.assertEqual( -20, numVariant(-10) + (-10) )
78
self.assertEqual( 10, numVariant(-10) + 20 )
79
self.assertEqual( 0x7fffffffffffffff + 1, numVariant(0x7fffffffffffffff) + 1)
80
self.assertEqual( -0x7fffffffffffffff + 10, numVariant(-0x7fffffffffffffff) + 10 )
81
self.assertEqual( 0, numVariant(-0x7fffffffffffffff) + 0x7fffffffffffffff )
82
self.assertEqual( 5, numVariant(3) + numVariant(2) )
85
self.assertEqual( 0, numVariant(5) - 5 )
86
self.assertEqual( 10, 15 - numVariant(5) )
89
self.assertEqual( 5, a )
90
self.assertEqual( -20, numVariant(-10) -10 )
91
self.assertEqual( -10, 10 - numVariant(20) )
92
self.assertEqual( -0xFFFFFFFF - 1, numVariant(-0xFFFFFFFF) - 1 )
93
self.assertEqual( 5, numVariant(7) - numVariant(2) )
96
self.assertEqual( 4, numVariant(2) * 2 )
97
self.assertEqual( 4, 2 * numVariant(2) )
98
self.assertEqual( -4, 2 * numVariant(-2) )
99
self.assertEqual( 4, -2 * numVariant(-2) )
100
self.assertEqual( 0x7fffffffffffffff * 2, numVariant(0x7fffffffffffffff) * 2)
101
self.assertEqual( 0x80000000*2, numVariant(0x80000000)*2 )
102
self.assertEqual( -0x80000000*2, 2 * numVariant(-0x80000000))
103
self.assertEqual( 14, numVariant(7)*numVariant(2) )
106
self.assertEqual( 1, numVariant(2) / 2 )
107
self.assertEqual( 2, 5 / numVariant(2) )
108
self.assertEqual( -1, 2 / numVariant(-2) )
109
self.assertEqual( 1, -2 / numVariant(-2) )
110
self.assertEqual( 3, numVariant(7)/numVariant(2) )
112
self.assertRaises(ZeroDivisionError, lambda x: -2 / numVariant(0), 0 )
113
self.assertRaises(ZeroDivisionError, lambda x: numVariant(2)/0, 0 )
114
self.assertRaises(ZeroDivisionError, lambda x: numVariant(0)/numVariant(0), 0 )
116
def testDivFloor(self):
117
self.assertEqual(0, numVariant(1) // 2 )
118
self.assertEqual(numVariant(1) // 2, 0 )
121
self.assertEqual( 1, numVariant(3) % 2 )
122
self.assertEqual( 0, numVariant(3) % 3 )
123
self.assertEqual( 1, 3 % numVariant(2) )
124
self.assertEqual( 0, 3 % numVariant(3) )
125
self.assertEqual( 2, numVariant(5) % numVariant(3) )
127
def testShift( self ):
128
self.assertEqual( 0xFFFFFFFF >> 8, numVariant(0xFFFFFFFF) >> 8 )
129
self.assertEqual( 0x00FFFFFF << 8, numVariant(0x00FFFFFF) << 8 )
130
self.assertEqual( 0xFFFFFFFF >> 8, 0xFFFFFFFF >> numVariant(8) )
131
self.assertEqual( 0x00FFFFFF << 8, 0x00FFFFFF << numVariant(8) )
134
self.assertEqual( 0xFFFFFFFF & 0xFFFF, numVariant(0xFFFFFFFF) & 0xFFFF )
135
self.assertEqual( 0xFFFFFFFF & 0xFFFF, 0xFFFFFFFF & numVariant(0xFFFF) )
136
self.assertEqual( -0xFFFFFFFF & 0xFFFF, numVariant(-0xFFFFFFFF) & 0xFFFF )
137
self.assertEqual( -0xFFFFFFFF & 0xFFFF, -0xFFFFFFFF & numVariant(0xFFFF) )
140
self.assertEqual( 0xFFFF0000 | 0xFFFF, numVariant(0xFFFF0000) | 0xFFFF )
141
self.assertEqual( 0xFFFF0000 | 0xFFFF, 0xFFFF0000 | numVariant(0xFFFF) )
142
self.assertEqual( -0xFFFF0000 | 0xFFFF, numVariant(-0xFFFF0000) | 0xFFFF )
143
self.assertEqual( -0xFFFF0000 | 0xFFFF, -0xFFFF0000 | numVariant(0xFFFF) )
146
self.assertEqual( 0xFFFFFFFF ^ 0xFFFF, numVariant(0xFFFFFFFF) ^ 0xFFFF )
147
self.assertEqual( 0xFFFFFFFF ^ 0xFFFF, 0xFFFFFFFF ^ numVariant(0xFFFF) )
148
self.assertEqual( -0xFFFFFFFF ^ 0xFFFF, numVariant(-0xFFFFFFFF) ^ 0xFFFF )
149
self.assertEqual( -0xFFFFFFFF ^ 0xFFFF, -0xFFFFFFFF ^ numVariant(0xFFFF) )
151
def testUnary( self ):
152
self.assertEqual( -0xFFFFFFFF, -numVariant(0xFFFFFFFF) )
153
self.assertEqual( 0xFFFFFFFF, +numVariant(0xFFFFFFFF) )
154
self.assertEqual( 0, ~numVariant(0xFFFFFFFF) )
156
def testLongConvert( self ):
157
self.assertEqual( "100", "%d" % numVariant(100) )
158
self.assertEqual( "64", "%x" % numVariant(100) )
159
self.assertEqual( "FFFF", "%X" % numVariant(0xFFFF) )
160
self.assertEqual( "-70000000000", "%d" % numVariant(-70000000000) )
161
self.assertEqual( "FFFFFFFFFFFFFF", "%X" % numVariant(0xFFFFFFFFFFFFFF) )
162
self.assertEqual( "0", "%d" % numVariant(False) )
164
def testFloatConvert(self):
165
self.assertEqual( "1.0", "%1.1f" % float(numVariant(1.0)))
166
self.assertEqual( "1", "%d" % int(numVariant(1.0)))
167
self.assertEqual( "1.0", "%1.1f" % numVariant(1.0))
168
self.assertEqual( "1", "%d" % numVariant(1.0))
171
self.assertEqual( "100", str(numVariant(100)) )
174
self.assertEqual( "0x64", hex(numVariant(100)) )