1 /*
2 * Copyright (c) 2020-2021 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 "utils/SamgrTestBase.h"
18
19 using namespace testing::ext;
20
21 struct DemoApi {
22 INHERIT_IUNKNOWN;
23 };
24
25 struct DemoFeature {
26 INHERIT_FEATURE;
27 INHERIT_IUNKNOWNENTRY(DemoApi);
28 Identity identity;
29 };
30
GetName(Service * service)31 static const char *GetName(Service *service)
32 {
33 (void)service;
34 return "serviceName401";
35 }
36
37 struct ExampleService {
38 INHERIT_SERVICE;
39 Identity identity;
40 };
41
Initialize(Service * service,Identity identity)42 static BOOL Initialize(Service *service, Identity identity)
43 {
44 ExampleService *example = (ExampleService *)service;
45 example->identity = identity;
46 return TRUE;
47 }
48
MessageHandle(Service * service,Request * msg)49 static BOOL MessageHandle(Service *service, Request *msg)
50 {
51 (void)service;
52 (void)msg;
53 return FALSE;
54 }
55
GetTaskConfig(Service * service)56 static TaskConfig GetTaskConfig(Service *service)
57 {
58 (void)service;
59 TaskConfig config = {
60 LEVEL_HIGH,
61 PRI_ABOVE_NORMAL,
62 0x800,
63 20,
64 SHARED_TASK
65 };
66 return config;
67 }
68
69 static ExampleService g_service = {
70 .GetName = GetName,
71 .Initialize = Initialize,
72 .MessageHandle = MessageHandle,
73 .GetTaskConfig = GetTaskConfig,
74 .identity = {-1, -1, nullptr},
75 };
76
FEATURE_GetName(Feature * feature)77 static const char *FEATURE_GetName(Feature *feature)
78 {
79 (void)feature;
80 return "featureName401";
81 }
FEATURE_OnInitialize(Feature * feature,Service * parent,Identity identity)82 static void FEATURE_OnInitialize(Feature *feature, Service *parent, Identity identity)
83 {
84 DemoFeature *demoFeature = (DemoFeature *)feature;
85 demoFeature->identity = identity;
86 }
FEATURE_OnStop(Feature * feature,Identity identity)87 static void FEATURE_OnStop(Feature *feature, Identity identity)
88 {
89 (void)feature;
90 (void)identity;
91 }
92
FEATURE_OnMessage(Feature * feature,Request * request)93 static BOOL FEATURE_OnMessage(Feature *feature, Request *request)
94 {
95 (void)feature;
96 (void)request;
97 return TRUE;
98 }
99
100 static DemoFeature g_feature = {
101 .GetName = FEATURE_GetName,
102 .OnInitialize = FEATURE_OnInitialize,
103 .OnStop = FEATURE_OnStop,
104 .OnMessage = FEATURE_OnMessage,
105 .ver = 1,
106 .ref = 1,
107 .iUnknown = {
108 DEFAULT_IUNKNOWN_IMPL,
109 },
110 .identity = {-1, -1, nullptr},
111 };
112
113 class FeatureApiTest : public testing::Test {
114 protected:
115 // SetUpTestCase: Testsuit setup, run before 1st testcase
SetUpTestCase(void)116 static void SetUpTestCase(void)
117 {
118 SystemInitProxy();
119 }
120 // TearDownTestCase: Testsuit teardown, run after last testcase
TearDownTestCase(void)121 static void TearDownTestCase(void)
122 {
123 }
124 // Testcase setup
SetUp()125 virtual void SetUp()
126 {
127 }
128 // Testcase teardown
TearDown()129 virtual void TearDown()
130 {
131 }
132 };
133
134 /**
135 * @tc.number : DMSLite_SAMGR_RegisterFeatureApi_0010
136 * @tc.name : Valid api can be registered under a feature
137 * @tc.desc : [C- SOFTWARE -0200]
138 */
139 HWTEST_F(FeatureApiTest, testRegisterFeatureApi0010, Function | MediumTest | Level1) {
140 SAMGR_GetInstance()->RegisterService((Service *)&g_service);
141 SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature);
142
143 BOOL result = SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401",
144 GET_IUNKNOWN(g_feature));
145 ASSERT_EQ(result, TRUE);
146
147 SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401");
148 SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401");
149 SAMGR_GetInstance()->UnregisterService("serviceName401");
150 }
151
152 /**
153 * @tc.number : DMSLite_SAMGR_RegisterFeatureApi_0020
154 * @tc.name : API failed to register if the specified service name is null or space
155 * @tc.desc : [C- SOFTWARE -0200]
156 */
157 HWTEST_F(FeatureApiTest, testRegisterFeatureApi0020, Function | MediumTest | Level2) {
158 SAMGR_GetInstance()->RegisterService((Service *)&g_service);
159 SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature);
160
161 BOOL result = SAMGR_GetInstance()->RegisterFeatureApi(NULL, "featureName401", GET_IUNKNOWN(g_feature));
162 ASSERT_EQ(result, FALSE);
163
164 result = SAMGR_GetInstance()->RegisterFeatureApi("", "featureName401", GET_IUNKNOWN(g_feature));
165 ASSERT_EQ(result, FALSE);
166
167 SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401");
168 SAMGR_GetInstance()->UnregisterService("serviceName401");
169 }
170
171 /**
172 * @tc.number : DMSLite_SAMGR_RegisterFeatureApi_0030
173 * @tc.name : API failed to register if the specified feature is space
174 * @tc.desc : [C- SOFTWARE -0200]
175 */
176 HWTEST_F(FeatureApiTest, testRegisterFeatureApi0030, Function | MediumTest | Level2) {
177 SAMGR_GetInstance()->RegisterService((Service *)&g_service);
178 SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature);
179
180 BOOL result = SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "", GET_IUNKNOWN(g_feature));
181 ASSERT_EQ(result, FALSE);
182
183 SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401");
184 SAMGR_GetInstance()->UnregisterService("serviceName401");
185 }
186
187 /**
188 * @tc.number : DMSLite_SAMGR_RegisterFeatureApi_0040
189 * @tc.name : API failed to register if the api is null
190 * @tc.desc : [C- SOFTWARE -0200]
191 */
192 HWTEST_F(FeatureApiTest, testRegisterFeatureApi0040, Function | MediumTest | Level2) {
193 SAMGR_GetInstance()->RegisterService((Service *)&g_service);
194 SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature);
195
196 BOOL result = SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", nullptr);
197 ASSERT_EQ(result, FALSE);
198
199 SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401");
200 SAMGR_GetInstance()->UnregisterService("serviceName401");
201 }
202
203 /**
204 * @tc.number : DMSLite_SAMGR_RegisterFeatureApi_0050
205 * @tc.name : If the specified feature is null api will be registered as default feature api
206 * @tc.desc : [C- SOFTWARE -0200]
207 */
208 HWTEST_F(FeatureApiTest, testRegisterFeatureApi0050, Function | MediumTest | Level2) {
209 SAMGR_GetInstance()->RegisterService((Service *)&g_service);
210 SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature);
211
212 // feature is null, handle as default feature api
213 BOOL result = SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", nullptr, GET_IUNKNOWN(g_feature));
214 ASSERT_EQ(result, TRUE);
215
216 SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", nullptr);
217 SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401");
218 SAMGR_GetInstance()->UnregisterService("serviceName401");
219 }
220
221 /**
222 * @tc.number : DMSLite_SAMGR_RegisterFeatureApi_0060
223 * @tc.name : API failed to register if the specified service name does not exist
224 * @tc.desc : [C- SOFTWARE -0200]
225 */
226 HWTEST_F(FeatureApiTest, testRegisterFeatureApi0060, Function | MediumTest | Level2) {
227 SAMGR_GetInstance()->RegisterService((Service *)&g_service);
228 SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature);
229
230 BOOL result = SAMGR_GetInstance()->RegisterFeatureApi("noExistService", "featureName401", GET_IUNKNOWN(g_feature));
231 ASSERT_EQ(result, FALSE);
232
233 SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401");
234 SAMGR_GetInstance()->UnregisterService("serviceName401");
235 }
236
237 /**
238 * @tc.number : DMSLite_SAMGR_RegisterFeatureApi_0070
239 * @tc.name : API failed to register if the specified feature name does not exist
240 * @tc.desc : [C- SOFTWARE -0200]
241 */
242 HWTEST_F(FeatureApiTest, testRegisterFeatureApi0070, Function | MediumTest | Level2) {
243 SAMGR_GetInstance()->RegisterService((Service *)&g_service);
244 SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature);
245
246 BOOL result = SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "noExistFeature", GET_IUNKNOWN(g_feature));
247 ASSERT_EQ(result, FALSE);
248
249 SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401");
250 SAMGR_GetInstance()->UnregisterService("serviceName401");
251 }
252
253 /**
254 * @tc.number : DMSLite_SAMGR_RegisterFeatureApi_0080
255 * @tc.name : feature api can not be registered twice
256 * @tc.desc : [C- SOFTWARE -0200]
257 */
258 HWTEST_F(FeatureApiTest, testRegisterFeatureApi0080, Function | MediumTest | Level2) {
259 SAMGR_GetInstance()->RegisterService((Service *)&g_service);
260 SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature);
261 SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401",
262 GET_IUNKNOWN(g_feature));
263
264 BOOL result = SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401",
265 GET_IUNKNOWN(g_feature));
266 ASSERT_EQ(result, FALSE);
267
268 SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401");
269 SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401");
270 SAMGR_GetInstance()->UnregisterService("serviceName401");
271 }
272
273 /**
274 * @tc.number : DMSLite_SAMGR_GetFeatureApi_0010
275 * @tc.name : Service can query API by serverName-featureName
276 * @tc.desc : [C- SOFTWARE -0200]
277 */
278 HWTEST_F(FeatureApiTest, testGetFeatureApi0010, Function | MediumTest | Level1) {
279 SAMGR_GetInstance()->RegisterService((Service *)&g_service);
280 SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature);
281 SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature));
282
283 IUnknown *resultIUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName401", "featureName401");
284 ASSERT_EQ(resultIUnknown != nullptr, TRUE);
285
286 SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401");
287 SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401");
288 SAMGR_GetInstance()->UnregisterService("serviceName401");
289 }
290
291 /**
292 * @tc.number : DMSLite_SAMGR_GetFeatureApi_0020
293 * @tc.name : If the specified serviceName is NULL or space GetFeatureApi return NULL
294 * @tc.desc : [C- SOFTWARE -0200]
295 */
296 HWTEST_F(FeatureApiTest, testGetFeatureApi0020, Function | MediumTest | Level2) {
297 SAMGR_GetInstance()->RegisterService((Service *)&g_service);
298 SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature);
299 SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature));
300
301 IUnknown *resultIUnknown = SAMGR_GetInstance()->GetFeatureApi(NULL, "featureName401");
302 ASSERT_EQ(resultIUnknown == nullptr, TRUE);
303 resultIUnknown = SAMGR_GetInstance()->GetFeatureApi("", "featureName401");
304 ASSERT_EQ(resultIUnknown == nullptr, TRUE);
305
306 SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401");
307 SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401");
308 SAMGR_GetInstance()->UnregisterService("serviceName401");
309 }
310
311 /**
312 * @tc.number : DMSLite_SAMGR_GetFeatureApi_0030
313 * @tc.name : If the specified featureName is NULL or space GetFeatureApi return NULL
314 * @tc.desc : [C- SOFTWARE -0200]
315 */
316 HWTEST_F(FeatureApiTest, testGetFeatureApi0030, Function | MediumTest | Level2) {
317 SAMGR_GetInstance()->RegisterService((Service *)&g_service);
318 SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature);
319 SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature));
320
321 IUnknown *resultIUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName401", nullptr);
322 ASSERT_EQ(resultIUnknown == nullptr, TRUE);
323 resultIUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName401", "");
324 ASSERT_EQ(resultIUnknown == nullptr, TRUE);
325
326 SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401");
327 SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401");
328 SAMGR_GetInstance()->UnregisterService("serviceName401");
329 }
330
331 /**
332 * @tc.number : DMSLite_SAMGR_GetFeatureApi_0040
333 * @tc.name : If the specified featureName does not exist GetFeatureApi return NULL
334 * @tc.desc : [C- SOFTWARE -0200]
335 */
336 HWTEST_F(FeatureApiTest, testGetFeatureApi0040, Function | MediumTest | Level2) {
337 SAMGR_GetInstance()->RegisterService((Service *)&g_service);
338 SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature);
339
340 IUnknown *resultIUnknown = SAMGR_GetInstance()->GetFeatureApi("noExistService", "featureName401");
341 ASSERT_EQ(resultIUnknown == nullptr, TRUE);
342 resultIUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName401", "noExistFeature");
343 ASSERT_EQ(resultIUnknown == nullptr, TRUE);
344
345 SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401");
346 SAMGR_GetInstance()->UnregisterService("serviceName401");
347 }
348
349 /**
350 * @tc.number : DMSLite_SAMGR_GetFeatureApi_0050
351 * @tc.name : If no API under the specified feature GetFeatureApi return NULL
352 * @tc.desc : [C- SOFTWARE -0200]
353 */
354 HWTEST_F(FeatureApiTest, testGetFeatureApi0050, Function | MediumTest | Level2) {
355 SAMGR_GetInstance()->RegisterService((Service *)&g_service);
356 SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature);
357
358 IUnknown *resultIUnknown = SAMGR_GetInstance()->GetFeatureApi("serviceName401", "featureName401");
359 ASSERT_EQ(resultIUnknown == nullptr, TRUE);
360
361 SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401");
362 SAMGR_GetInstance()->UnregisterService("serviceName401");
363 }
364
365 /**
366 * @tc.number : DMSLite_SAMGR_GetFeatureApi_0060
367 * @tc.name : The results of multiple queries are the same for GetFeatureApi
368 * @tc.desc : [C- SOFTWARE -0200]
369 */
370 HWTEST_F(FeatureApiTest, testGetFeatureApi0060, Function | MediumTest | Level2) {
371 SAMGR_GetInstance()->RegisterService((Service *)&g_service);
372 SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature);
373 SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature));
374
375 IUnknown *resultIUnknown1 = SAMGR_GetInstance()->GetFeatureApi("serviceName401", "featureName401");
376 IUnknown *resultIUnknown2 = SAMGR_GetInstance()->GetFeatureApi("serviceName401", "featureName401");
377 ASSERT_EQ(resultIUnknown1 == resultIUnknown2, TRUE);
378
379 SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401");
380 SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401");
381 SAMGR_GetInstance()->UnregisterService("serviceName401");
382 }
383
384 /**
385 * @tc.number : DMSLite_SAMGR_UnregisterFeatureApi_0010
386 * @tc.name : FeatureApi can be unregistered
387 * @tc.desc : [C- SOFTWARE -0200]
388 */
389 HWTEST_F(FeatureApiTest, testUnregisterFeatureApi0010, Function | MediumTest | Level2) {
390 SAMGR_GetInstance()->RegisterService((Service *)&g_service);
391 SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature);
392 SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature));
393
394 IUnknown *resultIUnknown = SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401");
395 ASSERT_EQ(resultIUnknown != nullptr, TRUE);
396
397 SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401");
398 SAMGR_GetInstance()->UnregisterService("serviceName401");
399 }
400
401 /**
402 * @tc.number : DMSLite_SAMGR_UnregisterFeatureApi_0020
403 * @tc.name : FeatureApi failed to unregister if the specified serviceName is NULL or space
404 * @tc.desc : [C- SOFTWARE -0200]
405 */
406 HWTEST_F(FeatureApiTest, testUnregisterFeatureApi0020, Function | MediumTest | Level2) {
407 SAMGR_GetInstance()->RegisterService((Service *)&g_service);
408 SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature);
409 SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature));
410
411 IUnknown *resultIUnknown = SAMGR_GetInstance()->UnregisterFeatureApi(NULL, "featureName401");
412 ASSERT_EQ(resultIUnknown == nullptr, TRUE);
413 resultIUnknown = SAMGR_GetInstance()->UnregisterFeatureApi("", "featureName401");
414 ASSERT_EQ(resultIUnknown == nullptr, TRUE);
415
416 SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401");
417 SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401");
418 SAMGR_GetInstance()->UnregisterService("serviceName401");
419 }
420
421 /**
422 * @tc.number : DMSLite_SAMGR_UnregisterFeatureApi_0030
423 * @tc.name : FeatureApi failed to unregister if the specified featureName is space
424 * @tc.desc : [C- SOFTWARE -0200]
425 */
426 HWTEST_F(FeatureApiTest, testUnregisterFeatureApi0030, Function | MediumTest | Level2) {
427 SAMGR_GetInstance()->RegisterService((Service *)&g_service);
428 SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature);
429 SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature));
430
431 IUnknown *resultIUnknown = SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "");
432 ASSERT_EQ(resultIUnknown == nullptr, TRUE);
433
434 SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401");
435 SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401");
436 SAMGR_GetInstance()->UnregisterService("serviceName401");
437 }
438
439 /**
440 * @tc.number : DMSLite_SAMGR_UnregisterFeatureApi_0040
441 * @tc.name : FeatureApi failed to unregister if the specified serviceName does not exist
442 * @tc.desc : [C- SOFTWARE -0200]
443 */
444 HWTEST_F(FeatureApiTest, testUnregisterFeatureApi0040, Function | MediumTest | Level2) {
445 SAMGR_GetInstance()->RegisterService((Service *)&g_service);
446 SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature);
447 SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature));
448
449 IUnknown *resultIUnknown = SAMGR_GetInstance()->UnregisterFeatureApi("noExistService", "featureName401");
450 ASSERT_EQ(resultIUnknown == nullptr, TRUE);
451
452 SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401");
453 SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401");
454 SAMGR_GetInstance()->UnregisterService("serviceName401");
455 }
456
457 /**
458 * @tc.number : DMSLite_SAMGR_UnregisterFeatureApi_0050
459 * @tc.name : FeatureApi failed to unregister if the specified featureName does not exist
460 * @tc.desc : [C- SOFTWARE -0200]
461 */
462 HWTEST_F(FeatureApiTest, testUnregisterFeatureApi0050, Function | MediumTest | Level2) {
463 SAMGR_GetInstance()->RegisterService((Service *)&g_service);
464 SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature);
465 SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401", GET_IUNKNOWN(g_feature));
466
467 IUnknown *resultIUnknown = SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "noExistFeature");
468 ASSERT_EQ(resultIUnknown == nullptr, TRUE);
469
470 SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401");
471 SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401");
472 SAMGR_GetInstance()->UnregisterService("serviceName401");
473 }
474
475 /**
476 * @tc.number : DMSLite_SAMGR_UnregisterFeatureApi_0060
477 * @tc.name : Register feature api and unregister repeatedly, no memory leak
478 * @tc.desc : [C- SOFTWARE -0200]
479 */
480 HWTEST_F(FeatureApiTest, testUnregisterFeatureApi0060, Function | MediumTest | Level2) {
481 SAMGR_GetInstance()->RegisterService((Service *)&g_service);
482 SAMGR_GetInstance()->RegisterFeature("serviceName401", (Feature *)&g_feature);
483
484 for (int i = 0; i < PRESSURE_BASE; i++) {
485 BOOL result = SAMGR_GetInstance()->RegisterFeatureApi("serviceName401", "featureName401",
486 GET_IUNKNOWN(g_feature));
487 ASSERT_EQ(result, TRUE);
488
489 IUnknown *resultIUnknown = SAMGR_GetInstance()->UnregisterFeatureApi("serviceName401", "featureName401");
490 ASSERT_EQ(resultIUnknown != nullptr, TRUE);
491 }
492 SAMGR_GetInstance()->UnregisterFeature("serviceName401", "featureName401");
493 SAMGR_GetInstance()->UnregisterService("serviceName401");
494 }