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 <map> 17 #include "gtest/gtest.h" 18 #define private public 19 #define protected public 20 #include "CommandLineFactory.h" 21 #include "CommandParser.h" 22 #include "JsAppImpl.h" 23 #include "MockGlobalResult.h" 24 #include "VirtualScreenImpl.h" 25 #include "KeyInputImpl.h" 26 #include "MouseInputImpl.h" 27 #include "SharedData.h" 28 #include "MouseWheelImpl.h" 29 #include "Interrupter.h" 30 using namespace std; 31 32 namespace { 33 class CommandLineTest : public ::testing::Test { 34 public: CommandLineTest()35 CommandLineTest() {} ~CommandLineTest()36 ~CommandLineTest() {} 37 static std::unique_ptr<LocalSocket> socket; 38 protected: SetUpTestCase()39 static void SetUpTestCase() 40 { 41 socket = std::make_unique<LocalSocket>(); 42 SharedData<bool>(SharedDataType::KEEP_SCREEN_ON, true); 43 SharedData<uint8_t>(SharedDataType::BATTERY_STATUS, (uint8_t)ChargeState::NOCHARGE, 44 (uint8_t)ChargeState::NOCHARGE, (uint8_t)ChargeState::CHARGING); 45 // The brightness ranges from 1 to 255. The default value is 255. 46 SharedData<uint8_t>(SharedDataType::BRIGHTNESS_VALUE, 255, 1, 255); 47 SharedData<uint8_t>(SharedDataType::BRIGHTNESS_MODE, (uint8_t)BrightnessMode::MANUAL, 48 (uint8_t)BrightnessMode::MANUAL, (uint8_t)BrightnessMode::AUTO); 49 // The value ranges from 0 to 999999. The default value is 0. 50 SharedData<uint32_t>(SharedDataType::SUMSTEP_VALUE, 0, 0, 999999); 51 // The volume ranges from 0.0 to 1.0. The default value is 1.0. 52 SharedData<double>(SharedDataType::VOLUME_VALUE, 1.0, 0.0, 1.0); 53 // Battery level range: 0.0–1.0; default: 1.0 54 SharedData<double>(SharedDataType::BATTERY_LEVEL, 1.0, 0.0, 1.0); 55 // Heart rate range: 0 to 255. The default value is 80. 56 SharedData<uint8_t>(SharedDataType::HEARTBEAT_VALUE, 80, 0, 255); 57 SharedData<string>(SharedDataType::LANGUAGE, "zh-CN"); 58 // The value ranges from 180 to 180. The default value is 0. 59 SharedData<double>(SharedDataType::LONGITUDE, 0, -180, 180); 60 // The atmospheric pressure ranges from 0 to 999900. The default value is 101325. 61 SharedData<uint32_t>(SharedDataType::PRESSURE_VALUE, 101325, 0, 999900); 62 SharedData<bool>(SharedDataType::WEARING_STATE, true); 63 // The value ranges from -90 to 90. The default value is 0. 64 SharedData<double>(SharedDataType::LATITUDE, 0, -90, 90); 65 } 66 }; 67 68 std::unique_ptr<LocalSocket> CommandLineTest::socket = nullptr; 69 70 TEST_F(CommandLineTest,BackClickedCommandTest)71 TEST_F(CommandLineTest, BackClickedCommandTest) 72 { 73 CommandLine::CommandType type = CommandLine::CommandType::ACTION; 74 std::string msg = "{\"args\":null}"; 75 Json2::Value args = JsonReader::ParseJsonData2(msg); 76 BackClickedCommand command(type, args, *socket); 77 g_dispatchOsBackEvent = false; 78 command.CheckAndRun(); 79 EXPECT_TRUE(g_dispatchOsBackEvent); 80 } 81 TEST_F(CommandLineTest,InspectorJSONTreeTest)82 TEST_F(CommandLineTest, InspectorJSONTreeTest) 83 { 84 CommandLine::CommandType type = CommandLine::CommandType::ACTION; 85 Json2::Value args; 86 InspectorJSONTree command(type, args, *socket); 87 g_getJSONTree = false; 88 command.CheckAndRun(); 89 EXPECT_TRUE(g_getJSONTree); 90 } 91 TEST_F(CommandLineTest,InspectorDefaultTest)92 TEST_F(CommandLineTest, InspectorDefaultTest) 93 { 94 CommandLine::CommandType type = CommandLine::CommandType::ACTION; 95 Json2::Value args; 96 InspectorDefault command(type, args, *socket); 97 g_getDefaultJSONTree = false; 98 command.CheckAndRun(); 99 EXPECT_TRUE(g_getDefaultJSONTree); 100 } 101 TEST_F(CommandLineTest,OrientationCommandTest)102 TEST_F(CommandLineTest, OrientationCommandTest) 103 { 104 JsAppImpl::GetInstance().orientation = ""; 105 CommandLine::CommandType type = CommandLine::CommandType::SET; 106 // args是null 107 Json2::Value args1 = JsonReader::CreateNull(); 108 OrientationCommand command1(type, args1, *socket); 109 command1.CheckAndRun(); 110 EXPECT_EQ(JsAppImpl::GetInstance().GetOrientation(), ""); 111 // 无Orientation 112 std::string jsonStr = "{\"aaaa\":\"landscape\"}"; 113 Json2::Value args2 = JsonReader::ParseJsonData2(jsonStr); 114 OrientationCommand command2(type, args2, *socket); 115 command2.CheckAndRun(); 116 EXPECT_EQ(JsAppImpl::GetInstance().GetOrientation(), ""); 117 // 有Orientation,但不是string类型 118 jsonStr = "{\"Orientation\":\"aaaaa\"}"; 119 Json2::Value args3 = JsonReader::ParseJsonData2(jsonStr); 120 OrientationCommand command3(type, args3, *socket); 121 command3.CheckAndRun(); 122 EXPECT_EQ(JsAppImpl::GetInstance().GetOrientation(), ""); 123 // Orientation : landscape 124 jsonStr = "{\"Orientation\":\"landscape\"}"; 125 Json2::Value args4 = JsonReader::ParseJsonData2(jsonStr); 126 OrientationCommand command4(type, args4, *socket); 127 g_output = false; 128 command4.CheckAndRun(); 129 EXPECT_TRUE(g_output); 130 EXPECT_EQ(JsAppImpl::GetInstance().GetOrientation(), "landscape"); 131 // Orientation : portrait 132 args4.Replace("Orientation", "portrait"); 133 OrientationCommand command5(type, args4, *socket); 134 command5.CheckAndRun(); 135 EXPECT_EQ(JsAppImpl::GetInstance().GetOrientation(), "portrait"); 136 } 137 138 // 参数异常 TEST_F(CommandLineTest,ResolutionSwitchCommandArgsTest)139 TEST_F(CommandLineTest, ResolutionSwitchCommandArgsTest) 140 { 141 JsAppImpl::GetInstance().width = 0; 142 JsAppImpl::GetInstance().height = 0; 143 CommandLine::CommandType type = CommandLine::CommandType::SET; 144 // null 145 Json2::Value args1 = JsonReader::CreateNull(); 146 ResolutionSwitchCommand command1(type, args1, *socket); 147 command1.CheckAndRun(); 148 EXPECT_EQ(JsAppImpl::GetInstance().width, 0); 149 EXPECT_EQ(JsAppImpl::GetInstance().height, 0); 150 // 缺失参数 151 string jsonStr = R"({"aaaaa":1080,"originHeight":2340,"width":1080,"height":2340,"screenDensity":480})"; 152 Json2::Value args2 = JsonReader::ParseJsonData2(jsonStr); 153 ResolutionSwitchCommand command3(type, args2, *socket); 154 command3.CheckAndRun(); 155 EXPECT_NE(JsAppImpl::GetInstance().width, 1080); 156 EXPECT_NE(JsAppImpl::GetInstance().height, 2340); 157 } 158 159 // 参数类型异常 TEST_F(CommandLineTest,ResolutionSwitchCommandArgsTypeTest)160 TEST_F(CommandLineTest, ResolutionSwitchCommandArgsTypeTest) 161 { 162 JsAppImpl::GetInstance().width = 0; 163 JsAppImpl::GetInstance().height = 0; 164 CommandLine::CommandType type = CommandLine::CommandType::SET; 165 string jsonStr = R"({"originWidth":"1080","originHeight":2340,"width":1080, 166 "height":2340,"screenDensity":480})"; 167 Json2::Value args2 = JsonReader::ParseJsonData2(jsonStr); 168 ResolutionSwitchCommand command3(type, args2, *socket); 169 command3.CheckAndRun(); 170 EXPECT_NE(JsAppImpl::GetInstance().width, 1080); 171 EXPECT_NE(JsAppImpl::GetInstance().height, 2340); 172 173 JsAppImpl::GetInstance().width = 0; 174 JsAppImpl::GetInstance().height = 0; 175 string jsonStr1 = R"({"originWidth" : 1080, "originHeight" : 2340, "width" : 1080, 176 "height" : 2340, "screenDensity" : 480, "reason" : 333})"; 177 Json2::Value args1 = JsonReader::ParseJsonData2(jsonStr1); 178 ResolutionSwitchCommand command1(type, args1, *socket); 179 command1.CheckAndRun(); 180 EXPECT_EQ(JsAppImpl::GetInstance().width, 0); 181 EXPECT_EQ(JsAppImpl::GetInstance().height, 0); 182 } 183 184 // 参数范围异常 TEST_F(CommandLineTest,ResolutionSwitchCommandArgsRangesTest)185 TEST_F(CommandLineTest, ResolutionSwitchCommandArgsRangesTest) 186 { 187 JsAppImpl::GetInstance().width = 0; 188 JsAppImpl::GetInstance().height = 0; 189 CommandLine::CommandType type = CommandLine::CommandType::SET; 190 string jsonStr = R"({"originWidth":5000,"originHeight":2340,"width":1080, 191 "height":2340,"screenDensity":480})"; 192 Json2::Value args2 = JsonReader::ParseJsonData2(jsonStr); 193 ResolutionSwitchCommand command3(type, args2, *socket); 194 command3.CheckAndRun(); 195 EXPECT_NE(JsAppImpl::GetInstance().width, 1080); 196 EXPECT_NE(JsAppImpl::GetInstance().height, 2340); 197 198 JsAppImpl::GetInstance().width = 0; 199 JsAppImpl::GetInstance().height = 0; 200 string jsonStr1 = R"({"originWidth" : 1080, "originHeight" : 2340, "width" : 1080, 201 "height" : 2340, "screenDensity" : 480, "reason" : "aaa"})"; 202 Json2::Value args1 = JsonReader::ParseJsonData2(jsonStr1); 203 ResolutionSwitchCommand command1(type, args1, *socket); 204 command1.CheckAndRun(); 205 EXPECT_EQ(JsAppImpl::GetInstance().width, 0); 206 EXPECT_EQ(JsAppImpl::GetInstance().height, 0); 207 208 JsAppImpl::GetInstance().width = 0; 209 JsAppImpl::GetInstance().height = 0; 210 string jsonStr4 = R"({"originWidth" : 1080, "originHeight" : 2340, "width" : 1080, 211 "height" : 2340, "screenDensity" : 100, "reason" : "resize"})"; 212 Json2::Value args4 = JsonReader::ParseJsonData2(jsonStr4); 213 ResolutionSwitchCommand command4(type, args4, *socket); 214 command4.CheckAndRun(); 215 EXPECT_EQ(JsAppImpl::GetInstance().width, 0); 216 EXPECT_EQ(JsAppImpl::GetInstance().height, 0); 217 218 JsAppImpl::GetInstance().width = 0; 219 JsAppImpl::GetInstance().height = 0; 220 string jsonStr5 = R"({"originWidth" : 1080, "originHeight" : 2340, "width" : 1080, 221 "height" : 2340, "screenDensity" : 700, "reason" : "resize"})"; 222 Json2::Value args5 = JsonReader::ParseJsonData2(jsonStr5); 223 ResolutionSwitchCommand command5(type, args5, *socket); 224 command5.CheckAndRun(); 225 EXPECT_EQ(JsAppImpl::GetInstance().width, 0); 226 EXPECT_EQ(JsAppImpl::GetInstance().height, 0); 227 } 228 229 // 参数正常 TEST_F(CommandLineTest,ResolutionSwitchCommandArgsCorrectTest)230 TEST_F(CommandLineTest, ResolutionSwitchCommandArgsCorrectTest) 231 { 232 JsAppImpl::GetInstance().width = 0; 233 JsAppImpl::GetInstance().height = 0; 234 CommandLine::CommandType type = CommandLine::CommandType::SET; 235 string jsonStr = R"({"originWidth" : 1080, "originHeight" : 2340, "width" : 1080, 236 "height" : 2340, "screenDensity" : 480, "reason" : "resize"})"; 237 Json2::Value args2 = JsonReader::ParseJsonData2(jsonStr); 238 ResolutionSwitchCommand command3(type, args2, *socket); 239 command3.CheckAndRun(); 240 EXPECT_EQ(JsAppImpl::GetInstance().width, 1080); 241 EXPECT_EQ(JsAppImpl::GetInstance().height, 2340); 242 } 243 TEST_F(CommandLineTest,CurrentRouterCommandTest)244 TEST_F(CommandLineTest, CurrentRouterCommandTest) 245 { 246 CommandLine::CommandType type = CommandLine::CommandType::GET; 247 Json2::Value args1 = JsonReader::CreateObject(); 248 CurrentRouterCommand command3(type, args1, *socket); 249 g_getCurrentRouter = false; 250 command3.CheckAndRun(); 251 EXPECT_TRUE(g_getCurrentRouter); 252 } 253 TEST_F(CommandLineTest,ReloadRuntimePageCommandTest)254 TEST_F(CommandLineTest, ReloadRuntimePageCommandTest) 255 { 256 CommandLine::CommandType type = CommandLine::CommandType::SET; 257 std::string msg = "{\"ReloadRuntimePage\":\"aaa\"}"; 258 Json2::Value args2 = JsonReader::ParseJsonData2(msg); 259 ReloadRuntimePageCommand command(type, args2, *socket); 260 g_reloadRuntimePage = false; 261 command.CheckAndRun(); 262 EXPECT_TRUE(g_reloadRuntimePage); 263 264 std::string msg2 = "{\"ReloadRuntimePage\" : 222}"; 265 Json2::Value args3 = JsonReader::ParseJsonData2(msg2); 266 ReloadRuntimePageCommand command3(type, args3, *socket); 267 g_reloadRuntimePage = false; 268 command3.CheckAndRun(); 269 EXPECT_FALSE(g_reloadRuntimePage); 270 } 271 TEST_F(CommandLineTest,ToUint8Test)272 TEST_F(CommandLineTest, ToUint8Test) 273 { 274 CommandLine::CommandType type = CommandLine::CommandType::SET; 275 // null 276 Json2::Value args1 = JsonReader::CreateNull(); 277 ResolutionSwitchCommand command1(type, args1, *socket); 278 EXPECT_EQ(command1.ToUint8("256"), 0); 279 } 280 TEST_F(CommandLineTest,IsBoolTypeTest)281 TEST_F(CommandLineTest, IsBoolTypeTest) 282 { 283 CommandLine::CommandType type = CommandLine::CommandType::SET; 284 // null 285 Json2::Value args1 = JsonReader::CreateNull(); 286 ResolutionSwitchCommand command1(type, args1, *socket); 287 EXPECT_TRUE(command1.IsBoolType("true")); 288 EXPECT_FALSE(command1.IsBoolType("XX")); 289 } 290 TEST_F(CommandLineTest,IsIntTypeTest)291 TEST_F(CommandLineTest, IsIntTypeTest) 292 { 293 CommandLine::CommandType type = CommandLine::CommandType::SET; 294 // null 295 Json2::Value args1 = JsonReader::CreateNull(); 296 ResolutionSwitchCommand command1(type, args1, *socket); 297 EXPECT_TRUE(command1.IsIntType("123")); 298 } 299 TEST_F(CommandLineTest,IsOneDigitFloatTypeTest)300 TEST_F(CommandLineTest, IsOneDigitFloatTypeTest) 301 { 302 CommandLine::CommandType type = CommandLine::CommandType::SET; 303 // null 304 Json2::Value args1 = JsonReader::CreateNull(); 305 ResolutionSwitchCommand command1(type, args1, *socket); 306 EXPECT_TRUE(command1.IsOneDigitFloatType("-6", true)); 307 EXPECT_TRUE(command1.IsOneDigitFloatType("3", false)); 308 } 309 TEST_F(CommandLineTest,IsSetArgValidTest)310 TEST_F(CommandLineTest, IsSetArgValidTest) 311 { 312 CommandLine::CommandType type = CommandLine::CommandType::SET; 313 // null 314 Json2::Value args1 = JsonReader::CreateNull(); 315 ColorModeCommand command1(type, args1, *socket); 316 command1.RunSet(); 317 EXPECT_FALSE(command1.IsSetArgValid()); 318 } 319 TEST_F(CommandLineTest,FontSelectCommandTest)320 TEST_F(CommandLineTest, FontSelectCommandTest) 321 { 322 CommandLine::CommandType type = CommandLine::CommandType::SET; 323 Json2::Value args1 = JsonReader::CreateNull(); 324 FontSelectCommand command1(type, args1, *socket); 325 g_output = false; 326 command1.CheckAndRun(); 327 command1.RunSet(); 328 EXPECT_FALSE(command1.IsSetArgValid()); 329 EXPECT_TRUE(g_output); 330 std::string msg = "{\"FontSelect\":true}"; 331 Json2::Value args2 = JsonReader::ParseJsonData2(msg); 332 FontSelectCommand command3(type, args2, *socket); 333 g_output = false; 334 command3.CheckAndRun(); 335 EXPECT_TRUE(g_output); 336 } 337 TEST_F(CommandLineTest,MemoryRefreshCommandTest)338 TEST_F(CommandLineTest, MemoryRefreshCommandTest) 339 { 340 CommandLine::CommandType type = CommandLine::CommandType::SET; 341 Json2::Value args1 = JsonReader::CreateNull(); 342 MemoryRefreshCommand command1(type, args1, *socket); 343 g_memoryRefresh = false; 344 command1.CheckAndRun(); 345 EXPECT_FALSE(g_memoryRefresh); 346 std::string msg = "{\"jsCode\":\"UEFOREEAAAAAAAAAAAAAA+wDAADEAAAAFQ\"}"; 347 Json2::Value args2 = JsonReader::ParseJsonData2(msg); 348 MemoryRefreshCommand command3(type, args2, *socket); 349 g_memoryRefresh = false; 350 command3.CheckAndRun(); 351 EXPECT_TRUE(g_memoryRefresh); 352 } 353 TEST_F(CommandLineTest,LoadDocumentCommandArgsTest)354 TEST_F(CommandLineTest, LoadDocumentCommandArgsTest) 355 { 356 CommandLine::CommandType type = CommandLine::CommandType::SET; 357 Json2::Value args2 = JsonReader::CreateNull(); 358 LoadDocumentCommand command(type, args2, *socket); 359 g_loadDocument = false; 360 command.CheckAndRun(); 361 EXPECT_FALSE(g_loadDocument); 362 } 363 TEST_F(CommandLineTest,LoadDocumentCommandArgsTypeTest)364 TEST_F(CommandLineTest, LoadDocumentCommandArgsTypeTest) 365 { 366 CommandLine::CommandType type = CommandLine::CommandType::SET; 367 std::string msg = R"({"url":"pages/Index","className":"Index","previewParam":{"width":1080, 368 "height":"2340","locale":"zh_CN","colorMode":"light","orientation":"portrait", 369 "deviceType":"phone","dpi":480}})"; 370 Json2::Value args2 = JsonReader::ParseJsonData2(msg); 371 LoadDocumentCommand command(type, args2, *socket); 372 g_loadDocument = false; 373 command.CheckAndRun(); 374 EXPECT_FALSE(g_loadDocument); 375 } 376 TEST_F(CommandLineTest,LoadDocumentCommandArgsNumRangeTest)377 TEST_F(CommandLineTest, LoadDocumentCommandArgsNumRangeTest) 378 { 379 CommandLine::CommandType type = CommandLine::CommandType::SET; 380 std::string msg = R"({"url" : "pages/Index", "className" : "Index", "previewParam" : {"width" : 1080, 381 "height" : 2340, "locale" : "zh_CN" , "colorMode" : "light", "orientation" : "portrait", 382 "deviceType" : "phone", "dpi" : 720}})"; 383 Json2::Value args2 = JsonReader::ParseJsonData2(msg); 384 LoadDocumentCommand command(type, args2, *socket); 385 g_loadDocument = false; 386 command.CheckAndRun(); 387 EXPECT_FALSE(g_loadDocument); 388 } 389 TEST_F(CommandLineTest,LoadDocumentCommandArgsStrRangeTest)390 TEST_F(CommandLineTest, LoadDocumentCommandArgsStrRangeTest) 391 { 392 CommandParser::GetInstance().deviceType = "phone"; 393 CommandLine::CommandType type = CommandLine::CommandType::SET; 394 std::string msg = R"({"url" : "pages/Index", "className" : "Index", "previewParam" : {"width" : 1080, 395 "height" : 2340, "locale" : "aa_PP", "colorMode" : "light", "orientation" : "portrait", 396 "deviceType" : "phone", "dpi" : 480}})"; 397 Json2::Value args = JsonReader::ParseJsonData2(msg); 398 // locale error 399 LoadDocumentCommand command(type, args, *socket); 400 g_loadDocument = false; 401 command.CheckAndRun(); 402 EXPECT_FALSE(g_loadDocument); 403 // colorMode error 404 std::string msg1 = R"({"url" : "pages/Index", "className" : "Index", "previewParam" : {"width" : 1080, 405 "height" : 2340, "locale" : "zh_CN", "colorMode" : "aaa", "orientation" : "portrait", 406 "deviceType" : "phone", "dpi" : 480}})"; 407 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 408 LoadDocumentCommand command1(type, args1, *socket); 409 g_loadDocument = false; 410 command1.CheckAndRun(); 411 EXPECT_FALSE(g_loadDocument); 412 // colorMode error 413 std::string msg2 = R"({"url" : "pages/Index", "className" : "Index", "previewParam" : {"width" : 1080, 414 "height" : 2340, "locale" : "zh_CN", "colorMode" : "dark", "orientation" : "aaa", 415 "deviceType" : "phone", "dpi" : 480}})"; 416 Json2::Value args2 = JsonReader::ParseJsonData2(msg2); 417 LoadDocumentCommand command2(type, args2, *socket); 418 g_loadDocument = false; 419 command2.CheckAndRun(); 420 EXPECT_FALSE(g_loadDocument); 421 // deviceType error 422 std::string msg3 = R"({"url" : "pages/Index", "className" : "Index", "previewParam" : {"width" : 1080, 423 "height" : 2340, "locale" : "zh_CN", "colorMode" : "dark", "orientation" : "landscape", 424 "deviceType" : "liteWearable", "dpi" : 480}})"; 425 Json2::Value args3 = JsonReader::ParseJsonData2(msg3); 426 LoadDocumentCommand command3(type, args3, *socket); 427 g_loadDocument = false; 428 command3.CheckAndRun(); 429 EXPECT_FALSE(g_loadDocument); 430 } 431 TEST_F(CommandLineTest,LoadDocumentCommandArgsCorrectTest)432 TEST_F(CommandLineTest, LoadDocumentCommandArgsCorrectTest) 433 { 434 CommandLine::CommandType type = CommandLine::CommandType::SET; 435 CommandParser::GetInstance().deviceType = "phone"; 436 std::string msg = R"({"url":"pages/Index","className":"Index","previewParam":{"width":1080, 437 "height":2340,"locale":"zh_CN","colorMode":"light","orientation":"portrait", 438 "deviceType":"phone","dpi":480}})"; 439 Json2::Value args1 = JsonReader::ParseJsonData2(msg); 440 LoadDocumentCommand command1(type, args1, *socket); 441 g_loadDocument = false; 442 command1.CheckAndRun(); 443 EXPECT_TRUE(g_loadDocument); 444 445 CommandParser::GetInstance().deviceType = "liteWearable"; 446 msg = R"({"url":"pages/Index","className":"Index","previewParam":{"width":1080, 447 "height":2340,"locale":"zh_CN","colorMode":"light","orientation":"portrait", 448 "deviceType":"liteWearable","dpi":480}})"; 449 Json2::Value args2 = JsonReader::ParseJsonData2(msg); 450 LoadDocumentCommand command2(type, args2, *socket); 451 g_loadDocument = false; 452 command2.CheckAndRun(); 453 EXPECT_FALSE(g_loadDocument); 454 } 455 TEST_F(CommandLineTest,FastPreviewMsgCommandTest)456 TEST_F(CommandLineTest, FastPreviewMsgCommandTest) 457 { 458 CommandLine::CommandType type = CommandLine::CommandType::GET; 459 Json2::Value args2 = JsonReader::CreateNull(); 460 FastPreviewMsgCommand command2(type, args2, *socket); 461 g_getFastPreviewMsg = false; 462 command2.CheckAndRun(); 463 EXPECT_TRUE(g_getFastPreviewMsg); 464 } 465 TEST_F(CommandLineTest,LoadContentCommandTest)466 TEST_F(CommandLineTest, LoadContentCommandTest) 467 { 468 CommandLine::CommandType type = CommandLine::CommandType::GET; 469 Json2::Value args2 = JsonReader::CreateNull(); 470 LoadContentCommand command2(type, args2, *socket); 471 g_getAbilityCurrentRouter = false; 472 command2.CheckAndRun(); 473 EXPECT_TRUE(g_getAbilityCurrentRouter); 474 } 475 TEST_F(CommandLineTest,DropFrameCommandTest)476 TEST_F(CommandLineTest, DropFrameCommandTest) 477 { 478 VirtualScreenImpl::GetInstance().dropFrameFrequency = 0; 479 CommandLine::CommandType type = CommandLine::CommandType::SET; 480 std::string msg = R"({"frequency" : 1000})"; 481 Json2::Value args1 = JsonReader::ParseJsonData2(msg); 482 DropFrameCommand command1(type, args1, *socket); 483 command1.CheckAndRun(); 484 EXPECT_EQ(VirtualScreenImpl::GetInstance().dropFrameFrequency, 1000); // set value is 1000 485 486 VirtualScreenImpl::GetInstance().dropFrameFrequency = 0; 487 std::string msg2 = R"({"frequency" : "aaaa"})"; 488 Json2::Value args2 = JsonReader::ParseJsonData2(msg2); 489 DropFrameCommand command2(type, args2, *socket); 490 command2.CheckAndRun(); 491 EXPECT_EQ(VirtualScreenImpl::GetInstance().dropFrameFrequency, 0); 492 493 VirtualScreenImpl::GetInstance().dropFrameFrequency = 0; 494 std::string msg3 = R"({"frequency" : -100})"; 495 Json2::Value args3 = JsonReader::ParseJsonData2(msg3); 496 DropFrameCommand command3(type, args3, *socket); 497 command3.CheckAndRun(); 498 EXPECT_EQ(VirtualScreenImpl::GetInstance().dropFrameFrequency, 0); 499 } 500 TEST_F(CommandLineTest,KeyPressCommandImeTest)501 TEST_F(CommandLineTest, KeyPressCommandImeTest) 502 { 503 CommandLine::CommandType type = CommandLine::CommandType::ACTION; 504 int codePoint = 2033; 505 std::string msg = R"({"isInputMethod":"aaa","codePoint":2033})"; 506 Json2::Value args1 = JsonReader::ParseJsonData2(msg); 507 KeyPressCommand command1(type, args1, *socket); 508 g_dispatchOsInputMethodEvent = false; 509 command1.CheckAndRun(); 510 EXPECT_FALSE(g_dispatchOsInputMethodEvent); 511 512 args1.Replace("isInputMethod", true); 513 args1.Replace("codePoint", "aaaa"); 514 KeyPressCommand command2(type, args1, *socket); 515 g_dispatchOsInputMethodEvent = false; 516 command2.CheckAndRun(); 517 EXPECT_FALSE(g_dispatchOsInputMethodEvent); 518 519 args1.Replace("codePoint", codePoint); 520 KeyPressCommand command3(type, args1, *socket); 521 g_dispatchOsInputMethodEvent = false; 522 KeyInputImpl::GetInstance().codePoint = 0; 523 command3.CheckAndRun(); 524 EXPECT_TRUE(g_dispatchOsInputMethodEvent); 525 EXPECT_EQ(KeyInputImpl::GetInstance().codePoint, codePoint); 526 } 527 TEST_F(CommandLineTest,KeyPressCommandNoneImeArgsTest)528 TEST_F(CommandLineTest, KeyPressCommandNoneImeArgsTest) 529 { 530 CommandLine::CommandType type = CommandLine::CommandType::ACTION; 531 std::string msg = R"({"isInputMethod":false,"keyCode":2033,"keyAction":0,"keyString":123, 532 "pressedCodes":[2033]})"; 533 Json2::Value args1 = JsonReader::ParseJsonData2(msg); 534 KeyPressCommand command1(type, args1, *socket); 535 g_dispatchOsKeyEvent = false; 536 command1.CheckAndRun(); 537 EXPECT_FALSE(g_dispatchOsKeyEvent); 538 } 539 TEST_F(CommandLineTest,KeyPressCommandNoneImeArgsTypeTest)540 TEST_F(CommandLineTest, KeyPressCommandNoneImeArgsTypeTest) 541 { 542 CommandLine::CommandType type = CommandLine::CommandType::ACTION; 543 std::string msg = R"({"isInputMethod":false,"keyCode":2033,"keyAction":0,"pressedCodes":["aaa"]})"; 544 Json2::Value args1 = JsonReader::ParseJsonData2(msg); 545 KeyPressCommand command1(type, args1, *socket); 546 g_dispatchOsKeyEvent = false; 547 command1.CheckAndRun(); 548 EXPECT_FALSE(g_dispatchOsKeyEvent); 549 } 550 TEST_F(CommandLineTest,KeyPressCommandNoneImeArgsRangeTest)551 TEST_F(CommandLineTest, KeyPressCommandNoneImeArgsRangeTest) 552 { 553 CommandLine::CommandType type = CommandLine::CommandType::ACTION; 554 // keyAction error 555 std::string msg = R"({"isInputMethod" : false, "keyCode" : 2033, "keyAction" : 3, "keyString" : "123", 556 "pressedCodes" : [2033]})"; 557 Json2::Value args1 = JsonReader::ParseJsonData2(msg); 558 KeyPressCommand command1(type, args1, *socket); 559 g_dispatchOsKeyEvent = false; 560 command1.CheckAndRun(); 561 EXPECT_FALSE(g_dispatchOsKeyEvent); 562 // keyCode error 563 args1.Replace("keyAction", 0); 564 args1.Replace("keyCode", 1900); 565 KeyPressCommand command2(type, args1, *socket); 566 g_dispatchOsKeyEvent = false; 567 command2.CheckAndRun(); 568 EXPECT_FALSE(g_dispatchOsKeyEvent); 569 // pressedCodes error 570 msg = R"({"isInputMethod" : false, "keyCode" : 2033, "keyAction" : 1, "keyString" : "123", 571 "pressedCodes" : [1900]})"; 572 Json2::Value args2 = JsonReader::ParseJsonData2(msg); 573 KeyPressCommand command3(type, args2, *socket); 574 g_dispatchOsKeyEvent = false; 575 command3.CheckAndRun(); 576 EXPECT_FALSE(g_dispatchOsKeyEvent); 577 } 578 TEST_F(CommandLineTest,KeyPressCommandNoneImeArgsCorrectTest)579 TEST_F(CommandLineTest, KeyPressCommandNoneImeArgsCorrectTest) 580 { 581 CommandLine::CommandType type = CommandLine::CommandType::ACTION; 582 std::string msg1 = R"({"isInputMethod":false,"keyCode":2033,"keyAction":0, 583 "keyString":"ctrl","pressedCodes":[2033]})"; 584 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 585 KeyPressCommand command1(type, args1, *socket); 586 g_dispatchOsKeyEvent = false; 587 command1.CheckAndRun(); 588 EXPECT_TRUE(g_dispatchOsKeyEvent); 589 EXPECT_EQ(KeyInputImpl::GetInstance().keyCode, 2033); 590 EXPECT_EQ(KeyInputImpl::GetInstance().keyAction, 0); 591 EXPECT_EQ(KeyInputImpl::GetInstance().keyString, "ctrl"); 592 EXPECT_EQ(KeyInputImpl::GetInstance().pressedCodes[0], OHOS::MMI::KeyCode(2033)); 593 594 std::string msg2 = R"({"isInputMethod":false,"keyCode":2033,"keyAction":0,"pressedCodes":[2033]})"; 595 Json2::Value args2 = JsonReader::ParseJsonData2(msg2); 596 KeyPressCommand command2(type, args2, *socket); 597 g_dispatchOsKeyEvent = false; 598 command2.CheckAndRun(); 599 EXPECT_TRUE(g_dispatchOsKeyEvent); 600 EXPECT_EQ(KeyInputImpl::GetInstance().keyString, ""); 601 602 KeyPressCommand command3(type, args1, *socket); 603 CommandParser::GetInstance().screenMode = CommandParser::ScreenMode::STATIC; 604 g_dispatchOsKeyEvent = false; 605 command3.CheckAndRun(); 606 CommandParser::GetInstance().screenMode = CommandParser::ScreenMode::DYNAMIC; 607 EXPECT_FALSE(g_dispatchOsKeyEvent); 608 } 609 TEST_F(CommandLineTest,PointEventCommandArgTest)610 TEST_F(CommandLineTest, PointEventCommandArgTest) 611 { 612 CommandLine::CommandType type = CommandLine::CommandType::ACTION; 613 // y error 614 std::string msg1 = R"({"x":365,"y":"aaa","duration":"","button":1,"action": 2,"axisValues":[0,0,0,0], 615 "sourceType":1,"sourceTool": 7,"pressedButtons":[0,1]})"; 616 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 617 PointEventCommand command1(type, args1, *socket); 618 g_dispatchOsTouchEvent = false; 619 command1.CheckAndRun(); 620 EXPECT_FALSE(g_dispatchOsTouchEvent); 621 // action error 622 args1.Replace("y", 1071); 623 args1.Replace("action", "2"); 624 PointEventCommand command2(type, args1, *socket); 625 g_dispatchOsTouchEvent = false; 626 command2.CheckAndRun(); 627 EXPECT_FALSE(g_dispatchOsTouchEvent); 628 // sourceTool error 629 args1.Replace("action", 2); 630 args1.Replace("sourceTool", "7"); 631 PointEventCommand command3(type, args1, *socket); 632 g_dispatchOsTouchEvent = false; 633 command3.CheckAndRun(); 634 EXPECT_FALSE(g_dispatchOsTouchEvent); 635 // axisValues error 636 args1.Replace("sourceTool", 7); 637 args1.Replace("axisValues", "aaa"); 638 PointEventCommand command4(type, args1, *socket); 639 g_dispatchOsTouchEvent = false; 640 command4.CheckAndRun(); 641 EXPECT_FALSE(g_dispatchOsTouchEvent); 642 } 643 TEST_F(CommandLineTest,PointEventCommandArgRangeTest)644 TEST_F(CommandLineTest, PointEventCommandArgRangeTest) 645 { 646 CommandLine::CommandType type = CommandLine::CommandType::ACTION; 647 // x error 648 std::string msg1 = R"({"x":2000,"y":1071,"duration":"","button":1,"action": 2,"axisValues":[0,0,0,0], 649 "sourceType":1,"sourceTool": 7,"pressedButtons":[0,1]})"; 650 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 651 PointEventCommand command1(type, args1, *socket); 652 g_dispatchOsTouchEvent = false; 653 command1.CheckAndRun(); 654 EXPECT_FALSE(g_dispatchOsTouchEvent); 655 // y error 656 args1.Replace("x", 365); 657 args1.Replace("y", 5000); 658 PointEventCommand command2(type, args1, *socket); 659 g_dispatchOsTouchEvent = false; 660 command2.CheckAndRun(); 661 EXPECT_FALSE(g_dispatchOsTouchEvent); 662 // sourceTool error 663 args1.Replace("y", 1071); 664 args1.Replace("sourceTool", -1); 665 PointEventCommand command3(type, args1, *socket); 666 g_dispatchOsTouchEvent = false; 667 command3.CheckAndRun(); 668 EXPECT_FALSE(g_dispatchOsTouchEvent); 669 // axisValues error 670 msg1 = R"({"x" : 300, "y" : 1071, "duration" : "", "button" : 1, "action" : 2, 671 "axisValues" : ["0", 0, 0, 0], "sourceType" : 1, "sourceTool" : 7, "pressedButtons" : [0, 1]})"; 672 Json2::Value args2 = JsonReader::ParseJsonData2(msg1); 673 PointEventCommand command4(type, args2, *socket); 674 g_dispatchOsTouchEvent = false; 675 command4.CheckAndRun(); 676 EXPECT_FALSE(g_dispatchOsTouchEvent); 677 // pressedButtons errors 678 msg1 = R"({"x" : 300, "y" : 1071, "duration" : "", "button" : 1, "action" : 2, 679 "axisValues" : [0, 0, 0, 0], "sourceType" : 1, "sourceTool" : 7, "pressedButtons" : [-2, 0, 1]})"; 680 Json2::Value args3 = JsonReader::ParseJsonData2(msg1); 681 PointEventCommand command5(type, args3, *socket); 682 g_dispatchOsTouchEvent = false; 683 command5.CheckAndRun(); 684 EXPECT_TRUE(g_dispatchOsTouchEvent); 685 } 686 TEST_F(CommandLineTest,PointEventCommandArgCorrectTest)687 TEST_F(CommandLineTest, PointEventCommandArgCorrectTest) 688 { 689 CommandLine::CommandType type = CommandLine::CommandType::ACTION; 690 std::string msg1 = R"({"x":365,"y":1071,"duration":"","button":1,"action": 2,"axisValues":[0,0,0,0], 691 "sourceType":1,"sourceTool": 7,"pressedButtons":[0,1]})"; 692 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 693 PointEventCommand command1(type, args1, *socket); 694 g_dispatchOsTouchEvent = false; 695 command1.CheckAndRun(); 696 EXPECT_TRUE(g_dispatchOsTouchEvent); 697 EXPECT_EQ(MouseInputImpl::GetInstance().mouseXPosition, 365); // 365 is test x 698 EXPECT_EQ(MouseInputImpl::GetInstance().mouseYPosition, 1071); // 1071 is test y 699 700 PointEventCommand command2(type, args1, *socket); 701 CommandParser::GetInstance().screenMode = CommandParser::ScreenMode::STATIC; 702 g_dispatchOsTouchEvent = false; 703 command2.CheckAndRun(); 704 CommandParser::GetInstance().screenMode = CommandParser::ScreenMode::DYNAMIC; 705 EXPECT_FALSE(g_dispatchOsTouchEvent); 706 } 707 TEST_F(CommandLineTest,FoldStatusCommandArgsTest)708 TEST_F(CommandLineTest, FoldStatusCommandArgsTest) 709 { 710 VirtualScreenImpl::GetInstance().SetFoldStatus("unfold"); 711 CommandLine::CommandType type = CommandLine::CommandType::SET; 712 // FoldStatus error 713 std::string msg1 = R"({"FoldStatus":100,"width":1080,"height":2504})"; 714 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 715 FoldStatusCommand command1(type, args1, *socket); 716 JsAppImpl::GetInstance().width = 0; 717 JsAppImpl::GetInstance().height = 0; 718 command1.CheckAndRun(); 719 EXPECT_NE(JsAppImpl::GetInstance().width, 1080); // 1080 is test width 720 EXPECT_NE(JsAppImpl::GetInstance().height, 2504); // 2504 is test height 721 // height error 722 args1.Replace("FoldStatus", "fold"); 723 args1.Replace("height", "aaa"); 724 FoldStatusCommand command2(type, args1, *socket); 725 JsAppImpl::GetInstance().width = 0; 726 JsAppImpl::GetInstance().height = 0; 727 command2.CheckAndRun(); 728 EXPECT_NE(JsAppImpl::GetInstance().width, 1080); // 1080 is test width 729 EXPECT_NE(JsAppImpl::GetInstance().height, 2504); // 2504 is test height 730 } 731 TEST_F(CommandLineTest,FoldStatusCommandArgsRangeTest)732 TEST_F(CommandLineTest, FoldStatusCommandArgsRangeTest) 733 { 734 VirtualScreenImpl::GetInstance().SetFoldStatus("unfold"); 735 CommandLine::CommandType type = CommandLine::CommandType::SET; 736 // FoldStatus error 737 std::string msg1 = R"({"FoldStatus":"fold","width":1080,"height":4000})"; 738 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 739 FoldStatusCommand command1(type, args1, *socket); 740 JsAppImpl::GetInstance().width = 0; 741 JsAppImpl::GetInstance().height = 0; 742 command1.CheckAndRun(); 743 EXPECT_NE(JsAppImpl::GetInstance().width, 1080); // 1080 is test width 744 EXPECT_NE(JsAppImpl::GetInstance().height, 4000); // 4000 is test height 745 // height error 746 args1.Replace("height", 2504); // 2504 is test height 747 args1.Replace("FoldStatus", "aaaa"); 748 FoldStatusCommand command2(type, args1, *socket); 749 JsAppImpl::GetInstance().width = 0; 750 JsAppImpl::GetInstance().height = 0; 751 command2.CheckAndRun(); 752 EXPECT_NE(JsAppImpl::GetInstance().width, 1080); // 1080 is test width 753 EXPECT_NE(JsAppImpl::GetInstance().height, 2504); // 2504 is test height 754 } 755 TEST_F(CommandLineTest,FoldStatusCommandArgsCorrectTest)756 TEST_F(CommandLineTest, FoldStatusCommandArgsCorrectTest) 757 { 758 VirtualScreenImpl::GetInstance().SetFoldStatus("unfold"); 759 CommandLine::CommandType type = CommandLine::CommandType::SET; 760 std::string msg1 = R"({"FoldStatus":"fold","width":1080,"height":2504})"; 761 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 762 FoldStatusCommand command1(type, args1, *socket); 763 JsAppImpl::GetInstance().width = 0; 764 JsAppImpl::GetInstance().height = 0; 765 command1.CheckAndRun(); 766 EXPECT_EQ(JsAppImpl::GetInstance().width, 1080); // 1080 is test width 767 EXPECT_EQ(JsAppImpl::GetInstance().height, 2504); // 2504 is test height 768 } 769 TEST_F(CommandLineTest,PowerCommandArgsTest)770 TEST_F(CommandLineTest, PowerCommandArgsTest) 771 { 772 CommandLine::CommandType type = CommandLine::CommandType::SET; 773 std::string msg1 = R"({"Power":"abc"})"; 774 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 775 PowerCommand command1(type, args1, *socket); 776 command1.CheckAndRun(); 777 double power = SharedData<double>::GetData(SharedDataType::BATTERY_LEVEL); 778 EXPECT_EQ(power, 1.0); // 1.0 is default Power value 779 780 args1.Replace("Power", 2.0); // 2.0 is test Power value 781 PowerCommand command2(type, args1, *socket); 782 command2.CheckAndRun(); 783 power = SharedData<double>::GetData(SharedDataType::BATTERY_LEVEL); 784 EXPECT_NE(power, 2.0); // 2.0 is test Power value 785 786 args1.Replace("Power", -1); 787 PowerCommand command3(type, args1, *socket); 788 command3.CheckAndRun(); 789 power = SharedData<double>::GetData(SharedDataType::BATTERY_LEVEL); 790 EXPECT_NE(power, -1); // -1 is test Power value 791 } 792 TEST_F(CommandLineTest,PowerCommandSetTest)793 TEST_F(CommandLineTest, PowerCommandSetTest) 794 { 795 std::string msg1 = R"({"Power":0.5})"; 796 CommandLine::CommandType type = CommandLine::CommandType::SET; 797 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 798 PowerCommand command1(type, args1, *socket); 799 command1.CheckAndRun(); 800 double power = SharedData<double>::GetData(SharedDataType::BATTERY_LEVEL); 801 EXPECT_EQ(power, 0.5); // 0.5 is test Barometer value 802 } 803 TEST_F(CommandLineTest,PowerCommandGetTest)804 TEST_F(CommandLineTest, PowerCommandGetTest) 805 { 806 CommandLine::CommandType type = CommandLine::CommandType::GET; 807 Json2::Value args2 = JsonReader::CreateNull(); 808 PowerCommand command2(type, args2, *socket); 809 g_output = false; 810 command2.CheckAndRun(); 811 EXPECT_TRUE(g_output); 812 } 813 TEST_F(CommandLineTest,VolumeCommandTest)814 TEST_F(CommandLineTest, VolumeCommandTest) 815 { 816 std::string msg1 = R"({"Volume":90})"; 817 CommandLine::CommandType type1 = CommandLine::CommandType::SET; 818 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 819 VolumeCommand command1(type1, args1, *socket); 820 g_output = false; 821 command1.CheckAndRun(); 822 EXPECT_TRUE(g_output); 823 824 CommandLine::CommandType type2 = CommandLine::CommandType::GET; 825 Json2::Value args2 = JsonReader::CreateNull(); 826 VolumeCommand command2(type2, args2, *socket); 827 g_output = false; 828 command2.CheckAndRun(); 829 command2.RunGet(); 830 EXPECT_TRUE(g_output); 831 } 832 TEST_F(CommandLineTest,BarometerCommandArgsTest)833 TEST_F(CommandLineTest, BarometerCommandArgsTest) 834 { 835 CommandLine::CommandType type = CommandLine::CommandType::SET; 836 std::string msg1 = R"({"Barometer":"abc"})"; 837 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 838 BarometerCommand command1(type, args1, *socket); 839 command1.CheckAndRun(); 840 int barometer = static_cast<int>(SharedData<uint32_t>::GetData(SharedDataType::PRESSURE_VALUE)); 841 EXPECT_EQ(barometer, 101325); // 101325 is default Power value 842 843 args1.Replace("Barometer", 999901); // 999901 is test Power value 844 BarometerCommand command2(type, args1, *socket); 845 command2.CheckAndRun(); 846 barometer = static_cast<int>(SharedData<uint32_t>::GetData(SharedDataType::PRESSURE_VALUE)); 847 EXPECT_NE(barometer, 999901); // 999901 is test Power value 848 849 args1.Replace("Barometer", -1); 850 BarometerCommand command3(type, args1, *socket); 851 command3.CheckAndRun(); 852 barometer = static_cast<int>(SharedData<uint32_t>::GetData(SharedDataType::PRESSURE_VALUE)); 853 EXPECT_NE(barometer, -1); // -1 is test Power value 854 } 855 TEST_F(CommandLineTest,BarometerCommandSetTest)856 TEST_F(CommandLineTest, BarometerCommandSetTest) 857 { 858 std::string msg1 = R"({"Barometer":999})"; 859 CommandLine::CommandType type = CommandLine::CommandType::SET; 860 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 861 BarometerCommand command1(type, args1, *socket); 862 command1.CheckAndRun(); 863 int barometer = static_cast<int>(SharedData<uint32_t>::GetData(SharedDataType::PRESSURE_VALUE)); 864 EXPECT_EQ(barometer, 999); // 999 is test Barometer value 865 } 866 TEST_F(CommandLineTest,BarometerCommandGetTest)867 TEST_F(CommandLineTest, BarometerCommandGetTest) 868 { 869 CommandLine::CommandType type = CommandLine::CommandType::GET; 870 Json2::Value args2 = JsonReader::CreateNull(); 871 BarometerCommand command2(type, args2, *socket); 872 g_output = false; 873 command2.CheckAndRun(); 874 EXPECT_TRUE(g_output); 875 } 876 TEST_F(CommandLineTest,LocationCommandArgsTest)877 TEST_F(CommandLineTest, LocationCommandArgsTest) 878 { 879 CommandLine::CommandType type = CommandLine::CommandType::SET; 880 std::string msg0 = R"({"latitude":"10.0"})"; 881 Json2::Value args0 = JsonReader::ParseJsonData2(msg0); 882 LocationCommand command0(type, args0, *socket); 883 command0.CheckAndRun(); 884 double latitude = SharedData<double>::GetData(SharedDataType::LATITUDE); 885 EXPECT_EQ(latitude, 0); 886 std::string msg1 = R"({"latitude":"10.0","longitude":"abc"})"; 887 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 888 LocationCommand command1(type, args1, *socket); 889 command1.CheckAndRun(); 890 latitude = SharedData<double>::GetData(SharedDataType::LATITUDE); 891 EXPECT_EQ(latitude, 0); 892 args1.Replace("longitude", "10.0"); // 10.0 is test longitude value 893 args1.Replace("latitude", "-91.0"); // -91 is test latitude value 894 LocationCommand command2(type, args1, *socket); 895 command2.CheckAndRun(); 896 latitude = SharedData<double>::GetData(SharedDataType::LATITUDE); 897 EXPECT_NE(latitude, -91.0); // -91 is test longitude value 898 args1.Replace("latitude", "91.0"); // 91 is test latitude value 899 LocationCommand command3(type, args1, *socket); 900 command3.CheckAndRun(); 901 latitude = SharedData<double>::GetData(SharedDataType::LATITUDE); 902 EXPECT_NE(latitude, 91); // 91 is test longitude value 903 args1.Replace("latitude", "10.0"); // 10.0 is test latitude value 904 args1.Replace("longitude", "-181.0"); // -181 is test longitude value 905 LocationCommand command4(type, args1, *socket); 906 command4.CheckAndRun(); 907 double longitude = SharedData<double>::GetData(SharedDataType::LONGITUDE); 908 EXPECT_NE(longitude, -181); // -181 is test longitude value 909 args1.Replace("longitude", "181.0"); // 181 is test longitude value 910 LocationCommand command5(type, args1, *socket); 911 command5.CheckAndRun(); 912 longitude = SharedData<double>::GetData(SharedDataType::LONGITUDE); 913 EXPECT_NE(longitude, 181); // 181 is test longitude value 914 } 915 TEST_F(CommandLineTest,LocationCommandSetTest)916 TEST_F(CommandLineTest, LocationCommandSetTest) 917 { 918 std::string msg1 = R"({"latitude":"10.9023142","longitude":"56.3043242"})"; 919 CommandLine::CommandType type = CommandLine::CommandType::SET; 920 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 921 LocationCommand command1(type, args1, *socket); 922 command1.CheckAndRun(); 923 double longitude = SharedData<double>::GetData(SharedDataType::LONGITUDE); 924 double latitude = SharedData<double>::GetData(SharedDataType::LATITUDE); 925 EXPECT_EQ(latitude, 10.9023142); // 10.9023142 is test longitude value 926 EXPECT_EQ(longitude, 56.3043242); // 56.3043242 is test latitude value 927 } 928 TEST_F(CommandLineTest,LocationCommandGetTest)929 TEST_F(CommandLineTest, LocationCommandGetTest) 930 { 931 CommandLine::CommandType type = CommandLine::CommandType::GET; 932 Json2::Value args2 = JsonReader::CreateNull(); 933 LocationCommand command2(type, args2, *socket); 934 g_output = false; 935 command2.CheckAndRun(); 936 EXPECT_TRUE(g_output); 937 } 938 TEST_F(CommandLineTest,KeepScreenOnStateCommandArgsTest)939 TEST_F(CommandLineTest, KeepScreenOnStateCommandArgsTest) 940 { 941 CommandLine::CommandType type = CommandLine::CommandType::SET; 942 std::string msg0 = R"({"KeepScreenOnState111":false})"; 943 Json2::Value args0 = JsonReader::ParseJsonData2(msg0); 944 KeepScreenOnStateCommand command0(type, args0, *socket); 945 command0.CheckAndRun(); 946 bool status = SharedData<bool>::GetData(SharedDataType::KEEP_SCREEN_ON); 947 EXPECT_EQ(status, true); 948 949 std::string msg1 = R"({"KeepScreenOnState":"abc"})"; 950 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 951 KeepScreenOnStateCommand command1(type, args1, *socket); 952 command1.CheckAndRun(); 953 status = SharedData<bool>::GetData(SharedDataType::KEEP_SCREEN_ON); 954 EXPECT_EQ(status, true); 955 } 956 TEST_F(CommandLineTest,KeepScreenOnStateCommandSetTest)957 TEST_F(CommandLineTest, KeepScreenOnStateCommandSetTest) 958 { 959 std::string msg1 = R"({"KeepScreenOnState":false})"; 960 CommandLine::CommandType type = CommandLine::CommandType::SET; 961 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 962 KeepScreenOnStateCommand command1(type, args1, *socket); 963 command1.CheckAndRun(); 964 bool status = SharedData<bool>::GetData(SharedDataType::KEEP_SCREEN_ON); 965 EXPECT_EQ(status, false); 966 } 967 TEST_F(CommandLineTest,KeepScreenOnStateCommandGetTest)968 TEST_F(CommandLineTest, KeepScreenOnStateCommandGetTest) 969 { 970 CommandLine::CommandType type = CommandLine::CommandType::GET; 971 Json2::Value args2 = JsonReader::CreateNull(); 972 KeepScreenOnStateCommand command2(type, args2, *socket); 973 g_output = false; 974 command2.CheckAndRun(); 975 EXPECT_TRUE(g_output); 976 } 977 TEST_F(CommandLineTest,WearingStateCommandArgsTest)978 TEST_F(CommandLineTest, WearingStateCommandArgsTest) 979 { 980 CommandLine::CommandType type = CommandLine::CommandType::SET; 981 std::string msg0 = R"({"WearingState11":false})"; 982 Json2::Value args0 = JsonReader::ParseJsonData2(msg0); 983 WearingStateCommand command0(type, args0, *socket); 984 command0.CheckAndRun(); 985 bool status = SharedData<bool>::GetData(SharedDataType::WEARING_STATE); 986 EXPECT_EQ(status, true); 987 988 std::string msg1 = R"({"WearingState":"abc"})"; 989 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 990 WearingStateCommand command1(type, args1, *socket); 991 command1.CheckAndRun(); 992 status = SharedData<bool>::GetData(SharedDataType::WEARING_STATE); 993 EXPECT_EQ(status, true); 994 } 995 TEST_F(CommandLineTest,WearingStateCommandSetTest)996 TEST_F(CommandLineTest, WearingStateCommandSetTest) 997 { 998 std::string msg1 = R"({"WearingState":false})"; 999 CommandLine::CommandType type = CommandLine::CommandType::SET; 1000 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 1001 WearingStateCommand command1(type, args1, *socket); 1002 command1.CheckAndRun(); 1003 bool status = SharedData<bool>::GetData(SharedDataType::WEARING_STATE); 1004 EXPECT_EQ(status, false); 1005 } 1006 TEST_F(CommandLineTest,WearingStateCommandGetTest)1007 TEST_F(CommandLineTest, WearingStateCommandGetTest) 1008 { 1009 CommandLine::CommandType type = CommandLine::CommandType::GET; 1010 Json2::Value args2 = JsonReader::CreateNull(); 1011 WearingStateCommand command2(type, args2, *socket); 1012 g_output = false; 1013 command2.CheckAndRun(); 1014 EXPECT_TRUE(g_output); 1015 } 1016 TEST_F(CommandLineTest,BrightnessModeCommandArgsTest)1017 TEST_F(CommandLineTest, BrightnessModeCommandArgsTest) 1018 { 1019 CommandLine::CommandType type = CommandLine::CommandType::SET; 1020 std::string msg0 = R"({"BrightnessMode111":1})"; 1021 Json2::Value args0 = JsonReader::ParseJsonData2(msg0); 1022 BrightnessModeCommand command0(type, args0, *socket); 1023 command0.CheckAndRun(); 1024 uint8_t brightness = SharedData<uint8_t>::GetData(SharedDataType::BRIGHTNESS_MODE); 1025 EXPECT_EQ(brightness, 0); // 0 is default brightness 1026 1027 std::string msg1 = R"({"BrightnessMode":"abc"})"; 1028 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 1029 BrightnessModeCommand command1(type, args1, *socket); 1030 command1.CheckAndRun(); 1031 brightness = SharedData<uint8_t>::GetData(SharedDataType::BRIGHTNESS_MODE); 1032 EXPECT_EQ(brightness, 0); // 0 is default brightness 1033 1034 msg1 = R"({"BrightnessMode":-1})"; 1035 Json2::Value args2 = JsonReader::ParseJsonData2(msg1); 1036 BrightnessModeCommand command2(type, args2, *socket); 1037 command2.CheckAndRun(); 1038 brightness = SharedData<uint8_t>::GetData(SharedDataType::BRIGHTNESS_MODE); 1039 EXPECT_NE(brightness, -1); // -1 is test brightness value 1040 1041 msg1 = R"({"BrightnessMode":2})"; 1042 Json2::Value args3 = JsonReader::ParseJsonData2(msg1); 1043 BrightnessModeCommand command3(type, args3, *socket); 1044 command3.CheckAndRun(); 1045 brightness = SharedData<uint8_t>::GetData(SharedDataType::BRIGHTNESS_MODE); 1046 EXPECT_NE(brightness, 2); // 2 is test brightness value 1047 } 1048 TEST_F(CommandLineTest,BrightnessModeCommandSetTest)1049 TEST_F(CommandLineTest, BrightnessModeCommandSetTest) 1050 { 1051 std::string msg1 = R"({"BrightnessMode":1})"; 1052 CommandLine::CommandType type = CommandLine::CommandType::SET; 1053 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 1054 BrightnessModeCommand command1(type, args1, *socket); 1055 command1.CheckAndRun(); 1056 uint8_t brightness = SharedData<uint8_t>::GetData(SharedDataType::BRIGHTNESS_MODE); 1057 EXPECT_EQ(brightness, 1); // 1 is default brightness 1058 } 1059 TEST_F(CommandLineTest,BrightnessModeCommandGetTest)1060 TEST_F(CommandLineTest, BrightnessModeCommandGetTest) 1061 { 1062 CommandLine::CommandType type = CommandLine::CommandType::GET; 1063 Json2::Value args2 = JsonReader::CreateNull(); 1064 BrightnessModeCommand command2(type, args2, *socket); 1065 g_output = false; 1066 command2.CheckAndRun(); 1067 EXPECT_TRUE(g_output); 1068 } 1069 TEST_F(CommandLineTest,ChargeModeCommandArgsTest)1070 TEST_F(CommandLineTest, ChargeModeCommandArgsTest) 1071 { 1072 CommandLine::CommandType type = CommandLine::CommandType::SET; 1073 std::string msg0 = R"({"ChargeMode111":1})"; 1074 Json2::Value args0 = JsonReader::ParseJsonData2(msg0); 1075 ChargeModeCommand command0(type, args0, *socket); 1076 command0.CheckAndRun(); 1077 uint8_t mode = SharedData<uint8_t>::GetData(SharedDataType::BATTERY_STATUS); 1078 EXPECT_EQ(mode, 0); // 0 is default mode 1079 1080 std::string msg1 = R"({"ChargeMode":"abc"})"; 1081 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 1082 ChargeModeCommand command1(type, args1, *socket); 1083 command1.CheckAndRun(); 1084 mode = SharedData<uint8_t>::GetData(SharedDataType::BATTERY_STATUS); 1085 EXPECT_EQ(mode, 0); // 0 is default mode 1086 1087 msg1 = R"({"ChargeMode":-1})"; 1088 Json2::Value args2 = JsonReader::ParseJsonData2(msg1); 1089 ChargeModeCommand command2(type, args2, *socket); 1090 command2.CheckAndRun(); 1091 mode = SharedData<uint8_t>::GetData(SharedDataType::BATTERY_STATUS); 1092 EXPECT_NE(mode, -1); // -1 is test mode value 1093 1094 msg1 = R"({"ChargeMode":2})"; 1095 Json2::Value args3 = JsonReader::ParseJsonData2(msg1); 1096 ChargeModeCommand command3(type, args3, *socket); 1097 command3.CheckAndRun(); 1098 mode = SharedData<uint8_t>::GetData(SharedDataType::BATTERY_STATUS); 1099 EXPECT_NE(mode, 2); // 2 is test mode value 1100 } 1101 TEST_F(CommandLineTest,ChargeModeCommandSetTest)1102 TEST_F(CommandLineTest, ChargeModeCommandSetTest) 1103 { 1104 std::string msg1 = R"({"ChargeMode":1})"; 1105 CommandLine::CommandType type = CommandLine::CommandType::SET; 1106 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 1107 ChargeModeCommand command1(type, args1, *socket); 1108 command1.CheckAndRun(); 1109 uint8_t mode = SharedData<uint8_t>::GetData(SharedDataType::BRIGHTNESS_MODE); 1110 EXPECT_EQ(mode, 1); // 1 is default mode 1111 } 1112 TEST_F(CommandLineTest,ChargeModeCommandGetTest)1113 TEST_F(CommandLineTest, ChargeModeCommandGetTest) 1114 { 1115 CommandLine::CommandType type = CommandLine::CommandType::GET; 1116 Json2::Value args2 = JsonReader::CreateNull(); 1117 ChargeModeCommand command2(type, args2, *socket); 1118 g_output = false; 1119 command2.CheckAndRun(); 1120 EXPECT_TRUE(g_output); 1121 } 1122 TEST_F(CommandLineTest,BrightnessCommandArgsTest)1123 TEST_F(CommandLineTest, BrightnessCommandArgsTest) 1124 { 1125 CommandLine::CommandType type = CommandLine::CommandType::SET; 1126 std::string msg0 = R"({"Brightness111":100})"; 1127 Json2::Value args0 = JsonReader::ParseJsonData2(msg0); 1128 BrightnessCommand command0(type, args0, *socket); 1129 command0.CheckAndRun(); 1130 uint8_t mode = SharedData<uint8_t>::GetData(SharedDataType::BRIGHTNESS_VALUE); 1131 EXPECT_EQ(mode, 255); // 255 is default mode 1132 1133 std::string msg1 = R"({"Brightness":"abc"})"; 1134 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 1135 BrightnessCommand command1(type, args1, *socket); 1136 command1.CheckAndRun(); 1137 mode = SharedData<uint8_t>::GetData(SharedDataType::BRIGHTNESS_VALUE); 1138 EXPECT_EQ(mode, 255); // 255 is default mode 1139 1140 msg1 = R"({"Brightness":256})"; 1141 Json2::Value args2 = JsonReader::ParseJsonData2(msg1); 1142 BrightnessCommand command2(type, args2, *socket); 1143 command2.CheckAndRun(); 1144 mode = SharedData<uint8_t>::GetData(SharedDataType::BRIGHTNESS_VALUE); 1145 EXPECT_NE(mode, 256); // 256 is test mode value 1146 1147 msg1 = R"({"Brightness":0})"; 1148 Json2::Value args3 = JsonReader::ParseJsonData2(msg1); 1149 BrightnessCommand command3(type, args3, *socket); 1150 command3.CheckAndRun(); 1151 mode = SharedData<uint8_t>::GetData(SharedDataType::BRIGHTNESS_VALUE); 1152 EXPECT_NE(mode, 0); // 0 is test mode value 1153 } 1154 TEST_F(CommandLineTest,BrightnessCommandSetTest)1155 TEST_F(CommandLineTest, BrightnessCommandSetTest) 1156 { 1157 std::string msg1 = R"({"Brightness":100})"; 1158 CommandLine::CommandType type = CommandLine::CommandType::SET; 1159 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 1160 BrightnessCommand command1(type, args1, *socket); 1161 command1.CheckAndRun(); 1162 uint8_t mode = SharedData<uint8_t>::GetData(SharedDataType::BRIGHTNESS_VALUE); 1163 EXPECT_EQ(mode, 100); // 100 is test mode 1164 } 1165 TEST_F(CommandLineTest,BrightnessCommandGetTest)1166 TEST_F(CommandLineTest, BrightnessCommandGetTest) 1167 { 1168 CommandLine::CommandType type = CommandLine::CommandType::GET; 1169 Json2::Value args2 = JsonReader::CreateNull(); 1170 BrightnessCommand command2(type, args2, *socket); 1171 g_output = false; 1172 command2.CheckAndRun(); 1173 EXPECT_TRUE(g_output); 1174 } 1175 TEST_F(CommandLineTest,HeartRateCommandArgsTest)1176 TEST_F(CommandLineTest, HeartRateCommandArgsTest) 1177 { 1178 CommandLine::CommandType type = CommandLine::CommandType::SET; 1179 std::string msg0 = R"({"HeartRate111":100})"; 1180 Json2::Value args0 = JsonReader::ParseJsonData2(msg0); 1181 HeartRateCommand command0(type, args0, *socket); 1182 command0.CheckAndRun(); 1183 uint8_t mode = SharedData<uint8_t>::GetData(SharedDataType::HEARTBEAT_VALUE); 1184 EXPECT_EQ(mode, 80); // 80 is default mode 1185 1186 std::string msg1 = R"({"HeartRate":"abc"})"; 1187 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 1188 HeartRateCommand command1(type, args1, *socket); 1189 command1.CheckAndRun(); 1190 mode = SharedData<uint8_t>::GetData(SharedDataType::HEARTBEAT_VALUE); 1191 EXPECT_EQ(mode, 80); // 80 is default mode 1192 1193 msg1 = R"({"HeartRate":256})"; 1194 Json2::Value args2 = JsonReader::ParseJsonData2(msg1); 1195 HeartRateCommand command2(type, args2, *socket); 1196 command2.CheckAndRun(); 1197 mode = SharedData<uint8_t>::GetData(SharedDataType::HEARTBEAT_VALUE); 1198 EXPECT_NE(mode, 256); // 256 is test mode value 1199 1200 msg1 = R"({"HeartRate":-1})"; 1201 Json2::Value args3 = JsonReader::ParseJsonData2(msg1); 1202 HeartRateCommand command3(type, args3, *socket); 1203 command3.CheckAndRun(); 1204 mode = SharedData<uint8_t>::GetData(SharedDataType::HEARTBEAT_VALUE); 1205 EXPECT_NE(mode, -1); // -1 is test mode value 1206 } 1207 TEST_F(CommandLineTest,HeartRateCommandSetTest)1208 TEST_F(CommandLineTest, HeartRateCommandSetTest) 1209 { 1210 std::string msg1 = R"({"HeartRate":100})"; 1211 CommandLine::CommandType type = CommandLine::CommandType::SET; 1212 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 1213 HeartRateCommand command1(type, args1, *socket); 1214 command1.CheckAndRun(); 1215 uint8_t mode = SharedData<uint8_t>::GetData(SharedDataType::HEARTBEAT_VALUE); 1216 EXPECT_EQ(mode, 100); // 100 is test mode 1217 } 1218 TEST_F(CommandLineTest,HeartRateCommandGetTest)1219 TEST_F(CommandLineTest, HeartRateCommandGetTest) 1220 { 1221 CommandLine::CommandType type = CommandLine::CommandType::GET; 1222 Json2::Value args2 = JsonReader::CreateNull(); 1223 HeartRateCommand command2(type, args2, *socket); 1224 g_output = false; 1225 command2.CheckAndRun(); 1226 EXPECT_TRUE(g_output); 1227 } 1228 TEST_F(CommandLineTest,StepCountCommandArgsTest)1229 TEST_F(CommandLineTest, StepCountCommandArgsTest) 1230 { 1231 CommandLine::CommandType type = CommandLine::CommandType::SET; 1232 std::string msg0 = R"({"StepCount111":100})"; 1233 Json2::Value args0 = JsonReader::ParseJsonData2(msg0); 1234 StepCountCommand command0(type, args0, *socket); 1235 command0.CheckAndRun(); 1236 uint32_t mode = SharedData<uint32_t>::GetData(SharedDataType::SUMSTEP_VALUE); 1237 EXPECT_EQ(mode, 0); // 0 is default mode 1238 1239 std::string msg1 = R"({"StepCount":"abc"})"; 1240 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 1241 StepCountCommand command1(type, args1, *socket); 1242 command1.CheckAndRun(); 1243 mode = SharedData<uint32_t>::GetData(SharedDataType::SUMSTEP_VALUE); 1244 EXPECT_EQ(mode, 0); // 0 is default mode 1245 1246 msg1 = R"({"StepCount":10000000})"; 1247 Json2::Value args2 = JsonReader::ParseJsonData2(msg1); 1248 StepCountCommand command2(type, args2, *socket); 1249 command2.CheckAndRun(); 1250 mode = SharedData<uint32_t>::GetData(SharedDataType::SUMSTEP_VALUE); 1251 EXPECT_NE(mode, 10000000); // 10000000 is test mode value 1252 1253 msg1 = R"({"StepCount":-1})"; 1254 Json2::Value args3 = JsonReader::ParseJsonData2(msg1); 1255 StepCountCommand command3(type, args3, *socket); 1256 command3.CheckAndRun(); 1257 mode = SharedData<uint32_t>::GetData(SharedDataType::SUMSTEP_VALUE); 1258 EXPECT_NE(mode, -1); // -1 is test mode value 1259 } 1260 TEST_F(CommandLineTest,StepCountCommandSetTest)1261 TEST_F(CommandLineTest, StepCountCommandSetTest) 1262 { 1263 std::string msg1 = R"({"StepCount":100})"; 1264 CommandLine::CommandType type = CommandLine::CommandType::SET; 1265 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 1266 StepCountCommand command1(type, args1, *socket); 1267 command1.CheckAndRun(); 1268 uint8_t mode = SharedData<uint32_t>::GetData(SharedDataType::SUMSTEP_VALUE); 1269 EXPECT_EQ(mode, 100); // 100 is test mode 1270 } 1271 TEST_F(CommandLineTest,StepCountCommandGetTest)1272 TEST_F(CommandLineTest, StepCountCommandGetTest) 1273 { 1274 CommandLine::CommandType type = CommandLine::CommandType::GET; 1275 Json2::Value args2 = JsonReader::CreateNull(); 1276 StepCountCommand command2(type, args2, *socket); 1277 g_output = false; 1278 command2.CheckAndRun(); 1279 EXPECT_TRUE(g_output); 1280 } 1281 TEST_F(CommandLineTest,DistributedCommunicationsCommandTest)1282 TEST_F(CommandLineTest, DistributedCommunicationsCommandTest) 1283 { 1284 CommandLine::CommandType type = CommandLine::CommandType::ACTION; 1285 std::string msg1 = R"({"DeviceId":"68-05-CA-90-9A-66","bundleName":"abc", 1286 "abilityName":"hello"})"; 1287 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 1288 DistributedCommunicationsCommand command1(type, args1, *socket); 1289 g_sendVirtualMessage = false; 1290 command1.CheckAndRun(); 1291 EXPECT_FALSE(g_sendVirtualMessage); 1292 1293 std::string msg2 = R"({"DeviceId":"68-05-CA-90-9A-66","bundleName":"abc", 1294 "abilityName":"hello"},"message":"")"; 1295 Json2::Value args2 = JsonReader::ParseJsonData2(msg2); 1296 DistributedCommunicationsCommand command2(type, args2, *socket); 1297 g_sendVirtualMessage = false; 1298 command2.CheckAndRun(); 1299 EXPECT_FALSE(g_sendVirtualMessage); 1300 1301 std::string msg3 = R"({"DeviceId":"68-05-CA-90-9A-66","bundleName":"abc", 1302 "abilityName":"hello","message":"{ action:'GET_WEATHER',city:'HangZhou' }"})"; 1303 Json2::Value args3 = JsonReader::ParseJsonData2(msg3); 1304 DistributedCommunicationsCommand command3(type, args3, *socket); 1305 g_sendVirtualMessage = false; 1306 command3.CheckAndRun(); 1307 EXPECT_TRUE(g_sendVirtualMessage); 1308 1309 std::string msg4 = R"({"DeviceId" : "68-05-CA-90-9A-66", "bundleName" : "abc", 1310 "abilityName" : "hello", "message" : ""})"; 1311 Json2::Value args4 = JsonReader::ParseJsonData2(msg4); 1312 DistributedCommunicationsCommand command4(type, args4, *socket); 1313 g_sendVirtualMessage = false; 1314 command4.CheckAndRun(); 1315 EXPECT_FALSE(g_sendVirtualMessage); 1316 } 1317 TEST_F(CommandLineTest,DistributedCommunicationsCommandTest2)1318 TEST_F(CommandLineTest, DistributedCommunicationsCommandTest2) 1319 { 1320 CommandLine::CommandType type = CommandLine::CommandType::ACTION; 1321 std::string msg = R"({"DeviceId" : "68-05-CA-90-9A-66", "bundleName" : "abc", 1322 "abilityName" : "hello", "message" : "{ action : 'GET_WEATHER', city : 'HangZhou' }"})"; 1323 Json2::Value args = JsonReader::ParseJsonData2(msg); 1324 DistributedCommunicationsCommand command(type, args, *socket); 1325 std::vector<char> vec = command.StringToCharVector("123"); 1326 int size = 4; 1327 EXPECT_EQ(vec.size(), size); 1328 } 1329 TEST_F(CommandLineTest,MouseWheelCommandTest)1330 TEST_F(CommandLineTest, MouseWheelCommandTest) 1331 { 1332 std::string msg1 = R"({"rotate":"aaa"})"; 1333 CommandLine::CommandType type = CommandLine::CommandType::ACTION; 1334 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 1335 MouseWheelCommand command1(type, args1, *socket); 1336 command1.CheckAndRun(); 1337 EXPECT_EQ(MouseWheelImpl::GetInstance().rotate, 0); // 0 is default value 1338 1339 std::string msg2 = R"({"rotate":100})"; 1340 Json2::Value args2 = JsonReader::ParseJsonData2(msg2); 1341 MouseWheelCommand command2(type, args2, *socket); 1342 command2.CheckAndRun(); 1343 EXPECT_EQ(MouseWheelImpl::GetInstance().GetRotate(), 100); // 100 is test mode 1344 1345 msg2 = R"({"rotate":150})"; 1346 Json2::Value args3 = JsonReader::ParseJsonData2(msg2); 1347 CommandParser::GetInstance().screenMode = CommandParser::ScreenMode::STATIC; 1348 MouseWheelCommand command3(type, args3, *socket); 1349 command3.CheckAndRun(); 1350 CommandParser::GetInstance().screenMode = CommandParser::ScreenMode::DYNAMIC; 1351 EXPECT_NE(MouseWheelImpl::GetInstance().GetRotate(), 150); // 100 is test mode 1352 } 1353 TEST_F(CommandLineTest,TouchPressCommandArgsTest)1354 TEST_F(CommandLineTest, TouchPressCommandArgsTest) 1355 { 1356 CommandLine::CommandType type = CommandLine::CommandType::ACTION; 1357 std::string msg1 = R"({"x":365,"y":"abc","duration":""})"; 1358 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 1359 TouchPressCommand command1(type, args1, *socket); 1360 g_dispatchOsTouchEvent = false; 1361 command1.CheckAndRun(); 1362 EXPECT_FALSE(g_dispatchOsTouchEvent); 1363 } 1364 TEST_F(CommandLineTest,TouchPressCommandArgsRangeTest)1365 TEST_F(CommandLineTest, TouchPressCommandArgsRangeTest) 1366 { 1367 CommandLine::CommandType type = CommandLine::CommandType::ACTION; 1368 std::string msg1 = R"({"x":365,"y":15000,"duration":""})"; 1369 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 1370 TouchPressCommand command1(type, args1, *socket); 1371 g_dispatchOsTouchEvent = false; 1372 command1.CheckAndRun(); 1373 EXPECT_FALSE(g_dispatchOsTouchEvent); 1374 1375 std::string msg2 = R"({"x":-1,"y":15000,"duration":""})"; 1376 Json2::Value args2 = JsonReader::ParseJsonData2(msg2); 1377 TouchPressCommand command2(type, args2, *socket); 1378 g_dispatchOsTouchEvent = false; 1379 command2.CheckAndRun(); 1380 EXPECT_FALSE(g_dispatchOsTouchEvent); 1381 1382 std::string msg3 = R"({"x":15000,"y":365,"duration":""})"; 1383 Json2::Value args3 = JsonReader::ParseJsonData2(msg3); 1384 TouchPressCommand command3(type, args3, *socket); 1385 g_dispatchOsTouchEvent = false; 1386 command3.CheckAndRun(); 1387 EXPECT_FALSE(g_dispatchOsTouchEvent); 1388 1389 std::string msg4 = R"({"x":15000,"y":-1,"duration":""})"; 1390 Json2::Value args4 = JsonReader::ParseJsonData2(msg4); 1391 TouchPressCommand command4(type, args4, *socket); 1392 g_dispatchOsTouchEvent = false; 1393 command4.CheckAndRun(); 1394 EXPECT_FALSE(g_dispatchOsTouchEvent); 1395 } 1396 TEST_F(CommandLineTest,TouchPressCommandArgsCorrectTest)1397 TEST_F(CommandLineTest, TouchPressCommandArgsCorrectTest) 1398 { 1399 CommandLine::CommandType type = CommandLine::CommandType::ACTION; 1400 std::string msg1 = R"({"x":365,"y":1076,"duration":""})"; 1401 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 1402 TouchPressCommand command1(type, args1, *socket); 1403 g_dispatchOsTouchEvent = false; 1404 command1.CheckAndRun(); 1405 EXPECT_TRUE(g_dispatchOsTouchEvent); 1406 1407 TouchPressCommand command2(type, args1, *socket); 1408 CommandParser::GetInstance().screenMode = CommandParser::ScreenMode::STATIC; 1409 g_dispatchOsTouchEvent = false; 1410 command2.CheckAndRun(); 1411 CommandParser::GetInstance().screenMode = CommandParser::ScreenMode::DYNAMIC; 1412 EXPECT_FALSE(g_dispatchOsTouchEvent); 1413 } 1414 TEST_F(CommandLineTest,TouchReleaseCommandArgsTest)1415 TEST_F(CommandLineTest, TouchReleaseCommandArgsTest) 1416 { 1417 CommandLine::CommandType type = CommandLine::CommandType::ACTION; 1418 std::string msg1 = R"({"x":365,"y":"abc"})"; 1419 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 1420 TouchReleaseCommand command1(type, args1, *socket); 1421 g_dispatchOsTouchEvent = false; 1422 command1.CheckAndRun(); 1423 EXPECT_FALSE(g_dispatchOsTouchEvent); 1424 } 1425 TEST_F(CommandLineTest,TouchReleaseCommandArgsRangeTest)1426 TEST_F(CommandLineTest, TouchReleaseCommandArgsRangeTest) 1427 { 1428 CommandLine::CommandType type = CommandLine::CommandType::ACTION; 1429 std::string msg1 = R"({"x":365,"y":15000})"; 1430 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 1431 TouchReleaseCommand command1(type, args1, *socket); 1432 g_dispatchOsTouchEvent = false; 1433 command1.CheckAndRun(); 1434 EXPECT_FALSE(g_dispatchOsTouchEvent); 1435 1436 std::string msg2 = R"({"x":-1,"y":15000})"; 1437 Json2::Value args2 = JsonReader::ParseJsonData2(msg2); 1438 TouchReleaseCommand command2(type, args2, *socket); 1439 g_dispatchOsTouchEvent = false; 1440 command2.CheckAndRun(); 1441 EXPECT_FALSE(g_dispatchOsTouchEvent); 1442 1443 std::string msg3 = R"({"x":15000,"y":365})"; 1444 Json2::Value args3 = JsonReader::ParseJsonData2(msg3); 1445 TouchReleaseCommand command3(type, args3, *socket); 1446 g_dispatchOsTouchEvent = false; 1447 command3.CheckAndRun(); 1448 EXPECT_FALSE(g_dispatchOsTouchEvent); 1449 1450 std::string msg4 = R"({"x":15000,"y":-1})"; 1451 Json2::Value args4 = JsonReader::ParseJsonData2(msg4); 1452 TouchReleaseCommand command4(type, args4, *socket); 1453 g_dispatchOsTouchEvent = false; 1454 command4.CheckAndRun(); 1455 EXPECT_FALSE(g_dispatchOsTouchEvent); 1456 } 1457 TEST_F(CommandLineTest,TouchReleaseCommandArgsCorrectTest)1458 TEST_F(CommandLineTest, TouchReleaseCommandArgsCorrectTest) 1459 { 1460 CommandLine::CommandType type = CommandLine::CommandType::ACTION; 1461 std::string msg1 = R"({"x":365,"y":1076})"; 1462 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 1463 TouchReleaseCommand command1(type, args1, *socket); 1464 g_dispatchOsTouchEvent = false; 1465 command1.CheckAndRun(); 1466 EXPECT_TRUE(g_dispatchOsTouchEvent); 1467 1468 TouchReleaseCommand command2(type, args1, *socket); 1469 CommandParser::GetInstance().screenMode = CommandParser::ScreenMode::STATIC; 1470 g_dispatchOsTouchEvent = false; 1471 command2.CheckAndRun(); 1472 CommandParser::GetInstance().screenMode = CommandParser::ScreenMode::DYNAMIC; 1473 EXPECT_FALSE(g_dispatchOsTouchEvent); 1474 } 1475 TEST_F(CommandLineTest,TouchMoveCommandArgsTest)1476 TEST_F(CommandLineTest, TouchMoveCommandArgsTest) 1477 { 1478 CommandLine::CommandType type = CommandLine::CommandType::ACTION; 1479 std::string msg1 = R"({"x":365,"y":"abc"})"; 1480 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 1481 TouchMoveCommand command1(type, args1, *socket); 1482 g_dispatchOsTouchEvent = false; 1483 command1.CheckAndRun(); 1484 EXPECT_FALSE(g_dispatchOsTouchEvent); 1485 } 1486 TEST_F(CommandLineTest,TouchMoveCommandArgsRangeTest)1487 TEST_F(CommandLineTest, TouchMoveCommandArgsRangeTest) 1488 { 1489 CommandLine::CommandType type = CommandLine::CommandType::ACTION; 1490 std::string msg1 = R"({"x":365,"y":15000})"; 1491 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 1492 TouchMoveCommand command1(type, args1, *socket); 1493 g_dispatchOsTouchEvent = false; 1494 command1.CheckAndRun(); 1495 EXPECT_FALSE(g_dispatchOsTouchEvent); 1496 1497 std::string msg2 = R"({"x":-1,"y":15000})"; 1498 Json2::Value args2 = JsonReader::ParseJsonData2(msg2); 1499 TouchMoveCommand command2(type, args2, *socket); 1500 g_dispatchOsTouchEvent = false; 1501 command2.CheckAndRun(); 1502 EXPECT_FALSE(g_dispatchOsTouchEvent); 1503 1504 std::string msg3 = R"({"x":15000,"y":365})"; 1505 Json2::Value args3 = JsonReader::ParseJsonData2(msg3); 1506 TouchMoveCommand command3(type, args3, *socket); 1507 g_dispatchOsTouchEvent = false; 1508 command3.CheckAndRun(); 1509 EXPECT_FALSE(g_dispatchOsTouchEvent); 1510 1511 std::string msg4 = R"({"x":15000,"y":-1})"; 1512 Json2::Value args4 = JsonReader::ParseJsonData2(msg4); 1513 TouchMoveCommand command4(type, args4, *socket); 1514 g_dispatchOsTouchEvent = false; 1515 command4.CheckAndRun(); 1516 EXPECT_FALSE(g_dispatchOsTouchEvent); 1517 } 1518 TEST_F(CommandLineTest,TouchMoveCommandArgsCorrectTest)1519 TEST_F(CommandLineTest, TouchMoveCommandArgsCorrectTest) 1520 { 1521 CommandLine::CommandType type = CommandLine::CommandType::ACTION; 1522 std::string msg1 = R"({"x":365,"y":1076})"; 1523 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 1524 TouchMoveCommand command1(type, args1, *socket); 1525 g_dispatchOsTouchEvent = false; 1526 command1.CheckAndRun(); 1527 EXPECT_TRUE(g_dispatchOsTouchEvent); 1528 1529 TouchMoveCommand command2(type, args1, *socket); 1530 CommandParser::GetInstance().screenMode = CommandParser::ScreenMode::STATIC; 1531 g_dispatchOsTouchEvent = false; 1532 command2.CheckAndRun(); 1533 CommandParser::GetInstance().screenMode = CommandParser::ScreenMode::DYNAMIC; 1534 EXPECT_FALSE(g_dispatchOsTouchEvent); 1535 } 1536 TEST_F(CommandLineTest,LanguageCommandArgsTest)1537 TEST_F(CommandLineTest, LanguageCommandArgsTest) 1538 { 1539 CommandLine::CommandType type = CommandLine::CommandType::SET; 1540 std::string msg1 = R"({"Language":111})"; 1541 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 1542 LanguageCommand command1(type, args1, *socket); 1543 command1.CheckAndRun(); 1544 std::string language = SharedData<string>::GetData(SharedDataType::LANGUAGE); 1545 EXPECT_EQ(language, "zh-CN"); // zh-CN is default value 1546 1547 CommandParser::GetInstance().deviceType = "liteWearable"; 1548 std::string msg2 = R"({"Language":"ar_AE"})"; 1549 Json2::Value args2 = JsonReader::ParseJsonData2(msg2); 1550 LanguageCommand command2(type, args2, *socket); 1551 command2.CheckAndRun(); 1552 language = SharedData<string>::GetData(SharedDataType::LANGUAGE); 1553 EXPECT_NE(language, "ar_AE"); 1554 1555 CommandParser::GetInstance().deviceType = "phone"; 1556 std::string msg3 = R"({"Language":"aa_BB"})"; 1557 Json2::Value args3 = JsonReader::ParseJsonData2(msg3); 1558 LanguageCommand command3(type, args3, *socket); 1559 command3.CheckAndRun(); 1560 language = SharedData<string>::GetData(SharedDataType::LANGUAGE); 1561 EXPECT_NE(language, "aa_BB"); 1562 } 1563 TEST_F(CommandLineTest,LanguageCommandSetTest)1564 TEST_F(CommandLineTest, LanguageCommandSetTest) 1565 { 1566 CommandParser::GetInstance().deviceType = "liteWearable"; 1567 CommandLine::CommandType type = CommandLine::CommandType::SET; 1568 std::string msg1 = R"({"Language":"en-US"})"; 1569 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 1570 LanguageCommand command1(type, args1, *socket); 1571 command1.CheckAndRun(); 1572 std::string language = SharedData<string>::GetData(SharedDataType::LANGUAGE); 1573 EXPECT_EQ(language, "en-US"); 1574 1575 CommandParser::GetInstance().deviceType = "phone"; 1576 std::string msg2 = R"({"Language":"en_US"})"; 1577 Json2::Value args2 = JsonReader::ParseJsonData2(msg2); 1578 LanguageCommand command2(type, args2, *socket); 1579 command2.CheckAndRun(); 1580 language = SharedData<string>::GetData(SharedDataType::LANGUAGE); 1581 EXPECT_EQ(language, "en_US"); 1582 } 1583 TEST_F(CommandLineTest,LanguageCommandGetTest)1584 TEST_F(CommandLineTest, LanguageCommandGetTest) 1585 { 1586 CommandLine::CommandType type = CommandLine::CommandType::GET; 1587 Json2::Value args2 = JsonReader::CreateNull(); 1588 LanguageCommand command2(type, args2, *socket); 1589 g_output = false; 1590 command2.CheckAndRun(); 1591 EXPECT_TRUE(g_output); 1592 } 1593 TEST_F(CommandLineTest,SupportedLanguagesCommandTest)1594 TEST_F(CommandLineTest, SupportedLanguagesCommandTest) 1595 { 1596 CommandParser::GetInstance().deviceType = "liteWearable"; 1597 CommandLine::CommandType type = CommandLine::CommandType::GET; 1598 Json2::Value args1 = JsonReader::CreateNull(); 1599 SupportedLanguagesCommand command1(type, args1, *socket); 1600 g_output = false; 1601 command1.CheckAndRun(); 1602 EXPECT_TRUE(g_output); 1603 1604 CommandParser::GetInstance().deviceType = "phone"; 1605 SupportedLanguagesCommand command2(type, args1, *socket); 1606 command2.CheckAndRun(); 1607 g_output = false; 1608 command2.CheckAndRun(); 1609 EXPECT_TRUE(g_output); 1610 } 1611 TEST_F(CommandLineTest,ExitCommandTest)1612 TEST_F(CommandLineTest, ExitCommandTest) 1613 { 1614 CommandLine::CommandType type = CommandLine::CommandType::ACTION; 1615 Interrupter::isInterrupt = false; 1616 Json2::Value args1 = JsonReader::CreateNull(); 1617 ExitCommand command1(type, args1, *socket); 1618 g_output = false; 1619 command1.CheckAndRun(); 1620 EXPECT_TRUE(Interrupter::isInterrupt); 1621 EXPECT_TRUE(g_output); 1622 } 1623 TEST_F(CommandLineTest,RestartCommandTest)1624 TEST_F(CommandLineTest, RestartCommandTest) 1625 { 1626 CommandLine::CommandType type = CommandLine::CommandType::GET; 1627 Json2::Value args2 = JsonReader::CreateNull(); 1628 RestartCommand command2(type, args2, *socket); 1629 command2.RunAction(); 1630 } 1631 TEST_F(CommandLineTest,ResolutionCommandTest)1632 TEST_F(CommandLineTest, ResolutionCommandTest) 1633 { 1634 CommandLine::CommandType type = CommandLine::CommandType::SET; 1635 Json2::Value args1 = JsonReader::CreateNull(); 1636 ResolutionCommand command1(type, args1, *socket); 1637 g_output = false; 1638 command1.CheckAndRun(); 1639 EXPECT_TRUE(g_output); 1640 } 1641 TEST_F(CommandLineTest,DeviceTypeCommandTest)1642 TEST_F(CommandLineTest, DeviceTypeCommandTest) 1643 { 1644 CommandLine::CommandType type = CommandLine::CommandType::SET; 1645 Json2::Value args1 = JsonReader::CreateNull(); 1646 DeviceTypeCommand command1(type, args1, *socket); 1647 g_output = false; 1648 command1.CheckAndRun(); 1649 EXPECT_TRUE(g_output); 1650 } 1651 TEST_F(CommandLineTest,AvoidAreaCommandTest)1652 TEST_F(CommandLineTest, AvoidAreaCommandTest) 1653 { 1654 CommandLine::CommandType type = CommandLine::CommandType::SET; 1655 std::string msg1 = R"({"topRect":{"posX":0,"posY":0,"width":2340,"height":117},"bottomRect": 1656 {"bottomRect":0,"posY":0,"width":0,"height":0},"leftRect":{"posX":0,"posY":0,"width":0,"height":0}})"; 1657 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 1658 AvoidAreaCommand command1(type, args1, *socket); 1659 g_output = false; 1660 command1.CheckAndRun(); 1661 command1.RunSet(); 1662 EXPECT_TRUE(g_output); 1663 std::string msg2 = R"({"topRect":{"posX":0,"posY":0,"width":2340,"height":117},"bottomRect":{"bottomRect": 1664 0,"posY":0,"width":0,"height":0},"leftRect":{"posX":0,"posY":0,"width":0,"height":0},"rightRect":0})"; 1665 Json2::Value args2 = JsonReader::ParseJsonData2(msg2); 1666 AvoidAreaCommand command2(type, args2, *socket); 1667 g_output = false; 1668 command2.CheckAndRun(); 1669 EXPECT_TRUE(g_output); 1670 std::string msg3 = R"({"topRect":{"posX":0,"posY":0,"width":2340,"height":117},"bottomRect": 1671 {"bottomRect":0,"posY":0,"width":0,"height":0},"leftRect":{"posX":0,"posY":0,"width":0,"height":0}, 1672 "rightRect":{"posX":0,"posY":0,"width":0}})"; 1673 Json2::Value args3 = JsonReader::ParseJsonData2(msg3); 1674 AvoidAreaCommand command3(type, args3, *socket); 1675 g_output = false; 1676 command3.CheckAndRun(); 1677 EXPECT_TRUE(g_output); 1678 std::string msg4 = R"({"topRect":{"posX":0,"posY":0,"width":2340,"height":117},"bottomRect": 1679 {"bottomRect":0,"posY":0,"width":0,"height":0},"leftRect":{"posX":0,"posY":0,"width":0,"height":0}, 1680 "rightRect":{"posX":0,"posY":0,"width":0,"height":"350"}})"; 1681 Json2::Value args4 = JsonReader::ParseJsonData2(msg4); 1682 AvoidAreaCommand command4(type, args4, *socket); 1683 g_output = false; 1684 command4.CheckAndRun(); 1685 EXPECT_TRUE(g_output); 1686 std::string msg5 = R"({"topRect":{"posX":0,"posY":0,"width":2340,"height":117},"bottomRect":{"bottomRect": 1687 0,"posY":0,"width":0,"height":0},"leftRect":{"posX":0,"posY":0,"width":0,"height":0}, 1688 "rightRect":{"posX":0,"posY":0,"width":-1,"height":-1}})"; 1689 Json2::Value args5 = JsonReader::ParseJsonData2(msg5); 1690 AvoidAreaCommand command5(type, args5, *socket); 1691 g_output = false; 1692 command5.CheckAndRun(); 1693 EXPECT_TRUE(g_output); 1694 std::string msg6 = R"({"topRect":{"posX":0,"posY":0,"width":2340,"height":117},"bottomRect":{"bottomRect": 1695 0,"posY":0,"width":0,"height":0},"leftRect":{"posX":0,"posY":0,"width":0,"height":0}, 1696 "rightRect":{"posX":0,"posY":0,"width":2340,"height":84}})"; 1697 Json2::Value args6 = JsonReader::ParseJsonData2(msg6); 1698 AvoidAreaCommand command6(type, args6, *socket); 1699 g_output = false; 1700 command6.CheckAndRun(); 1701 EXPECT_TRUE(g_output); 1702 } 1703 TEST_F(CommandLineTest,AvoidAreaCommandArgsRangeTest)1704 TEST_F(CommandLineTest, AvoidAreaCommandArgsRangeTest) 1705 { 1706 CommandLine::CommandType type = CommandLine::CommandType::SET; 1707 std::string msg1 = R"({"topRect" : {"posX" :0, "posY" : 0, "width" : 2340, "height" : 117}, 1708 "bottomRect" : {"posX" : 0, "posY" : 0, "width" : 0, "height" : 0}, "leftRect" : {"posX" : 0, 1709 "posY" : 0, "width" : 0, "height" : 0}, "rightRect" : {"posX" : 0, "posY" : 0, "width" : 2340, 1710 "height" : "84"}})"; 1711 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 1712 AvoidAreaCommand command1(type, args1, *socket); 1713 g_output = false; 1714 command1.CheckAndRun(); 1715 EXPECT_TRUE(g_output); 1716 1717 std::string msg2 = R"({"topRect" : {"posX" :0, "posY" : 0, "width" : 2340, "height" : 117}, 1718 "bottomRect" : {"posX" : 0, "posY" : 0, "width" : 0, "height" : 0}, "leftRect" : {"posX" : 0, 1719 "posY" : 0, "width" : 0, "height" : 0}, "rightRect" : {"posX" : 0, "posY" : -2, "width" : 2340, 1720 "height" : 84}})"; 1721 Json2::Value args2 = JsonReader::ParseJsonData2(msg2); 1722 AvoidAreaCommand command2(type, args2, *socket); 1723 g_output = false; 1724 command2.CheckAndRun(); 1725 EXPECT_TRUE(g_output); 1726 1727 1728 std::string msg3 = R"({"topRect" : {"posX" :0, "posY" : 0, "width" : 2340, "height" : 117}, 1729 "bottomRect" : {"posX" : 0, "posY" : 0, "width" : 0, "height" : 0}, "leftRect" : {"posX" : 0, 1730 "posY" : 0, "width" : 0, "height" : 0}, "rightRect" : {"posX" : 0, "posY" : 0, "width" : 2340, 1731 "height" : 84}})"; 1732 Json2::Value args3 = JsonReader::ParseJsonData2(msg3); 1733 AvoidAreaCommand command3(type, args3, *socket); 1734 g_output = false; 1735 command3.CheckAndRun(); 1736 EXPECT_TRUE(g_output); 1737 } 1738 TEST_F(CommandLineTest,AvoidAreaChangedCommandTest)1739 TEST_F(CommandLineTest, AvoidAreaChangedCommandTest) 1740 { 1741 CommandLine::CommandType type = CommandLine::CommandType::GET; 1742 Json2::Value args2 = JsonReader::CreateNull(); 1743 AvoidAreaChangedCommand command2(type, args2, *socket); 1744 g_output = false; 1745 command2.CheckAndRun(); 1746 EXPECT_TRUE(g_output); 1747 } 1748 TEST_F(CommandLineTest,IsArgValidTest_Err)1749 TEST_F(CommandLineTest, IsArgValidTest_Err) 1750 { 1751 CommandLine::CommandType type = CommandLine::CommandType::GET; 1752 Json2::Value args1 = JsonReader::CreateObject(); 1753 CurrentRouterCommand command2(type, args1, *socket); 1754 command2.type = CommandLine::CommandType::INVALID; 1755 EXPECT_TRUE(command2.IsArgValid()); 1756 } 1757 TEST_F(CommandLineTest,ColorModeCommandArgsCorrectTest)1758 TEST_F(CommandLineTest, ColorModeCommandArgsCorrectTest) 1759 { 1760 JsAppImpl::GetInstance().colorMode = "light"; 1761 CommandLine::CommandType type = CommandLine::CommandType::SET; 1762 std::string msg = R"({"ColorMode" : "dark"})"; 1763 Json2::Value args = JsonReader::ParseJsonData2(msg); 1764 ColorModeCommand command(type, args, *socket); 1765 command.CheckAndRun(); 1766 EXPECT_EQ(JsAppImpl::GetInstance().colorMode, "dark"); 1767 } 1768 TEST_F(CommandLineTest,ColorModeCommandArgsTypeTest)1769 TEST_F(CommandLineTest, ColorModeCommandArgsTypeTest) 1770 { 1771 JsAppImpl::GetInstance().colorMode = "light"; 1772 CommandLine::CommandType type = CommandLine::CommandType::SET; 1773 Json2::Value args = JsonReader::CreateNull(); 1774 ColorModeCommand command(type, args, *socket); 1775 command.CheckAndRun(); 1776 EXPECT_EQ(JsAppImpl::GetInstance().colorMode, "light"); 1777 1778 JsAppImpl::GetInstance().colorMode = "light"; 1779 std::string msg1 = R"({"aaa" : "dark"})"; 1780 Json2::Value args1 = JsonReader::ParseJsonData2(msg1); 1781 ColorModeCommand command1(type, args1, *socket); 1782 command1.CheckAndRun(); 1783 EXPECT_EQ(JsAppImpl::GetInstance().colorMode, "light"); 1784 1785 JsAppImpl::GetInstance().colorMode = "light"; 1786 std::string msg2 = R"({"ColorMode" : 123})"; 1787 Json2::Value args2 = JsonReader::ParseJsonData2(msg2); 1788 ColorModeCommand command2(type, args2, *socket); 1789 command2.CheckAndRun(); 1790 EXPECT_EQ(JsAppImpl::GetInstance().colorMode, "light"); 1791 } 1792 TEST_F(CommandLineTest,ColorModeCommandArgsRangeTest)1793 TEST_F(CommandLineTest, ColorModeCommandArgsRangeTest) 1794 { 1795 CommandLine::CommandType type = CommandLine::CommandType::SET; 1796 JsAppImpl::GetInstance().colorMode = "light"; 1797 std::string msg2 = R"({"ColorMode" : "aaa"})"; 1798 Json2::Value args2 = JsonReader::ParseJsonData2(msg2); 1799 ColorModeCommand command2(type, args2, *socket); 1800 command2.CheckAndRun(); 1801 EXPECT_EQ(JsAppImpl::GetInstance().colorMode, "light"); 1802 } 1803 } 1804