aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/json
diff options
context:
space:
mode:
authorGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2015-12-12 01:47:36 +0100
committerGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2015-12-12 02:42:39 +0100
commit11c320da083946e89c7c173e37156ec37af3e6ac (patch)
tree42f5872a857eba5b1dab85fcc2ee07d4ab0d5448 /test/core/json
parent420effac80564a62774c27f51caaebfcaa072a99 (diff)
Increasing json code coverage.
Diffstat (limited to 'test/core/json')
-rw-r--r--test/core/json/json_stream_error_test.c75
-rw-r--r--test/core/json/json_test.c17
2 files changed, 88 insertions, 4 deletions
diff --git a/test/core/json/json_stream_error_test.c b/test/core/json/json_stream_error_test.c
new file mode 100644
index 0000000000..bac825dde2
--- /dev/null
+++ b/test/core/json/json_stream_error_test.c
@@ -0,0 +1,75 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <grpc/support/alloc.h>
+#include <grpc/support/useful.h>
+#include <grpc/support/log.h>
+#include "test/core/util/test_config.h"
+
+#include "src/core/json/json_reader.h"
+#include "src/core/json/json_writer.h"
+
+static int g_string_clear_once = 0;
+
+static void string_clear(void *userdata) {
+ GPR_ASSERT(!g_string_clear_once);
+ g_string_clear_once = 1;
+}
+
+static gpr_uint32 read_char(void *userdata) {
+ return GRPC_JSON_READ_CHAR_ERROR;
+}
+
+static grpc_json_reader_vtable reader_vtable = {
+ string_clear, NULL, NULL, read_char, NULL, NULL,
+ NULL, NULL, NULL, NULL, NULL, NULL
+};
+
+static void read_error() {
+ grpc_json_reader reader;
+ grpc_json_reader_status status;
+ grpc_json_reader_init(&reader, &reader_vtable, NULL);
+
+ status = grpc_json_reader_run(&reader);
+ GPR_ASSERT(status == GRPC_JSON_READ_ERROR);
+}
+
+int main(int argc, char **argv) {
+ grpc_test_init(argc, argv);
+ read_error();
+ gpr_log(GPR_INFO, "json_stream_error success");
+ return 0;
+}
diff --git a/test/core/json/json_test.c b/test/core/json/json_test.c
index f16494edf6..5add80d753 100644
--- a/test/core/json/json_test.c
+++ b/test/core/json/json_test.c
@@ -49,10 +49,10 @@ typedef struct testing_pair {
static testing_pair testing_pairs[] = {
/* Testing valid parsing. */
-
/* Testing trivial parses, with de-indentation. */
{" 0 ", "0"},
{" 1 ", "1"},
+ {" \" \" ", "\" \""},
{" \"a\" ", "\"a\""},
{" true ", "true"},
/* Testing the parser's ability to decode trivial UTF-16. */
@@ -69,8 +69,8 @@ static testing_pair testing_pairs[] = {
" [ [ ] , { } , [ ] ] ", "[[],{},[]]",
},
/* Testing escapes and control chars in key strings. */
- {" { \"\x7f\\n\\\\a , b\": 1, \"\": 0 } ",
- "{\"\\u007f\\n\\\\a , b\":1,\"\":0}"},
+ {" { \"\\u007f\x7f\\n\\r\\\"\\f\\b\\\\a , b\": 1, \"\": 0 } ",
+ "{\"\\u007f\\u007f\\n\\r\\\"\\f\\b\\\\a , b\":1,\"\":0}"},
/* Testing the writer's ability to cut off invalid UTF-8 sequences. */
{"\"abc\xf0\x9d\x24\"", "\"abc\""},
{"\"\xff\"", "\"\""},
@@ -96,6 +96,9 @@ static testing_pair testing_pairs[] = {
{"\"\\udd1ef", NULL},
{"\"\\ud834\\ud834\"", NULL},
{"\"\\ud834\\u1234\"", NULL},
+ {"\"\\ud834]\"", NULL},
+ {"\"\\ud834 \"", NULL},
+ {"\"\\ud834\\\\\"", NULL},
/* Testing embedded invalid whitechars. */
{"\"\n\"", NULL},
{"\"\t\"", NULL},
@@ -110,9 +113,15 @@ static testing_pair testing_pairs[] = {
{"[[]", NULL},
{"[}", NULL},
{"{]", NULL},
- /*Testing trailing comma. */
+ /* Testing bad containers. */
+ {"{x}", NULL},
+ {"{x=0,y}", NULL},
+ /* Testing trailing comma. */
{"{,}", NULL},
{"[1,2,3,4,]", NULL},
+ {"{\"a\": 1, }", NULL},
+ /* Testing after-ending characters. */
+ {"{}x", NULL},
/* Testing having a key syntax in an array. */
{"[\"x\":0]", NULL},
/* Testing invalid numbers. */