Imported Upstream version 1.26.0
[platform/upstream/grpc.git] / test / core / json / json_stream_error_test.cc
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18
19 #include <stdio.h>
20 #include <stdlib.h>
21
22 #include <grpc/support/alloc.h>
23 #include <grpc/support/log.h>
24 #include "test/core/util/test_config.h"
25
26 #include "src/core/lib/json/json_reader.h"
27 #include "src/core/lib/json/json_writer.h"
28
29 static int g_string_clear_once = 0;
30
31 static void string_clear(void* /*userdata*/) {
32   GPR_ASSERT(!g_string_clear_once);
33   g_string_clear_once = 1;
34 }
35
36 static uint32_t read_char(void* /*userdata*/) {
37   return GRPC_JSON_READ_CHAR_ERROR;
38 }
39
40 static grpc_json_reader_vtable reader_vtable = {
41     string_clear, nullptr, nullptr, read_char, nullptr, nullptr,
42     nullptr,      nullptr, nullptr, nullptr,   nullptr, nullptr};
43
44 static void read_error() {
45   grpc_json_reader reader;
46   grpc_json_reader_status status;
47   grpc_json_reader_init(&reader, &reader_vtable, nullptr);
48
49   status = grpc_json_reader_run(&reader);
50   GPR_ASSERT(status == GRPC_JSON_READ_ERROR);
51 }
52
53 int main(int argc, char** argv) {
54   grpc::testing::TestEnvironment env(argc, argv);
55   read_error();
56   gpr_log(GPR_INFO, "json_stream_error success");
57   return 0;
58 }