• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 "device/dev_profile.h"
19 #include "device/dm_adapter.h"
20 #include "pasteboard_error.h"
21 
22 namespace OHOS::MiscServices {
23 using namespace testing::ext;
24 class DevProfileTest : public testing::Test {
25 public:
26     static void SetUpTestCase(void);
27     static void TearDownTestCase(void);
28     void SetUp();
29     void TearDown();
30 };
31 
SetUpTestCase(void)32 void DevProfileTest::SetUpTestCase(void) { }
33 
TearDownTestCase(void)34 void DevProfileTest::TearDownTestCase(void) { }
35 
SetUp(void)36 void DevProfileTest::SetUp(void) { }
37 
TearDown(void)38 void DevProfileTest::TearDown(void) { }
39 
40 /**
41  * @tc.name: GetRemoteDeviceVersionTest001
42  * @tc.desc: Get Remote Device Version
43  * @tc.type: FUNC
44  * @tc.require:
45  * @tc.author:
46  */
47 HWTEST_F(DevProfileTest, GetRemoteDeviceVersionTest001, TestSize.Level0)
48 {
49 #ifdef PB_DEVICE_INFO_MANAGER_ENABLE
50     uint32_t versionId;
51     std::string bundleName = "com.dev.profile";
52     DevProfile::GetInstance().GetRemoteDeviceVersion(bundleName, versionId);
53     EXPECT_TRUE(true);
54 #else
55     EXPECT_TRUE(true);
56 #endif
57 }
58 
59 /**
60  * @tc.name: GetRemoteDeviceVersionTest002
61  * @tc.desc: Get Remote Device Version
62  * @tc.type: FUNC
63  * @tc.require:
64  * @tc.author:
65  */
66 HWTEST_F(DevProfileTest, GetRemoteDeviceVersionTest002, TestSize.Level0)
67 {
68 #ifdef PB_DEVICE_INFO_MANAGER_ENABLE
69     uint32_t versionId;
70     std::string bundleName = "com.dev.profile";
71     bool res = DMAdapter::GetInstance().Initialize(bundleName);
72     DevProfile::GetInstance().GetRemoteDeviceVersion(bundleName, versionId);
73     EXPECT_TRUE(true);
74 #else
75     EXPECT_TRUE(true);
76 #endif
77 }
78 
79 /**
80  * @tc.name: GetEnabledStatusTest001
81  * @tc.desc: GetEnabledStatus should not return E_OK when query invalid networkId
82  * @tc.type: FUNC
83  * @tc.require:
84  * @tc.author:
85  */
86 HWTEST_F(DevProfileTest, GetEnabledStatusTest001, TestSize.Level0)
87 {
88 #ifdef PB_DEVICE_INFO_MANAGER_ENABLE
89     std::string enabledStatus = "";
90     std::string networkId = "test.dev.profile";
91     int32_t ret = DevProfile::GetInstance().GetEnabledStatus(networkId, enabledStatus);
92     EXPECT_NE(ret, static_cast<int32_t>(PasteboardError::E_OK));
93 #else
94     EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::NO_TRUST_DEVICE_ERROR));
95 #endif
96 }
97 
98 /**
99  * @tc.name: GetEnabledStatusTest002
100  * @tc.desc: GetEnabledStatus should not return NO_TRUST_DEVICE_ERROR when query valid networkId
101  * @tc.type: FUNC
102  * @tc.require:
103  * @tc.author:
104  */
105 HWTEST_F(DevProfileTest, GetEnabledStatusTest002, TestSize.Level0)
106 {
107 #ifdef PB_DEVICE_INFO_MANAGER_ENABLE
108     std::string enabledStatus = "";
109     auto networkId = DMAdapter::GetInstance().GetLocalNetworkId();
110     int32_t ret = DevProfile::GetInstance().GetEnabledStatus(networkId, enabledStatus);
111     EXPECT_NE(ret, static_cast<int32_t>(PasteboardError::NO_TRUST_DEVICE_ERROR));
112 #else
113     EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::NO_TRUST_DEVICE_ERROR));
114 #endif
115 }
116 
117 /**
118  * @tc.name: PutEnabledStatus001
119  * @tc.desc: PutEnabledStatus should not return NO_TRUST_DEVICE_ERROR when query valid networkId
120  * @tc.type: FUNC
121  * @tc.require:
122  * @tc.author:
123  */
124 HWTEST_F(DevProfileTest, PutEnabledStatus001, TestSize.Level0)
125 {
126 #ifdef PB_DEVICE_INFO_MANAGER_ENABLE
127     std::string bundleName = "com.example.myApplication";
128     bool res = DMAdapter::GetInstance().Initialize(bundleName);
129     std::string enabledStatus = "1";
130     DevProfile::GetInstance().PutEnabledStatus(enabledStatus);
131     EXPECT_TRUE(true);
132 #else
133     EXPECT_TRUE(true);
134 #endif
135 }
136 
137 /**
138  * @tc.name: SubscribeProfileEvent001
139  * @tc.desc: Sub scribe Profile Event
140  * @tc.type: FUNC
141  * @tc.require:
142  * @tc.author:
143  */
144 HWTEST_F(DevProfileTest, SubscribeProfileEventTest001, TestSize.Level0)
145 {
146 #ifdef PB_DEVICE_INFO_MANAGER_ENABLE
147     std::string bundleName = "com.pro.proEvent";
148     DevProfile::GetInstance().SubscribeProfileEvent(bundleName);
149     EXPECT_TRUE(true);
150 #else
151     EXPECT_TRUE(true);
152 #endif
153 }
154 
155 /**
156  * @tc.name: SubscribeProfileEvent002
157  * @tc.desc: Subscribe Profile Event
158  * @tc.type: FUNC
159  * @tc.require:
160  * @tc.author:
161  */
162 HWTEST_F(DevProfileTest, SubscribeProfileEventTest002, TestSize.Level0)
163 {
164 #ifdef PB_DEVICE_INFO_MANAGER_ENABLE
165     std::string bundleName = "com.pro.proEvent";
166     bool res = DMAdapter::GetInstance().Initialize(bundleName);
167     DevProfile::GetInstance().SubscribeProfileEvent(bundleName);
168     EXPECT_TRUE(true);
169 #else
170     EXPECT_TRUE(true);
171 #endif
172 }
173 
174 /**
175  * @tc.name: SubscribeProfileEvent003
176  * @tc.desc: Subscribe Profile Event
177  * @tc.type: FUNC
178  * @tc.require:
179  * @tc.author:
180  */
181 HWTEST_F(DevProfileTest, SubscribeProfileEventTest003, TestSize.Level0)
182 {
183 #ifdef PB_DEVICE_INFO_MANAGER_ENABLE
184     std::string bundleName = "com.pro.proEvent";
185     bool res = DMAdapter::GetInstance().Initialize(bundleName);
186     DevProfile::GetInstance().SubscribeProfileEvent(bundleName);
187     DevProfile::GetInstance().SubscribeProfileEvent(bundleName);
188     EXPECT_TRUE(true);
189 #else
190     EXPECT_TRUE(true);
191 #endif
192 }
193 
194 /**
195  * @tc.name: UnSubscribeProfileEvent001
196  * @tc.desc: UnSub scribe Profile Event
197  * @tc.type: FUNC
198  * @tc.require:
199  * @tc.author:
200  */
201 HWTEST_F(DevProfileTest, UnSubscribeProfileEventTest001, TestSize.Level0)
202 {
203 #ifdef PB_DEVICE_INFO_MANAGER_ENABLE
204     std::string bsndleName = "com.pro.proEvent";
205     DevProfile::GetInstance().UnSubscribeProfileEvent(bsndleName);
206     EXPECT_TRUE(true);
207 #else
208     EXPECT_TRUE(true);
209 #endif
210 }
211 
212 /**
213  * @tc.name: UnSubscribeProfileEvent002
214  * @tc.desc: UnSubscribe Profile Event
215  * @tc.type: FUNC
216  * @tc.require:
217  * @tc.author:
218  */
219 HWTEST_F(DevProfileTest, UnSubscribeProfileEventTest002, TestSize.Level0)
220 {
221 #ifdef PB_DEVICE_INFO_MANAGER_ENABLE
222     std::string bundleName = "com.pro.proEvent";
223     bool res = DMAdapter::GetInstance().Initialize(bundleName);
224     DevProfile::GetInstance().UnSubscribeProfileEvent(bundleName);
225     EXPECT_TRUE(true);
226 #else
227     EXPECT_TRUE(true);
228 #endif
229 }
230 
231 /**
232  * @tc.name: UnSubscribeProfileEvent003
233  * @tc.desc: UnSubscribe Profile Event
234  * @tc.type: FUNC
235  * @tc.require:
236  * @tc.author:
237  */
238 HWTEST_F(DevProfileTest, UnSubscribeProfileEventTest003, TestSize.Level0)
239 {
240 #ifdef PB_DEVICE_INFO_MANAGER_ENABLE
241     std::string bundleName = "com.pro.proEvent";
242     bool res = DMAdapter::GetInstance().Initialize(bundleName);
243     DevProfile::GetInstance().SubscribeProfileEvent(bundleName);
244     DevProfile::GetInstance().UnSubscribeProfileEvent(bundleName);
245     EXPECT_TRUE(true);
246 #else
247     EXPECT_TRUE(true);
248 #endif
249 }
250 
251 /**
252  * @tc.name: WatchTest
253  * @tc.desc: Watch
254  * @tc.type: FUNC
255  * @tc.require:
256  * @tc.author:
257  */
258 HWTEST_F(DevProfileTest, Watch, TestSize.Level0)
259 {
260     DevProfile::Observer observer;
261     DevProfile::GetInstance().Watch(observer);
262     EXPECT_FALSE(observer);
263 }
264 } // namespace OHOS::MiscServices