diff options
author | Craig Tiller <ctiller@google.com> | 2015-12-11 17:59:03 -0800 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2015-12-11 17:59:03 -0800 |
commit | 82821ba778df5ed9793379da1f970bc0e3cd85e5 (patch) | |
tree | 2b89106f90af6466071ed0564455963df4618ae7 /test/core | |
parent | 3a977a49f642a087637ddb5cb72245b0485ac665 (diff) | |
parent | 11c320da083946e89c7c173e37156ec37af3e6ac (diff) |
Merge pull request #4438 from nicolasnoble/json-coverage-2
Increasing json code coverage.
Diffstat (limited to 'test/core')
-rw-r--r-- | test/core/json/json_stream_error_test.c | 75 | ||||
-rw-r--r-- | test/core/json/json_test.c | 17 |
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. */ |