1 /* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef JSONUTIL_TEST_H 17 #define JSONUTIL_TEST_H 18 19 20 typedef void *json_handle; 21 typedef void *json_pobject; 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 json_handle parse_json(const char *data); 28 void free_json(json_handle handle); 29 30 json_pobject get_json_obj(json_pobject parent, const char *field); 31 int32_t get_json_int(json_pobject obj, const char *field); 32 const char *get_json_string(json_pobject obj, const char *field); 33 int32_t get_json_bool(json_pobject obj, const char *field); 34 int32_t get_array_size(json_pobject obj); 35 json_pobject get_array_idx(json_pobject obj, int32_t idx); 36 37 json_pobject create_json_object(void); 38 void delete_json_object(json_pobject obj); 39 void add_item_to_object(json_pobject parent, const char *field, json_pobject obj); 40 json_pobject add_string_to_object(json_pobject parent, const char *field, const char *value); 41 json_pobject add_number_to_object(json_pobject parent, const char *field, int32_t value); 42 json_pobject add_bool_to_object(json_pobject parent, const char *field, int32_t value); 43 json_pobject add_object_to_object(json_pobject parent, const char *field); 44 45 char *json_to_string(json_pobject obj); 46 void free_json_string(char *json_str); 47 48 json_pobject add_array_to_object(json_pobject parent, const char *field); 49 void add_string_to_array(json_pobject objArr, const char *value); 50 void add_number_to_array(json_pobject objArr, int32_t value); 51 void add_bool_to_array(json_pobject objArr, int32_t value); 52 void add_obj_to_array(json_pobject objArr, json_pobject obj); 53 54 #ifdef __cplusplus 55 } 56 #endif 57 58 #endif