Corrected unit test for the abort PDU message.

This commit is contained in:
skarg
2006-10-07 13:29:30 +00:00
parent 434fd34b02
commit 8d9c621e89
2 changed files with 46 additions and 18 deletions
+44 -17
View File
@@ -78,7 +78,8 @@ int abort_decode_service_request(uint8_t * apdu,
/* decode the whole APDU - mainly used for unit testing */
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;
@@ -88,6 +89,10 @@ int abort_decode_apdu(uint8_t * apdu,
if (apdu_len) {
if ((apdu[0] & 0xF0) != PDU_TYPE_ABORT)
return -1;
if (apdu[0] & 1)
*server = true;
else
*server = false;
if (apdu_len > 1) {
len = abort_decode_service_request(&apdu[1],
apdu_len - 1, invoke_id, abort_reason);
@@ -97,54 +102,76 @@ int abort_decode_apdu(uint8_t * apdu,
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)
{
uint8_t apdu[480] = { 0 };
int len = 0;
int apdu_len = 0;
uint8_t invoke_id = 0;
uint8_t abort_reason = 0;
uint8_t test_invoke_id = 0;
uint8_t 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);
apdu_len = len;
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, test_invoke_id == invoke_id);
ct_test(pTest, test_abort_reason == abort_reason);
ct_test(pTest, test_server == server);
/* change type to get negative response */
apdu[0] = PDU_TYPE_REJECT;
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);
/* test NULL APDU */
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);
/* force a zero length */
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);
/* check them all... */
for (invoke_id = 0; invoke_id < 255; invoke_id++) {
for (abort_reason = 0; abort_reason < 255; abort_reason++) {
len = abort_encode_apdu(&apdu[0], invoke_id, abort_reason);
apdu_len = len;
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);
testAbortAPDU(pTest, invoke_id, abort_reason, false);
testAbortAPDU(pTest, invoke_id, abort_reason, true);
}
}
}
+2 -1
View File
@@ -50,7 +50,8 @@ extern "C" {
#ifdef TEST
#include "ctest.h"
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);
#endif