|
|
@ -0,0 +1,36 @@ |
|
|
|
#include "test.h" |
|
|
|
#include "util.h" |
|
|
|
|
|
|
|
#include <assert.h> |
|
|
|
#include <stdio.h> |
|
|
|
#include <stdlib.h> |
|
|
|
#include <string.h> |
|
|
|
|
|
|
|
#define ARR_SIZE 50 |
|
|
|
|
|
|
|
void test_read_file(void) { |
|
|
|
const char *filepath = tmpnam(NULL); |
|
|
|
|
|
|
|
uint8_t arr[ARR_SIZE] = {0}; |
|
|
|
for (size_t i = 0; i < sizeof arr; ++i) { |
|
|
|
arr[i] = rand() % 256; |
|
|
|
} |
|
|
|
|
|
|
|
FILE *fp = fopen(filepath, "wb"); |
|
|
|
assert(fp != NULL); |
|
|
|
|
|
|
|
fwrite(&arr[0], 1, ARR_SIZE, fp); |
|
|
|
fclose(fp); |
|
|
|
|
|
|
|
byte_arr_t *barr = read_file(filepath); |
|
|
|
assert(barr != NULL); |
|
|
|
assert(barr->size == ARR_SIZE); |
|
|
|
|
|
|
|
assert(memcmp(&arr[0], barr->data, ARR_SIZE) == 0); |
|
|
|
} |
|
|
|
|
|
|
|
const test_case_t TEST_CASES[] = { |
|
|
|
{"can read simple file", test_read_file}, |
|
|
|
}; |
|
|
|
|
|
|
|
const size_t NUM_TEST_CASES = sizeof TEST_CASES / sizeof TEST_CASES[0]; |