diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2016-08-01 22:11:07 +0200 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2016-08-01 22:11:07 +0200 |
commit | 4ac5f8bbbd6e007ecd02be46bfbc0c11de010722 (patch) | |
tree | 5baef202153147b396ba5b377da2e88cb62ae19a /unittest/test.cc | |
parent | 137a28c05ceacd0427fe1fb25b5a184d6b96985c (diff) | |
download | libnitrokey-4ac5f8bbbd6e007ecd02be46bfbc0c11de010722.tar.gz libnitrokey-4ac5f8bbbd6e007ecd02be46bfbc0c11de010722.tar.bz2 |
C++ tests: use get_payload() function to clear packet before using
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'unittest/test.cc')
-rw-r--r-- | unittest/test.cc | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/unittest/test.cc b/unittest/test.cc index 02f742c..6267512 100644 --- a/unittest/test.cc +++ b/unittest/test.cc @@ -11,9 +11,11 @@ using namespace std; using namespace nitrokey::device; using namespace nitrokey::proto::stick10; using namespace nitrokey::log; +using namespace nitrokey::misc; + std::string getSlotName(Stick10 &stick, int slotNo) { - ReadSlot::CommandTransaction::CommandPayload slot_req; + auto slot_req = get_payload<ReadSlot>(); slot_req.slot_number = slotNo; auto slot = ReadSlot::CommandTransaction::run(stick, slot_req); std::string sName(reinterpret_cast<char *>(slot.slot_name)); @@ -29,16 +31,17 @@ TEST_CASE("Slot names are correct", "[slotNames]") { auto resp = GetStatus::CommandTransaction::run(stick); - FirstAuthenticate::CommandTransaction::CommandPayload authreq; + auto authreq = get_payload<FirstAuthenticate>(); strcpy((char *)(authreq.card_password), "12345678"); FirstAuthenticate::CommandTransaction::run(stick, authreq); { - EnablePasswordSafe::CommandTransaction::CommandPayload authreq; - strcpy((char *)(authreq.password), "123456"); + auto authreq = get_payload<EnablePasswordSafe>(); + strcpy((char *)(authreq.user_password), "123456"); EnablePasswordSafe::CommandTransaction::run(stick, authreq); } + //assuming these values were set earlier, thus failing on normal use REQUIRE(getSlotName(stick, 0x20) == std::string("1")); REQUIRE(getSlotName(stick, 0x21) == std::string("slot2")); @@ -52,7 +55,7 @@ TEST_CASE("Slot names are correct", "[slotNames]") { } { - GetPasswordSafeSlotName::CommandTransaction::CommandPayload slot; + auto slot = get_payload<GetPasswordSafeSlotName>(); slot.slot_number = 0; auto resp2 = GetPasswordSafeSlotName::CommandTransaction::run(stick, slot); std::string sName(reinterpret_cast<char *>(resp2.slot_name)); @@ -60,7 +63,7 @@ TEST_CASE("Slot names are correct", "[slotNames]") { } { - GetPasswordSafeSlotPassword::CommandTransaction::CommandPayload slot; + auto slot = get_payload<GetPasswordSafeSlotPassword>(); slot.slot_number = 0; auto resp2 = GetPasswordSafeSlotPassword::CommandTransaction::run(stick, slot); @@ -69,7 +72,7 @@ TEST_CASE("Slot names are correct", "[slotNames]") { } { - GetPasswordSafeSlotLogin::CommandTransaction::CommandPayload slot; + auto slot = get_payload<GetPasswordSafeSlotLogin>(); slot.slot_number = 0; auto resp2 = GetPasswordSafeSlotLogin::CommandTransaction::run(stick, slot); std::string sName(reinterpret_cast<char *>(resp2.slot_login)); |