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