1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17
18 #include "mmi_client.h"
19 #include "mmi_log.h"
20
21 #undef MMI_LOG_TAG
22 #define MMI_LOG_TAG "MMIClientTest"
23
24 namespace OHOS {
25 namespace MMI {
26 namespace {
27 using namespace testing::ext;
28 } // namespace
29
30 class MMIClientTest : public testing::Test {
31 public:
SetUpTestCase(void)32 static void SetUpTestCase(void) {}
TearDownTestCase(void)33 static void TearDownTestCase(void) {}
34 };
35
36 ConnectCallback connectFun;
37
38 /**
39 * @tc.name: RegisterConnectedFunction
40 * @tc.desc: Verify register connected
41 * @tc.type: FUNC
42 * @tc.require:
43 */
HWTEST_F(MMIClientTest, RegisterConnectedFunction, TestSize.Level1)44 HWTEST_F(MMIClientTest, RegisterConnectedFunction, TestSize.Level1)
45 {
46 CALL_TEST_DEBUG;
47 MMIClient mmiClient;
48 ASSERT_NO_FATAL_FAILURE(mmiClient.RegisterConnectedFunction(connectFun));
49 }
50
51 /**
52 * @tc.name: RegisterDisconnectedFunction
53 * @tc.desc: Verify register disconnected
54 * @tc.type: FUNC
55 * @tc.require:
56 */
HWTEST_F(MMIClientTest, RegisterDisconnectedFunction, TestSize.Level1)57 HWTEST_F(MMIClientTest, RegisterDisconnectedFunction, TestSize.Level1)
58 {
59 CALL_TEST_DEBUG;
60 MMIClient mmiClient;
61 ASSERT_NO_FATAL_FAILURE(mmiClient.RegisterDisconnectedFunction(connectFun));
62 }
63
64 /**
65 * @tc.name: KeyCommandHandlerTest_Start_001
66 * @tc.desc: Create a connection to server
67 * @tc.type: FUNC
68 * @tc.require:
69 */
HWTEST_F(MMIClientTest, MMIClientTest_Start__001, TestSize.Level1)70 HWTEST_F(MMIClientTest, MMIClientTest_Start__001, TestSize.Level1)
71 {
72 CALL_TEST_DEBUG;
73 std::shared_ptr<MMIClient> client = std::make_shared<MMIClient>();
74 EXPECT_TRUE(client->Start());
75 client->Stop();
76 }
77
78 /**
79 * @tc.name: KeyCommandHandlerTest_GetCurrentConnectedStatus_001
80 * @tc.desc: Get current connection status
81 * @tc.type: FUNC
82 * @tc.require:
83 */
HWTEST_F(MMIClientTest, MMIClientTest_GetCurrentConnectedStatus__001, TestSize.Level1)84 HWTEST_F(MMIClientTest, MMIClientTest_GetCurrentConnectedStatus__001, TestSize.Level1)
85 {
86 CALL_TEST_DEBUG;
87 std::shared_ptr<MMIClient> client = std::make_shared<MMIClient>();
88 client->Start();
89 EXPECT_TRUE(client->GetCurrentConnectedStatus());
90 client->Stop();
91 }
92
93 /**
94 * @tc.name: KeyCommandHandlerTest_Reconnect_001
95 * @tc.desc: Socket reconnection
96 * @tc.type: FUNC
97 * @tc.require:
98 */
HWTEST_F(MMIClientTest, MMIClientTest_Reconnect_001, TestSize.Level1)99 HWTEST_F(MMIClientTest, MMIClientTest_Reconnect_001, TestSize.Level1)
100 {
101 CALL_TEST_DEBUG;
102 std::shared_ptr<MMIClient> client = std::make_shared<MMIClient>();
103 client->Start();
104 EXPECT_FALSE(client->Reconnect());
105 client->Stop();
106 }
107
108 /**
109 * @tc.name: KeyCommandHandlerTest_OnDisconnect_001
110 * @tc.desc: Disconnected from server
111 * @tc.type: FUNC
112 * @tc.require:
113 */
HWTEST_F(MMIClientTest, MMIClientTest_OnDisconnect_001, TestSize.Level1)114 HWTEST_F(MMIClientTest, MMIClientTest_OnDisconnect_001, TestSize.Level1)
115 {
116 CALL_TEST_DEBUG;
117 std::shared_ptr<MMIClient> client = std::make_shared<MMIClient>();
118 client->Start();
119 client->OnDisconnect();
120 ASSERT_NO_FATAL_FAILURE(client->OnDisconnect());
121 client->Stop();
122 }
123 }
124 } // namespace MMI
125