Reformat the test sources. No functional change.
This commit is contained in:
165
tests/test1.c
165
tests/test1.c
@@ -9,25 +9,22 @@
|
|||||||
|
|
||||||
static int sort_fn (const void *j1, const void *j2)
|
static int sort_fn (const void *j1, const void *j2)
|
||||||
{
|
{
|
||||||
json_object * const *jso1, * const *jso2;
|
json_object * const *jso1, * const *jso2;
|
||||||
int i1, i2;
|
int i1, i2;
|
||||||
|
|
||||||
jso1 = (json_object* const*)j1;
|
jso1 = (json_object* const*)j1;
|
||||||
jso2 = (json_object* const*)j2;
|
jso2 = (json_object* const*)j2;
|
||||||
if (!*jso1 && !*jso2) {
|
if (!*jso1 && !*jso2)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
if (!*jso1)
|
||||||
if (!*jso1) {
|
return -1;
|
||||||
return -1;
|
if (!*jso2)
|
||||||
}
|
return 1;
|
||||||
if (!*jso2) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
i1 = json_object_get_int(*jso1);
|
i1 = json_object_get_int(*jso1);
|
||||||
i2 = json_object_get_int(*jso2);
|
i2 = json_object_get_int(*jso2);
|
||||||
|
|
||||||
return i1 - i2;
|
return i1 - i2;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TEST_FORMATTED
|
#ifdef TEST_FORMATTED
|
||||||
@@ -38,88 +35,92 @@ static int sort_fn (const void *j1, const void *j2)
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
json_object *my_string, *my_int, *my_object, *my_array;
|
json_object *my_string, *my_int, *my_object, *my_array;
|
||||||
int i;
|
int i;
|
||||||
#ifdef TEST_FORMATTED
|
#ifdef TEST_FORMATTED
|
||||||
int sflags = 0;
|
int sflags = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
MC_SET_DEBUG(1);
|
MC_SET_DEBUG(1);
|
||||||
|
|
||||||
#ifdef TEST_FORMATTED
|
#ifdef TEST_FORMATTED
|
||||||
sflags = parse_flags(argc, argv);
|
sflags = parse_flags(argc, argv);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
my_string = json_object_new_string("\t");
|
my_string = json_object_new_string("\t");
|
||||||
printf("my_string=%s\n", json_object_get_string(my_string));
|
printf("my_string=%s\n", json_object_get_string(my_string));
|
||||||
printf("my_string.to_string()=%s\n", json_object_to_json_string(my_string));
|
printf("my_string.to_string()=%s\n", json_object_to_json_string(my_string));
|
||||||
json_object_put(my_string);
|
json_object_put(my_string);
|
||||||
|
|
||||||
my_string = json_object_new_string("\\");
|
my_string = json_object_new_string("\\");
|
||||||
printf("my_string=%s\n", json_object_get_string(my_string));
|
printf("my_string=%s\n", json_object_get_string(my_string));
|
||||||
printf("my_string.to_string()=%s\n", json_object_to_json_string(my_string));
|
printf("my_string.to_string()=%s\n", json_object_to_json_string(my_string));
|
||||||
json_object_put(my_string);
|
json_object_put(my_string);
|
||||||
|
|
||||||
my_string = json_object_new_string("foo");
|
my_string = json_object_new_string("foo");
|
||||||
printf("my_string=%s\n", json_object_get_string(my_string));
|
printf("my_string=%s\n", json_object_get_string(my_string));
|
||||||
printf("my_string.to_string()=%s\n", json_object_to_json_string(my_string));
|
printf("my_string.to_string()=%s\n", json_object_to_json_string(my_string));
|
||||||
|
|
||||||
my_int = json_object_new_int(9);
|
my_int = json_object_new_int(9);
|
||||||
printf("my_int=%d\n", json_object_get_int(my_int));
|
printf("my_int=%d\n", json_object_get_int(my_int));
|
||||||
printf("my_int.to_string()=%s\n", json_object_to_json_string(my_int));
|
printf("my_int.to_string()=%s\n", json_object_to_json_string(my_int));
|
||||||
|
|
||||||
my_array = json_object_new_array();
|
my_array = json_object_new_array();
|
||||||
json_object_array_add(my_array, json_object_new_int(1));
|
json_object_array_add(my_array, json_object_new_int(1));
|
||||||
json_object_array_add(my_array, json_object_new_int(2));
|
json_object_array_add(my_array, json_object_new_int(2));
|
||||||
json_object_array_add(my_array, json_object_new_int(3));
|
json_object_array_add(my_array, json_object_new_int(3));
|
||||||
json_object_array_put_idx(my_array, 4, json_object_new_int(5));
|
json_object_array_put_idx(my_array, 4, json_object_new_int(5));
|
||||||
printf("my_array=\n");
|
printf("my_array=\n");
|
||||||
for(i=0; i < json_object_array_length(my_array); i++) {
|
for(i=0; i < json_object_array_length(my_array); i++)
|
||||||
json_object *obj = json_object_array_get_idx(my_array, i);
|
{
|
||||||
printf("\t[%d]=%s\n", i, json_object_to_json_string(obj));
|
json_object *obj = json_object_array_get_idx(my_array, i);
|
||||||
}
|
printf("\t[%d]=%s\n", i, json_object_to_json_string(obj));
|
||||||
printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array));
|
}
|
||||||
|
printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array));
|
||||||
|
|
||||||
json_object_put(my_array);
|
json_object_put(my_array);
|
||||||
|
|
||||||
my_array = json_object_new_array();
|
my_array = json_object_new_array();
|
||||||
json_object_array_add(my_array, json_object_new_int(3));
|
json_object_array_add(my_array, json_object_new_int(3));
|
||||||
json_object_array_add(my_array, json_object_new_int(1));
|
json_object_array_add(my_array, json_object_new_int(1));
|
||||||
json_object_array_add(my_array, json_object_new_int(2));
|
json_object_array_add(my_array, json_object_new_int(2));
|
||||||
json_object_array_put_idx(my_array, 4, json_object_new_int(0));
|
json_object_array_put_idx(my_array, 4, json_object_new_int(0));
|
||||||
printf("my_array=\n");
|
printf("my_array=\n");
|
||||||
for(i=0; i < json_object_array_length(my_array); i++) {
|
for(i=0; i < json_object_array_length(my_array); i++)
|
||||||
json_object *obj = json_object_array_get_idx(my_array, i);
|
{
|
||||||
printf("\t[%d]=%s\n", i, json_object_to_json_string(obj));
|
json_object *obj = json_object_array_get_idx(my_array, i);
|
||||||
}
|
printf("\t[%d]=%s\n", i, json_object_to_json_string(obj));
|
||||||
printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array));
|
}
|
||||||
json_object_array_sort(my_array, sort_fn);
|
printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array));
|
||||||
printf("my_array=\n");
|
json_object_array_sort(my_array, sort_fn);
|
||||||
for(i=0; i < json_object_array_length(my_array); i++) {
|
printf("my_array=\n");
|
||||||
json_object *obj = json_object_array_get_idx(my_array, i);
|
for(i=0; i < json_object_array_length(my_array); i++)
|
||||||
printf("\t[%d]=%s\n", i, json_object_to_json_string(obj));
|
{
|
||||||
}
|
json_object *obj = json_object_array_get_idx(my_array, i);
|
||||||
printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array));
|
printf("\t[%d]=%s\n", i, json_object_to_json_string(obj));
|
||||||
|
}
|
||||||
|
printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array));
|
||||||
|
|
||||||
my_object = json_object_new_object();
|
my_object = json_object_new_object();
|
||||||
json_object_object_add(my_object, "abc", json_object_new_int(12));
|
json_object_object_add(my_object, "abc", json_object_new_int(12));
|
||||||
json_object_object_add(my_object, "foo", json_object_new_string("bar"));
|
json_object_object_add(my_object, "foo", json_object_new_string("bar"));
|
||||||
json_object_object_add(my_object, "bool0", json_object_new_boolean(0));
|
json_object_object_add(my_object, "bool0", json_object_new_boolean(0));
|
||||||
json_object_object_add(my_object, "bool1", json_object_new_boolean(1));
|
json_object_object_add(my_object, "bool1", json_object_new_boolean(1));
|
||||||
json_object_object_add(my_object, "baz", json_object_new_string("bang"));
|
json_object_object_add(my_object, "baz", json_object_new_string("bang"));
|
||||||
json_object_object_add(my_object, "baz", json_object_new_string("fark"));
|
json_object_object_add(my_object, "baz", json_object_new_string("fark"));
|
||||||
json_object_object_del(my_object, "baz");
|
json_object_object_del(my_object, "baz");
|
||||||
/*json_object_object_add(my_object, "arr", my_array);*/
|
/*json_object_object_add(my_object, "arr", my_array);*/
|
||||||
printf("my_object=\n");
|
printf("my_object=\n");
|
||||||
json_object_object_foreach(my_object, key, val) {
|
json_object_object_foreach(my_object, key, val)
|
||||||
printf("\t%s: %s\n", key, json_object_to_json_string(val));
|
{
|
||||||
}
|
printf("\t%s: %s\n", key, json_object_to_json_string(val));
|
||||||
printf("my_object.to_string()=%s\n", json_object_to_json_string(my_object));
|
}
|
||||||
|
printf("my_object.to_string()=%s\n", json_object_to_json_string(my_object));
|
||||||
|
|
||||||
json_object_put(my_string);
|
json_object_put(my_string);
|
||||||
json_object_put(my_int);
|
json_object_put(my_int);
|
||||||
json_object_put(my_object);
|
json_object_put(my_object);
|
||||||
json_object_put(my_array);
|
json_object_put(my_array);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,20 +15,20 @@
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
json_object *new_obj;
|
json_object *new_obj;
|
||||||
#ifdef TEST_FORMATTED
|
#ifdef TEST_FORMATTED
|
||||||
int sflags = 0;
|
int sflags = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
MC_SET_DEBUG(1);
|
MC_SET_DEBUG(1);
|
||||||
|
|
||||||
#ifdef TEST_FORMATTED
|
#ifdef TEST_FORMATTED
|
||||||
sflags = parse_flags(argc, argv);
|
sflags = parse_flags(argc, argv);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
new_obj = json_tokener_parse("/* more difficult test case */ { \"glossary\": { \"title\": \"example glossary\", \"GlossDiv\": { \"title\": \"S\", \"GlossList\": [ { \"ID\": \"SGML\", \"SortAs\": \"SGML\", \"GlossTerm\": \"Standard Generalized Markup Language\", \"Acronym\": \"SGML\", \"Abbrev\": \"ISO 8879:1986\", \"GlossDef\": \"A meta-markup language, used to create markup languages such as DocBook.\", \"GlossSeeAlso\": [\"GML\", \"XML\", \"markup\"] } ] } } }");
|
new_obj = json_tokener_parse("/* more difficult test case */ { \"glossary\": { \"title\": \"example glossary\", \"GlossDiv\": { \"title\": \"S\", \"GlossList\": [ { \"ID\": \"SGML\", \"SortAs\": \"SGML\", \"GlossTerm\": \"Standard Generalized Markup Language\", \"Acronym\": \"SGML\", \"Abbrev\": \"ISO 8879:1986\", \"GlossDef\": \"A meta-markup language, used to create markup languages such as DocBook.\", \"GlossSeeAlso\": [\"GML\", \"XML\", \"markup\"] } ] } } }");
|
||||||
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
||||||
json_object_put(new_obj);
|
json_object_put(new_obj);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* gcc -o utf8 utf8.c -I/home/y/include -L./.libs -ljson
|
* gcc -o utf8 utf8.c -I/home/y/include -L./.libs -ljson
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -10,40 +10,44 @@
|
|||||||
#include "json_object.h"
|
#include "json_object.h"
|
||||||
#include "json_tokener.h"
|
#include "json_tokener.h"
|
||||||
|
|
||||||
void print_hex( const char* s) {
|
void print_hex( const char* s)
|
||||||
const char *iter = s;
|
{
|
||||||
unsigned char ch;
|
const char *iter = s;
|
||||||
while ((ch = *iter++) != 0) {
|
unsigned char ch;
|
||||||
if( ',' != ch)
|
while ((ch = *iter++) != 0)
|
||||||
printf("%x ", ch);
|
{
|
||||||
else
|
if( ',' != ch)
|
||||||
printf( ",");
|
printf("%x ", ch);
|
||||||
}
|
else
|
||||||
printf("\n");
|
printf( ",");
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
const char *input = "\"\\ud840\\udd26,\\ud840\\udd27,\\ud800\\udd26,\\ud800\\udd27\"";
|
{
|
||||||
const char *expected = "\xF0\xA0\x84\xA6,\xF0\xA0\x84\xA7,\xF0\x90\x84\xA6,\xF0\x90\x84\xA7";
|
const char *input = "\"\\ud840\\udd26,\\ud840\\udd27,\\ud800\\udd26,\\ud800\\udd27\"";
|
||||||
struct json_object *parse_result = json_tokener_parse((char*)input);
|
const char *expected = "\xF0\xA0\x84\xA6,\xF0\xA0\x84\xA7,\xF0\x90\x84\xA6,\xF0\x90\x84\xA7";
|
||||||
const char *unjson = json_object_get_string(parse_result);
|
struct json_object *parse_result = json_tokener_parse((char*)input);
|
||||||
|
const char *unjson = json_object_get_string(parse_result);
|
||||||
|
|
||||||
printf("input: %s\n", input);
|
printf("input: %s\n", input);
|
||||||
|
|
||||||
int strings_match = !strcmp( expected, unjson);
|
int strings_match = !strcmp( expected, unjson);
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
if (strings_match) {
|
if (strings_match)
|
||||||
printf("JSON parse result is correct: %s\n", unjson);
|
{
|
||||||
printf("PASS\n");
|
printf("JSON parse result is correct: %s\n", unjson);
|
||||||
} else {
|
printf("PASS\n");
|
||||||
printf("JSON parse result doesn't match expected string\n");
|
} else {
|
||||||
printf("expected string bytes: ");
|
printf("JSON parse result doesn't match expected string\n");
|
||||||
print_hex( expected);
|
printf("expected string bytes: ");
|
||||||
printf("parsed string bytes: ");
|
print_hex( expected);
|
||||||
print_hex( unjson);
|
printf("parsed string bytes: ");
|
||||||
printf("FAIL\n");
|
print_hex( unjson);
|
||||||
retval = 1;
|
printf("FAIL\n");
|
||||||
}
|
retval = 1;
|
||||||
|
}
|
||||||
json_object_put(parse_result);
|
json_object_put(parse_result);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,9 +58,9 @@ int main(int argc, char **argv)
|
|||||||
checktype(new_obj, "big_number");
|
checktype(new_obj, "big_number");
|
||||||
checktype(new_obj, "a_null");
|
checktype(new_obj, "a_null");
|
||||||
|
|
||||||
json_object_put(new_obj);
|
json_object_put(new_obj);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void getit(struct json_object *new_obj, const char *field)
|
static void getit(struct json_object *new_obj, const char *field)
|
||||||
|
|||||||
@@ -9,27 +9,29 @@
|
|||||||
#include "json_inttypes.h"
|
#include "json_inttypes.h"
|
||||||
#include "json_object.h"
|
#include "json_object.h"
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
// this test has a space after the null character. check that it's still included
|
{
|
||||||
const char *input = " \0 ";
|
// this test has a space after the null character. check that it's still included
|
||||||
const char *expected = "\" \\u0000 \"";
|
const char *input = " \0 ";
|
||||||
struct json_object *string = json_object_new_string_len(input, 3);
|
const char *expected = "\" \\u0000 \"";
|
||||||
const char *json = json_object_to_json_string(string);
|
struct json_object *string = json_object_new_string_len(input, 3);
|
||||||
|
const char *json = json_object_to_json_string(string);
|
||||||
|
|
||||||
int strings_match = !strcmp( expected, json);
|
int strings_match = !strcmp( expected, json);
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
if (strings_match) {
|
if (strings_match)
|
||||||
printf("JSON write result is correct: %s\n", json);
|
{
|
||||||
printf("PASS\n");
|
printf("JSON write result is correct: %s\n", json);
|
||||||
} else {
|
printf("PASS\n");
|
||||||
printf("JSON write result doesn't match expected string\n");
|
} else {
|
||||||
printf("expected string: ");
|
printf("JSON write result doesn't match expected string\n");
|
||||||
printf("%s\n", expected);
|
printf("expected string: ");
|
||||||
printf("parsed string: ");
|
printf("%s\n", expected);
|
||||||
printf("%s\n", json);
|
printf("parsed string: ");
|
||||||
printf("FAIL\n");
|
printf("%s\n", json);
|
||||||
retval=1;
|
printf("FAIL\n");
|
||||||
}
|
retval=1;
|
||||||
json_object_put(string);
|
}
|
||||||
return retval;
|
json_object_put(string);
|
||||||
|
return retval;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,83 +25,83 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
static void test_basic_parse()
|
static void test_basic_parse()
|
||||||
{
|
{
|
||||||
json_object *new_obj;
|
json_object *new_obj;
|
||||||
|
|
||||||
new_obj = json_tokener_parse("\"\003\"");
|
new_obj = json_tokener_parse("\"\003\"");
|
||||||
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
||||||
json_object_put(new_obj);
|
json_object_put(new_obj);
|
||||||
|
|
||||||
new_obj = json_tokener_parse("/* hello */\"foo\"");
|
new_obj = json_tokener_parse("/* hello */\"foo\"");
|
||||||
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
||||||
json_object_put(new_obj);
|
json_object_put(new_obj);
|
||||||
|
|
||||||
new_obj = json_tokener_parse("// hello\n\"foo\"");
|
new_obj = json_tokener_parse("// hello\n\"foo\"");
|
||||||
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
||||||
json_object_put(new_obj);
|
json_object_put(new_obj);
|
||||||
|
|
||||||
new_obj = json_tokener_parse("\"\\u0041\\u0042\\u0043\"");
|
new_obj = json_tokener_parse("\"\\u0041\\u0042\\u0043\"");
|
||||||
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
||||||
json_object_put(new_obj);
|
json_object_put(new_obj);
|
||||||
|
|
||||||
new_obj = json_tokener_parse("null");
|
new_obj = json_tokener_parse("null");
|
||||||
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
||||||
json_object_put(new_obj);
|
json_object_put(new_obj);
|
||||||
|
|
||||||
new_obj = json_tokener_parse("True");
|
new_obj = json_tokener_parse("True");
|
||||||
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
||||||
json_object_put(new_obj);
|
json_object_put(new_obj);
|
||||||
|
|
||||||
new_obj = json_tokener_parse("12");
|
new_obj = json_tokener_parse("12");
|
||||||
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
||||||
json_object_put(new_obj);
|
json_object_put(new_obj);
|
||||||
|
|
||||||
new_obj = json_tokener_parse("12.3");
|
new_obj = json_tokener_parse("12.3");
|
||||||
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
||||||
json_object_put(new_obj);
|
json_object_put(new_obj);
|
||||||
|
|
||||||
new_obj = json_tokener_parse("[\"\\n\"]");
|
new_obj = json_tokener_parse("[\"\\n\"]");
|
||||||
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
||||||
json_object_put(new_obj);
|
json_object_put(new_obj);
|
||||||
|
|
||||||
new_obj = json_tokener_parse("[\"\\nabc\\n\"]");
|
new_obj = json_tokener_parse("[\"\\nabc\\n\"]");
|
||||||
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
||||||
json_object_put(new_obj);
|
json_object_put(new_obj);
|
||||||
|
|
||||||
new_obj = json_tokener_parse("[null]");
|
new_obj = json_tokener_parse("[null]");
|
||||||
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
||||||
json_object_put(new_obj);
|
json_object_put(new_obj);
|
||||||
|
|
||||||
new_obj = json_tokener_parse("[]");
|
new_obj = json_tokener_parse("[]");
|
||||||
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
||||||
json_object_put(new_obj);
|
json_object_put(new_obj);
|
||||||
|
|
||||||
new_obj = json_tokener_parse("[false]");
|
new_obj = json_tokener_parse("[false]");
|
||||||
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
||||||
json_object_put(new_obj);
|
json_object_put(new_obj);
|
||||||
|
|
||||||
new_obj = json_tokener_parse("[\"abc\",null,\"def\",12]");
|
new_obj = json_tokener_parse("[\"abc\",null,\"def\",12]");
|
||||||
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
||||||
json_object_put(new_obj);
|
json_object_put(new_obj);
|
||||||
|
|
||||||
new_obj = json_tokener_parse("{}");
|
new_obj = json_tokener_parse("{}");
|
||||||
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
||||||
json_object_put(new_obj);
|
json_object_put(new_obj);
|
||||||
|
|
||||||
new_obj = json_tokener_parse("{ \"foo\": \"bar\" }");
|
new_obj = json_tokener_parse("{ \"foo\": \"bar\" }");
|
||||||
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
||||||
json_object_put(new_obj);
|
json_object_put(new_obj);
|
||||||
|
|
||||||
new_obj = json_tokener_parse("{ \"foo\": \"bar\", \"baz\": null, \"bool0\": true }");
|
new_obj = json_tokener_parse("{ \"foo\": \"bar\", \"baz\": null, \"bool0\": true }");
|
||||||
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
||||||
json_object_put(new_obj);
|
json_object_put(new_obj);
|
||||||
|
|
||||||
new_obj = json_tokener_parse("{ \"foo\": [null, \"foo\"] }");
|
new_obj = json_tokener_parse("{ \"foo\": [null, \"foo\"] }");
|
||||||
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
||||||
json_object_put(new_obj);
|
json_object_put(new_obj);
|
||||||
|
|
||||||
new_obj = json_tokener_parse("{ \"abc\": 12, \"foo\": \"bar\", \"bool0\": false, \"bool1\": true, \"arr\": [ 1, 2, 3, null, 5 ] }");
|
new_obj = json_tokener_parse("{ \"abc\": 12, \"foo\": \"bar\", \"bool0\": false, \"bool1\": true, \"arr\": [ 1, 2, 3, null, 5 ] }");
|
||||||
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
printf("new_obj.to_string()=%s\n", json_object_to_json_string(new_obj));
|
||||||
json_object_put(new_obj);
|
json_object_put(new_obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_verbose_parse()
|
static void test_verbose_parse()
|
||||||
@@ -121,7 +121,7 @@ static void test_verbose_parse()
|
|||||||
new_obj = json_tokener_parse_verbose("foo", &error);
|
new_obj = json_tokener_parse_verbose("foo", &error);
|
||||||
assert (new_obj == NULL);
|
assert (new_obj == NULL);
|
||||||
|
|
||||||
/* b/c the string starts with 'f' parsing return a boolean error */
|
/* b/c the string starts with 'f' parsing return a boolean error */
|
||||||
assert (error == json_tokener_error_parse_boolean);
|
assert (error == json_tokener_error_parse_boolean);
|
||||||
|
|
||||||
printf("json_tokener_parse_versbose() OK\n");
|
printf("json_tokener_parse_versbose() OK\n");
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ static void test_printbuf_memset_length(void);
|
|||||||
static void test_basic_printbuf_memset()
|
static void test_basic_printbuf_memset()
|
||||||
{
|
{
|
||||||
struct printbuf *pb;
|
struct printbuf *pb;
|
||||||
|
|
||||||
printf("%s: starting test\n", __func__);
|
printf("%s: starting test\n", __func__);
|
||||||
pb = printbuf_new();
|
pb = printbuf_new();
|
||||||
sprintbuf(pb, "blue:%d", 1);
|
sprintbuf(pb, "blue:%d", 1);
|
||||||
@@ -104,7 +104,7 @@ static void test_printbuf_memappend(int *before_resize)
|
|||||||
memset(data, 'X', *before_resize + 1);
|
memset(data, 'X', *before_resize + 1);
|
||||||
printbuf_memappend_fast(pb, data, *before_resize + 1);
|
printbuf_memappend_fast(pb, data, *before_resize + 1);
|
||||||
printf("Append to just after resize: %d, [%s]\n", printbuf_length(pb), pb->buf);
|
printf("Append to just after resize: %d, [%s]\n", printbuf_length(pb), pb->buf);
|
||||||
|
|
||||||
free(data);
|
free(data);
|
||||||
|
|
||||||
printbuf_free(pb);
|
printbuf_free(pb);
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ int main(int argc, char **argv)
|
|||||||
printf("my_object.to_string(custom serializer)=%s\n", json_object_to_json_string(my_object));
|
printf("my_object.to_string(custom serializer)=%s\n", json_object_to_json_string(my_object));
|
||||||
printf("Next line of output should be from the custom freeit function:\n");
|
printf("Next line of output should be from the custom freeit function:\n");
|
||||||
|
|
||||||
freeit_was_called = 0;
|
freeit_was_called = 0;
|
||||||
json_object_put(my_object);
|
json_object_put(my_object);
|
||||||
assert(freeit_was_called);
|
assert(freeit_was_called);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user