2011-04-11 01:54:52 +08:00
|
|
|
/*
|
2016-09-18 19:17:03 +08:00
|
|
|
* Copyright (c) 2009-2016 Petri Lehtinen <petri@digip.org>
|
2011-04-11 01:54:52 +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.
|
|
|
|
*/
|
|
|
|
|
2019-10-17 14:08:51 +08:00
|
|
|
#include "util.h"
|
2011-04-11 01:54:52 +08:00
|
|
|
#include <jansson.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2019-10-17 14:08:51 +08:00
|
|
|
static void run_tests() {
|
2011-04-11 01:54:52 +08:00
|
|
|
json_t *json;
|
|
|
|
json_error_t error;
|
|
|
|
const char str[] = "[\"A\", {\"B\": \"C\"}, 1, 2, 3]garbage";
|
|
|
|
size_t len = strlen(str) - strlen("garbage");
|
|
|
|
|
|
|
|
json = json_loadb(str, len, 0, &error);
|
2019-10-17 14:08:51 +08:00
|
|
|
if (!json) {
|
2011-04-11 01:54:52 +08:00
|
|
|
fail("json_loadb failed on a valid JSON buffer");
|
|
|
|
}
|
|
|
|
json_decref(json);
|
|
|
|
|
|
|
|
json = json_loadb(str, len - 1, 0, &error);
|
|
|
|
if (json) {
|
|
|
|
json_decref(json);
|
2019-10-17 14:08:51 +08:00
|
|
|
fail("json_loadb should have failed on an incomplete buffer, but it "
|
|
|
|
"didn't");
|
2011-04-11 01:54:52 +08:00
|
|
|
}
|
2019-10-17 14:08:51 +08:00
|
|
|
if (error.line != 1) {
|
2011-04-11 01:54:52 +08:00
|
|
|
fail("json_loadb returned an invalid line number on fail");
|
|
|
|
}
|
2019-10-17 14:08:51 +08:00
|
|
|
if (strcmp(error.text, "']' expected near end of file") != 0) {
|
|
|
|
fail("json_loadb returned an invalid error message for an unclosed "
|
|
|
|
"top-level array");
|
2011-04-11 01:54:52 +08:00
|
|
|
}
|
|
|
|
}
|