aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenryk Plötz <henryk@ploetzli.ch>2010-10-15 15:00:27 +0200
committerHenryk Plötz <henryk@ploetzli.ch>2010-10-15 17:08:08 +0200
commiteb61017dab2c329510526af2b3c1a675cf3c74a1 (patch)
treee78719787a892579b9412dfaa3e90078fe6f09ac
parenta8d72543e97fe96837cbbcdf14b5247fdf876203 (diff)
Add unit tests for ADPU class
-rw-r--r--tests/__init__.py1
-rw-r--r--tests/__main__.py5
-rw-r--r--tests/utilstest.py38
3 files changed, 44 insertions, 0 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..0d6dac5
--- /dev/null
+++ b/tests/__init__.py
@@ -0,0 +1 @@
+from utilstest import *
diff --git a/tests/__main__.py b/tests/__main__.py
new file mode 100644
index 0000000..df956d9
--- /dev/null
+++ b/tests/__main__.py
@@ -0,0 +1,5 @@
+import unittest
+from tests import *
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tests/utilstest.py b/tests/utilstest.py
new file mode 100644
index 0000000..65b74b6
--- /dev/null
+++ b/tests/utilstest.py
@@ -0,0 +1,38 @@
+"""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())
+