1 #ifndef __TEST_UTIL_H__
2 #define __TEST_UTIL_H__
6 static int vtokeq(
const char *s,
jsmntok_t *t,
int numtok, va_list ap) {
8 int i, start, end, size;
14 for (i = 0; i < numtok; i++) {
15 type = va_arg(ap,
int);
17 value = va_arg(ap,
char *);
18 size = va_arg(ap,
int);
21 value = va_arg(ap,
char *);
22 start = end = size = -1;
24 start = va_arg(ap,
int);
25 end = va_arg(ap,
int);
26 size = va_arg(ap,
int);
29 if (t[i].type != type) {
30 printf(
"token %d type is %d, not %d\n", i, t[i].type, type);
33 if (start != -1 && end != -1) {
34 if (t[i].start != start) {
35 printf(
"token %d start is %d, not %d\n", i, t[i].start, start);
38 if (t[i].end != end ) {
39 printf(
"token %d end is %d, not %d\n", i, t[i].end, end);
43 if (size != -1 && t[i].size != size) {
44 printf(
"token %d size is %d, not %d\n", i, t[i].size, size);
48 if (s != NULL && value != NULL) {
49 const char *p = s + t[i].
start;
50 if (strlen(value) != t[i].end - t[i].start ||
51 strncmp(p, value, t[i].end - t[i].start) != 0) {
52 printf(
"token %d value is %.*s, not %s\n", i, t[i].end-t[i].start,
62 static int tokeq(
const char *s,
jsmntok_t *tokens,
int numtok, ...) {
65 va_start(args, numtok);
66 ok = vtokeq(s, tokens, numtok, args);
71 static int parse(
const char *s,
int status,
int numtok, ...) {
81 printf(
"status is %d, not %d\n", r, status);
86 va_start(args, numtok);
87 ok = vtokeq(s, t, numtok, args);
JSON token description.
Definition: jsmn.h:40
JSON parser.
Definition: jsmn.h:54
int start
Definition: jsmn.h:42
int jsmn_parse(jsmn_parser *parser, const char *js, size_t len, jsmntok_t *tokens, unsigned int num_tokens)
Parse JSON string and fill tokens.
Definition: jsmn.c:151
void jsmn_init(jsmn_parser *parser)
Creates a new parser based over a given buffer with an array of tokens available. ...
Definition: jsmn.c:309