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