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