• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 "soft_bus_client_socket_test.h"
17 #include "soft_bus_client_socket.h"
18 #include "soft_bus_manager.h"
19 #include "remote_connect_listener_manager.h"
20 
21 #include "gtest/gtest.h"
22 #include "gmock/gmock.h"
23 
24 namespace OHOS {
25 namespace UserIam {
26 namespace UserAuth {
27 using namespace testing;
28 using namespace testing::ext;
29 
SetUpTestCase()30 void SoftBusClientSocketTest::SetUpTestCase()
31 {
32 }
33 
TearDownTestCase()34 void SoftBusClientSocketTest::TearDownTestCase()
35 {
36 }
37 
SetUp()38 void SoftBusClientSocketTest::SetUp()
39 {
40 }
41 
TearDown()42 void SoftBusClientSocketTest::TearDown()
43 {
44 }
45 
46 class ClientSocketTest : public ClientSocket {
47 public:
48     explicit ClientSocketTest(const int32_t socketId);
49     ~ClientSocketTest();
50 };
51 
ClientSocketTest(const int32_t socketId)52 ClientSocketTest::ClientSocketTest(const int32_t socketId)
53     : ClientSocket(socketId)
54 {
55 }
56 
~ClientSocketTest()57 ClientSocketTest::~ClientSocketTest()
58 {
59 }
60 
61 HWTEST_F(SoftBusClientSocketTest, SoftBusClientSocketTestSendMessageSocketIdInvalid, TestSize.Level0)
62 {
63     int32_t socketId = -1;
64     ClientSocketTest *clientSocket = new ClientSocketTest(socketId);
65     const std::string connectionName = "connectionName";
66     const std::string srcEndPoint = "srcEndPoint";
67     const std::string destEndPoint = "destEndPoint";
68     MsgCallback msgCallback;
69     EXPECT_EQ(clientSocket->SendMessage(connectionName, srcEndPoint, destEndPoint, nullptr, msgCallback),
70         GENERAL_ERROR);
71     delete clientSocket;
72 }
73 
74 HWTEST_F(SoftBusClientSocketTest, SoftBusClientSocketTestOnBytesNetworkIdEmpty, TestSize.Level0)
75 {
76     int32_t socketId = 1;
77     ClientSocketTest *clientSocket = new ClientSocketTest(socketId);
78     void *data = new char[10];
79     uint32_t dataLen = 10;
80     EXPECT_NO_THROW(clientSocket->OnBytes(socketId, data, dataLen));
81     delete clientSocket;
82 }
83 
84 HWTEST_F(SoftBusClientSocketTest, SoftBusClientSocketTestOnBytesSoftBusMessageNull, TestSize.Level0)
85 {
86     int32_t socketId = 1;
87     ClientSocketTest *clientSocket = new ClientSocketTest(socketId);
88     const std::string networkId = "connectionName";
89     clientSocket->SetNetworkId(networkId);
90     void *data = new char[10];
91     uint32_t dataLen = 10;
92     EXPECT_NO_THROW(clientSocket->OnBytes(socketId, data, dataLen));
93     delete clientSocket;
94 }
95 
96 HWTEST_F(SoftBusClientSocketTest, SoftBusClientSocketTestRefreshKeepAliveTimerHasValue, TestSize.Level0)
97 {
98     int32_t socketId = 1;
99     ClientSocketTest *clientSocket = new ClientSocketTest(socketId);
100     EXPECT_NO_THROW(clientSocket->RefreshKeepAliveTimer());
101     EXPECT_NO_THROW(clientSocket->RefreshKeepAliveTimer());
102     delete clientSocket;
103 }
104 
105 HWTEST_F(SoftBusClientSocketTest, SoftBusClientSocketTestSendKeepAliveMessage, TestSize.Level0)
106 {
107     int32_t socketId = 1;
108     ClientSocketTest *clientSocket = new ClientSocketTest(socketId);
109     EXPECT_NO_THROW(clientSocket->SendKeepAliveMessage());
110     delete clientSocket;
111 }
112 } // namespace UserAuth
113 } // namespace UserIam
114 } // namespace OHOS
115