libsodium update: 1.0.0
[tomato.git] / release / src / router / libsodium / test / default / cmptest.h
blob156640c2eae36397d10f6c0814362fdc928368a4
2 #ifndef __CMPTEST_H__
3 #define __CMPTEST_H__
5 #include <assert.h>
6 #include <stdio.h>
7 #include <stdint.h>
8 #include <stdlib.h>
9 #include <string.h>
11 #include "sodium.h"
13 #ifndef TEST_SRCDIR
14 # define TEST_SRCDIR "."
15 #endif
17 #define TEST_NAME_RES TEST_NAME ".res"
18 #define TEST_NAME_OUT TEST_SRCDIR "/" TEST_NAME ".exp"
20 #ifdef HAVE_ARC4RANDOM
21 # undef rand
22 # define rand(X) arc4random(X)
23 #endif
25 FILE *fp_res;
26 int xmain(void);
28 int main(void)
30 FILE *fp_out;
31 int c;
33 if ((fp_res = fopen(TEST_NAME_RES, "w+")) == NULL) {
34 perror("fopen(" TEST_NAME_RES ")");
35 return 99;
37 if (sodium_init() != 0) {
38 return 99;
40 if (xmain() != 0) {
41 return 99;
43 rewind(fp_res);
44 if ((fp_out = fopen(TEST_NAME_OUT, "r")) == NULL) {
45 perror("fopen(" TEST_NAME_OUT ")");
46 return 99;
48 do {
49 if ((c = fgetc(fp_res)) != fgetc(fp_out)) {
50 return 99;
52 } while (c != EOF);
54 return 0;
57 #undef printf
58 #define printf(...) fprintf(fp_res, __VA_ARGS__)
59 #define main xmain
61 #endif