• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #include "securec.h"
18 
19 #include "trans_client_proxy_standard.h"
20 #include "softbus_def.h"
21 #include "softbus_errcode.h"
22 #include "iservice_registry.h"
23 #include "if_system_ability_manager.h"
24 #include "iremote_object.h"
25 #include "softbus_server_death_recipient.h"
26 #include "softbus_client_info_manager.h"
27 #include "ipc_skeleton.h"
28 #include "softbus_trans_def.h"
29 #include "session.h"
30 #include "softbus_adapter_mem.h"
31 
32 
33 using namespace std;
34 using namespace testing::ext;
35 
36 #define TEST_TMP_DATE 1
37 #define TEST_ERRTMP_DATE (-1)
38 
39 namespace OHOS {
40 class TransClientProxyStandardTest : public testing::Test {
41 public:
TransClientProxyStandardTest()42     TransClientProxyStandardTest() {}
~TransClientProxyStandardTest()43     ~TransClientProxyStandardTest() {}
44     static void SetUpTestCase(void);
45     static void TearDownTestCase(void);
SetUp()46     void SetUp() override {}
TearDown()47     void TearDown() override {}
48 };
49 
SetUpTestCase(void)50 void TransClientProxyStandardTest::SetUpTestCase(void) {}
TearDownTestCase(void)51 void TransClientProxyStandardTest::TearDownTestCase(void) {}
52 
53 /**
54  * @tc.name: InformPermissionChangeTest001
55  * @tc.desc: trans client proxy standard test, use the normal parameter.
56  * @tc.type: FUNC
57  * @tc.require:
58  */
59 HWTEST_F(TransClientProxyStandardTest, TransClientProxyStandardTest001, TestSize.Level0)
60 {
61     #define TEST_INVALID 0
62     int32_t ret;
63     DeviceInfo device;
64 
65     static const uint32_t SOFTBUS_SA_ID = 4700;
66     sptr<ISystemAbilityManager> saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
67     sptr<IRemoteObject> remoteObject = saManager->GetSystemAbility(SOFTBUS_SA_ID);
68     ASSERT_TRUE(remoteObject != nullptr);
69     sptr<TransClientProxy> clientProxy = new (std::nothrow) TransClientProxy(remoteObject);
70     ASSERT_TRUE(clientProxy != nullptr);
71 
72     clientProxy->OnDeviceFound(&device);
73 
74     int tmp = TEST_INVALID;
75     clientProxy->OnDiscoverFailed(tmp, tmp);
76 
77     clientProxy->OnDiscoverySuccess(tmp);
78 
79     clientProxy->OnPublishSuccess(tmp);
80 
81     clientProxy->OnPublishFail(tmp, tmp);
82 
83     void *addr = nullptr;
84     uint32_t addrTypeLen = TEST_INVALID;
85     const char *networkId = nullptr;
86     ret = clientProxy->OnJoinLNNResult(addr, addrTypeLen, networkId, tmp);
87     EXPECT_EQ(SOFTBUS_OK, ret);
88 
89     ret = clientProxy->OnJoinMetaNodeResult(addr, addrTypeLen, networkId, tmp);
90     EXPECT_EQ(SOFTBUS_OK, ret);
91 
92     ret = clientProxy->OnLeaveLNNResult(networkId, tmp);
93     EXPECT_EQ(SOFTBUS_OK, ret);
94 
95     ret = clientProxy->OnLeaveMetaNodeResult(networkId, tmp);
96     EXPECT_EQ(SOFTBUS_OK, ret);
97 
98     bool isOnline = false;
99     ret = clientProxy->OnNodeOnlineStateChanged(isOnline, addr, addrTypeLen);
100     EXPECT_EQ(SOFTBUS_OK, ret);
101 
102     ret = clientProxy->OnNodeBasicInfoChanged(addr, addrTypeLen, tmp);
103     EXPECT_EQ(SOFTBUS_OK, ret);
104 
105     ret = clientProxy->OnTimeSyncResult(addr, addrTypeLen, tmp);
106     EXPECT_EQ(SOFTBUS_OK, ret);
107 
108     clientProxy->OnPublishLNNResult(tmp, tmp);
109 
110     clientProxy->OnRefreshLNNResult(tmp, tmp);
111 
112     clientProxy->OnRefreshDeviceFound(addr, addrTypeLen);
113 }
114 
115 /**
116  * @tc.name: InformPermissionChangeTest002
117  * @tc.desc: trans client proxy standard test, use the normal parameter.
118  * @tc.type: FUNC
119  * @tc.require:
120  */
121 HWTEST_F(TransClientProxyStandardTest, TransClientProxyStandardTest002, TestSize.Level0)
122 {
123     int32_t ret;
124     const char *pkgName = "dms";
125     static const uint32_t SOFTBUS_SA_ID = 4700;
126     sptr<ISystemAbilityManager> saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
127     sptr<IRemoteObject> remoteObject = saManager->GetSystemAbility(SOFTBUS_SA_ID);
128     ASSERT_TRUE(remoteObject != nullptr);
129     sptr<TransClientProxy> clientProxy = new (std::nothrow) TransClientProxy(remoteObject);
130     ASSERT_TRUE(clientProxy != nullptr);
131 
132     ret = clientProxy->OnChannelLinkDown(nullptr, TEST_TMP_DATE);
133     EXPECT_EQ(SOFTBUS_ERR, ret);
134 
135     ret = clientProxy->OnClientPermissonChange(nullptr, TEST_TMP_DATE);
136     EXPECT_EQ(SOFTBUS_ERR, ret);
137 
138     ret = clientProxy->OnClientPermissonChange(pkgName, TEST_ERRTMP_DATE);
139     EXPECT_EQ(SOFTBUS_OK, ret);
140 }
141 } // namespace OHOS