1 /*
2 * Copyright (c) 2022 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/base/pt_types.h"
17 #include "ecmascript/tests/test_helper.h"
18 #include "protocol_handler.h"
19
20 using namespace panda::ecmascript;
21 using namespace panda::ecmascript::tooling;
22
23 namespace panda::test {
24 class PtTypesTest : public testing::Test {
25 public:
SetUpTestCase()26 static void SetUpTestCase()
27 {
28 GTEST_LOG_(INFO) << "SetUpTestCase";
29 }
30
TearDownTestCase()31 static void TearDownTestCase()
32 {
33 GTEST_LOG_(INFO) << "TearDownCase";
34 }
35
SetUp()36 void SetUp() override
37 {
38 TestHelper::CreateEcmaVMWithScope(ecmaVm, thread, scope);
39 }
40
TearDown()41 void TearDown() override
42 {
43 TestHelper::DestroyEcmaVMWithScope(ecmaVm, scope);
44 }
45
46 protected:
47 EcmaVM *ecmaVm {nullptr};
48 EcmaHandleScope *scope {nullptr};
49 JSThread *thread {nullptr};
50 };
51
HWTEST_F_L0(PtTypesTest,BreakpointDetailsToString)52 HWTEST_F_L0(PtTypesTest, BreakpointDetailsToString)
53 {
54 BreakpointDetails input;
55 BreakpointId result = BreakpointDetails::ToString(input);
56 ASSERT_TRUE(result == "id:0:0:");
57 }
58
HWTEST_F_L0(PtTypesTest,BreakpointDetailsParseBreakpointId)59 HWTEST_F_L0(PtTypesTest, BreakpointDetailsParseBreakpointId)
60 {
61 BreakpointId input = "";
62 BreakpointDetails detail;
63 bool result = BreakpointDetails::ParseBreakpointId(input, &detail);
64 ASSERT_TRUE(!result);
65 input = "id:0";
66 result = BreakpointDetails::ParseBreakpointId(input, &detail);
67 ASSERT_TRUE(!result);
68 input = "id:0:0";
69 result = BreakpointDetails::ParseBreakpointId(input, &detail);
70 ASSERT_TRUE(!result);
71 input = "id:0:0:url";
72 result = BreakpointDetails::ParseBreakpointId(input, &detail);
73 ASSERT_TRUE(result);
74 }
75
HWTEST_F_L0(PtTypesTest,TypeNameValid)76 HWTEST_F_L0(PtTypesTest, TypeNameValid)
77 {
78 std::string type = "object";
79 bool result = RemoteObject::TypeName::Valid(type);
80 ASSERT_TRUE(result);
81 type = "function";
82 result = RemoteObject::TypeName::Valid(type);
83 ASSERT_TRUE(result);
84 type = "undefined";
85 result = RemoteObject::TypeName::Valid(type);
86 ASSERT_TRUE(result);
87 type = "string";
88 result = RemoteObject::TypeName::Valid(type);
89 ASSERT_TRUE(result);
90 type = "number";
91 result = RemoteObject::TypeName::Valid(type);
92 ASSERT_TRUE(result);
93 type = "boolean";
94 result = RemoteObject::TypeName::Valid(type);
95 ASSERT_TRUE(result);
96 type = "symbol";
97 result = RemoteObject::TypeName::Valid(type);
98 ASSERT_TRUE(result);
99 type = "bigint";
100 result = RemoteObject::TypeName::Valid(type);
101 ASSERT_TRUE(result);
102 type = "wasm";
103 result = RemoteObject::TypeName::Valid(type);
104 ASSERT_TRUE(result);
105 type = "int";
106 result = RemoteObject::TypeName::Valid(type);
107 ASSERT_TRUE(!result);
108 }
109
HWTEST_F_L0(PtTypesTest,SubTypeNameValid)110 HWTEST_F_L0(PtTypesTest, SubTypeNameValid)
111 {
112 std::string type = "array";
113 bool result = RemoteObject::SubTypeName::Valid(type);
114 ASSERT_TRUE(result);
115 type = "null";
116 result = RemoteObject::SubTypeName::Valid(type);
117 ASSERT_TRUE(result);
118 type = "node";
119 result = RemoteObject::SubTypeName::Valid(type);
120 ASSERT_TRUE(result);
121 type = "regexp";
122 result = RemoteObject::SubTypeName::Valid(type);
123 ASSERT_TRUE(result);
124 type = "map";
125 result = RemoteObject::SubTypeName::Valid(type);
126 ASSERT_TRUE(result);
127 type = "set";
128 result = RemoteObject::SubTypeName::Valid(type);
129 ASSERT_TRUE(result);
130 type = "weakmap";
131 result = RemoteObject::SubTypeName::Valid(type);
132 ASSERT_TRUE(result);
133 type = "iterator";
134 result = RemoteObject::SubTypeName::Valid(type);
135 ASSERT_TRUE(result);
136 type = "generator";
137 result = RemoteObject::SubTypeName::Valid(type);
138 ASSERT_TRUE(result);
139 type = "error";
140 result = RemoteObject::SubTypeName::Valid(type);
141 ASSERT_TRUE(result);
142 type = "proxy";
143 result = RemoteObject::SubTypeName::Valid(type);
144 ASSERT_TRUE(result);
145 type = "promise";
146 result = RemoteObject::SubTypeName::Valid(type);
147 ASSERT_TRUE(result);
148 type = "typedarray";
149 result = RemoteObject::SubTypeName::Valid(type);
150 ASSERT_TRUE(result);
151 type = "arraybuffer";
152 result = RemoteObject::SubTypeName::Valid(type);
153 ASSERT_TRUE(result);
154 type = "dataview";
155 result = RemoteObject::SubTypeName::Valid(type);
156 ASSERT_TRUE(result);
157 type = "i32";
158 result = RemoteObject::SubTypeName::Valid(type);
159 ASSERT_TRUE(result);
160 type = "i64";
161 result = RemoteObject::SubTypeName::Valid(type);
162 ASSERT_TRUE(result);
163 type = "f32";
164 result = RemoteObject::SubTypeName::Valid(type);
165 ASSERT_TRUE(result);
166 type = "f64";
167 result = RemoteObject::SubTypeName::Valid(type);
168 ASSERT_TRUE(result);
169 type = "v128";
170 result = RemoteObject::SubTypeName::Valid(type);
171 ASSERT_TRUE(result);
172 type = "externref";
173 result = RemoteObject::SubTypeName::Valid(type);
174 ASSERT_TRUE(result);
175 type = "int";
176 result = RemoteObject::SubTypeName::Valid(type);
177 ASSERT_TRUE(!result);
178 }
179
HWTEST_F_L0(PtTypesTest,ExceptionDetailsGetException)180 HWTEST_F_L0(PtTypesTest, ExceptionDetailsGetException)
181 {
182 ExceptionDetails exception;
183 RemoteObject* result = exception.GetException();
184 ASSERT_TRUE(result == nullptr);
185 }
186
HWTEST_F_L0(PtTypesTest,InternalPropertyDescriptorGetValue)187 HWTEST_F_L0(PtTypesTest, InternalPropertyDescriptorGetValue)
188 {
189 InternalPropertyDescriptor descriptor;
190 RemoteObject* result = descriptor.GetValue();
191 ASSERT_TRUE(result == nullptr);
192 }
193
HWTEST_F_L0(PtTypesTest,PrivatePropertyDescriptor)194 HWTEST_F_L0(PtTypesTest, PrivatePropertyDescriptor)
195 {
196 PrivatePropertyDescriptor descriptor;
197 ASSERT_TRUE(descriptor.GetName() == "");
198 }
199
HWTEST_F_L0(PtTypesTest,PropertyDescriptorGetValue)200 HWTEST_F_L0(PtTypesTest, PropertyDescriptorGetValue)
201 {
202 panda::ecmascript::tooling::PropertyDescriptor descriptor;
203 RemoteObject* result = descriptor.GetValue();
204 ASSERT_TRUE(result == nullptr);
205 result = descriptor.GetGet();
206 ASSERT_TRUE(result == nullptr);
207 result = descriptor.GetSet();
208 ASSERT_TRUE(result == nullptr);
209 result = descriptor.GetSymbol();
210 ASSERT_TRUE(result == nullptr);
211 bool res = descriptor.HasSymbol();
212 ASSERT_TRUE(!res);
213 }
214
HWTEST_F_L0(PtTypesTest,BreakLocationTypeValid)215 HWTEST_F_L0(PtTypesTest, BreakLocationTypeValid)
216 {
217 BreakLocation::Type type;
218 bool result = type.Valid("debuggerStatement");
219 ASSERT_TRUE(result);
220 result = type.Valid("call");
221 ASSERT_TRUE(result);
222 result = type.Valid("return");
223 ASSERT_TRUE(result);
224 result = type.Valid("test");
225 ASSERT_TRUE(!result);
226 }
227
HWTEST_F_L0(PtTypesTest,ScopeTypeValid)228 HWTEST_F_L0(PtTypesTest, ScopeTypeValid)
229 {
230 Scope::Type type;
231 bool result = type.Valid("global");
232 ASSERT_TRUE(result);
233 result = type.Valid("local");
234 ASSERT_TRUE(result);
235 result = type.Valid("with");
236 ASSERT_TRUE(result);
237 result = type.Valid("closure");
238 ASSERT_TRUE(result);
239 result = type.Valid("catch");
240 ASSERT_TRUE(result);
241 result = type.Valid("block");
242 ASSERT_TRUE(result);
243 result = type.Valid("script");
244 ASSERT_TRUE(result);
245 result = type.Valid("eval");
246 ASSERT_TRUE(result);
247 result = type.Valid("module");
248 ASSERT_TRUE(result);
249 result = type.Valid("wasm-expression-stack");
250 ASSERT_TRUE(result);
251 result = type.Valid("test");
252 ASSERT_TRUE(!result);
253 }
254
HWTEST_F_L0(PtTypesTest,CallFrameGetFunctionLocation)255 HWTEST_F_L0(PtTypesTest, CallFrameGetFunctionLocation)
256 {
257 CallFrame callFrame;
258 Location *location = callFrame.GetFunctionLocation();
259 ASSERT_TRUE(location == nullptr);
260 RemoteObject *result = callFrame.GetReturnValue();
261 ASSERT_TRUE(result == nullptr);
262 }
263
HWTEST_F_L0(PtTypesTest,MemoryDumpLevelOfDetailValuesValid)264 HWTEST_F_L0(PtTypesTest, MemoryDumpLevelOfDetailValuesValid)
265 {
266 bool result = MemoryDumpLevelOfDetailValues::Valid("background");
267 ASSERT_TRUE(result);
268 result = MemoryDumpLevelOfDetailValues::Valid("light");
269 ASSERT_TRUE(result);
270 result = MemoryDumpLevelOfDetailValues::Valid("detailed");
271 ASSERT_TRUE(result);
272 result = MemoryDumpLevelOfDetailValues::Valid("test");
273 ASSERT_TRUE(!result);
274 }
275
HWTEST_F_L0(PtTypesTest,TraceConfigRecordModeValuesValid)276 HWTEST_F_L0(PtTypesTest, TraceConfigRecordModeValuesValid)
277 {
278 bool result = TraceConfig::RecordModeValues::Valid("recordUntilFull");
279 ASSERT_TRUE(result);
280 result = TraceConfig::RecordModeValues::Valid("recordContinuously");
281 ASSERT_TRUE(result);
282 result = TraceConfig::RecordModeValues::Valid("recordAsMuchAsPossible");
283 ASSERT_TRUE(result);
284 result = TraceConfig::RecordModeValues::Valid("echoToConsole");
285 ASSERT_TRUE(result);
286 result = TraceConfig::RecordModeValues::Valid("test");
287 ASSERT_TRUE(!result);
288 }
289
HWTEST_F_L0(PtTypesTest,TracingBackendValues)290 HWTEST_F_L0(PtTypesTest, TracingBackendValues)
291 {
292 bool result = TracingBackendValues::Valid("auto");
293 ASSERT_TRUE(result);
294 result = TracingBackendValues::Valid("chrome");
295 ASSERT_TRUE(result);
296 result = TracingBackendValues::Valid("system");
297 ASSERT_TRUE(result);
298 result = TracingBackendValues::Valid("test");
299 ASSERT_TRUE(!result);
300 }
301
HWTEST_F_L0(PtTypesTest,TraceConfigToJsonTest)302 HWTEST_F_L0(PtTypesTest, TraceConfigToJsonTest)
303 {
304 TraceConfig treceConfig;
305 std::vector<std::string> vct {"one", "two"};
306 treceConfig.SetIncludedCategories(vct);
307 treceConfig.SetExcludedCategories(vct);
308 treceConfig.SetSyntheticDelays(vct);
309 std::unique_ptr<PtJson> result = treceConfig.ToJson();
310 ASSERT_TRUE(result);
311 }
312
HWTEST_F_L0(PtTypesTest,TraceConfigCreateTest)313 HWTEST_F_L0(PtTypesTest, TraceConfigCreateTest)
314 {
315 std::string attribute = "test";
316 std::unique_ptr<PtJson> ptJson = PtJson::CreateObject();
317 ptJson->Add("recordMode", 0);
318 ptJson->Add("enableSampling", attribute.c_str());
319 ptJson->Add("enableSystrace", attribute.c_str());
320 ptJson->Add("enableArgumentFilter", attribute.c_str());
321 ptJson->Add("includedCategories", attribute.c_str());
322 ptJson->Add("excludedCategories", attribute.c_str());
323 ptJson->Add("syntheticDelays", attribute.c_str());
324 ptJson->Add("memoryDumpConfig", attribute.c_str());
325 std::unique_ptr<TraceConfig> traceConfig = TraceConfig::Create(*ptJson);
326 ASSERT_TRUE(!traceConfig);
327
328 std::unique_ptr<PtJson> ptJson1 = PtJson::CreateObject();
329 ptJson1->Add("recordMode", "test");
330 std::unique_ptr<TraceConfig> traceConfig1 = TraceConfig::Create(*ptJson1);
331 ASSERT_TRUE(!traceConfig1);
332
333 std::unique_ptr<PtJson> ptJson2 = PtJson::CreateObject();
334 std::unique_ptr<TraceConfig> traceConfig2 = TraceConfig::Create(*ptJson2);
335 ASSERT_TRUE(traceConfig2);
336
337 std::unique_ptr<PtJson> includedCategoriesArray = PtJson::CreateArray();
338 includedCategoriesArray->Push("includedCategory");
339 std::unique_ptr<PtJson> excludedCategoriesArray = PtJson::CreateArray();
340 excludedCategoriesArray->Push("excludedCategory1");
341 excludedCategoriesArray->Push("excludedCategory2");
342 std::unique_ptr<PtJson> syntheticDelaysArray = PtJson::CreateArray();
343 syntheticDelaysArray->Push("syntheticDelay1");
344 syntheticDelaysArray->Push("syntheticDelay2");
345 syntheticDelaysArray->Push("syntheticDelay3");
346 std::unique_ptr<PtJson> ptJson3 = PtJson::CreateObject();
347 ptJson3->Add("recordMode", "recordUntilFull");
348 ptJson3->Add("enableSampling", true);
349 ptJson3->Add("enableSystrace", true);
350 ptJson3->Add("enableArgumentFilter", true);
351 ptJson3->Add("includedCategories", includedCategoriesArray);
352 ptJson3->Add("excludedCategories", excludedCategoriesArray);
353 ptJson3->Add("syntheticDelays", syntheticDelaysArray);
354 ptJson3->Add("memoryDumpConfig", PtJson::CreateObject());
355 std::unique_ptr<TraceConfig> traceConfig3 = TraceConfig::Create(*ptJson3);
356 ASSERT_TRUE(traceConfig3);
357 ASSERT_TRUE(traceConfig3->GetEnableSampling());
358 ASSERT_TRUE(traceConfig3->GetEnableSystrace());
359 ASSERT_TRUE(traceConfig3->GetEnableArgumentFilter());
360 ASSERT_EQ(traceConfig3->GetIncludedCategories()->size(), 1);
361 ASSERT_EQ(traceConfig3->GetExcludedCategories()->size(), 2);
362 ASSERT_EQ(traceConfig3->GetSyntheticDelays()->size(), 3);
363 }
364
HWTEST_F_L0(PtTypesTest,ScriptTypeProfileCreateTest)365 HWTEST_F_L0(PtTypesTest, ScriptTypeProfileCreateTest)
366 {
367 std::unique_ptr<PtJson> ptJson = PtJson::CreateObject();
368 std::unique_ptr<PtJson> array = PtJson::CreateArray();
369 std::unique_ptr<PtJson> object = PtJson::CreateObject();
370 object->Add("offset", "test");
371 array->Push(object);
372 ptJson->Add("entries", array);
373 std::unique_ptr<ScriptTypeProfile> profile = ScriptTypeProfile::Create(*ptJson);
374 ASSERT_TRUE(!profile);
375 }
376
HWTEST_F_L0(PtTypesTest,TypeProfileEntryCreateTest)377 HWTEST_F_L0(PtTypesTest, TypeProfileEntryCreateTest)
378 {
379 std::unique_ptr<PtJson> ptJson = PtJson::CreateObject();
380 std::unique_ptr<PtJson> array = PtJson::CreateArray();
381 std::unique_ptr<PtJson> object = PtJson::CreateObject();
382 object->Add("name", 0);
383 array->Push(object);
384 ptJson->Add("types", array);
385 std::unique_ptr<TypeProfileEntry> entry = TypeProfileEntry::Create(*ptJson);
386 ASSERT_TRUE(!entry);
387 }
388
HWTEST_F_L0(PtTypesTest,ScriptCoverageCreateTest)389 HWTEST_F_L0(PtTypesTest, ScriptCoverageCreateTest)
390 {
391 std::unique_ptr<PtJson> ptJson = PtJson::CreateObject();
392 std::unique_ptr<PtJson> array = PtJson::CreateArray();
393 std::unique_ptr<PtJson> object = PtJson::CreateObject();
394 object->Add("functionName", 0);
395 array->Push(object);
396 ptJson->Add("functions", array);
397 std::unique_ptr<ScriptCoverage> coverage = ScriptCoverage::Create(*ptJson);
398 ASSERT_TRUE(!coverage);
399 }
400
HWTEST_F_L0(PtTypesTest,FunctionCoverageCreateTest)401 HWTEST_F_L0(PtTypesTest, FunctionCoverageCreateTest)
402 {
403 std::unique_ptr<PtJson> ptJson = PtJson::CreateObject();
404 std::unique_ptr<PtJson> array = PtJson::CreateArray();
405 std::unique_ptr<PtJson> object = PtJson::CreateObject();
406 object->Add("functionName", 0);
407 array->Push(object);
408 ptJson->Add("ranges", array);
409 std::unique_ptr<FunctionCoverage> coverage = FunctionCoverage::Create(*ptJson);
410 ASSERT_TRUE(!coverage);
411 }
412
HWTEST_F_L0(PtTypesTest,SymbolRemoteObjectTest)413 HWTEST_F_L0(PtTypesTest, SymbolRemoteObjectTest)
414 {
415 size_t size = 10;
416 const char *data = "SymbolRemoteObjectTest";
417 SymbolRemoteObject obj(ecmaVm, SymbolRef::New(ecmaVm, StringRef::NewFromUtf8(ecmaVm, (const char*)data, size)));
418 }
419
HWTEST_F_L0(PtTypesTest,DescriptionForObjectForDate)420 HWTEST_F_L0(PtTypesTest, DescriptionForObjectForDate)
421 {
422 double input = 123456789.0;
423 Local<DateRef> date = DateRef::New(ecmaVm, input);
424 std::string description = ObjectRemoteObject::DescriptionForObject(ecmaVm, date);
425 ASSERT_TRUE(description.find("GMT") != std::string::npos);
426 }
427
HWTEST_F_L0(PtTypesTest,DescriptionForObjectForPromise)428 HWTEST_F_L0(PtTypesTest, DescriptionForObjectForPromise)
429 {
430 Local<PromiseCapabilityRef> capability = PromiseCapabilityRef::New(ecmaVm);
431 Local<PromiseRef> promise = capability->GetPromise(ecmaVm);
432 std::string description = ObjectRemoteObject::DescriptionForObject(ecmaVm, promise);
433 ASSERT_TRUE(description == "Promise");
434 }
435
HWTEST_F_L0(PtTypesTest,PrivatePropertyDescriptorCreate)436 HWTEST_F_L0(PtTypesTest, PrivatePropertyDescriptorCreate)
437 {
438 std::unique_ptr<PtJson> ptJson = PtJson::CreateObject();
439 std::unique_ptr<PtJson> ptJson1 = PtJson::CreateObject();
440 bool value = true;
441 ptJson->Add("userCode", value);
442 std::unique_ptr<PrivatePropertyDescriptor> result = PrivatePropertyDescriptor::Create(*ptJson);
443 ASSERT_TRUE(result == nullptr);
444 value = false;
445 ptJson->Add("userCode1", value);
446 result = PrivatePropertyDescriptor::Create(*ptJson);
447 ASSERT_TRUE(result == nullptr);
448 int32_t value1 = 100;
449 ptJson1->Add("test", value1);
450 std::unique_ptr<PrivatePropertyDescriptor> result1 = PrivatePropertyDescriptor::Create(*ptJson1);
451 ASSERT_TRUE(result == nullptr);
452 int64_t value2 = 0;
453 ptJson1->Add("", value2);
454 result1 = PrivatePropertyDescriptor::Create(*ptJson1);
455 ASSERT_TRUE(result == nullptr);
456 std::unique_ptr<PtJson> ptJson2 = PtJson::CreateObject();
457 ptJson2->Add("name", value);
458 std::unique_ptr<PrivatePropertyDescriptor> result2 = PrivatePropertyDescriptor::Create(*ptJson2);
459 ASSERT_TRUE(result == nullptr);
460 ptJson2->Add("value", value1);
461 result2 = PrivatePropertyDescriptor::Create(*ptJson2);
462 ASSERT_TRUE(result == nullptr);
463 ptJson2->Add("get", value2);
464 result2 = PrivatePropertyDescriptor::Create(*ptJson2);
465 ASSERT_TRUE(result == nullptr);
466 value2 = 10;
467 ptJson2->Add("set", value2);
468 result2 = PrivatePropertyDescriptor::Create(*ptJson2);
469 ASSERT_TRUE(result == nullptr);
470 std::unique_ptr<PtJson> ptJson3 = PtJson::CreateObject();
471 ptJson3->Add("name", "test");
472 ptJson3->Add("value", ptJson);
473 ptJson3->Add("get", ptJson1);
474 ptJson3->Add("set", ptJson2);
475 std::unique_ptr<PrivatePropertyDescriptor> result3 = PrivatePropertyDescriptor::Create(*ptJson3);
476 ASSERT_TRUE(result == nullptr);
477 }
478
HWTEST_F_L0(PtTypesTest,CallArgumentToJson)479 HWTEST_F_L0(PtTypesTest, CallArgumentToJson)
480 {
481 CallArgument callArgument;
482 Local<JSValueRef> name = StringRef::NewFromUtf8(ecmaVm, "name");
483 callArgument.SetValue(name);
484 RemoteObjectId objectId(10);
485 callArgument.SetObjectId(objectId);
486 UnserializableValue value("test");
487 callArgument.SetUnserializableValue(value);
488 std::unique_ptr<PtJson> ret = callArgument.ToJson();
489 ASSERT_TRUE(ret != nullptr);
490 CallArgument callArgument1;
491 RemoteObjectId objectId1(20);
492 callArgument1.SetObjectId(objectId1);
493 ret = callArgument1.ToJson();
494 ASSERT_TRUE(ret != nullptr);
495 CallArgument callArgument2;
496 UnserializableValue value1("CallArgumentToJson");
497 callArgument2.ToJson();
498 ASSERT_TRUE(ret != nullptr);
499 }
500
HWTEST_F_L0(PtTypesTest,ScriptPositionToJson)501 HWTEST_F_L0(PtTypesTest, ScriptPositionToJson)
502 {
503 ScriptPosition position;
504 int32_t line = 10;
505 position.SetLine(line);
506 int32_t column = 8;
507 position.SetColumn(column);
508 std::unique_ptr<PtJson> ret = position.ToJson();
509 ASSERT_TRUE(ret != nullptr);
510 }
511
HWTEST_F_L0(PtTypesTest,SearchMatchCreate)512 HWTEST_F_L0(PtTypesTest, SearchMatchCreate)
513 {
514 std::unique_ptr<PtJson> ptJson = PtJson::CreateObject();
515 int32_t lineNumber = 10;
516 ptJson->Add("lineNumber", lineNumber);
517 std::string lineContent = "12";
518 ptJson->Add("lineContent", lineContent.c_str());
519 std::unique_ptr<SearchMatch> ret = SearchMatch::Create(*ptJson);
520 ASSERT_TRUE(ret != nullptr);
521
522 std::unique_ptr<PtJson> ptJson1 = PtJson::CreateObject();
523 std::string attribute = "32";
524 ptJson1->Add("lineNumber", attribute.c_str());
525 std::unique_ptr<SearchMatch> ret1 = SearchMatch::Create(*ptJson1);
526 ASSERT_TRUE(ret1 == nullptr);
527
528 std::unique_ptr<PtJson> ptJson2 = PtJson::CreateObject();
529 int32_t lineNumber2 = 14;
530 std::string lineContent2 = "12";
531 ptJson1->Add("lineNumber1", lineNumber2);
532 ptJson1->Add("lineContent2", lineContent2.c_str());
533 std::unique_ptr<SearchMatch> ret2 = SearchMatch::Create(*ptJson1);
534 ASSERT_TRUE(ret2 == nullptr);
535 }
536
HWTEST_F_L0(PtTypesTest,LocationRangeCreate)537 HWTEST_F_L0(PtTypesTest, LocationRangeCreate)
538 {
539 std::unique_ptr<PtJson> ptJson = PtJson::CreateObject();
540 std::unique_ptr<PtJson> start = PtJson::CreateObject();
541 std::unique_ptr<PtJson> end = PtJson::CreateObject();
542 std::string scriptId = "12";
543 int32_t lineNumber = 1;
544 int32_t columnNumber = 2;
545 start->Add("lineNumber", lineNumber);
546 start->Add("columnNumber", columnNumber);
547 end->Add("lineNumber", lineNumber + 1);
548 end->Add("columnNumber", columnNumber + 2);
549 ptJson->Add("scriptId", scriptId.c_str());
550 ptJson->Add("start", start);
551 ptJson->Add("end", end);
552 std::unique_ptr<LocationRange> ret = LocationRange::Create(*ptJson);
553 ASSERT_TRUE(ret != nullptr);
554 }
555
HWTEST_F_L0(PtTypesTest,LocationRangeCreateSwitch)556 HWTEST_F_L0(PtTypesTest, LocationRangeCreateSwitch)
557 {
558 std::unique_ptr<PtJson> ptJson = PtJson::CreateObject();
559 std::unique_ptr<PtJson> start = PtJson::CreateObject();
560 std::unique_ptr<PtJson> end = PtJson::CreateObject();
561 std::string scriptId = "12";
562 int32_t lineNumber = 1;
563 int32_t columnNumber = 2;
564 start->Add("lineNumber1", lineNumber);
565 start->Add("columnNumber1", columnNumber);
566 end->Add("lineNumber1", lineNumber + 1);
567 end->Add("columnNumber1", columnNumber + 2);
568 ptJson->Add("scriptId1", scriptId.c_str());
569 ptJson->Add("start", start);
570 ptJson->Add("end", end);
571 std::unique_ptr<LocationRange> ret = LocationRange::Create(*ptJson);
572 ASSERT_TRUE(ret == nullptr);
573 }
574
HWTEST_F_L0(PtTypesTest,LocationRangeCreateSwitchFail)575 HWTEST_F_L0(PtTypesTest, LocationRangeCreateSwitchFail)
576 {
577 std::unique_ptr<PtJson> ptJson = PtJson::CreateObject();
578 std::unique_ptr<PtJson> start = PtJson::CreateObject();
579 std::unique_ptr<PtJson> end = PtJson::CreateObject();
580 std::string scriptId = "12";
581 int32_t lineNumber = 1;
582 int32_t columnNumber = 2;
583 start->Add("lineNumber1", lineNumber);
584 start->Add("columnNumber1", columnNumber);
585 end->Add("lineNumber1", lineNumber + 1);
586 end->Add("columnNumber1", columnNumber + 2);
587 ptJson->Add("scriptId1", scriptId.c_str());
588 ptJson->Add("start1", start);
589 ptJson->Add("end1", end);
590 std::unique_ptr<LocationRange> ret = LocationRange::Create(*ptJson);
591 ASSERT_TRUE(ret == nullptr);
592 }
593
HWTEST_F_L0(PtTypesTest,RuntimeCallFrameCreate)594 HWTEST_F_L0(PtTypesTest, RuntimeCallFrameCreate)
595 {
596 std::unique_ptr<PtJson> ptJson = PtJson::CreateObject();
597 std::string functionName = "RuntimeCallFrameCreate";
598 std::string scriptId = "scriptId";
599 std::string url = "url";
600 int32_t lineNumber = 2;
601 int32_t columnNumber = 10;
602 ptJson->Add("functionName", functionName.c_str());
603 ptJson->Add("moduleName", functionName.c_str());
604 ptJson->Add("scriptId", scriptId.c_str());
605 ptJson->Add("url", url.c_str());
606 ptJson->Add("lineNumber", lineNumber);
607 ptJson->Add("columnNumber", columnNumber);
608 std::unique_ptr<RuntimeCallFrame> ret = RuntimeCallFrame::Create(*ptJson);
609 ASSERT_TRUE(ret != nullptr);
610 }
611
HWTEST_F_L0(PtTypesTest,RuntimeCallFrameCreateFailSwitch)612 HWTEST_F_L0(PtTypesTest, RuntimeCallFrameCreateFailSwitch)
613 {
614 std::unique_ptr<PtJson> ptJson = PtJson::CreateObject();
615 std::string functionName = "RuntimeCallFrameCreate";
616 std::string scriptId = "scriptId";
617 std::string url = "url";
618 int32_t lineNumber = 2;
619 int32_t columnNumber = 10;
620 ptJson->Add("functionName1", functionName.c_str());
621 ptJson->Add("moduleName1", functionName.c_str());
622 ptJson->Add("scriptId1", scriptId.c_str());
623 ptJson->Add("url1", url.c_str());
624 ptJson->Add("lineNumber1", lineNumber);
625 ptJson->Add("columnNumber1", columnNumber);
626 std::unique_ptr<RuntimeCallFrame> ret = RuntimeCallFrame::Create(*ptJson);
627 ASSERT_TRUE(ret == nullptr);
628 }
629
HWTEST_F_L0(PtTypesTest,SamplingHeapProfileNodeCreate)630 HWTEST_F_L0(PtTypesTest, SamplingHeapProfileNodeCreate)
631 {
632 std::unique_ptr<PtJson> ptJson = PtJson::CreateObject();
633 std::unique_ptr<PtJson> callFrame = PtJson::CreateObject();
634 std::unique_ptr<PtJson> array = PtJson::CreateArray();
635 std::unique_ptr<PtJson> object = PtJson::CreateObject();
636 callFrame->Add("callFrame", "test");
637 ptJson->Add("callFrame", callFrame);
638 object->Add("test", 0);
639 array->Push(object);
640 ptJson->Add("children", array);
641 std::unique_ptr<SamplingHeapProfileNode> ret = SamplingHeapProfileNode::Create(*ptJson);
642 ASSERT_TRUE(ret == nullptr);
643 }
644
HWTEST_F_L0(PtTypesTest,SamplingHeapProfileCreate)645 HWTEST_F_L0(PtTypesTest, SamplingHeapProfileCreate)
646 {
647 std::unique_ptr<PtJson> ptJson = PtJson::CreateObject();
648 std::unique_ptr<PtJson> head = PtJson::CreateObject();
649 std::unique_ptr<PtJson> array = PtJson::CreateArray();
650 std::unique_ptr<PtJson> object = PtJson::CreateObject();
651 head->Add("head", "headTest");
652 ptJson->Add("head", head);
653 object->Add("test", 0);
654 array->Push(object);
655 ptJson->Add("samples", array);
656 std::unique_ptr<SamplingHeapProfile> ret = SamplingHeapProfile::Create(*ptJson);
657 ASSERT_TRUE(ret == nullptr);
658 }
659
HWTEST_F_L0(PtTypesTest,ExceptionDetailsCreate)660 HWTEST_F_L0(PtTypesTest, ExceptionDetailsCreate)
661 {
662 std::unique_ptr<PtJson> ptJson = PtJson::CreateObject();
663 std::unique_ptr<PtJson> exception = PtJson::CreateObject();
664 exception->Add("exception", "test");
665 ptJson->Add("exception", exception);
666 std::unique_ptr<ExceptionDetails> ret = ExceptionDetails::Create(*ptJson);
667 ASSERT_TRUE(ret == nullptr);
668 }
669
670
HWTEST_F_L0(PtTypesTest,ProfileToJsonTest)671 HWTEST_F_L0(PtTypesTest, ProfileToJsonTest)
672 {
673 Profile profile;
674 std::vector<int32_t> samples {1, 2, 3}; // 1:element 2:element 3:element
675 std::vector<int32_t> timeDeltas {1, 2, 3}; // 1:element 2:element 3:element
676 profile.SetSamples(samples);
677 profile.SetTimeDeltas(timeDeltas);
678 std::unique_ptr<PtJson> result = profile.ToJson();
679 ASSERT_TRUE(result);
680 }
681
HWTEST_F_L0(PtTypesTest,ProfileFromProfileInfoTest)682 HWTEST_F_L0(PtTypesTest, ProfileFromProfileInfoTest)
683 {
684 ProfileInfo info;
685 info.samples.push_back(1);
686 info.samples.push_back(2);
687 info.timeDeltas.push_back(1);
688 info.timeDeltas.push_back(2);
689 std::unique_ptr<Profile> result = Profile::FromProfileInfo(info);
690 ASSERT_TRUE(result);
691 }
692
HWTEST_F_L0(PtTypesTest,ProfileNodeToJsonTest)693 HWTEST_F_L0(PtTypesTest, ProfileNodeToJsonTest)
694 {
695 std::unique_ptr<PtJson> ptJson = PtJson::CreateObject();
696 ProfileNode node;
697 std::vector<int32_t> children {0, 1, 2, 3}; // 1: element 2:element, 3:element
698 std::unique_ptr<PositionTickInfo> positionTickInfo = std::make_unique<PositionTickInfo>();
699 std::unique_ptr<RuntimeCallFrame> callFrame = std::make_unique<RuntimeCallFrame>();
700 positionTickInfo->SetLine(123);
701 positionTickInfo->SetTicks(123);
702 std::vector<std::unique_ptr<PositionTickInfo>> positionTicks;
703 positionTicks.push_back(std::move(positionTickInfo));
704 node.SetChildren(children);
705 node.SetPositionTicks(std::move(positionTicks));
706 node.SetCallFrame(std::move(callFrame));
707 std::unique_ptr<PtJson> result = node.ToJson();
708 ASSERT_TRUE(result);
709 ProfileNode node1;
710 std::unique_ptr<RuntimeCallFrame> callFrame1 = std::make_unique<RuntimeCallFrame>();
711 node1.SetCallFrame(std::move(callFrame1));
712 std::unique_ptr<PtJson> result1 = node1.ToJson();
713 ASSERT_TRUE(result1);
714 }
715
HWTEST_F_L0(PtTypesTest,ProfileNodeFromCpuProfileNodeTest)716 HWTEST_F_L0(PtTypesTest, ProfileNodeFromCpuProfileNodeTest)
717 {
718 CpuProfileNode cpuProfileNode;
719 cpuProfileNode.children.push_back(0);
720 cpuProfileNode.children.push_back(1); // 1: element
721 std::unique_ptr<ProfileNode> result = ProfileNode::FromCpuProfileNode(cpuProfileNode);
722 ASSERT_TRUE(result);
723 }
724
HWTEST_F_L0(PtTypesTest,PrivatePropertyDescriptorToJsonTest)725 HWTEST_F_L0(PtTypesTest, PrivatePropertyDescriptorToJsonTest)
726 {
727 PrivatePropertyDescriptor descriptor;
728 std::unique_ptr<RemoteObject> value = std::make_unique<RemoteObject>();
729 std::unique_ptr<RemoteObject> get = std::make_unique<RemoteObject>();
730 std::unique_ptr<RemoteObject> set = std::make_unique<RemoteObject>();
731 descriptor.SetValue(std::move(value));
732 descriptor.SetGet(std::move(get));
733 descriptor.SetSet(std::move(set));
734 std::unique_ptr<PtJson> result = descriptor.ToJson();
735 ASSERT_TRUE(result);
736 }
737
HWTEST_F_L0(PtTypesTest,PropertyDescriptorFromPropertyTest)738 HWTEST_F_L0(PtTypesTest, PropertyDescriptorFromPropertyTest)
739 {
740 Local<SymbolRef> symbol = SymbolRef::New(ecmaVm, StringRef::NewFromUtf8(ecmaVm, "test"));
741 PropertyAttribute property;
742 property.SetGetter(StringRef::NewFromUtf8(ecmaVm, "test"));
743 property.SetSetter(StringRef::NewFromUtf8(ecmaVm, "test"));
744 std::unique_ptr<panda::ecmascript::tooling::PropertyDescriptor> result =
745 panda::ecmascript::tooling::PropertyDescriptor::FromProperty(ecmaVm, symbol, property);
746 ASSERT_TRUE(result);
747 }
748
HWTEST_F_L0(PtTypesTest,PtEventsGetReasonString)749 HWTEST_F_L0(PtTypesTest, PtEventsGetReasonString)
750 {
751 PauseReason reason = static_cast<PauseReason>(50);
752 std::string ret = Paused::GetReasonString(reason);
753 ASSERT_TRUE(ret.empty());
754 }
755
HWTEST_F_L0(PtTypesTest,LocationRangeToJsonTest)756 HWTEST_F_L0(PtTypesTest, LocationRangeToJsonTest)
757 {
758 LocationRange range;
759 std::unique_ptr<ScriptPosition> start = std::make_unique<ScriptPosition>();
760 std::unique_ptr<ScriptPosition> end = std::make_unique<ScriptPosition>();
761 range.SetStart(std::move(start));
762 range.SetEnd(std::move(end));
763 std::unique_ptr<PtJson> result = range.ToJson();
764 ASSERT_TRUE(result);
765 }
766
HWTEST_F_L0(PtTypesTest,BreakLocationToJsonTest)767 HWTEST_F_L0(PtTypesTest, BreakLocationToJsonTest)
768 {
769 BreakLocation location;
770 location.SetColumn(0);
771 location.SetType("test");
772 std::unique_ptr<PtJson> result = location.ToJson();
773 ASSERT_TRUE(result);
774 }
775
HWTEST_F_L0(PtTypesTest,CallFrameCreateTest)776 HWTEST_F_L0(PtTypesTest, CallFrameCreateTest)
777 {
778 std::unique_ptr<PtJson> ptJson = PtJson::CreateObject();
779 std::unique_ptr<PtJson> array = PtJson::CreateArray();
780 std::unique_ptr<PtJson> object = PtJson::CreateObject();
781 object->Add("type", 0);
782 array->Push(object);
783 ptJson->Add("scopeChain", array);
784 std::unique_ptr<CallFrame> result = CallFrame::Create(*ptJson);
785 ASSERT_TRUE(!result);
786 }
787
HWTEST_F_L0(PtTypesTest,ProfileCreate)788 HWTEST_F_L0(PtTypesTest, ProfileCreate)
789 {
790 std::unique_ptr<PtJson> ptJson = PtJson::CreateObject();
791 std::unique_ptr<PtJson> array = PtJson::CreateArray();
792 std::unique_ptr<PtJson> object = PtJson::CreateObject();
793 std::unique_ptr<PtJson> object1 = PtJson::CreateObject();
794 object->Add("type", 0);
795 array->Push(object);
796 ptJson->Add("nodes", array);
797 std::unique_ptr<Profile> result = Profile::Create(*ptJson);
798 ASSERT_TRUE(!result);
799 std::unique_ptr<PtJson> ptJson1 = PtJson::CreateObject();
800 ptJson1->Add("samples", 0);
801 ptJson1->Add("timeDeltas", 0);
802 std::unique_ptr<Profile> result1 = Profile::Create(*ptJson1);
803 ASSERT_TRUE(!result1);
804 }
805
HWTEST_F_L0(PtTypesTest,ProfileNodeCreate)806 HWTEST_F_L0(PtTypesTest, ProfileNodeCreate)
807 {
808 std::unique_ptr<PtJson> ptJson = PtJson::CreateObject();
809 std::string attribute = "test";
810 std::unique_ptr<PtJson> object = PtJson::CreateObject();
811 object->Add("functionName", 0);
812 ptJson->Add("callFrame", object);
813 ptJson->Add("hitCount", attribute.c_str());
814 ptJson->Add("children", attribute.c_str());
815 ptJson->Add("positionTicks", attribute.c_str());
816 ptJson->Add("deoptReason", 0);
817 std::unique_ptr<ProfileNode> result = ProfileNode::Create(*ptJson);
818 ASSERT_TRUE(!result);
819 std::unique_ptr<PtJson> ptJson1 = PtJson::CreateObject();
820 std::unique_ptr<PtJson> object1 = PtJson::CreateObject();
821 std::unique_ptr<PtJson> array = PtJson::CreateArray();
822 object1->Add("attribute", attribute.c_str());
823 array->Push(object1);
824 ptJson1->Add("positionTicks", array);
825 std::unique_ptr<ProfileNode> result1 = ProfileNode::Create(*ptJson1);
826 ASSERT_TRUE(!result1);
827 }
828
HWTEST_F_L0(PtTypesTest,LocationCreate)829 HWTEST_F_L0(PtTypesTest, LocationCreate)
830 {
831 std::unique_ptr<PtJson> ptJson = PtJson::CreateObject();
832 std::string attribute = "test";
833 ptJson->Add("columnNumber", attribute.c_str());
834 std::unique_ptr<Location> result = Location::Create(*ptJson);
835 ASSERT_TRUE(!result);
836 }
837
HWTEST_F_L0(PtTypesTest,PropertyDescriptorCreate)838 HWTEST_F_L0(PtTypesTest, PropertyDescriptorCreate)
839 {
840 std::unique_ptr<PtJson> ptJson = PtJson::CreateObject();
841 std::unique_ptr<PtJson> get = PtJson::CreateObject();
842 std::unique_ptr<PtJson> set = PtJson::CreateObject();
843 std::unique_ptr<PtJson> symbol = PtJson::CreateObject();
844 std::string attribute = "test";
845 get->Add("type", attribute.c_str());
846 set->Add("type", attribute.c_str());
847 symbol->Add("type", attribute.c_str());
848 ptJson->Add("get", get);
849 ptJson->Add("set", set);
850 ptJson->Add("symbol", symbol);
851 std::unique_ptr<tooling::PropertyDescriptor> result = tooling::PropertyDescriptor::Create(*ptJson);
852 ASSERT_TRUE(!result);
853 }
854
HWTEST_F_L0(PtTypesTest,SamplingHeapProfileFromSamplingInfo)855 HWTEST_F_L0(PtTypesTest, SamplingHeapProfileFromSamplingInfo)
856 {
857 SamplingInfo samplingInfo;
858 samplingInfo.head_.selfSize_ = 0;
859 samplingInfo.head_.id_ = 0;
860 samplingInfo.head_.callFrameInfo_.codeType_ = "codetype";
861 samplingInfo.head_.callFrameInfo_.columnNumber_ = 21;
862 samplingInfo.head_.callFrameInfo_.functionName_ = "TestSampling";
863 samplingInfo.head_.callFrameInfo_.lineNumber_ = 221;
864 samplingInfo.head_.callFrameInfo_.scriptId_ = 1;
865 samplingInfo.head_.callFrameInfo_.url_ = "url";
866 Sample sampleInfo(12024, 19, 1, 2);
867 samplingInfo.samples_.push_back(sampleInfo);
868 std::unique_ptr<SamplingHeapProfile> profile = SamplingHeapProfile::FromSamplingInfo(&samplingInfo);
869 ASSERT_TRUE(profile != nullptr);
870 SamplingHeapProfileNode *nodeInfo = profile->GetHead();
871 int32_t selfSize = nodeInfo->GetSelfSize();
872 ASSERT_TRUE(selfSize == samplingInfo.head_.selfSize_);
873 int32_t id = nodeInfo->GetId();
874 ASSERT_TRUE(id == samplingInfo.head_.id_);
875 RuntimeCallFrame *callFrame = nodeInfo->GetCallFrame();
876 const std::string functionName = callFrame->GetFunctionName();
877 ASSERT_TRUE(functionName == samplingInfo.head_.callFrameInfo_.functionName_);
878 const std::string url = callFrame->GetUrl();
879 ASSERT_TRUE(url == samplingInfo.head_.callFrameInfo_.url_);
880 int32_t lineNumber = callFrame->GetLineNumber();
881 ASSERT_TRUE(lineNumber == samplingInfo.head_.callFrameInfo_.lineNumber_);
882 int32_t columnNumber = callFrame->GetColumnNumber();
883 ASSERT_TRUE(columnNumber == samplingInfo.head_.callFrameInfo_.columnNumber_);
884 const std::vector<std::unique_ptr<SamplingHeapProfileSample>> *sampData = profile->GetSamples();
885 int32_t nodeId = sampData->data()->get()->GetNodeId();
886 ASSERT_TRUE(nodeId == sampleInfo.nodeId_);
887 int32_t size = sampData->data()->get()->GetSize();
888 ASSERT_TRUE(size == (sampleInfo.size_ * sampleInfo.count_));
889 int64_t ordinal = sampData->data()->get()->GetOrdinal();
890 ASSERT_TRUE(ordinal == sampleInfo.ordinal_);
891 }
892
HWTEST_F_L0(PtTypesTest,SamplingHeapProfileTransferHead)893 HWTEST_F_L0(PtTypesTest, SamplingHeapProfileTransferHead)
894 {
895 SamplingNode allocationNode;
896 allocationNode.selfSize_ = 0;
897 allocationNode.id_ = 0;
898 allocationNode.callFrameInfo_.codeType_ = "codetype";
899 allocationNode.callFrameInfo_.columnNumber_ = 21;
900 allocationNode.callFrameInfo_.functionName_ = "TestSampling";
901 allocationNode.callFrameInfo_.lineNumber_ = 221;
902 allocationNode.callFrameInfo_.scriptId_ = 1;
903 allocationNode.callFrameInfo_.url_ = "url";
904 std::unique_ptr<SamplingHeapProfileNode> headInfo = SamplingHeapProfile::TransferHead(&allocationNode);
905 ASSERT_TRUE(headInfo != nullptr);
906 int32_t selfSize = headInfo->GetSelfSize();
907 ASSERT_TRUE(selfSize == allocationNode.selfSize_);
908 int32_t id = headInfo->GetId();
909 ASSERT_TRUE(id == allocationNode.id_);
910 RuntimeCallFrame *callFrame = headInfo->GetCallFrame();
911 const std::string functionName = callFrame->GetFunctionName();
912 ASSERT_TRUE(functionName == allocationNode.callFrameInfo_.functionName_);
913 const std::string url = callFrame->GetUrl();
914 ASSERT_TRUE(url == allocationNode.callFrameInfo_.url_);
915 int32_t lineNumber = callFrame->GetLineNumber();
916 ASSERT_TRUE(lineNumber == allocationNode.callFrameInfo_.lineNumber_);
917 int32_t columnNumber = callFrame->GetColumnNumber();
918 ASSERT_TRUE(columnNumber == allocationNode.callFrameInfo_.columnNumber_);
919 }
920
HWTEST_F_L0(PtTypesTest,DescriptionForObjectTest)921 HWTEST_F_L0(PtTypesTest, DescriptionForObjectTest)
922 {
923 Local<WeakMapRef> weakmap = WeakMapRef::New(ecmaVm);
924 std::string description = ObjectRemoteObject::DescriptionForObject(ecmaVm, weakmap);
925 ASSERT_TRUE(description.find("WeakMap") != std::string::npos);
926
927 Local<MapRef> map = MapRef::New(ecmaVm);
928 Local<MapIteratorRef> mapiterator = MapIteratorRef::New(ecmaVm, map);
929 description = ObjectRemoteObject::DescriptionForObject(ecmaVm, mapiterator);
930 ASSERT_TRUE(description.find("MapIterator") != std::string::npos);
931
932 Local<SetRef> set = SetRef::New(ecmaVm);
933 Local<SetIteratorRef> setiterator = SetIteratorRef::New(ecmaVm, set);
934 description = ObjectRemoteObject::DescriptionForObject(ecmaVm, setiterator);
935 ASSERT_TRUE(description.find("SetIterator") != std::string::npos);
936
937 size_t size = 10;
938 Local<NativePointerRef> nativepointer = NativePointerRef::New(ecmaVm, ecmaVm, size);
939 description = ObjectRemoteObject::DescriptionForObject(ecmaVm, nativepointer);
940 std::cout << description << std::endl;
941 ASSERT_TRUE(description.find("External") != std::string::npos);
942 }
943
HWTEST_F_L0(PtTypesTest,FromTaggedTest)944 HWTEST_F_L0(PtTypesTest, FromTaggedTest)
945 {
946 double input = 123456789.0;
947 Local<DateRef> date = DateRef::New(ecmaVm, input);
948 std::unique_ptr<RemoteObject> remoteObject = RemoteObject::FromTagged(ecmaVm, date);
949 std::string description = remoteObject->GetDescription();
950 ASSERT_TRUE(description.find("GMT") != std::string::npos);
951
952 Local<WeakMapRef> weakmap = WeakMapRef::New(ecmaVm);
953 remoteObject = RemoteObject::FromTagged(ecmaVm, weakmap);
954 description = remoteObject->GetDescription();
955 ASSERT_TRUE(description.find("WeakMap") != std::string::npos);
956
957 Local<MapRef> map = MapRef::New(ecmaVm);
958 Local<MapIteratorRef> mapiterator = MapIteratorRef::New(ecmaVm, map);
959 remoteObject = RemoteObject::FromTagged(ecmaVm, mapiterator);
960 description = remoteObject->GetDescription();
961 ASSERT_TRUE(description.find("MapIterator") != std::string::npos);
962
963 Local<SetRef> set = SetRef::New(ecmaVm);
964 Local<SetIteratorRef> setiterator = SetIteratorRef::New(ecmaVm, set);
965 remoteObject = RemoteObject::FromTagged(ecmaVm, setiterator);
966 description = remoteObject->GetDescription();
967 ASSERT_TRUE(description.find("SetIterator") != std::string::npos);
968
969 Local<PromiseCapabilityRef> capability = PromiseCapabilityRef::New(ecmaVm);
970 Local<PromiseRef> promise = capability->GetPromise(ecmaVm);
971 remoteObject = RemoteObject::FromTagged(ecmaVm, promise);
972 description = remoteObject->GetDescription();
973 ASSERT_TRUE(description.find("Promise") != std::string::npos);
974
975 size_t size = 10;
976 Local<NativePointerRef> nativepointer = NativePointerRef::New(ecmaVm, ecmaVm, size);
977 remoteObject = RemoteObject::FromTagged(ecmaVm, nativepointer);
978 description = remoteObject->GetDescription();
979 ASSERT_TRUE(description.find("External") != std::string::npos);
980 }
981
HWTEST_F_L0(PtTypesTest,NativeRangeCreateTest)982 HWTEST_F_L0(PtTypesTest, NativeRangeCreateTest)
983 {
984 std::string msg;
985 std::unique_ptr<NativeRange> nativeRange;
986
987 msg = std::string() + R"({})";
988 nativeRange = NativeRange::Create(DispatchRequest(msg).GetParams());
989 EXPECT_EQ(nativeRange, nullptr);
990
991 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"start":20,"end":40}})";
992 nativeRange = NativeRange::Create(DispatchRequest(msg).GetParams());
993 ASSERT_TRUE(nativeRange != nullptr);
994 }
995
HWTEST_F_L0(PtTypesTest,BreakpointInfoCreateTest)996 HWTEST_F_L0(PtTypesTest, BreakpointInfoCreateTest)
997 {
998 std::string msg;
999 std::unique_ptr<BreakpointInfo> breakpointInfo;
1000
1001 msg = std::string() + R"({})";
1002 breakpointInfo = BreakpointInfo::Create(DispatchRequest(msg).GetParams());
1003 EXPECT_EQ(breakpointInfo, nullptr);
1004
1005 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"condition":"Test","urlRegex":"Test"}})";
1006 breakpointInfo = BreakpointInfo::Create(DispatchRequest(msg).GetParams());
1007 EXPECT_EQ(breakpointInfo, nullptr);
1008
1009 msg = std::string() + R"({"id":0,"method":"Debugger.Test",
1010 "params":{"scriptHash":"Test", "restrictToFunction": true}})";
1011 breakpointInfo = BreakpointInfo::Create(DispatchRequest(msg).GetParams());
1012 EXPECT_EQ(breakpointInfo, nullptr);
1013
1014 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"lineNumber":1,"columnNumber":2,"url":"Test",
1015 "condition":"Test", "urlRegex":"Test", "scriptHash":"Test", "restrictToFunction": true}})";
1016 breakpointInfo = BreakpointInfo::Create(DispatchRequest(msg).GetParams());
1017 std::unique_ptr<PtJson> resultJson = breakpointInfo->ToJson();
1018 ASSERT_TRUE(resultJson != nullptr);
1019
1020 msg = std::string() + R"({"id":0,"method":"Debugger.Test",
1021 "params":{"lineNumber":1, "columnNumber":2, "url":"Test"}})";
1022 breakpointInfo = BreakpointInfo::Create(DispatchRequest(msg).GetParams());
1023 resultJson = breakpointInfo->ToJson();
1024 ASSERT_TRUE(resultJson != nullptr);
1025 }
1026
HWTEST_F_L0(PtTypesTest,BreakpointReturnInfoCreateTest)1027 HWTEST_F_L0(PtTypesTest, BreakpointReturnInfoCreateTest)
1028 {
1029 std::string msg;
1030 std::unique_ptr<BreakpointReturnInfo> breakpointReturnInfo;
1031
1032 msg = std::string() + R"({})";
1033 breakpointReturnInfo = BreakpointReturnInfo::Create(DispatchRequest(msg).GetParams());
1034 EXPECT_EQ(breakpointReturnInfo, nullptr);
1035
1036 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"lineNumber":20,"columnNumber":40}})";
1037 breakpointReturnInfo = BreakpointReturnInfo::Create(DispatchRequest(msg).GetParams());
1038 ASSERT_TRUE(breakpointReturnInfo != nullptr);
1039
1040 msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"id":"Test","scriptId":5}})";
1041 breakpointReturnInfo = BreakpointReturnInfo::Create(DispatchRequest(msg).GetParams());
1042 EXPECT_EQ(breakpointReturnInfo, nullptr);
1043 }
1044 } // namespace panda::test
1045