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 "CommandParse.h"
20 #include "secodeFuzz.h"
21 #include "CommandParse.h"
22 #include "common.h"
23 #include "CommandLineInterface.h"
24 #define private public
25 #include "CommandParser.h"
26 using namespace std;
27 using namespace fuzztest;
28
29 namespace {
30 std::map<std::string, std::string> liteDataMap = {
31 {"Power", R"({"Power":1.0})"},
32 {"Volume", R"({"Volume":90})"},
33 {"Barometer", R"({"Barometer":1.0})"},
34 {"Location", R"({"latitude":"10.9023142","longitude":"56.3043242"})"},
35 {"KeepScreenOnState", R"({"KeepScreenOnState":true})"},
36 {"WearingState", R"({"WearingState":true})"},
37 {"BrightnessMode", R"({"BrightnessMode":1})"},
38 {"ChargeMode", R"({"ChargeMode":1})"},
39 {"Brightness", R"({"Brightness":100})"},
40 {"HeartRate", R"({"HeartRate":100})"},
41 {"StepCount", R"({"StepCount":10025})"},
42 {"DistributedCommunications", R"({"DeviceId":"68-05-CA-90-9A-66","bundleName":"com.test.demo",
43 "abilityName":"hello","message":"{ action:'GET_WEATHER',city:'HangZhou' }"})"},
44 {"CrownRotate", R"({"rotate":150})"}
45 };
46
TEST(LiteCommandParseFuzzTest,test_command)47 TEST(LiteCommandParseFuzzTest, test_command)
48 {
49 std::cout << "--> LiteCommandParseFuzzTest for rich start <--" << std::endl;
50 DT_FUZZ_START(0, TEST_TIMES, (char*)"LiteCommandParseFuzzTest", 0)
51 {
52 CommandParse parse;
53 CommandParser::GetInstance().deviceType = "liteWearable";
54 parse.CreateAndExecuteCommand(liteDataMap);
55 }
56 DT_FUZZ_END()
57 printf("end ---- LiteCommandParseFuzzTest\r\n");
58 if (DT_GetIsPass() == 0) {
59 printf("test LiteCommandParseFuzzTest is not ok\r\n");
60 } else {
61 printf("test LiteCommandParseFuzzTest is ok\r\n");
62 }
63 std::cout << "--> LiteCommandParseFuzzTest for rich end <--" << std::endl;
64 }
65 }