-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c
More file actions
36 lines (31 loc) · 984 Bytes
/
test.c
File metadata and controls
36 lines (31 loc) · 984 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "jsonw.h"
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
char *buf = NULL;
while (*++argv) {
// printf("parsing %s\n", *argv);
long size;
FILE *fp = fopen(*argv, "r");
if (fp == NULL)
perror("fopen"), exit(EXIT_FAILURE);
if (fseek(fp, 0, SEEK_END) == -1)
perror("fseek"), exit(EXIT_FAILURE);
if ((size = ftell(fp)) == -1)
perror("ftell"), exit(EXIT_FAILURE);
rewind(fp);
buf = realloc(buf, size + 1);
if (fread(buf, 1, size, fp) != size)
perror("fread"), exit(EXIT_FAILURE);
buf[size] = '\0';
if (fclose(fp) == EOF)
perror("fclose"), exit(EXIT_FAILURE);
char *end = jsonw_text(NULL, buf);
bool valid = end && end - buf == size;
if (**argv == 'y' && !valid || **argv == 'n' && valid)
printf("test failed: %s:\n%s\n", *argv, buf);
if (**argv != 'y' && **argv != 'n' && **argv != 'i')
printf("invalid test: %s\n", *argv);
}
free(buf);
}