pykd

Форк
0
/
intbase.py 
173 строки · 8.5 Кб
1

2
import unittest
3
import target
4
import sys
5
from pykd import numVariant
6

7
class IntBaseTest( unittest.TestCase ):
8

9
    def testCtor( self ):
10
        a = numVariant(0xFF)
11
        a = numVariant(0xFFFF)
12
        a = numVariant(0xFFFFFFFF)
13
        a = numVariant(0x8000000000000000)
14
        a = numVariant(0xFFFFFFFFFFFFFFFF)
15
        a = numVariant(-20)
16
        a = numVariant(-2000)
17
        a = numVariant(-200000)
18
        a = numVariant(-20000000000) 
19
        a = numVariant( True )
20

21
        self.assertRaises(OverflowError, numVariant, -0xFFFFFFFFFFFFFFFF )
22
        self.assertRaises(OverflowError, numVariant, 0x10000000000000000 )
23

24
        
25
    def testEq( self ):
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) )
41
        
42
    def testNe( self ):
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) )
53
        
54
    def testLtGt( self ):
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) )
61
        
62
    def testLeGe( self ):
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) )
70
                
71
    def testAdd( self ):
72
        self.assertEqual( 10, numVariant(5) + 5 )
73
        self.assertEqual( 10, 5 + numVariant(5) )
74
        a = 10
75
        a += numVariant(10)
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) )
83

84
    def testSub( self ):
85
        self.assertEqual( 0, numVariant(5) - 5 )
86
        self.assertEqual( 10, 15 - numVariant(5) )
87
        a = 10
88
        a -= 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) )
94
        
95
    def testMul( self ):
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) )
104
        
105
    def testDiv( self ):
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) )
111

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 )
115

116
    def testDivFloor(self):
117
        self.assertEqual(0, numVariant(1) // 2 )
118
        self.assertEqual(numVariant(1) // 2, 0 )
119
            
120
    def testMod( self ):
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) )
126
        
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) )
132
    
133
    def testAnd( self ):
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) )
138
        
139
    def testOr( self ):
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) )        
144
        
145
    def testXor( self ):
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) )        
150
        
151
    def testUnary( self ):
152
        self.assertEqual( -0xFFFFFFFF, -numVariant(0xFFFFFFFF) )
153
        self.assertEqual( 0xFFFFFFFF, +numVariant(0xFFFFFFFF) )
154
        self.assertEqual( 0, ~numVariant(0xFFFFFFFF) )
155
        
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) )
163

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))
169
        
170
    def testStr(self):
171
        self.assertEqual( "100", str(numVariant(100)) )
172

173
    def testHex(self):
174
        self.assertEqual( "0x64", hex(numVariant(100)) )
175

176

177

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.