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