• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 <string>
17 #include <map>
18 #include <gtest/gtest.h>
19 #include "secodeFuzz.h"
20 #include "common.h"
21 #include "CommandParse.h"
22 #include "CommandLineInterface.h"
23 #define private public
24 #include "CommandParser.h"
25 using namespace std;
26 using namespace fuzztest;
27 
28 namespace {
29 std::map<std::string, std::string> richDataMap = {
30     {"BackClicked", ""},
31     {"inspector", ""},
32     {"inspectorDefault", ""},
33     {"ColorMode", R"({"ColorMode":"dark"})"},
34     {"Orientation", R"({"Orientation":"landscape","screenDensity":480,"width":2340,
35         "height":1080,"originWidth":2340,"originHeight":1080})"},
36     {"ResolutionSwitch", R"({"originWidth":1080,"originHeight":2340,"width":1080,
37         "height":2340,"screenDensity":480})"},
38     {"CurrentRouter", ""},
39     {"ReloadRuntimePage", R"({"ReloadRuntimePage":"aaa"})"},
40     {"FontSelect", R"({"FontSelect":true})"},
41     {"MemoryRefresh", R"({"jsCode":"UEFOREEAAAAAAAAAAAAAA+wDAADEAAAAFQAAAAMoDAAA=\r\n",
42         "propertyVariable":[],"viewID":"1","offset":{"line":11,"column":9},
43         "globalVariable":[],"slot":0,"type":"UpdateComponent","parentID":2})"},
44     {"LoadDocument", R"({"url":"pages/Index","className":"Index","previewParam":{"width":1080,
45         "height":2340,"locale":"zh_CN","colorMode":"light","orientation":"portrait",
46         "deviceType":"phone","dpi":480}})"},
47     {"FastPreviewMsg", ""},
48     {"DropFrame", R"({"frequency":1000})"},
49     {"KeyPress", R"({"isInputMethod":false,"keyCode":2033,"keyAction":0,"pressedCodes":[2033]})"},
50     {"PointEvent", R"({"x":365,"y":1071,"duration":"","button":-1,"action": 3,"axisValues":[0,0,0,0],
51         "sourceType":1,"sourceTool": 7,"pressedButtons":[0,1]})"},
52     {"FoldStatus", R"({"FoldStatus":"fold","width":1080,"height":2504})"},
53     {"AvoidArea", R"({"topRect":{"posX":0,"posY":0,"width":2340,"height":117},"bottomRect":{"posX":
54         0,"posY":0,"width":0,"height":0},"leftRect":{"posX":0,"posY":0,"width":0,"height":0},
55         "rightRect":{"posX":0,"posY":0,"width":2340,"height":84}})"},
56     {"AvoidAreaChanged", ""}
57 };
58 
TEST(RichCommandParseFuzzTest,test_command)59 TEST(RichCommandParseFuzzTest, test_command)
60 {
61     std::cout << "--> RichCommandParseFuzzTest for rich start <--" << std::endl;
62     DT_FUZZ_START(0, TEST_TIMES, (char*)"RichCommandParseFuzzTest", 0)
63     {
64         CommandParse parse;
65         CommandParser::GetInstance().deviceType = "phone";
66         parse.CreateAndExecuteCommand(richDataMap);
67     }
68     DT_FUZZ_END()
69     printf("end ---- RichCommandParseFuzzTest\r\n");
70     if (DT_GetIsPass() == 0) {
71         printf("test RichCommandParseFuzzTest is not ok\r\n");
72     } else {
73         printf("test RichCommandParseFuzzTest is ok\r\n");
74     }
75     std::cout << "--> RichCommandParseFuzzTest for rich end <--" << std::endl;
76 }
77 }