psx emulator
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
765 B

  1. #include <assert.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include "test.h"
  6. #include "util.h"
  7. #define ARR_SIZE 50
  8. void test_read_file(void) {
  9. const char *filepath = tmpnam(NULL);
  10. uint8_t arr[ARR_SIZE] = {0};
  11. for (size_t i = 0; i < sizeof arr; ++i) {
  12. arr[i] = rand() % 256;
  13. }
  14. FILE *fp = fopen(filepath, "wb");
  15. assert(fp != NULL);
  16. fwrite(&arr[0], 1, ARR_SIZE, fp);
  17. fclose(fp);
  18. byte_arr_t *barr = read_file(filepath);
  19. assert(barr != NULL);
  20. assert(barr->size == ARR_SIZE);
  21. assert(memcmp(&arr[0], barr->data, ARR_SIZE) == 0);
  22. }
  23. const test_case_t TEST_CASES[] = {
  24. {"can read simple file", test_read_file},
  25. };
  26. const size_t NUM_TEST_CASES = sizeof TEST_CASES / sizeof TEST_CASES[0];