• 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 <gtest/gtest.h>
17 
18 #include "softbus_client_info_manager.h"
19 #include "softbus_error_code.h"
20 
21 #define TEST_PID 100
22 
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 class SoftbusClientInfoManagerTest : public testing::Test {
27 public:
SoftbusClientInfoManagerTest()28     SoftbusClientInfoManagerTest()
29     {}
~SoftbusClientInfoManagerTest()30     ~SoftbusClientInfoManagerTest()
31     {}
SetUpTestCase()32     static void SetUpTestCase()
33     {}
TearDownTestCase()34     static void TearDownTestCase()
35     {}
SetUp()36     void SetUp() override
37     {}
TearDown()38     void TearDown() override
39     {}
40 };
41 
42 /**
43  * @tc.name: SoftbusClientInfoManagerTest001
44  * @tc.desc: SoftbusAddService function test
45  * @tc.type: FUNC
46  * @tc.require:
47  */
48 HWTEST_F(SoftbusClientInfoManagerTest, SoftbusClientInfoManagerTest001, TestSize.Level1)
49 {
50     int32_t pidTest = TEST_PID;
51     std::string pkgName = "testPkgName";
52     const sptr<IRemoteObject> object = nullptr;
53     const sptr<IRemoteObject::DeathRecipient> abilityDeath = nullptr;
54     int32_t ret = SoftbusClientInfoManager::GetInstance().SoftbusAddService(pkgName,
55         object, abilityDeath, pidTest);
56     EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
57 
58     ret = SoftbusClientInfoManager::GetInstance().SoftbusAddServiceInner(pkgName,
59         nullptr, pidTest);
60     EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
61 }
62 
63 /**
64  * @tc.name: SoftbusClientInfoManagerTest002
65  * @tc.desc: SoftbusRemoveServiceInner function test
66  * @tc.type: FUNC
67  * @tc.require:
68  */
69 HWTEST_F(SoftbusClientInfoManagerTest, SoftbusClientInfoManagerTest002, TestSize.Level1)
70 {
71     std::string pkgName;
72     int32_t ret = SoftbusClientInfoManager::GetInstance().SoftbusRemoveServiceInner(pkgName);
73     EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
74 
75     const char *sessionName = "ohos.distributedschedule.dms.test";
76     ret = SoftbusClientInfoManager::GetInstance().SoftbusRemoveServiceInner(sessionName);
77     EXPECT_EQ(ret, SOFTBUS_OK);
78 }
79 
80 /**
81  * @tc.name: SoftbusClientInfoManagerTest003
82  * @tc.desc: SoftbusRemoveService function test
83  * @tc.type: FUNC
84  * @tc.require:
85  */
86 HWTEST_F(SoftbusClientInfoManagerTest, SoftbusClientInfoManagerTest003, TestSize.Level1)
87 {
88     std::string pkgName;
89     int32_t ret = SoftbusClientInfoManager::GetInstance().SoftbusRemoveService(
90         nullptr, pkgName, nullptr);
91     EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
92 }
93 
94 /**
95  * @tc.name: SoftbusClientInfoManagerTest004
96  * @tc.desc: GetSoftbusInnerObject function test
97  * @tc.type: FUNC
98  * @tc.require:
99  */
100 HWTEST_F(SoftbusClientInfoManagerTest, SoftbusClientInfoManagerTest004, TestSize.Level1)
101 {
102     std::string pkgName;
103     int32_t ret = SoftbusClientInfoManager::GetInstance().GetSoftbusInnerObject(
104         pkgName, nullptr);
105     EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
106 
107     ISessionListenerInner object;
108     const char *sessionName = "ohos.distributedschedule.dms.test";
109     ret = SoftbusClientInfoManager::GetInstance().GetSoftbusInnerObject(
110         sessionName, &object);
111     EXPECT_EQ(ret, SOFTBUS_NOT_FIND);
112 }
113 
114 /**
115  * @tc.name: SoftbusClientInfoManagerTest005
116  * @tc.desc: GetSoftbusClientProxy function test
117  * @tc.type: FUNC
118  * @tc.require:
119  */
120 HWTEST_F(SoftbusClientInfoManagerTest, SoftbusClientInfoManagerTest005, TestSize.Level1)
121 {
122     const char *sessionName = "ohos.distributedschedule.dms.test";
123     sptr<IRemoteObject> clientObject =
124         SoftbusClientInfoManager::GetInstance().GetSoftbusClientProxy(sessionName);
125     EXPECT_EQ(clientObject, nullptr);
126 }
127 }
128