2016-07-26 09:57:05 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#define mu_assert(message, test) do { if (!(test)) return message; } while (0)
|
2016-08-01 15:33:32 +00:00
|
|
|
#define mu_run_test(test) do { char *message; printf(" - run: %s\n", #test); \
|
|
|
|
message = test(); tests_run++; \
|
2016-07-26 09:57:05 +00:00
|
|
|
if (message) return message; } while (0)
|
2016-08-10 13:46:15 +00:00
|
|
|
|
2016-07-26 09:57:05 +00:00
|
|
|
int tests_run = 0;
|
|
|
|
static char *mu_all_tests(void);
|
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
char *result = mu_all_tests();
|
2016-07-26 15:53:52 +00:00
|
|
|
if (result != NULL) {
|
|
|
|
printf("error: %s\n", result);
|
2016-07-27 09:45:53 +00:00
|
|
|
printf("!!! TEST FAILURE !!!\n");
|
2016-07-26 09:57:05 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("ALL TESTS PASSED\n");
|
|
|
|
}
|
|
|
|
printf("Tests run: %d\n", tests_run);
|
|
|
|
|
|
|
|
return result != 0;
|
|
|
|
}
|
|
|
|
|
2016-08-10 13:46:15 +00:00
|
|
|
void dump(const unsigned char *data, size_t size) {
|
|
|
|
char ascii[17];
|
|
|
|
size_t i, j;
|
|
|
|
ascii[16] = '\0';
|
|
|
|
for (i = 0; i < size; ++i) {
|
|
|
|
printf("%02X ", ((unsigned char*)data)[i]);
|
|
|
|
if (((unsigned char*)data)[i] >= ' ' && ((unsigned char*)data)[i] <= '~') {
|
|
|
|
ascii[i % 16] = ((unsigned char*)data)[i];
|
|
|
|
} else {
|
|
|
|
ascii[i % 16] = '.';
|
|
|
|
}
|
|
|
|
if ((i+1) % 8 == 0 || i+1 == size) {
|
|
|
|
printf(" ");
|
|
|
|
if ((i+1) % 16 == 0) {
|
|
|
|
printf("| %s \n", ascii);
|
|
|
|
} else if (i+1 == size) {
|
|
|
|
ascii[(i+1) % 16] = '\0';
|
|
|
|
if ((i+1) % 16 <= 8) {
|
|
|
|
printf(" ");
|
|
|
|
}
|
|
|
|
for (j = (i+1) % 16; j < 16; ++j) {
|
|
|
|
printf(" ");
|
|
|
|
}
|
|
|
|
printf("| %s \n", ascii);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|