• 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 #include <string>
16 #include "gtest/gtest.h"
17 #define private public
18 #include "CommandLineFactory.h"
19 #include "CommandParser.h"
20 using namespace std;
21 
22 namespace {
TEST(CommandLineFactoryTest,DefaultConstructorBehaviorTest)23     TEST(CommandLineFactoryTest, DefaultConstructorBehaviorTest)
24     {
25         CommandLineFactory factory;
26         factory.InitCommandMap();
27         EXPECT_TRUE(factory.typeMap.size() > 0);
28     }
29 
TEST(CommandLineFactoryTest,InitCommandMapTest)30     TEST(CommandLineFactoryTest, InitCommandMapTest)
31     {
32         string deviceType = "phone";
33         CommandParser::GetInstance().deviceType = deviceType;
34         CommandLineFactory::InitCommandMap();
35         EXPECT_TRUE(CommandLineFactory::typeMap.size() > 0);
36     }
37 
TEST(CommandLineFactoryTest,CreateCommandLineTest)38     TEST(CommandLineFactoryTest, CreateCommandLineTest)
39     {
40         std::string commandName = "ColorMode";
41         std::string jsonStr = R"({"ColorMode":"dark"})";
42         Json2::Value jsonData = JsonReader::ParseJsonData2(jsonStr);
43         std::unique_ptr<LocalSocket> socket = std::make_unique<LocalSocket>();
44 
45         CommandLine::CommandType commandType = CommandLine::CommandType::SET;
46         std::string commandNameNull = "ColorMode1";
47         std::unique_ptr<CommandLine> commandLineNull =
48             CommandLineFactory::CreateCommandLine(commandNameNull, commandType, jsonData, *socket);
49         EXPECT_TRUE(commandLineNull == nullptr);
50 
51         std::unique_ptr<CommandLine> commandLine =
52             CommandLineFactory::CreateCommandLine(commandName, commandType, jsonData, *socket);
53         EXPECT_FALSE(commandLine == nullptr);
54     }
55 }
56