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 "tooling/dynamic/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", "moduleName":"entry", "scriptId":"10", "url":"url3", "lineNumber":100,
1773 "columnNumber":20},
1774 "selfSize":10,
1775 "id":5,
1776 "children":[]
1777 }})";
1778 object = SamplingHeapProfileNode::Create(DispatchRequest(msg).GetParams());
1779 ASSERT_NE(object, nullptr);
1780 RuntimeCallFrame *runTimeCallFrame = object->GetCallFrame();
1781 ASSERT_NE(runTimeCallFrame, nullptr);
1782 EXPECT_EQ(runTimeCallFrame->GetFunctionName(), "Create");
1783 EXPECT_EQ(runTimeCallFrame->GetModuleName(), "entry");
1784 EXPECT_EQ(runTimeCallFrame->GetScriptId(), "10");
1785 EXPECT_EQ(runTimeCallFrame->GetUrl(), "url3");
1786 EXPECT_EQ(runTimeCallFrame->GetLineNumber(), 100);
1787 EXPECT_EQ(runTimeCallFrame->GetColumnNumber(), 20);
1788
1789 EXPECT_EQ(object->GetSelfSize(), 10);
1790 EXPECT_EQ(object->GetId(), 5);
1791 const std::vector<std::unique_ptr<SamplingHeapProfileNode>> *children = object->GetChildren();
1792 ASSERT_NE(children, nullptr);
1793 EXPECT_EQ((int)children->size(), 0);
1794 }
1795
HWTEST_F_L0(DebuggerTypesTest,SamplingHeapProfileNodeToJsonTest)1796 HWTEST_F_L0(DebuggerTypesTest, SamplingHeapProfileNodeToJsonTest)
1797 {
1798 std::string msg;
1799 std::unique_ptr<SamplingHeapProfileNode> samplingHeapProfileNode;
1800 std::string tmpStr;
1801 std::unique_ptr<PtJson> tmpJson;
1802 int32_t tmpInt;
1803 Result ret;
1804
1805 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1806 "callFrame": {"functionName":"Create", "moduleName":"entry", "scriptId":"10", "url":"url3", "lineNumber":100,
1807 "columnNumber":20},
1808 "selfSize":10,
1809 "id":5,
1810 "children":[]
1811 }})";
1812 samplingHeapProfileNode = SamplingHeapProfileNode::Create(DispatchRequest(msg).GetParams());
1813 ASSERT_NE(samplingHeapProfileNode, nullptr);
1814 auto json = samplingHeapProfileNode->ToJson();
1815
1816 ret = json->GetObject("callFrame", &tmpJson);
1817 EXPECT_EQ(ret, Result::SUCCESS);
1818 ASSERT_NE(tmpJson, nullptr);
1819 ret = tmpJson->GetString("functionName", &tmpStr);
1820 EXPECT_EQ(ret, Result::SUCCESS);
1821 EXPECT_EQ(tmpStr, "Create");
1822 ret = tmpJson->GetString("moduleName", &tmpStr);
1823 EXPECT_EQ(ret, Result::SUCCESS);
1824 EXPECT_EQ(tmpStr, "entry");
1825 ret = tmpJson->GetString("scriptId", &tmpStr);
1826 EXPECT_EQ(ret, Result::SUCCESS);
1827 EXPECT_EQ(tmpStr, "10");
1828 ret = tmpJson->GetString("url", &tmpStr);
1829 EXPECT_EQ(ret, Result::SUCCESS);
1830 EXPECT_EQ(tmpStr, "url3");
1831
1832 ret = json->GetInt("selfSize", &tmpInt);
1833 EXPECT_EQ(ret, Result::SUCCESS);
1834 EXPECT_EQ(tmpInt, 10);
1835 ret = json->GetInt("id", &tmpInt);
1836 EXPECT_EQ(ret, Result::SUCCESS);
1837 EXPECT_EQ(tmpInt, 5);
1838 ret = json->GetArray("children", &tmpJson);
1839 EXPECT_EQ(ret, Result::SUCCESS);
1840 ASSERT_NE(tmpJson, nullptr);
1841 EXPECT_EQ(tmpJson->GetSize(), 0);
1842 }
1843
HWTEST_F_L0(DebuggerTypesTest,SamplingHeapProfileCreateTest)1844 HWTEST_F_L0(DebuggerTypesTest, SamplingHeapProfileCreateTest)
1845 {
1846 std::string msg;
1847 std::unique_ptr<SamplingHeapProfile> object;
1848
1849 // abnormal params of null msg
1850 msg = std::string() + R"({})";
1851 object = SamplingHeapProfile::Create(DispatchRequest(msg).GetParams());
1852 EXPECT_EQ(object, nullptr);
1853
1854 // abnormal params of unexist key params
1855 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
1856 object = SamplingHeapProfile::Create(DispatchRequest(msg).GetParams());
1857 EXPECT_EQ(object, nullptr);
1858
1859 // abnormal params of null params.sub-key
1860 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
1861 object = SamplingHeapProfile::Create(DispatchRequest(msg).GetParams());
1862 EXPECT_EQ(object, nullptr);
1863
1864 // abnormal params of unknown params.sub-key
1865 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
1866 object = SamplingHeapProfile::Create(DispatchRequest(msg).GetParams());
1867 EXPECT_EQ(object, nullptr);
1868
1869 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1870 "head": {
1871 "callFrame": {"functionName":"Create", "moduleName":"entry", "scriptId":"10", "url":"url3",
1872 "lineNumber":100, "columnNumber":20},
1873 "selfSize":10,
1874 "id":5,
1875 "children":[]
1876 },
1877 "samples":[{"size":100, "nodeId":1, "ordinal":10}]
1878 }})";
1879 object = SamplingHeapProfile::Create(DispatchRequest(msg).GetParams());
1880 ASSERT_NE(object, nullptr);
1881 SamplingHeapProfileNode *head = object->GetHead();
1882 ASSERT_NE(head, nullptr);
1883
1884 RuntimeCallFrame *runTimeCallFrame = head->GetCallFrame();
1885 ASSERT_NE(runTimeCallFrame, nullptr);
1886 EXPECT_EQ(runTimeCallFrame->GetFunctionName(), "Create");
1887 EXPECT_EQ(runTimeCallFrame->GetModuleName(), "entry");
1888 EXPECT_EQ(runTimeCallFrame->GetScriptId(), "10");
1889 EXPECT_EQ(runTimeCallFrame->GetUrl(), "url3");
1890 EXPECT_EQ(runTimeCallFrame->GetLineNumber(), 100);
1891 EXPECT_EQ(runTimeCallFrame->GetColumnNumber(), 20);
1892
1893 EXPECT_EQ(head->GetSelfSize(), 10);
1894 EXPECT_EQ(head->GetId(), 5);
1895 const std::vector<std::unique_ptr<SamplingHeapProfileNode>> *children = head->GetChildren();
1896 ASSERT_NE(children, nullptr);
1897 EXPECT_EQ((int)children->size(), 0);
1898
1899 const std::vector<std::unique_ptr<SamplingHeapProfileSample>> *samples = object->GetSamples();
1900 ASSERT_NE(samples, nullptr);
1901 EXPECT_EQ((int)samples->size(), 1);
1902 EXPECT_EQ(samples->data()->get()->GetSize(), 100);
1903 EXPECT_EQ(samples->data()->get()->GetNodeId(), 1);
1904 EXPECT_EQ(samples->data()->get()->GetOrdinal(), 10);
1905 }
1906
HWTEST_F_L0(DebuggerTypesTest,SamplingHeapProfileToJsonTest)1907 HWTEST_F_L0(DebuggerTypesTest, SamplingHeapProfileToJsonTest)
1908 {
1909 std::string msg;
1910 std::unique_ptr<SamplingHeapProfile> samplingHeapProfile;
1911 std::string tmpStr;
1912 int32_t tmpInt;
1913 std::unique_ptr<PtJson> tmpJson;
1914 std::unique_ptr<PtJson> varTmpJson;
1915 std::unique_ptr<PtJson> exTmpJson;
1916 Result ret;
1917
1918 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
1919 "head": {
1920 "callFrame": {"functionName":"Create", "moduleName":"entry", "scriptId":"10", "url":"url3",
1921 "lineNumber":100, "columnNumber":20},
1922 "selfSize":10,
1923 "id":5,
1924 "children":[]
1925 },
1926 "samples":[{"size":100, "nodeId":1, "ordinal":10}]
1927 }})";
1928
1929 samplingHeapProfile = SamplingHeapProfile::Create(DispatchRequest(msg).GetParams());
1930 ASSERT_NE(samplingHeapProfile, nullptr);
1931 auto json = samplingHeapProfile->ToJson();
1932
1933 ret = json->GetObject("head", &tmpJson);
1934 EXPECT_EQ(ret, Result::SUCCESS);
1935 ASSERT_NE(tmpJson, nullptr);
1936 ret = tmpJson->GetObject("callFrame", &varTmpJson);
1937 EXPECT_EQ(ret, Result::SUCCESS);
1938 ASSERT_NE(varTmpJson, nullptr);
1939 ret = varTmpJson->GetString("functionName", &tmpStr);
1940 EXPECT_EQ(ret, Result::SUCCESS);
1941 EXPECT_EQ(tmpStr, "Create");
1942 ret = varTmpJson->GetString("moduleName", &tmpStr);
1943 EXPECT_EQ(ret, Result::SUCCESS);
1944 EXPECT_EQ(tmpStr, "entry");
1945 ret = varTmpJson->GetString("scriptId", &tmpStr);
1946 EXPECT_EQ(ret, Result::SUCCESS);
1947 EXPECT_EQ(tmpStr, "10");
1948 ret = varTmpJson->GetString("url", &tmpStr);
1949 EXPECT_EQ(ret, Result::SUCCESS);
1950 EXPECT_EQ(tmpStr, "url3");
1951
1952 ret = tmpJson->GetInt("selfSize", &tmpInt);
1953 EXPECT_EQ(ret, Result::SUCCESS);
1954 EXPECT_EQ(tmpInt, 10);
1955 ret = tmpJson->GetInt("id", &tmpInt);
1956 EXPECT_EQ(ret, Result::SUCCESS);
1957 EXPECT_EQ(tmpInt, 5);
1958 ret = tmpJson->GetArray("children", &exTmpJson);
1959 EXPECT_EQ(ret, Result::SUCCESS);
1960 ASSERT_NE(exTmpJson, nullptr);
1961 EXPECT_EQ(exTmpJson->GetSize(), 0);
1962
1963 ret = json->GetArray("samples", &tmpJson);
1964 EXPECT_EQ(ret, Result::SUCCESS);
1965 ASSERT_NE(tmpJson, nullptr);
1966 EXPECT_EQ(tmpJson->GetSize(), 1);
1967 }
1968
HWTEST_F_L0(DebuggerTypesTest,PositionTickInfoCreateTest)1969 HWTEST_F_L0(DebuggerTypesTest, PositionTickInfoCreateTest)
1970 {
1971 std::string msg;
1972 std::unique_ptr<PositionTickInfo> positionTickInfo;
1973
1974 // abnormal params of null msg
1975 msg = std::string() + R"({})";
1976 positionTickInfo = PositionTickInfo::Create(DispatchRequest(msg).GetParams());
1977 EXPECT_EQ(positionTickInfo, nullptr);
1978
1979 // abnormal params of unexist key params
1980 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
1981 positionTickInfo = PositionTickInfo::Create(DispatchRequest(msg).GetParams());
1982 EXPECT_EQ(positionTickInfo, nullptr);
1983
1984 // abnormal params of null params.sub-key
1985 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
1986 positionTickInfo = PositionTickInfo::Create(DispatchRequest(msg).GetParams());
1987 EXPECT_EQ(positionTickInfo, nullptr);
1988
1989 // abnormal params of unknown params.sub-key
1990 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
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 // abnormal params of params.sub-key=["line":"11","ticks":"99"]
2001 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2002 "line":"11","ticks":"99"}})";
2003 positionTickInfo = PositionTickInfo::Create(DispatchRequest(msg).GetParams());
2004 EXPECT_EQ(positionTickInfo, nullptr);
2005
2006 // abnormal params of params.sub-key=["line":[11],"ticks":[99]]
2007 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2008 "line":[11],"ticks":[99]}})";
2009 positionTickInfo = PositionTickInfo::Create(DispatchRequest(msg).GetParams());
2010 EXPECT_EQ(positionTickInfo, nullptr);
2011
2012 // normal params of params.sub-key=["line":11,"ticks":99]
2013 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"line":1,"ticks":0}})";
2014 positionTickInfo = PositionTickInfo::Create(DispatchRequest(msg).GetParams());
2015 ASSERT_NE(positionTickInfo, nullptr);
2016 EXPECT_EQ(positionTickInfo->GetLine(), 1);
2017 EXPECT_EQ(positionTickInfo->GetTicks(), 0);
2018 }
2019
HWTEST_F_L0(DebuggerTypesTest,PositionTickInfoToJsonTest)2020 HWTEST_F_L0(DebuggerTypesTest, PositionTickInfoToJsonTest)
2021 {
2022 std::string msg;
2023 std::unique_ptr<PositionTickInfo> positionTickInfo;
2024 int32_t tmpInt;
2025 Result ret;
2026
2027 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"line":1,"ticks":0}})";
2028 positionTickInfo = PositionTickInfo::Create(DispatchRequest(msg).GetParams());
2029 ASSERT_NE(positionTickInfo, nullptr);
2030 auto json = positionTickInfo->ToJson();
2031
2032 ret = json->GetInt("line", &tmpInt);
2033 EXPECT_EQ(ret, Result::SUCCESS);
2034 EXPECT_EQ(tmpInt, 1);
2035
2036 ret = json->GetInt("ticks", &tmpInt);
2037 EXPECT_EQ(ret, Result::SUCCESS);
2038 EXPECT_EQ(tmpInt, 0);
2039 }
2040
HWTEST_F_L0(DebuggerTypesTest,ProfileNodeCreateTest)2041 HWTEST_F_L0(DebuggerTypesTest, ProfileNodeCreateTest)
2042 {
2043 std::string msg;
2044 std::unique_ptr<ProfileNode> profileNode;
2045
2046 // abnormal params of null msg
2047 msg = std::string() + R"({})";
2048 profileNode = ProfileNode::Create(DispatchRequest(msg).GetParams());
2049 EXPECT_EQ(profileNode, nullptr);
2050
2051 // abnormal params of unexist key params
2052 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
2053 profileNode = ProfileNode::Create(DispatchRequest(msg).GetParams());
2054 EXPECT_EQ(profileNode, nullptr);
2055
2056 // abnormal params of null params.sub-key
2057 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
2058 profileNode = ProfileNode::Create(DispatchRequest(msg).GetParams());
2059 EXPECT_EQ(profileNode, nullptr);
2060
2061 // abnormal params of unknown params.sub-key
2062 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
2063 profileNode = ProfileNode::Create(DispatchRequest(msg).GetParams());
2064 EXPECT_EQ(profileNode, nullptr);
2065
2066 // normal params of params.sub-key=[..]
2067 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2068 "id":10,
2069 "callFrame": {"functionName":"name0", "moduleName":"entry", "scriptId":"12", "url":"url15", "lineNumber":11,
2070 "columnNumber":20}, "hitCount":15, "children":[], "positionTicks":[], "deoptReason":"yyy"}})";
2071 profileNode = ProfileNode::Create(DispatchRequest(msg).GetParams());
2072
2073 ASSERT_NE(profileNode, nullptr);
2074 EXPECT_EQ(profileNode->GetId(), 10);
2075 RuntimeCallFrame *runTimeCallFrame = profileNode->GetCallFrame();
2076 ASSERT_NE(runTimeCallFrame, nullptr);
2077 EXPECT_EQ(runTimeCallFrame->GetFunctionName(), "name0");
2078 EXPECT_EQ(runTimeCallFrame->GetModuleName(), "entry");
2079 EXPECT_EQ(runTimeCallFrame->GetScriptId(), "12");
2080 EXPECT_EQ(runTimeCallFrame->GetUrl(), "url15");
2081 EXPECT_EQ(runTimeCallFrame->GetLineNumber(), 11);
2082 EXPECT_EQ(runTimeCallFrame->GetColumnNumber(), 20);
2083
2084 EXPECT_EQ(profileNode->GetHitCount(), 15);
2085 EXPECT_EQ(profileNode->GetDeoptReason(), "yyy");
2086 }
2087
HWTEST_F_L0(DebuggerTypesTest,ProfileNodeToJsonTest)2088 HWTEST_F_L0(DebuggerTypesTest, ProfileNodeToJsonTest)
2089 {
2090 std::string msg;
2091 std::unique_ptr<ProfileNode> profilenode;
2092 std::string tmpStr;
2093 int32_t tmpInt;
2094 std::unique_ptr<PtJson> tmpJson;
2095 Result ret;
2096
2097 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2098 "id":10,
2099 "callFrame": {"functionName":"name0", "moduleName":"entry", "scriptId":"12", "url":"url15", "lineNumber":11,
2100 "columnNumber":20}, "hitCount":15, "children":[], "positionTicks":[], "deoptReason":"yyy"}})";
2101 profilenode = ProfileNode::Create(DispatchRequest(msg).GetParams());
2102 ASSERT_NE(profilenode, nullptr);
2103 auto json = profilenode->ToJson();
2104
2105 ret = json->GetInt("id", &tmpInt);
2106 EXPECT_EQ(ret, Result::SUCCESS);
2107 EXPECT_EQ(tmpInt, 10);
2108
2109 ret = json->GetObject("callFrame", &tmpJson);
2110 EXPECT_EQ(ret, Result::SUCCESS);
2111 ASSERT_NE(tmpJson, nullptr);
2112 ret = tmpJson->GetString("functionName", &tmpStr);
2113 EXPECT_EQ(ret, Result::SUCCESS);
2114 EXPECT_EQ(tmpStr, "name0");
2115 ret = tmpJson->GetString("moduleName", &tmpStr);
2116 EXPECT_EQ(ret, Result::SUCCESS);
2117 EXPECT_EQ(tmpStr, "entry");
2118 ret = tmpJson->GetString("scriptId", &tmpStr);
2119 EXPECT_EQ(ret, Result::SUCCESS);
2120 EXPECT_EQ(tmpStr, "12");
2121 ret = tmpJson->GetString("url", &tmpStr);
2122 EXPECT_EQ(ret, Result::SUCCESS);
2123 EXPECT_EQ(tmpStr, "url15");
2124 ret = tmpJson->GetInt("lineNumber", &tmpInt);
2125 EXPECT_EQ(ret, Result::SUCCESS);
2126 EXPECT_EQ(tmpInt, 11);
2127 ret = tmpJson->GetInt("columnNumber", &tmpInt);
2128 EXPECT_EQ(ret, Result::SUCCESS);
2129 EXPECT_EQ(tmpInt, 20);
2130
2131 ret = json->GetInt("hitCount", &tmpInt);
2132 EXPECT_EQ(ret, Result::SUCCESS);
2133 EXPECT_EQ(tmpInt, 15);
2134
2135 ret = json->GetString("deoptReason", &tmpStr);
2136 EXPECT_EQ(ret, Result::SUCCESS);
2137 EXPECT_EQ(tmpStr, "yyy");
2138 }
2139
HWTEST_F_L0(DebuggerTypesTest,ProfileCreateTest)2140 HWTEST_F_L0(DebuggerTypesTest, ProfileCreateTest)
2141 {
2142 std::string msg;
2143 std::unique_ptr<Profile> profile;
2144
2145 // abnormal params of null msg
2146 msg = std::string() + R"({})";
2147 profile = Profile::Create(DispatchRequest(msg).GetParams());
2148 EXPECT_EQ(profile, nullptr);
2149
2150 // abnormal params of unexist key params
2151 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
2152 profile = Profile::Create(DispatchRequest(msg).GetParams());
2153 EXPECT_EQ(profile, nullptr);
2154
2155 // abnormal params of null params.sub-key
2156 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
2157 profile = Profile::Create(DispatchRequest(msg).GetParams());
2158 EXPECT_EQ(profile, nullptr);
2159
2160 // abnormal params of unknown params.sub-key
2161 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
2162 profile = Profile::Create(DispatchRequest(msg).GetParams());
2163 EXPECT_EQ(profile, nullptr);
2164
2165 // abnormal params of params.sub-key=[..]
2166 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2167 "tid":1000, "startTime":10, "endTime":25, "gcTime":25, "cInterpreterTime":25, "asmInterpreterTime":25,
2168 "aotTime":25, "builtinTime":25, "napiTime":25, "arkuiEngineTime":25, "runtimeTime":25, "otherTime":25,
2169 "nodes":[{"id":12, "callFrame": {"functionName":"Create", "moduleName":"entry", "scriptId":"10",
2170 "url":"url3", "lineNumber":100, "columnNumber":20}}], "samples":[],"timeDeltas":[]}})";
2171 profile = Profile::Create(DispatchRequest(msg).GetParams());
2172 ASSERT_NE(profile, nullptr);
2173
2174 EXPECT_EQ(profile->GetTid(), 1000LL);
2175 EXPECT_EQ(profile->GetStartTime(), 10LL);
2176 EXPECT_EQ(profile->GetEndTime(), 25LL);
2177 EXPECT_EQ(profile->GetGcTime(), 25LL);
2178 EXPECT_EQ(profile->GetCInterpreterTime(), 25LL);
2179 EXPECT_EQ(profile->GetAsmInterpreterTime(), 25LL);
2180 EXPECT_EQ(profile->GetAotTime(), 25LL);
2181 EXPECT_EQ(profile->GetBuiltinTime(), 25LL);
2182 EXPECT_EQ(profile->GetNapiTime(), 25LL);
2183 EXPECT_EQ(profile->GetArkuiEngineTime(), 25LL);
2184 EXPECT_EQ(profile->GetRuntimeTime(), 25LL);
2185 EXPECT_EQ(profile->GetOtherTime(), 25LL);
2186 const std::vector<std::unique_ptr<ProfileNode>> *profileNode = profile->GetNodes();
2187 ASSERT_NE(profileNode, nullptr);
2188 EXPECT_EQ((int)profileNode->size(), 1);
2189 }
2190
HWTEST_F_L0(DebuggerTypesTest,ProfileToJsonTest)2191 HWTEST_F_L0(DebuggerTypesTest, ProfileToJsonTest)
2192 {
2193 std::string msg;
2194 std::unique_ptr<Profile> profile;
2195 std::string tmpStr;
2196 int32_t tmpInt;
2197 std::unique_ptr<PtJson> tmpJson;
2198 Result ret;
2199
2200 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2201 "tid":1000, "startTime":10, "endTime":25, "gcTime":25, "cInterpreterTime":25, "asmInterpreterTime":25,
2202 "aotTime":25, "builtinTime":25, "napiTime":25, "arkuiEngineTime":25, "runtimeTime":25, "otherTime":25,
2203 "nodes":[{"id":12, "callFrame": {"functionName":"Create", "moduleName":"entry", "scriptId":"10",
2204 "url":"url3", "lineNumber":100, "columnNumber":20}}], "samples":[],"timeDeltas":[]}})";
2205 profile = Profile::Create(DispatchRequest(msg).GetParams());
2206 ASSERT_NE(profile, nullptr);
2207 auto json = profile->ToJson();
2208
2209 ret = json->GetInt("tid", &tmpInt);
2210 EXPECT_EQ(ret, Result::SUCCESS);
2211 EXPECT_EQ(tmpInt, 1000);
2212
2213 ret = json->GetInt("startTime", &tmpInt);
2214 EXPECT_EQ(ret, Result::SUCCESS);
2215 EXPECT_EQ(tmpInt, 10);
2216
2217 ret = json->GetInt("endTime", &tmpInt);
2218 EXPECT_EQ(ret, Result::SUCCESS);
2219 EXPECT_EQ(tmpInt, 25);
2220
2221 ret = json->GetInt("gcTime", &tmpInt);
2222 EXPECT_EQ(ret, Result::SUCCESS);
2223 EXPECT_EQ(tmpInt, 25);
2224
2225 ret = json->GetInt("cInterpreterTime", &tmpInt);
2226 EXPECT_EQ(ret, Result::SUCCESS);
2227 EXPECT_EQ(tmpInt, 25);
2228
2229 ret = json->GetInt("asmInterpreterTime", &tmpInt);
2230 EXPECT_EQ(ret, Result::SUCCESS);
2231 EXPECT_EQ(tmpInt, 25);
2232
2233 ret = json->GetInt("aotTime", &tmpInt);
2234 EXPECT_EQ(ret, Result::SUCCESS);
2235 EXPECT_EQ(tmpInt, 25);
2236
2237 ret = json->GetInt("builtinTime", &tmpInt);
2238 EXPECT_EQ(ret, Result::SUCCESS);
2239 EXPECT_EQ(tmpInt, 25);
2240
2241 ret = json->GetInt("napiTime", &tmpInt);
2242 EXPECT_EQ(ret, Result::SUCCESS);
2243 EXPECT_EQ(tmpInt, 25);
2244
2245 ret = json->GetInt("arkuiEngineTime", &tmpInt);
2246 EXPECT_EQ(ret, Result::SUCCESS);
2247 EXPECT_EQ(tmpInt, 25);
2248
2249 ret = json->GetInt("runtimeTime", &tmpInt);
2250 EXPECT_EQ(ret, Result::SUCCESS);
2251 EXPECT_EQ(tmpInt, 25);
2252
2253 ret = json->GetInt("otherTime", &tmpInt);
2254 EXPECT_EQ(ret, Result::SUCCESS);
2255 EXPECT_EQ(tmpInt, 25);
2256 }
2257
HWTEST_F_L0(DebuggerTypesTest,CoverageCreateTest)2258 HWTEST_F_L0(DebuggerTypesTest, CoverageCreateTest)
2259 {
2260 std::string msg;
2261 std::unique_ptr<Coverage> coverage;
2262
2263 // abnormal params of null msg
2264 msg = std::string() + R"({})";
2265 coverage = Coverage::Create(DispatchRequest(msg).GetParams());
2266 EXPECT_EQ(coverage, nullptr);
2267
2268 // abnormal params of unexist key params
2269 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
2270 coverage = Coverage::Create(DispatchRequest(msg).GetParams());
2271 EXPECT_EQ(coverage, nullptr);
2272
2273 // abnormal params of null params.sub-key
2274 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
2275 coverage = Coverage::Create(DispatchRequest(msg).GetParams());
2276 EXPECT_EQ(coverage, nullptr);
2277
2278 // abnormal params of unknown params.sub-key
2279 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
2280 coverage = Coverage::Create(DispatchRequest(msg).GetParams());
2281 EXPECT_EQ(coverage, nullptr);
2282
2283 // normal params of params.sub-key=["startOffset":0,"endOffset":5,"count":13]
2284 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2285 "startOffset":0,"endOffset":13,"count":13}})";
2286 coverage = Coverage::Create(DispatchRequest(msg).GetParams());
2287 ASSERT_NE(coverage, nullptr);
2288 EXPECT_EQ(coverage->GetStartOffset(), 0);
2289 EXPECT_EQ(coverage->GetEndOffset(), 13);
2290 EXPECT_EQ(coverage->GetCount(), 13);
2291 }
2292
HWTEST_F_L0(DebuggerTypesTest,CoverageToJsonTest)2293 HWTEST_F_L0(DebuggerTypesTest, CoverageToJsonTest)
2294 {
2295 std::string msg;
2296 std::unique_ptr<Coverage> coverage;
2297 std::string tmpStr;
2298 int32_t tmpInt;
2299 Result ret;
2300
2301 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2302 "startOffset":0,"endOffset":13,"count":13}})";
2303 coverage = Coverage::Create(DispatchRequest(msg).GetParams());
2304 ASSERT_NE(coverage, nullptr);
2305 auto json = coverage->ToJson();
2306
2307 ret = json->GetInt("startOffset", &tmpInt);
2308 EXPECT_EQ(ret, Result::SUCCESS);
2309 EXPECT_EQ(tmpInt, 0);
2310
2311 ret = json->GetInt("endOffset", &tmpInt);
2312 EXPECT_EQ(ret, Result::SUCCESS);
2313 EXPECT_EQ(tmpInt, 13);
2314
2315 ret = json->GetInt("count", &tmpInt);
2316 EXPECT_EQ(ret, Result::SUCCESS);
2317 EXPECT_EQ(tmpInt, 13);
2318 }
2319
HWTEST_F_L0(DebuggerTypesTest,FunctionCoverageCreateTest)2320 HWTEST_F_L0(DebuggerTypesTest, FunctionCoverageCreateTest)
2321 {
2322 std::string msg;
2323 std::unique_ptr<FunctionCoverage> functionCoverage;
2324
2325 // abnormal params of null msg
2326 msg = std::string() + R"({})";
2327 functionCoverage = FunctionCoverage::Create(DispatchRequest(msg).GetParams());
2328 EXPECT_EQ(functionCoverage, nullptr);
2329
2330 // abnormal params of unexist key params
2331 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
2332 functionCoverage = FunctionCoverage::Create(DispatchRequest(msg).GetParams());
2333 EXPECT_EQ(functionCoverage, nullptr);
2334
2335 // abnormal params of null params.sub-key
2336 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
2337 functionCoverage = FunctionCoverage::Create(DispatchRequest(msg).GetParams());
2338 EXPECT_EQ(functionCoverage, nullptr);
2339
2340 // abnormal params of unknown params.sub-key
2341 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
2342 functionCoverage = FunctionCoverage::Create(DispatchRequest(msg).GetParams());
2343 EXPECT_EQ(functionCoverage, nullptr);
2344
2345 // normal params of params.sub-key=[..]
2346 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2347 "functionName":"Create0","ranges":[{"startOffset":0,"endOffset":13,"count":13}],"isBlockCoverage":true}})";
2348 functionCoverage = FunctionCoverage::Create(DispatchRequest(msg).GetParams());
2349
2350 ASSERT_NE(functionCoverage, nullptr);
2351 EXPECT_EQ(functionCoverage->GetFunctionName(), "Create0");
2352 const std::vector<std::unique_ptr<Coverage>> *ranges = functionCoverage->GetRanges();
2353 ASSERT_NE(ranges, nullptr);
2354 EXPECT_EQ((int)ranges->size(), 1);
2355 ASSERT_TRUE(functionCoverage->GetIsBlockCoverage());
2356 }
2357
HWTEST_F_L0(DebuggerTypesTest,FunctionCoverageToJsonTest)2358 HWTEST_F_L0(DebuggerTypesTest, FunctionCoverageToJsonTest)
2359 {
2360 std::string msg;
2361 std::unique_ptr<FunctionCoverage> functionCoverage;
2362 std::string tmpStr;
2363 bool tmpBool;
2364 std::unique_ptr<PtJson> tmpJson;
2365 Result ret;
2366
2367 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2368 "functionName":"Create0","ranges":[{"startOffset":0,"endOffset":13,"count":13}],"isBlockCoverage":true}})";
2369 functionCoverage = FunctionCoverage::Create(DispatchRequest(msg).GetParams());
2370 ASSERT_NE(functionCoverage, nullptr);
2371 auto json = functionCoverage->ToJson();
2372
2373 ret = json->GetString("functionName", &tmpStr);
2374 EXPECT_EQ(ret, Result::SUCCESS);
2375 EXPECT_EQ(tmpStr, "Create0");
2376
2377 ret = json->GetArray("ranges", &tmpJson);
2378 EXPECT_EQ(ret, Result::SUCCESS);
2379 ASSERT_NE(tmpJson, nullptr);
2380 EXPECT_EQ(tmpJson->GetSize(), 1);
2381
2382 ret = json->GetBool("isBlockCoverage", &tmpBool);
2383 EXPECT_EQ(ret, Result::SUCCESS);
2384 ASSERT_TRUE(tmpBool);
2385 }
2386
HWTEST_F_L0(DebuggerTypesTest,ScriptCoverageCreateTest)2387 HWTEST_F_L0(DebuggerTypesTest, ScriptCoverageCreateTest)
2388 {
2389 std::string msg;
2390 std::unique_ptr<ScriptCoverage> scriptCoverage;
2391
2392 // abnormal params of null msg
2393 msg = std::string() + R"({})";
2394 scriptCoverage = ScriptCoverage::Create(DispatchRequest(msg).GetParams());
2395 EXPECT_EQ(scriptCoverage, nullptr);
2396
2397 // abnormal params of unexist key params
2398 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
2399 scriptCoverage = ScriptCoverage::Create(DispatchRequest(msg).GetParams());
2400 EXPECT_EQ(scriptCoverage, nullptr);
2401
2402 // abnormal params of null params.sub-key
2403 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
2404 scriptCoverage = ScriptCoverage::Create(DispatchRequest(msg).GetParams());
2405 EXPECT_EQ(scriptCoverage, nullptr);
2406
2407 // abnormal params of unknown params.sub-key
2408 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
2409 scriptCoverage = ScriptCoverage::Create(DispatchRequest(msg).GetParams());
2410 EXPECT_EQ(scriptCoverage, nullptr);
2411
2412 // normal params of params.sub-key=[..]
2413 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2414 "scriptId":"1001",
2415 "url":"url17",
2416 "functions":[{"functionName":"Create0",
2417 "ranges":[{"startOffset":0, "endOffset":13, "count":13}],
2418 "isBlockCoverage":true}]}})";
2419 scriptCoverage = ScriptCoverage::Create(DispatchRequest(msg).GetParams());
2420 ASSERT_NE(scriptCoverage, nullptr);
2421 EXPECT_EQ(scriptCoverage->GetScriptId(), "1001");
2422 EXPECT_EQ(scriptCoverage->GetUrl(), "url17");
2423 const std::vector<std::unique_ptr<FunctionCoverage>> *functions = scriptCoverage->GetFunctions();
2424 ASSERT_NE(functions, nullptr);
2425 EXPECT_EQ((int)functions->size(), 1);
2426 }
2427
HWTEST_F_L0(DebuggerTypesTest,ScriptCoverageToJsonTest)2428 HWTEST_F_L0(DebuggerTypesTest, ScriptCoverageToJsonTest)
2429 {
2430 std::string msg;
2431 std::unique_ptr<ScriptCoverage> scriptCoverage;
2432 std::string tmpStr;
2433 std::unique_ptr<PtJson> tmpJson;
2434 Result ret;
2435
2436 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2437 "scriptId":"1001",
2438 "url":"url17",
2439 "functions": [{"functionName":"Create0",
2440 "ranges": [{"startOffset":0, "endOffset":13, "count":13}],
2441 "isBlockCoverage":true}]}})";
2442 scriptCoverage = ScriptCoverage::Create(DispatchRequest(msg).GetParams());
2443 ASSERT_NE(scriptCoverage, nullptr);
2444 auto json = scriptCoverage->ToJson();
2445
2446 ret = json->GetString("scriptId", &tmpStr);
2447 EXPECT_EQ(ret, Result::SUCCESS);
2448 EXPECT_EQ(tmpStr, "1001");
2449
2450 ret = json->GetString("url", &tmpStr);
2451 EXPECT_EQ(ret, Result::SUCCESS);
2452 EXPECT_EQ(tmpStr, "url17");
2453
2454 ret = json->GetArray("functions", &tmpJson);
2455 EXPECT_EQ(ret, Result::SUCCESS);
2456 ASSERT_NE(tmpJson, nullptr);
2457 EXPECT_EQ(tmpJson->GetSize(), 1);
2458 }
2459
HWTEST_F_L0(DebuggerTypesTest,TypeObjectCreateTest)2460 HWTEST_F_L0(DebuggerTypesTest, TypeObjectCreateTest)
2461 {
2462 std::string msg;
2463 std::unique_ptr<TypeObject> typeObject;
2464
2465 // abnormal params of null msg
2466 msg = std::string() + R"({})";
2467 typeObject = TypeObject::Create(DispatchRequest(msg).GetParams());
2468 EXPECT_EQ(typeObject, nullptr);
2469
2470 // abnormal params of unexist key params
2471 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
2472 typeObject = TypeObject::Create(DispatchRequest(msg).GetParams());
2473 EXPECT_EQ(typeObject, nullptr);
2474
2475 // abnormal params of null params.sub-key
2476 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
2477 typeObject = TypeObject::Create(DispatchRequest(msg).GetParams());
2478 EXPECT_EQ(typeObject, nullptr);
2479
2480 // abnormal params of unknown params.sub-key
2481 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
2482 typeObject = TypeObject::Create(DispatchRequest(msg).GetParams());
2483 EXPECT_EQ(typeObject, nullptr);
2484
2485 // normal params of params.sub-key=[..]
2486 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2487 "name":"Create1"}})";
2488 typeObject = TypeObject::Create(DispatchRequest(msg).GetParams());
2489 ASSERT_NE(typeObject, nullptr);
2490 EXPECT_EQ(typeObject->GetName(), "Create1");
2491 }
2492
HWTEST_F_L0(DebuggerTypesTest,TypeObjectToJsonTest)2493 HWTEST_F_L0(DebuggerTypesTest, TypeObjectToJsonTest)
2494 {
2495 std::string msg;
2496 std::unique_ptr<TypeObject> typeObject;
2497 std::string tmpStr;
2498 Result ret;
2499
2500 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2501 "name":"Create1"}})";
2502 typeObject = TypeObject::Create(DispatchRequest(msg).GetParams());
2503 ASSERT_NE(typeObject, nullptr);
2504 auto json = typeObject->ToJson();
2505
2506 ret = json->GetString("name", &tmpStr);
2507 EXPECT_EQ(ret, Result::SUCCESS);
2508 EXPECT_EQ(tmpStr, "Create1");
2509 }
2510
HWTEST_F_L0(DebuggerTypesTest,TypeProfileEntryCreateTest)2511 HWTEST_F_L0(DebuggerTypesTest, TypeProfileEntryCreateTest)
2512 {
2513 std::string msg;
2514 std::unique_ptr<TypeProfileEntry> typeProfileEntry;
2515
2516 // abnormal params of null msg
2517 msg = std::string() + R"({})";
2518 typeProfileEntry = TypeProfileEntry::Create(DispatchRequest(msg).GetParams());
2519 EXPECT_EQ(typeProfileEntry, nullptr);
2520
2521 // abnormal params of unexist key params
2522 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
2523 typeProfileEntry = TypeProfileEntry::Create(DispatchRequest(msg).GetParams());
2524 EXPECT_EQ(typeProfileEntry, nullptr);
2525
2526 // abnormal params of null params.sub-key
2527 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
2528 typeProfileEntry = TypeProfileEntry::Create(DispatchRequest(msg).GetParams());
2529 EXPECT_EQ(typeProfileEntry, nullptr);
2530
2531 // abnormal params of unknown params.sub-key
2532 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
2533 typeProfileEntry = TypeProfileEntry::Create(DispatchRequest(msg).GetParams());
2534 EXPECT_EQ(typeProfileEntry, nullptr);
2535
2536 // normal params of params.sub-key=[..]
2537 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2538 "offset":11,"types":[{"name":"Create1"}]}})";
2539 typeProfileEntry = TypeProfileEntry::Create(DispatchRequest(msg).GetParams());
2540 ASSERT_NE(typeProfileEntry, nullptr);
2541 EXPECT_EQ(typeProfileEntry->GetOffset(), 11);
2542 const std::vector<std::unique_ptr<TypeObject>> *typeObject = typeProfileEntry->GetTypes();
2543 ASSERT_NE(typeObject, nullptr);
2544 EXPECT_EQ((int)typeObject->size(), 1);
2545 }
2546
HWTEST_F_L0(DebuggerTypesTest,TypeProfileEntryToJsonTest)2547 HWTEST_F_L0(DebuggerTypesTest, TypeProfileEntryToJsonTest)
2548 {
2549 std::string msg;
2550 std::unique_ptr<TypeProfileEntry> typeProfileEntry;
2551 int32_t tmpInt;
2552 std::unique_ptr<PtJson> tmpJson;
2553 Result ret;
2554
2555 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2556 "offset":11,"types":[{"name":"Create1"}]}})";
2557 typeProfileEntry = TypeProfileEntry::Create(DispatchRequest(msg).GetParams());
2558 ASSERT_NE(typeProfileEntry, nullptr);
2559 auto json = typeProfileEntry->ToJson();
2560
2561 ret = json->GetInt("offset", &tmpInt);
2562 EXPECT_EQ(ret, Result::SUCCESS);
2563 EXPECT_EQ(tmpInt, 11);
2564
2565 ret = json->GetArray("types", &tmpJson);
2566 EXPECT_EQ(ret, Result::SUCCESS);
2567 ASSERT_NE(tmpJson, nullptr);
2568 EXPECT_EQ(tmpJson->GetSize(), 1);
2569 }
2570
HWTEST_F_L0(DebuggerTypesTest,ScriptTypeProfileCreateTest)2571 HWTEST_F_L0(DebuggerTypesTest, ScriptTypeProfileCreateTest)
2572 {
2573 std::string msg;
2574 std::unique_ptr<ScriptTypeProfile> scriptTypeProfile;
2575
2576 // abnormal params of null msg
2577 msg = std::string() + R"({})";
2578 scriptTypeProfile = ScriptTypeProfile::Create(DispatchRequest(msg).GetParams());
2579 EXPECT_EQ(scriptTypeProfile, nullptr);
2580
2581 // abnormal params of unexist key params
2582 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
2583 scriptTypeProfile = ScriptTypeProfile::Create(DispatchRequest(msg).GetParams());
2584 EXPECT_EQ(scriptTypeProfile, nullptr);
2585
2586 // abnormal params of null params.sub-key
2587 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
2588 scriptTypeProfile = ScriptTypeProfile::Create(DispatchRequest(msg).GetParams());
2589 EXPECT_EQ(scriptTypeProfile, nullptr);
2590
2591 // abnormal params of unknown params.sub-key
2592 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
2593 scriptTypeProfile = ScriptTypeProfile::Create(DispatchRequest(msg).GetParams());
2594 EXPECT_EQ(scriptTypeProfile, nullptr);
2595
2596 // normal params of params.sub-key=[..]
2597 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2598 "scriptId":"122","url":"url15","entries":[{"offset":11,"types":[{"name":"Create1"}]}]}})";
2599 scriptTypeProfile = ScriptTypeProfile::Create(DispatchRequest(msg).GetParams());
2600 ASSERT_NE(scriptTypeProfile, nullptr);
2601 EXPECT_EQ(scriptTypeProfile->GetScriptId(), "122");
2602 EXPECT_EQ(scriptTypeProfile->GetUrl(), "url15");
2603 const std::vector<std::unique_ptr<TypeProfileEntry>> *typeProfileEntry = scriptTypeProfile->GetEntries();
2604 ASSERT_NE(typeProfileEntry, nullptr);
2605 EXPECT_EQ((int)typeProfileEntry->size(), 1);
2606 }
2607
HWTEST_F_L0(DebuggerTypesTest,ScriptTypeProfileToJsonTest)2608 HWTEST_F_L0(DebuggerTypesTest, ScriptTypeProfileToJsonTest)
2609 {
2610 std::string msg;
2611 std::unique_ptr<ScriptTypeProfile> scriptTypeProfile;
2612 std::string tmpStr;
2613 std::unique_ptr<PtJson> tmpJson;
2614 Result ret;
2615
2616 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2617 "scriptId":"122","url":"url15","entries":[{"offset":11,"types":[{"name":"Create1"}]}]}})";
2618 scriptTypeProfile = ScriptTypeProfile::Create(DispatchRequest(msg).GetParams());
2619 ASSERT_NE(scriptTypeProfile, nullptr);
2620 auto json = scriptTypeProfile->ToJson();
2621
2622 ret = json->GetString("scriptId", &tmpStr);
2623 EXPECT_EQ(ret, Result::SUCCESS);
2624 EXPECT_EQ(tmpStr, "122");
2625
2626 ret = json->GetString("url", &tmpStr);
2627 EXPECT_EQ(ret, Result::SUCCESS);
2628 EXPECT_EQ(tmpStr, "url15");
2629
2630 ret = json->GetArray("entries", &tmpJson);
2631 EXPECT_EQ(ret, Result::SUCCESS);
2632 ASSERT_NE(tmpJson, nullptr);
2633 EXPECT_EQ(tmpJson->GetSize(), 1);
2634 }
2635
HWTEST_F_L0(DebuggerTypesTest,TraceConfigCreateTest)2636 HWTEST_F_L0(DebuggerTypesTest, TraceConfigCreateTest)
2637 {
2638 std::string msg;
2639 std::unique_ptr<TraceConfig> traceConfig;
2640
2641 // abnormal params of null msg
2642 msg = std::string() + R"({})";
2643 traceConfig = TraceConfig::Create(DispatchRequest(msg).GetParams());
2644 ASSERT_NE(traceConfig, nullptr);
2645
2646 // abnormal params of unexist key params
2647 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
2648 traceConfig = TraceConfig::Create(DispatchRequest(msg).GetParams());
2649 ASSERT_NE(traceConfig, nullptr);
2650
2651 // abnormal params of null params.sub-key
2652 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
2653 traceConfig = TraceConfig::Create(DispatchRequest(msg).GetParams());
2654 ASSERT_NE(traceConfig, nullptr);
2655
2656 // abnormal params of unknown params.sub-key
2657 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
2658 traceConfig = TraceConfig::Create(DispatchRequest(msg).GetParams());
2659 ASSERT_NE(traceConfig, nullptr);
2660
2661 // normal params of params.sub-key=[..]
2662 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2663 "recordMode":"recordUntilFull", "enableSampling":true, "enableSystrace":true,
2664 "enableArgumentFilter":true}})";
2665 traceConfig = TraceConfig::Create(DispatchRequest(msg).GetParams());
2666 ASSERT_NE(traceConfig, nullptr);
2667
2668 EXPECT_EQ(traceConfig->GetRecordMode(), "recordUntilFull");
2669 ASSERT_TRUE(traceConfig->GetEnableSampling());
2670 ASSERT_TRUE(traceConfig->GetEnableSystrace());
2671 ASSERT_TRUE(traceConfig->GetEnableArgumentFilter());
2672 }
2673
HWTEST_F_L0(DebuggerTypesTest,TraceConfigToJsonTest)2674 HWTEST_F_L0(DebuggerTypesTest, TraceConfigToJsonTest)
2675 {
2676 std::string msg;
2677 std::unique_ptr<TraceConfig> traceConfig;
2678 std::string tmpStr;
2679 std::unique_ptr<PtJson> tmpJson;
2680 bool tmpBool;
2681 Result ret;
2682
2683 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2684 "recordMode":"recordUntilFull", "enableSampling":true, "enableSystrace":true,
2685 "enableArgumentFilter":true}})";
2686 traceConfig = TraceConfig::Create(DispatchRequest(msg).GetParams());
2687 ASSERT_NE(traceConfig, nullptr);
2688 auto json = traceConfig->ToJson();
2689
2690 ret = json->GetString("recordMode", &tmpStr);
2691 EXPECT_EQ(ret, Result::SUCCESS);
2692 EXPECT_EQ(tmpStr, "recordUntilFull");
2693
2694 ret = json->GetBool("enableSampling", &tmpBool);
2695 EXPECT_EQ(ret, Result::SUCCESS);
2696 ASSERT_TRUE(tmpBool);
2697
2698 ret = json->GetBool("enableSystrace", &tmpBool);
2699 EXPECT_EQ(ret, Result::SUCCESS);
2700 ASSERT_TRUE(tmpBool);
2701
2702 ret = json->GetBool("enableArgumentFilter", &tmpBool);
2703 EXPECT_EQ(ret, Result::SUCCESS);
2704 ASSERT_TRUE(tmpBool);
2705 }
2706
HWTEST_F_L0(DebuggerTypesTest,CallArgumentCreateTest)2707 HWTEST_F_L0(DebuggerTypesTest, CallArgumentCreateTest)
2708 {
2709 std::string msg;
2710 std::unique_ptr<CallArgument> callArgument;
2711
2712 // abnormal params of null msg
2713 msg = std::string() + R"({})";
2714 callArgument = CallArgument::Create(DispatchRequest(msg).GetParams());
2715 ASSERT_NE(callArgument, nullptr);
2716
2717 // abnormal params of unexist key params
2718 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
2719 callArgument = CallArgument::Create(DispatchRequest(msg).GetParams());
2720 ASSERT_NE(callArgument, nullptr);
2721
2722 // abnormal params of null params.sub-key
2723 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
2724 callArgument = CallArgument::Create(DispatchRequest(msg).GetParams());
2725 ASSERT_NE(callArgument, nullptr);
2726
2727 // abnormal params of unknown params.sub-key
2728 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
2729 callArgument = CallArgument::Create(DispatchRequest(msg).GetParams());
2730 ASSERT_NE(callArgument, nullptr);
2731 }
2732
HWTEST_F_L0(DebuggerTypesTest,CallArgumentToJsonTest)2733 HWTEST_F_L0(DebuggerTypesTest, CallArgumentToJsonTest)
2734 {
2735 CallArgument callArgument;
2736 Local<JSValueRef> callArgumentName = StringRef::NewFromUtf8(ecmaVm, "name");
2737 callArgument.SetValue(callArgumentName);
2738
2739 RemoteObjectId remoteObjectId_1(10);
2740 callArgument.SetObjectId(remoteObjectId_1);
2741 UnserializableValue testValue1("test");
2742 callArgument.SetUnserializableValue(testValue1);
2743 std::unique_ptr<PtJson> ret = callArgument.ToJson();
2744 ASSERT_TRUE(ret != nullptr);
2745
2746 CallArgument callArgument_test1;
2747 RemoteObjectId remoteObjectId_2(20);
2748 callArgument_test1.SetObjectId(remoteObjectId_2);
2749 ret = callArgument_test1.ToJson();
2750 ASSERT_TRUE(ret != nullptr);
2751
2752 CallArgument callArgument_test2;
2753 UnserializableValue testValue2("CallArgumentToJson");
2754 callArgument_test2.ToJson();
2755 ASSERT_TRUE(ret != nullptr);
2756 }
2757
HWTEST_F_L0(DebuggerTypesTest,ScriptPositionCreateTest)2758 HWTEST_F_L0(DebuggerTypesTest, ScriptPositionCreateTest)
2759 {
2760 std::string msg;
2761 std::unique_ptr<ScriptPosition> scriptPosition;
2762
2763 // abnormal params of null msg
2764 msg = std::string() + R"({})";
2765 scriptPosition = ScriptPosition::Create(DispatchRequest(msg).GetParams());
2766 EXPECT_EQ(scriptPosition, nullptr);
2767
2768 // abnormal params of unexist key params
2769 msg = std::string() + R"({"id":0,"method":"Debugger.Test"})";
2770 scriptPosition = ScriptPosition::Create(DispatchRequest(msg).GetParams());
2771 EXPECT_EQ(scriptPosition, nullptr);
2772
2773 // abnormal params of null params.sub-key
2774 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})";
2775 scriptPosition = ScriptPosition::Create(DispatchRequest(msg).GetParams());
2776 EXPECT_EQ(scriptPosition, nullptr);
2777
2778 // abnormal params of unknown params.sub-key
2779 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})";
2780 scriptPosition = ScriptPosition::Create(DispatchRequest(msg).GetParams());
2781 EXPECT_EQ(scriptPosition, nullptr);
2782
2783 // normal params of params.sub-key=["scriptId":"2","lineNumber":99,"columnNumber":138,"type":"return"]
2784 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2785 "scriptId":"222","lineNumber":899,"columnNumber":138,"type":"return"
2786 }})";
2787 scriptPosition = ScriptPosition::Create(DispatchRequest(msg).GetParams());
2788 ASSERT_NE(scriptPosition, nullptr);
2789 EXPECT_EQ(scriptPosition->GetLine(), 899);
2790 EXPECT_EQ(scriptPosition->GetColumn(), 138);
2791
2792 // normal params of params.sub-key=["scriptId":"2122","lineNumber":8299]
2793 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{
2794 "scriptId":"222","lineNumber":8299,"columnNumber":16,"type":"return"
2795 }})";
2796 scriptPosition = ScriptPosition::Create(DispatchRequest(msg).GetParams());
2797 ASSERT_NE(scriptPosition, nullptr);
2798 EXPECT_EQ(scriptPosition->GetLine(), 8299);
2799 EXPECT_EQ(scriptPosition->GetColumn(), 16);
2800 }
2801
HWTEST_F_L0(DebuggerTypesTest,ScriptPositionToJsonTest)2802 HWTEST_F_L0(DebuggerTypesTest, ScriptPositionToJsonTest)
2803 {
2804 ScriptPosition scriptPosition;
2805 int32_t lineNumber = 11;
2806 scriptPosition.SetLine(lineNumber);
2807 int32_t columnNumber = 7;
2808 scriptPosition.SetColumn(columnNumber);
2809 std::unique_ptr<PtJson> ret = scriptPosition.ToJson();
2810 ASSERT_TRUE(ret != nullptr);
2811 }
2812
HWTEST_F_L0(DebuggerTypesTest,RuntimeCallFrameToJsonTest)2813 HWTEST_F_L0(DebuggerTypesTest, RuntimeCallFrameToJsonTest)
2814 {
2815 std::unique_ptr<PtJson> runtimeCallFrame = PtJson::CreateObject();
2816 std::string runtimeCallFrame_functionName = "RuntimeCallFrameToJsonTest";
2817 std::string runtimeCallFrame_scriptId = "scriptId";
2818 std::string runtimeCallFrame_url = "url";
2819 int32_t runtimeCallFrame_lineNumber = 2;
2820 int32_t runtimeCallFrame_columnNumber = 10;
2821 runtimeCallFrame->Add("functionName", runtimeCallFrame_functionName.c_str());
2822 runtimeCallFrame->Add("moduleName", runtimeCallFrame_functionName.c_str());
2823 runtimeCallFrame->Add("scriptId", runtimeCallFrame_scriptId.c_str());
2824 runtimeCallFrame->Add("url", runtimeCallFrame_url.c_str());
2825 runtimeCallFrame->Add("lineNumber", runtimeCallFrame_lineNumber);
2826 runtimeCallFrame->Add("columnNumber", runtimeCallFrame_columnNumber);
2827 std::unique_ptr<RuntimeCallFrame> ret = RuntimeCallFrame::Create(*runtimeCallFrame);
2828 ASSERT_TRUE(ret != nullptr);
2829 }
2830
HWTEST_F_L0(DebuggerTypesTest,LocationRangeCreateTest)2831 HWTEST_F_L0(DebuggerTypesTest, LocationRangeCreateTest)
2832 {
2833 std::unique_ptr<PtJson> locationRange = PtJson::CreateObject();
2834 std::unique_ptr<PtJson> locationRange_start = PtJson::CreateObject();
2835 std::unique_ptr<PtJson> locationRange_end = PtJson::CreateObject();
2836
2837 std::string locationRange_scriptId = "14";
2838 int32_t locationRange_lineNumber = 1;
2839 int32_t locationRange_columnNumber = 2;
2840 locationRange_start->Add("lineNumber", locationRange_lineNumber);
2841 locationRange_start->Add("columnNumber", locationRange_columnNumber);
2842 locationRange_end->Add("lineNumber", locationRange_lineNumber + 1);
2843 locationRange_end->Add("columnNumber", locationRange_columnNumber + 2);
2844
2845 locationRange->Add("scriptId", locationRange_scriptId.c_str());
2846 locationRange->Add("start", locationRange_start);
2847 locationRange->Add("end", locationRange_end);
2848 std::unique_ptr<LocationRange> ret = LocationRange::Create(*locationRange);
2849 ASSERT_TRUE(ret != nullptr);
2850 }
2851 } // namespace panda::test
2852