libfreefare/test/test_mifare_application.c

64 lines
1.9 KiB
C
Raw Normal View History

2010-01-11 21:14:30 +01:00
#include <cutter.h>
#include <freefare.h>
void
2017-06-27 13:58:31 +02:00
test_mifare_application(void)
2010-01-11 21:14:30 +01:00
{
/* Card publisher part */
MadAid aid = { 0x22, 0x42 };
2017-06-27 13:58:31 +02:00
Mad mad = mad_new(2);
int i;
2017-06-27 13:58:31 +02:00
cut_assert_not_null(mad, cut_message("mad_new() failed"));
2010-01-11 21:14:30 +01:00
2017-06-27 13:58:31 +02:00
MifareClassicSectorNumber *s_alloc = mifare_application_alloc(mad, aid, 3 * 3 * 16);
cut_assert_not_null(s_alloc, cut_message("mifare_application_alloc() failed"));
2010-01-11 21:14:30 +01:00
2017-06-27 13:58:31 +02:00
MifareClassicSectorNumber *s_found = mifare_application_find(mad, aid);
cut_assert_not_null(s_found, cut_message("mifare_application_alloc() failed"));
2010-01-11 21:14:30 +01:00
for (i = 0; s_alloc[i]; i++) {
2017-06-27 13:58:31 +02:00
cut_assert_equal_int(s_alloc[i], s_found[i], cut_message("Allocated and found blocks don't match at position %d", i));
2010-01-11 21:14:30 +01:00
}
2017-06-27 13:58:31 +02:00
cut_assert_equal_int(0, s_alloc[i], cut_message("Invalid size"));
cut_assert_equal_int(0, s_found[i], cut_message("Invalid size"));
2010-01-11 21:14:30 +01:00
2017-06-27 13:58:31 +02:00
mifare_application_free(mad, aid);
2017-06-27 13:58:31 +02:00
free(s_alloc);
free(s_found);
2017-06-27 13:58:31 +02:00
s_found = mifare_application_find(mad, aid);
cut_assert_null(s_found, cut_message("mifare_application_free() failed"));
2017-06-27 13:58:31 +02:00
s_alloc = mifare_application_alloc(mad, aid, 15 * 16 + 1 * 16 + 1);
cut_assert_not_null(s_alloc, cut_message("mifare_application_alloc() failed"));
2017-06-27 13:58:31 +02:00
s_found = mifare_application_find(mad, aid);
cut_assert_not_null(s_found, cut_message("mifare_application_alloc() failed"));
for (i = 0; s_alloc[i]; i++) {
2017-06-27 13:58:31 +02:00
cut_assert_equal_int(s_alloc[i], s_found[i], cut_message("Allocated and found blocks don't match at position %d", i));
}
2017-06-27 13:58:31 +02:00
cut_assert_equal_int(0, s_alloc[i], cut_message("Invalid size"));
cut_assert_equal_int(0, s_found[i], cut_message("Invalid size"));
2017-06-27 13:58:31 +02:00
mifare_application_free(mad, aid);
2010-01-11 21:14:30 +01:00
2017-06-27 13:58:31 +02:00
free(s_alloc);
free(s_found);
2010-01-11 21:14:30 +01:00
2017-06-27 13:58:31 +02:00
s_found = mifare_application_find(mad, aid);
cut_assert_null(s_found, cut_message("mifare_application_free() failed"));
2010-01-11 21:14:30 +01:00
2017-06-27 13:58:31 +02:00
mad_free(mad);
2010-01-11 21:14:30 +01:00
}