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.

61 lines
1.0 KiB

  1. #ifndef __CMPTEST_H__
  2. #define __CMPTEST_H__
  3. #include <assert.h>
  4. #include <stdio.h>
  5. #include <stdint.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include "sodium.h"
  9. #ifndef TEST_SRCDIR
  10. # define TEST_SRCDIR "."
  11. #endif
  12. #define TEST_NAME_RES TEST_NAME ".res"
  13. #define TEST_NAME_OUT TEST_SRCDIR "/" TEST_NAME ".exp"
  14. #ifdef HAVE_ARC4RANDOM
  15. # undef rand
  16. # define rand(X) arc4random(X)
  17. #endif
  18. FILE *fp_res;
  19. int xmain(void);
  20. int main(void)
  21. {
  22. FILE *fp_out;
  23. int c;
  24. if ((fp_res = fopen(TEST_NAME_RES, "w+")) == NULL) {
  25. perror("fopen(" TEST_NAME_RES ")");
  26. return 99;
  27. }
  28. if (sodium_init() != 0) {
  29. return 99;
  30. }
  31. if (xmain() != 0) {
  32. return 99;
  33. }
  34. rewind(fp_res);
  35. if ((fp_out = fopen(TEST_NAME_OUT, "r")) == NULL) {
  36. perror("fopen(" TEST_NAME_OUT ")");
  37. return 99;
  38. }
  39. do {
  40. if ((c = fgetc(fp_res)) != fgetc(fp_out)) {
  41. return 99;
  42. }
  43. } while (c != EOF);
  44. return 0;
  45. }
  46. #undef printf
  47. #define printf(...) fprintf(fp_res, __VA_ARGS__)
  48. #define main xmain
  49. #endif