diff --git a/test/mifare_classic_fixture.c b/test/mifare_classic_fixture.c index 9dbfe52..3588d33 100644 --- a/test/mifare_classic_fixture.c +++ b/test/mifare_classic_fixture.c @@ -14,14 +14,14 @@ setup () cut_assert_not_null (device, cut_message ("No device found")); tags = mifare_classic_get_tags (device); - cut_assert_not_null (tags, cut_message ("Error enumerating NFC tags")); + cut_assert_not_null (tags, cut_message ("mifare_classic_get_tags() failed")); - cut_assert_not_null (tags[0], cut_message ("No MIFARE CLassic tag on NFC device")); + cut_assert_not_null (tags[0], cut_message ("No MIFARE Classic tag on NFC device")); tag = tags[0]; res = mifare_classic_connect (tag); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_connect() failed")); } void diff --git a/test/test_mad.c b/test/test_mad.c index 2706115..e26aedd 100644 --- a/test/test_mad.c +++ b/test/test_mad.c @@ -9,21 +9,21 @@ test_mad (void) int res; Mad mad = mad_new (1); - cut_assert_not_null (mad); + cut_assert_not_null (mad, cut_message ("Can create a new MAD")); - cut_assert_equal_int (1, mad_get_version (mad)); + cut_assert_equal_int (1, mad_get_version (mad), cut_message ("Wrong default MAD version")); mad_set_version (mad, 2); - cut_assert_equal_int (2, mad_get_version (mad)); + cut_assert_equal_int (2, mad_get_version (mad), cut_message ("Can't change MAD version")); - cut_assert_equal_int (0, mad_get_card_publisher_sector (mad)); + cut_assert_equal_int (0, mad_get_card_publisher_sector (mad), cut_message ("Wrong default MAD publisher")); res = mad_set_card_publisher_sector (mad, 13); - cut_assert_equal_int (res, 0); - cut_assert_equal_int (13, mad_get_card_publisher_sector (mad)); + cut_assert_equal_int (0, res, cut_message ("mad_set_card_publisher_sector() returned an error.")); + cut_assert_equal_int (13, mad_get_card_publisher_sector (mad), cut_message ("Wrong publisher sector")); res = mad_set_card_publisher_sector (mad, 0xff); - cut_assert_equal_int (res, -1); - cut_assert_equal_int (13, mad_get_card_publisher_sector (mad)); + cut_assert_equal_int (-1, res, cut_message ("Invalid sector")); + cut_assert_equal_int (13, mad_get_card_publisher_sector (mad), cut_message ("Previous publisher sector value")); MadAid aid = { .function_cluster_code = 0, @@ -31,19 +31,19 @@ test_mad (void) }; res = mad_get_aid (mad, 3, &aid); - cut_assert_equal_int (0, res); - cut_assert_equal_int (0, aid.function_cluster_code); - cut_assert_equal_int (0, aid.application_code); + cut_assert_equal_int (0, res, cut_message ("mad_get_aid() failed")); + cut_assert_equal_int (0, aid.function_cluster_code, cut_message ("Invalid default value")); + cut_assert_equal_int (0, aid.application_code, cut_message ("Invalid default value")); aid.function_cluster_code = 0xc0; aid.application_code = 0x42; res = mad_set_aid (mad, 3, aid); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mad_set_aid() failed")); res = mad_get_aid (mad, 3, &aid); - cut_assert_equal_int (0, res); - cut_assert_equal_int (0xC0, aid.function_cluster_code); - cut_assert_equal_int (0x42, aid.application_code); + cut_assert_equal_int (0, res, cut_message ("mad_get_aid() failed")); + cut_assert_equal_int (0xC0, aid.function_cluster_code, cut_message ("Invalid value")); + cut_assert_equal_int (0x42, aid.application_code, cut_message ("Invalid value")); mad_free (mad); } @@ -59,7 +59,7 @@ test_mad_crc8_basic (void) /* Insert data */ crc = 0x00; crc8(&crc, crc_value); - cut_assert_equal_int (crc_value, crc); + cut_assert_equal_int (crc_value, crc, cut_message ("Initialization should not produce a CRC")); /* Insert data with leading zeros */ crc = 0x00; @@ -69,7 +69,7 @@ test_mad_crc8_basic (void) crc8(&crc, 0x00); crc8(&crc, 0x00); crc8(&crc, crc_value); - cut_assert_equal_int (crc_value, crc); + cut_assert_equal_int (crc_value, crc, cut_message ("Burst error should not be detected with uninitialized polies")); /* Check integrity */ crc = CRC_PRESET; @@ -80,7 +80,7 @@ test_mad_crc8_basic (void) crc = CRC_PRESET; crc8(&crc, crc_value); crc8(&crc, save); - cut_assert_equal_int (0x00, crc); + cut_assert_equal_int (0x00, crc, cut_message ("CRC should verify crc(message + crc(message)) = 0")); } /* @@ -134,7 +134,7 @@ test_mad_crc8_doc_example (void) /* Append zeros of augmented message */ crc8(&crc, 0x00); - cut_assert_equal_int (0x89, crc); + cut_assert_equal_int (0x89, crc, cut_message ("Sample CRC should match")); } /* @@ -188,7 +188,7 @@ test_mad_crc8_real_example_1 (void) /* Append zeros of augmented message */ crc8(&crc, 0x00); - cut_assert_equal_int (0xc4, crc); + cut_assert_equal_int (0xc4, crc, cut_message ("Read example 1 CRC should match")); } /* @@ -242,7 +242,7 @@ test_mad_crc8_real_example_2 (void) /* Append zeros of augmented message */ crc8(&crc, 0x00); - cut_assert_equal_int (0xab, crc); + cut_assert_equal_int (0xab, crc, cut_message ("Read example 1 CRC should match")); } void @@ -250,7 +250,7 @@ test_mad_sector_0x00_crc8 (void) { int res; Mad mad = mad_new (1); - cut_assert_not_null (mad); + cut_assert_not_null (mad, cut_message ("mad_new() failed")); res = mad_set_card_publisher_sector (mad, 0x01); @@ -283,7 +283,7 @@ test_mad_sector_0x00_crc8 (void) mad_set_aid (mad, 15, aid5); res = sector_0x00_crc8 (mad); - cut_assert_equal_int(0x89, res); + cut_assert_equal_int(0x89, res, cut_message ("Sample CRC should match")); mad_free (mad); } diff --git a/test/test_mifare_classic.c b/test/test_mifare_classic.c index 6c52ef8..451f9c7 100644 --- a/test/test_mifare_classic.c +++ b/test/test_mifare_classic.c @@ -11,7 +11,7 @@ test_mifare_classic_authenticate (void) int res; MifareClassicKey k = { 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5 }; res = mifare_classic_authenticate (tag, 0x00, k, MFC_KEY_A); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_authenticate() failed")); } void @@ -23,16 +23,16 @@ test_mifare_classic_read_sector_0 (void) MifareClassicKey k = { 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5 }; res = mifare_classic_authenticate (tag, 0x00, k, MFC_KEY_A); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_authenticate() failed")); MifareClassicBlock r; res = mifare_classic_read (tag, 0x00, &r); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_read() failed")); MifareClassicBlock e = { 0xba, 0xc7, 0x7a, 0xfc, 0xfb, 0x88, 0x04, 0x00 , 0x46, 0x5d, 0x55, 0x96, 0x41, 0x10, 0x19, 0x08 }; - cut_assert_equal_memory (e, sizeof (e), r, sizeof (r)); + cut_assert_equal_memory (e, sizeof (e), r, sizeof (r), cut_message ("Unexpected sector 0 value")); } void @@ -42,29 +42,29 @@ test_mifare_classic_get_data_block_permission (void) MifareClassicKey k = { 0xd3, 0xf7, 0xd3, 0xf7, 0xd3, 0xf7 }; res = mifare_classic_authenticate (tag, 0x04, k, MFC_KEY_A); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_authenticate() failed")); - cut_assert_equal_int (1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_R, MFC_KEY_A) ); - cut_assert_equal_int (1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_R, MFC_KEY_B) ); - cut_assert_equal_int (1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_W, MFC_KEY_A) ); - cut_assert_equal_int (1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_W, MFC_KEY_B) ); - cut_assert_equal_int (1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_D, MFC_KEY_A) ); - cut_assert_equal_int (1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_D, MFC_KEY_B) ); - cut_assert_equal_int (1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_I, MFC_KEY_A) ); - cut_assert_equal_int (1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_I, MFC_KEY_B) ); + cut_assert_equal_int (1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_R, MFC_KEY_A), cut_message ("Wrong permission")); + cut_assert_equal_int (1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_R, MFC_KEY_B), cut_message ("Wrong permission")); + cut_assert_equal_int (1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_W, MFC_KEY_A), cut_message ("Wrong permission")); + cut_assert_equal_int (1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_W, MFC_KEY_B), cut_message ("Wrong permission")); + cut_assert_equal_int (1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_D, MFC_KEY_A), cut_message ("Wrong permission")); + cut_assert_equal_int (1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_D, MFC_KEY_B), cut_message ("Wrong permission")); + cut_assert_equal_int (1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_I, MFC_KEY_A), cut_message ("Wrong permission")); + cut_assert_equal_int (1, mifare_classic_get_data_block_permission(tag, 0x04, MCAB_I, MFC_KEY_B), cut_message ("Wrong permission")); - cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_READ_KEYA, MFC_KEY_A) ); - cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_READ_KEYA, MFC_KEY_B) ); - cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_WRITE_KEYA, MFC_KEY_A) ); - cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_WRITE_KEYA, MFC_KEY_B) ); - cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_READ_ACCESS_BITS, MFC_KEY_A) ); - cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_READ_ACCESS_BITS, MFC_KEY_B) ); - cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_WRITE_ACCESS_BITS, MFC_KEY_A) ); - cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_WRITE_ACCESS_BITS, MFC_KEY_B) ); - cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_READ_KEYB, MFC_KEY_A) ); - cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_READ_KEYB, MFC_KEY_B) ); - cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_WRITE_KEYB, MFC_KEY_A) ); - cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_WRITE_KEYB, MFC_KEY_B) ); + cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_READ_KEYA, MFC_KEY_A), cut_message ("Wrong permission")); + cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_READ_KEYA, MFC_KEY_B), cut_message ("Wrong permission")); + cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_WRITE_KEYA, MFC_KEY_A), cut_message ("Wrong permission")); + cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_WRITE_KEYA, MFC_KEY_B), cut_message ("Wrong permission")); + cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_READ_ACCESS_BITS, MFC_KEY_A), cut_message ("Wrong permission")); + cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_READ_ACCESS_BITS, MFC_KEY_B), cut_message ("Wrong permission")); + cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_WRITE_ACCESS_BITS, MFC_KEY_A), cut_message ("Wrong permission")); + cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_WRITE_ACCESS_BITS, MFC_KEY_B), cut_message ("Wrong permission")); + cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_READ_KEYB, MFC_KEY_A), cut_message ("Wrong permission")); + cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_READ_KEYB, MFC_KEY_B), cut_message ("Wrong permission")); + cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_WRITE_KEYB, MFC_KEY_A), cut_message ("Wrong permission")); + cut_assert_equal_int (-1, mifare_classic_get_trailer_block_permission(tag, 0x04, MCAB_WRITE_KEYB, MFC_KEY_B), cut_message ("Wrong permission")); } void @@ -74,36 +74,36 @@ test_mifare_classic_get_trailer_permission (void) MifareClassicKey k = { 0xd3, 0xf7, 0xd3, 0xf7, 0xd3, 0xf7 }; res = mifare_classic_authenticate (tag, 0x07, k, MFC_KEY_A); - cut_assert_equal_int (res, 0); + cut_assert_equal_int (res, 0, cut_message ("mifare_classic_authenticate() failed")); - cut_assert_equal_int (-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_R, MFC_KEY_A) ); - cut_assert_equal_int (-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_R, MFC_KEY_B) ); - cut_assert_equal_int (-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_W, MFC_KEY_A) ); - cut_assert_equal_int (-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_W, MFC_KEY_B) ); - cut_assert_equal_int (-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_D, MFC_KEY_A) ); - cut_assert_equal_int (-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_D, MFC_KEY_B) ); - cut_assert_equal_int (-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_I, MFC_KEY_A) ); - cut_assert_equal_int (-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_I, MFC_KEY_B) ); + cut_assert_equal_int (-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_R, MFC_KEY_A), cut_message ("Wrong permission")); + cut_assert_equal_int (-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_R, MFC_KEY_B), cut_message ("Wrong permission")); + cut_assert_equal_int (-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_W, MFC_KEY_A), cut_message ("Wrong permission")); + cut_assert_equal_int (-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_W, MFC_KEY_B), cut_message ("Wrong permission")); + cut_assert_equal_int (-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_D, MFC_KEY_A), cut_message ("Wrong permission")); + cut_assert_equal_int (-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_D, MFC_KEY_B), cut_message ("Wrong permission")); + cut_assert_equal_int (-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_I, MFC_KEY_A), cut_message ("Wrong permission")); + cut_assert_equal_int (-1, mifare_classic_get_data_block_permission(tag, 0x07, MCAB_I, MFC_KEY_B), cut_message ("Wrong permission")); - cut_assert_equal_int (0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_READ_KEYA, MFC_KEY_A) ); - cut_assert_equal_int (0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_READ_KEYA, MFC_KEY_B) ); - cut_assert_equal_int (0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_WRITE_KEYA, MFC_KEY_A) ); - cut_assert_equal_int (1, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_WRITE_KEYA, MFC_KEY_B) ); - cut_assert_equal_int (1, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_READ_ACCESS_BITS, MFC_KEY_A) ); - cut_assert_equal_int (1, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_READ_ACCESS_BITS, MFC_KEY_B) ); - cut_assert_equal_int (0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_WRITE_ACCESS_BITS, MFC_KEY_A) ); - cut_assert_equal_int (1, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_WRITE_ACCESS_BITS, MFC_KEY_B) ); - cut_assert_equal_int (0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_READ_KEYB, MFC_KEY_A) ); - cut_assert_equal_int (0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_READ_KEYB, MFC_KEY_B) ); - cut_assert_equal_int (0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_WRITE_KEYB, MFC_KEY_A) ); - cut_assert_equal_int (1, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_WRITE_KEYB, MFC_KEY_B) ); + cut_assert_equal_int (0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_READ_KEYA, MFC_KEY_A), cut_message ("Wrong permission")); + cut_assert_equal_int (0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_READ_KEYA, MFC_KEY_B), cut_message ("Wrong permission")); + cut_assert_equal_int (0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_WRITE_KEYA, MFC_KEY_A), cut_message ("Wrong permission")); + cut_assert_equal_int (1, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_WRITE_KEYA, MFC_KEY_B), cut_message ("Wrong permission")); + cut_assert_equal_int (1, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_READ_ACCESS_BITS, MFC_KEY_A), cut_message ("Wrong permission")); + cut_assert_equal_int (1, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_READ_ACCESS_BITS, MFC_KEY_B), cut_message ("Wrong permission")); + cut_assert_equal_int (0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_WRITE_ACCESS_BITS, MFC_KEY_A), cut_message ("Wrong permission")); + cut_assert_equal_int (1, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_WRITE_ACCESS_BITS, MFC_KEY_B), cut_message ("Wrong permission")); + cut_assert_equal_int (0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_READ_KEYB, MFC_KEY_A), cut_message ("Wrong permission")); + cut_assert_equal_int (0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_READ_KEYB, MFC_KEY_B), cut_message ("Wrong permission")); + cut_assert_equal_int (0, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_WRITE_KEYB, MFC_KEY_A), cut_message ("Wrong permission")); + cut_assert_equal_int (1, mifare_classic_get_trailer_block_permission(tag, 0x07, MCAB_WRITE_KEYB, MFC_KEY_B), cut_message ("Wrong permission")); } void test_mifare_classic_read_mad (void) { Mad mad = mad_read (tag); - cut_assert_not_null (mad); + cut_assert_not_null (mad, cut_message ("mad_read() failed")); } void @@ -113,7 +113,7 @@ test_mifare_classic_format (void) MifareClassicKey k = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; res = mifare_classic_authenticate (tag, 0x3c, k, MFC_KEY_A); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_authenticate() failed")); MifareClassicBlock data = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, @@ -124,30 +124,30 @@ test_mifare_classic_format (void) memset (empty, '\x00', sizeof (empty)); res = mifare_classic_write (tag, 0x3c, data); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_write() failed")); res = mifare_classic_write (tag, 0x3d, data); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_write() failed")); res = mifare_classic_write (tag, 0x3e, data); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_write() failed")); res = mifare_classic_format_sector (tag, 0x0f); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_format_sector() failed")); res = mifare_classic_read (tag, 0x3c, &data); - cut_assert_equal_int (0, res); - cut_assert_equal_memory (data, sizeof (data), empty, sizeof (data)); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_read() failed")); + cut_assert_equal_memory (data, sizeof (data), empty, sizeof (data), cut_message ("Wrong data in formatted sector (block 1/3)")); res = mifare_classic_read (tag, 0x3d, &data); - cut_assert_equal_int (0, res); - cut_assert_equal_memory (data, sizeof (data), empty, sizeof (data)); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_read() failed")); + cut_assert_equal_memory (data, sizeof (data), empty, sizeof (data), cut_message ("Wrong data in formatted sector (block 2/3)")); res = mifare_classic_read (tag, 0x3e, &data); - cut_assert_equal_int (0, res); - cut_assert_equal_memory (data, sizeof (data), empty, sizeof (data)); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_read() failed")); + cut_assert_equal_memory (data, sizeof (data), empty, sizeof (data), cut_message ("Wrong data in formatted sector (block 3/3)")); res = mifare_classic_read (tag, 0x3f, &data); - cut_assert_equal_int (0, res); - cut_assert_equal_memory (data, sizeof (data), "\x00\x00\x00\x00\x00\x00\xff\x07\x80\x69\xff\xff\xff\xff\xff\xff", sizeof (data)); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_read() failed")); + cut_assert_equal_memory (data, sizeof (data), "\x00\x00\x00\x00\x00\x00\xff\x07\x80\x69\xff\xff\xff\xff\xff\xff", sizeof (data), cut_message ("Wrong permissions in formatted sector")); } @@ -159,45 +159,45 @@ test_mifare_classic_value_block_increment (void) MifareClassicBlockNumber block = 0x04; MifareClassicKey k = { 0xd3, 0xf7, 0xd3, 0xf7, 0xd3, 0xf7 }; res = mifare_classic_authenticate (tag, block, k, MFC_KEY_A); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_authenticate() failed")); res = mifare_classic_init_value (tag, block, 1000, 0x00); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_init_value() failed")); /* Initialize value block */ int32_t value; MifareClassicBlockNumber adr; res = mifare_classic_read_value (tag, block, &value, &adr); - cut_assert_equal_int (0, res); - cut_assert_equal_int (1000, value); - cut_assert_equal_int (0x00, adr); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_read_value() failed")); + cut_assert_equal_int (1000, value, cut_message ("Wrong value block value")); + cut_assert_equal_int (0x00, adr, cut_message ("Wrong value block address")); /* Increment by 1 */ res = mifare_classic_increment (tag, block, 1); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_increment() failed")); res = mifare_classic_transfer (tag, block); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_transfer() failed")); res = mifare_classic_read_value (tag, block, &value, &adr); - cut_assert_equal_int (0, res); - cut_assert_equal_int (1001, value); - cut_assert_equal_int (0x00, adr); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_read_value() failed")); + cut_assert_equal_int (1001, value, cut_message ("Wrong value block value")); + cut_assert_equal_int (0x00, adr, cut_message ("Wrong value block address")); /* Increment by 10 */ res = mifare_classic_increment (tag, block, 10); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_increment() failed")); res = mifare_classic_transfer (tag, block); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_transfer() failed")); res = mifare_classic_read_value (tag, block, &value, &adr); - cut_assert_equal_int (0, res); - cut_assert_equal_int (1011, value); - cut_assert_equal_int (0x00, adr); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_read_value() failed")); + cut_assert_equal_int (1011, value, cut_message ("Wrong value block value")); + cut_assert_equal_int (0x00, adr, cut_message ("Wrong value block address")); } void @@ -208,43 +208,43 @@ test_mifare_classic_value_block_decrement (void) MifareClassicBlockNumber block = 0x04; MifareClassicKey k = { 0xd3, 0xf7, 0xd3, 0xf7, 0xd3, 0xf7 }; res = mifare_classic_authenticate (tag, block, k, MFC_KEY_A); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_authenticate() failed")); res = mifare_classic_init_value (tag, block, 1000, 0x00); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_init_value() failed")); /* Initialize value block */ int32_t value; MifareClassicBlockNumber adr; res = mifare_classic_read_value (tag, block, &value, &adr); - cut_assert_equal_int (0, res); - cut_assert_equal_int (1000, value); - cut_assert_equal_int (0x00, adr); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_read_value() failed")); + cut_assert_equal_int (1000, value, cut_message ("Wrong value block value")); + cut_assert_equal_int (0x00, adr, cut_message ("Wrong value block address")); /* Decrement */ res = mifare_classic_decrement (tag, block, 1); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_decrement() failed")); res = mifare_classic_transfer (tag, block); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_transfer() failed")); res = mifare_classic_read_value (tag, block, &value, &adr); - cut_assert_equal_int (0, res); - cut_assert_equal_int (999, value); - cut_assert_equal_int (0x00, adr); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_read_value() failed")); + cut_assert_equal_int (999, value, cut_message ("Wrong value block value")); + cut_assert_equal_int (0x00, adr, cut_message ("Wrong value block address")); res = mifare_classic_decrement (tag, block, 1000); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_decrement() failed")); res = mifare_classic_transfer (tag, block); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_transfer() failed")); res = mifare_classic_read_value (tag, block, &value, &adr); - cut_assert_equal_int (0, res); - cut_assert_equal_int (-1, value); - cut_assert_equal_int (0x00, adr); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_read_value() failed")); + cut_assert_equal_int (-1, value, cut_message ("Wrong value block value")); + cut_assert_equal_int (0x00, adr, cut_message ("Wrong value block address")); } void @@ -255,7 +255,7 @@ test_mifare_classic_value_block_restore (void) MifareClassicBlockNumber block = 0x04; MifareClassicKey k = { 0xd3, 0xf7, 0xd3, 0xf7, 0xd3, 0xf7 }; res = mifare_classic_authenticate (tag, block, k, MFC_KEY_A); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_authenticate() failed")); /* Restore */ @@ -282,26 +282,26 @@ test_mifare_classic_value_block_restore (void) }; res = mifare_classic_write (tag, block, sample); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_write() failed")); res = mifare_classic_read (tag, block, &data); - cut_assert_equal_int (0, res); - cut_assert_equal_memory (sample, sizeof (sample), data, sizeof (data)); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_read() failed")); + cut_assert_equal_memory (sample, sizeof (sample), data, sizeof (data), cut_message ("Wrong value block contents")); res = mifare_classic_write (tag, block+1, nul); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_write() failed")); res = mifare_classic_read (tag, block+1, &data); - cut_assert_equal_int (0, res); - cut_assert_equal_memory (nul, sizeof (sample), data, sizeof (data)); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_read() failed")); + cut_assert_equal_memory (nul, sizeof (sample), data, sizeof (data), cut_message ("Wrong value block contents")); res = mifare_classic_restore (tag, block); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_restore() failed")); res = mifare_classic_transfer (tag, block+1); - cut_assert_equal_int (0, res); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_transfer() failed")); res = mifare_classic_read (tag, block+1, &data); - cut_assert_equal_int (0, res); - cut_assert_equal_memory (sample, sizeof (sample), data, sizeof (data)); + cut_assert_equal_int (0, res, cut_message ("mifare_classic_read() failed")); + cut_assert_equal_memory (sample, sizeof (sample), data, sizeof (data), cut_message ("Wrong value block contents")); } diff --git a/test/test_mifare_classic_application.c b/test/test_mifare_classic_application.c index c244983..89296d4 100644 --- a/test/test_mifare_classic_application.c +++ b/test/test_mifare_classic_application.c @@ -9,20 +9,20 @@ test_mifare_classic_application (void) MadAid aid = { 0x22, 0x42 }; Mad mad = mad_new (2); - cut_assert_not_null (mad); + cut_assert_not_null (mad, cut_message ("mad_new() failed")); MifareSectorNumber *s_alloc = mifare_application_alloc (mad, aid, 3); - cut_assert_not_null (s_alloc); + cut_assert_not_null (s_alloc, cut_message ("mifare_application_alloc() failed")); MifareSectorNumber *s_found = mifare_application_find (mad, aid); - cut_assert_not_null (s_found); + cut_assert_not_null (s_found, cut_message ("mifare_application_alloc() failed")); for (int i = 0; i < 3; i++) { - cut_assert_equal_int (s_alloc[i], s_found[i]); + cut_assert_equal_int (s_alloc[i], s_found[i], cut_message ("Allocated and foudn blocks don't match")); } - cut_assert_equal_int (0, s_alloc[3]); - cut_assert_equal_int (0, s_found[3]); + cut_assert_equal_int (0, s_alloc[3], cut_message ("Invalid size")); + cut_assert_equal_int (0, s_found[3], cut_message ("Invalid size")); mifare_application_free (mad, aid); @@ -30,7 +30,7 @@ test_mifare_classic_application (void) free (s_found); s_found = mifare_application_find (mad, aid); - cut_assert_null (s_found); + cut_assert_null (s_found, cut_message ("mifare_application_free() failed")); mad_free (mad); } diff --git a/test/test_mifare_classic_create_trailer_block.c b/test/test_mifare_classic_create_trailer_block.c index 692fdd1..d109a55 100644 --- a/test/test_mifare_classic_create_trailer_block.c +++ b/test/test_mifare_classic_create_trailer_block.c @@ -12,6 +12,6 @@ test_mifare_classic_create_trailer_block (void) mifare_classic_trailer_block (&data, key_a, 0, 0, 0, 4, 0x42, key_b); - cut_assert_equal_memory (data, sizeof (data), "\xff\xff\xff\xff\xff\xff\xff\x07\x80\x42\xde\xad\xbe\xef\xff\xff", sizeof (data)); + cut_assert_equal_memory (data, sizeof (data), "\xff\xff\xff\xff\xff\xff\xff\x07\x80\x42\xde\xad\xbe\xef\xff\xff", sizeof (data), cut_message ("Wrong generated block")); }