• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
string_clear(void * userdata)31 static void string_clear(void* userdata) {
32   GPR_ASSERT(!g_string_clear_once);
33   g_string_clear_once = 1;
34 }
35 
read_char(void * userdata)36 static uint32_t read_char(void* userdata) { return GRPC_JSON_READ_CHAR_ERROR; }
37 
38 static grpc_json_reader_vtable reader_vtable = {
39     string_clear, nullptr, nullptr, read_char, nullptr, nullptr,
40     nullptr,      nullptr, nullptr, nullptr,   nullptr, nullptr};
41 
read_error()42 static void read_error() {
43   grpc_json_reader reader;
44   grpc_json_reader_status status;
45   grpc_json_reader_init(&reader, &reader_vtable, nullptr);
46 
47   status = grpc_json_reader_run(&reader);
48   GPR_ASSERT(status == GRPC_JSON_READ_ERROR);
49 }
50 
main(int argc,char ** argv)51 int main(int argc, char** argv) {
52   grpc_test_init(argc, argv);
53   read_error();
54   gpr_log(GPR_INFO, "json_stream_error success");
55   return 0;
56 }
57