2013-07-29 16:49:55 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
2018-04-22 03:32:05 +02:00
|
|
|
Test for Data Encoding
|
2018-04-22 03:29:30 +02:00
|
|
|
|
2018-04-22 03:32:05 +02:00
|
|
|
All Packets tested here should be those which are SENT to the PT mainly.
|
|
|
|
you can see the incoming tests in parsing.
|
2018-04-22 03:29:30 +02:00
|
|
|
|
2018-04-22 03:32:05 +02:00
|
|
|
Lets test if packets are encoded right
|
2018-04-22 03:29:30 +02:00
|
|
|
|
2018-04-22 03:32:05 +02:00
|
|
|
Unter docs/examples finden sich dateien mit logs.
|
|
|
|
Diese Tests sehen nach ob unsere Klassen dieselben binären daten
|
|
|
|
erzeugen.
|
2013-07-29 16:49:55 +02:00
|
|
|
"""
|
|
|
|
|
2018-04-22 16:27:27 +02:00
|
|
|
from unittest import TestCase, main
|
2018-04-22 02:47:48 +02:00
|
|
|
|
2018-04-22 16:27:27 +02:00
|
|
|
from ecrterm.conv import toHexString
|
|
|
|
from ecrterm.packets.base_packets import (
|
2018-04-22 17:35:27 +02:00
|
|
|
Authorisation, Diagnosis, DisplayText, Initialisation, PacketReceived,
|
2019-08-23 15:43:49 +02:00
|
|
|
PacketReceivedError, PrintLine, Registration, ResetTerminal, StatusEnquiry, ReadCard)
|
2018-04-22 16:27:27 +02:00
|
|
|
from ecrterm.transmission.signals import ACK, NAK
|
|
|
|
from ecrterm.transmission.transport_serial import SerialMessage
|
2018-04-22 02:47:48 +02:00
|
|
|
|
2013-07-29 16:49:55 +02:00
|
|
|
|
|
|
|
def list_of_bytes(apdu):
|
|
|
|
sm = SerialMessage(apdu)
|
|
|
|
byte_list = sm.dump_message()
|
2018-04-22 03:32:05 +02:00
|
|
|
# return " ".join(["%02h" % i for i in byte_list])
|
2018-04-22 16:27:27 +02:00
|
|
|
return toHexString(byte_list)
|
2013-07-29 16:49:55 +02:00
|
|
|
|
2018-04-22 03:32:05 +02:00
|
|
|
|
2018-04-22 16:27:27 +02:00
|
|
|
class TestCaseDataEncoding(TestCase):
|
|
|
|
maxDiff = None
|
2013-07-29 16:49:55 +02:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_nakack(self):
|
|
|
|
self.assertEqual(chr(NAK), chr(0x15))
|
|
|
|
self.assertEqual(chr(ACK), chr(0x6))
|
|
|
|
|
|
|
|
def test_Anmeldung(self):
|
|
|
|
# Register Packet std.
|
2018-04-22 16:27:27 +02:00
|
|
|
data_expected = '10 02 06 00 06 12 34 56 BA 09 78 10 03 24 C3'
|
2019-06-29 00:42:41 +02:00
|
|
|
pk = Registration('123456', 0xBA, 978)
|
2013-07-29 16:49:55 +02:00
|
|
|
self.assertEqual(data_expected, list_of_bytes(pk))
|
|
|
|
|
|
|
|
def test_Initialisierung(self):
|
|
|
|
# Initialization Std.
|
2018-04-22 16:27:27 +02:00
|
|
|
data_expected = '10 02 06 93 03 12 34 56 10 03 CA A4'
|
2019-06-29 00:42:41 +02:00
|
|
|
pk = Initialisation('123456')
|
2013-07-29 16:49:55 +02:00
|
|
|
self.assertEqual(data_expected, list_of_bytes(pk))
|
|
|
|
|
|
|
|
def test_Zahlung_eccash(self):
|
|
|
|
# Authorisation
|
2018-04-22 16:27:27 +02:00
|
|
|
data_expected = \
|
|
|
|
'10 02 06 01 0A 04 00 00 00 01 10 10 00 49 09 78 10 03 F2 FF'
|
2013-07-29 16:49:55 +02:00
|
|
|
pk = Authorisation(amount=11000,
|
|
|
|
currency_code=978)
|
|
|
|
self.assertEqual(data_expected, list_of_bytes(pk))
|
|
|
|
|
|
|
|
def test_packet_diagnosis(self):
|
|
|
|
# Diagnosis
|
2018-04-22 16:27:27 +02:00
|
|
|
data_expected = '10 02 06 70 00 10 03 D9 F9'
|
2013-07-29 16:49:55 +02:00
|
|
|
pk = Diagnosis()
|
|
|
|
self.assertEqual(data_expected, list_of_bytes(pk))
|
|
|
|
|
|
|
|
def test_packet_printline(self):
|
|
|
|
# Print Line Packet
|
2018-04-22 16:27:27 +02:00
|
|
|
data_expected = \
|
|
|
|
'10 02 06 D1 19 00 47 65 73 61 6D 74 20 20 20 20 20 20 30 20 20 ' \
|
|
|
|
'20 20 20 20 20 30 2C 30 30 10 03 B5 AB'
|
|
|
|
pk = PrintLine(
|
|
|
|
text='Gesamt 0 0,00', attribute=0)
|
2013-07-29 16:49:55 +02:00
|
|
|
self.assertEqual(data_expected, list_of_bytes(pk))
|
|
|
|
|
|
|
|
def test_packet_received(self):
|
2018-04-22 16:27:27 +02:00
|
|
|
data_expected = '10 02 80 00 00 10 03 F5 1F'
|
2013-07-29 16:49:55 +02:00
|
|
|
pk = PacketReceived()
|
|
|
|
self.assertEqual(data_expected, list_of_bytes(pk))
|
|
|
|
|
|
|
|
def test_packet_received_error(self):
|
2018-04-22 16:27:27 +02:00
|
|
|
data_expected = '10 02 84 9C 00 10 03 C3 41'
|
2013-07-29 16:49:55 +02:00
|
|
|
pk = PacketReceivedError()
|
2019-06-29 00:42:41 +02:00
|
|
|
pk.cmd_instr = 0x9c
|
2013-07-29 16:49:55 +02:00
|
|
|
self.assertEqual(data_expected, list_of_bytes(pk))
|
|
|
|
|
|
|
|
def test_packet_resetterminal(self):
|
2018-04-22 16:27:27 +02:00
|
|
|
data_expected = '10 02 06 18 00 10 03 56 3A'
|
2013-07-29 16:49:55 +02:00
|
|
|
pk = ResetTerminal()
|
|
|
|
self.assertEqual(data_expected, list_of_bytes(pk))
|
|
|
|
|
|
|
|
def test_packet_showtext(self):
|
2018-04-22 16:27:27 +02:00
|
|
|
data_expected = \
|
2018-04-22 17:35:27 +02:00
|
|
|
'10 02 06 E0 25 F1 F1 F6 46 41 48 52 45 52 4E 55 4D 4D 45 52 20 ' \
|
|
|
|
'20 20 20 F2 F1 F5 45 49 4E 47 45 42 45 4E 20 55 4E 44 20 4F 4B ' \
|
|
|
|
'10 03 DE CD'
|
|
|
|
lines = ['FAHRERNUMMER ', 'EINGEBEN UND OK']
|
|
|
|
# FAHRERNUMMER:
|
2018-04-22 16:27:27 +02:00
|
|
|
# F1 F1 F6 46 41 48 52 45 52 4E 55 4D 4D 45 52 20 20 20 20
|
2018-04-22 17:35:27 +02:00
|
|
|
# EINGEBEN UND OK:
|
2018-04-22 16:27:27 +02:00
|
|
|
# F2 F1 F5 45 49 4E 47 45 42 45 4E 20 55 4E 44 20 4F 4B
|
2018-04-22 17:35:27 +02:00
|
|
|
pk = DisplayText(
|
2018-04-22 03:32:05 +02:00
|
|
|
# display_duration=0,
|
2013-07-29 16:49:55 +02:00
|
|
|
line1=lines[0],
|
2018-04-22 03:32:05 +02:00
|
|
|
# beeps=5,
|
2013-07-29 16:49:55 +02:00
|
|
|
line2=lines[1],
|
2018-04-22 03:32:05 +02:00
|
|
|
)
|
2013-07-29 16:49:55 +02:00
|
|
|
self.assertEqual(data_expected, list_of_bytes(pk))
|
|
|
|
|
|
|
|
def test_packet_statusenquiry(self):
|
2018-04-22 16:27:27 +02:00
|
|
|
data_expected = '10 02 05 01 03 12 34 56 10 03 E0 43'
|
2019-06-29 00:42:41 +02:00
|
|
|
pk = StatusEnquiry('123456')
|
2013-07-29 16:49:55 +02:00
|
|
|
self.assertEqual(data_expected, list_of_bytes(pk))
|
|
|
|
|
|
|
|
|
2019-08-23 15:43:49 +02:00
|
|
|
class TestReadCard(TestCase):
|
|
|
|
def test_read_card_1(self):
|
|
|
|
a = ReadCard(timeout=0x01, tlv={0x1F15: b'\xD0'})
|
|
|
|
self.assertEqual(bytearray.fromhex('06c0070106041f1501d0'), a.serialize())
|
|
|
|
|
|
|
|
|
2013-07-29 16:49:55 +02:00
|
|
|
if __name__ == '__main__':
|
2018-04-22 16:27:27 +02:00
|
|
|
main()
|