| 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 | #ifdef HAVE_CONFIG_H |
|---|
| 12 | #include <config.h> |
|---|
| 13 | #endif |
|---|
| 14 | |
|---|
| 15 | #include <stdio.h> |
|---|
| 16 | #include <stdlib.h> |
|---|
| 17 | #if HAVE_LOCALE_H |
|---|
| 18 | #include <locale.h> |
|---|
| 19 | #endif |
|---|
| 20 | |
|---|
| 21 | #include <jansson.h> |
|---|
| 22 | |
|---|
| 23 | #define failhdr fprintf(stderr, "%s:%s:%d: ", __FILE__, __FUNCTION__, __LINE__) |
|---|
| 24 | |
|---|
| 25 | #define fail(msg) \ |
|---|
| 26 | do { \ |
|---|
| 27 | failhdr; \ |
|---|
| 28 | fprintf(stderr, "%s\n", msg); \ |
|---|
| 29 | exit(1); \ |
|---|
| 30 | } while(0) |
|---|
| 31 | |
|---|
| 32 | /* Assumes json_error_t error */ |
|---|
| 33 | #define check_error(text_, source_, line_, column_, position_) \ |
|---|
| 34 | do { \ |
|---|
| 35 | if(strcmp(error.text, text_) != 0) { \ |
|---|
| 36 | failhdr; \ |
|---|
| 37 | fprintf(stderr, "text: \"%s\" != \"%s\"\n", error.text, text_); \ |
|---|
| 38 | exit(1); \ |
|---|
| 39 | } \ |
|---|
| 40 | if(strcmp(error.source, source_) != 0) { \ |
|---|
| 41 | failhdr; \ |
|---|
| 42 | \ |
|---|
| 43 | fprintf(stderr, "source: \"%s\" != \"%s\"\n", error.source, source_); \ |
|---|
| 44 | exit(1); \ |
|---|
| 45 | } \ |
|---|
| 46 | if(error.line != line_) { \ |
|---|
| 47 | failhdr; \ |
|---|
| 48 | fprintf(stderr, "line: %d != %d\n", error.line, line_); \ |
|---|
| 49 | exit(1); \ |
|---|
| 50 | } \ |
|---|
| 51 | if(error.column != column_) { \ |
|---|
| 52 | failhdr; \ |
|---|
| 53 | fprintf(stderr, "column: %d != %d\n", error.column, column_); \ |
|---|
| 54 | exit(1); \ |
|---|
| 55 | } \ |
|---|
| 56 | if(error.position != position_) { \ |
|---|
| 57 | failhdr; \ |
|---|
| 58 | fprintf(stderr, "position: %d != %d\n", error.position, position_); \ |
|---|
| 59 | exit(1); \ |
|---|
| 60 | } \ |
|---|
| 61 | } while(0) |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | static void run_tests(); |
|---|
| 65 | |
|---|
| 66 | int main() { |
|---|
| 67 | #ifdef HAVE_SETLOCALE |
|---|
| 68 | setlocale(LC_ALL, ""); |
|---|
| 69 | #endif |
|---|
| 70 | run_tests(); |
|---|
| 71 | return 0; |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | #endif |
|---|