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 #include "napi/native_api.h"
16 #include "udmf.h"
17 #include "udmf_err_code.h"
18 #include <bits/alltypes.h>
19 #include <iostream>
20 #include <string>
21 #include "udmf_meta.h"
22 #include "uds.h"
23 #include "utd.h"
24 #include "napi/native_node_api.h"
25 #include "napi/native_api.h"
26
27 #define PARAM_0 0
28 #define PARAM_1 1
29
OH_Udmf_CreateUnifiedData001(napi_env env,napi_callback_info info)30 static napi_value OH_Udmf_CreateUnifiedData001(napi_env env, napi_callback_info info)
31 {
32 OH_UdmfData *unifiedData = OH_UdmfData_Create();
33 napi_value result;
34 napi_create_int32(env, unifiedData != nullptr, &result);
35 OH_UdmfData_Destroy(unifiedData);
36 return result;
37 }
OH_Udmf_AddRecordToUnifiedData001(napi_env env,napi_callback_info info)38 static napi_value OH_Udmf_AddRecordToUnifiedData001(napi_env env, napi_callback_info info)
39 {
40 OH_UdmfRecord *record = OH_UdmfRecord_Create();
41 OH_UdmfData *unifiedData = OH_UdmfData_Create();
42 int status = OH_UdmfData_AddRecord(unifiedData, record);
43 napi_value result;
44 napi_create_int32(env, status == UDMF_E_OK, &result);
45 OH_UdmfRecord_Destroy(record);
46 OH_UdmfData_Destroy(unifiedData);
47 return result;
48 }
49
OH_Udmf_HasUnifiedDataType001(napi_env env,napi_callback_info info)50 static napi_value OH_Udmf_HasUnifiedDataType001(napi_env env, napi_callback_info info)
51 {
52 OH_UdmfData *unifiedData = OH_UdmfData_Create();
53 OH_UdmfRecord *record = OH_UdmfRecord_Create();
54 OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
55 OH_UdmfRecord_AddPlainText(record, plainText);
56 OH_UdmfData_AddRecord(unifiedData, record);
57
58 char type1[] = "general.plain-text";
59 int hasType1 = OH_UdmfData_HasType(unifiedData, type1);
60
61 char type2[] = "general.html";
62 int hasType2 = OH_UdmfData_HasType(unifiedData, type2);
63
64 napi_value result;
65 napi_create_int32(env, (unifiedData !=nullptr) && (hasType1 == 1) && (hasType2 == 0), &result);
66 OH_UdsPlainText_Destroy(plainText);
67 OH_UdmfRecord_Destroy(record);
68 OH_UdmfData_Destroy(unifiedData);
69 return result;
70 }
OH_Udmf_GetUnifiedDataTypes001(napi_env env,napi_callback_info info)71 static napi_value OH_Udmf_GetUnifiedDataTypes001(napi_env env, napi_callback_info info)
72 {
73 OH_UdmfData *unifiedData = OH_UdmfData_Create();
74 OH_UdmfRecord *record = OH_UdmfRecord_Create();
75 OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
76 OH_UdmfRecord_AddPlainText(record, plainText);
77 OH_UdmfData_AddRecord(unifiedData, record);
78 OH_UdmfRecord *record1 = OH_UdmfRecord_Create();
79 OH_UdsHyperlink *hyperlink = OH_UdsHyperlink_Create();
80 OH_UdmfRecord_AddHyperlink(record1, hyperlink);
81 OH_UdmfData_AddRecord(unifiedData, record1);
82 int num = 2;
83 unsigned int count1 = 0;
84 char **types1 = OH_UdmfData_GetTypes(unifiedData, &count1);
85 NAPI_ASSERT(env, types1 != nullptr, "OH_UdmfData_GetTypes is fail.");
86 NAPI_ASSERT(env, count1 == num, "OH_UdmfData_GetTypes is fail.");
87
88 char **types2 = OH_UdmfData_GetTypes(unifiedData, &count1);
89 NAPI_ASSERT(env, types1 == types2, "OH_UdmfData_GetTypes is fail.");
90 napi_value result;
91 napi_create_int32(env, 1, &result);
92 OH_UdsPlainText_Destroy(plainText);
93 OH_UdsHyperlink_Destroy(hyperlink);
94 OH_UdmfRecord_Destroy(record);
95 OH_UdmfData_Destroy(unifiedData);
96 return result;
97 }
OH_Udmf_GetUnifiedRecordTypes001(napi_env env,napi_callback_info info)98 static napi_value OH_Udmf_GetUnifiedRecordTypes001(napi_env env, napi_callback_info info)
99 {
100 OH_UdmfRecord *record = OH_UdmfRecord_Create();
101 OH_UdsPlainText *plaintext = OH_UdsPlainText_Create();
102 OH_UdmfRecord_AddPlainText(record, plaintext);
103 unsigned int count = 0;
104 char **types1 = OH_UdmfRecord_GetTypes(record, &count);
105
106 unsigned int count1 = 0;
107 char **types2 = OH_UdmfRecord_GetTypes(record, &count1);
108
109 napi_value result;
110 napi_create_int32(env, (types1 != nullptr) && (count == 1) && (types1 == types2)
111 && (types2 != nullptr) && (count1 == 1), &result);
112 OH_UdmfRecord_Destroy(record);
113 OH_UdsPlainText_Destroy(plaintext);
114 return result;
115 }
OH_Udmf_GetRecords001(napi_env env,napi_callback_info info)116 static napi_value OH_Udmf_GetRecords001(napi_env env, napi_callback_info info)
117 {
118 OH_UdmfRecord *record = OH_UdmfRecord_Create();
119 OH_UdsPlainText *plaintext = OH_UdsPlainText_Create();
120 OH_UdmfRecord_AddPlainText(record, plaintext);
121 unsigned int count = 0;
122 char **types1 = OH_UdmfRecord_GetTypes(record, &count);
123
124 unsigned int count1 = 0;
125 char **types2 = OH_UdmfRecord_GetTypes(record, &count1);
126
127 napi_value result;
128 napi_create_int32(env, (types1 != nullptr) && (count == 1) && (types1 == types2)
129 && (types2 != nullptr) && (count1 == 1), &result);
130 OH_UdmfRecord_Destroy(record);
131 OH_UdsPlainText_Destroy(plaintext);
132 return result;
133 }
OH_Udmf_SetAndGetUnifiedData001(napi_env env,napi_callback_info info)134 static napi_value OH_Udmf_SetAndGetUnifiedData001(napi_env env, napi_callback_info info)
135 {
136 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
137 OH_UdmfRecord *record = OH_UdmfRecord_Create();
138 OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
139 char content[] = "hello world";
140 OH_UdsPlainText_SetContent(plainText, content);
141 OH_UdmfRecord_AddPlainText(record, plainText);
142 OH_UdmfData_AddRecord(udmfUnifiedData, record);
143 Udmf_Intention intention = UDMF_INTENTION_DRAG;
144 char key[UDMF_KEY_BUFFER_LEN];
145
146 int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
147 NAPI_ASSERT(env, setRes == UDMF_E_OK, "OH_Udmf_SetUnifiedData is fail.");
148 NAPI_ASSERT(env, key[0] != '\0', "OH_Udmf_SetUnifiedData is fail.");
149
150 OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
151 int getRes = OH_Udmf_GetUnifiedData(key, intention, readUnifiedData);
152 NAPI_ASSERT(env, getRes == UDMF_E_OK, "OH_Udmf_GetUnifiedData is fail.");
153
154 unsigned int count = 0;
155 OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(readUnifiedData, &count);
156 NAPI_ASSERT(env, count == 1, "OH_UdmfData_GetRecords is fail.");
157
158 OH_UdsPlainText *getPlainText = OH_UdsPlainText_Create();
159 OH_UdmfRecord_GetPlainText(getRecords[0], getPlainText);
160 const char *getContent = OH_UdsPlainText_GetContent(getPlainText);
161 NAPI_ASSERT(env, strcmp(getContent, content) == 0, "OH_UdmfData_GetRecords is fail.");
162
163 napi_value result;
164 napi_create_int32(env, 1, &result);
165 OH_UdsPlainText_Destroy(plainText);
166 OH_UdmfRecord_Destroy(record);
167 OH_UdmfData_Destroy(udmfUnifiedData);
168
169 OH_UdsPlainText_Destroy(getPlainText);
170 OH_UdmfData_Destroy(readUnifiedData);
171 return result;
172 }
OH_Udmf_SetAndGetUnifiedData002(napi_env env,napi_callback_info info)173 static napi_value OH_Udmf_SetAndGetUnifiedData002(napi_env env, napi_callback_info info)
174 {
175 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
176 OH_UdmfRecord *record = OH_UdmfRecord_Create();
177 OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
178 char content[] = "hello world";
179 OH_UdsPlainText_SetContent(plainText, content);
180 OH_UdmfRecord_AddPlainText(record, plainText);
181 OH_UdmfData_AddRecord(udmfUnifiedData, record);
182 Udmf_Intention intention = UDMF_INTENTION_DRAG;
183 char key[UDMF_KEY_BUFFER_LEN];
184
185 int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
186 NAPI_ASSERT(env, setRes == UDMF_E_OK, "OH_Udmf_SetUnifiedData is fail.");
187 NAPI_ASSERT(env, key[0] != '\0', "OH_Udmf_SetUnifiedData is fail.");
188
189 OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
190 int getRes = OH_Udmf_GetUnifiedData(key, intention, readUnifiedData);
191 NAPI_ASSERT(env, getRes == UDMF_E_OK, "OH_Udmf_GetUnifiedData is fail.");
192
193 unsigned int count = 0;
194 OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(readUnifiedData, &count);
195 NAPI_ASSERT(env, count == 1, "OH_UdmfData_GetRecords is fail.");
196
197 OH_UdsPlainText *getPlainText = OH_UdsPlainText_Create();
198 OH_UdmfRecord_GetPlainText(getRecords[0], getPlainText);
199 const char *getContent = OH_UdsPlainText_GetContent(getPlainText);
200 NAPI_ASSERT(env, strcmp(getContent, content) == 0, "OH_UdsPlainText_GetContent is fail.");
201
202 napi_value result;
203 napi_create_int32(env, 1, &result);
204
205 OH_UdsPlainText_Destroy(plainText);
206 OH_UdmfRecord_Destroy(record);
207 OH_UdmfData_Destroy(udmfUnifiedData);
208
209 OH_UdsPlainText_Destroy(getPlainText);
210 OH_UdmfData_Destroy(readUnifiedData);
211 return result;
212 }
OH_Udmf_GetRecords002(napi_env env,napi_callback_info info)213 static napi_value OH_Udmf_GetRecords002(napi_env env, napi_callback_info info)
214 {
215 OH_UdmfData *unifiedData = OH_UdmfData_Create();
216 OH_UdmfRecord *record = OH_UdmfRecord_Create();
217 OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
218 OH_UdmfRecord_AddPlainText(record, plainText);
219 OH_UdmfData_AddRecord(unifiedData, record);
220 OH_UdmfRecord *record1 = OH_UdmfRecord_Create();
221 OH_UdsHyperlink *hyperlink = OH_UdsHyperlink_Create();
222 OH_UdmfRecord_AddHyperlink(record1, hyperlink);
223 OH_UdmfData_AddRecord(unifiedData, record1);
224
225 unsigned int count = 0;
226 OH_UdmfRecord **records1 = OH_UdmfData_GetRecords(unifiedData, &count);
227
228 OH_UdmfRecord **records2 = OH_UdmfData_GetRecords(unifiedData, &count);
229 int num = 2;
230 napi_value result;
231 napi_create_int32(env, (count == num) &&(records1 != nullptr) && (count == num)
232 && (records2 != nullptr) && (records2 == records1), &result);
233
234 OH_UdsPlainText_Destroy(plainText);
235 OH_UdsHyperlink_Destroy(hyperlink);
236 OH_UdmfRecord_Destroy(record);
237 OH_UdmfRecord_Destroy(record1);
238 OH_UdmfData_Destroy(unifiedData);
239 return result;
240 }
OH_Udmf_AddAndGetGeneralEntry001(napi_env env,napi_callback_info info)241 static napi_value OH_Udmf_AddAndGetGeneralEntry001(napi_env env, napi_callback_info info)
242 {
243 char typeId[] = "general.plain-text";
244 unsigned char entry[] = "CreateGeneralRecord";
245 unsigned int count = sizeof(entry);
246 OH_UdmfRecord *record = OH_UdmfRecord_Create();
247 int addRes1 = OH_UdmfRecord_AddGeneralEntry(record, typeId, entry, count);
248
249 unsigned int getCount = 0;
250 unsigned char *getEntry;
251 int getRes = OH_UdmfRecord_GetGeneralEntry(record, typeId, &getEntry, &getCount);
252
253 unsigned int getCount1 = 0;
254 unsigned char *getEntry1;
255 int getRes1 = OH_UdmfRecord_GetGeneralEntry(record, typeId, &getEntry1, &getCount1);
256
257 napi_value result;
258 napi_create_int32(env, (addRes1 == UDMF_E_OK) &&(getRes == UDMF_E_OK) && (getCount == count)
259 && (std::memcmp(getEntry, entry, getCount) == 0) && (getEntry1 == getEntry)
260 && (getRes1 == UDMF_E_OK), &result);
261
262 OH_UdmfRecord_Destroy(record);
263
264 return result;
265 }
266
267 // 2. BuildAndGet NAPI_ASSERT =======================================================
OH_Udmf_BuildAndGetPlainTextFromRecord001(napi_env env,napi_callback_info info)268 static napi_value OH_Udmf_BuildAndGetPlainTextFromRecord001(napi_env env, napi_callback_info info)
269 {
270 int errCode = 0;
271 OH_UdmfRecord *record1 = OH_UdmfRecord_Create();
272 OH_UdsPlainText *plainText1 = OH_UdsPlainText_Create();
273 char content[] = "hello world";
274 OH_UdsPlainText_SetContent(plainText1, content);
275 int buildRes = OH_UdmfRecord_AddPlainText(record1, plainText1);
276 NAPI_ASSERT(env, buildRes == UDMF_E_OK, "OH_UdmfRecord_AddPlainText is fail.");
277
278 OH_UdsPlainText *plainText2 = OH_UdsPlainText_Create();
279 int getRes = OH_UdmfRecord_GetPlainText(record1, plainText2);
280 NAPI_ASSERT(env, getRes == UDMF_E_OK, "OH_UdmfRecord_GetPlainText is fail.");
281
282 const char *getContent = OH_UdsPlainText_GetContent(plainText2);
283 NAPI_ASSERT(env, strcmp(content, getContent) == 0, "OH_UdsPlainText_GetContent is fail.");
284
285 OH_UdmfRecord_Destroy(record1);
286 OH_UdsPlainText_Destroy(plainText1);
287 OH_UdsPlainText_Destroy(plainText2);
288
289 errCode = buildRes;
290 napi_value returnCode;
291 napi_create_double(env, errCode, &returnCode);
292 return returnCode;
293 }
294
OH_Udmf_BuildAndGetHyperlinkFromRecord001(napi_env env,napi_callback_info info)295 static napi_value OH_Udmf_BuildAndGetHyperlinkFromRecord001(napi_env env, napi_callback_info info)
296 {
297 int errCode = 0;
298 OH_UdmfRecord *record1 = OH_UdmfRecord_Create();
299 OH_UdsHyperlink *hyperlink1 = OH_UdsHyperlink_Create();
300 char url[] = "https://gitee.com/openharmony/distributeddatamgr_udmf/members";
301 OH_UdsHyperlink_SetUrl(hyperlink1, url);
302 int buildRes = OH_UdmfRecord_AddHyperlink(record1, hyperlink1);
303 NAPI_ASSERT(env, buildRes == UDMF_E_OK, "OH_UdmfRecord_AddHyperlink is fail.");
304
305 OH_UdsHyperlink *hyperlink2 = OH_UdsHyperlink_Create();
306 int getRes = OH_UdmfRecord_GetHyperlink(record1, hyperlink2);
307 NAPI_ASSERT(env, getRes == UDMF_E_OK, "OH_UdmfRecord_GetHyperlink is fail.");
308
309 const char *getUrl = OH_UdsHyperlink_GetUrl(hyperlink2);
310 NAPI_ASSERT(env, strcmp(url, getUrl) == 0, "OH_UdsHyperlink_GetUrl is fail.");
311
312 OH_UdmfRecord_Destroy(record1);
313 OH_UdsHyperlink_Destroy(hyperlink1);
314 OH_UdsHyperlink_Destroy(hyperlink2);
315
316 errCode = buildRes;
317 napi_value returnCode;
318 napi_create_double(env, errCode, &returnCode);
319 return returnCode;
320 }
321
322
OH_Udmf_BuildAndGetHtmlFromRecord001(napi_env env,napi_callback_info info)323 static napi_value OH_Udmf_BuildAndGetHtmlFromRecord001(napi_env env, napi_callback_info info)
324 {
325 int errCode = 0;
326 OH_UdmfRecord *record1 = OH_UdmfRecord_Create();
327 OH_UdsHtml *html1 = OH_UdsHtml_Create();
328 char content[] = "hello world";
329 OH_UdsHtml_SetContent(html1, content);
330 int buildRes = OH_UdmfRecord_AddHtml(record1, html1);
331 NAPI_ASSERT(env, buildRes == UDMF_E_OK, "OH_UdmfRecord_AddHtml is fail.");
332
333 OH_UdsHtml *html2 = OH_UdsHtml_Create();
334 int getRes = OH_UdmfRecord_GetHtml(record1, html2);
335 NAPI_ASSERT(env, getRes == UDMF_E_OK, "OH_UdmfRecord_GetHtml is fail.");
336
337 const char *getContent = OH_UdsHtml_GetContent(html2);
338 NAPI_ASSERT(env, strcmp(content, getContent) == 0, "OH_UdsHtml_GetContent is fail.");
339
340 OH_UdmfRecord_Destroy(record1);
341 OH_UdsHtml_Destroy(html1);
342 OH_UdsHtml_Destroy(html2);
343
344 errCode = buildRes;
345 napi_value returnCode;
346 napi_create_double(env, errCode, &returnCode);
347 return returnCode;
348 }
349
OH_Udmf_BuildAndGetAppItemFromRecord001(napi_env env,napi_callback_info info)350 static napi_value OH_Udmf_BuildAndGetAppItemFromRecord001(napi_env env, napi_callback_info info)
351 {
352 int errCode = 0;
353 OH_UdmfRecord *record1 = OH_UdmfRecord_Create();
354 OH_UdsAppItem *appItem1 = OH_UdsAppItem_Create();
355 char name[] = "appItem";
356 OH_UdsAppItem_SetName(appItem1, name);
357 int buildRes = OH_UdmfRecord_AddAppItem(record1, appItem1);
358 NAPI_ASSERT(env, buildRes == UDMF_E_OK, "OH_UdmfRecord_AddAppItem is fail.");
359
360 OH_UdsAppItem *appItem2 = OH_UdsAppItem_Create();
361 int getRes = OH_UdmfRecord_GetAppItem(record1, appItem2);
362 NAPI_ASSERT(env, getRes == UDMF_E_OK, "OH_UdmfRecord_GetAppItem is fail.");
363
364 const char *getName = OH_UdsAppItem_GetName(appItem2);
365 NAPI_ASSERT(env, strcmp(name, getName) == 0, "OH_UdsAppItem_GetName is fail.");
366
367 OH_UdmfRecord_Destroy(record1);
368 OH_UdsAppItem_Destroy(appItem1);
369 OH_UdsAppItem_Destroy(appItem2);
370
371 errCode = buildRes;
372 napi_value returnCode;
373 napi_create_double(env, errCode, &returnCode);
374 return returnCode;
375 }
376
377 // 3. OH_UdmfProperty napi_create_int32 =======================================================
OH_Udmf_CreatePropertiesFromUnifiedData001(napi_env env,napi_callback_info info)378 static napi_value OH_Udmf_CreatePropertiesFromUnifiedData001(napi_env env, napi_callback_info info)
379 {
380 OH_UdmfData *data = OH_UdmfData_Create();
381 OH_UdmfProperty *properties = OH_UdmfProperty_Create(data);
382
383 napi_value result = nullptr;
384 napi_create_int32(env, properties != nullptr, &result);
385
386 OH_UdmfData_Destroy(data);
387 OH_UdmfProperty_Destroy(properties);
388 return result;
389 }
390
OH_Udmf_SetPropertiesTag001(napi_env env,napi_callback_info info)391 static napi_value OH_Udmf_SetPropertiesTag001(napi_env env, napi_callback_info info)
392 {
393 OH_UdmfData *data = OH_UdmfData_Create();
394 OH_UdmfProperty *properties = OH_UdmfProperty_Create(data);
395 int ret = OH_UdmfProperty_SetTag(properties, "tag");
396
397 napi_value result = nullptr;
398 napi_create_int32(env, ret == UDMF_E_OK, &result);
399 OH_UdmfData_Destroy(data);
400 OH_UdmfProperty_Destroy(properties);
401 return result;
402 }
403
OH_Udmf_GetPropertiesTag001(napi_env env,napi_callback_info info)404 static napi_value OH_Udmf_GetPropertiesTag001(napi_env env, napi_callback_info info)
405 {
406 OH_UdmfData *data = OH_UdmfData_Create();
407 OH_UdmfProperty *properties = OH_UdmfProperty_Create(data);
408 OH_UdmfProperty_SetTag(properties, "tag");
409 const char* pf = OH_UdmfProperty_GetTag(properties);
410
411 int64_t resTime = OH_UdmfProperty_GetTimestamp (properties);
412
413 napi_value result = nullptr;
414 napi_create_int32(env, (strcmp(pf, "tag") == PARAM_0) && (resTime !=0), &result);
415 OH_UdmfData_Destroy(data);
416 OH_UdmfProperty_Destroy(properties);
417 return result;
418 }
419
OH_Udmf_SetPropertiesShareOption001(napi_env env,napi_callback_info info)420 static napi_value OH_Udmf_SetPropertiesShareOption001(napi_env env, napi_callback_info info)
421 {
422 OH_UdmfData *data = OH_UdmfData_Create();
423 OH_UdmfProperty *properties = OH_UdmfProperty_Create(data);
424 int ret = OH_UdmfProperty_SetShareOption(properties, Udmf_ShareOption::SHARE_OPTIONS_IN_APP);
425
426 napi_value result = nullptr;
427 napi_create_int32(env, ret == UDMF_E_OK, &result);
428 OH_UdmfData_Destroy(data);
429 OH_UdmfProperty_Destroy(properties);
430 return result;
431 }
432
OH_Udmf_GetPropertiesShareOption001(napi_env env,napi_callback_info info)433 static napi_value OH_Udmf_GetPropertiesShareOption001(napi_env env, napi_callback_info info)
434 {
435 OH_UdmfData *data = OH_UdmfData_Create();
436 OH_UdmfProperty *properties = OH_UdmfProperty_Create(data);
437 OH_UdmfProperty_SetShareOption(properties, Udmf_ShareOption::SHARE_OPTIONS_IN_APP);
438 int ret = OH_UdmfProperty_GetShareOption(properties);
439
440 napi_value result = nullptr;
441 napi_create_int32(env, ret == Udmf_ShareOption::SHARE_OPTIONS_IN_APP, &result);
442 OH_UdmfData_Destroy(data);
443 OH_UdmfProperty_Destroy(properties);
444 return result;
445 }
446
OH_Udmf_SetPropertiesShareOption002(napi_env env,napi_callback_info info)447 static napi_value OH_Udmf_SetPropertiesShareOption002(napi_env env, napi_callback_info info)
448 {
449 OH_UdmfData *data = OH_UdmfData_Create();
450 OH_UdmfProperty *properties = OH_UdmfProperty_Create(data);
451 int ret = OH_UdmfProperty_SetShareOption(properties, Udmf_ShareOption::SHARE_OPTIONS_CROSS_APP);
452
453 napi_value result = nullptr;
454 napi_create_int32(env, ret == UDMF_E_OK, &result);
455 OH_UdmfData_Destroy(data);
456 OH_UdmfProperty_Destroy(properties);
457 return result;
458 }
459
OH_Udmf_GetPropertiesShareOption002(napi_env env,napi_callback_info info)460 static napi_value OH_Udmf_GetPropertiesShareOption002(napi_env env, napi_callback_info info)
461 {
462 OH_UdmfData *data = OH_UdmfData_Create();
463 OH_UdmfProperty *properties = OH_UdmfProperty_Create(data);
464 OH_UdmfProperty_SetShareOption(properties, Udmf_ShareOption::SHARE_OPTIONS_CROSS_APP);
465 int ret = OH_UdmfProperty_GetShareOption(properties);
466
467 napi_value result = nullptr;
468 napi_create_int32(env, ret == Udmf_ShareOption::SHARE_OPTIONS_CROSS_APP, &result);
469 OH_UdmfData_Destroy(data);
470 OH_UdmfProperty_Destroy(properties);
471 return result;
472 }
473
OH_Udmf_SetPropertiesShareOption003(napi_env env,napi_callback_info info)474 static napi_value OH_Udmf_SetPropertiesShareOption003(napi_env env, napi_callback_info info)
475 {
476 OH_UdmfData *data = OH_UdmfData_Create();
477 OH_UdmfProperty *properties = OH_UdmfProperty_Create(data);
478 int ret = OH_UdmfProperty_SetShareOption(properties, Udmf_ShareOption::SHARE_OPTIONS_INVALID);
479
480 napi_value result = nullptr;
481 napi_create_int32(env, ret == UDMF_E_INVALID_PARAM, &result);
482 OH_UdmfData_Destroy(data);
483 OH_UdmfProperty_Destroy(properties);
484 return result;
485 }
486
OH_Udmf_SetPropertiesExtrasIntParam001(napi_env env,napi_callback_info info)487 static napi_value OH_Udmf_SetPropertiesExtrasIntParam001(napi_env env, napi_callback_info info)
488 {
489 OH_UdmfData *data = OH_UdmfData_Create();
490 OH_UdmfProperty *properties = OH_UdmfProperty_Create(data);
491 int ret = OH_UdmfProperty_SetExtrasIntParam(properties, "keyInt", 0);
492
493 napi_value result = nullptr;
494 napi_create_int32(env, ret == UDMF_E_OK, &result);
495 OH_UdmfData_Destroy(data);
496 OH_UdmfProperty_Destroy(properties);
497 return result;
498 }
499
OH_Udmf_GetPropertiesExtrasIntParam001(napi_env env,napi_callback_info info)500 static napi_value OH_Udmf_GetPropertiesExtrasIntParam001(napi_env env, napi_callback_info info)
501 {
502 OH_UdmfData *data = OH_UdmfData_Create();
503 OH_UdmfProperty *properties = OH_UdmfProperty_Create(data);
504 OH_UdmfProperty_SetExtrasIntParam(properties, "keyInt", 0);
505 int ret = OH_UdmfProperty_GetExtrasIntParam(properties, "keyInt", -1);
506
507 napi_value result = nullptr;
508 napi_create_int32(env, ret == 0, &result);
509 OH_UdmfData_Destroy(data);
510 OH_UdmfProperty_Destroy(properties);
511 return result;
512 }
513
OH_Udmf_SetPropertiesExtrasStringParam001(napi_env env,napi_callback_info info)514 static napi_value OH_Udmf_SetPropertiesExtrasStringParam001(napi_env env, napi_callback_info info)
515 {
516 OH_UdmfData *data = OH_UdmfData_Create();
517 OH_UdmfProperty *properties = OH_UdmfProperty_Create(data);
518 int ret = OH_UdmfProperty_SetExtrasStringParam(properties, "keyStr", "str");
519
520 napi_value result = nullptr;
521 napi_create_int32(env, ret == UDMF_E_OK, &result);
522 OH_UdmfData_Destroy(data);
523 OH_UdmfProperty_Destroy(properties);
524 return result;
525 }
526
OH_Udmf_GetPropertiesExtrasStringParam001(napi_env env,napi_callback_info info)527 static napi_value OH_Udmf_GetPropertiesExtrasStringParam001(napi_env env, napi_callback_info info)
528 {
529 OH_UdmfData *data = OH_UdmfData_Create();
530 OH_UdmfProperty *properties = OH_UdmfProperty_Create(data);
531 OH_UdmfProperty_SetExtrasStringParam(properties, "keyStr", "str");
532 const char* pf = OH_UdmfProperty_GetExtrasStringParam(properties, "keyStr");
533
534 napi_value result = nullptr;
535 napi_create_int32(env, strcmp(pf, "str") == PARAM_0, &result);
536 OH_UdmfData_Destroy(data);
537 OH_UdmfProperty_Destroy(properties);
538 return result;
539 }
540
Init(napi_env env,napi_value exports)541 EXTERN_C_START static napi_value Init(napi_env env, napi_value exports)
542 {
543 napi_property_descriptor desc[] = {
544 {"OH_Udmf_CreatePropertiesFromUnifiedData001", nullptr, OH_Udmf_CreatePropertiesFromUnifiedData001, nullptr, nullptr, nullptr, napi_default, nullptr},
545 {"OH_Udmf_SetPropertiesTag001", nullptr, OH_Udmf_SetPropertiesTag001, nullptr, nullptr, nullptr,
546 napi_default, nullptr},
547 {"OH_Udmf_AddRecordToUnifiedData001", nullptr, OH_Udmf_AddRecordToUnifiedData001, nullptr,
548 nullptr, nullptr, napi_default, nullptr},
549 {"OH_Udmf_CreateUnifiedData001", nullptr, OH_Udmf_CreateUnifiedData001, nullptr, nullptr, nullptr,
550 napi_default, nullptr},
551 {"OH_Udmf_HasUnifiedDataType001", nullptr, OH_Udmf_HasUnifiedDataType001, nullptr, nullptr,
552 nullptr, napi_default, nullptr},
553 {"OH_Udmf_GetUnifiedDataTypes001", nullptr, OH_Udmf_GetUnifiedDataTypes001, nullptr, nullptr,
554 nullptr, napi_default, nullptr},
555 {"OH_Udmf_GetUnifiedRecordTypes001", nullptr, OH_Udmf_GetUnifiedRecordTypes001, nullptr, nullptr,
556 nullptr, napi_default, nullptr},
557 {"OH_Udmf_GetRecords001", nullptr, OH_Udmf_GetRecords001, nullptr, nullptr, nullptr, napi_default,
558 nullptr},
559 {"OH_Udmf_SetAndGetUnifiedData001", nullptr, OH_Udmf_SetAndGetUnifiedData001, nullptr, nullptr,
560 nullptr, napi_default, nullptr},
561 {"OH_Udmf_GetRecords002", nullptr, OH_Udmf_GetRecords002, nullptr, nullptr, nullptr, napi_default, nullptr},
562 {"OH_Udmf_AddAndGetGeneralEntry001", nullptr, OH_Udmf_AddAndGetGeneralEntry001, nullptr, nullptr,
563 nullptr, napi_default, nullptr},
564 {"OH_Udmf_SetAndGetUnifiedData002", nullptr, OH_Udmf_SetAndGetUnifiedData002, nullptr, nullptr,
565 nullptr, napi_default, nullptr},
566 {"OH_Udmf_BuildAndGetPlainTextFromRecord001", nullptr, OH_Udmf_BuildAndGetPlainTextFromRecord001, nullptr,
567 nullptr, nullptr, napi_default, nullptr},
568 {"OH_Udmf_BuildAndGetHyperlinkFromRecord001", nullptr, OH_Udmf_BuildAndGetHyperlinkFromRecord001, nullptr,
569 nullptr, nullptr, napi_default, nullptr},
570 {"OH_Udmf_BuildAndGetHtmlFromRecord001", nullptr, OH_Udmf_BuildAndGetHtmlFromRecord001, nullptr, nullptr,
571 nullptr, napi_default, nullptr},
572 {"OH_Udmf_BuildAndGetAppItemFromRecord001", nullptr, OH_Udmf_BuildAndGetAppItemFromRecord001, nullptr,
573 nullptr, nullptr, napi_default, nullptr},
574 {"OH_Udmf_GetPropertiesTag001", nullptr, OH_Udmf_GetPropertiesTag001, nullptr, nullptr, nullptr,
575 napi_default, nullptr},
576 {"OH_Udmf_SetPropertiesShareOption001", nullptr, OH_Udmf_SetPropertiesShareOption001, nullptr, nullptr, nullptr,
577 napi_default, nullptr},
578 {"OH_Udmf_GetPropertiesShareOption001", nullptr, OH_Udmf_GetPropertiesShareOption001, nullptr, nullptr, nullptr,
579 napi_default, nullptr},
580 {"OH_Udmf_SetPropertiesShareOption002", nullptr, OH_Udmf_SetPropertiesShareOption002, nullptr, nullptr, nullptr,
581 napi_default, nullptr},
582 {"OH_Udmf_GetPropertiesShareOption002", nullptr, OH_Udmf_GetPropertiesShareOption002, nullptr, nullptr, nullptr,
583 napi_default, nullptr},
584 {"OH_Udmf_SetPropertiesShareOption003", nullptr, OH_Udmf_SetPropertiesShareOption003, nullptr, nullptr, nullptr,
585 napi_default, nullptr},
586 {"OH_Udmf_SetPropertiesExtrasIntParam001", nullptr, OH_Udmf_SetPropertiesExtrasIntParam001, nullptr, nullptr,
587 nullptr, napi_default, nullptr},
588 {"OH_Udmf_GetPropertiesExtrasIntParam001", nullptr, OH_Udmf_GetPropertiesExtrasIntParam001, nullptr, nullptr,
589 nullptr, napi_default, nullptr},
590 {"OH_Udmf_SetPropertiesExtrasStringParam001", nullptr, OH_Udmf_SetPropertiesExtrasStringParam001, nullptr,
591 nullptr, nullptr, napi_default, nullptr},
592 {"OH_Udmf_GetPropertiesExtrasStringParam001", nullptr, OH_Udmf_GetPropertiesExtrasStringParam001, nullptr,
593 nullptr, nullptr, napi_default, nullptr},
594 };
595 napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
596 return exports;
597 }
598 EXTERN_C_END
599
600 static napi_module demoModule = {
601 .nm_version = 1,
602 .nm_flags = 0,
603 .nm_filename = nullptr,
604 .nm_register_func = Init,
605 .nm_modname = "UdmfNdk",
606 .nm_priv = ((void *)0),
607 .reserved = {0},
608 };
609
RegisterEntryModule(void)610 extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); }
611