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 #include "base/pt_types.h"
17 #include "dispatcher.h"
18
19 #include "ecmascript/js_array.h"
20 #include "ecmascript/js_object-inl.h"
21 #include "ecmascript/js_tagged_value-inl.h"
22 #include "ecmascript/object_factory.h"
23 #include "ecmascript/tests/test_helper.h"
24
25 using namespace panda::ecmascript;
26 using namespace panda::ecmascript::tooling;
27
28 namespace panda::test {
29
30 // Duplicate name of panda::ecmascript::PropertyDescriptor in js_object-inl.h
31 using panda::ecmascript::tooling::PropertyDescriptor;
32
33 using ObjectType = RemoteObject::TypeName;
34 using ObjectSubType = RemoteObject::SubTypeName;
35 using ObjectClassName = RemoteObject::ClassName;
36
37 class DebuggerTypesTest : public testing::Test {
38 public:
SetUpTestCase()39 static void SetUpTestCase()
40 {
41 GTEST_LOG_(INFO) << "SetUpTestCase";
42 Logger::InitializeStdLogging(Logger::Level::FATAL, LoggerComponentMaskAll);
43 }
44
TearDownTestCase()45 static void TearDownTestCase()
46 {
47 Logger::InitializeStdLogging(Logger::Level::ERROR, LoggerComponentMaskAll);
48 GTEST_LOG_(INFO) << "TearDownCase";
49 }
50
SetUp()51 void SetUp() override
52 {
53 TestHelper::CreateEcmaVMWithScope(ecmaVm, thread, scope);
54 // Main logic is JSON parser, so not need trigger GC to decrease execute time
55 ecmaVm->SetEnableForceGC(false);
56 }
57
TearDown()58 void TearDown() override
59 {
60 TestHelper::DestroyEcmaVMWithScope(ecmaVm, scope);
61 }
62
63 protected:
64 EcmaVM *ecmaVm {nullptr};
65 EcmaHandleScope *scope {nullptr};
66 JSThread *thread {nullptr};
67 };
68
HWTEST_F_L0(DebuggerTypesTest,RemoteObjectCreateTest)69 HWTEST_F_L0(DebuggerTypesTest, RemoteObjectCreateTest)
70 {
71 std::string msg;
72 std::unique_ptr<RemoteObject> remoteObject;
73
74 // abnormal params of null msg
75 msg = std::string() + R"({})";
76 remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams());
77 EXPECT_EQ(remoteObject, nullptr);
78
79 // abnormal params of unexist key params
80 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
81 remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams());
82 EXPECT_EQ(remoteObject, nullptr);
83
84 // abnormal params of null params.sub-key
85 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
86 remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams());
87 EXPECT_EQ(remoteObject, nullptr);
88
89 // abnormal params of unknown params.sub-key
90 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
91 remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams());
92 EXPECT_EQ(remoteObject, nullptr);
93
94 // abnormal params of params.sub-key = [ type = 100, ]
95 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":100}})";
96 remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams());
97 EXPECT_EQ(remoteObject, nullptr);
98
99 // abnormal params of params.sub-key = [ type = [ "sub": "test" ] }, ]
100 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":100}})";
101 remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams());
102 EXPECT_EQ(remoteObject, nullptr);
103
104 // normal params of params.sub-key = [ type = "object", ]
105 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object + R"("}})";
106 remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams());
107 ASSERT_NE(remoteObject, nullptr);
108 EXPECT_EQ(ObjectType::Object, remoteObject->GetType());
109
110 // abnormal params of params.sub-key = [ type = "object", subtype = "unknown"]
111 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object +
112 R"(","subtype":"unknown"}})";
113 remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams());
114 EXPECT_EQ(remoteObject, nullptr);
115
116 // abnormal params of params.sub-key = [ type = "object", subtype = 100]
117 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object +
118 R"(","subtype":100}})";
119 remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams());
120 EXPECT_EQ(remoteObject, nullptr);
121
122 // normal params of params.sub-key = [ type = "object", subtype = "array"]
123 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object +
124 R"(","subtype":")" + ObjectSubType::Array + R"("}})";
125 remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams());
126 ASSERT_NE(remoteObject, nullptr);
127 EXPECT_EQ(ObjectType::Object, remoteObject->GetType());
128 ASSERT_TRUE(remoteObject->HasSubType());
129 EXPECT_EQ(ObjectSubType::Array, remoteObject->GetSubType());
130
131 // abnormal params of params.sub-key = [ type = "object", className = 100]
132 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object +
133 R"(","className":100}})";
134 remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams());
135 EXPECT_EQ(remoteObject, nullptr);
136
137 // abnormal params of params.sub-key = [ type = "object", className = {"xx":"yy"}]
138 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object +
139 R"(","className":{"xx":"yy"}}})";
140 remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams());
141 EXPECT_EQ(remoteObject, nullptr);
142
143 // normal params of params.sub-key = [ type = "object", className = "TestClass"]
144 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object +
145 R"(","className":"TestClass"}})";
146 remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams());
147 ASSERT_NE(remoteObject, nullptr);
148 EXPECT_EQ(ObjectType::Object, remoteObject->GetType());
149 ASSERT_TRUE(remoteObject->HasClassName());
150 EXPECT_EQ("TestClass", remoteObject->GetClassName());
151
152 // normal params of params.sub-key = [ type = "object", value = 100]
153 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object +
154 R"(","value":100}})";
155 remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams());
156 ASSERT_NE(remoteObject, nullptr);
157 EXPECT_EQ(ObjectType::Object, remoteObject->GetType());
158
159 // normal params of params.sub-key = [ type = "object", value = {"xx":"yy"}]
160 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object +
161 R"(","value":{"xx":"yy"}}})";
162 remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams());
163 ASSERT_NE(remoteObject, nullptr);
164 EXPECT_EQ(ObjectType::Object, remoteObject->GetType());
165
166 // normal params of params.sub-key = [ type = "object", value = "Test"]
167 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object +
168 R"(","value":"Test"}})";
169 remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams());
170 ASSERT_NE(remoteObject, nullptr);
171 EXPECT_EQ(ObjectType::Object, remoteObject->GetType());
172
173 // abnormal params of params.sub-key = [ type = "object", unserializableValue = 100]
174 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object +
175 R"(","unserializableValue":100}})";
176 remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams());
177 EXPECT_EQ(remoteObject, nullptr);
178
179 // abnormal params of params.sub-key = [ type = "object", unserializableValue = {"xx":"yy"}]
180 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object +
181 R"(","unserializableValue":{"xx":"yy"}}})";
182 remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams());
183 EXPECT_EQ(remoteObject, nullptr);
184
185 // normal params of params.sub-key = [ type = "object", unserializableValue = "TestClass"]
186 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object +
187 R"(","unserializableValue":"Test"}})";
188 remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams());
189 ASSERT_NE(remoteObject, nullptr);
190 EXPECT_EQ(ObjectType::Object, remoteObject->GetType());
191 ASSERT_TRUE(remoteObject->HasUnserializableValue());
192 EXPECT_EQ("Test", remoteObject->GetUnserializableValue());
193
194 // abnormal params of params.sub-key = [ type = "object", description = 100]
195 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object +
196 R"(","description":100}})";
197 remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams());
198 EXPECT_EQ(remoteObject, nullptr);
199
200 // abnormal params of params.sub-key = [ type = "object", description = {"xx":"yy"}]
201 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object +
202 R"(","description":{"xx":"yy"}}})";
203 remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams());
204 EXPECT_EQ(remoteObject, nullptr);
205
206 // normal params of params.sub-key = [ type = "object", description = "Test"]
207 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object +
208 R"(","description":"Test"}})";
209 remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams());
210 ASSERT_NE(remoteObject, nullptr);
211 EXPECT_EQ(ObjectType::Object, remoteObject->GetType());
212 ASSERT_TRUE(remoteObject->HasDescription());
213 EXPECT_EQ("Test", remoteObject->GetDescription());
214
215 // abnormal params of params.sub-key = [ type = "object", objectId = 100]
216 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object +
217 R"(","objectId":100}})";
218 remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams());
219 EXPECT_EQ(remoteObject, nullptr);
220
221 // abnormal params of params.sub-key = [ type = "object", objectId = {"xx":"yy"}]
222 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object +
223 R"(","objectId":{"xx":"yy"}}})";
224 remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams());
225 EXPECT_EQ(remoteObject, nullptr);
226
227 // normal params of params.sub-key = [ type = "object", objectId = "id_1"]
228 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object +
229 R"(","objectId":"1"}})";
230 remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams());
231 ASSERT_NE(remoteObject, nullptr);
232 EXPECT_EQ(ObjectType::Object, remoteObject->GetType());
233 ASSERT_TRUE(remoteObject->HasObjectId());
234 EXPECT_EQ(remoteObject->GetObjectId(), 1);
235 }
236
HWTEST_F_L0(DebuggerTypesTest,RemoteObjectToJsonTest)237 HWTEST_F_L0(DebuggerTypesTest, RemoteObjectToJsonTest)
238 {
239 std::string msg;
240 std::unique_ptr<RemoteObject> remoteObject;
241 std::string tmpStr;
242 Result ret;
243
244 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object +
245 R"(", "subtype":")" + ObjectSubType::Array +
246 R"(","className":"TestClass","value":100, "unserializableValue":"Test","description":"Test","objectId":"1"}})";
247 remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams());
248 ASSERT_NE(remoteObject, nullptr);
249 auto objJson = remoteObject->ToJson();
250
251 ret = objJson->GetString("type", &tmpStr);
252 EXPECT_EQ(ret, Result::SUCCESS);
253 EXPECT_EQ(std::string(ObjectType::Object.c_str()), tmpStr);
254
255 ret = objJson->GetString("subtype", &tmpStr);
256 EXPECT_EQ(ret, Result::SUCCESS);
257 EXPECT_EQ(std::string(ObjectSubType::Array.c_str()), tmpStr);
258
259 ret = objJson->GetString("className", &tmpStr);
260 EXPECT_EQ(ret, Result::SUCCESS);
261 EXPECT_EQ("TestClass", tmpStr);
262
263 ret = objJson->GetString("unserializableValue", &tmpStr);
264 EXPECT_EQ(ret, Result::SUCCESS);
265 EXPECT_EQ("Test", tmpStr);
266
267 ret = objJson->GetString("description", &tmpStr);
268 EXPECT_EQ(ret, Result::SUCCESS);
269 EXPECT_EQ("Test", tmpStr);
270
271 ret = objJson->GetString("objectId", &tmpStr);
272 EXPECT_EQ(ret, Result::SUCCESS);
273 EXPECT_EQ("1", tmpStr);
274 }
275
HWTEST_F_L0(DebuggerTypesTest,ExceptionDetailsCreateTest)276 HWTEST_F_L0(DebuggerTypesTest, ExceptionDetailsCreateTest)
277 {
278 std::string msg;
279 std::unique_ptr<ExceptionDetails> exceptionMetaData;
280
281 // abnormal params of null msg
282 msg = std::string() + R"({})";
283 exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams());
284 EXPECT_EQ(exceptionMetaData, nullptr);
285
286 // abnormal params of unexist key params
287 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
288 exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams());
289 EXPECT_EQ(exceptionMetaData, nullptr);
290
291 // abnormal params of null params.sub-key
292 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
293 exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams());
294 EXPECT_EQ(exceptionMetaData, nullptr);
295
296 // abnormal params of unknown params.sub-key
297 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
298 exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams());
299 EXPECT_EQ(exceptionMetaData, nullptr);
300
301 // abnormal params of params.sub-key = [ exceptionId="Test","text"="text0","lineNumber"=10,"columnNumber"=20]
302 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
303 "exceptionId":"Test","text":"text0","lineNumber":10,"columnNumber":20}})";
304 exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams());
305 EXPECT_EQ(exceptionMetaData, nullptr);
306
307 // abnormal params of params.sub-key = [ exceptionId={"xx":"yy"},"text"="text0","lineNumber"=10,"columnNumber"=20]
308 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
309 "exceptionId":{"xx":"yy"},"text":"text0","lineNumber":10,"columnNumber":20}})";
310 exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams());
311 EXPECT_EQ(exceptionMetaData, nullptr);
312
313 // abnormal params of params.sub-key = [ exceptionId=3,"text"=10,"lineNumber"=10,"columnNumber"=20]
314 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
315 "exceptionId":3,"text":10,"lineNumber":10,"columnNumber":20}})";
316 exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams());
317 EXPECT_EQ(exceptionMetaData, nullptr);
318
319 // abnormal params of params.sub-key = [ exceptionId=3,"text"=["text0"],"lineNumber"=10,"columnNumber"=20]
320 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
321 "exceptionId":3,"text":["text0"],"lineNumber":10,"columnNumber":20}})";
322 exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams());
323 EXPECT_EQ(exceptionMetaData, nullptr);
324
325 // abnormal params of params.sub-key = [ exceptionId=3,"text"="text0","lineNumber"="10","columnNumber"=20]
326 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
327 "exceptionId":3,"text":"text0","lineNumber":"10","columnNumber":20}})";
328 exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams());
329 EXPECT_EQ(exceptionMetaData, nullptr);
330
331 // abnormal params of params.sub-key = [ exceptionId=3,"text"="text0","lineNumber"=["10"],"columnNumber"=20]
332 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
333 "exceptionId":3,"text":"text0","lineNumber":["10"],"columnNumber":20}})";
334 exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams());
335 EXPECT_EQ(exceptionMetaData, nullptr);
336
337 // abnormal params of params.sub-key = [ exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"="20"]
338 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
339 "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":"20"}})";
340 exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams());
341 EXPECT_EQ(exceptionMetaData, nullptr);
342
343 // abnormal params of params.sub-key = [ exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=["20"]]
344 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
345 "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":["20"]}})";
346 exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams());
347 EXPECT_EQ(exceptionMetaData, nullptr);
348
349 // normal params of params.sub-key = [ exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=20]
350 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
351 "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20}})";
352 exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams());
353 ASSERT_NE(exceptionMetaData, nullptr);
354 EXPECT_EQ(exceptionMetaData->GetExceptionId(), 3);
355 EXPECT_EQ("text0", exceptionMetaData->GetText());
356 EXPECT_EQ(exceptionMetaData->GetLine(), 10);
357 EXPECT_EQ(exceptionMetaData->GetColumn(), 20);
358
359 // abnormal params of params.sub-key =
360 // [exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=20,"scriptId"=10]
361 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
362 "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20,"scriptId":10}})";
363 exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams());
364 EXPECT_EQ(exceptionMetaData, nullptr);
365
366 // abnormal params of params.sub-key =
367 // [exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=20,"scriptId"=["10"]]
368 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
369 "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20,"scriptId":["10"]}})";
370 exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams());
371 EXPECT_EQ(exceptionMetaData, nullptr);
372
373 // normal params of params.sub-key =
374 // [exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=20,"scriptId"="id0"]
375 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
376 "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20,"scriptId":"0"}})";
377 exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams());
378 ASSERT_NE(exceptionMetaData, nullptr);
379 EXPECT_EQ(exceptionMetaData->GetExceptionId(), 3);
380 EXPECT_EQ("text0", exceptionMetaData->GetText());
381 EXPECT_EQ(exceptionMetaData->GetLine(), 10);
382 EXPECT_EQ(exceptionMetaData->GetColumn(), 20);
383 EXPECT_EQ(exceptionMetaData->GetScriptId(), 0);
384
385 // abnormal params of params.sub-key =
386 // [exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=20,"url"=10]
387 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
388 "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20,"url":10}})";
389 exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams());
390 EXPECT_EQ(exceptionMetaData, nullptr);
391
392 // abnormal params of params.sub-key =
393 // [exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=20,"url"=["10"]]
394 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
395 "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20,"url":["10"]}})";
396 exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams());
397 EXPECT_EQ(exceptionMetaData, nullptr);
398
399 // normal params of params.sub-key =
400 // [exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=20,"url"="url0"]
401 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
402 "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20,"url":"url0"}})";
403 exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams());
404 ASSERT_NE(exceptionMetaData, nullptr);
405 EXPECT_EQ(exceptionMetaData->GetExceptionId(), 3);
406 EXPECT_EQ("text0", exceptionMetaData->GetText());
407 EXPECT_EQ(exceptionMetaData->GetLine(), 10);
408 EXPECT_EQ(exceptionMetaData->GetColumn(), 20);
409 EXPECT_EQ("url0", exceptionMetaData->GetUrl());
410
411 // abnormal params of params.sub-key =
412 // [exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=20,"exception"=10]
413 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
414 "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20,"exception":10}})";
415 exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams());
416 EXPECT_EQ(exceptionMetaData, nullptr);
417
418 // abnormal params of params.sub-key =
419 // [exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=20,"exception"=["10"]]
420 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
421 "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20,"exception":["10"]}})";
422 exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams());
423 EXPECT_EQ(exceptionMetaData, nullptr);
424
425 // normal params of params.sub-key =
426 // [exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=20,"exception"={}]
427 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
428 "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20,"exception":{"type":")" +
429 ObjectType::Object + R"(","subtype":")" + ObjectSubType::Error + R"("}}})";
430 exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams());
431 ASSERT_NE(exceptionMetaData, nullptr);
432 EXPECT_EQ(exceptionMetaData->GetExceptionId(), 3);
433 EXPECT_EQ("text0", exceptionMetaData->GetText());
434 EXPECT_EQ(exceptionMetaData->GetLine(), 10);
435 EXPECT_EQ(exceptionMetaData->GetColumn(), 20);
436 RemoteObject *exception = exceptionMetaData->GetException();
437 ASSERT_NE(exception, nullptr);
438 EXPECT_EQ(exception->GetType(), ObjectType::Object);
439 EXPECT_EQ(exception->GetSubType(), ObjectSubType::Error);
440
441 // abnormal params of params.sub-key =
442 // [exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=20,"executionContextId"="10"]
443 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
444 "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20,"executionContextId":"10"}})";
445 exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams());
446 EXPECT_EQ(exceptionMetaData, nullptr);
447
448 // abnormal params of params.sub-key =
449 // [exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=20,"executionContextId"=["10"]]
450 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
451 "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20,"executionContextId":["10"]}})";
452 exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams());
453 EXPECT_EQ(exceptionMetaData, nullptr);
454
455 // normal params of params.sub-key =
456 // [exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=20,"executionContextId"=2]
457 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
458 "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20,"executionContextId":2}})";
459 exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams());
460 ASSERT_NE(exceptionMetaData, nullptr);
461 EXPECT_EQ(exceptionMetaData->GetExceptionId(), 3);
462 EXPECT_EQ("text0", exceptionMetaData->GetText());
463 EXPECT_EQ(exceptionMetaData->GetLine(), 10);
464 EXPECT_EQ(exceptionMetaData->GetColumn(), 20);
465 EXPECT_EQ(exceptionMetaData->GetExecutionContextId(), 2);
466 }
467
HWTEST_F_L0(DebuggerTypesTest,ExceptionDetailsToJsonTest)468 HWTEST_F_L0(DebuggerTypesTest, ExceptionDetailsToJsonTest)
469 {
470 std::string msg;
471 std::unique_ptr<ExceptionDetails> exceptionMetaData;
472 std::string tmpStr;
473 int32_t tmpInt;
474 std::unique_ptr<PtJson> tmpJson;
475 Result ret;
476
477 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
478 "exceptionId":5,"text":"text0","lineNumber":10,"columnNumber":20,"scriptId":"100","url":"url0",
479 "exception":{"type":")" +
480 ObjectType::Object + R"(","subtype":")" + ObjectSubType::Error + R"("},"executionContextId":30}})";
481 exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams());
482 ASSERT_NE(exceptionMetaData, nullptr);
483 auto objJson = exceptionMetaData->ToJson();
484
485 ret = objJson->GetInt("exceptionId", &tmpInt);
486 EXPECT_EQ(ret, Result::SUCCESS);
487 EXPECT_EQ(tmpInt, 5);
488
489 ret = objJson->GetString("text", &tmpStr);
490 EXPECT_EQ(ret, Result::SUCCESS);
491 EXPECT_EQ("text0", tmpStr);
492
493 ret = objJson->GetInt("lineNumber", &tmpInt);
494 EXPECT_EQ(ret, Result::SUCCESS);
495 EXPECT_EQ(tmpInt, 10);
496
497 ret = objJson->GetInt("columnNumber", &tmpInt);
498 EXPECT_EQ(ret, Result::SUCCESS);
499 EXPECT_EQ(tmpInt, 20);
500
501 ret = objJson->GetString("scriptId", &tmpStr);
502 EXPECT_EQ(ret, Result::SUCCESS);
503 EXPECT_EQ("100", tmpStr);
504
505 ret = objJson->GetString("url", &tmpStr);
506 EXPECT_EQ(ret, Result::SUCCESS);
507 EXPECT_EQ("url0", tmpStr);
508
509 ret = objJson->GetObject("exception", &tmpJson);
510 EXPECT_EQ(ret, Result::SUCCESS);
511 ASSERT_NE(tmpJson, nullptr);
512 ret = tmpJson->GetString("type", &tmpStr);
513 EXPECT_EQ(ret, Result::SUCCESS);
514 EXPECT_EQ(std::string(ObjectType::Object.c_str()), tmpStr);
515 ret = tmpJson->GetString("subtype", &tmpStr);
516 EXPECT_EQ(ret, Result::SUCCESS);
517 EXPECT_EQ(std::string(ObjectSubType::Error.c_str()), tmpStr);
518
519 ret = objJson->GetInt("executionContextId", &tmpInt);
520 EXPECT_EQ(ret, Result::SUCCESS);
521 EXPECT_EQ(tmpInt, 30);
522 }
523
HWTEST_F_L0(DebuggerTypesTest,InternalPropertyDescriptorCreateTest)524 HWTEST_F_L0(DebuggerTypesTest, InternalPropertyDescriptorCreateTest)
525 {
526 std::string msg;
527 std::unique_ptr<InternalPropertyDescriptor> internalPropertyDescriptor;
528
529 // abnormal params of null msg
530 msg = std::string() + R"({})";
531 internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams());
532 EXPECT_EQ(internalPropertyDescriptor, nullptr);
533
534 // abnormal params of unexist key params
535 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
536 internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams());
537 EXPECT_EQ(internalPropertyDescriptor, nullptr);
538
539 // abnormal params of null params.sub-key
540 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
541 internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams());
542 EXPECT_EQ(internalPropertyDescriptor, nullptr);
543
544 // abnormal params of unknown params.sub-key=["name":"name8"]
545 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
546 "name":"name8","value":99}})";
547 internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams());
548 EXPECT_EQ(internalPropertyDescriptor, nullptr);
549
550 // abnormal params of unknown params.sub-key=["name":"name8"]
551 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
552 "name":"name8","value":99}})";
553 internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams());
554 EXPECT_EQ(internalPropertyDescriptor, nullptr);
555
556 // abnormal params of unknown params.sub-key=["name":"name8","value":99]
557 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
558 "name":"name8","value":99}})";
559 internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams());
560 EXPECT_EQ(internalPropertyDescriptor, nullptr);
561
562 // abnormal params of unknown params.sub-key
563 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
564 internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams());
565 EXPECT_EQ(internalPropertyDescriptor, nullptr);
566
567 // abnormal params of unknown params.sub-key=["name":99]
568 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
569 "name":"name8","value":99}})";
570 internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams());
571 EXPECT_EQ(internalPropertyDescriptor, nullptr);
572
573 // abnormal params of unknown params.sub-key=["name":[99]]
574 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
575 "name":"name8","value":[99]}})";
576 internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams());
577 EXPECT_EQ(internalPropertyDescriptor, nullptr);
578
579 // normal params of params.sub-key=["name":"name7"]
580 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
581 "name":"name7"}})";
582 internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams());
583 ASSERT_NE(internalPropertyDescriptor, nullptr);
584 EXPECT_EQ("name7", internalPropertyDescriptor->GetName());
585
586 // abnormal params of unknown params.sub-key=["name":"name8","value":{"type":"object","subtype":"map"}]
587 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
588 "name":"name8","value":"99"}})";
589 internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams());
590 EXPECT_EQ(internalPropertyDescriptor, nullptr);
591
592 // abnormal params of unknown params.sub-key=["name":"name8","value":{"type":"object","subtype":"wrong"}]
593 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
594 "name":"name8","value":{"type":")" +
595 ObjectType::Object + R"(","subtype":"wrong"}}})";
596 internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams());
597 EXPECT_EQ(internalPropertyDescriptor, nullptr);
598
599 // normal params of params.sub-key=["name":"name8","value":{"type":"object","subtype":"map"}]
600 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
601 "name":"name8","value":{"type":")" +
602 ObjectType::Object + R"(","subtype":")" + ObjectSubType::Map + R"("}}})";
603 internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams());
604 ASSERT_NE(internalPropertyDescriptor, nullptr);
605 EXPECT_EQ("name8", internalPropertyDescriptor->GetName());
606 ASSERT_TRUE(internalPropertyDescriptor->HasValue());
607 RemoteObject *value = internalPropertyDescriptor->GetValue();
608 ASSERT_NE(value, nullptr);
609 EXPECT_EQ(value->GetType(), ObjectType::Object);
610 EXPECT_EQ(value->GetSubType(), ObjectSubType::Map);
611 }
612
HWTEST_F_L0(DebuggerTypesTest,InternalPropertyDescriptorToJsonTest)613 HWTEST_F_L0(DebuggerTypesTest, InternalPropertyDescriptorToJsonTest)
614 {
615 std::string msg;
616 std::unique_ptr<InternalPropertyDescriptor> internalPropertyDescriptor;
617 std::string tmpStr;
618 std::unique_ptr<PtJson> tmpJson;
619 Result ret;
620
621 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
622 "name":"name8","value":{"type":")" +
623 ObjectType::Object + R"(","subtype":")" + ObjectSubType::Map + R"("}}})";
624 internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams());
625 ASSERT_NE(internalPropertyDescriptor, nullptr);
626 auto objJson = internalPropertyDescriptor->ToJson();
627
628 ret = objJson->GetString("name", &tmpStr);
629 EXPECT_EQ(ret, Result::SUCCESS);
630 EXPECT_EQ("name8", tmpStr);
631
632 ret = objJson->GetObject("value", &tmpJson);
633 EXPECT_EQ(ret, Result::SUCCESS);
634 ASSERT_NE(tmpJson, nullptr);
635 ret = tmpJson->GetString("type", &tmpStr);
636 EXPECT_EQ(ret, Result::SUCCESS);
637 EXPECT_EQ(std::string(ObjectType::Object.c_str()), tmpStr);
638 ret = tmpJson->GetString("subtype", &tmpStr);
639 EXPECT_EQ(ret, Result::SUCCESS);
640 EXPECT_EQ(std::string(ObjectSubType::Map.c_str()), tmpStr);
641 }
642
HWTEST_F_L0(DebuggerTypesTest,PropertyDescriptorCreateTest)643 HWTEST_F_L0(DebuggerTypesTest, PropertyDescriptorCreateTest)
644 {
645 std::string msg;
646 std::unique_ptr<PropertyDescriptor> propertyDescriptor;
647
648 // abnormal params of null msg
649 msg = std::string() + R"({})";
650 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
651 EXPECT_EQ(propertyDescriptor, nullptr);
652
653 // abnormal params of unexist key params
654 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
655 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
656 EXPECT_EQ(propertyDescriptor, nullptr);
657
658 // abnormal params of null params.sub-key
659 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
660 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
661 EXPECT_EQ(propertyDescriptor, nullptr);
662
663 // abnormal params of unknown params.sub-key
664 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
665 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
666 EXPECT_EQ(propertyDescriptor, nullptr);
667
668 // abnormal params of params.sub-key=["name":10,"configurable":true,"enumerable":true]
669 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
670 "name":10,"configurable":true,"enumerable":true,"value":10}})";
671 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
672 EXPECT_EQ(propertyDescriptor, nullptr);
673
674 // abnormal params of params.sub-key=["name":["name85"],"configurable":true,"enumerable":true]
675 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
676 "name":["name85"],"configurable":true,"enumerable":true,"value":10}})";
677 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
678 EXPECT_EQ(propertyDescriptor, nullptr);
679
680 // abnormal params of params.sub-key=["name":"name8","configurable":10,"enumerable":true]
681 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
682 "name":"name85","configurable":10,"enumerable":true}})";
683 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
684 EXPECT_EQ(propertyDescriptor, nullptr);
685
686 // abnormal params of params.sub-key=["name":"name8","configurable":"true","enumerable":true]
687 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
688 "name":"name85","configurable":"true","enumerable":true}})";
689 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
690 EXPECT_EQ(propertyDescriptor, nullptr);
691
692 // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":10]
693 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
694 "name":"name85","configurable":true,"enumerable":10}})";
695 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
696 EXPECT_EQ(propertyDescriptor, nullptr);
697
698 // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":"true"]
699 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
700 "name":"name85","configurable":true,"enumerable":"true"}})";
701 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
702 EXPECT_EQ(propertyDescriptor, nullptr);
703
704 // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"value":10]
705 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
706 "name":"name85","configurable":true,"enumerable":true,"value":10}})";
707 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
708 EXPECT_EQ(propertyDescriptor, nullptr);
709
710 // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"value":{"ee":"11"}]
711 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
712 "name":"name85","configurable":true,"enumerable":true,"value":{"ee":"11"}}})";
713 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
714 EXPECT_EQ(propertyDescriptor, nullptr);
715
716 // normal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"value":{..}]
717 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
718 "name":"name85","configurable":true,"enumerable":true,"value":{"type":")" +
719 ObjectType::Symbol + R"("}}})";
720 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
721 ASSERT_NE(propertyDescriptor, nullptr);
722 EXPECT_EQ("name85", propertyDescriptor->GetName());
723 ASSERT_TRUE(propertyDescriptor->GetConfigurable());
724 ASSERT_TRUE(propertyDescriptor->GetEnumerable());
725 RemoteObject *value = propertyDescriptor->GetValue();
726 ASSERT_NE(value, nullptr);
727 EXPECT_EQ(value->GetType(), ObjectType::Symbol);
728
729 // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"writable":98]
730 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
731 "name":"name85","configurable":true,"enumerable":true,"writable":98}})";
732 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
733 EXPECT_EQ(propertyDescriptor, nullptr);
734
735 // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"writable":[true]]
736 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
737 "name":"name85","configurable":true,"enumerable":true,"writable":[true]}})";
738 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
739 EXPECT_EQ(propertyDescriptor, nullptr);
740
741 // normal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"writable":true]
742 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
743 "name":"name85","configurable":true,"enumerable":true,"writable":true}})";
744 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
745 ASSERT_NE(propertyDescriptor, nullptr);
746 EXPECT_EQ("name85", propertyDescriptor->GetName());
747 ASSERT_TRUE(propertyDescriptor->GetConfigurable());
748 ASSERT_TRUE(propertyDescriptor->GetEnumerable());
749 ASSERT_TRUE(propertyDescriptor->GetWritable());
750
751 // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"get":10]
752 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
753 "name":"name85","configurable":true,"enumerable":true,"get":10}})";
754 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
755 EXPECT_EQ(propertyDescriptor, nullptr);
756
757 // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"get":[10]]
758 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
759 "name":"name85","configurable":true,"enumerable":true,"get":[10]}})";
760 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
761 EXPECT_EQ(propertyDescriptor, nullptr);
762
763 // normal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"get":{}]
764 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
765 "name":"name85","configurable":true,"enumerable":true,"get":{"type":")" +
766 ObjectType::Function + R"("}}})";
767 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
768 ASSERT_NE(propertyDescriptor, nullptr);
769 EXPECT_EQ("name85", propertyDescriptor->GetName());
770 ASSERT_TRUE(propertyDescriptor->GetConfigurable());
771 ASSERT_TRUE(propertyDescriptor->GetEnumerable());
772 RemoteObject *get = propertyDescriptor->GetGet();
773 ASSERT_NE(get, nullptr);
774 EXPECT_EQ(get->GetType(), ObjectType::Function);
775
776 // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"set":10]
777 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
778 "name":"name85","configurable":true,"enumerable":true,"set":10}})";
779 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
780 EXPECT_EQ(propertyDescriptor, nullptr);
781
782 // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"set":[10]]
783 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
784 "name":"name85","configurable":true,"enumerable":true,"set":[10]}})";
785 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
786 EXPECT_EQ(propertyDescriptor, nullptr);
787
788 // normal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"set":{}]
789 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
790 "name":"name85","configurable":true,"enumerable":true,"set":{"type":")" +
791 ObjectType::String + R"("}}})";
792 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
793 ASSERT_NE(propertyDescriptor, nullptr);
794 EXPECT_EQ("name85", propertyDescriptor->GetName());
795 ASSERT_TRUE(propertyDescriptor->GetConfigurable());
796 ASSERT_TRUE(propertyDescriptor->GetEnumerable());
797 RemoteObject *set = propertyDescriptor->GetSet();
798 ASSERT_NE(set, nullptr);
799 EXPECT_EQ(set->GetType(), ObjectType::String);
800
801 // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"wasThrown":98]
802 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
803 "name":"name85","configurable":true,"enumerable":true,"wasThrown":98}})";
804 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
805 EXPECT_EQ(propertyDescriptor, nullptr);
806
807 // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"wasThrown":[true]]
808 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
809 "name":"name85","configurable":true,"enumerable":true,"wasThrown":[true]}})";
810 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
811 EXPECT_EQ(propertyDescriptor, nullptr);
812
813 // normal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"wasThrown":true]
814 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
815 "name":"name85","configurable":true,"enumerable":true,"wasThrown":true}})";
816 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
817 ASSERT_NE(propertyDescriptor, nullptr);
818 EXPECT_EQ("name85", propertyDescriptor->GetName());
819 ASSERT_TRUE(propertyDescriptor->GetConfigurable());
820 ASSERT_TRUE(propertyDescriptor->GetEnumerable());
821 ASSERT_TRUE(propertyDescriptor->GetWasThrown());
822
823 // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"isOwn":98]
824 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
825 "name":"name85","configurable":true,"enumerable":true,"isOwn":98}})";
826 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
827 EXPECT_EQ(propertyDescriptor, nullptr);
828
829 // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"isOwn":[true]]
830 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
831 "name":"name85","configurable":true,"enumerable":true,"isOwn":[true]}})";
832 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
833 EXPECT_EQ(propertyDescriptor, nullptr);
834
835 // normal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"isOwn":true]
836 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
837 "name":"name85","configurable":true,"enumerable":true,"isOwn":true}})";
838 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
839 ASSERT_NE(propertyDescriptor, nullptr);
840 EXPECT_EQ("name85", propertyDescriptor->GetName());
841 ASSERT_TRUE(propertyDescriptor->GetConfigurable());
842 ASSERT_TRUE(propertyDescriptor->GetEnumerable());
843 ASSERT_TRUE(propertyDescriptor->GetIsOwn());
844
845 // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true, "symbol":10]
846 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
847 "name":"name85","configurable":true,"enumerable":true,"symbol":10}})";
848 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
849 EXPECT_EQ(propertyDescriptor, nullptr);
850
851 // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true, "symbol":[10]]
852 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
853 "name":"name85","configurable":true,"enumerable":true,"symbol":[10]}})";
854 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
855 EXPECT_EQ(propertyDescriptor, nullptr);
856
857 // normal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true, "symbol":{}]
858 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
859 "name":"name85","configurable":true,"enumerable":true,"symbol":{"type":")" +
860 ObjectType::Wasm + R"("}}})";
861 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
862 ASSERT_NE(propertyDescriptor, nullptr);
863 EXPECT_EQ("name85", propertyDescriptor->GetName());
864 ASSERT_TRUE(propertyDescriptor->GetConfigurable());
865 ASSERT_TRUE(propertyDescriptor->GetEnumerable());
866 RemoteObject *symbol = propertyDescriptor->GetSymbol();
867 ASSERT_NE(symbol, nullptr);
868 EXPECT_EQ(symbol->GetType(), ObjectType::Wasm);
869 }
870
HWTEST_F_L0(DebuggerTypesTest,PropertyDescriptorToJsonTest)871 HWTEST_F_L0(DebuggerTypesTest, PropertyDescriptorToJsonTest)
872 {
873 std::string msg;
874 std::unique_ptr<PropertyDescriptor> propertyDescriptor;
875 std::string tmpStr;
876 std::unique_ptr<PtJson> tmpJson;
877 bool tmpBool;
878 Result ret;
879
880 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
881 "name":"name8","value":{"type":")" +
882 ObjectType::Object + R"(","subtype":")" + ObjectSubType::Map + R"("},
883 "writable":true,"get":{"type":")" +
884 ObjectType::Object + R"(","subtype":")" + ObjectSubType::Regexp + R"("},"set":{"type":")" +
885 ObjectType::Object + R"(","subtype":")" + ObjectSubType::Generator +
886 R"("},"configurable":true,"enumerable":true,"wasThrown":true,"isOwn":true,"symbol":{"type":")" +
887 ObjectType::Object + R"(","subtype":")" + ObjectSubType::Proxy + R"("}}})";
888 propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams());
889 ASSERT_NE(propertyDescriptor, nullptr);
890 auto objJson = propertyDescriptor->ToJson();
891
892 ret = objJson->GetString("name", &tmpStr);
893 EXPECT_EQ(ret, Result::SUCCESS);
894 EXPECT_EQ("name8", tmpStr);
895
896 ret = objJson->GetObject("value", &tmpJson);
897 EXPECT_EQ(ret, Result::SUCCESS);
898 ASSERT_NE(tmpJson, nullptr);
899 ret = tmpJson->GetString("type", &tmpStr);
900 EXPECT_EQ(ret, Result::SUCCESS);
901 EXPECT_EQ(std::string(ObjectType::Object.c_str()), tmpStr);
902 ret = tmpJson->GetString("subtype", &tmpStr);
903 EXPECT_EQ(ret, Result::SUCCESS);
904 EXPECT_EQ(std::string(ObjectSubType::Map.c_str()), tmpStr);
905
906 ret = objJson->GetBool("writable", &tmpBool);
907 EXPECT_EQ(ret, Result::SUCCESS);
908 ASSERT_TRUE(tmpBool);
909
910 ret = objJson->GetObject("get", &tmpJson);
911 EXPECT_EQ(ret, Result::SUCCESS);
912 ASSERT_NE(tmpJson, nullptr);
913 ret = tmpJson->GetString("type", &tmpStr);
914 EXPECT_EQ(ret, Result::SUCCESS);
915 EXPECT_EQ(std::string(ObjectType::Object.c_str()), tmpStr);
916 ret = tmpJson->GetString("subtype", &tmpStr);
917 EXPECT_EQ(ret, Result::SUCCESS);
918 EXPECT_EQ(std::string(ObjectSubType::Regexp.c_str()), tmpStr);
919
920 ret = objJson->GetObject("set", &tmpJson);
921 EXPECT_EQ(ret, Result::SUCCESS);
922 ASSERT_NE(tmpJson, nullptr);
923 ret = tmpJson->GetString("type", &tmpStr);
924 EXPECT_EQ(ret, Result::SUCCESS);
925 EXPECT_EQ(std::string(ObjectType::Object.c_str()), tmpStr);
926 ret = tmpJson->GetString("subtype", &tmpStr);
927 EXPECT_EQ(ret, Result::SUCCESS);
928 EXPECT_EQ(std::string(ObjectSubType::Generator.c_str()), tmpStr);
929
930 ret = objJson->GetBool("configurable", &tmpBool);
931 EXPECT_EQ(ret, Result::SUCCESS);
932 ASSERT_TRUE(tmpBool);
933
934 ret = objJson->GetBool("enumerable", &tmpBool);
935 EXPECT_EQ(ret, Result::SUCCESS);
936 ASSERT_TRUE(tmpBool);
937
938 ret = objJson->GetBool("wasThrown", &tmpBool);
939 EXPECT_EQ(ret, Result::SUCCESS);
940 ASSERT_TRUE(tmpBool);
941
942 ret = objJson->GetBool("isOwn", &tmpBool);
943 EXPECT_EQ(ret, Result::SUCCESS);
944 ASSERT_TRUE(tmpBool);
945
946 ret = objJson->GetObject("symbol", &tmpJson);
947 EXPECT_EQ(ret, Result::SUCCESS);
948 ASSERT_NE(tmpJson, nullptr);
949 ret = tmpJson->GetString("type", &tmpStr);
950 EXPECT_EQ(ret, Result::SUCCESS);
951 EXPECT_EQ(std::string(ObjectType::Object.c_str()), tmpStr);
952 ret = tmpJson->GetString("subtype", &tmpStr);
953 EXPECT_EQ(ret, Result::SUCCESS);
954 EXPECT_EQ(std::string(ObjectSubType::Proxy.c_str()), tmpStr);
955 }
956
HWTEST_F_L0(DebuggerTypesTest,LocationCreateTest)957 HWTEST_F_L0(DebuggerTypesTest, LocationCreateTest)
958 {
959 std::string msg;
960 std::unique_ptr<Location> location;
961
962 // abnormal params of null msg
963 msg = std::string() + R"({})";
964 location = Location::Create(DispatchRequest(msg).GetParams());
965 EXPECT_EQ(location, nullptr);
966
967 // abnormal params of unexist key params
968 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
969 location = Location::Create(DispatchRequest(msg).GetParams());
970 EXPECT_EQ(location, nullptr);
971
972 // abnormal params of null params.sub-key
973 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
974 location = Location::Create(DispatchRequest(msg).GetParams());
975 EXPECT_EQ(location, nullptr);
976
977 // abnormal params of unknown params.sub-key
978 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
979 location = Location::Create(DispatchRequest(msg).GetParams());
980 EXPECT_EQ(location, nullptr);
981
982 // abnormal params of params.sub-key=["scriptId":10,"lineNumber":99]
983 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
984 "scriptId":10,"lineNumber":99
985 }})";
986 location = Location::Create(DispatchRequest(msg).GetParams());
987 EXPECT_EQ(location, nullptr);
988
989 // abnormal params of params.sub-key=["scriptId":["id3"],"lineNumber":99]
990 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
991 "scriptId":["id3"],"lineNumber":99
992 }})";
993 location = Location::Create(DispatchRequest(msg).GetParams());
994 EXPECT_EQ(location, nullptr);
995
996 // abnormal params of params.sub-key=["scriptId":"222","lineNumber":"99"]
997 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
998 "scriptId":"222","lineNumber":"99"
999 }})";
1000 location = Location::Create(DispatchRequest(msg).GetParams());
1001 EXPECT_EQ(location, nullptr);
1002
1003 // abnormal params of params.sub-key=["scriptId":"222","lineNumber":[99]]
1004 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1005 "scriptId":"222","lineNumber":[99]
1006 }})";
1007 location = Location::Create(DispatchRequest(msg).GetParams());
1008 EXPECT_EQ(location, nullptr);
1009
1010 // normal params of params.sub-key=["scriptId":"2","lineNumber":99,"columnNumber":138]
1011 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1012 "scriptId":"222","lineNumber":899,"columnNumber":138
1013 }})";
1014 location = Location::Create(DispatchRequest(msg).GetParams());
1015 ASSERT_NE(location, nullptr);
1016 EXPECT_EQ(location->GetScriptId(), 222);
1017 EXPECT_EQ(location->GetLine(), 899);
1018 EXPECT_EQ(location->GetColumn(), 138);
1019
1020 // normal params of params.sub-key=["scriptId":"2122","lineNumber":8299]
1021 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1022 "scriptId":"2122","lineNumber":8299
1023 }})";
1024 location = Location::Create(DispatchRequest(msg).GetParams());
1025 ASSERT_NE(location, nullptr);
1026 EXPECT_EQ(location->GetScriptId(), 2122);
1027 EXPECT_EQ(location->GetLine(), 8299);
1028 }
1029
HWTEST_F_L0(DebuggerTypesTest,LocationToJsonTest)1030 HWTEST_F_L0(DebuggerTypesTest, LocationToJsonTest)
1031 {
1032 std::string msg;
1033 std::unique_ptr<Location> location;
1034 std::string tmpStr;
1035 int32_t tmpInt;
1036 Result ret;
1037
1038 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1039 "scriptId":"2","lineNumber":99,"columnNumber":18
1040 }})";
1041 location = Location::Create(DispatchRequest(msg).GetParams());
1042 ASSERT_NE(location, nullptr);
1043 auto objJson = location->ToJson();
1044
1045 ret = objJson->GetString("scriptId", &tmpStr);
1046 EXPECT_EQ(ret, Result::SUCCESS);
1047 EXPECT_EQ("2", tmpStr);
1048
1049 ret = objJson->GetInt("lineNumber", &tmpInt);
1050 EXPECT_EQ(ret, Result::SUCCESS);
1051 EXPECT_EQ(tmpInt, 99);
1052
1053 ret = objJson->GetInt("columnNumber", &tmpInt);
1054 EXPECT_EQ(ret, Result::SUCCESS);
1055 EXPECT_EQ(tmpInt, 18);
1056 }
1057
HWTEST_F_L0(DebuggerTypesTest,BreakLocationCreateTest)1058 HWTEST_F_L0(DebuggerTypesTest, BreakLocationCreateTest)
1059 {
1060 std::string msg;
1061 std::unique_ptr<BreakLocation> breakLocation;
1062
1063 // abnormal params of null msg
1064 msg = std::string() + R"({})";
1065 breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams());
1066 EXPECT_EQ(breakLocation, nullptr);
1067
1068 // abnormal params of unexist key params
1069 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
1070 breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams());
1071 EXPECT_EQ(breakLocation, nullptr);
1072
1073 // abnormal params of null params.sub-key
1074 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
1075 breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams());
1076 EXPECT_EQ(breakLocation, nullptr);
1077
1078 // abnormal params of unknown params.sub-key
1079 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
1080 breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams());
1081 EXPECT_EQ(breakLocation, nullptr);
1082
1083 // abnormal params of params.sub-key=["scriptId":10,"lineNumber":99]
1084 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1085 "scriptId":10,"lineNumber":99
1086 }})";
1087 breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams());
1088 EXPECT_EQ(breakLocation, nullptr);
1089
1090 // abnormal params of params.sub-key=["scriptId":["id3"],"lineNumber":99]
1091 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1092 "scriptId":["id3"],"lineNumber":99
1093 }})";
1094 breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams());
1095 EXPECT_EQ(breakLocation, nullptr);
1096
1097 // abnormal params of params.sub-key=["scriptId":"222","lineNumber":"99"]
1098 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1099 "scriptId":"222","lineNumber":"99"
1100 }})";
1101 breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams());
1102 EXPECT_EQ(breakLocation, nullptr);
1103
1104 // abnormal params of params.sub-key=["scriptId":"222","lineNumber":[99]]
1105 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1106 "scriptId":"222","lineNumber":[99]
1107 }})";
1108 breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams());
1109 EXPECT_EQ(breakLocation, nullptr);
1110
1111 // abnormal params of params.sub-key=["scriptId":"2","lineNumber":99,"columnNumber":"18"]
1112 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1113 "scriptId":"222","lineNumber":899,"columnNumber":"18"
1114 }})";
1115 breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams());
1116 EXPECT_EQ(breakLocation, nullptr);
1117
1118 // abnormal params of params.sub-key=["scriptId":"2","lineNumber":99,"columnNumber":"18","type":10]
1119 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1120 "scriptId":"222","lineNumber":899,"columnNumber":"18","type":10
1121 }})";
1122 breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams());
1123 EXPECT_EQ(breakLocation, nullptr);
1124
1125 // abnormal params of params.sub-key=["scriptId":"2","lineNumber":99,"columnNumber":"18","type":"ee"]
1126 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1127 "scriptId":"222","lineNumber":899,"columnNumber":"18","type":"ee"
1128 }})";
1129 breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams());
1130 EXPECT_EQ(breakLocation, nullptr);
1131
1132 // normal params of params.sub-key=["scriptId":"2","lineNumber":99,"columnNumber":138,"type":"return"]
1133 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1134 "scriptId":"222","lineNumber":899,"columnNumber":138,"type":"return"
1135 }})";
1136 breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams());
1137 ASSERT_NE(breakLocation, nullptr);
1138 EXPECT_EQ(breakLocation->GetScriptId(), 222);
1139 EXPECT_EQ(breakLocation->GetLine(), 899);
1140 EXPECT_EQ(breakLocation->GetColumn(), 138);
1141 EXPECT_EQ("return", breakLocation->GetType());
1142
1143 // normal params of params.sub-key=["scriptId":"2122","lineNumber":8299]
1144 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1145 "scriptId":"2122","lineNumber":8299
1146 }})";
1147 breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams());
1148 ASSERT_NE(breakLocation, nullptr);
1149 EXPECT_EQ(breakLocation->GetScriptId(), 2122);
1150 EXPECT_EQ(breakLocation->GetLine(), 8299);
1151 }
1152
HWTEST_F_L0(DebuggerTypesTest,BreakLocationToJsonTest)1153 HWTEST_F_L0(DebuggerTypesTest, BreakLocationToJsonTest)
1154 {
1155 std::string msg;
1156 std::unique_ptr<BreakLocation> breakLocation;
1157 std::string tmpStr;
1158 int32_t tmpInt;
1159 Result ret;
1160
1161 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1162 "scriptId":"12","lineNumber":919,"columnNumber":148,"type":"call"
1163 }})";
1164 breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams());
1165 ASSERT_NE(breakLocation, nullptr);
1166 auto objJson = breakLocation->ToJson();
1167
1168 ret = objJson->GetString("scriptId", &tmpStr);
1169 EXPECT_EQ(ret, Result::SUCCESS);
1170 EXPECT_EQ("12", tmpStr);
1171
1172 ret = objJson->GetInt("lineNumber", &tmpInt);
1173 EXPECT_EQ(ret, Result::SUCCESS);
1174 EXPECT_EQ(tmpInt, 919);
1175
1176 ret = objJson->GetInt("columnNumber", &tmpInt);
1177 EXPECT_EQ(ret, Result::SUCCESS);
1178 EXPECT_EQ(tmpInt, 148);
1179
1180 ret = objJson->GetString("type", &tmpStr);
1181 EXPECT_EQ(ret, Result::SUCCESS);
1182 EXPECT_EQ("call", tmpStr);
1183 }
1184
HWTEST_F_L0(DebuggerTypesTest,ScopeCreateTest)1185 HWTEST_F_L0(DebuggerTypesTest, ScopeCreateTest)
1186 {
1187 std::string msg;
1188 std::unique_ptr<Scope> scope;
1189
1190 // abnormal params of null msg
1191 msg = std::string() + R"({})";
1192 scope = Scope::Create(DispatchRequest(msg).GetParams());
1193 EXPECT_EQ(scope, nullptr);
1194
1195 // abnormal params of unexist key params
1196 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
1197 scope = Scope::Create(DispatchRequest(msg).GetParams());
1198 EXPECT_EQ(scope, nullptr);
1199
1200 // abnormal params of null params.sub-key
1201 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
1202 scope = Scope::Create(DispatchRequest(msg).GetParams());
1203 EXPECT_EQ(scope, nullptr);
1204
1205 // abnormal params of unknown params.sub-key
1206 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
1207 scope = Scope::Create(DispatchRequest(msg).GetParams());
1208 EXPECT_EQ(scope, nullptr);
1209
1210 // abnormal params of params.sub-key=["type":"ss","object":{..}]
1211 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1212 "type":"ss","object":{"type":")" +
1213 ObjectType::Bigint + R"("}}})";
1214 scope = Scope::Create(DispatchRequest(msg).GetParams());
1215 EXPECT_EQ(scope, nullptr);
1216
1217 // abnormal params of params.sub-key=["type":12,"object":{..}]
1218 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1219 "type":12,"object":{"type":")" +
1220 ObjectType::Bigint + R"("}}})";
1221 scope = Scope::Create(DispatchRequest(msg).GetParams());
1222 EXPECT_EQ(scope, nullptr);
1223
1224 // abnormal params of params.sub-key=["type":"global","object":10]
1225 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1226 "type":"global","object":10}})";
1227 scope = Scope::Create(DispatchRequest(msg).GetParams());
1228 EXPECT_EQ(scope, nullptr);
1229
1230 // abnormal params of params.sub-key=["type":"global","object":{..}]
1231 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1232 "type":"global","object":{"ww":")" +
1233 ObjectType::Bigint + R"("}}})";
1234 scope = Scope::Create(DispatchRequest(msg).GetParams());
1235 EXPECT_EQ(scope, nullptr);
1236
1237 // abnormal params of params.sub-key=["type":"global","object":{..},"name":10]
1238 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1239 "type":"global","object":{"type":")" +
1240 ObjectType::Bigint + R"("},"name":10}})";
1241 scope = Scope::Create(DispatchRequest(msg).GetParams());
1242 EXPECT_EQ(scope, nullptr);
1243
1244 // abnormal params of params.sub-key=["type":"global","object":{..},"name":["10"]]
1245 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1246 "type":"global","object":{"type":")" +
1247 ObjectType::Bigint + R"("},"name":["10"]}})";
1248 scope = Scope::Create(DispatchRequest(msg).GetParams());
1249 EXPECT_EQ(scope, nullptr);
1250
1251 // normal params of params.sub-key=["type":"global","object":{..},"name":"name128"]
1252 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1253 "type":"global","object":{"type":")" +
1254 ObjectType::Bigint + R"("},"name":"name117"}})";
1255 scope = Scope::Create(DispatchRequest(msg).GetParams());
1256 ASSERT_NE(scope, nullptr);
1257 EXPECT_EQ("name117", scope->GetName());
1258
1259 // abnormal params of params.sub-key=["type":"global","object":{..},"startLocation":10]
1260 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1261 "type":"global","object":{"type":")" +
1262 ObjectType::Bigint + R"("},"startLocation":10}})";
1263 scope = Scope::Create(DispatchRequest(msg).GetParams());
1264 EXPECT_EQ(scope, nullptr);
1265
1266 // abnormal params of params.sub-key=["type":"global","object":{..},"startLocation":{"12":"34"}]
1267 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1268 "type":"global","object":{"type":")" +
1269 ObjectType::Bigint + R"("},"startLocation":{"12":"34"}}})";
1270 scope = Scope::Create(DispatchRequest(msg).GetParams());
1271 EXPECT_EQ(scope, nullptr);
1272
1273 // abnormal params of params.sub-key=["type":"global","object":{..},"endLocation":10]
1274 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1275 "type":"global","object":{"type":")" +
1276 ObjectType::Bigint + R"("},"endLocation":10}})";
1277 scope = Scope::Create(DispatchRequest(msg).GetParams());
1278 EXPECT_EQ(scope, nullptr);
1279
1280 // abnormal params of params.sub-key=["type":"global","object":{..},"endLocation":{"12":"34"}]
1281 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1282 "type":"global","object":{"type":")" +
1283 ObjectType::Bigint + R"("},"endLocation":{"12":"34"}}})";
1284 scope = Scope::Create(DispatchRequest(msg).GetParams());
1285 EXPECT_EQ(scope, nullptr);
1286
1287 // normal params of params.sub-key=["type":"global","object":{..}]
1288 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1289 "type":"global","object":{"type":")" +
1290 ObjectType::Bigint + R"("}}})";
1291 scope = Scope::Create(DispatchRequest(msg).GetParams());
1292 ASSERT_NE(scope, nullptr);
1293 EXPECT_EQ("global", scope->GetType());
1294 RemoteObject *object = scope->GetObject();
1295 ASSERT_NE(object, nullptr);
1296 EXPECT_EQ(object->GetType(), ObjectType::Bigint);
1297 }
1298
HWTEST_F_L0(DebuggerTypesTest,ScopeToJsonTest)1299 HWTEST_F_L0(DebuggerTypesTest, ScopeToJsonTest)
1300 {
1301 std::string msg;
1302 std::unique_ptr<Scope> scope;
1303 std::string tmpStr;
1304 int32_t tmpInt;
1305 std::unique_ptr<PtJson> tmpJson;
1306 Result ret;
1307
1308 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1309 "type":"global","object":{"type":")" +
1310 ObjectType::Object + R"(","subtype":")" + ObjectSubType::Dataview + R"("},"name":"name9",
1311 "startLocation":{"scriptId":"2","lineNumber":99},
1312 "endLocation":{"scriptId":"13","lineNumber":146}
1313 }})";
1314 scope = Scope::Create(DispatchRequest(msg).GetParams());
1315 ASSERT_NE(scope, nullptr);
1316 auto objJson = scope->ToJson();
1317
1318 ret = objJson->GetString("type", &tmpStr);
1319 EXPECT_EQ(ret, Result::SUCCESS);
1320 EXPECT_EQ("global", tmpStr);
1321
1322 ret = objJson->GetObject("object", &tmpJson);
1323 EXPECT_EQ(ret, Result::SUCCESS);
1324 ASSERT_NE(tmpJson, nullptr);
1325 ret = tmpJson->GetString("type", &tmpStr);
1326 EXPECT_EQ(ret, Result::SUCCESS);
1327 EXPECT_EQ(std::string(ObjectType::Object.c_str()), tmpStr);
1328 ret = tmpJson->GetString("subtype", &tmpStr);
1329 EXPECT_EQ(ret, Result::SUCCESS);
1330 EXPECT_EQ(std::string(ObjectSubType::Dataview.c_str()), tmpStr);
1331
1332 ret = objJson->GetString("name", &tmpStr);
1333 EXPECT_EQ(ret, Result::SUCCESS);
1334 EXPECT_EQ("name9", tmpStr);
1335
1336 ret = objJson->GetObject("startLocation", &tmpJson);
1337 EXPECT_EQ(ret, Result::SUCCESS);
1338 ASSERT_NE(tmpJson, nullptr);
1339 ret = tmpJson->GetString("scriptId", &tmpStr);
1340 EXPECT_EQ(ret, Result::SUCCESS);
1341 EXPECT_EQ("2", tmpStr);
1342 ret = tmpJson->GetInt("lineNumber", &tmpInt);
1343 EXPECT_EQ(ret, Result::SUCCESS);
1344 EXPECT_EQ(tmpInt, 99);
1345
1346 ret = objJson->GetObject("endLocation", &tmpJson);
1347 EXPECT_EQ(ret, Result::SUCCESS);
1348 ASSERT_NE(tmpJson, nullptr);
1349 ret = tmpJson->GetString("scriptId", &tmpStr);
1350 EXPECT_EQ(ret, Result::SUCCESS);
1351 EXPECT_EQ("13", tmpStr);
1352 ret = tmpJson->GetInt("lineNumber", &tmpInt);
1353 EXPECT_EQ(ret, Result::SUCCESS);
1354 EXPECT_EQ(tmpInt, 146);
1355 }
1356
HWTEST_F_L0(DebuggerTypesTest,CallFrameCreateTest)1357 HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest)
1358 {
1359 std::string msg;
1360 std::unique_ptr<CallFrame> callFrame;
1361
1362 // abnormal params of null msg
1363 msg = std::string() + R"({})";
1364 callFrame = CallFrame::Create(DispatchRequest(msg).GetParams());
1365 EXPECT_EQ(callFrame, nullptr);
1366
1367 // abnormal params of unexist key params
1368 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
1369 callFrame = CallFrame::Create(DispatchRequest(msg).GetParams());
1370 EXPECT_EQ(callFrame, nullptr);
1371
1372 // abnormal params of null params.sub-key
1373 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
1374 callFrame = CallFrame::Create(DispatchRequest(msg).GetParams());
1375 EXPECT_EQ(callFrame, nullptr);
1376
1377 // abnormal params of unknown params.sub-key
1378 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
1379 callFrame = CallFrame::Create(DispatchRequest(msg).GetParams());
1380 EXPECT_EQ(callFrame, nullptr);
1381
1382 // abnormal params of params.sub-key=[..]
1383 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1384 "callFrameId":10,"functionName":"name0",
1385 "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain":
1386 [{"type":"global","object":{"type":")" +
1387 ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object +
1388 R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})";
1389 callFrame = CallFrame::Create(DispatchRequest(msg).GetParams());
1390 EXPECT_EQ(callFrame, nullptr);
1391
1392 // abnormal params of params.sub-key=[..]
1393 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1394 "callFrameId":["0"],"functionName":"name0",
1395 "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain":
1396 [{"type":"global","object":{"type":")" +
1397 ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object +
1398 R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})";
1399 callFrame = CallFrame::Create(DispatchRequest(msg).GetParams());
1400 EXPECT_EQ(callFrame, nullptr);
1401
1402 // abnormal params of params.sub-key=[..]
1403 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1404 "callFrameId":"0","functionName":10,
1405 "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain":
1406 [{"type":"global","object":{"type":")" +
1407 ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object +
1408 R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})";
1409 callFrame = CallFrame::Create(DispatchRequest(msg).GetParams());
1410 EXPECT_EQ(callFrame, nullptr);
1411
1412 // abnormal params of params.sub-key=[..]
1413 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1414 "callFrameId":"0","functionName":["name0"],
1415 "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain":
1416 [{"type":"global","object":{"type":")" +
1417 ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object +
1418 R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})";
1419 callFrame = CallFrame::Create(DispatchRequest(msg).GetParams());
1420 EXPECT_EQ(callFrame, nullptr);
1421
1422 // abnormal params of params.sub-key=[..]
1423 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1424 "callFrameId":"0","functionName":"name0","functionLocation":10,
1425 "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain":
1426 [{"type":"global","object":{"type":")" +
1427 ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object +
1428 R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})";
1429 callFrame = CallFrame::Create(DispatchRequest(msg).GetParams());
1430 EXPECT_EQ(callFrame, nullptr);
1431
1432 // abnormal params of params.sub-key=[..]
1433 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1434 "callFrameId":"0","functionName":"name0","functionLocation":{"scriptId11":"id5","lineNumber":19},
1435 "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain":
1436 [{"type":"global","object":{"type":")" +
1437 ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object +
1438 R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})";
1439 callFrame = CallFrame::Create(DispatchRequest(msg).GetParams());
1440 EXPECT_EQ(callFrame, nullptr);
1441
1442 // abnormal params of params.sub-key=[..]
1443 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1444 "callFrameId":"0","functionName":"name0",
1445 "location":{"scriptId2":"id5","lineNumber":19},"url":"url7","scopeChain":
1446 [{"type":"global","object":{"type":")" +
1447 ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object +
1448 R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})";
1449 callFrame = CallFrame::Create(DispatchRequest(msg).GetParams());
1450 EXPECT_EQ(callFrame, nullptr);
1451
1452 // abnormal params of params.sub-key=[..]
1453 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1454 "callFrameId":"0","functionName":"name0",
1455 "location":10,"url":"url7","scopeChain":
1456 [{"type":"global","object":{"type":")" +
1457 ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object +
1458 R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})";
1459 callFrame = CallFrame::Create(DispatchRequest(msg).GetParams());
1460 EXPECT_EQ(callFrame, nullptr);
1461
1462 // abnormal params of params.sub-key=[..]
1463 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1464 "callFrameId":"0","functionName":"name0",
1465 "location":{"scriptId":"5","lineNumber":19},"url":10,"scopeChain":
1466 [{"type":"global","object":{"type":")" +
1467 ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object +
1468 R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})";
1469 callFrame = CallFrame::Create(DispatchRequest(msg).GetParams());
1470 EXPECT_EQ(callFrame, nullptr);
1471
1472 // abnormal params of params.sub-key=[..]
1473 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1474 "callFrameId":"0","functionName":"name0",
1475 "location":{"scriptId":"5","lineNumber":19},"url":{"url":"url7"},"scopeChain":
1476 [{"type":"global","object":{"type":")" +
1477 ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object +
1478 R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})";
1479 callFrame = CallFrame::Create(DispatchRequest(msg).GetParams());
1480 EXPECT_EQ(callFrame, nullptr);
1481
1482 // abnormal params of params.sub-key=[..]
1483 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1484 "callFrameId":"0","functionName":"name0", "location":{"scriptId":"5","lineNumber":19},
1485 "url":"url7","scopeChain":10,"this":{"type":")" +
1486 ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})";
1487 callFrame = CallFrame::Create(DispatchRequest(msg).GetParams());
1488 EXPECT_EQ(callFrame, nullptr);
1489
1490 // abnormal params of params.sub-key=[..]
1491 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1492 "callFrameId":"0","functionName":"name0",
1493 "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain":
1494 {"type":"22","object":{"type":")" +
1495 ObjectType::Object + R"("}},"this":{"type":")" + ObjectType::Object + R"(","subtype":")" +
1496 ObjectSubType::V128 + R"("}}})";
1497 callFrame = CallFrame::Create(DispatchRequest(msg).GetParams());
1498 EXPECT_EQ(callFrame, nullptr);
1499
1500 // abnormal params of params.sub-key=[..]
1501 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1502 "callFrameId":"0","functionName":"name0",
1503 "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain":
1504 [{"type":"global","object":{"type":")" +
1505 ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object +
1506 R"("}}],"this":10}})";
1507 callFrame = CallFrame::Create(DispatchRequest(msg).GetParams());
1508 EXPECT_EQ(callFrame, nullptr);
1509
1510 // abnormal params of params.sub-key=[..]
1511 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1512 "callFrameId":"0","functionName":"name0",
1513 "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain":
1514 [{"type":"global","object":{"type":")" +
1515 ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object +
1516 R"("}}],"this":{"11":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})";
1517 callFrame = CallFrame::Create(DispatchRequest(msg).GetParams());
1518 EXPECT_EQ(callFrame, nullptr);
1519
1520 // abnormal params of params.sub-key=[..]
1521 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1522 "callFrameId":"0","functionName":"name0",
1523 "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain":
1524 [{"type":"global","object":{"type":")" +
1525 ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object +
1526 R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("},
1527 "returnValue":10}})";
1528 callFrame = CallFrame::Create(DispatchRequest(msg).GetParams());
1529 EXPECT_EQ(callFrame, nullptr);
1530
1531 // abnormal params of params.sub-key=[..]
1532 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1533 "callFrameId":"0","functionName":"name0",
1534 "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain":
1535 [{"type":"global","object":{"type":")" +
1536 ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object +
1537 R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("},
1538 "returnValue":{"type":"object","subtype":"11"}}})";
1539 callFrame = CallFrame::Create(DispatchRequest(msg).GetParams());
1540 EXPECT_EQ(callFrame, nullptr);
1541
1542 // normal params of params.sub-key=[..]
1543 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1544 "callFrameId":"0","functionName":"name0",
1545 "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain":
1546 [{"type":"global","object":{"type":")" +
1547 ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object +
1548 R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})";
1549 callFrame = CallFrame::Create(DispatchRequest(msg).GetParams());
1550 ASSERT_NE(callFrame, nullptr);
1551 EXPECT_EQ(callFrame->GetCallFrameId(), 0);
1552 EXPECT_EQ("name0", callFrame->GetFunctionName());
1553 ASSERT_FALSE(callFrame->HasFunctionLocation());
1554 Location *location = callFrame->GetLocation();
1555 EXPECT_EQ(location->GetScriptId(), 5);
1556 EXPECT_EQ(location->GetLine(), 19);
1557 EXPECT_EQ("url7", callFrame->GetUrl());
1558 const std::vector<std::unique_ptr<Scope>> *scopeChain = callFrame->GetScopeChain();
1559 EXPECT_EQ(scopeChain->size(), 2U);
1560 RemoteObject *thisObj = callFrame->GetThis();
1561 ASSERT_NE(thisObj, nullptr);
1562 EXPECT_EQ(thisObj->GetType(), ObjectType::Object);
1563 EXPECT_EQ(thisObj->GetSubType(), ObjectSubType::V128);
1564 ASSERT_FALSE(callFrame->HasReturnValue());
1565
1566 // normal params of params.sub-key=[..]
1567 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1568 "callFrameId":"10","functionName":"name0","functionLocation":{"scriptId":"3","lineNumber":16},
1569 "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain":
1570 [{"type":"global","object":{"type":")" +
1571 ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object +
1572 R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 +
1573 R"("},"returnValue":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::I32 + R"("}}})";
1574 callFrame = CallFrame::Create(DispatchRequest(msg).GetParams());
1575 ASSERT_NE(callFrame, nullptr);
1576 EXPECT_EQ(callFrame->GetCallFrameId(), 10);
1577 EXPECT_EQ("name0", callFrame->GetFunctionName());
1578 Location *functionLocation = callFrame->GetFunctionLocation();
1579 EXPECT_EQ(functionLocation->GetScriptId(), 3);
1580 EXPECT_EQ(functionLocation->GetLine(), 16);
1581 location = callFrame->GetLocation();
1582 EXPECT_EQ(location->GetScriptId(), 5);
1583 EXPECT_EQ(location->GetLine(), 19);
1584 EXPECT_EQ("url7", callFrame->GetUrl());
1585 scopeChain = callFrame->GetScopeChain();
1586 EXPECT_EQ(scopeChain->size(), 2U);
1587 thisObj = callFrame->GetThis();
1588 ASSERT_NE(thisObj, nullptr);
1589 EXPECT_EQ(thisObj->GetType(), ObjectType::Object);
1590 EXPECT_EQ(thisObj->GetSubType(), ObjectSubType::V128);
1591 RemoteObject *returnObj = callFrame->GetReturnValue();
1592 ASSERT_NE(returnObj, nullptr);
1593 EXPECT_EQ(returnObj->GetType(), ObjectType::Object);
1594 EXPECT_EQ(returnObj->GetSubType(), ObjectSubType::I32);
1595 }
1596
HWTEST_F_L0(DebuggerTypesTest,CallFrameToJsonTest)1597 HWTEST_F_L0(DebuggerTypesTest, CallFrameToJsonTest)
1598 {
1599 std::string msg;
1600 std::unique_ptr<CallFrame> callFrame;
1601 std::string tmpStr;
1602 int32_t tmpInt;
1603 std::unique_ptr<PtJson> tmpJson;
1604 Result ret;
1605
1606 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1607 "callFrameId":"0","functionName":"name0","functionLocation":{"scriptId":"3","lineNumber":16},
1608 "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain":
1609 [{"type":"global","object":{"type":")" +
1610 ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object +
1611 R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::Iterator +
1612 R"("},"returnValue":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::I64 + R"("}}})";
1613 callFrame = CallFrame::Create(DispatchRequest(msg).GetParams());
1614 ASSERT_NE(callFrame, nullptr);
1615 auto objJson = callFrame->ToJson();
1616
1617 ret = objJson->GetString("callFrameId", &tmpStr);
1618 EXPECT_EQ(ret, Result::SUCCESS);
1619 EXPECT_EQ("0", tmpStr);
1620
1621 ret = objJson->GetString("functionName", &tmpStr);
1622 EXPECT_EQ(ret, Result::SUCCESS);
1623 EXPECT_EQ("name0", tmpStr);
1624
1625 ret = objJson->GetObject("functionLocation", &tmpJson);
1626 EXPECT_EQ(ret, Result::SUCCESS);
1627 ASSERT_NE(tmpJson, nullptr);
1628 ret = tmpJson->GetString("scriptId", &tmpStr);
1629 EXPECT_EQ(ret, Result::SUCCESS);
1630 EXPECT_EQ("3", tmpStr);
1631 ret = tmpJson->GetInt("lineNumber", &tmpInt);
1632 EXPECT_EQ(ret, Result::SUCCESS);
1633 EXPECT_EQ(tmpInt, 16);
1634
1635 ret = objJson->GetObject("location", &tmpJson);
1636 EXPECT_EQ(ret, Result::SUCCESS);
1637 ASSERT_NE(tmpJson, nullptr);
1638 ret = tmpJson->GetString("scriptId", &tmpStr);
1639 EXPECT_EQ(ret, Result::SUCCESS);
1640 EXPECT_EQ("5", tmpStr);
1641 ret = tmpJson->GetInt("lineNumber", &tmpInt);
1642 EXPECT_EQ(ret, Result::SUCCESS);
1643 EXPECT_EQ(tmpInt, 19);
1644
1645 ret = objJson->GetString("url", &tmpStr);
1646 EXPECT_EQ(ret, Result::SUCCESS);
1647 EXPECT_EQ("url7", tmpStr);
1648
1649 ret = objJson->GetArray("scopeChain", &tmpJson);
1650 EXPECT_EQ(ret, Result::SUCCESS);
1651 ASSERT_NE(tmpJson, nullptr);
1652 EXPECT_EQ(tmpJson->GetSize(), 2);
1653
1654 ret = objJson->GetObject("this", &tmpJson);
1655 EXPECT_EQ(ret, Result::SUCCESS);
1656 ASSERT_NE(tmpJson, nullptr);
1657 ret = tmpJson->GetString("type", &tmpStr);
1658 EXPECT_EQ(ret, Result::SUCCESS);
1659 EXPECT_EQ(std::string(ObjectType::Object.c_str()), tmpStr);
1660 ret = tmpJson->GetString("subtype", &tmpStr);
1661 EXPECT_EQ(ret, Result::SUCCESS);
1662 EXPECT_EQ(std::string(ObjectSubType::Iterator.c_str()), tmpStr);
1663
1664 ret = objJson->GetObject("returnValue", &tmpJson);
1665 EXPECT_EQ(ret, Result::SUCCESS);
1666 ASSERT_NE(tmpJson, nullptr);
1667 ret = tmpJson->GetString("type", &tmpStr);
1668 EXPECT_EQ(ret, Result::SUCCESS);
1669 EXPECT_EQ(std::string(ObjectType::Object.c_str()), tmpStr);
1670 ret = tmpJson->GetString("subtype", &tmpStr);
1671 EXPECT_EQ(ret, Result::SUCCESS);
1672 EXPECT_EQ(std::string(ObjectSubType::I64.c_str()), tmpStr);
1673 }
1674
HWTEST_F_L0(DebuggerTypesTest,SamplingHeapProfileSampleCreateTest)1675 HWTEST_F_L0(DebuggerTypesTest, SamplingHeapProfileSampleCreateTest)
1676 {
1677 std::string msg;
1678 std::unique_ptr<SamplingHeapProfileSample> object;
1679
1680 // abnormal params of null msg
1681 msg = std::string() + R"({})";
1682 object = SamplingHeapProfileSample::Create(DispatchRequest(msg).GetParams());
1683 EXPECT_EQ(object, nullptr);
1684
1685 // abnormal params of unexist key params
1686 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
1687 object = SamplingHeapProfileSample::Create(DispatchRequest(msg).GetParams());
1688 EXPECT_EQ(object, nullptr);
1689
1690 // abnormal params of null params.sub-key
1691 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
1692 object = SamplingHeapProfileSample::Create(DispatchRequest(msg).GetParams());
1693 EXPECT_EQ(object, nullptr);
1694
1695 // abnormal params of unknown params.sub-key
1696 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
1697 object = SamplingHeapProfileSample::Create(DispatchRequest(msg).GetParams());
1698 EXPECT_EQ(object, nullptr);
1699
1700 // abnormal params of params.sub-key = [ "size"="Test","nodeId"="Test","ordinal"="Test"]
1701 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1702 "size":"Test","nodeId":"Test","ordinal":"Test"}})";
1703 object = SamplingHeapProfileSample::Create(DispatchRequest(msg).GetParams());
1704 EXPECT_EQ(object, nullptr);
1705
1706 // abnormal params of params.sub-key = [ "size"={"xx":"yy"},"nodeId"={"xx":"yy"},"ordinal"={"xx":"yy"}]
1707 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1708 "size":{"xx":"yy"},"nodeId":{"xx":"yy"},"ordinal":{"xx":"yy"}}})";
1709 object = SamplingHeapProfileSample::Create(DispatchRequest(msg).GetParams());
1710 EXPECT_EQ(object, nullptr);
1711
1712 // abnormal params of params.sub-key = [ "size"=100,"nodeId"=1,"ordinal"=10]
1713 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"size":100,"nodeId":1,"ordinal":10}})";
1714 object = SamplingHeapProfileSample::Create(DispatchRequest(msg).GetParams());
1715 ASSERT_NE(object, nullptr);
1716 EXPECT_EQ(object->GetSize(), 100);
1717 EXPECT_EQ(object->GetNodeId(), 1);
1718 EXPECT_EQ(object->GetOrdinal(), 10);
1719 }
1720
HWTEST_F_L0(DebuggerTypesTest,SamplingHeapProfileSampleToJsonTest)1721 HWTEST_F_L0(DebuggerTypesTest, SamplingHeapProfileSampleToJsonTest)
1722 {
1723 std::string msg;
1724 std::unique_ptr<SamplingHeapProfileSample> samplingHeapProfileSampleData;
1725 std::string tmpStr;
1726 int32_t tmpInt;
1727 Result ret;
1728
1729 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"size":100,"nodeId":1,"ordinal":10}})";
1730 samplingHeapProfileSampleData =
1731 SamplingHeapProfileSample::Create(DispatchRequest(msg).GetParams());
1732 ASSERT_NE(samplingHeapProfileSampleData, nullptr);
1733 auto json = samplingHeapProfileSampleData->ToJson();
1734
1735 ret = json->GetInt("size", &tmpInt);
1736 EXPECT_EQ(ret, Result::SUCCESS);
1737 EXPECT_EQ(tmpInt, 100);
1738 ret = json->GetInt("nodeId", &tmpInt);
1739 EXPECT_EQ(ret, Result::SUCCESS);
1740 EXPECT_EQ(tmpInt, 1);
1741 ret = json->GetInt("ordinal", &tmpInt);
1742 EXPECT_EQ(ret, Result::SUCCESS);
1743 EXPECT_EQ(tmpInt, 10);
1744 }
1745
HWTEST_F_L0(DebuggerTypesTest,SamplingHeapProfileNodeCreateTest)1746 HWTEST_F_L0(DebuggerTypesTest, SamplingHeapProfileNodeCreateTest)
1747 {
1748 std::string msg;
1749 std::unique_ptr<SamplingHeapProfileNode> object;
1750
1751 // abnormal params of null msg
1752 msg = std::string() + R"({})";
1753 object = SamplingHeapProfileNode::Create(DispatchRequest(msg).GetParams());
1754 EXPECT_EQ(object, nullptr);
1755
1756 // abnormal params of unexist key params
1757 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
1758 object = SamplingHeapProfileNode::Create(DispatchRequest(msg).GetParams());
1759 EXPECT_EQ(object, nullptr);
1760
1761 // abnormal params of null params.sub-key
1762 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
1763 object = SamplingHeapProfileNode::Create(DispatchRequest(msg).GetParams());
1764 EXPECT_EQ(object, nullptr);
1765
1766 // abnormal params of unknown params.sub-key
1767 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
1768 object = SamplingHeapProfileNode::Create(DispatchRequest(msg).GetParams());
1769 EXPECT_EQ(object, nullptr);
1770
1771 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1772 "callFrame": {"functionName":"Create", "scriptId":"10", "url":"url3", "lineNumber":100, "columnNumber":20},
1773 "selfSize":10,
1774 "id":5,
1775 "children":[]
1776 }})";
1777 object = SamplingHeapProfileNode::Create(DispatchRequest(msg).GetParams());
1778 ASSERT_NE(object, nullptr);
1779 RuntimeCallFrame *runTimeCallFrame = object->GetCallFrame();
1780 ASSERT_NE(runTimeCallFrame, nullptr);
1781 EXPECT_EQ(runTimeCallFrame->GetFunctionName(), "Create");
1782 EXPECT_EQ(runTimeCallFrame->GetScriptId(), "10");
1783 EXPECT_EQ(runTimeCallFrame->GetUrl(), "url3");
1784 EXPECT_EQ(runTimeCallFrame->GetLineNumber(), 100);
1785 EXPECT_EQ(runTimeCallFrame->GetColumnNumber(), 20);
1786
1787 EXPECT_EQ(object->GetSelfSize(), 10);
1788 EXPECT_EQ(object->GetId(), 5);
1789 const std::vector<std::unique_ptr<SamplingHeapProfileNode>> *children = object->GetChildren();
1790 ASSERT_NE(children, nullptr);
1791 EXPECT_EQ((int)children->size(), 0);
1792 }
1793
HWTEST_F_L0(DebuggerTypesTest,SamplingHeapProfileNodeToJsonTest)1794 HWTEST_F_L0(DebuggerTypesTest, SamplingHeapProfileNodeToJsonTest)
1795 {
1796 std::string msg;
1797 std::unique_ptr<SamplingHeapProfileNode> samplingHeapProfileNode;
1798 std::string tmpStr;
1799 std::unique_ptr<PtJson> tmpJson;
1800 int32_t tmpInt;
1801 Result ret;
1802
1803 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1804 "callFrame": {"functionName":"Create", "scriptId":"10", "url":"url3", "lineNumber":100, "columnNumber":20},
1805 "selfSize":10,
1806 "id":5,
1807 "children":[]
1808 }})";
1809 samplingHeapProfileNode = SamplingHeapProfileNode::Create(DispatchRequest(msg).GetParams());
1810 ASSERT_NE(samplingHeapProfileNode, nullptr);
1811 auto json = samplingHeapProfileNode->ToJson();
1812
1813 ret = json->GetObject("callFrame", &tmpJson);
1814 EXPECT_EQ(ret, Result::SUCCESS);
1815 ASSERT_NE(tmpJson, nullptr);
1816 ret = tmpJson->GetString("functionName", &tmpStr);
1817 EXPECT_EQ(ret, Result::SUCCESS);
1818 EXPECT_EQ(tmpStr, "Create");
1819 ret = tmpJson->GetString("scriptId", &tmpStr);
1820 EXPECT_EQ(ret, Result::SUCCESS);
1821 EXPECT_EQ(tmpStr, "10");
1822 ret = tmpJson->GetString("url", &tmpStr);
1823 EXPECT_EQ(ret, Result::SUCCESS);
1824 EXPECT_EQ(tmpStr, "url3");
1825
1826 ret = json->GetInt("selfSize", &tmpInt);
1827 EXPECT_EQ(ret, Result::SUCCESS);
1828 EXPECT_EQ(tmpInt, 10);
1829 ret = json->GetInt("id", &tmpInt);
1830 EXPECT_EQ(ret, Result::SUCCESS);
1831 EXPECT_EQ(tmpInt, 5);
1832 ret = json->GetArray("children", &tmpJson);
1833 EXPECT_EQ(ret, Result::SUCCESS);
1834 ASSERT_NE(tmpJson, nullptr);
1835 EXPECT_EQ(tmpJson->GetSize(), 0);
1836 }
1837
HWTEST_F_L0(DebuggerTypesTest,SamplingHeapProfileCreateTest)1838 HWTEST_F_L0(DebuggerTypesTest, SamplingHeapProfileCreateTest)
1839 {
1840 std::string msg;
1841 std::unique_ptr<SamplingHeapProfile> object;
1842
1843 // abnormal params of null msg
1844 msg = std::string() + R"({})";
1845 object = SamplingHeapProfile::Create(DispatchRequest(msg).GetParams());
1846 EXPECT_EQ(object, nullptr);
1847
1848 // abnormal params of unexist key params
1849 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
1850 object = SamplingHeapProfile::Create(DispatchRequest(msg).GetParams());
1851 EXPECT_EQ(object, nullptr);
1852
1853 // abnormal params of null params.sub-key
1854 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
1855 object = SamplingHeapProfile::Create(DispatchRequest(msg).GetParams());
1856 EXPECT_EQ(object, nullptr);
1857
1858 // abnormal params of unknown params.sub-key
1859 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
1860 object = SamplingHeapProfile::Create(DispatchRequest(msg).GetParams());
1861 EXPECT_EQ(object, nullptr);
1862
1863 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1864 "head": {
1865 "callFrame": {"functionName":"Create", "scriptId":"10", "url":"url3", "lineNumber":100, "columnNumber":20},
1866 "selfSize":10,
1867 "id":5,
1868 "children":[]
1869 },
1870 "samples":[{"size":100, "nodeId":1, "ordinal":10}]
1871 }})";
1872 object = SamplingHeapProfile::Create(DispatchRequest(msg).GetParams());
1873 ASSERT_NE(object, nullptr);
1874 SamplingHeapProfileNode *head = object->GetHead();
1875 ASSERT_NE(head, nullptr);
1876
1877 RuntimeCallFrame *runTimeCallFrame = head->GetCallFrame();
1878 ASSERT_NE(runTimeCallFrame, nullptr);
1879 EXPECT_EQ(runTimeCallFrame->GetFunctionName(), "Create");
1880 EXPECT_EQ(runTimeCallFrame->GetScriptId(), "10");
1881 EXPECT_EQ(runTimeCallFrame->GetUrl(), "url3");
1882 EXPECT_EQ(runTimeCallFrame->GetLineNumber(), 100);
1883 EXPECT_EQ(runTimeCallFrame->GetColumnNumber(), 20);
1884
1885 EXPECT_EQ(head->GetSelfSize(), 10);
1886 EXPECT_EQ(head->GetId(), 5);
1887 const std::vector<std::unique_ptr<SamplingHeapProfileNode>> *children = head->GetChildren();
1888 ASSERT_NE(children, nullptr);
1889 EXPECT_EQ((int)children->size(), 0);
1890
1891 const std::vector<std::unique_ptr<SamplingHeapProfileSample>> *samples = object->GetSamples();
1892 ASSERT_NE(samples, nullptr);
1893 EXPECT_EQ((int)samples->size(), 1);
1894 EXPECT_EQ(samples->data()->get()->GetSize(), 100);
1895 EXPECT_EQ(samples->data()->get()->GetNodeId(), 1);
1896 EXPECT_EQ(samples->data()->get()->GetOrdinal(), 10);
1897 }
1898
HWTEST_F_L0(DebuggerTypesTest,SamplingHeapProfileToJsonTest)1899 HWTEST_F_L0(DebuggerTypesTest, SamplingHeapProfileToJsonTest)
1900 {
1901 std::string msg;
1902 std::unique_ptr<SamplingHeapProfile> samplingHeapProfile;
1903 std::string tmpStr;
1904 int32_t tmpInt;
1905 std::unique_ptr<PtJson> tmpJson;
1906 std::unique_ptr<PtJson> varTmpJson;
1907 std::unique_ptr<PtJson> exTmpJson;
1908 Result ret;
1909
1910 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1911 "head": {
1912 "callFrame": {"functionName":"Create", "scriptId":"10", "url":"url3", "lineNumber":100, "columnNumber":20},
1913 "selfSize":10,
1914 "id":5,
1915 "children":[]
1916 },
1917 "samples":[{"size":100, "nodeId":1, "ordinal":10}]
1918 }})";
1919
1920 samplingHeapProfile = SamplingHeapProfile::Create(DispatchRequest(msg).GetParams());
1921 ASSERT_NE(samplingHeapProfile, nullptr);
1922 auto json = samplingHeapProfile->ToJson();
1923
1924 ret = json->GetObject("head", &tmpJson);
1925 EXPECT_EQ(ret, Result::SUCCESS);
1926 ASSERT_NE(tmpJson, nullptr);
1927 ret = tmpJson->GetObject("callFrame", &varTmpJson);
1928 EXPECT_EQ(ret, Result::SUCCESS);
1929 ASSERT_NE(varTmpJson, nullptr);
1930 ret = varTmpJson->GetString("functionName", &tmpStr);
1931 EXPECT_EQ(ret, Result::SUCCESS);
1932 EXPECT_EQ(tmpStr, "Create");
1933 ret = varTmpJson->GetString("scriptId", &tmpStr);
1934 EXPECT_EQ(ret, Result::SUCCESS);
1935 EXPECT_EQ(tmpStr, "10");
1936 ret = varTmpJson->GetString("url", &tmpStr);
1937 EXPECT_EQ(ret, Result::SUCCESS);
1938 EXPECT_EQ(tmpStr, "url3");
1939
1940 ret = tmpJson->GetInt("selfSize", &tmpInt);
1941 EXPECT_EQ(ret, Result::SUCCESS);
1942 EXPECT_EQ(tmpInt, 10);
1943 ret = tmpJson->GetInt("id", &tmpInt);
1944 EXPECT_EQ(ret, Result::SUCCESS);
1945 EXPECT_EQ(tmpInt, 5);
1946 ret = tmpJson->GetArray("children", &exTmpJson);
1947 EXPECT_EQ(ret, Result::SUCCESS);
1948 ASSERT_NE(exTmpJson, nullptr);
1949 EXPECT_EQ(exTmpJson->GetSize(), 0);
1950
1951 ret = json->GetArray("samples", &tmpJson);
1952 EXPECT_EQ(ret, Result::SUCCESS);
1953 ASSERT_NE(tmpJson, nullptr);
1954 EXPECT_EQ(tmpJson->GetSize(), 1);
1955 }
1956
HWTEST_F_L0(DebuggerTypesTest,PositionTickInfoCreateTest)1957 HWTEST_F_L0(DebuggerTypesTest, PositionTickInfoCreateTest)
1958 {
1959 std::string msg;
1960 std::unique_ptr<PositionTickInfo> positionTickInfo;
1961
1962 // abnormal params of null msg
1963 msg = std::string() + R"({})";
1964 positionTickInfo = PositionTickInfo::Create(DispatchRequest(msg).GetParams());
1965 EXPECT_EQ(positionTickInfo, nullptr);
1966
1967 // abnormal params of unexist key params
1968 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
1969 positionTickInfo = PositionTickInfo::Create(DispatchRequest(msg).GetParams());
1970 EXPECT_EQ(positionTickInfo, nullptr);
1971
1972 // abnormal params of null params.sub-key
1973 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
1974 positionTickInfo = PositionTickInfo::Create(DispatchRequest(msg).GetParams());
1975 EXPECT_EQ(positionTickInfo, nullptr);
1976
1977 // abnormal params of unknown params.sub-key
1978 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
1979 positionTickInfo = PositionTickInfo::Create(DispatchRequest(msg).GetParams());
1980 EXPECT_EQ(positionTickInfo, nullptr);
1981
1982 // abnormal params of params.sub-key=["line":11,"ticks":99]
1983 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1984 "line":"11","ticks":99}})";
1985 positionTickInfo = PositionTickInfo::Create(DispatchRequest(msg).GetParams());
1986 EXPECT_EQ(positionTickInfo, nullptr);
1987
1988 // abnormal params of params.sub-key=["line":"11","ticks":"99"]
1989 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1990 "line":"11","ticks":"99"}})";
1991 positionTickInfo = PositionTickInfo::Create(DispatchRequest(msg).GetParams());
1992 EXPECT_EQ(positionTickInfo, nullptr);
1993
1994 // abnormal params of params.sub-key=["line":[11],"ticks":[99]]
1995 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1996 "line":[11],"ticks":[99]}})";
1997 positionTickInfo = PositionTickInfo::Create(DispatchRequest(msg).GetParams());
1998 EXPECT_EQ(positionTickInfo, nullptr);
1999
2000 // normal params of params.sub-key=["line":11,"ticks":99]
2001 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"line":1,"ticks":0}})";
2002 positionTickInfo = PositionTickInfo::Create(DispatchRequest(msg).GetParams());
2003 ASSERT_NE(positionTickInfo, nullptr);
2004 EXPECT_EQ(positionTickInfo->GetLine(), 1);
2005 EXPECT_EQ(positionTickInfo->GetTicks(), 0);
2006 }
2007
HWTEST_F_L0(DebuggerTypesTest,PositionTickInfoToJsonTest)2008 HWTEST_F_L0(DebuggerTypesTest, PositionTickInfoToJsonTest)
2009 {
2010 std::string msg;
2011 std::unique_ptr<PositionTickInfo> positionTickInfo;
2012 int32_t tmpInt;
2013 Result ret;
2014
2015 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"line":1,"ticks":0}})";
2016 positionTickInfo = PositionTickInfo::Create(DispatchRequest(msg).GetParams());
2017 ASSERT_NE(positionTickInfo, nullptr);
2018 auto json = positionTickInfo->ToJson();
2019
2020 ret = json->GetInt("line", &tmpInt);
2021 EXPECT_EQ(ret, Result::SUCCESS);
2022 EXPECT_EQ(tmpInt, 1);
2023
2024 ret = json->GetInt("ticks", &tmpInt);
2025 EXPECT_EQ(ret, Result::SUCCESS);
2026 EXPECT_EQ(tmpInt, 0);
2027 }
2028
HWTEST_F_L0(DebuggerTypesTest,ProfileNodeCreateTest)2029 HWTEST_F_L0(DebuggerTypesTest, ProfileNodeCreateTest)
2030 {
2031 std::string msg;
2032 std::unique_ptr<ProfileNode> profileNode;
2033
2034 // abnormal params of null msg
2035 msg = std::string() + R"({})";
2036 profileNode = ProfileNode::Create(DispatchRequest(msg).GetParams());
2037 EXPECT_EQ(profileNode, nullptr);
2038
2039 // abnormal params of unexist key params
2040 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
2041 profileNode = ProfileNode::Create(DispatchRequest(msg).GetParams());
2042 EXPECT_EQ(profileNode, nullptr);
2043
2044 // abnormal params of null params.sub-key
2045 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
2046 profileNode = ProfileNode::Create(DispatchRequest(msg).GetParams());
2047 EXPECT_EQ(profileNode, nullptr);
2048
2049 // abnormal params of unknown params.sub-key
2050 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
2051 profileNode = ProfileNode::Create(DispatchRequest(msg).GetParams());
2052 EXPECT_EQ(profileNode, nullptr);
2053
2054 // normal params of params.sub-key=[..]
2055 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2056 "id":10,
2057 "callFrame": {"functionName":"name0", "scriptId":"12", "url":"url15", "lineNumber":11, "columnNumber":20},
2058 "hitCount":15,"children":[],"positionTicks":[],"deoptReason":"yyy"}})";
2059 profileNode = ProfileNode::Create(DispatchRequest(msg).GetParams());
2060
2061 ASSERT_NE(profileNode, nullptr);
2062 EXPECT_EQ(profileNode->GetId(), 10);
2063 RuntimeCallFrame *runTimeCallFrame = profileNode->GetCallFrame();
2064 ASSERT_NE(runTimeCallFrame, nullptr);
2065 EXPECT_EQ(runTimeCallFrame->GetFunctionName(), "name0");
2066 EXPECT_EQ(runTimeCallFrame->GetScriptId(), "12");
2067 EXPECT_EQ(runTimeCallFrame->GetUrl(), "url15");
2068 EXPECT_EQ(runTimeCallFrame->GetLineNumber(), 11);
2069 EXPECT_EQ(runTimeCallFrame->GetColumnNumber(), 20);
2070
2071 EXPECT_EQ(profileNode->GetHitCount(), 15);
2072 EXPECT_EQ(profileNode->GetDeoptReason(), "yyy");
2073 }
2074
HWTEST_F_L0(DebuggerTypesTest,ProfileNodeToJsonTest)2075 HWTEST_F_L0(DebuggerTypesTest, ProfileNodeToJsonTest)
2076 {
2077 std::string msg;
2078 std::unique_ptr<ProfileNode> profilenode;
2079 std::string tmpStr;
2080 int32_t tmpInt;
2081 std::unique_ptr<PtJson> tmpJson;
2082 Result ret;
2083
2084 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2085 "id":10,
2086 "callFrame": {"functionName":"name0", "scriptId":"12", "url":"url15", "lineNumber":11, "columnNumber":20},
2087 "hitCount":15,"children":[],"positionTicks":[],"deoptReason":"yyy"}})";
2088 profilenode = ProfileNode::Create(DispatchRequest(msg).GetParams());
2089 ASSERT_NE(profilenode, nullptr);
2090 auto json = profilenode->ToJson();
2091
2092 ret = json->GetInt("id", &tmpInt);
2093 EXPECT_EQ(ret, Result::SUCCESS);
2094 EXPECT_EQ(tmpInt, 10);
2095
2096 ret = json->GetObject("callFrame", &tmpJson);
2097 EXPECT_EQ(ret, Result::SUCCESS);
2098 ASSERT_NE(tmpJson, nullptr);
2099 ret = tmpJson->GetString("functionName", &tmpStr);
2100 EXPECT_EQ(ret, Result::SUCCESS);
2101 EXPECT_EQ(tmpStr, "name0");
2102 ret = tmpJson->GetString("scriptId", &tmpStr);
2103 EXPECT_EQ(ret, Result::SUCCESS);
2104 EXPECT_EQ(tmpStr, "12");
2105 ret = tmpJson->GetString("url", &tmpStr);
2106 EXPECT_EQ(ret, Result::SUCCESS);
2107 EXPECT_EQ(tmpStr, "url15");
2108 ret = tmpJson->GetInt("lineNumber", &tmpInt);
2109 EXPECT_EQ(ret, Result::SUCCESS);
2110 EXPECT_EQ(tmpInt, 11);
2111 ret = tmpJson->GetInt("columnNumber", &tmpInt);
2112 EXPECT_EQ(ret, Result::SUCCESS);
2113 EXPECT_EQ(tmpInt, 20);
2114
2115 ret = json->GetInt("hitCount", &tmpInt);
2116 EXPECT_EQ(ret, Result::SUCCESS);
2117 EXPECT_EQ(tmpInt, 15);
2118
2119 ret = json->GetString("deoptReason", &tmpStr);
2120 EXPECT_EQ(ret, Result::SUCCESS);
2121 EXPECT_EQ(tmpStr, "yyy");
2122 }
2123
HWTEST_F_L0(DebuggerTypesTest,ProfileCreateTest)2124 HWTEST_F_L0(DebuggerTypesTest, ProfileCreateTest)
2125 {
2126 std::string msg;
2127 std::unique_ptr<Profile> profile;
2128
2129 // abnormal params of null msg
2130 msg = std::string() + R"({})";
2131 profile = Profile::Create(DispatchRequest(msg).GetParams());
2132 EXPECT_EQ(profile, nullptr);
2133
2134 // abnormal params of unexist key params
2135 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
2136 profile = Profile::Create(DispatchRequest(msg).GetParams());
2137 EXPECT_EQ(profile, nullptr);
2138
2139 // abnormal params of null params.sub-key
2140 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
2141 profile = Profile::Create(DispatchRequest(msg).GetParams());
2142 EXPECT_EQ(profile, nullptr);
2143
2144 // abnormal params of unknown params.sub-key
2145 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
2146 profile = Profile::Create(DispatchRequest(msg).GetParams());
2147 EXPECT_EQ(profile, nullptr);
2148
2149 // abnormal params of params.sub-key=[..]
2150 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2151 "tid":1000, "startTime":10, "endTime":25, "gcTime":25, "cInterpreterTime":25, "asmInterpreterTime":25,
2152 "aotTime":25, "builtinTime":25, "napiTime":25, "arkuiEngineTime":25, "runtimeTime":25, "otherTime":25,
2153 "nodes":[{"id":12, "callFrame": {"functionName":"Create", "scriptId":"10", "url":"url3", "lineNumber":100,
2154 "columnNumber":20}}], "samples":[],"timeDeltas":[]}})";
2155 profile = Profile::Create(DispatchRequest(msg).GetParams());
2156 ASSERT_NE(profile, nullptr);
2157
2158 EXPECT_EQ(profile->GetTid(), 1000LL);
2159 EXPECT_EQ(profile->GetStartTime(), 10LL);
2160 EXPECT_EQ(profile->GetEndTime(), 25LL);
2161 EXPECT_EQ(profile->GetGcTime(), 25LL);
2162 EXPECT_EQ(profile->GetCInterpreterTime(), 25LL);
2163 EXPECT_EQ(profile->GetAsmInterpreterTime(), 25LL);
2164 EXPECT_EQ(profile->GetAotTime(), 25LL);
2165 EXPECT_EQ(profile->GetBuiltinTime(), 25LL);
2166 EXPECT_EQ(profile->GetNapiTime(), 25LL);
2167 EXPECT_EQ(profile->GetArkuiEngineTime(), 25LL);
2168 EXPECT_EQ(profile->GetRuntimeTime(), 25LL);
2169 EXPECT_EQ(profile->GetOtherTime(), 25LL);
2170 const std::vector<std::unique_ptr<ProfileNode>> *profileNode = profile->GetNodes();
2171 ASSERT_NE(profileNode, nullptr);
2172 EXPECT_EQ((int)profileNode->size(), 1);
2173 }
2174
HWTEST_F_L0(DebuggerTypesTest,ProfileToJsonTest)2175 HWTEST_F_L0(DebuggerTypesTest, ProfileToJsonTest)
2176 {
2177 std::string msg;
2178 std::unique_ptr<Profile> profile;
2179 std::string tmpStr;
2180 int32_t tmpInt;
2181 std::unique_ptr<PtJson> tmpJson;
2182 Result ret;
2183
2184 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2185 "tid":1000, "startTime":10, "endTime":25, "gcTime":25, "cInterpreterTime":25, "asmInterpreterTime":25,
2186 "aotTime":25, "builtinTime":25, "napiTime":25, "arkuiEngineTime":25, "runtimeTime":25, "otherTime":25,
2187 "nodes":[{"id":12, "callFrame": {"functionName":"Create", "scriptId":"10", "url":"url3", "lineNumber":100,
2188 "columnNumber":20}}], "samples":[],"timeDeltas":[]}})";
2189 profile = Profile::Create(DispatchRequest(msg).GetParams());
2190 ASSERT_NE(profile, nullptr);
2191 auto json = profile->ToJson();
2192
2193 ret = json->GetInt("tid", &tmpInt);
2194 EXPECT_EQ(ret, Result::SUCCESS);
2195 EXPECT_EQ(tmpInt, 1000);
2196
2197 ret = json->GetInt("startTime", &tmpInt);
2198 EXPECT_EQ(ret, Result::SUCCESS);
2199 EXPECT_EQ(tmpInt, 10);
2200
2201 ret = json->GetInt("endTime", &tmpInt);
2202 EXPECT_EQ(ret, Result::SUCCESS);
2203 EXPECT_EQ(tmpInt, 25);
2204
2205 ret = json->GetInt("gcTime", &tmpInt);
2206 EXPECT_EQ(ret, Result::SUCCESS);
2207 EXPECT_EQ(tmpInt, 25);
2208
2209 ret = json->GetInt("cInterpreterTime", &tmpInt);
2210 EXPECT_EQ(ret, Result::SUCCESS);
2211 EXPECT_EQ(tmpInt, 25);
2212
2213 ret = json->GetInt("asmInterpreterTime", &tmpInt);
2214 EXPECT_EQ(ret, Result::SUCCESS);
2215 EXPECT_EQ(tmpInt, 25);
2216
2217 ret = json->GetInt("aotTime", &tmpInt);
2218 EXPECT_EQ(ret, Result::SUCCESS);
2219 EXPECT_EQ(tmpInt, 25);
2220
2221 ret = json->GetInt("builtinTime", &tmpInt);
2222 EXPECT_EQ(ret, Result::SUCCESS);
2223 EXPECT_EQ(tmpInt, 25);
2224
2225 ret = json->GetInt("napiTime", &tmpInt);
2226 EXPECT_EQ(ret, Result::SUCCESS);
2227 EXPECT_EQ(tmpInt, 25);
2228
2229 ret = json->GetInt("arkuiEngineTime", &tmpInt);
2230 EXPECT_EQ(ret, Result::SUCCESS);
2231 EXPECT_EQ(tmpInt, 25);
2232
2233 ret = json->GetInt("runtimeTime", &tmpInt);
2234 EXPECT_EQ(ret, Result::SUCCESS);
2235 EXPECT_EQ(tmpInt, 25);
2236
2237 ret = json->GetInt("otherTime", &tmpInt);
2238 EXPECT_EQ(ret, Result::SUCCESS);
2239 EXPECT_EQ(tmpInt, 25);
2240 }
2241
HWTEST_F_L0(DebuggerTypesTest,CoverageCreateTest)2242 HWTEST_F_L0(DebuggerTypesTest, CoverageCreateTest)
2243 {
2244 std::string msg;
2245 std::unique_ptr<Coverage> coverage;
2246
2247 // abnormal params of null msg
2248 msg = std::string() + R"({})";
2249 coverage = Coverage::Create(DispatchRequest(msg).GetParams());
2250 EXPECT_EQ(coverage, nullptr);
2251
2252 // abnormal params of unexist key params
2253 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
2254 coverage = Coverage::Create(DispatchRequest(msg).GetParams());
2255 EXPECT_EQ(coverage, nullptr);
2256
2257 // abnormal params of null params.sub-key
2258 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
2259 coverage = Coverage::Create(DispatchRequest(msg).GetParams());
2260 EXPECT_EQ(coverage, nullptr);
2261
2262 // abnormal params of unknown params.sub-key
2263 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
2264 coverage = Coverage::Create(DispatchRequest(msg).GetParams());
2265 EXPECT_EQ(coverage, nullptr);
2266
2267 // normal params of params.sub-key=["startOffset":0,"endOffset":5,"count":13]
2268 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2269 "startOffset":0,"endOffset":13,"count":13}})";
2270 coverage = Coverage::Create(DispatchRequest(msg).GetParams());
2271 ASSERT_NE(coverage, nullptr);
2272 EXPECT_EQ(coverage->GetStartOffset(), 0);
2273 EXPECT_EQ(coverage->GetEndOffset(), 13);
2274 EXPECT_EQ(coverage->GetCount(), 13);
2275 }
2276
HWTEST_F_L0(DebuggerTypesTest,CoverageToJsonTest)2277 HWTEST_F_L0(DebuggerTypesTest, CoverageToJsonTest)
2278 {
2279 std::string msg;
2280 std::unique_ptr<Coverage> coverage;
2281 std::string tmpStr;
2282 int32_t tmpInt;
2283 Result ret;
2284
2285 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2286 "startOffset":0,"endOffset":13,"count":13}})";
2287 coverage = Coverage::Create(DispatchRequest(msg).GetParams());
2288 ASSERT_NE(coverage, nullptr);
2289 auto json = coverage->ToJson();
2290
2291 ret = json->GetInt("startOffset", &tmpInt);
2292 EXPECT_EQ(ret, Result::SUCCESS);
2293 EXPECT_EQ(tmpInt, 0);
2294
2295 ret = json->GetInt("endOffset", &tmpInt);
2296 EXPECT_EQ(ret, Result::SUCCESS);
2297 EXPECT_EQ(tmpInt, 13);
2298
2299 ret = json->GetInt("count", &tmpInt);
2300 EXPECT_EQ(ret, Result::SUCCESS);
2301 EXPECT_EQ(tmpInt, 13);
2302 }
2303
HWTEST_F_L0(DebuggerTypesTest,FunctionCoverageCreateTest)2304 HWTEST_F_L0(DebuggerTypesTest, FunctionCoverageCreateTest)
2305 {
2306 std::string msg;
2307 std::unique_ptr<FunctionCoverage> functionCoverage;
2308
2309 // abnormal params of null msg
2310 msg = std::string() + R"({})";
2311 functionCoverage = FunctionCoverage::Create(DispatchRequest(msg).GetParams());
2312 EXPECT_EQ(functionCoverage, nullptr);
2313
2314 // abnormal params of unexist key params
2315 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
2316 functionCoverage = FunctionCoverage::Create(DispatchRequest(msg).GetParams());
2317 EXPECT_EQ(functionCoverage, nullptr);
2318
2319 // abnormal params of null params.sub-key
2320 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
2321 functionCoverage = FunctionCoverage::Create(DispatchRequest(msg).GetParams());
2322 EXPECT_EQ(functionCoverage, nullptr);
2323
2324 // abnormal params of unknown params.sub-key
2325 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
2326 functionCoverage = FunctionCoverage::Create(DispatchRequest(msg).GetParams());
2327 EXPECT_EQ(functionCoverage, nullptr);
2328
2329 // normal params of params.sub-key=[..]
2330 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2331 "functionName":"Create0","ranges":[{"startOffset":0,"endOffset":13,"count":13}],"isBlockCoverage":true}})";
2332 functionCoverage = FunctionCoverage::Create(DispatchRequest(msg).GetParams());
2333
2334 ASSERT_NE(functionCoverage, nullptr);
2335 EXPECT_EQ(functionCoverage->GetFunctionName(), "Create0");
2336 const std::vector<std::unique_ptr<Coverage>> *ranges = functionCoverage->GetRanges();
2337 ASSERT_NE(ranges, nullptr);
2338 EXPECT_EQ((int)ranges->size(), 1);
2339 ASSERT_TRUE(functionCoverage->GetIsBlockCoverage());
2340 }
2341
HWTEST_F_L0(DebuggerTypesTest,FunctionCoverageToJsonTest)2342 HWTEST_F_L0(DebuggerTypesTest, FunctionCoverageToJsonTest)
2343 {
2344 std::string msg;
2345 std::unique_ptr<FunctionCoverage> functionCoverage;
2346 std::string tmpStr;
2347 bool tmpBool;
2348 std::unique_ptr<PtJson> tmpJson;
2349 Result ret;
2350
2351 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2352 "functionName":"Create0","ranges":[{"startOffset":0,"endOffset":13,"count":13}],"isBlockCoverage":true}})";
2353 functionCoverage = FunctionCoverage::Create(DispatchRequest(msg).GetParams());
2354 ASSERT_NE(functionCoverage, nullptr);
2355 auto json = functionCoverage->ToJson();
2356
2357 ret = json->GetString("functionName", &tmpStr);
2358 EXPECT_EQ(ret, Result::SUCCESS);
2359 EXPECT_EQ(tmpStr, "Create0");
2360
2361 ret = json->GetArray("ranges", &tmpJson);
2362 EXPECT_EQ(ret, Result::SUCCESS);
2363 ASSERT_NE(tmpJson, nullptr);
2364 EXPECT_EQ(tmpJson->GetSize(), 1);
2365
2366 ret = json->GetBool("isBlockCoverage", &tmpBool);
2367 EXPECT_EQ(ret, Result::SUCCESS);
2368 ASSERT_TRUE(tmpBool);
2369 }
2370
HWTEST_F_L0(DebuggerTypesTest,ScriptCoverageCreateTest)2371 HWTEST_F_L0(DebuggerTypesTest, ScriptCoverageCreateTest)
2372 {
2373 std::string msg;
2374 std::unique_ptr<ScriptCoverage> scriptCoverage;
2375
2376 // abnormal params of null msg
2377 msg = std::string() + R"({})";
2378 scriptCoverage = ScriptCoverage::Create(DispatchRequest(msg).GetParams());
2379 EXPECT_EQ(scriptCoverage, nullptr);
2380
2381 // abnormal params of unexist key params
2382 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
2383 scriptCoverage = ScriptCoverage::Create(DispatchRequest(msg).GetParams());
2384 EXPECT_EQ(scriptCoverage, nullptr);
2385
2386 // abnormal params of null params.sub-key
2387 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
2388 scriptCoverage = ScriptCoverage::Create(DispatchRequest(msg).GetParams());
2389 EXPECT_EQ(scriptCoverage, nullptr);
2390
2391 // abnormal params of unknown params.sub-key
2392 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
2393 scriptCoverage = ScriptCoverage::Create(DispatchRequest(msg).GetParams());
2394 EXPECT_EQ(scriptCoverage, nullptr);
2395
2396 // normal params of params.sub-key=[..]
2397 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2398 "scriptId":"1001",
2399 "url":"url17",
2400 "functions":[{"functionName":"Create0",
2401 "ranges":[{"startOffset":0, "endOffset":13, "count":13}],
2402 "isBlockCoverage":true}]}})";
2403 scriptCoverage = ScriptCoverage::Create(DispatchRequest(msg).GetParams());
2404 ASSERT_NE(scriptCoverage, nullptr);
2405 EXPECT_EQ(scriptCoverage->GetScriptId(), "1001");
2406 EXPECT_EQ(scriptCoverage->GetUrl(), "url17");
2407 const std::vector<std::unique_ptr<FunctionCoverage>> *functions = scriptCoverage->GetFunctions();
2408 ASSERT_NE(functions, nullptr);
2409 EXPECT_EQ((int)functions->size(), 1);
2410 }
2411
HWTEST_F_L0(DebuggerTypesTest,ScriptCoverageToJsonTest)2412 HWTEST_F_L0(DebuggerTypesTest, ScriptCoverageToJsonTest)
2413 {
2414 std::string msg;
2415 std::unique_ptr<ScriptCoverage> scriptCoverage;
2416 std::string tmpStr;
2417 std::unique_ptr<PtJson> tmpJson;
2418 Result ret;
2419
2420 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2421 "scriptId":"1001",
2422 "url":"url17",
2423 "functions": [{"functionName":"Create0",
2424 "ranges": [{"startOffset":0, "endOffset":13, "count":13}],
2425 "isBlockCoverage":true}]}})";
2426 scriptCoverage = ScriptCoverage::Create(DispatchRequest(msg).GetParams());
2427 ASSERT_NE(scriptCoverage, nullptr);
2428 auto json = scriptCoverage->ToJson();
2429
2430 ret = json->GetString("scriptId", &tmpStr);
2431 EXPECT_EQ(ret, Result::SUCCESS);
2432 EXPECT_EQ(tmpStr, "1001");
2433
2434 ret = json->GetString("url", &tmpStr);
2435 EXPECT_EQ(ret, Result::SUCCESS);
2436 EXPECT_EQ(tmpStr, "url17");
2437
2438 ret = json->GetArray("functions", &tmpJson);
2439 EXPECT_EQ(ret, Result::SUCCESS);
2440 ASSERT_NE(tmpJson, nullptr);
2441 EXPECT_EQ(tmpJson->GetSize(), 1);
2442 }
2443
HWTEST_F_L0(DebuggerTypesTest,TypeObjectCreateTest)2444 HWTEST_F_L0(DebuggerTypesTest, TypeObjectCreateTest)
2445 {
2446 std::string msg;
2447 std::unique_ptr<TypeObject> typeObject;
2448
2449 // abnormal params of null msg
2450 msg = std::string() + R"({})";
2451 typeObject = TypeObject::Create(DispatchRequest(msg).GetParams());
2452 EXPECT_EQ(typeObject, nullptr);
2453
2454 // abnormal params of unexist key params
2455 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
2456 typeObject = TypeObject::Create(DispatchRequest(msg).GetParams());
2457 EXPECT_EQ(typeObject, nullptr);
2458
2459 // abnormal params of null params.sub-key
2460 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
2461 typeObject = TypeObject::Create(DispatchRequest(msg).GetParams());
2462 EXPECT_EQ(typeObject, nullptr);
2463
2464 // abnormal params of unknown params.sub-key
2465 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
2466 typeObject = TypeObject::Create(DispatchRequest(msg).GetParams());
2467 EXPECT_EQ(typeObject, nullptr);
2468
2469 // normal params of params.sub-key=[..]
2470 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2471 "name":"Create1"}})";
2472 typeObject = TypeObject::Create(DispatchRequest(msg).GetParams());
2473 ASSERT_NE(typeObject, nullptr);
2474 EXPECT_EQ(typeObject->GetName(), "Create1");
2475 }
2476
HWTEST_F_L0(DebuggerTypesTest,TypeObjectToJsonTest)2477 HWTEST_F_L0(DebuggerTypesTest, TypeObjectToJsonTest)
2478 {
2479 std::string msg;
2480 std::unique_ptr<TypeObject> typeObject;
2481 std::string tmpStr;
2482 Result ret;
2483
2484 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2485 "name":"Create1"}})";
2486 typeObject = TypeObject::Create(DispatchRequest(msg).GetParams());
2487 ASSERT_NE(typeObject, nullptr);
2488 auto json = typeObject->ToJson();
2489
2490 ret = json->GetString("name", &tmpStr);
2491 EXPECT_EQ(ret, Result::SUCCESS);
2492 EXPECT_EQ(tmpStr, "Create1");
2493 }
2494
HWTEST_F_L0(DebuggerTypesTest,TypeProfileEntryCreateTest)2495 HWTEST_F_L0(DebuggerTypesTest, TypeProfileEntryCreateTest)
2496 {
2497 std::string msg;
2498 std::unique_ptr<TypeProfileEntry> typeProfileEntry;
2499
2500 // abnormal params of null msg
2501 msg = std::string() + R"({})";
2502 typeProfileEntry = TypeProfileEntry::Create(DispatchRequest(msg).GetParams());
2503 EXPECT_EQ(typeProfileEntry, nullptr);
2504
2505 // abnormal params of unexist key params
2506 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
2507 typeProfileEntry = TypeProfileEntry::Create(DispatchRequest(msg).GetParams());
2508 EXPECT_EQ(typeProfileEntry, nullptr);
2509
2510 // abnormal params of null params.sub-key
2511 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
2512 typeProfileEntry = TypeProfileEntry::Create(DispatchRequest(msg).GetParams());
2513 EXPECT_EQ(typeProfileEntry, nullptr);
2514
2515 // abnormal params of unknown params.sub-key
2516 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
2517 typeProfileEntry = TypeProfileEntry::Create(DispatchRequest(msg).GetParams());
2518 EXPECT_EQ(typeProfileEntry, nullptr);
2519
2520 // normal params of params.sub-key=[..]
2521 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2522 "offset":11,"types":[{"name":"Create1"}]}})";
2523 typeProfileEntry = TypeProfileEntry::Create(DispatchRequest(msg).GetParams());
2524 ASSERT_NE(typeProfileEntry, nullptr);
2525 EXPECT_EQ(typeProfileEntry->GetOffset(), 11);
2526 const std::vector<std::unique_ptr<TypeObject>> *typeObject = typeProfileEntry->GetTypes();
2527 ASSERT_NE(typeObject, nullptr);
2528 EXPECT_EQ((int)typeObject->size(), 1);
2529 }
2530
HWTEST_F_L0(DebuggerTypesTest,TypeProfileEntryToJsonTest)2531 HWTEST_F_L0(DebuggerTypesTest, TypeProfileEntryToJsonTest)
2532 {
2533 std::string msg;
2534 std::unique_ptr<TypeProfileEntry> typeProfileEntry;
2535 int32_t tmpInt;
2536 std::unique_ptr<PtJson> tmpJson;
2537 Result ret;
2538
2539 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2540 "offset":11,"types":[{"name":"Create1"}]}})";
2541 typeProfileEntry = TypeProfileEntry::Create(DispatchRequest(msg).GetParams());
2542 ASSERT_NE(typeProfileEntry, nullptr);
2543 auto json = typeProfileEntry->ToJson();
2544
2545 ret = json->GetInt("offset", &tmpInt);
2546 EXPECT_EQ(ret, Result::SUCCESS);
2547 EXPECT_EQ(tmpInt, 11);
2548
2549 ret = json->GetArray("types", &tmpJson);
2550 EXPECT_EQ(ret, Result::SUCCESS);
2551 ASSERT_NE(tmpJson, nullptr);
2552 EXPECT_EQ(tmpJson->GetSize(), 1);
2553 }
2554
HWTEST_F_L0(DebuggerTypesTest,ScriptTypeProfileCreateTest)2555 HWTEST_F_L0(DebuggerTypesTest, ScriptTypeProfileCreateTest)
2556 {
2557 std::string msg;
2558 std::unique_ptr<ScriptTypeProfile> scriptTypeProfile;
2559
2560 // abnormal params of null msg
2561 msg = std::string() + R"({})";
2562 scriptTypeProfile = ScriptTypeProfile::Create(DispatchRequest(msg).GetParams());
2563 EXPECT_EQ(scriptTypeProfile, nullptr);
2564
2565 // abnormal params of unexist key params
2566 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
2567 scriptTypeProfile = ScriptTypeProfile::Create(DispatchRequest(msg).GetParams());
2568 EXPECT_EQ(scriptTypeProfile, nullptr);
2569
2570 // abnormal params of null params.sub-key
2571 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
2572 scriptTypeProfile = ScriptTypeProfile::Create(DispatchRequest(msg).GetParams());
2573 EXPECT_EQ(scriptTypeProfile, nullptr);
2574
2575 // abnormal params of unknown params.sub-key
2576 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
2577 scriptTypeProfile = ScriptTypeProfile::Create(DispatchRequest(msg).GetParams());
2578 EXPECT_EQ(scriptTypeProfile, nullptr);
2579
2580 // normal params of params.sub-key=[..]
2581 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2582 "scriptId":"122","url":"url15","entries":[{"offset":11,"types":[{"name":"Create1"}]}]}})";
2583 scriptTypeProfile = ScriptTypeProfile::Create(DispatchRequest(msg).GetParams());
2584 ASSERT_NE(scriptTypeProfile, nullptr);
2585 EXPECT_EQ(scriptTypeProfile->GetScriptId(), "122");
2586 EXPECT_EQ(scriptTypeProfile->GetUrl(), "url15");
2587 const std::vector<std::unique_ptr<TypeProfileEntry>> *typeProfileEntry = scriptTypeProfile->GetEntries();
2588 ASSERT_NE(typeProfileEntry, nullptr);
2589 EXPECT_EQ((int)typeProfileEntry->size(), 1);
2590 }
2591
HWTEST_F_L0(DebuggerTypesTest,ScriptTypeProfileToJsonTest)2592 HWTEST_F_L0(DebuggerTypesTest, ScriptTypeProfileToJsonTest)
2593 {
2594 std::string msg;
2595 std::unique_ptr<ScriptTypeProfile> scriptTypeProfile;
2596 std::string tmpStr;
2597 std::unique_ptr<PtJson> tmpJson;
2598 Result ret;
2599
2600 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2601 "scriptId":"122","url":"url15","entries":[{"offset":11,"types":[{"name":"Create1"}]}]}})";
2602 scriptTypeProfile = ScriptTypeProfile::Create(DispatchRequest(msg).GetParams());
2603 ASSERT_NE(scriptTypeProfile, nullptr);
2604 auto json = scriptTypeProfile->ToJson();
2605
2606 ret = json->GetString("scriptId", &tmpStr);
2607 EXPECT_EQ(ret, Result::SUCCESS);
2608 EXPECT_EQ(tmpStr, "122");
2609
2610 ret = json->GetString("url", &tmpStr);
2611 EXPECT_EQ(ret, Result::SUCCESS);
2612 EXPECT_EQ(tmpStr, "url15");
2613
2614 ret = json->GetArray("entries", &tmpJson);
2615 EXPECT_EQ(ret, Result::SUCCESS);
2616 ASSERT_NE(tmpJson, nullptr);
2617 EXPECT_EQ(tmpJson->GetSize(), 1);
2618 }
2619
HWTEST_F_L0(DebuggerTypesTest,TraceConfigCreateTest)2620 HWTEST_F_L0(DebuggerTypesTest, TraceConfigCreateTest)
2621 {
2622 std::string msg;
2623 std::unique_ptr<TraceConfig> traceConfig;
2624
2625 // abnormal params of null msg
2626 msg = std::string() + R"({})";
2627 traceConfig = TraceConfig::Create(DispatchRequest(msg).GetParams());
2628 ASSERT_NE(traceConfig, nullptr);
2629
2630 // abnormal params of unexist key params
2631 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
2632 traceConfig = TraceConfig::Create(DispatchRequest(msg).GetParams());
2633 ASSERT_NE(traceConfig, nullptr);
2634
2635 // abnormal params of null params.sub-key
2636 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
2637 traceConfig = TraceConfig::Create(DispatchRequest(msg).GetParams());
2638 ASSERT_NE(traceConfig, nullptr);
2639
2640 // abnormal params of unknown params.sub-key
2641 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
2642 traceConfig = TraceConfig::Create(DispatchRequest(msg).GetParams());
2643 ASSERT_NE(traceConfig, nullptr);
2644
2645 // normal params of params.sub-key=[..]
2646 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2647 "recordMode":"recordUntilFull", "enableSampling":true, "enableSystrace":true,
2648 "enableArgumentFilter":true}})";
2649 traceConfig = TraceConfig::Create(DispatchRequest(msg).GetParams());
2650 ASSERT_NE(traceConfig, nullptr);
2651
2652 EXPECT_EQ(traceConfig->GetRecordMode(), "recordUntilFull");
2653 ASSERT_TRUE(traceConfig->GetEnableSampling());
2654 ASSERT_TRUE(traceConfig->GetEnableSystrace());
2655 ASSERT_TRUE(traceConfig->GetEnableArgumentFilter());
2656 }
2657
HWTEST_F_L0(DebuggerTypesTest,TraceConfigToJsonTest)2658 HWTEST_F_L0(DebuggerTypesTest, TraceConfigToJsonTest)
2659 {
2660 std::string msg;
2661 std::unique_ptr<TraceConfig> traceConfig;
2662 std::string tmpStr;
2663 std::unique_ptr<PtJson> tmpJson;
2664 bool tmpBool;
2665 Result ret;
2666
2667 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2668 "recordMode":"recordUntilFull", "enableSampling":true, "enableSystrace":true,
2669 "enableArgumentFilter":true}})";
2670 traceConfig = TraceConfig::Create(DispatchRequest(msg).GetParams());
2671 ASSERT_NE(traceConfig, nullptr);
2672 auto json = traceConfig->ToJson();
2673
2674 ret = json->GetString("recordMode", &tmpStr);
2675 EXPECT_EQ(ret, Result::SUCCESS);
2676 EXPECT_EQ(tmpStr, "recordUntilFull");
2677
2678 ret = json->GetBool("enableSampling", &tmpBool);
2679 EXPECT_EQ(ret, Result::SUCCESS);
2680 ASSERT_TRUE(tmpBool);
2681
2682 ret = json->GetBool("enableSystrace", &tmpBool);
2683 EXPECT_EQ(ret, Result::SUCCESS);
2684 ASSERT_TRUE(tmpBool);
2685
2686 ret = json->GetBool("enableArgumentFilter", &tmpBool);
2687 EXPECT_EQ(ret, Result::SUCCESS);
2688 ASSERT_TRUE(tmpBool);
2689 }
2690 } // namespace panda::test
2691