RDK Documentation (Open Sourced RDK Components)
FakeAampJsonObject.cpp
1 /*
2 * If not stated otherwise in this file or this component's license file the
3 * following copyright and licenses apply:
4 *
5 * Copyright 2022 RDK Management
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19 
20 #include "MockAampJsonObject.h"
21 #include "AampJsonObject.h"
22 
23 std::shared_ptr<MockAampJsonObject> g_mockAampJsonObject;
24 
25 AampJsonObject::AampJsonObject() : mParent(NULL), mJsonObj()
26 {
27 }
28 
29 AampJsonObject::AampJsonObject(const std::string& jsonStr) : mParent(NULL), mJsonObj()
30 {
31 }
32 
33 AampJsonObject::AampJsonObject(const char* jsonStr) : mParent(NULL), mJsonObj()
34 {
35 }
36 
37 AampJsonObject::~AampJsonObject()
38 {
39 }
40 
41 bool AampJsonObject::add(const std::string& name, const std::string& value, const ENCODING encoding)
42 {
43  if (g_mockAampJsonObject != nullptr)
44  {
45  return g_mockAampJsonObject->add(name, value, encoding);
46  }
47  return false;
48 }
49 
50 bool AampJsonObject::add(const std::string& name, const char *value, const ENCODING encoding)
51 {
52  if (g_mockAampJsonObject != nullptr)
53  {
54  return g_mockAampJsonObject->add(name, value, encoding);
55  }
56  return false;
57 }
58 
59 bool AampJsonObject::add(const std::string& name, const std::vector<std::string>& values)
60 {
61  if (g_mockAampJsonObject != nullptr)
62  {
63  return g_mockAampJsonObject->add(name, values);
64  }
65  return false;
66 }
67 
68 bool AampJsonObject::add(const std::string& name, const std::vector<uint8_t>& values, const ENCODING encoding)
69 {
70  if (g_mockAampJsonObject != nullptr)
71  {
72  return g_mockAampJsonObject->add(name, values, encoding);
73  }
74  return false;
75 }
76 
77 bool AampJsonObject::add(const std::string& name, AampJsonObject& value)
78 {
79  if (g_mockAampJsonObject != nullptr)
80  {
81  return g_mockAampJsonObject->add(name, value);
82  }
83  return false;
84 }
85 
86 bool AampJsonObject::add(const std::string& name, std::vector<AampJsonObject*>& values)
87 {
88  if (g_mockAampJsonObject != nullptr)
89  {
90  return g_mockAampJsonObject->add(name, values);
91  }
92  return false;
93 }
94 
95 bool AampJsonObject::add(const std::string& name, cJSON *value)
96 {
97  if (g_mockAampJsonObject != nullptr)
98  {
99  return g_mockAampJsonObject->add(name, value);
100  }
101  return false;
102 }
103 
104 bool AampJsonObject::add(const std::string& name, bool value)
105 {
106  if (g_mockAampJsonObject != nullptr)
107  {
108  return g_mockAampJsonObject->add(name, value);
109  }
110  return false;
111 }
112 
113 bool AampJsonObject::add(const std::string& name, int value)
114 {
115  if (g_mockAampJsonObject != nullptr)
116  {
117  return g_mockAampJsonObject->add(name, value);
118  }
119  return false;
120 }
121 
122 bool AampJsonObject::add(const std::string& name, double value)
123 {
124  if (g_mockAampJsonObject != nullptr)
125  {
126  return g_mockAampJsonObject->add(name, value);
127  }
128  return false;
129 }
130 
131 bool AampJsonObject::add(const std::string& name, long value)
132 {
133  if (g_mockAampJsonObject != nullptr)
134  {
135  return g_mockAampJsonObject->add(name, value);
136  }
137  return false;
138 }
139 
140 bool AampJsonObject::set(AampJsonObject *parent, cJSON *object)
141 {
142  if (g_mockAampJsonObject != nullptr)
143  {
144  return g_mockAampJsonObject->set(parent, object);
145  }
146  return false;
147 }
148 
149 bool AampJsonObject::get(const std::string& name, AampJsonObject &value)
150 {
151  if (g_mockAampJsonObject != nullptr)
152  {
153  return g_mockAampJsonObject->get(name, value);
154  }
155  return false;
156 }
157 
158 bool AampJsonObject::get(const std::string& name, std::string& value)
159 {
160  if (g_mockAampJsonObject != nullptr)
161  {
162  return g_mockAampJsonObject->get(name, value);
163  }
164  return false;
165 }
166 
167 bool AampJsonObject::get(const std::string& name, int& value)
168 {
169  if (g_mockAampJsonObject != nullptr)
170  {
171  return g_mockAampJsonObject->get(name, value);
172  }
173  return false;
174 }
175 
176 bool AampJsonObject::get(const std::string& name, std::vector<std::string>& values)
177 {
178  if (g_mockAampJsonObject != nullptr)
179  {
180  return g_mockAampJsonObject->get(name, values);
181  }
182  return false;
183 }
184 
185 bool AampJsonObject::get(const std::string& name, std::vector<uint8_t>& values, const ENCODING encoding)
186 {
187  if (g_mockAampJsonObject != nullptr)
188  {
189  return g_mockAampJsonObject->get(name, values, encoding);
190  }
191  return false;
192 }
193 
194 std::string AampJsonObject::print()
195 {
196  return "";
197 }
198 
200 {
201  return "";
202 }
203 
204 void AampJsonObject::print(std::vector<uint8_t>& data)
205 {
206 }
207 
208 bool AampJsonObject::isArray(const std::string& name)
209 {
210  return false;
211 }
212 
213 bool AampJsonObject::isString(const std::string& name)
214 {
215  return false;
216 }
217 
218 bool AampJsonObject::isNumber(const std::string& name)
219 {
220  return false;
221 }
222 
223 bool AampJsonObject::isObject(const std::string& name)
224 {
225  return false;
226 }
AampJsonObject::set
bool set(AampJsonObject *parent, cJSON *object)
Set cJSON value.
Definition: AampJsonObject.cpp:229
AampJsonObject::get
bool get(const std::string &name, std::vector< std::string > &values)
Get a string value.
Definition: AampJsonObject.cpp:291
AampJsonObject::isArray
bool isArray(const std::string &name)
Check whether the value is Array or not.
Definition: AampJsonObject.cpp:404
AampJsonObject::isObject
bool isObject(const std::string &name)
Check whether the value is Object or not.
Definition: AampJsonObject.cpp:446
AampJsonObject::isString
bool isString(const std::string &name)
Check whether the value is String or not.
Definition: AampJsonObject.cpp:418
AampJsonObject.h
File to handle Json format.
AampJsonObject::print
std::string print()
Print the constructed JSON to a string.
Definition: AampJsonObject.cpp:365
AampJsonObject::isNumber
bool isNumber(const std::string &name)
Check whether the value is Number or not.
Definition: AampJsonObject.cpp:432
AampJsonObject::print_UnFormatted
std::string print_UnFormatted()
Print the constructed JSON to a string.
Definition: AampJsonObject.cpp:380
AampJsonObject::add
bool add(const std::string &name, const std::string &value, const ENCODING encoding=ENCODING_STRING)
Add a string value.
Definition: AampJsonObject.cpp:69
AampJsonObject
Utility class to construct a JSON string.
Definition: AampJsonObject.h:37