aboutsummaryrefslogtreecommitdiffstats
path: root/tests/utilstest.py
blob: 42d34f45e84dec86002a4df7fc93040686f78943 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""Unit test for utils.py"""

import utils
import unittest

class APDUCase1Tests(unittest.TestCase):
    
    def setUp(self):
        self.a4 = utils.C_APDU("\x00\xa4\x00\x00")
    
    def tearDown(self):
        del self.a4
    
    def testCreation(self):
        self.assertEqual(0, self.a4.CLA)
        self.assertEqual(0xa4, self.a4.INS)
        self.assertEqual(0, self.a4.P1)
        self.assertEqual(0, self.a4.P2)
    
    def testRender(self):
        self.assertEqual("\x00\xa4\x00\x00", self.a4.render())
    
    def testCopy(self):
        b0 = utils.C_APDU(self.a4, INS=0xb0)

        self.assertEqual("\x00\xb0\x00\x00", b0.render())
    
    def testAssign(self):
        self.a4.p2 = 5
        
        self.assertEqual(5, self.a4.P2)
        self.assertEqual("\x00\xa4\x00\x05", self.a4.render())
    
    def testCreateSequence(self):
        a4_2 = utils.C_APDU(0, 0xa4, 0, 0)
        
        self.assertEqual(self.a4.render(), a4_2.render())

class APDUChainTests(unittest.TestCase):
    
    def testChain(self):
        a = utils.R_APDU("abcd\x61\x04")
        b = utils.R_APDU("efgh\x90\x00")
        
        c = a.append(b)
        
        self.assertEqual("abcdefgh\x90\x00", c.render())