1/*
2 * Copyright (c) 2024 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#define LOG_TAG "UdsTest"
17
18#include <gtest/gtest.h>
19#include <unistd.h>
20
21#include "token_setproc.h"
22#include "accesstoken_kit.h"
23#include "nativetoken_kit.h"
24#include "logger.h"
25#include "pixelmap_native_impl.h"
26#include "uds.h"
27#include "udmf_capi_common.h"
28#include "udmf_meta.h"
29#include "udmf_err_code.h"
30
31using namespace testing::ext;
32using namespace OHOS::Security::AccessToken;
33using namespace OHOS::UDMF;
34using namespace OHOS;
35
36namespace OHOS::Test {
37class UdsTest : public testing::Test {
38public:
39    static void SetUpTestCase(void);
40    static void TearDownTestCase(void);
41    void SetUp();
42    void TearDown();
43    static bool CheckUnsignedChar(unsigned char* dst, unsigned char* src, int size);
44};
45
46void UdsTest::SetUpTestCase(void) {}
47
48void UdsTest::TearDownTestCase(void) {}
49
50void UdsTest::SetUp(void) {}
51
52void UdsTest::TearDown(void) {}
53
54bool UdsTest::CheckUnsignedChar(unsigned char* dst, unsigned char* src, int size)
55{
56    EXPECT_NE(dst, nullptr);
57    EXPECT_NE(src, nullptr);
58    for (int i = 0; i < size; ++i) {
59        if (dst[i] != src[i]) {
60            return false;
61        }
62    }
63    return true;
64}
65
66/**
67 * @tc.name: OH_UdsPlainText_Create_001
68 * @tc.desc: Normal testcase of OH_UdsPlainText_Create
69 * @tc.type: FUNC
70 */
71HWTEST_F(UdsTest, OH_UdsPlainText_Create_001, TestSize.Level1)
72{
73    LOG_INFO(UDMF_TEST, "OH_UdsPlainText_Create_001 begin.");
74    auto plainText = OH_UdsPlainText_Create();
75    EXPECT_EQ(UDMF_META_PLAIN_TEXT, *(std::get_if<std::string>(&(plainText->obj->value_[UNIFORM_DATA_TYPE]))));
76    OH_UdsPlainText_Destroy(plainText);
77    LOG_INFO(UDMF_TEST, "OH_UdsPlainText_Create_001 end.");
78}
79
80/**
81 * @tc.name: OH_UdsPlainText_GetType_001
82 * @tc.desc: Normal testcase of OH_UdsPlainText_GetType
83 * @tc.type: FUNC
84 */
85HWTEST_F(UdsTest, OH_UdsPlainText_GetType_001, TestSize.Level1)
86{
87    LOG_INFO(UDMF_TEST, "OH_UdsPlainText_GetType_001 begin.");
88    auto plainText = OH_UdsPlainText_Create();
89    EXPECT_EQ(UDMF_META_PLAIN_TEXT, std::string(OH_UdsPlainText_GetType(plainText)));
90    OH_UdsPlainText_Destroy(plainText);
91
92    OH_UdsPlainText* plainTextNullptr = nullptr;
93    EXPECT_EQ(nullptr, OH_UdsPlainText_GetType(plainTextNullptr));
94
95    plainTextNullptr = new OH_UdsPlainText;
96    EXPECT_EQ(nullptr, OH_UdsPlainText_GetType(plainTextNullptr));
97    OH_UdsPlainText_Destroy(plainTextNullptr);
98    LOG_INFO(UDMF_TEST, "OH_UdsPlainText_GetType_001 end.");
99}
100
101/**
102 * @tc.name: OH_UdsPlainText_GetContent_001
103 * @tc.desc: Normal testcase of OH_UdsPlainText_GetContent
104 * @tc.type: FUNC
105 */
106HWTEST_F(UdsTest, OH_UdsPlainText_GetContent_001, TestSize.Level1)
107{
108    LOG_INFO(UDMF_TEST, "OH_UdsPlainText_GetContent_001 begin.");
109    auto plainText = OH_UdsPlainText_Create();
110    plainText->obj->value_[CONTENT] = "doing something";
111    EXPECT_EQ("doing something", std::string(OH_UdsPlainText_GetContent(plainText)));
112    OH_UdsPlainText_Destroy(plainText);
113
114    OH_UdsPlainText* plainTextNullptr = nullptr;
115    EXPECT_EQ(nullptr, OH_UdsPlainText_GetContent(plainTextNullptr));
116
117    plainTextNullptr = new OH_UdsPlainText;
118    EXPECT_EQ(nullptr, OH_UdsPlainText_GetContent(plainTextNullptr));
119    OH_UdsPlainText_Destroy(plainTextNullptr);
120    LOG_INFO(UDMF_TEST, "OH_UdsPlainText_GetContent_001 end.");
121}
122
123/**
124 * @tc.name: OH_UdsPlainText_GetAbstract_001
125 * @tc.desc: Normal testcase of OH_UdsPlainText_GetAbstract
126 * @tc.type: FUNC
127 */
128HWTEST_F(UdsTest, OH_UdsPlainText_GetAbstract_001, TestSize.Level1)
129{
130    LOG_INFO(UDMF_TEST, "OH_UdsPlainText_GetAbstract_001 begin.");
131    auto plainText = OH_UdsPlainText_Create();
132    plainText->obj->value_[ABSTRACT] = "doing something";
133    EXPECT_EQ("doing something", std::string(OH_UdsPlainText_GetAbstract(plainText)));
134    OH_UdsPlainText_Destroy(plainText);
135
136    OH_UdsPlainText* plainTextNullptr = nullptr;
137    EXPECT_EQ(nullptr, OH_UdsPlainText_GetAbstract(plainTextNullptr));
138
139    plainTextNullptr = new OH_UdsPlainText;
140    EXPECT_EQ(nullptr, OH_UdsPlainText_GetAbstract(plainTextNullptr));
141    OH_UdsPlainText_Destroy(plainTextNullptr);
142    LOG_INFO(UDMF_TEST, "OH_UdsPlainText_GetAbstract_001 end.");
143}
144
145/**
146 * @tc.name: OH_UdsPlainText_SetContent_001
147 * @tc.desc: Normal testcase of OH_UdsPlainText_SetContent
148 * @tc.type: FUNC
149 */
150HWTEST_F(UdsTest, OH_UdsPlainText_SetContent_001, TestSize.Level1)
151{
152    LOG_INFO(UDMF_TEST, "OH_UdsPlainText_SetContent_001 begin.");
153    auto plainText = OH_UdsPlainText_Create();
154    int result = OH_UdsPlainText_SetContent(plainText, "doing something");
155    EXPECT_EQ(UDMF_E_OK, result);
156    EXPECT_EQ("doing something", std::string(OH_UdsPlainText_GetContent(plainText)));
157
158    result = OH_UdsPlainText_SetContent(nullptr, "doing something");
159    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
160
161    result = OH_UdsPlainText_SetContent(plainText, nullptr);
162    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
163
164    plainText->obj = nullptr;
165    result = OH_UdsPlainText_SetContent(plainText, "doing something");
166    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
167    OH_UdsPlainText_Destroy(plainText);
168    LOG_INFO(UDMF_TEST, "OH_UdsPlainText_SetContent_001 end.");
169}
170
171/**
172 * @tc.name: OH_UdsPlainText_SetAbstract_001
173 * @tc.desc: Normal testcase of OH_UdsPlainText_SetAbstract
174 * @tc.type: FUNC
175 */
176HWTEST_F(UdsTest, OH_UdsPlainText_SetAbstract_001, TestSize.Level1)
177{
178    LOG_INFO(UDMF_TEST, "OH_UdsPlainText_SetAbstract_001 begin.");
179    auto plainText = OH_UdsPlainText_Create();
180    int result = OH_UdsPlainText_SetAbstract(plainText, "doing something");
181    EXPECT_EQ(UDMF_E_OK, result);
182    EXPECT_EQ("doing something", std::string(OH_UdsPlainText_GetAbstract(plainText)));
183
184    result = OH_UdsPlainText_SetAbstract(nullptr, "doing something");
185    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
186
187    result = OH_UdsPlainText_SetAbstract(plainText, nullptr);
188    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
189
190    plainText->obj = nullptr;
191    result = OH_UdsPlainText_SetAbstract(plainText, "doing something");
192    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
193    OH_UdsPlainText_Destroy(plainText);
194    LOG_INFO(UDMF_TEST, "OH_UdsPlainText_SetAbstract_001 end.");
195}
196
197/**
198 * @tc.name: OH_UdsHyperlink_Create_001
199 * @tc.desc: Normal testcase of OH_UdsHyperlink_Create
200 * @tc.type: FUNC
201 */
202HWTEST_F(UdsTest, OH_UdsHyperlink_Create_001, TestSize.Level1)
203{
204    LOG_INFO(UDMF_TEST, "OH_UdsHyperlink_Create_001 begin.");
205    auto hyperlink = OH_UdsHyperlink_Create();
206    EXPECT_EQ(UDMF_META_HYPERLINK, *(std::get_if<std::string>(&(hyperlink->obj)->value_[UNIFORM_DATA_TYPE])));
207    OH_UdsHyperlink_Destroy(hyperlink);
208    LOG_INFO(UDMF_TEST, "OH_UdsHyperlink_Create_001 end.");
209}
210
211/**
212 * @tc.name: OH_UdsHyperlink_GetType_001
213 * @tc.desc: Normal testcase of OH_UdsHyperlink_GetType
214 * @tc.type: FUNC
215 */
216HWTEST_F(UdsTest, OH_UdsHyperlink_GetType_001, TestSize.Level1)
217{
218    LOG_INFO(UDMF_TEST, "OH_UdsHyperlink_GetType_001 begin.");
219    auto hyperlink = OH_UdsHyperlink_Create();
220    EXPECT_EQ(UDMF_META_HYPERLINK, std::string(OH_UdsHyperlink_GetType(hyperlink)));
221    OH_UdsHyperlink_Destroy(hyperlink);
222
223    OH_UdsHyperlink* hyperlinkNullptr = nullptr;
224    EXPECT_EQ(nullptr, OH_UdsHyperlink_GetType(hyperlinkNullptr));
225
226    hyperlinkNullptr = new OH_UdsHyperlink;
227    EXPECT_EQ(nullptr, OH_UdsHyperlink_GetType(hyperlinkNullptr));
228    OH_UdsHyperlink_Destroy(hyperlinkNullptr);
229    LOG_INFO(UDMF_TEST, "OH_UdsHyperlink_GetType_001 end.");
230}
231
232/**
233 * @tc.name: OH_UdsHyperlink_GetUrl_001
234 * @tc.desc: Normal testcase of OH_UdsHyperlink_GetUrl
235 * @tc.type: FUNC
236 */
237HWTEST_F(UdsTest, OH_UdsHyperlink_GetUrl_001, TestSize.Level1)
238{
239    LOG_INFO(UDMF_TEST, "OH_UdsHyperlink_GetUrl_001 begin.");
240    auto hyperlink = OH_UdsHyperlink_Create();
241    hyperlink->obj->value_[URL] = "www.xxx.com";
242    EXPECT_EQ("www.xxx.com", std::string(OH_UdsHyperlink_GetUrl(hyperlink)));
243    OH_UdsHyperlink_Destroy(hyperlink);
244
245    OH_UdsHyperlink* hyperlinkNullptr = nullptr;
246    EXPECT_EQ(nullptr, OH_UdsHyperlink_GetUrl(hyperlinkNullptr));
247
248    hyperlinkNullptr = new OH_UdsHyperlink;
249    EXPECT_EQ(nullptr, OH_UdsHyperlink_GetUrl(hyperlinkNullptr));
250    OH_UdsHyperlink_Destroy(hyperlinkNullptr);
251    LOG_INFO(UDMF_TEST, "OH_UdsHyperlink_GetUrl_001 end.");
252}
253
254/**
255 * @tc.name: OH_UdsHyperlink_GetDescription_001
256 * @tc.desc: Normal testcase of OH_UdsHyperlink_GetDescription
257 * @tc.type: FUNC
258 */
259HWTEST_F(UdsTest, OH_UdsHyperlink_GetDescription_001, TestSize.Level1)
260{
261    LOG_INFO(UDMF_TEST, "OH_UdsHyperlink_GetDescription_001 begin.");
262    auto hyperlink = OH_UdsHyperlink_Create();
263    hyperlink->obj->value_[DESCRIPTION] = "do something";
264    EXPECT_EQ("do something", std::string(OH_UdsHyperlink_GetDescription(hyperlink)));
265    OH_UdsHyperlink_Destroy(hyperlink);
266
267    OH_UdsHyperlink* hyperlinkNullptr = nullptr;
268    EXPECT_EQ(nullptr, OH_UdsHyperlink_GetDescription(hyperlinkNullptr));
269
270    hyperlinkNullptr = new OH_UdsHyperlink;
271    EXPECT_EQ(nullptr, OH_UdsHyperlink_GetDescription(hyperlinkNullptr));
272    OH_UdsHyperlink_Destroy(hyperlinkNullptr);
273    LOG_INFO(UDMF_TEST, "OH_UdsHyperlink_GetDescription_001 end.");
274}
275
276/**
277 * @tc.name: OH_UdsHyperlink_SetUrl_001
278 * @tc.desc: Normal testcase of OH_UdsHyperlink_SetUrl
279 * @tc.type: FUNC
280 */
281HWTEST_F(UdsTest, OH_UdsHyperlink_SetUrl_001, TestSize.Level1)
282{
283    LOG_INFO(UDMF_TEST, "OH_UdsHyperlink_SetUrl_001 begin.");
284    auto hyperlink = OH_UdsHyperlink_Create();
285    int result = OH_UdsHyperlink_SetUrl(hyperlink, "www.xxx.com");
286    EXPECT_EQ(UDMF_E_OK, result);
287    EXPECT_EQ("www.xxx.com", std::string(OH_UdsHyperlink_GetUrl(hyperlink)));
288
289    result = OH_UdsHyperlink_SetUrl(nullptr, "www.xxx.com");
290    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
291
292    result = OH_UdsHyperlink_SetUrl(hyperlink, nullptr);
293    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
294
295    hyperlink->obj = nullptr;
296    result = OH_UdsHyperlink_SetUrl(hyperlink, "www.xxx.com");
297    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
298    OH_UdsHyperlink_Destroy(hyperlink);
299    LOG_INFO(UDMF_TEST, "OH_UdsHyperlink_SetUrl_001 end.");
300}
301
302/**
303 * @tc.name: OH_UdsHyperlink_SetDescription_001
304 * @tc.desc: Normal testcase of OH_UdsHyperlink_SetDescription
305 * @tc.type: FUNC
306 */
307HWTEST_F(UdsTest, OH_UdsHyperlink_SetDescription_001, TestSize.Level1)
308{
309    LOG_INFO(UDMF_TEST, "OH_UdsHyperlink_SetDescription_001 begin.");
310    auto hyperlink = OH_UdsHyperlink_Create();
311    int result = OH_UdsHyperlink_SetDescription(hyperlink, "doing something");
312    EXPECT_EQ(UDMF_E_OK, result);
313    EXPECT_EQ("doing something", std::string(OH_UdsHyperlink_GetDescription(hyperlink)));
314
315    result = OH_UdsHyperlink_SetDescription(nullptr, "doing something");
316    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
317
318    result = OH_UdsHyperlink_SetDescription(hyperlink, nullptr);
319    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
320
321    hyperlink->obj = nullptr;
322    result = OH_UdsHyperlink_SetDescription(hyperlink, "doing something");
323    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
324    OH_UdsHyperlink_Destroy(hyperlink);
325    LOG_INFO(UDMF_TEST, "OH_UdsHyperlink_SetDescription_001 end.");
326}
327
328/**
329 * @tc.name: OH_UdsHtml_Create_001
330 * @tc.desc: Normal testcase of OH_UdsHtml_Create
331 * @tc.type: FUNC
332 */
333HWTEST_F(UdsTest, OH_UdsHtml_Create_001, TestSize.Level1)
334{
335    LOG_INFO(UDMF_TEST, "OH_UdsHtml_Create_001 begin.");
336    auto html = OH_UdsHtml_Create();
337    EXPECT_EQ(UDMF_META_HTML, *(std::get_if<std::string>(&(html->obj)->value_[UNIFORM_DATA_TYPE])));
338    OH_UdsHtml_Destroy(html);
339    LOG_INFO(UDMF_TEST, "OH_UdsHtml_Create_001 end.");
340}
341
342/**
343 * @tc.name: OH_UdsHtml_GetType_001
344 * @tc.desc: Normal testcase of OH_UdsHtml_GetType
345 * @tc.type: FUNC
346 */
347HWTEST_F(UdsTest, OH_UdsHtml_GetType_001, TestSize.Level1)
348{
349    LOG_INFO(UDMF_TEST, "OH_UdsHtml_GetType_001 begin.");
350    auto html = OH_UdsHtml_Create();
351    EXPECT_EQ(UDMF_META_HTML, std::string(OH_UdsHtml_GetType(html)));
352    OH_UdsHtml_Destroy(html);
353
354    OH_UdsHtml* htmlNullptr = nullptr;
355    EXPECT_EQ(nullptr, OH_UdsHtml_GetType(htmlNullptr));
356
357    htmlNullptr = new OH_UdsHtml;
358    EXPECT_EQ(nullptr, OH_UdsHtml_GetType(htmlNullptr));
359    OH_UdsHtml_Destroy(htmlNullptr);
360    LOG_INFO(UDMF_TEST, "OH_UdsHtml_GetType_001 end.");
361}
362
363/**
364 * @tc.name: OH_UdsHtml_GetContent_001
365 * @tc.desc: Normal testcase of OH_UdsHtml_GetContent
366 * @tc.type: FUNC
367 */
368HWTEST_F(UdsTest, OH_UdsHtml_GetContent_001, TestSize.Level1)
369{
370    LOG_INFO(UDMF_TEST, "OH_UdsHtml_GetContent_001 begin.");
371    auto html = OH_UdsHtml_Create();
372    html->obj->value_[HTML_CONTENT] = "htmlxxxxx";
373    EXPECT_EQ("htmlxxxxx", std::string(OH_UdsHtml_GetContent(html)));
374    OH_UdsHtml_Destroy(html);
375
376    OH_UdsHtml* htmlNullptr = nullptr;
377    EXPECT_EQ(nullptr, OH_UdsHtml_GetContent(htmlNullptr));
378
379    htmlNullptr = new OH_UdsHtml;
380    EXPECT_EQ(nullptr, OH_UdsHtml_GetContent(htmlNullptr));
381    OH_UdsHtml_Destroy(htmlNullptr);
382    LOG_INFO(UDMF_TEST, "OH_UdsHtml_GetContent_001 end.");
383}
384
385/**
386 * @tc.name: OH_UdsHtml_GetPlainContent_001
387 * @tc.desc: Normal testcase of OH_UdsHtml_GetPlainContent
388 * @tc.type: FUNC
389 */
390HWTEST_F(UdsTest, OH_UdsHtml_GetPlainContent_001, TestSize.Level1)
391{
392    LOG_INFO(UDMF_TEST, "OH_UdsHtml_GetPlainContent_001 begin.");
393    auto html = OH_UdsHtml_Create();
394    html->obj->value_[PLAIN_CONTENT] = "do something";
395    EXPECT_EQ("do something", std::string(OH_UdsHtml_GetPlainContent(html)));
396    OH_UdsHtml_Destroy(html);
397
398    OH_UdsHtml* htmlNullptr = nullptr;
399    EXPECT_EQ(nullptr, OH_UdsHtml_GetPlainContent(htmlNullptr));
400
401    htmlNullptr = new OH_UdsHtml;
402    EXPECT_EQ(nullptr, OH_UdsHtml_GetPlainContent(htmlNullptr));
403    OH_UdsHtml_Destroy(htmlNullptr);
404    LOG_INFO(UDMF_TEST, "OH_UdsHtml_GetPlainContent_001 end.");
405}
406
407/**
408 * @tc.name: OH_UdsHtml_SetContent_001
409 * @tc.desc: Normal testcase of OH_UdsHtml_SetContent
410 * @tc.type: FUNC
411 */
412HWTEST_F(UdsTest, OH_UdsHtml_SetContent_001, TestSize.Level1)
413{
414    LOG_INFO(UDMF_TEST, "OH_UdsHtml_SetContent_001 begin.");
415    auto html = OH_UdsHtml_Create();
416    int result = OH_UdsHtml_SetContent(html, "htmlxxx");
417    EXPECT_EQ(UDMF_E_OK, result);
418    EXPECT_EQ("htmlxxx", std::string(OH_UdsHtml_GetContent(html)));
419
420    result = OH_UdsHtml_SetContent(nullptr, "htmlxxx");
421    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
422
423    result = OH_UdsHtml_SetContent(html, nullptr);
424    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
425
426    html->obj = nullptr;
427    result = OH_UdsHtml_SetContent(html, "htmlxxx");
428    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
429    OH_UdsHtml_Destroy(html);
430    LOG_INFO(UDMF_TEST, "OH_UdsHtml_SetContent_001 end.");
431}
432
433/**
434 * @tc.name: OH_UdsHtml_SetPlainContent_001
435 * @tc.desc: Normal testcase of OH_UdsHtml_SetPlainContent
436 * @tc.type: FUNC
437 */
438HWTEST_F(UdsTest, OH_UdsHtml_SetPlainContent_001, TestSize.Level1)
439{
440    LOG_INFO(UDMF_TEST, "OH_UdsHtml_SetPlainContent_001 begin.");
441    auto html = OH_UdsHtml_Create();
442    int result = OH_UdsHtml_SetPlainContent(html, "doing something");
443    EXPECT_EQ(UDMF_E_OK, result);
444    EXPECT_EQ("doing something", std::string(OH_UdsHtml_GetPlainContent(html)));
445
446    result = OH_UdsHtml_SetPlainContent(nullptr, "doing something");
447    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
448
449    result = OH_UdsHtml_SetPlainContent(html, nullptr);
450    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
451
452    html->obj = nullptr;
453    result = OH_UdsHtml_SetPlainContent(html, "doing something");
454    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
455    OH_UdsHtml_Destroy(html);
456    LOG_INFO(UDMF_TEST, "OH_UdsHtml_SetPlainContent_001 end.");
457}
458
459/**
460 * @tc.name: OH_UdsAppItem_Create_001
461 * @tc.desc: Normal testcase of OH_UdsAppItem_Create
462 * @tc.type: FUNC
463 */
464HWTEST_F(UdsTest, OH_UdsAppItem_Create_001, TestSize.Level1)
465{
466    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_Create_001 begin.");
467    auto appItem = OH_UdsAppItem_Create();
468    EXPECT_EQ(UDMF_META_OPENHARMONY_APP_ITEM, *(std::get_if<std::string>(&(appItem->obj)->value_[UNIFORM_DATA_TYPE])));
469    OH_UdsAppItem_Destroy(appItem);
470    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_Create_001 end.");
471}
472
473/**
474 * @tc.name: OH_UdsAppItem_GetType_001
475 * @tc.desc: Normal testcase of OH_UdsAppItem_GetType
476 * @tc.type: FUNC
477 */
478HWTEST_F(UdsTest, OH_UdsAppItem_GetType_001, TestSize.Level1)
479{
480    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_GetType_001 begin.");
481    auto appItem = OH_UdsAppItem_Create();
482    EXPECT_EQ(UDMF_META_OPENHARMONY_APP_ITEM, std::string(OH_UdsAppItem_GetType(appItem)));
483    OH_UdsAppItem_Destroy(appItem);
484
485    OH_UdsAppItem* appItemNullptr = nullptr;
486    EXPECT_EQ(nullptr, OH_UdsAppItem_GetType(appItemNullptr));
487
488    appItemNullptr = new OH_UdsAppItem;
489    EXPECT_EQ(nullptr, OH_UdsAppItem_GetType(appItemNullptr));
490    OH_UdsAppItem_Destroy(appItemNullptr);
491    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_GetType_001 end.");
492}
493
494/**
495 * @tc.name: OH_UdsAppItem_GetId_001
496 * @tc.desc: Normal testcase of OH_UdsAppItem_GetId
497 * @tc.type: FUNC
498 */
499HWTEST_F(UdsTest, OH_UdsAppItem_GetId_001, TestSize.Level1)
500{
501    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_GetId_001 begin.");
502    auto appItem = OH_UdsAppItem_Create();
503    appItem->obj->value_[APP_ID] = "com.xxx";
504    EXPECT_EQ("com.xxx", std::string(OH_UdsAppItem_GetId(appItem)));
505    OH_UdsAppItem_Destroy(appItem);
506
507    OH_UdsAppItem* appItemNullptr = nullptr;
508    EXPECT_EQ(nullptr, OH_UdsAppItem_GetId(appItemNullptr));
509
510    appItemNullptr = new OH_UdsAppItem;
511    EXPECT_EQ(nullptr, OH_UdsAppItem_GetId(appItemNullptr));
512    OH_UdsAppItem_Destroy(appItemNullptr);
513    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_GetId_001 end.");
514}
515
516/**
517 * @tc.name: OH_UdsAppItem_GetName_001
518 * @tc.desc: Normal testcase of OH_UdsAppItem_GetName
519 * @tc.type: FUNC
520 */
521HWTEST_F(UdsTest, OH_UdsAppItem_GetName_001, TestSize.Level1)
522{
523    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_GetName_001 begin.");
524    auto appItem = OH_UdsAppItem_Create();
525    appItem->obj->value_[APP_NAME] = "OH";
526    EXPECT_EQ("OH", std::string(OH_UdsAppItem_GetName(appItem)));
527    OH_UdsAppItem_Destroy(appItem);
528
529    OH_UdsAppItem* appItemNullptr = nullptr;
530    EXPECT_EQ(nullptr, OH_UdsAppItem_GetName(appItemNullptr));
531
532    appItemNullptr = new OH_UdsAppItem;
533    EXPECT_EQ(nullptr, OH_UdsAppItem_GetName(appItemNullptr));
534    OH_UdsAppItem_Destroy(appItemNullptr);
535    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_GetName_001 end.");
536}
537
538/**
539 * @tc.name: OH_UdsAppItem_GetIconId_001
540 * @tc.desc: Normal testcase of OH_UdsAppItem_GetIconId
541 * @tc.type: FUNC
542 */
543HWTEST_F(UdsTest, OH_UdsAppItem_GetIconId_001, TestSize.Level1)
544{
545    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_GetIconId_001 begin.");
546    auto appItem = OH_UdsAppItem_Create();
547    appItem->obj->value_[APP_ICON_ID] = "icon";
548    EXPECT_EQ("icon", std::string(OH_UdsAppItem_GetIconId(appItem)));
549    OH_UdsAppItem_Destroy(appItem);
550
551    OH_UdsAppItem* appItemNullptr = nullptr;
552    EXPECT_EQ(nullptr, OH_UdsAppItem_GetIconId(appItemNullptr));
553
554    appItemNullptr = new OH_UdsAppItem;
555    EXPECT_EQ(nullptr, OH_UdsAppItem_GetIconId(appItemNullptr));
556    OH_UdsAppItem_Destroy(appItemNullptr);
557    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_GetIconId_001 end.");
558}
559
560/**
561 * @tc.name: OH_UdsAppItem_GetLabelId_001
562 * @tc.desc: Normal testcase of OH_UdsAppItem_GetLabelId
563 * @tc.type: FUNC
564 */
565HWTEST_F(UdsTest, OH_UdsAppItem_GetLabelId_001, TestSize.Level1)
566{
567    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_GetLabelId_001 begin.");
568    auto appItem = OH_UdsAppItem_Create();
569    appItem->obj->value_[APP_LABEL_ID] = "label";
570    EXPECT_EQ("label", std::string(OH_UdsAppItem_GetLabelId(appItem)));
571    OH_UdsAppItem_Destroy(appItem);
572
573    OH_UdsAppItem* appItemNullptr = nullptr;
574    EXPECT_EQ(nullptr, OH_UdsAppItem_GetLabelId(appItemNullptr));
575
576    appItemNullptr = new OH_UdsAppItem;
577    EXPECT_EQ(nullptr, OH_UdsAppItem_GetLabelId(appItemNullptr));
578    OH_UdsAppItem_Destroy(appItemNullptr);
579    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_GetLabelId_001 end.");
580}
581
582/**
583 * @tc.name: OH_UdsAppItem_GetBundleName_001
584 * @tc.desc: Normal testcase of OH_UdsAppItem_GetBundleName
585 * @tc.type: FUNC
586 */
587HWTEST_F(UdsTest, OH_UdsAppItem_GetBundleName_001, TestSize.Level1)
588{
589    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_GetBundleName_001 begin.");
590    auto appItem = OH_UdsAppItem_Create();
591    appItem->obj->value_[BUNDLE_NAME] = "bundle";
592    EXPECT_EQ("bundle", std::string(OH_UdsAppItem_GetBundleName(appItem)));
593    OH_UdsAppItem_Destroy(appItem);
594
595    OH_UdsAppItem* appItemNullptr = nullptr;
596    EXPECT_EQ(nullptr, OH_UdsAppItem_GetBundleName(appItemNullptr));
597
598    appItemNullptr = new OH_UdsAppItem;
599    EXPECT_EQ(nullptr, OH_UdsAppItem_GetBundleName(appItemNullptr));
600    OH_UdsAppItem_Destroy(appItemNullptr);
601    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_GetBundleName_001 end.");
602}
603
604/**
605 * @tc.name: OH_UdsAppItem_GetAbilityName_001
606 * @tc.desc: Normal testcase of OH_UdsAppItem_GetAbilityName
607 * @tc.type: FUNC
608 */
609HWTEST_F(UdsTest, OH_UdsAppItem_GetAbilityName_001, TestSize.Level1)
610{
611    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_GetAbilityName_001 begin.");
612    auto appItem = OH_UdsAppItem_Create();
613    appItem->obj->value_[ABILITY_NAME] = "ability";
614    EXPECT_EQ("ability", std::string(OH_UdsAppItem_GetAbilityName(appItem)));
615    OH_UdsAppItem_Destroy(appItem);
616
617    OH_UdsAppItem* appItemNullptr = nullptr;
618    EXPECT_EQ(nullptr, OH_UdsAppItem_GetAbilityName(appItemNullptr));
619
620    appItemNullptr = new OH_UdsAppItem;
621    EXPECT_EQ(nullptr, OH_UdsAppItem_GetAbilityName(appItemNullptr));
622    OH_UdsAppItem_Destroy(appItemNullptr);
623    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_GetAbilityName_001 end.");
624}
625
626/**
627 * @tc.name: OH_UdsAppItem_SetId_001
628 * @tc.desc: Normal testcase of OH_UdsAppItem_SetId
629 * @tc.type: FUNC
630 */
631HWTEST_F(UdsTest, OH_UdsAppItem_SetId_001, TestSize.Level1)
632{
633    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_SetId_001 begin.");
634    auto appItem = OH_UdsAppItem_Create();
635    int result = OH_UdsAppItem_SetId(appItem, "com.xxx");
636    EXPECT_EQ(UDMF_E_OK, result);
637    EXPECT_EQ("com.xxx", std::string(OH_UdsAppItem_GetId(appItem)));
638
639    result = OH_UdsAppItem_SetId(nullptr, "com.xxx");
640    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
641
642    result = OH_UdsAppItem_SetId(appItem, nullptr);
643    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
644
645    appItem->obj = nullptr;
646    result = OH_UdsAppItem_SetId(appItem, "com.xxx");
647    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
648    OH_UdsAppItem_Destroy(appItem);
649    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_SetId_001 end.");
650}
651
652/**
653 * @tc.name: OH_UdsAppItem_SetName_001
654 * @tc.desc: Normal testcase of OH_UdsAppItem_SetName
655 * @tc.type: FUNC
656 */
657HWTEST_F(UdsTest, OH_UdsAppItem_SetName_001, TestSize.Level1)
658{
659    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_SetName_001 begin.");
660    auto appItem = OH_UdsAppItem_Create();
661    int result = OH_UdsAppItem_SetName(appItem, "OH");
662    EXPECT_EQ(UDMF_E_OK, result);
663    EXPECT_EQ("OH", std::string(OH_UdsAppItem_GetName(appItem)));
664
665    result = OH_UdsAppItem_SetName(nullptr, "OH");
666    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
667
668    result = OH_UdsAppItem_SetName(appItem, nullptr);
669    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
670
671    appItem->obj = nullptr;
672    result = OH_UdsAppItem_SetName(appItem, "OH");
673    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
674    OH_UdsAppItem_Destroy(appItem);
675    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_SetName_001 end.");
676}
677
678/**
679 * @tc.name: OH_UdsAppItem_SetIconId_001
680 * @tc.desc: Normal testcase of OH_UdsAppItem_SetIconId
681 * @tc.type: FUNC
682 */
683HWTEST_F(UdsTest, OH_UdsAppItem_SetIconId_001, TestSize.Level1)
684{
685    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_SetIconId_001 begin.");
686    auto appItem = OH_UdsAppItem_Create();
687    int result = OH_UdsAppItem_SetIconId(appItem, "icon");
688    EXPECT_EQ(UDMF_E_OK, result);
689    EXPECT_EQ("icon", std::string(OH_UdsAppItem_GetIconId(appItem)));
690
691    result = OH_UdsAppItem_SetIconId(nullptr, "icon");
692    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
693
694    result = OH_UdsAppItem_SetIconId(appItem, nullptr);
695    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
696
697    appItem->obj = nullptr;
698    result = OH_UdsAppItem_SetIconId(appItem, "icon");
699    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
700    OH_UdsAppItem_Destroy(appItem);
701    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_SetIconId_001 end.");
702}
703
704/**
705 * @tc.name: OH_UdsAppItem_SetLabelId_001
706 * @tc.desc: Normal testcase of OH_UdsAppItem_SetLabelId
707 * @tc.type: FUNC
708 */
709HWTEST_F(UdsTest, OH_UdsAppItem_SetLabelId_001, TestSize.Level1)
710{
711    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_SetLabelId_001 begin.");
712    auto appItem = OH_UdsAppItem_Create();
713    int result = OH_UdsAppItem_SetLabelId(appItem, "label");
714    EXPECT_EQ(UDMF_E_OK, result);
715    EXPECT_EQ("label", std::string(OH_UdsAppItem_GetLabelId(appItem)));
716
717    result = OH_UdsAppItem_SetLabelId(nullptr, "label");
718    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
719
720    result = OH_UdsAppItem_SetLabelId(appItem, nullptr);
721    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
722
723    appItem->obj = nullptr;
724    result = OH_UdsAppItem_SetLabelId(appItem, "label");
725    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
726    OH_UdsAppItem_Destroy(appItem);
727    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_SetLabelId_001 end.");
728}
729
730/**
731 * @tc.name: OH_UdsAppItem_SetBundleName_001
732 * @tc.desc: Normal testcase of OH_UdsAppItem_SetBundleName
733 * @tc.type: FUNC
734 */
735HWTEST_F(UdsTest, OH_UdsAppItem_SetBundleName_001, TestSize.Level1)
736{
737    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_SetBundleName_001 begin.");
738    auto appItem = OH_UdsAppItem_Create();
739    int result = OH_UdsAppItem_SetBundleName(appItem, "bundle");
740    EXPECT_EQ(UDMF_E_OK, result);
741    EXPECT_EQ("bundle", std::string(OH_UdsAppItem_GetBundleName(appItem)));
742
743    result = OH_UdsAppItem_SetBundleName(nullptr, "bundle");
744    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
745
746    result = OH_UdsAppItem_SetBundleName(appItem, nullptr);
747    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
748
749    appItem->obj = nullptr;
750    result = OH_UdsAppItem_SetBundleName(appItem, "bundle");
751    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
752    OH_UdsAppItem_Destroy(appItem);
753    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_SetBundleName_001 end.");
754}
755
756/**
757 * @tc.name: OH_UdsAppItem_SetAbilityName_001
758 * @tc.desc: Normal testcase of OH_UdsAppItem_SetAbilityName
759 * @tc.type: FUNC
760 */
761HWTEST_F(UdsTest, OH_UdsAppItem_SetAbilityName_001, TestSize.Level1)
762{
763    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_SetAbilityName_001 begin.");
764    auto appItem = OH_UdsAppItem_Create();
765    int result = OH_UdsAppItem_SetAbilityName(appItem, "ability");
766    EXPECT_EQ(UDMF_E_OK, result);
767    EXPECT_EQ("ability", std::string(OH_UdsAppItem_GetAbilityName(appItem)));
768
769    result = OH_UdsAppItem_SetAbilityName(nullptr, "ability");
770    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
771
772    result = OH_UdsAppItem_SetAbilityName(appItem, nullptr);
773    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
774
775    appItem->obj = nullptr;
776    result = OH_UdsAppItem_SetAbilityName(appItem, "ability");
777    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
778    OH_UdsAppItem_Destroy(appItem);
779    LOG_INFO(UDMF_TEST, "OH_UdsAppItem_SetAbilityName_001 end.");
780}
781
782/**
783 * @tc.name: OH_UdsFileUri_Create_001
784 * @tc.desc: Normal testcase of OH_UdsFileUri_Create
785 * @tc.type: FUNC
786 */
787HWTEST_F(UdsTest, OH_UdsFileUri_Create_001, TestSize.Level1)
788{
789    auto fileUri = OH_UdsFileUri_Create();
790    EXPECT_EQ(UDMF_META_GENERAL_FILE_URI, *(std::get_if<std::string>(&(fileUri->obj)->value_[UNIFORM_DATA_TYPE])));
791    OH_UdsFileUri_Destroy(fileUri);
792}
793
794/**
795 * @tc.name: OH_UdsFileUri_GetType_001
796 * @tc.desc: Normal testcase of OH_UdsFileUri_GetType
797 * @tc.type: FUNC
798 */
799HWTEST_F(UdsTest, OH_UdsFileUri_GetType_001, TestSize.Level1)
800{
801    auto fileUri = OH_UdsFileUri_Create();
802    EXPECT_EQ(UDMF_META_GENERAL_FILE_URI, std::string(OH_UdsFileUri_GetType(fileUri)));
803    OH_UdsFileUri_Destroy(fileUri);
804
805    OH_UdsFileUri* fileUriNullptr = nullptr;
806    EXPECT_EQ(nullptr, OH_UdsFileUri_GetType(fileUriNullptr));
807
808    fileUriNullptr = new OH_UdsFileUri;
809    EXPECT_EQ(nullptr, OH_UdsFileUri_GetType(fileUriNullptr));
810    OH_UdsFileUri_Destroy(fileUriNullptr);
811}
812
813/**
814 * @tc.name: OH_UdsFileUri_GetFileUri_001
815 * @tc.desc: Normal testcase of OH_UdsFileUri_GetFileUri
816 * @tc.type: FUNC
817 */
818HWTEST_F(UdsTest, OH_UdsFileUri_GetFileUri_001, TestSize.Level1)
819{
820    auto fileUri = OH_UdsFileUri_Create();
821    fileUri->obj->value_[FILE_URI_PARAM] = "fileUri";
822    EXPECT_EQ("fileUri", std::string(OH_UdsFileUri_GetFileUri(fileUri)));
823    OH_UdsFileUri_Destroy(fileUri);
824
825    OH_UdsFileUri* fileUriNullptr = nullptr;
826    EXPECT_EQ(nullptr, OH_UdsFileUri_GetFileUri(fileUriNullptr));
827
828    fileUriNullptr = new OH_UdsFileUri;
829    EXPECT_EQ(nullptr, OH_UdsFileUri_GetFileUri(fileUriNullptr));
830    OH_UdsFileUri_Destroy(fileUriNullptr);
831}
832
833/**
834 * @tc.name: OH_UdsFileUri_GetFileType_001
835 * @tc.desc: Normal testcase of OH_UdsFileUri_GetFileType
836 * @tc.type: FUNC
837 */
838HWTEST_F(UdsTest, OH_UdsFileUri_GetFileType_001, TestSize.Level1)
839{
840    auto fileUri = OH_UdsFileUri_Create();
841    fileUri->obj->value_[FILE_TYPE] = "fileType";
842    EXPECT_EQ("fileType", std::string(OH_UdsFileUri_GetFileType(fileUri)));
843    OH_UdsFileUri_Destroy(fileUri);
844
845    OH_UdsFileUri* fileUriNullptr = nullptr;
846    EXPECT_EQ(nullptr, OH_UdsFileUri_GetFileType(fileUriNullptr));
847
848    fileUriNullptr = new OH_UdsFileUri;
849    EXPECT_EQ(nullptr, OH_UdsFileUri_GetFileType(fileUriNullptr));
850    OH_UdsFileUri_Destroy(fileUriNullptr);
851}
852
853/**
854 * @tc.name: OH_UdsFileUri_SetFileUri_001
855 * @tc.desc: Normal testcase of OH_UdsFileUri_SetFileUri
856 * @tc.type: FUNC
857 */
858HWTEST_F(UdsTest, OH_UdsFileUri_SetFileUri_001, TestSize.Level1)
859{
860    auto fileUri = OH_UdsFileUri_Create();
861    int result = OH_UdsFileUri_SetFileUri(fileUri, "file uri");
862    EXPECT_EQ(UDMF_E_OK, result);
863    EXPECT_EQ("file uri", std::string(OH_UdsFileUri_GetFileUri(fileUri)));
864
865    result = OH_UdsFileUri_SetFileUri(nullptr, "file uri");
866    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
867
868    result = OH_UdsFileUri_SetFileUri(fileUri, nullptr);
869    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
870
871    fileUri->obj = nullptr;
872    result = OH_UdsFileUri_SetFileUri(fileUri, "file uri");
873    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
874    OH_UdsFileUri_Destroy(fileUri);
875}
876
877/**
878 * @tc.name: OH_UdsFileUri_SetFileUri_001
879 * @tc.desc: Normal testcase of OH_UdsFileUri_SetFileUri
880 * @tc.type: FUNC
881 */
882HWTEST_F(UdsTest, OH_UdsFileUri_SetFileType_001, TestSize.Level1)
883{
884    auto fileUri = OH_UdsFileUri_Create();
885    int result = OH_UdsFileUri_SetFileType(fileUri, "file type");
886    EXPECT_EQ(UDMF_E_OK, result);
887    EXPECT_EQ("file type", std::string(OH_UdsFileUri_GetFileType(fileUri)));
888
889    result = OH_UdsFileUri_SetFileType(nullptr, "file type");
890    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
891
892    result = OH_UdsFileUri_SetFileType(fileUri, nullptr);
893    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
894
895    fileUri->obj = nullptr;
896    result = OH_UdsFileUri_SetFileType(fileUri, "file type");
897    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
898    OH_UdsFileUri_Destroy(fileUri);
899}
900
901/**
902 * @tc.name: OH_UdsPixelMap_Create_001
903 * @tc.desc: Normal testcase of OH_UdsPixelMap_Create
904 * @tc.type: FUNC
905 */
906HWTEST_F(UdsTest, OH_UdsPixelMap_Create_001, TestSize.Level1)
907{
908    auto pixelMap = OH_UdsPixelMap_Create();
909    EXPECT_EQ(UDMF_META_OPENHARMONY_PIXEL_MAP,
910        *(std::get_if<std::string>(&(pixelMap->obj)->value_[UNIFORM_DATA_TYPE])));
911    OH_UdsPixelMap_Destroy(pixelMap);
912}
913
914/**
915 * @tc.name: OH_UdsPixelMap_GetType_001
916 * @tc.desc: Normal testcase of OH_UdsPixelMap_GetType
917 * @tc.type: FUNC
918 */
919HWTEST_F(UdsTest, OH_UdsPixelMap_GetType_001, TestSize.Level1)
920{
921    auto pixelMap = OH_UdsPixelMap_Create();
922    EXPECT_EQ(UDMF_META_OPENHARMONY_PIXEL_MAP, std::string(OH_UdsPixelMap_GetType(pixelMap)));
923    OH_UdsPixelMap_Destroy(pixelMap);
924
925    OH_UdsPixelMap* pixelMapNullptr = nullptr;
926    EXPECT_EQ(nullptr, OH_UdsPixelMap_GetType(pixelMapNullptr));
927
928    pixelMapNullptr = new OH_UdsPixelMap;
929    EXPECT_EQ(nullptr, OH_UdsPixelMap_GetType(pixelMapNullptr));
930    OH_UdsPixelMap_Destroy(pixelMapNullptr);
931}
932
933/**
934 * @tc.name: OH_UdsPixelMap_GetPixelMap_001
935 * @tc.desc: Normal testcase of OH_UdsPixelMap_GetPixelMap
936 * @tc.type: FUNC
937 */
938HWTEST_F(UdsTest, OH_UdsPixelMap_GetPixelMap_001, TestSize.Level1)
939{
940    auto pixelMap = OH_UdsPixelMap_Create();
941    std::shared_ptr<OHOS::Media::PixelMap> pixelMapPtr = std::make_shared<OHOS::Media::PixelMap>();
942    pixelMapPtr->SetTransformered(true);
943    pixelMap->obj->value_[PIXEL_MAP] = pixelMapPtr;
944    OH_PixelmapNative* pixelMapResult = new OH_PixelmapNative(nullptr);
945    OH_UdsPixelMap_GetPixelMap(pixelMap, pixelMapResult);
946    auto innerPixelMap = pixelMapResult->GetInnerPixelmap();
947    EXPECT_NE(nullptr, innerPixelMap);
948    EXPECT_TRUE(innerPixelMap->IsTransformered());
949    OH_UdsPixelMap_Destroy(pixelMap);
950    delete pixelMapResult;
951
952    OH_PixelmapNative* ohPixelMapNull = new OH_PixelmapNative(nullptr);
953    OH_UdsPixelMap* pixelMapNullptr = nullptr;
954    OH_UdsPixelMap_GetPixelMap(pixelMapNullptr, ohPixelMapNull);
955    EXPECT_EQ(nullptr, ohPixelMapNull->GetInnerPixelmap());
956    delete pixelMapNullptr;
957
958    pixelMapNullptr = new OH_UdsPixelMap;
959    OH_UdsPixelMap_GetPixelMap(pixelMapNullptr, ohPixelMapNull);
960    EXPECT_EQ(nullptr, ohPixelMapNull->GetInnerPixelmap());
961    delete ohPixelMapNull;
962    OH_UdsPixelMap_Destroy(pixelMapNullptr);
963}
964
965/**
966 * @tc.name: OH_UdsPixelMap_SetPixelMap_001
967 * @tc.desc: Normal testcase of OH_UdsPixelMap_SetPixelMap
968 * @tc.type: FUNC
969 */
970HWTEST_F(UdsTest, OH_UdsPixelMap_SetPixelMap_001, TestSize.Level1)
971{
972    auto pixelMap = OH_UdsPixelMap_Create();
973    std::shared_ptr<OHOS::Media::PixelMap> pixelMapPtr = std::make_shared<OHOS::Media::PixelMap>();
974    pixelMapPtr->SetTransformered(true);
975    OH_PixelmapNative* ohPixelmapNative = new OH_PixelmapNative(pixelMapPtr);
976    int result = OH_UdsPixelMap_SetPixelMap(pixelMap, ohPixelmapNative);
977    EXPECT_EQ(UDMF_E_OK, result);
978    OH_PixelmapNative* pixelMapResult = new OH_PixelmapNative(nullptr);
979    OH_UdsPixelMap_GetPixelMap(pixelMap, pixelMapResult);
980    auto innerPixelMap = pixelMapResult->GetInnerPixelmap();
981    EXPECT_NE(nullptr, innerPixelMap);
982    EXPECT_TRUE(innerPixelMap->IsTransformered());
983
984    result = OH_UdsPixelMap_SetPixelMap(nullptr, ohPixelmapNative);
985    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
986
987    result = OH_UdsPixelMap_SetPixelMap(pixelMap, nullptr);
988    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
989
990    pixelMap->obj = nullptr;
991    result = OH_UdsPixelMap_SetPixelMap(pixelMap, ohPixelmapNative);
992    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
993    delete pixelMapResult;
994    delete ohPixelmapNative;
995    OH_UdsPixelMap_Destroy(pixelMap);
996}
997/**
998 * @tc.name: OH_UdsArrayBuffer_Create_001
999 * @tc.desc: Normal testcase of OH_UdsArrayBuffer_Create
1000 * @tc.type: FUNC
1001 */
1002HWTEST_F(UdsTest, OH_UdsArrayBuffer_Create_001, TestSize.Level1)
1003{
1004    LOG_INFO(UDMF_TEST, "OH_UdsArrayBuffer_Create_001 begin.");
1005    auto buffer = OH_UdsArrayBuffer_Create();
1006    EXPECT_NE(buffer, nullptr);
1007    int ret = OH_UdsArrayBuffer_Destroy(buffer);
1008    EXPECT_EQ(UDMF_E_OK, ret);
1009    LOG_INFO(UDMF_TEST, "OH_UdsArrayBuffer_Create_001 end.");
1010}
1011
1012/**
1013 * @tc.name: OH_UdsArrayBuffer_GetData_001
1014 * @tc.desc: Normal testcase of OH_UdsArrayBuffer_GetData
1015 * @tc.type: FUNC
1016 */
1017HWTEST_F(UdsTest, OH_UdsArrayBuffer_GetData_001, TestSize.Level1)
1018{
1019    LOG_INFO(UDMF_TEST, "OH_UdsArrayBuffer_GetData_001 begin.");
1020    auto buffer = OH_UdsArrayBuffer_Create();
1021
1022    unsigned char data[] = "doing something";
1023    int len = sizeof(data);
1024
1025    std::vector<uint8_t> bufferData(data, data + len);
1026    buffer->obj->value_[ARRAY_BUFFER] = bufferData;
1027    buffer->obj->value_[ARRAY_BUFFER_LENGTH] = len;
1028
1029    unsigned char *getData;
1030    unsigned int getLen;
1031    int ret = OH_UdsArrayBuffer_GetData(buffer, &getData, &getLen);
1032    ASSERT_EQ(UDMF_E_OK, ret);
1033    ASSERT_EQ(len, getLen);
1034    ASSERT_TRUE(CheckUnsignedChar(data, getData, getLen));
1035    OH_UdsArrayBuffer_Destroy(buffer);
1036
1037    OH_UdsArrayBuffer* bufferNullptr = nullptr;
1038    EXPECT_EQ(UDMF_E_INVALID_PARAM, OH_UdsArrayBuffer_GetData(bufferNullptr, &getData, &getLen));
1039    delete bufferNullptr;
1040
1041    bufferNullptr = new OH_UdsArrayBuffer;
1042    EXPECT_EQ(UDMF_E_INVALID_PARAM, OH_UdsArrayBuffer_GetData(bufferNullptr, &getData, &getLen));
1043    OH_UdsArrayBuffer_Destroy(bufferNullptr);
1044    LOG_INFO(UDMF_TEST, "OH_UdsArrayBuffer_GetContent_001 end.");
1045}
1046
1047/**
1048 * @tc.name: OH_UdsArrayBuffer_SetData_001
1049 * @tc.desc: Normal testcase of OH_UdsArrayBuffer_SetData
1050 * @tc.type: FUNC
1051 */
1052HWTEST_F(UdsTest, OH_UdsArrayBuffer_SetData_001, TestSize.Level1)
1053{
1054    LOG_INFO(UDMF_TEST, "OH_UdsArrayBuffer_SetData_001 begin.");
1055    int result = OH_UdsArrayBuffer_SetData(nullptr, nullptr, 0);
1056    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
1057
1058    auto buffer = OH_UdsArrayBuffer_Create();
1059    result = OH_UdsArrayBuffer_SetData(buffer, nullptr, 0);
1060    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
1061
1062    unsigned char data[] = "doing something";
1063    unsigned int len = sizeof(data);
1064    result = OH_UdsArrayBuffer_SetData(buffer, data, 0);
1065    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
1066
1067    result = OH_UdsArrayBuffer_SetData(buffer, data, 100 * 1024 * 1024 + 1);
1068    EXPECT_EQ(UDMF_E_INVALID_PARAM, result);
1069
1070    result = OH_UdsArrayBuffer_SetData(buffer, data, len);
1071    EXPECT_EQ(UDMF_E_OK, result);
1072
1073    unsigned char *getData;
1074    unsigned int getLen;
1075    int ret = OH_UdsArrayBuffer_GetData(buffer, &getData, &getLen);
1076    ASSERT_EQ(UDMF_E_OK, ret);
1077    ASSERT_EQ(len, getLen);
1078    ASSERT_TRUE(CheckUnsignedChar(data, getData, getLen));
1079
1080    OH_UdsArrayBuffer_Destroy(buffer);
1081    LOG_INFO(UDMF_TEST, "OH_UdsArrayBuffer_SetData_001 end.");
1082}
1083
1084/**
1085 * @tc.name: OH_UdsContentForm_SetAndGetParm_001
1086 * @tc.desc: Normal testcase of OH_UdsContentForm's interface
1087 * @tc.type: FUNC
1088 */
1089HWTEST_F(UdsTest, OH_UdsContentForm_SetAndGetParm_001, TestSize.Level1)
1090{
1091    LOG_INFO(UDMF_TEST, "OH_UdsContentForm_SetAndGetParm_001 begin.");
1092    auto contentForm = OH_UdsContentForm_Create();
1093    EXPECT_EQ(UDMF_METE_GENERAL_CONTENT_FORM, std::string(OH_UdsContentForm_GetType(contentForm)));
1094    unsigned char thumbData[] = {0, 1, 2, 3, 4};
1095    unsigned char appIcon[] = {5, 6, 7, 8, 9};
1096    auto result = OH_UdsContentForm_SetThumbData(contentForm, thumbData, 5);
1097    result = (result == UDMF_E_OK) && OH_UdsContentForm_SetDescription(contentForm, "description");
1098    result = (result == UDMF_E_OK) && OH_UdsContentForm_SetTitle(contentForm, "title");
1099    result = (result == UDMF_E_OK) && OH_UdsContentForm_SetAppIcon(contentForm, appIcon, 5);
1100    result = (result == UDMF_E_OK) && OH_UdsContentForm_SetAppName(contentForm, "appName");
1101    result = (result == UDMF_E_OK) && OH_UdsContentForm_SetLinkUri(contentForm, "link url");
1102    EXPECT_EQ(UDMF_E_OK, result);
1103    EXPECT_EQ("description", std::string(OH_UdsContentForm_GetDescription(contentForm)));
1104    EXPECT_EQ("title", std::string(OH_UdsContentForm_GetTitle(contentForm)));
1105    EXPECT_EQ("appName", std::string(OH_UdsContentForm_GetAppName(contentForm)));
1106    EXPECT_EQ("link url", std::string(OH_UdsContentForm_GetLinkUri(contentForm)));
1107
1108    unsigned char *readThumbData;
1109    unsigned int thumbDataLen = 0;
1110    result = OH_UdsContentForm_GetThumbData(contentForm, &readThumbData, &thumbDataLen);
1111    ASSERT_EQ(5, thumbDataLen);
1112    ASSERT_TRUE(CheckUnsignedChar(thumbData, readThumbData, thumbDataLen));
1113
1114    unsigned char *readAppIcon;
1115    unsigned int appIconLen = 0;
1116    result = OH_UdsContentForm_GetAppIcon(contentForm, &readAppIcon, &appIconLen);
1117    ASSERT_EQ(5, thumbDataLen);
1118    ASSERT_TRUE(CheckUnsignedChar(thumbData, readThumbData, thumbDataLen));
1119
1120    OH_UdsContentForm_Destroy(contentForm);
1121    LOG_INFO(UDMF_TEST, "OH_UdsContentForm_SetAndGetParm_001 end.");
1122}
1123
1124}
1125