Reformat the test sources. No functional change.

This commit is contained in:
Eric Haszlakiewicz
2012-09-16 20:43:29 -05:00
parent d1f237e28a
commit c3068bfd09
8 changed files with 211 additions and 204 deletions

View File

@@ -14,15 +14,12 @@ static int sort_fn (const void *j1, const void *j2)
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)
if (!*jso2) {
return 1; 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);
@@ -74,7 +71,8 @@ int main(int argc, char **argv)
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); json_object *obj = json_object_array_get_idx(my_array, i);
printf("\t[%d]=%s\n", i, json_object_to_json_string(obj)); printf("\t[%d]=%s\n", i, json_object_to_json_string(obj));
} }
@@ -88,14 +86,16 @@ int main(int argc, char **argv)
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); json_object *obj = json_object_array_get_idx(my_array, i);
printf("\t[%d]=%s\n", i, json_object_to_json_string(obj)); 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_array_sort(my_array, sort_fn); json_object_array_sort(my_array, sort_fn);
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); json_object *obj = json_object_array_get_idx(my_array, i);
printf("\t[%d]=%s\n", i, json_object_to_json_string(obj)); printf("\t[%d]=%s\n", i, json_object_to_json_string(obj));
} }
@@ -111,7 +111,8 @@ int main(int argc, char **argv)
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));

View File

@@ -10,10 +10,12 @@
#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; const char *iter = s;
unsigned char ch; unsigned char ch;
while ((ch = *iter++) != 0) { while ((ch = *iter++) != 0)
{
if( ',' != ch) if( ',' != ch)
printf("%x ", ch); printf("%x ", ch);
else else
@@ -22,7 +24,8 @@ void print_hex( const char* s) {
printf("\n"); printf("\n");
} }
int main() { int main()
{
const char *input = "\"\\ud840\\udd26,\\ud840\\udd27,\\ud800\\udd26,\\ud800\\udd27\""; 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 *expected = "\xF0\xA0\x84\xA6,\xF0\xA0\x84\xA7,\xF0\x90\x84\xA6,\xF0\x90\x84\xA7";
struct json_object *parse_result = json_tokener_parse((char*)input); struct json_object *parse_result = json_tokener_parse((char*)input);
@@ -32,7 +35,8 @@ int main() {
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("JSON parse result is correct: %s\n", unjson);
printf("PASS\n"); printf("PASS\n");
} else { } else {

View File

@@ -9,7 +9,8 @@
#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 // this test has a space after the null character. check that it's still included
const char *input = " \0 "; const char *input = " \0 ";
const char *expected = "\" \\u0000 \""; const char *expected = "\" \\u0000 \"";
@@ -18,7 +19,8 @@ int main() {
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("JSON write result is correct: %s\n", json);
printf("PASS\n"); printf("PASS\n");
} else { } else {