diff --git a/test.c b/test.c index c3728ea..34be4d7 100644 --- a/test.c +++ b/test.c @@ -25,26 +25,6 @@ #include #include "cJSON.h" -/* Parse text to JSON, then render back to text, and print! */ -static void doit(char *text) -{ - char *out = NULL; - cJSON *json = NULL; - - json = cJSON_Parse(text); - if (!json) - { - printf("Error before: [%s]\n", cJSON_GetErrorPtr()); - } - else - { - out = cJSON_Print(json); - cJSON_Delete(json); - printf("%s\n", out); - free(out); - } -} - /* Used by some code below as an example datatype. */ struct record { @@ -278,90 +258,9 @@ static void create_objects(void) int main(void) { - /* a bunch of json: */ - char text1[] = - "{\n" - "\"name\": \"Jack (\\\"Bee\\\") Nimble\", \n" - "\"format\": {\"type\": \"rect\", \n" - "\"width\": 1920, \n" - "\"height\": 1080, \n" - "\"interlace\": false,\"frame rate\": 24\n" - "}\n" - "}"; - char text2[] = "[\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"]"; - char text3[] = - "[\n" - " [0, -1, 0],\n" - " [1, 0, 0],\n" - " [0, 0, 1]\n" - "\t]\n"; - char text4[] = - "{\n" - "\t\t\"Image\": {\n" - "\t\t\t\"Width\": 800,\n" - "\t\t\t\"Height\": 600,\n" - "\t\t\t\"Title\": \"View from 15th Floor\",\n" - "\t\t\t\"Thumbnail\": {\n" - "\t\t\t\t\"Url\": \"http:/*www.example.com/image/481989943\",\n" - "\t\t\t\t\"Height\": 125,\n" - "\t\t\t\t\"Width\": \"100\"\n" - "\t\t\t},\n" - "\t\t\t\"IDs\": [116, 943, 234, 38793]\n" - "\t\t}\n" - "\t}"; - char text5[] = - "[\n" - "\t {\n" - "\t \"precision\": \"zip\",\n" - "\t \"Latitude\": 37.7668,\n" - "\t \"Longitude\": -122.3959,\n" - "\t \"Address\": \"\",\n" - "\t \"City\": \"SAN FRANCISCO\",\n" - "\t \"State\": \"CA\",\n" - "\t \"Zip\": \"94107\",\n" - "\t \"Country\": \"US\"\n" - "\t },\n" - "\t {\n" - "\t \"precision\": \"zip\",\n" - "\t \"Latitude\": 37.371991,\n" - "\t \"Longitude\": -122.026020,\n" - "\t \"Address\": \"\",\n" - "\t \"City\": \"SUNNYVALE\",\n" - "\t \"State\": \"CA\",\n" - "\t \"Zip\": \"94085\",\n" - "\t \"Country\": \"US\"\n" - "\t }\n" - "\t ]"; - - char text6[] = - "" - "\n" - "\n" - " \n" - " \n" - "Application Error\n" - "\n" - "\n" - " \n" - "\n" - "\n"; - /* print the version */ printf("Version: %s\n", cJSON_Version()); - /* Process each json textblock by parsing, then rebuilding: */ - doit(text1); - doit(text2); - doit(text3); - doit(text4); - doit(text5); - doit(text6); - /* Now some samplecode for building objects concisely: */ create_objects(); diff --git a/tests/inputs/test10 b/tests/inputs/test10 new file mode 100644 index 0000000..d19eb8b --- /dev/null +++ b/tests/inputs/test10 @@ -0,0 +1 @@ +["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] diff --git a/tests/inputs/test10.expected b/tests/inputs/test10.expected new file mode 100644 index 0000000..747ba62 --- /dev/null +++ b/tests/inputs/test10.expected @@ -0,0 +1 @@ +["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] \ No newline at end of file diff --git a/tests/inputs/test11 b/tests/inputs/test11 new file mode 100644 index 0000000..eaf43e6 --- /dev/null +++ b/tests/inputs/test11 @@ -0,0 +1,8 @@ +{ +"name": "Jack (\"Bee\") Nimble", +"format": {"type": "rect", +"width": 1920, +"height": 1080, +"interlace": false,"frame rate": 24 +} +} diff --git a/tests/inputs/test11.expected b/tests/inputs/test11.expected new file mode 100644 index 0000000..24e72ec --- /dev/null +++ b/tests/inputs/test11.expected @@ -0,0 +1,10 @@ +{ + "name": "Jack (\"Bee\") Nimble", + "format": { + "type": "rect", + "width": 1920, + "height": 1080, + "interlace": false, + "frame rate": 24 + } +} \ No newline at end of file diff --git a/tests/inputs/test7 b/tests/inputs/test7 new file mode 100644 index 0000000..3308536 --- /dev/null +++ b/tests/inputs/test7 @@ -0,0 +1,22 @@ +[ + { + "precision": "zip", + "Latitude": 37.7668, + "Longitude": -122.3959, + "Address": "", + "City": "SAN FRANCISCO", + "State": "CA", + "Zip": "94107", + "Country": "US" + }, + { + "precision": "zip", + "Latitude": 37.371991, + "Longitude": -122.026020, + "Address": "", + "City": "SUNNYVALE", + "State": "CA", + "Zip": "94085", + "Country": "US" + } + ] diff --git a/tests/inputs/test7.expected b/tests/inputs/test7.expected new file mode 100644 index 0000000..6e2e075 --- /dev/null +++ b/tests/inputs/test7.expected @@ -0,0 +1,19 @@ +[{ + "precision": "zip", + "Latitude": 37.766800, + "Longitude": -122.395900, + "Address": "", + "City": "SAN FRANCISCO", + "State": "CA", + "Zip": "94107", + "Country": "US" + }, { + "precision": "zip", + "Latitude": 37.371991, + "Longitude": -122.026020, + "Address": "", + "City": "SUNNYVALE", + "State": "CA", + "Zip": "94085", + "Country": "US" + }] \ No newline at end of file diff --git a/tests/inputs/test8 b/tests/inputs/test8 new file mode 100644 index 0000000..4b1f5b9 --- /dev/null +++ b/tests/inputs/test8 @@ -0,0 +1,13 @@ +{ + "Image": { + "Width": 800, + "Height": 600, + "Title": "View from 15th Floor", + "Thumbnail": { + "Url": "http:/*www.example.com/image/481989943", + "Height": 125, + "Width": "100" + }, + "IDs": [116, 943, 234, 38793] + } + } diff --git a/tests/inputs/test8.expected b/tests/inputs/test8.expected new file mode 100644 index 0000000..2e6b731 --- /dev/null +++ b/tests/inputs/test8.expected @@ -0,0 +1,13 @@ +{ + "Image": { + "Width": 800, + "Height": 600, + "Title": "View from 15th Floor", + "Thumbnail": { + "Url": "http:/*www.example.com/image/481989943", + "Height": 125, + "Width": "100" + }, + "IDs": [116, 943, 234, 38793] + } +} \ No newline at end of file diff --git a/tests/inputs/test9 b/tests/inputs/test9 new file mode 100644 index 0000000..2a939b9 --- /dev/null +++ b/tests/inputs/test9 @@ -0,0 +1,5 @@ +[ + [0, -1, 0], + [1, 0, 0], + [0, 0, 1] + ] diff --git a/tests/inputs/test9.expected b/tests/inputs/test9.expected new file mode 100644 index 0000000..0eea3c9 --- /dev/null +++ b/tests/inputs/test9.expected @@ -0,0 +1 @@ +[[0, -1, 0], [1, 0, 0], [0, 0, 1]] \ No newline at end of file diff --git a/tests/parse_examples.c b/tests/parse_examples.c index 6ea45d8..8232e8a 100644 --- a/tests/parse_examples.c +++ b/tests/parse_examples.c @@ -210,6 +210,31 @@ static void file_test6_should_not_be_parsed(void) } } +static void file_test7_should_be_parsed_and_printed(void) +{ + do_test("test7"); +} + +static void file_test8_should_be_parsed_and_printed(void) +{ + do_test("test8"); +} + +static void file_test9_should_be_parsed_and_printed(void) +{ + do_test("test9"); +} + +static void file_test10_should_be_parsed_and_printed(void) +{ + do_test("test10"); +} + +static void file_test11_should_be_parsed_and_printed(void) +{ + do_test("test11"); +} + int main(void) { UNITY_BEGIN(); @@ -219,5 +244,10 @@ int main(void) RUN_TEST(file_test4_should_be_parsed_and_printed); RUN_TEST(file_test5_should_be_parsed_and_printed); RUN_TEST(file_test6_should_not_be_parsed); + RUN_TEST(file_test7_should_be_parsed_and_printed); + RUN_TEST(file_test8_should_be_parsed_and_printed); + RUN_TEST(file_test9_should_be_parsed_and_printed); + RUN_TEST(file_test10_should_be_parsed_and_printed); + RUN_TEST(file_test11_should_be_parsed_and_printed); return UNITY_END(); }