1/* 2 * Copyright (c) 2009-2014 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#include <jansson.h> 9#include <string.h> 10#include "util.h" 11 12static void run_tests() 13{ 14 json_t *json; 15 json_error_t error; 16 const char str[] = "[\"A\", {\"B\": \"C\"}, 1, 2, 3]garbage"; 17 size_t len = strlen(str) - strlen("garbage"); 18 19 json = json_loadb(str, len, 0, &error); 20 if(!json) { 21 fail("json_loadb failed on a valid JSON buffer"); 22 } 23 json_decref(json); 24 25 json = json_loadb(str, len - 1, 0, &error); 26 if (json) { 27 json_decref(json); 28 fail("json_loadb should have failed on an incomplete buffer, but it didn't"); 29 } 30 if(error.line != 1) { 31 fail("json_loadb returned an invalid line number on fail"); 32 } 33 if(strcmp(error.text, "']' expected near end of file") != 0) { 34 fail("json_loadb returned an invalid error message for an unclosed top-level array"); 35 } 36} 37