Corrected unit test for the abort PDU message.
This commit is contained in:
+44
-17
@@ -78,7 +78,8 @@ int abort_decode_service_request(uint8_t * apdu,
|
|||||||
|
|
||||||
/* decode the whole APDU - mainly used for unit testing */
|
/* decode the whole APDU - mainly used for unit testing */
|
||||||
int abort_decode_apdu(uint8_t * apdu,
|
int abort_decode_apdu(uint8_t * apdu,
|
||||||
unsigned apdu_len, uint8_t * invoke_id, uint8_t * abort_reason)
|
unsigned apdu_len, uint8_t * invoke_id, uint8_t * abort_reason,
|
||||||
|
bool * server)
|
||||||
{
|
{
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
|
||||||
@@ -88,6 +89,10 @@ int abort_decode_apdu(uint8_t * apdu,
|
|||||||
if (apdu_len) {
|
if (apdu_len) {
|
||||||
if ((apdu[0] & 0xF0) != PDU_TYPE_ABORT)
|
if ((apdu[0] & 0xF0) != PDU_TYPE_ABORT)
|
||||||
return -1;
|
return -1;
|
||||||
|
if (apdu[0] & 1)
|
||||||
|
*server = true;
|
||||||
|
else
|
||||||
|
*server = false;
|
||||||
if (apdu_len > 1) {
|
if (apdu_len > 1) {
|
||||||
len = abort_decode_service_request(&apdu[1],
|
len = abort_decode_service_request(&apdu[1],
|
||||||
apdu_len - 1, invoke_id, abort_reason);
|
apdu_len - 1, invoke_id, abort_reason);
|
||||||
@@ -97,54 +102,76 @@ int abort_decode_apdu(uint8_t * apdu,
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testAbortAPDU(Test * pTest,
|
||||||
|
uint8_t invoke_id,
|
||||||
|
uint8_t abort_reason,
|
||||||
|
bool server)
|
||||||
|
{
|
||||||
|
uint8_t apdu[480] = { 0 };
|
||||||
|
int len = 0;
|
||||||
|
int apdu_len = 0;
|
||||||
|
uint8_t test_invoke_id = 0;
|
||||||
|
uint8_t test_abort_reason = 0;
|
||||||
|
bool test_server = false;
|
||||||
|
|
||||||
|
len = abort_encode_apdu(&apdu[0], invoke_id, abort_reason, server);
|
||||||
|
apdu_len = len;
|
||||||
|
ct_test(pTest, len != 0);
|
||||||
|
len = abort_decode_apdu(&apdu[0],
|
||||||
|
apdu_len, &test_invoke_id, &test_abort_reason, &test_server);
|
||||||
|
ct_test(pTest, len != -1);
|
||||||
|
ct_test(pTest, test_invoke_id == invoke_id);
|
||||||
|
ct_test(pTest, test_abort_reason == abort_reason);
|
||||||
|
ct_test(pTest, test_server == server);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void testAbort(Test * pTest)
|
void testAbort(Test * pTest)
|
||||||
{
|
{
|
||||||
uint8_t apdu[480] = { 0 };
|
uint8_t apdu[480] = { 0 };
|
||||||
int len = 0;
|
int len = 0;
|
||||||
int apdu_len = 0;
|
int apdu_len = 0;
|
||||||
uint8_t invoke_id = 0;
|
uint8_t invoke_id = 0;
|
||||||
uint8_t abort_reason = 0;
|
|
||||||
uint8_t test_invoke_id = 0;
|
uint8_t test_invoke_id = 0;
|
||||||
|
uint8_t abort_reason = 0;
|
||||||
uint8_t test_abort_reason = 0;
|
uint8_t test_abort_reason = 0;
|
||||||
|
bool server = false;
|
||||||
|
bool test_server = false;
|
||||||
|
|
||||||
len = abort_encode_apdu(&apdu[0], invoke_id, abort_reason);
|
len = abort_encode_apdu(&apdu[0], invoke_id, abort_reason, server);
|
||||||
ct_test(pTest, len != 0);
|
ct_test(pTest, len != 0);
|
||||||
apdu_len = len;
|
apdu_len = len;
|
||||||
|
|
||||||
len = abort_decode_apdu(&apdu[0],
|
len = abort_decode_apdu(&apdu[0],
|
||||||
apdu_len, &test_invoke_id, &test_abort_reason);
|
apdu_len, &test_invoke_id, &test_abort_reason,
|
||||||
|
&test_server);
|
||||||
ct_test(pTest, len != -1);
|
ct_test(pTest, len != -1);
|
||||||
ct_test(pTest, test_invoke_id == invoke_id);
|
ct_test(pTest, test_invoke_id == invoke_id);
|
||||||
ct_test(pTest, test_abort_reason == abort_reason);
|
ct_test(pTest, test_abort_reason == abort_reason);
|
||||||
|
ct_test(pTest, test_server == server);
|
||||||
|
|
||||||
/* change type to get negative response */
|
/* change type to get negative response */
|
||||||
apdu[0] = PDU_TYPE_REJECT;
|
apdu[0] = PDU_TYPE_REJECT;
|
||||||
len = abort_decode_apdu(&apdu[0],
|
len = abort_decode_apdu(&apdu[0],
|
||||||
apdu_len, &test_invoke_id, &test_abort_reason);
|
apdu_len, &test_invoke_id, &test_abort_reason, &test_server);
|
||||||
ct_test(pTest, len == -1);
|
ct_test(pTest, len == -1);
|
||||||
|
|
||||||
/* test NULL APDU */
|
/* test NULL APDU */
|
||||||
len = abort_decode_apdu(NULL,
|
len = abort_decode_apdu(NULL,
|
||||||
apdu_len, &test_invoke_id, &test_abort_reason);
|
apdu_len, &test_invoke_id, &test_abort_reason, &test_server);
|
||||||
ct_test(pTest, len == -1);
|
ct_test(pTest, len == -1);
|
||||||
|
|
||||||
/* force a zero length */
|
/* force a zero length */
|
||||||
len = abort_decode_apdu(&apdu[0],
|
len = abort_decode_apdu(&apdu[0],
|
||||||
0, &test_invoke_id, &test_abort_reason);
|
0, &test_invoke_id, &test_abort_reason, &test_server);
|
||||||
ct_test(pTest, len == 0);
|
ct_test(pTest, len == 0);
|
||||||
|
|
||||||
|
|
||||||
/* check them all... */
|
/* check them all... */
|
||||||
for (invoke_id = 0; invoke_id < 255; invoke_id++) {
|
for (invoke_id = 0; invoke_id < 255; invoke_id++) {
|
||||||
for (abort_reason = 0; abort_reason < 255; abort_reason++) {
|
for (abort_reason = 0; abort_reason < 255; abort_reason++) {
|
||||||
len = abort_encode_apdu(&apdu[0], invoke_id, abort_reason);
|
testAbortAPDU(pTest, invoke_id, abort_reason, false);
|
||||||
apdu_len = len;
|
testAbortAPDU(pTest, invoke_id, abort_reason, true);
|
||||||
ct_test(pTest, len != 0);
|
|
||||||
len = abort_decode_apdu(&apdu[0],
|
|
||||||
apdu_len, &test_invoke_id, &test_abort_reason);
|
|
||||||
ct_test(pTest, len != -1);
|
|
||||||
ct_test(pTest, test_invoke_id == invoke_id);
|
|
||||||
ct_test(pTest, test_abort_reason == abort_reason);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ extern "C" {
|
|||||||
#ifdef TEST
|
#ifdef TEST
|
||||||
#include "ctest.h"
|
#include "ctest.h"
|
||||||
int abort_decode_apdu(uint8_t * apdu,
|
int abort_decode_apdu(uint8_t * apdu,
|
||||||
unsigned apdu_len, uint8_t * invoke_id, uint8_t * abort_reason);
|
unsigned apdu_len, uint8_t * invoke_id, uint8_t * abort_reason,
|
||||||
|
bool * server);
|
||||||
|
|
||||||
void testAbort(Test * pTest);
|
void testAbort(Test * pTest);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user