• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include "softbus_json_utils_mock.h"
17 
18 using namespace testing;
19 using namespace testing::ext;
20 
21 namespace OHOS {
22 void *g_jsonUtilsInterface;
23 
JsonUtilsInterfaceMock()24 JsonUtilsInterfaceMock::JsonUtilsInterfaceMock()
25 {
26     g_jsonUtilsInterface = reinterpret_cast<void *>(this);
27 }
28 
~JsonUtilsInterfaceMock()29 JsonUtilsInterfaceMock::~JsonUtilsInterfaceMock()
30 {
31     g_jsonUtilsInterface = nullptr;
32 }
33 
GetJsonUtilsInterface()34 static JsonUtilsInterface *GetJsonUtilsInterface()
35 {
36     return reinterpret_cast<JsonUtilsInterfaceMock *>(g_jsonUtilsInterface);
37 }
38 
39 extern "C" {
GetStringItemByJsonObject(const cJSON * json,const char * const string,char * target,uint32_t targetLen)40 int32_t GetStringItemByJsonObject(const cJSON *json, const char * const string, char *target, uint32_t targetLen)
41 {
42     return GetJsonUtilsInterface()->GetStringItemByJsonObject(json, string, target, targetLen);
43 }
44 
GetJsonObjectStringItem(const cJSON * json,const char * const string,char * target,uint32_t targetLen)45 bool GetJsonObjectStringItem(const cJSON *json, const char * const string, char *target, uint32_t targetLen)
46 {
47     return GetJsonUtilsInterface()->GetJsonObjectStringItem(json, string, target, targetLen);
48 }
49 
GetJsonObjectNumber16Item(const cJSON * json,const char * const string,uint16_t * target)50 bool GetJsonObjectNumber16Item(const cJSON *json, const char * const string, uint16_t *target)
51 {
52     return GetJsonUtilsInterface()->GetJsonObjectNumber16Item(json, string, target);
53 }
54 
GetJsonObjectNumberItem(const cJSON * json,const char * const string,int32_t * target)55 bool GetJsonObjectNumberItem(const cJSON *json, const char * const string, int32_t *target)
56 {
57     return GetJsonUtilsInterface()->GetJsonObjectNumberItem(json, string, target);
58 }
59 
GetJsonObjectSignedNumberItem(const cJSON * json,const char * const string,int32_t * target)60 bool GetJsonObjectSignedNumberItem(const cJSON *json, const char * const string, int32_t *target)
61 {
62     return GetJsonUtilsInterface()->GetJsonObjectSignedNumberItem(json, string, target);
63 }
64 
GetJsonObjectNumber64Item(const cJSON * json,const char * const string,int64_t * target)65 bool GetJsonObjectNumber64Item(const cJSON *json, const char * const string, int64_t *target)
66 {
67     return GetJsonUtilsInterface()->GetJsonObjectNumber64Item(json, string, target);
68 }
69 
GetJsonObjectSignedNumber64Item(const cJSON * json,const char * const string,int64_t * target)70 bool GetJsonObjectSignedNumber64Item(const cJSON *json, const char * const string, int64_t *target)
71 {
72     return GetJsonUtilsInterface()->GetJsonObjectSignedNumber64Item(json, string, target);
73 }
74 
GetJsonObjectDoubleItem(const cJSON * json,const char * const string,double * target)75 bool GetJsonObjectDoubleItem(const cJSON *json, const char * const string, double *target)
76 {
77     return GetJsonUtilsInterface()->GetJsonObjectDoubleItem(json, string, target);
78 }
79 
GetJsonObjectBoolItem(const cJSON * json,const char * const string,bool * target)80 bool GetJsonObjectBoolItem(const cJSON *json, const char * const string, bool *target)
81 {
82     return GetJsonUtilsInterface()->GetJsonObjectBoolItem(json, string, target);
83 }
84 
AddStringToJsonObject(cJSON * json,const char * const string,const char * value)85 bool AddStringToJsonObject(cJSON *json, const char * const string, const char *value)
86 {
87     return GetJsonUtilsInterface()->AddStringToJsonObject(json, string, value);
88 }
89 
AddStringArrayToJsonObject(cJSON * json,const char * const string,const char * const * strings,int32_t count)90 bool AddStringArrayToJsonObject(cJSON *json, const char * const string, const char * const *strings, int32_t count)
91 {
92     return GetJsonUtilsInterface()->AddStringArrayToJsonObject(json, string, strings, count);
93 }
94 
AddNumber16ToJsonObject(cJSON * json,const char * const string,uint16_t num)95 bool AddNumber16ToJsonObject(cJSON *json, const char * const string, uint16_t num)
96 {
97     return GetJsonUtilsInterface()->AddNumber16ToJsonObject(json, string, num);
98 }
99 
AddNumberToJsonObject(cJSON * json,const char * const string,int32_t num)100 bool AddNumberToJsonObject(cJSON *json, const char * const string, int32_t num)
101 {
102     return GetJsonUtilsInterface()->AddNumberToJsonObject(json, string, num);
103 }
104 
AddNumber64ToJsonObject(cJSON * json,const char * const string,int64_t num)105 bool AddNumber64ToJsonObject(cJSON *json, const char * const string, int64_t num)
106 {
107     return GetJsonUtilsInterface()->AddNumber64ToJsonObject(json, string, num);
108 }
109 
AddBoolToJsonObject(cJSON * json,const char * const string,bool value)110 bool AddBoolToJsonObject(cJSON *json, const char * const string, bool value)
111 {
112     return GetJsonUtilsInterface()->AddBoolToJsonObject(json, string, value);
113 }
114 
GetJsonObjectInt32Item(const cJSON * json,const char * const string,int32_t * target)115 bool GetJsonObjectInt32Item(const cJSON *json, const char * const string, int32_t *target)
116 {
117     return GetJsonUtilsInterface()->GetJsonObjectInt32Item(json, string, target);
118 }
119 
GetDynamicStringItemByJsonObject(const cJSON * const json,const char * const string,uint32_t limit)120 char *GetDynamicStringItemByJsonObject(const cJSON * const json, const char * const string, uint32_t limit)
121 {
122     return GetJsonUtilsInterface()->GetDynamicStringItemByJsonObject(json, string, limit);
123 }
124 
AddIntArrayToJsonObject(cJSON * json,const char * string,const int32_t * array,int32_t arrayLen)125 bool AddIntArrayToJsonObject(cJSON *json, const char *string, const int32_t *array, int32_t arrayLen)
126 {
127     return GetJsonUtilsInterface()->AddIntArrayToJsonObject(json, string, array, arrayLen);
128 }
129 
GetJsonObjectIntArrayItem(const cJSON * json,const char * string,int32_t * array,int32_t arrayLen)130 bool GetJsonObjectIntArrayItem(const cJSON *json, const char *string, int32_t *array, int32_t arrayLen)
131 {
132     return GetJsonUtilsInterface()->GetJsonObjectIntArrayItem(json, string, array, arrayLen);
133 }
134 }
135 } // namespace OHOS