Add lots of tests for pack/unpack code, fix bugs found
[jansson.git] / test / suites / api / util.h
1 /*
2  * Copyright (c) 2009-2011 Petri Lehtinen <petri@digip.org>
3  *
4  * Jansson is free software; you can redistribute it and/or modify
5  * it under the terms of the MIT license. See LICENSE for details.
6  */
7
8 #ifndef UTIL_H
9 #define UTIL_H
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <jansson.h>
14
15 #define failhdr fprintf(stderr, "%s:%s:%d: ", __FILE__, __FUNCTION__, __LINE__)
16
17 #define fail(msg)                                                \
18     do {                                                         \
19         failhdr;                                                 \
20         fprintf(stderr, "%s\n", msg);                            \
21         exit(1);                                                 \
22     } while(0)
23
24 /* Assumes json_error_t error */
25 #define check_error(text_, source_, line_, column_, position_)          \
26     do {                                                                \
27         if(strcmp(error.text, text_) != 0) {                            \
28             failhdr;                                                    \
29             fprintf(stderr, "text: \"%s\" != \"%s\"\n", error.text, text_); \
30             exit(1);                                                    \
31         }                                                               \
32         if(strcmp(error.source, source_) != 0) {                        \
33             failhdr;                                                    \
34                                                                         \
35             fprintf(stderr, "source: \"%s\" != \"%s\"\n", error.source, source_); \
36             exit(1);                                                    \
37         }                                                               \
38         if(error.line != line_) {                                       \
39             failhdr;                                                    \
40             fprintf(stderr, "line: %d != %d\n", error.line, line_);     \
41             exit(1);                                                    \
42         }                                                               \
43         if(error.column != column_) {                                   \
44             failhdr;                                                    \
45             fprintf(stderr, "column: %d != %d\n", error.column, column_); \
46             exit(1);                                                    \
47         }                                                               \
48         if(error.position != position_) {                               \
49             failhdr;                                                    \
50             fprintf(stderr, "position: %d != %d\n", error.position, position_); \
51             exit(1);                                                    \
52         }                                                               \
53     } while(0)
54
55 #endif