2009-08-25 22:50:41 +08:00
|
|
|
/*
|
2014-01-28 15:16:05 +08:00
|
|
|
* Copyright (c) 2009-2014 Petri Lehtinen <petri@digip.org>
|
2009-08-25 22:50:41 +08:00
|
|
|
*
|
|
|
|
* Jansson is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the MIT license. See LICENSE for details.
|
|
|
|
*/
|
|
|
|
|
2011-02-23 01:08:41 +08:00
|
|
|
#ifndef UTIL_H
|
|
|
|
#define UTIL_H
|
2009-08-19 02:33:45 +08:00
|
|
|
|
2011-10-03 02:27:53 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2014-01-14 00:13:44 +08:00
|
|
|
#include <jansson_private_config.h>
|
2011-10-03 02:27:53 +08:00
|
|
|
#endif
|
|
|
|
|
2011-02-23 01:08:41 +08:00
|
|
|
#include <stdio.h>
|
2009-09-30 02:19:55 +08:00
|
|
|
#include <stdlib.h>
|
2011-10-03 02:27:53 +08:00
|
|
|
#if HAVE_LOCALE_H
|
|
|
|
#include <locale.h>
|
|
|
|
#endif
|
|
|
|
|
2011-02-23 01:08:41 +08:00
|
|
|
#include <jansson.h>
|
|
|
|
|
2014-10-03 13:38:57 +08:00
|
|
|
#define failhdr fprintf(stderr, "%s:%d: ", __FILE__, __LINE__)
|
2009-09-30 02:19:55 +08:00
|
|
|
|
2009-08-19 02:33:45 +08:00
|
|
|
#define fail(msg) \
|
|
|
|
do { \
|
2011-02-23 01:08:41 +08:00
|
|
|
failhdr; \
|
|
|
|
fprintf(stderr, "%s\n", msg); \
|
2009-09-30 02:19:55 +08:00
|
|
|
exit(1); \
|
2009-08-19 02:33:45 +08:00
|
|
|
} while(0)
|
|
|
|
|
2011-02-23 01:08:41 +08:00
|
|
|
/* Assumes json_error_t error */
|
2015-12-18 08:56:22 +08:00
|
|
|
#define check_errors(texts_, num_, source_, line_, column_, position_) \
|
2011-02-23 01:08:41 +08:00
|
|
|
do { \
|
2015-12-18 08:56:22 +08:00
|
|
|
int i_, found_ = 0; \
|
|
|
|
for(i_ = 0; i_ < num_; i_++) { \
|
|
|
|
if(strcmp(error.text, texts_[i_]) == 0) { \
|
|
|
|
found_ = 1; \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
if (!found_) { \
|
2011-02-23 01:08:41 +08:00
|
|
|
failhdr; \
|
2015-12-18 08:56:22 +08:00
|
|
|
if (num_ == 1) { \
|
|
|
|
fprintf(stderr, "text: \"%s\" != \"%s\"\n", error.text, texts_[0]); \
|
|
|
|
} else { \
|
|
|
|
fprintf(stderr, "text: \"%s\" does not match\n", error.text); \
|
|
|
|
} \
|
2011-02-23 01:08:41 +08:00
|
|
|
exit(1); \
|
|
|
|
} \
|
|
|
|
if(strcmp(error.source, source_) != 0) { \
|
|
|
|
failhdr; \
|
|
|
|
\
|
|
|
|
fprintf(stderr, "source: \"%s\" != \"%s\"\n", error.source, source_); \
|
|
|
|
exit(1); \
|
|
|
|
} \
|
|
|
|
if(error.line != line_) { \
|
|
|
|
failhdr; \
|
|
|
|
fprintf(stderr, "line: %d != %d\n", error.line, line_); \
|
|
|
|
exit(1); \
|
|
|
|
} \
|
|
|
|
if(error.column != column_) { \
|
|
|
|
failhdr; \
|
|
|
|
fprintf(stderr, "column: %d != %d\n", error.column, column_); \
|
|
|
|
exit(1); \
|
|
|
|
} \
|
|
|
|
if(error.position != position_) { \
|
|
|
|
failhdr; \
|
|
|
|
fprintf(stderr, "position: %d != %d\n", error.position, position_); \
|
|
|
|
exit(1); \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
2011-10-03 02:27:53 +08:00
|
|
|
|
2015-12-18 08:56:22 +08:00
|
|
|
/* Assumes json_error_t error */
|
|
|
|
#define check_error(text_, source_, line_, column_, position_) \
|
|
|
|
check_errors(&text_, 1, source_, line_, column_, position_)
|
|
|
|
|
|
|
|
|
2011-10-03 02:27:53 +08:00
|
|
|
static void run_tests();
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
#ifdef HAVE_SETLOCALE
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
#endif
|
|
|
|
run_tests();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-19 02:33:45 +08:00
|
|
|
#endif
|