• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
17import UDC from '@ohos.data.unifiedDataChannel';
18import UTD from '@ohos.data.uniformTypeDescriptor';
19import image from '@ohos.multimedia.image';
20
21const TEST_BUNDLE_NAME = 'MyBundleName';
22const KEY_TEST_ELEMENT = 'TestKey';
23const VALUE_TEST_ELEMENT = 'TestValue';
24const TEST_ID = 123456;
25const TEST_ABILITY_NAME = 'MyAbilityName';
26const TEST_MODULE = 'MyModule';
27const NUM_2M = 2 * 1024 * 1024;
28const NUM_4M = 4 * 1024 * 1024;
29const LONG_TEST2M = 'a'.repeat(NUM_2M);
30const LONG_TESTOVER2M = 'a'.repeat((NUM_2M + 1));
31
32let U8_ARRAY = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
33
34describe('UdmfJSTest', function () {
35
36  const optionsValid = { intention: 'DataHub', };
37
38  /**
39   * @tc.name UdmfTextTest
40   * @tc.desc Test Js Api Text testcase
41   * @tc.type: FUNC
42   * @tc.require: issueNumber
43   */
44  it('UdmfTextTest', 0, function () {
45    console.info('UdmfTextTest start');
46    let text = new UDC.Text();
47    text.details = {
48      Key: 'text' + KEY_TEST_ELEMENT,
49      Value: 'text' + VALUE_TEST_ELEMENT,
50    };
51    let unifiedData = new UDC.UnifiedData(text);
52    let records = unifiedData.getRecords();
53    expect(records.length).assertEqual(1);
54    expect(records[0].details.Key).assertEqual('text' + KEY_TEST_ELEMENT);
55    expect(records[0].details.Value).assertEqual('text' + VALUE_TEST_ELEMENT);
56    console.info('UdmfTextTest end');
57  });
58
59  /**
60   * @tc.name UdmfPlainTextTest
61   * @tc.desc Test Js Api PlainText testcase
62   * @tc.type: FUNC
63   * @tc.require: issueNumber
64   */
65  it('UdmfPlainTextTest', 0, function () {
66    console.info('UdmfPlainTextTest start');
67    let plainText = new UDC.PlainText();
68    plainText.details = {
69      Key: 'text' + KEY_TEST_ELEMENT,
70      Value: 'text' + VALUE_TEST_ELEMENT,
71    };
72    plainText.textContent = 'textContent';
73    plainText.abstract = 'abstract';
74    let unifiedData = new UDC.UnifiedData(plainText);
75    let records = unifiedData.getRecords();
76    expect(records.length).assertEqual(1);
77    expect(records[0].details.Key).assertEqual('text' + KEY_TEST_ELEMENT);
78    expect(records[0].details.Value).assertEqual('text' + VALUE_TEST_ELEMENT);
79    expect(records[0].textContent).assertEqual('textContent');
80    expect(records[0].abstract).assertEqual('abstract');
81    console.info('UdmfPlainTextTest end');
82  });
83
84  /**
85   * @tc.name UdmfHyperlinkTest
86   * @tc.desc Test Js Api Hyperlink testcase
87   * @tc.type: FUNC
88   * @tc.require: issueNumber
89   */
90  it('UdmfHyperlinkTest', 0, function () {
91    console.info('UdmfHyperlinkTest start');
92    let link = new UDC.Hyperlink();
93    link.details = {
94      Key: 'link' + KEY_TEST_ELEMENT,
95      Value: 'link' + VALUE_TEST_ELEMENT,
96    };
97    link.url = 'url';
98    link.description = 'description';
99    let unifiedData = new UDC.UnifiedData(link);
100    let records = unifiedData.getRecords();
101    expect(records.length).assertEqual(1);
102    expect(records[0].details.Key).assertEqual('link' + KEY_TEST_ELEMENT);
103    expect(records[0].details.Value).assertEqual('link' + VALUE_TEST_ELEMENT);
104    expect(records[0].url).assertEqual('url');
105    expect(records[0].description).assertEqual('description');
106    console.info('UdmfHyperlinkTest end');
107  });
108
109  /**
110   * @tc.name UdmfHtmlTest
111   * @tc.desc Test Js Api HTML testcase
112   * @tc.type: FUNC
113   * @tc.require: issueNumber
114   */
115  it('UdmfHtmlTest', 0, function () {
116    console.info('UdmfHtmlTest start');
117    let html = new UDC.HTML();
118    html.details = {
119      Key: 'html' + KEY_TEST_ELEMENT,
120      Value: 'html' + VALUE_TEST_ELEMENT,
121    };
122    html.htmlContent = 'htmlContent';
123    html.plainContent = 'plainContent';
124    let unifiedData = new UDC.UnifiedData(html);
125    let records = unifiedData.getRecords();
126    expect(records.length).assertEqual(1);
127    expect(records[0].details.Key).assertEqual('html' + KEY_TEST_ELEMENT);
128    expect(records[0].details.Value).assertEqual('html' + VALUE_TEST_ELEMENT);
129    expect(records[0].htmlContent).assertEqual('htmlContent');
130    expect(records[0].plainContent).assertEqual('plainContent');
131    console.info('UdmfHtmlTest end');
132  });
133
134  /**
135   * @tc.name UdmfFileTest
136   * @tc.desc Test Js Api File testcase
137   * @tc.type: FUNC
138   * @tc.require: issueNumber
139   */
140  it('UdmfFileTest', 0, function () {
141    console.info('UdmfFileTest start');
142    let file = new UDC.File();
143    file.details = {
144      Key: 'file' + KEY_TEST_ELEMENT,
145      Value: 'file' + VALUE_TEST_ELEMENT,
146    };
147    file.uri = 'uri';
148    let unifiedData = new UDC.UnifiedData(file);
149    let records = unifiedData.getRecords();
150    expect(records.length).assertEqual(1);
151    expect(records[0].details.Key).assertEqual('file' + KEY_TEST_ELEMENT);
152    expect(records[0].details.Value).assertEqual('file' + VALUE_TEST_ELEMENT);
153    expect(records[0].uri).assertEqual('uri');
154    console.info('UdmfFileTest end');
155  });
156
157  /**
158   * @tc.name UdmfFolderTest
159   * @tc.desc Test Js Api Folder testcase
160   * @tc.type: FUNC
161   * @tc.require: issueNumber
162   */
163  it('UdmfFolderTest', 0, function () {
164    console.info('UdmfFolderTest start');
165    let folder = new UDC.Folder();
166    folder.details = {
167      Key: 'folder' + KEY_TEST_ELEMENT,
168      Value: 'folder' + VALUE_TEST_ELEMENT,
169    };
170    folder.uri = 'folderUri';
171    let unifiedData = new UDC.UnifiedData(folder);
172    let records = unifiedData.getRecords();
173    expect(records.length).assertEqual(1);
174    expect(records[0].details.Key).assertEqual('folder' + KEY_TEST_ELEMENT);
175    expect(records[0].details.Value).assertEqual('folder' + VALUE_TEST_ELEMENT);
176    expect(records[0].uri).assertEqual('folderUri');
177    console.info('UdmfFolderTest end');
178  });
179
180  /**
181   * @tc.name UdmfImageTest
182   * @tc.desc Test Js Api Image testcase
183   * @tc.type: FUNC
184   * @tc.require: issueNumber
185   */
186  it('UdmfImageTest', 0, function () {
187    console.info('UdmfImageTest start');
188    let image = new UDC.Image();
189    image.details = {
190      Key: 'image' + KEY_TEST_ELEMENT,
191      Value: 'image' + VALUE_TEST_ELEMENT,
192    };
193    image.imageUri = 'imageUri';
194    let unifiedData = new UDC.UnifiedData(image);
195    let records = unifiedData.getRecords();
196    expect(records.length).assertEqual(1);
197    expect(records[0].details.Key).assertEqual('image' + KEY_TEST_ELEMENT);
198    expect(records[0].details.Value).assertEqual('image' + VALUE_TEST_ELEMENT);
199    expect(records[0].imageUri).assertEqual('imageUri');
200    console.info('UdmfImageTest end');
201  });
202
203  /**
204   * @tc.name UdmfVideoTest
205   * @tc.desc Test Js Api Video testcase
206   * @tc.type: FUNC
207   * @tc.require: issueNumber
208   */
209  it('UdmfVideoTest', 0, function () {
210    console.info('UdmfVideoTest start');
211    let video = new UDC.Video();
212    video.details = {
213      Key: 'video' + KEY_TEST_ELEMENT,
214      Value: 'video' + VALUE_TEST_ELEMENT,
215    };
216    video.videoUri = 'videoUri';
217    let unifiedData = new UDC.UnifiedData(video);
218    let records = unifiedData.getRecords();
219    expect(records.length).assertEqual(1);
220    expect(records[0].details.Key).assertEqual('video' + KEY_TEST_ELEMENT);
221    expect(records[0].details.Value).assertEqual('video' + VALUE_TEST_ELEMENT);
222    expect(records[0].videoUri).assertEqual('videoUri');
223    console.info('UdmfVideoTest end');
224  });
225
226  /**
227   * @tc.name UdmfSystemDefinedRecordTest
228   * @tc.desc Test Js Api SystemDefinedRecord testcase
229   * @tc.type: FUNC
230   * @tc.require: issueNumber
231   */
232  it('UdmfSystemDefinedRecordTest', 0, function () {
233    console.info('UdmfSystemDefinedRecordTest start');
234    let systemDefinedRecord = new UDC.SystemDefinedRecord();
235    systemDefinedRecord.details = {
236      recordKey1: 'systemDefinedRecord' + KEY_TEST_ELEMENT,
237      recordKey2: 1,
238      recordKey3: U8_ARRAY,
239    };
240    let unifiedData = new UDC.UnifiedData(systemDefinedRecord);
241    let records = unifiedData.getRecords();
242    expect(records.length).assertEqual(1);
243    expect(records[0].details.recordKey1).assertEqual('systemDefinedRecord' + KEY_TEST_ELEMENT);
244    expect(records[0].details.recordKey2).assertEqual(1);
245    for (let i = 0; i < U8_ARRAY.length; i++) {
246      expect(records[0].details.recordKey3[i]).assertEqual(U8_ARRAY[i]);
247    }
248    console.info('UdmfSystemDefinedRecordTest end');
249  });
250
251  /**
252   * @tc.name UdmfSystemDefinedPixelMapTest
253   * @tc.desc Test Js Api SystemDefinedPixelMap testcase
254   * @tc.type: FUNC
255   * @tc.require: issueNumber
256   */
257  it('UdmfSystemDefinedPixelMapTest', 0, function () {
258    console.info('UdmfSystemDefinedPixelMapTest start');
259    let systemDefinedPixelMap = new UDC.SystemDefinedPixelMap();
260    systemDefinedPixelMap.details = {
261      recordKey1: 'systemDefinedPixelMap' + KEY_TEST_ELEMENT,
262      recordKey2: 1,
263      recordKey3: U8_ARRAY,
264    };
265    systemDefinedPixelMap.rawData = U8_ARRAY;
266    let unifiedData = new UDC.UnifiedData(systemDefinedPixelMap);
267    let records = unifiedData.getRecords();
268    expect(records.length).assertEqual(1);
269    expect(records[0].details.recordKey1).assertEqual('systemDefinedPixelMap' + KEY_TEST_ELEMENT);
270    expect(records[0].details.recordKey2).assertEqual(1);
271    for (let i = 0; i < U8_ARRAY.length; i++) {
272      expect(records[0].details.recordKey3[i]).assertEqual(U8_ARRAY[i]);
273    }
274    for (let i = 0; i < U8_ARRAY.length; i++) {
275      expect(records[0].rawData[i]).assertEqual(U8_ARRAY[i]);
276    }
277    console.info('UdmfSystemDefinedPixelMapTest end');
278  });
279
280  /**
281   * @tc.name UdmfSystemDefinedFormTest
282   * @tc.desc Test Js Api SystemDefinedForm testcase
283   * @tc.type: FUNC
284   * @tc.require: issueNumber
285   */
286  it('UdmfSystemDefinedFormTest', 0, function () {
287    console.info('UdmfSystemDefinedFormTest start');
288    let form = new UDC.SystemDefinedForm();
289    form.formId = TEST_ID;
290    form.formName = 'MyFormName';
291    form.bundleName = TEST_BUNDLE_NAME;
292    form.abilityName = TEST_ABILITY_NAME;
293    form.module = TEST_MODULE;
294    form.details = {
295      formKey1: 1,
296      formKey2: 'form' + VALUE_TEST_ELEMENT,
297      formKey3: U8_ARRAY,
298    };
299    let unifiedData = new UDC.UnifiedData(form);
300    let records = unifiedData.getRecords();
301    expect(records.length).assertEqual(1);
302    expect(records[0].details.formKey1).assertEqual(1);
303    expect(records[0].details.formKey2).assertEqual('form' + VALUE_TEST_ELEMENT);
304    for (let i = 0; i < U8_ARRAY.length; i++) {
305      expect(records[0].details.formKey3[i]).assertEqual(U8_ARRAY[i]);
306    }
307    expect(records[0].formId).assertEqual(TEST_ID);
308    expect(records[0].formName).assertEqual('MyFormName');
309    expect(records[0].bundleName).assertEqual(TEST_BUNDLE_NAME);
310    expect(records[0].abilityName).assertEqual(TEST_ABILITY_NAME);
311    expect(records[0].module).assertEqual(TEST_MODULE);
312    console.info('UdmfSystemDefinedFormTest end');
313  });
314
315  /**
316   * @tc.name UdmfSystemDefinedAppItemTest
317   * @tc.desc Test Js Api SystemDefinedAppItem testcase
318   * @tc.type: FUNC
319   * @tc.require: issueNumber
320   */
321  it('UdmfSystemDefinedAppItemTest', 0, function () {
322    console.info('UdmfSystemDefinedAppItemTest start');
323    let appItem = new UDC.SystemDefinedAppItem();
324    appItem.appId = 'MyAppId';
325    appItem.appName = 'MyAppName';
326    appItem.abilityName = TEST_ABILITY_NAME;
327    appItem.bundleName = TEST_BUNDLE_NAME;
328    appItem.appIconId = 'MyAppIconId';
329    appItem.appLabelId = 'MyAppLabelId';
330    appItem.details = {
331      appItemKey1: 1,
332      appItemKey2: 'appItem' + VALUE_TEST_ELEMENT,
333      appItemKey3: U8_ARRAY,
334    };
335    let unifiedData = new UDC.UnifiedData(appItem);
336    let records = unifiedData.getRecords();
337    expect(records.length).assertEqual(1);
338    expect(records[0].details.appItemKey1).assertEqual(1);
339    expect(records[0].details.appItemKey2).assertEqual('appItem' + VALUE_TEST_ELEMENT);
340    for (let i = 0; i < U8_ARRAY.length; i++) {
341      expect(records[0].details.appItemKey3[i]).assertEqual(U8_ARRAY[i]);
342    }
343    expect(records[0].appId).assertEqual('MyAppId');
344    expect(records[0].appName).assertEqual('MyAppName');
345    expect(records[0].abilityName).assertEqual(TEST_ABILITY_NAME);
346    expect(records[0].bundleName).assertEqual(TEST_BUNDLE_NAME);
347    expect(records[0].appIconId).assertEqual('MyAppIconId');
348    expect(records[0].appLabelId).assertEqual('MyAppLabelId');
349    console.info('UdmfSystemDefinedAppItemTest end');
350  });
351
352  /**
353   * @tc.name UdmfSystemDefinedFormTest
354   * @tc.desc Test Js Api ApplicationDefinedRecord testcase
355   * @tc.type: FUNC
356   * @tc.require: issueNumber
357   */
358  it('UdmfApplicationDefinedRecord', 0, function () {
359    console.info('UdmfApplicationDefinedRecord start');
360    let applicationDefinedRecord = new UDC.ApplicationDefinedRecord();
361    applicationDefinedRecord.applicationDefinedType = 'applicationDefinedType';
362    applicationDefinedRecord.rawData = U8_ARRAY;
363    let unifiedData = new UDC.UnifiedData(applicationDefinedRecord);
364    let records = unifiedData.getRecords();
365    expect(records.length).assertEqual(1);
366    expect(records[0].applicationDefinedType).assertEqual('applicationDefinedType');
367    for (let i = 0; i < U8_ARRAY.length; i++) {
368      expect(records[0].rawData[i]).assertEqual(U8_ARRAY[i]);
369    }
370    console.info('UdmfApplicationDefinedRecord end');
371  });
372
373  /**
374   * @tc.name UdmfAllRecordsTest
375   * @tc.desc Test Js AllRecords testcase
376   * @tc.type: FUNC
377   * @tc.require: issueNumber
378   */
379  it('UdmfAllRecordsTest', 0, function () {
380    console.info('UdmfAllRecordsTest start');
381    let text = new UDC.Text();
382    let unifiedDatas = new UDC.UnifiedData(text);
383    let plainText = new UDC.PlainText();
384    unifiedDatas.addRecord(plainText);
385    let link = new UDC.Hyperlink();
386    unifiedDatas.addRecord(link);
387    let html = new UDC.HTML();
388    unifiedDatas.addRecord(html);
389    let file = new UDC.File();
390    unifiedDatas.addRecord(file);
391    let folder = new UDC.Folder();
392    unifiedDatas.addRecord(folder);
393    let image = new UDC.Image();
394    unifiedDatas.addRecord(image);
395    let video = new UDC.Video();
396    unifiedDatas.addRecord(video);
397    let systemDefinedRecord = new UDC.SystemDefinedRecord();
398    unifiedDatas.addRecord(systemDefinedRecord);
399    let systemDefinedPixelMap = new UDC.SystemDefinedPixelMap();
400    unifiedDatas.addRecord(systemDefinedPixelMap);
401    let form = new UDC.SystemDefinedForm();
402    unifiedDatas.addRecord(form);
403    let appItem = new UDC.SystemDefinedAppItem();
404    unifiedDatas.addRecord(appItem);
405    let applicationDefinedRecord = new UDC.ApplicationDefinedRecord();
406    unifiedDatas.addRecord(applicationDefinedRecord);
407    let records = unifiedDatas.getRecords();
408    expect(records.length).assertEqual(13);
409    expect(records[0].getType()).assertEqual(UTD.UniformDataType.TEXT);
410    expect(records[1].getType()).assertEqual(UTD.UniformDataType.PLAIN_TEXT);
411    expect(records[2].getType()).assertEqual(UTD.UniformDataType.HYPERLINK);
412    expect(records[3].getType()).assertEqual(UTD.UniformDataType.HTML);
413    expect(records[4].getType()).assertEqual(UTD.UniformDataType.FILE);
414    expect(records[5].getType()).assertEqual(UTD.UniformDataType.FOLDER);
415    expect(records[6].getType()).assertEqual(UTD.UniformDataType.IMAGE);
416    expect(records[7].getType()).assertEqual(UTD.UniformDataType.VIDEO);
417    expect(records[9].getType()).assertEqual(UTD.UniformDataType.OPENHARMONY_PIXEL_MAP);
418    expect(records[10].getType()).assertEqual(UTD.UniformDataType.OPENHARMONY_FORM);
419    expect(records[11].getType()).assertEqual(UTD.UniformDataType.OPENHARMONY_APP_ITEM);
420    console.info('UdmfAllRecordsTest end');
421  });
422
423  /**
424   * @tc.name UdmfText2MPlainText
425   * @tc.desc PlainText 2MB
426   * @tc.type: FUNC
427   * @tc.require: issueNumber
428   */
429  it('UdmfText2MPlainText', 0, async function (done) {
430    const TAG = 'UdmfText2MPlainText:';
431    console.info(TAG, 'start');
432    try {
433      let plainText = new UDC.PlainText();
434      plainText.textContent = LONG_TEST2M;
435      let unifiedData = new UDC.UnifiedData(plainText);
436      UDC.insertData(optionsValid, unifiedData).then((data) => {
437        console.info(TAG, `insert success. The key: ${data}`);
438        let options = { key: data };
439        console.info(TAG, `query start. The options: ${JSON.stringify(options)}`);
440        UDC.queryData(options).then((data) => {
441          console.info(TAG, 'query success.');
442          expect(data.length).assertEqual(1);
443          expect(data[0].getRecords()[0].textContent).assertEqual(LONG_TEST2M);
444          UDC.deleteData(options).then((data) => {
445            console.info(TAG, 'delete success.');
446            expect(data.length).assertEqual(1);
447            done();
448          }).catch(() => {
449            console.error(TAG, 'Unreachable code!');
450            expect(null).assertFail();
451            done();
452          });
453        }).catch(() => {
454          console.error(TAG, 'Unreachable code!');
455          expect(null).assertFail();
456          done();
457        });
458      }).catch(() => {
459        console.error(TAG, 'Unreachable code!');
460        expect(null).assertFail();
461        done();
462      });
463    } catch (e) {
464      console.error(TAG, 'Unreachable code!');
465      expect(null).assertFail();
466      done();
467    }
468    console.info(TAG, 'end');
469  });
470
471  /**
472   * @tc.name UdmfTextOver2MTest
473   * @tc.desc Test Over 2MB
474   * @tc.type: FUNC
475   * @tc.require: issueNumber
476   */
477  it('UdmfTextOver2MTest', 0, async function (done) {
478    const TAG = 'UdmfTextOver2MTest:';
479    console.info(TAG, 'start');
480    try {
481      let text = new UDC.Text();
482      text.details = {
483        title: '',
484        content: LONG_TESTOVER2M,
485      };
486      let unifiedData = new UDC.UnifiedData(text);
487      UDC.insertData(optionsValid, unifiedData).then((data) => {
488        console.info(TAG, `insert success. The key: ${data}`);
489        let options = { key: data };
490        console.info(TAG, `query start. The options: ${JSON.stringify(options)}`);
491        UDC.queryData(options).then((data) => {
492          console.info(TAG, 'query success.');
493          expect(data.length).assertEqual(1);
494          expect(data[0].getRecords()[0].details.content).assertEqual(LONG_TESTOVER2M);
495          UDC.deleteData(options).then((data) => {
496            console.info(TAG, 'delete success.');
497            expect(data.length).assertEqual(1);
498            done();
499          }).catch(() => {
500            console.error(TAG, 'Unreachable code!');
501            expect(null).assertFail();
502            done();
503          });
504        }).catch(() => {
505          console.error(TAG, 'Unreachable code!');
506          expect(null).assertFail();
507          done();
508        });
509      }).catch(() => {
510        console.error(TAG, 'Unreachable code!');
511        expect(null).assertFail();
512        done();
513      });
514    } catch (e) {
515      console.error(TAG, 'Unreachable code!');
516      expect(null).assertFail();
517      done();
518    }
519    console.info(TAG, 'end');
520  });
521
522  /**
523   * @tc.name UdmfTextOver2MPlainText
524   * @tc.desc PlainText Over 2MB
525   * @tc.type: FUNC
526   * @tc.require: issueNumber
527   */
528  it('UdmfTextOver2MPlainText', 0, async function (done) {
529    const TAG = 'UdmfTextOver2MPlainText:';
530    console.info(TAG, 'start');
531    try {
532      let plainText = new UDC.PlainText();
533      plainText.textContent = LONG_TESTOVER2M;
534      let unifiedData = new UDC.UnifiedData(plainText);
535      UDC.insertData(optionsValid, unifiedData).then((data) => {
536        console.info(TAG, `insert success. The key: ${data}`);
537        let options = { key: data };
538        console.info(TAG, `query start. The options: ${JSON.stringify(options)}`);
539        UDC.queryData(options).then((data) => {
540          console.info(TAG, 'query success.');
541          expect(data.length).assertEqual(1);
542          expect(data[0].getRecords()[0].textContent).assertEqual(LONG_TESTOVER2M);
543          UDC.deleteData(options).then((data) => {
544            console.info(TAG, 'delete success.');
545            expect(data.length).assertEqual(1);
546            done();
547          }).catch(() => {
548            console.error(TAG, 'Unreachable code!');
549            expect(null).assertFail();
550            done();
551          });
552        }).catch(() => {
553          console.error(TAG, 'Unreachable code!');
554          expect(null).assertFail();
555          done();
556        });
557      }).catch(() => {
558        console.error(TAG, 'Unreachable code!');
559        expect(null).assertFail();
560        done();
561      });
562    } catch (e) {
563      console.error(TAG, 'Unreachable code!');
564      expect(null).assertFail();
565      done();
566    }
567    console.info(TAG, 'end');
568  });
569
570  /**
571   * @tc.name UdmfTextOver2MHyperlink
572   * @tc.desc Hyperlink Over 2MB
573   * @tc.type: FUNC
574   * @tc.require: issueNumber
575   */
576  it('UdmfTextOver2MHyperlink', 0, async function (done) {
577    const TAG = 'UdmfTextOver2MHyperlink:';
578    console.info(TAG, 'start');
579    try {
580      let link = new UDC.Hyperlink();
581      link.url = LONG_TESTOVER2M;
582      let unifiedData = new UDC.UnifiedData(link);
583      UDC.insertData(optionsValid, unifiedData).then((data) => {
584        console.info(TAG, `insert success. The key: ${data}`);
585        let options = { key: data };
586        console.info(TAG, `query start. The options: ${JSON.stringify(options)}`);
587        UDC.queryData(options).then((data) => {
588          console.info(TAG, 'query success.');
589          expect(data.length).assertEqual(1);
590          expect(data[0].getRecords()[0].url).assertEqual(LONG_TESTOVER2M);
591          UDC.deleteData(options).then((data) => {
592            console.info(TAG, 'delete success.');
593            expect(data.length).assertEqual(1);
594            done();
595          }).catch(() => {
596            console.error(TAG, 'Unreachable code!');
597            expect(null).assertFail();
598            done();
599          });
600        }).catch(() => {
601          console.error(TAG, 'Unreachable code!');
602          expect(null).assertFail();
603          done();
604        });
605      }).catch(() => {
606        console.error(TAG, 'Unreachable code!');
607        expect(null).assertFail();
608        done();
609      });
610    } catch (e) {
611      console.error(TAG, 'Unreachable code!');
612      expect(null).assertFail();
613      done();
614    }
615    console.info(TAG, 'end');
616  });
617
618  /**
619   * @tc.name UdmfTextOver2MHTML
620   * @tc.desc HTML Over 2MB
621   * @tc.type: FUNC
622   * @tc.require: issueNumber
623   */
624  it('UdmfTextOver2MHTML', 0, async function (done) {
625    const TAG = 'UdmfTextOver2MHTML:';
626    console.info(TAG, 'start');
627    try {
628      let html = new UDC.HTML();
629      html.htmlContent = LONG_TESTOVER2M;
630      let unifiedData = new UDC.UnifiedData(html);
631      UDC.insertData(optionsValid, unifiedData).then((data) => {
632        console.info(TAG, `insert success. The key: ${data}`);
633        let options = { key: data };
634        console.info(TAG, `query start. The options: ${JSON.stringify(options)}`);
635        UDC.queryData(options).then((data) => {
636          console.info(TAG, 'query success.');
637          expect(data.length).assertEqual(1);
638          expect(data[0].getRecords()[0].htmlContent).assertEqual(LONG_TESTOVER2M);
639          UDC.deleteData(options).then((data) => {
640            console.info(TAG, 'delete success.');
641            expect(data.length).assertEqual(1);
642            done();
643          }).catch(() => {
644            console.error(TAG, 'Unreachable code!');
645            expect(null).assertFail();
646            done();
647          });
648        }).catch(() => {
649          console.error(TAG, 'Unreachable code!');
650          expect(null).assertFail();
651          done();
652        });
653      }).catch(() => {
654        console.error(TAG, 'Unreachable code!');
655        expect(null).assertFail();
656        done();
657      });
658    } catch (e) {
659      console.error(TAG, 'Unreachable code!');
660      expect(null).assertFail();
661      done();
662    }
663    console.info(TAG, 'end');
664  });
665
666  /**
667   * @tc.name UdmfTextOver2MSystemDefinedRecord
668   * @tc.desc SystemDefinedRecord Over 2MB
669   * @tc.type: FUNC
670   * @tc.require: issueNumber
671   */
672  it('UdmfTextOver2MSystemDefinedRecord', 0, async function (done) {
673    const TAG = 'UdmfTextOver2MSystemDefinedRecord:';
674    console.info(TAG, 'start');
675    try {
676      let systemDefinedRecord = new UDC.SystemDefinedRecord();
677      systemDefinedRecord.details = {
678        title: '',
679        content: LONG_TESTOVER2M
680      };
681      let unifiedData = new UDC.UnifiedData(systemDefinedRecord);
682      UDC.insertData(optionsValid, unifiedData).then((data) => {
683        console.info(TAG, `insert success. The key: ${data}`);
684        let options = { key: data };
685        console.info(TAG, `query start. The options: ${JSON.stringify(options)}`);
686        UDC.queryData(options).then((data) => {
687          console.info(TAG, 'query success.');
688          expect(data.length).assertEqual(1);
689          expect(data[0].getRecords()[0].details.content).assertEqual(LONG_TESTOVER2M);
690          UDC.deleteData(options).then((data) => {
691            console.info(TAG, 'delete success.');
692            expect(data.length).assertEqual(1);
693            done();
694          }).catch(() => {
695            console.error(TAG, 'Unreachable code!');
696            expect(null).assertFail();
697            done();
698          });
699        }).catch(() => {
700          console.error(TAG, 'Unreachable code!');
701          expect(null).assertFail();
702          done();
703        });
704      }).catch(() => {
705        console.error(TAG, 'Unreachable code!');
706        expect(null).assertFail();
707        done();
708      });
709    } catch (e) {
710      console.error(TAG, 'Unreachable code!');
711      expect(null).assertFail();
712      done();
713    }
714    console.info(TAG, 'end');
715  });
716
717  /**
718   * @tc.name UdmfTextOver2MSystemDefinedForm
719   * @tc.desc SystemDefinedForm Over 2MB
720   * @tc.type: FUNC
721   * @tc.require: issueNumber
722   */
723  it('UdmfTextOver2MSystemDefinedForm', 0, async function (done) {
724    const TAG = 'UdmfTextOver2MSystemDefinedForm:';
725    console.info(TAG, 'start');
726    try {
727      let systemDefinedForm = new UDC.SystemDefinedForm();
728      systemDefinedForm.formId = 123;
729      systemDefinedForm.formName = '1';
730      systemDefinedForm.bundleName = 'MyBundleName';
731      systemDefinedForm.abilityName = 'abilityName';
732      systemDefinedForm.module = LONG_TESTOVER2M;
733      let unifiedData = new UDC.UnifiedData(systemDefinedForm);
734      UDC.insertData(optionsValid, unifiedData).then((data) => {
735        console.info(TAG, `insert success. The key: ${data}`);
736        let options = { key: data };
737        console.info(TAG, `query start. The options: ${JSON.stringify(options)}`);
738        UDC.queryData(options).then((data) => {
739          console.info(TAG, 'query success.');
740          expect(data.length).assertEqual(1);
741          console.info(TAG, 'formId= ' + data[0].getRecords()[0].formId);
742          console.info(TAG, 'formName= ' + data[0].getRecords()[0].formName);
743          console.info(TAG, 'bundleName= ' + data[0].getRecords()[0].bundleName);
744          console.info(TAG, 'abilityName= ' + data[0].getRecords()[0].abilityName);
745          expect(data[0].getRecords()[0].module).assertEqual(LONG_TESTOVER2M);
746          UDC.deleteData(options).then((data) => {
747            console.info(TAG, 'delete success.');
748            expect(data.length).assertEqual(1);
749            done();
750          }).catch(() => {
751            console.error(TAG, 'Unreachable code!');
752            expect(null).assertFail();
753            done();
754          });
755        }).catch(() => {
756          console.error(TAG, 'Unreachable code!');
757          expect(null).assertFail();
758          done();
759        });
760      }).catch(() => {
761        console.error(TAG, 'Unreachable code!');
762        expect(null).assertFail();
763        done();
764      });
765    } catch (e) {
766      console.error(TAG, 'Unreachable code!');
767      expect(null).assertFail();
768      done();
769    }
770    console.info(TAG, 'end');
771  });
772
773  /**
774   * @tc.name UdmfTextOver2MSystemDefinedAppItem
775   * @tc.desc SystemDefinedAppItem Over 2MB
776   * @tc.type: FUNC
777   * @tc.require: issueNumber
778   */
779  it('UdmfTextOver2MSystemDefinedAppItem', 0, async function (done) {
780    const TAG = 'UdmfTextOver2MSystemDefinedAppItem:';
781    console.info(TAG, 'start');
782    try {
783      let systemDefinedAppItem = new UDC.SystemDefinedAppItem();
784      systemDefinedAppItem.appId = '1';
785      systemDefinedAppItem.appName = '2';
786      systemDefinedAppItem.appIconId = '3';
787      systemDefinedAppItem.appLabelId = '4';
788      systemDefinedAppItem.bundleName = '5';
789      systemDefinedAppItem.abilityName = LONG_TESTOVER2M;
790      let unifiedData = new UDC.UnifiedData(systemDefinedAppItem);
791      UDC.insertData(optionsValid, unifiedData).then((data) => {
792        console.info(TAG, `insert success. The key: ${data}`);
793        let options = { key: data };
794        console.info(TAG, `query start. The options: ${JSON.stringify(options)}`);
795        UDC.queryData(options).then((data) => {
796          console.info(TAG, 'query success.');
797          expect(data.length).assertEqual(1);
798          console.info(TAG, 'appId= ' + data[0].getRecords()[0].appId);
799          console.info(TAG, 'appName= ' + data[0].getRecords()[0].appName);
800          console.info(TAG, 'appIconId= ' + data[0].getRecords()[0].appIconId);
801          console.info(TAG, 'appLabelId= ' + data[0].getRecords()[0].appLabelId);
802          console.info(TAG, 'bundleName= ' + data[0].getRecords()[0].bundleName);
803          expect(data[0].getRecords()[0].abilityName).assertEqual(LONG_TESTOVER2M);
804          UDC.deleteData(options).then((data) => {
805            console.info(TAG, 'delete success.');
806            expect(data.length).assertEqual(1);
807            done();
808          }).catch(() => {
809            console.error(TAG, 'Unreachable code!');
810            expect(null).assertFail();
811            done();
812          });
813        }).catch(() => {
814          console.error(TAG, 'Unreachable code!');
815          expect(null).assertFail();
816          done();
817        });
818      }).catch(() => {
819        console.error(TAG, 'Unreachable code!');
820        expect(null).assertFail();
821        done();
822      });
823    } catch (e) {
824      console.error(TAG, 'Unreachable code!');
825      expect(null).assertFail();
826      done();
827    }
828    console.info(TAG, 'end');
829  });
830
831  /**
832   * @tc.name UdmfTextOver2MSystemDefinedPixelMap
833   * @tc.desc SystemDefinedPixelMap Over 2MB
834   * @tc.type: FUNC
835   * @tc.require: issueNumber
836   */
837  it('UdmfTextOver2MSystemDefinedPixelMap', 0, async function (done) {
838    const TAG = 'UdmfTextOver2MSystemDefinedPixelMap:';
839    console.info(TAG, 'start');
840    try {
841      let text = new UDC.SystemDefinedPixelMap();
842      let longU8ArrayData = new Uint8Array(NUM_4M);
843      longU8ArrayData.fill(0);
844      text.rawData = longU8ArrayData;
845      text.details = {
846        recordKey1: 'systemDefinedPixelMap' + KEY_TEST_ELEMENT,
847        recordKey2: U8_ARRAY,
848      };
849      let unifiedData = new UDC.UnifiedData(text);
850      UDC.insertData(optionsValid, unifiedData).then((data) => {
851        console.info(TAG, `insert success. The key: ${data}`);
852        let options = { key: data };
853        console.info(TAG, `query start. The options: ${JSON.stringify(options)}`);
854        UDC.queryData(options).then((data) => {
855          console.info(TAG, 'query success.');
856          expect(data.length).assertEqual(1);
857          let records = data[0].getRecords();
858          expect(records.length).assertEqual(1);
859          expect(records[0].details.recordKey1).assertEqual('systemDefinedPixelMap' + KEY_TEST_ELEMENT);
860          for (let i = 0; i < U8_ARRAY.length; i++) {
861            expect(records[0].details.recordKey2[i]).assertEqual(U8_ARRAY[i]);
862          }
863          expect(records[0].rawData.toString()).assertEqual(longU8ArrayData.toString());
864          UDC.deleteData(options).then((data) => {
865            console.info(TAG, 'delete success.');
866            expect(data.length).assertEqual(1);
867            done();
868          }).catch(() => {
869            console.error(TAG, 'Unreachable code!');
870            expect(null).assertFail();
871            done();
872          });
873        }).catch(() => {
874          console.error(TAG, 'Unreachable code!');
875          expect(null).assertFail();
876          done();
877        });
878      }).catch(() => {
879        console.error(TAG, 'Unreachable code!');
880        expect(null).assertFail();
881        done();
882      });
883    } catch (e) {
884      console.error(TAG, 'Unreachable code!');
885      expect(null).assertFail();
886      done();
887    }
888    console.info(TAG, 'end');
889  });
890
891  /**
892   * @tc.name UdmfTextOver2MApplicationDefinedRecord
893   * @tc.desc ApplicationDefinedRecord Over 2MB
894   * @tc.type: FUNC
895   * @tc.require: issueNumber
896   */
897  it('UdmfTextOver2MApplicationDefinedRecord', 0, async function (done) {
898    const TAG = 'UdmfTextOver2MApplicationDefinedRecord:';
899    console.info(TAG, 'start');
900    try {
901      let text = new UDC.ApplicationDefinedRecord();
902      text.applicationDefinedType = '1';
903      text.rawData = new Uint8Array(NUM_4M);
904      let unifiedData = new UDC.UnifiedData(text);
905      UDC.insertData(optionsValid, unifiedData).then((data) => {
906        console.info(TAG, `insert success. The key: ${data}`);
907        let options = { key: data };
908        console.info(TAG, `query start. The options: ${JSON.stringify(options)}`);
909        UDC.queryData(options).then((data) => {
910          console.info(TAG, 'query success.');
911          expect(data.length).assertEqual(1);
912          UDC.deleteData(options).then((data) => {
913            console.info(TAG, 'delete success.');
914            expect(data.length).assertEqual(1);
915            done();
916          }).catch(() => {
917            console.error(TAG, 'Unreachable code!');
918            expect(null).assertFail();
919            done();
920          });
921        }).catch(() => {
922          console.error(TAG, 'Unreachable code!');
923          expect(null).assertFail();
924          done();
925        });
926      }).catch(() => {
927        console.error(TAG, 'Unreachable code!');
928        expect(null).assertFail();
929        done();
930      });
931    } catch (e) {
932      console.error(TAG, 'Unreachable code!');
933      expect(null).assertFail();
934      done();
935    }
936    console.info(TAG, 'end');
937  });
938
939  /**
940   * @tc.name UdmfText4M
941   * @tc.desc UdmfText4M 4MB
942   * @tc.type: FUNC
943   * @tc.require: issueNumber
944   */
945  it('UdmfText4M', 0, async function (done) {
946    const TAG = 'UdmfText4M:';
947    console.info(TAG, 'start');
948    try {
949      let text = new UDC.PlainText();
950      text.textContent = LONG_TEST2M;
951      let unifiedData = new UDC.UnifiedData(text);
952      let html = new UDC.HTML();
953      html.htmlContent = LONG_TEST2M;
954      unifiedData.addRecord(html);
955      UDC.insertData(optionsValid, unifiedData).then((data) => {
956        console.info(TAG, `insert success. The key: ${data}`);
957        let options = { key: data };
958        console.info(TAG, `query start. The options: ${JSON.stringify(options)}`);
959        UDC.queryData(options).then((data) => {
960          console.info(TAG, 'query success.');
961          expect(data.length).assertEqual(1);
962          let records = data[0].getRecords();
963          console.info(TAG, `records.length = ${records.length}.`);
964          console.info(TAG, `records[0] = ${records[0].textContent === LONG_TEST2M}.`);
965          console.info(TAG, `records[1] = ${records[1].htmlContent === LONG_TEST2M}.`);
966          console.info(TAG, `records[0].getType() = ${records[0].getType()}.`);
967          console.info(TAG, `records[1].getType() = ${records[1].getType()}.`);
968          console.info(TAG, `records[0].getType() = ${records[0].getType() === UTD.UniformDataType.PLAIN_TEXT}.`);
969          console.info(TAG, `records[1].getType() = ${records[1].getType() === UTD.UniformDataType.HTML}.`);
970          expect(records[0].textContent).assertEqual(LONG_TEST2M);
971          expect(records[1].htmlContent).assertEqual(LONG_TEST2M);
972          UDC.deleteData(options).then((data) => {
973            console.info(TAG, 'delete success.');
974            expect(data.length).assertEqual(1);
975            done();
976          }).catch(() => {
977            console.error(TAG, 'Unreachable code!');
978            expect(null).assertFail();
979            done();
980          });
981        }).catch(() => {
982          console.error(TAG, 'Unreachable code!');
983          expect(null).assertFail();
984          done();
985        });
986      }).catch(() => {
987        console.error(TAG, 'Unreachable code!');
988        expect(null).assertFail();
989        done();
990      });
991    } catch (e) {
992      console.error(TAG, 'Unreachable code!');
993      expect(null).assertFail();
994      done();
995    }
996    console.info(TAG, 'end');
997  });
998
999  /**
1000   * @tc.name UnifiedDataPropertiesTest001
1001   * @tc.desc Test Js UnifiedDataProperties testcase
1002   * @tc.type: FUNC
1003   * @tc.require:
1004   */
1005  it('UnifiedDataPropertiesTest001', 0, function () {
1006    const TAG = 'UnifiedDataPropertiesTest001';
1007    console.info(TAG, 'start');
1008    let text = new UDC.Text();
1009    let unifiedDatas = new UDC.UnifiedData();
1010    unifiedDatas.addRecord(text);
1011    let properties = unifiedDatas.properties;
1012    expect(typeof properties).assertEqual('object');
1013    expect(typeof properties.extras).assertEqual('object');
1014    expect(typeof properties.tag).assertEqual('string');
1015    expect(typeof properties.timestamp).assertEqual('object');
1016    expect(typeof properties.shareOptions).assertEqual('number');
1017    expect(typeof properties.getDelayData).assertEqual('undefined');
1018  });
1019
1020  /**
1021   * @tc.name UnifiedDataPropertiesTest002
1022   * @tc.desc Test Js UnifiedDataProperties testcase
1023   * @tc.type: FUNC
1024   * @tc.require:
1025   */
1026  it('UnifiedDataPropertiesTest002', 0, function () {
1027    const TAG = 'UnifiedDataPropertiesTest002';
1028    console.info(TAG, 'start');
1029    let text = new UDC.Text();
1030    let unifiedData = new UDC.UnifiedData(text);
1031    let properties = new UDC.UnifiedDataProperties();
1032
1033    expect(properties.shareOptions).assertEqual(UDC.ShareOptions.CROSS_APP);
1034    properties.shareOptions = UDC.ShareOptions.IN_APP;
1035    unifiedData.properties = properties;
1036    expect(unifiedData.properties.shareOptions).assertEqual(UDC.ShareOptions.IN_APP);
1037    unifiedData.properties.shareOptions = UDC.ShareOptions.CROSS_APP;
1038    expect(unifiedData.properties.shareOptions).assertEqual(UDC.ShareOptions.CROSS_APP);
1039
1040    expect(unifiedData.properties.tag).assertEqual('');
1041    unifiedData.properties.tag = 'DataTag';
1042    expect(unifiedData.properties.tag).assertEqual('DataTag');
1043
1044    expect(Object.keys(unifiedData.properties.extras).length).assertEqual(0);
1045    let person = {fname: 'John', lname: 'Doe', age: 25};
1046    unifiedData.properties.extras = person;
1047    expect(Object.keys(unifiedData.properties.extras).length).assertEqual(3);
1048    expect(unifiedData.properties.extras.fname).assertEqual(person.fname);
1049  });
1050
1051  /**
1052   * @tc.name UnifiedDataPropertiesTest003
1053   * @tc.desc Test Js UnifiedDataProperties testcase
1054   * @tc.type: FUNC
1055   * @tc.require:
1056   */
1057  it('UnifiedDataPropertiesTest003', 0, function () {
1058    const TAG = 'UnifiedDataPropertiesTest003';
1059    console.info(TAG, 'start');
1060    let text = new UDC.Text();
1061    let unifiedData = new UDC.UnifiedData(text);
1062
1063    function func(inputStr) {
1064      console.info(TAG, 'execute func');
1065      let text = new UDC.Text();
1066      text.details = {
1067        Key: inputStr + KEY_TEST_ELEMENT,
1068        Value: inputStr + VALUE_TEST_ELEMENT,
1069      };
1070      let data = new UDC.UnifiedData(text);
1071      data.properties.tag = 'FileTag';
1072      return data;
1073    }
1074    unifiedData.properties.getDelayData = func;
1075    const data = unifiedData.properties.getDelayData('inputTest');
1076    let records = data.getRecords();
1077    expect(records.length).assertEqual(1);
1078    expect(records[0].details.Key).assertEqual('inputTest' + KEY_TEST_ELEMENT);
1079    expect(records[0].details.Value).assertEqual('inputTest' + VALUE_TEST_ELEMENT);
1080    expect(data.properties.tag).assertEqual('FileTag');
1081  });
1082
1083  /**
1084   * @tc.name UnifiedDataHasType
1085   * @tc.desc Test Js UnifiedDataProperties testcase
1086   * @tc.type: FUNC
1087   * @tc.require:
1088   */
1089  it('UnifiedDataHasType', 0, function () {
1090    const TAG = 'UnifiedDataHasType';
1091    console.info(TAG, 'start');
1092    const textType = 'general.text';
1093    const plaintextType = 'general.plain-text';
1094    const htmlType = 'general.html';
1095
1096    let text = new UDC.Text();
1097    let unifiedData = new UDC.UnifiedData(text);
1098    expect(unifiedData.hasType(textType)).assertEqual(true);
1099    expect(unifiedData.hasType(htmlType)).assertEqual(false);
1100    expect(unifiedData.hasType(plaintextType)).assertEqual(false);
1101    let types = unifiedData.getTypes();
1102    expect(types.length).assertEqual(1);
1103    expect(types[0]).assertEqual(textType);
1104
1105    let html = new UDC.HTML();
1106    unifiedData.addRecord(html);
1107    expect(unifiedData.hasType(textType)).assertEqual(true);
1108    expect(unifiedData.hasType(htmlType)).assertEqual(true);
1109    expect(unifiedData.hasType(plaintextType)).assertEqual(false);
1110    types = unifiedData.getTypes();
1111    expect(types.length).assertEqual(2);
1112    expect(types[0]).assertEqual(textType);
1113    expect(types[1]).assertEqual(htmlType);
1114  });
1115
1116  /**
1117   * @tc.name UnifiedRecordConstruct001
1118   * @tc.desc Test Js UnifiedRecord testcase
1119   * @tc.type: FUNC
1120   * @tc.require:
1121   */
1122  it('UnifiedRecordConstruct001', 0, async function () {
1123    const TAG = 'UnifiedRecordConstruct001';
1124    console.info(TAG, 'start');
1125
1126    const dataUri = new ArrayBuffer(256);
1127    let view1 = new Uint32Array(dataUri);
1128    view1[0] = 123456;
1129    let record1 = new UDC.UnifiedRecord('general.message', dataUri);
1130    const data1 = record1.getValue();
1131    expect(data1.byteLength).assertEqual(256);
1132    let view2 = new Uint32Array(data1);
1133    expect(view1[0]).assertEqual(view2[0]);
1134
1135    let record2 = new UDC.UnifiedRecord('general.message', 'xxx.com');
1136    const data2 = record2.getValue();
1137    expect(data2).assertEqual('xxx.com');
1138
1139    let record3 = new UDC.UnifiedRecord('general.message', 8899);
1140    const data3 = record3.getValue();
1141    expect(data3).assertEqual(8899);
1142
1143    let record4 = new UDC.UnifiedRecord('general.message', 8899.7788);
1144    const data4 = record4.getValue();
1145    expect(data4).assertEqual(8899.7788);
1146
1147    const buffer = new ArrayBuffer(128);
1148    const opt = {
1149      size: { height: 5, width: 5 },
1150      pixelFormat: 3,
1151      editable: true,
1152      alphaType: 1,
1153      scaleMode: 1,
1154    };
1155    const pixelMap = await image.createPixelMap(buffer, opt);
1156    let record5 = new UDC.UnifiedRecord('openharmony.pixel-map', pixelMap);
1157    const data5 = record5.getValue();
1158    data5.getImageInfo().then((imageInfo)=>{
1159      expect(imageInfo.size.height).assertEqual(opt.size.height);
1160      expect(imageInfo.pixelFormat).assertEqual(opt.pixelFormat);
1161    });
1162
1163    const wantText = {
1164      bundleName: 'com.example.myapplication1',
1165      abilityName: 'com.example.myapplication1.MainAbility',
1166    };
1167    let record6 = new UDC.UnifiedRecord('openharmony.want', wantText);
1168    const data6 = record6.getValue();
1169    expect(data6.bundleName).assertEqual(wantText.bundleName);
1170    expect(data6.abilityName).assertEqual(wantText.abilityName);
1171  });
1172
1173  /**
1174   * @tc.name UnifiedRecordConstruct002
1175   * @tc.desc Test Js UnifiedData GetRecords testcase
1176   * @tc.type: FUNC
1177   * @tc.require:
1178   */
1179  it('UnifiedRecordConstruct002', 0, async function () {
1180    const TAG = 'UnifiedRecordConstruct002';
1181    console.info(TAG, 'start');
1182
1183    const dataUri = new ArrayBuffer(256);
1184    let view1 = new Uint32Array(dataUri);
1185    view1[0] = 123456;
1186    let record1 = new UDC.UnifiedRecord('general.message', dataUri);
1187
1188    let unifiedData = new UDC.UnifiedData(record1);
1189    let records = unifiedData.getRecords();
1190    expect(records.length).assertEqual(1);
1191
1192    let record2 = new UDC.UnifiedRecord('general.message', 'xxx.com');
1193    unifiedData.addRecord(record2);
1194    let record3 = new UDC.UnifiedRecord('general.message', 8899);
1195    unifiedData.addRecord(record3);
1196    let record4 = new UDC.UnifiedRecord('general.message', 8899.7788);
1197    unifiedData.addRecord(record4);
1198    const buffer = new ArrayBuffer(128);
1199    const opt = {
1200      size: { height: 5, width: 5 },
1201      pixelFormat: 3,
1202      editable: true,
1203      alphaType: 1,
1204      scaleMode: 1,
1205    };
1206    const pixelMap = await image.createPixelMap(buffer, opt);
1207    let record5 = new UDC.UnifiedRecord('openharmony.pixel-map', pixelMap);
1208    unifiedData.addRecord(record5);
1209    const wantText = {
1210      bundleName: 'com.example.myapplication1',
1211      abilityName: 'com.example.myapplication1.MainAbility',
1212    };
1213    let record6 = new UDC.UnifiedRecord('openharmony.want', wantText);
1214    unifiedData.addRecord(record6);
1215
1216    records = unifiedData.getRecords();
1217    expect(records.length).assertEqual(6);
1218    const data1 = records[0].getValue();
1219    expect(data1.byteLength).assertEqual(256);
1220    let view2 = new Uint32Array(data1);
1221    expect(view1[0]).assertEqual(view2[0]);
1222    const data2 = records[1].getValue();
1223    expect(data2).assertEqual('xxx.com');
1224    const data3 = records[2].getValue();
1225    expect(data3).assertEqual(8899);
1226    const data4 = records[3].getValue();
1227    expect(data4).assertEqual(8899.7788);
1228    const data5 = records[4].getValue();
1229    data5.getImageInfo().then((imageInfo)=>{
1230      expect(imageInfo.size.height).assertEqual(opt.size.height);
1231      expect(imageInfo.pixelFormat).assertEqual(opt.pixelFormat);
1232    });
1233    const data6 = records[5].getValue();
1234    expect(data6.bundleName).assertEqual(wantText.bundleName);
1235    expect(data6.abilityName).assertEqual(wantText.abilityName);
1236  });
1237
1238  /**
1239   * @tc.name UnifiedRecordConstruct003
1240   * @tc.desc Test Js UnifiedData GetRecords testcase
1241   * @tc.type: FUNC
1242   * @tc.require:
1243   */
1244  it('UnifiedRecordConstruct003', 0, async function () {
1245    const TAG = 'UnifiedRecordConstruct003';
1246    console.info(TAG, 'start');
1247
1248    const dataUri = new ArrayBuffer(256);
1249    let view1 = new Uint32Array(dataUri);
1250    view1[0] = 123456;
1251    let record1 = new UDC.UnifiedRecord('general.text', dataUri);
1252    let unifiedData = new UDC.UnifiedData(record1);
1253    let record2 = new UDC.UnifiedRecord('general.text', 'xxx.com');
1254    unifiedData.addRecord(record2);
1255    let record3 = new UDC.UnifiedRecord('general.text', 8899);
1256    unifiedData.addRecord(record3);
1257    let record4 = new UDC.UnifiedRecord('general.text', 8899.7788);
1258    unifiedData.addRecord(record4);
1259
1260    let records = unifiedData.getRecords();
1261    expect(records.length).assertEqual(4);
1262    const data1 = records[0].getValue();
1263    expect(data1.byteLength).assertEqual(256);
1264    let view2 = new Uint32Array(data1);
1265    expect(view1[0]).assertEqual(view2[0]);
1266    const data2 = records[1].getValue();
1267    expect(data2).assertEqual('xxx.com');
1268    const data3 = records[2].getValue();
1269    expect(data3).assertEqual(8899);
1270    const data4 = records[3].getValue();
1271    expect(data4).assertEqual(8899.7788);
1272  });
1273
1274  /**
1275   * @tc.name UnifiedRecordConstruct004
1276   * @tc.desc Test Js UnifiedData GetRecords testcase
1277   * @tc.type: FUNC
1278   * @tc.require:
1279   */
1280  it('UnifiedRecordConstruct004', 0, async function () {
1281    const TAG = 'UnifiedRecordConstruct004';
1282    console.info(TAG, 'start');
1283
1284    const dataUri = new ArrayBuffer(256);
1285    let view1 = new Uint32Array(dataUri);
1286    view1[0] = 123456;
1287    let record1 = new UDC.UnifiedRecord('otherType', dataUri);
1288    let unifiedData = new UDC.UnifiedData(record1);
1289    let record2 = new UDC.UnifiedRecord('otherType', 'xxx.com');
1290    unifiedData.addRecord(record2);
1291    let record3 = new UDC.UnifiedRecord('otherType', 8899);
1292    unifiedData.addRecord(record3);
1293    let record4 = new UDC.UnifiedRecord('otherType', 8899.7788);
1294    unifiedData.addRecord(record4);
1295
1296    let records = unifiedData.getRecords();
1297    expect(records.length).assertEqual(4);
1298    const data1 = records[0].getValue();
1299    expect(data1.byteLength).assertEqual(256);
1300    let view2 = new Uint32Array(data1);
1301    expect(view1[0]).assertEqual(view2[0]);
1302    const data2 = records[1].getValue();
1303    expect(data2).assertEqual('xxx.com');
1304    const data3 = records[2].getValue();
1305    expect(data3).assertEqual(8899);
1306    const data4 = records[3].getValue();
1307    expect(data4).assertEqual(8899.7788);
1308  });
1309
1310  /**
1311   * @tc.name UDSTest001
1312   * @tc.desc
1313   * @tc.type: FUNC
1314   * @tc.require:
1315   */
1316  it('UDSTest001', 0, async function () {
1317    const TAG = 'UDSTest001';
1318    console.info(TAG, 'start');
1319
1320    let plainTextDetails = {
1321      'key1': 'value1',
1322      'key2': 'value2',
1323    };
1324    let plainText = {
1325      uniformDataType: UTD.UniformDataType.PLAIN_TEXT,
1326      textContent: 'This is plainText textContent example',
1327      abstract: 'this is abstract',
1328      details: plainTextDetails
1329    };
1330    let record1 = new UDC.UnifiedRecord(UTD.UniformDataType.PLAIN_TEXT, plainText);
1331    let unifiedData = new UDC.UnifiedData(record1);
1332    let records = unifiedData.getRecords();
1333    expect(records.length).assertEqual(1);
1334    const value1 = records[0].getValue();
1335
1336    expect(value1.uniformDataType).assertEqual(plainText.uniformDataType);
1337    expect(value1.textContent).assertEqual(plainText.textContent);
1338    expect(value1.abstract).assertEqual(plainText.abstract);
1339    expect(value1.details.key1).assertEqual(plainText.details.key1);
1340    expect(value1.details.key2).assertEqual(plainText.details.key2);
1341  });
1342
1343  /**
1344   * @tc.name UDSTest002
1345   * @tc.desc
1346   * @tc.type: FUNC
1347   * @tc.require:
1348   */
1349  it('UDSTest002', 0, async function (done) {
1350    const TAG = 'UDSTest002';
1351    console.info(TAG, 'start');
1352
1353    let plainTextDetails = {
1354      'key1': 'value1',
1355      'key2': 'value2',
1356    };
1357    let plainText = {
1358      uniformDataType: UTD.UniformDataType.PLAIN_TEXT,
1359      textContent: 'This is plainText textContent example',
1360      abstract: 'this is abstract',
1361      details: plainTextDetails
1362    };
1363    let record1 = new UDC.UnifiedRecord(UTD.UniformDataType.PLAIN_TEXT, plainText);
1364    let unifiedData = new UDC.UnifiedData(record1);
1365
1366    try {
1367      UDC.insertData(optionsValid, unifiedData).then((data) => {
1368        console.info(TAG, `insert success. The key: ${data}`);
1369        let options = { key: data };
1370        console.info(TAG, `query start. The options: ${JSON.stringify(options)}`);
1371        UDC.queryData(options).then((data) => {
1372          console.info(TAG, 'query success.');
1373          expect(data.length).assertEqual(1);
1374          let records = data[0].getRecords();
1375          expect(records.length).assertEqual(1);
1376          let value = records[0].getValue();
1377          expect(value.uniformDataType).assertEqual(plainText.uniformDataType);
1378          expect(value.textContent).assertEqual(plainText.textContent);
1379          expect(value.abstract).assertEqual(plainText.abstract);
1380          expect(value.details.key1).assertEqual(plainText.details.key1);
1381          expect(value.details.key2).assertEqual(plainText.details.key2);
1382          UDC.deleteData(options).then((data) => {
1383            console.info(TAG, 'delete success.');
1384            expect(data.length).assertEqual(1);
1385            done();
1386          }).catch(() => {
1387            console.error(TAG, 'Unreachable code!');
1388            expect(null).assertFail();
1389            done();
1390          });
1391        }).catch(() => {
1392          console.error(TAG, 'Unreachable code!');
1393          expect(null).assertFail();
1394          done();
1395        });
1396      }).catch(() => {
1397        console.error(TAG, 'Unreachable code!');
1398        expect(null).assertFail();
1399        done();
1400      });
1401    } catch (e) {
1402      console.error(TAG, 'Unreachable code!');
1403      expect(null).assertFail();
1404      done();
1405    }
1406  });
1407
1408  /**
1409   * @tc.name UDSTest003
1410   * @tc.desc
1411   * @tc.type: FUNC
1412   * @tc.require:
1413   */
1414  it('UDSTest003', 0, async function (done) {
1415    const TAG = 'UDSTest003';
1416    console.info(TAG, 'start');
1417
1418    let hyperLinkDetails = {
1419      'key1': 'value1',
1420      'key2': 'value2',
1421    };
1422    let hyperLink = {
1423      uniformDataType: UTD.UniformDataType.HYPERLINK,
1424      url: 'www.xxx',
1425      description: 'hyperlinkDescription',
1426      details: hyperLinkDetails
1427    };
1428    let record1 = new UDC.UnifiedRecord(UTD.UniformDataType.HYPERLINK, hyperLink);
1429    let unifiedData = new UDC.UnifiedData(record1);
1430
1431    try {
1432      UDC.insertData(optionsValid, unifiedData).then((data) => {
1433        console.info(TAG, `insert success. The key: ${data}`);
1434        let options = { key: data };
1435        console.info(TAG, `query start. The options: ${JSON.stringify(options)}`);
1436        UDC.queryData(options).then((data) => {
1437          console.info(TAG, 'query success.');
1438          expect(data.length).assertEqual(1);
1439          let records = data[0].getRecords();
1440          expect(records.length).assertEqual(1);
1441          let value = records[0].getValue();
1442          expect(value.uniformDataType).assertEqual(hyperLink.uniformDataType);
1443          expect(value.url).assertEqual(hyperLink.url);
1444          expect(value.description).assertEqual(hyperLink.description);
1445          expect(value.details.key1).assertEqual(hyperLink.details.key1);
1446          expect(value.details.key2).assertEqual(hyperLink.details.key2);
1447          UDC.deleteData(options).then((data) => {
1448            console.info(TAG, 'delete success.');
1449            expect(data.length).assertEqual(1);
1450            done();
1451          }).catch(() => {
1452            console.error(TAG, 'Unreachable code!');
1453            expect(null).assertFail();
1454            done();
1455          });
1456        }).catch(() => {
1457          console.error(TAG, 'Unreachable code!');
1458          expect(null).assertFail();
1459          done();
1460        });
1461      }).catch(() => {
1462        console.error(TAG, 'Unreachable code!');
1463        expect(null).assertFail();
1464        done();
1465      });
1466    } catch (e) {
1467      console.error(TAG, 'Unreachable code!');
1468      expect(null).assertFail();
1469      done();
1470    }
1471  });
1472
1473  /**
1474   * @tc.name UDSTest004
1475   * @tc.desc
1476   * @tc.type: FUNC
1477   * @tc.require:
1478   */
1479  it('UDSTest004', 0, async function (done) {
1480    const TAG = 'UDSTest004';
1481    console.info(TAG, 'start');
1482
1483    let htmlDetails = {
1484      'key1': 'value1',
1485      'key2': 'value2',
1486    };
1487    let html = {
1488      uniformDataType: UTD.UniformDataType.HTML,
1489      htmlContent: 'www.xxx',
1490      plainContent: 'htmlDescription',
1491      details: htmlDetails
1492    };
1493    let record1 = new UDC.UnifiedRecord(UTD.UniformDataType.HTML, html);
1494    let unifiedData = new UDC.UnifiedData(record1);
1495
1496    try {
1497      UDC.insertData(optionsValid, unifiedData).then((data) => {
1498        console.info(TAG, `insert success. The key: ${data}`);
1499        let options = { key: data };
1500        console.info(TAG, `query start. The options: ${JSON.stringify(options)}`);
1501        UDC.queryData(options).then((data) => {
1502          console.info(TAG, 'query success.');
1503          expect(data.length).assertEqual(1);
1504          let records = data[0].getRecords();
1505          expect(records.length).assertEqual(1);
1506          let value = records[0].getValue();
1507          expect(value.uniformDataType).assertEqual(html.uniformDataType);
1508          expect(value.htmlContent).assertEqual(html.htmlContent);
1509          expect(value.plainContent).assertEqual(html.plainContent);
1510          expect(value.details.key1).assertEqual(html.details.key1);
1511          expect(value.details.key2).assertEqual(html.details.key2);
1512          UDC.deleteData(options).then((data) => {
1513            console.info(TAG, 'delete success.');
1514            expect(data.length).assertEqual(1);
1515            done();
1516          }).catch(() => {
1517            console.error(TAG, 'Unreachable code!');
1518            expect(null).assertFail();
1519            done();
1520          });
1521        }).catch(() => {
1522          console.error(TAG, 'Unreachable code!');
1523          expect(null).assertFail();
1524          done();
1525        });
1526      }).catch(() => {
1527        console.error(TAG, 'Unreachable code!');
1528        expect(null).assertFail();
1529        done();
1530      });
1531    } catch (e) {
1532      console.error(TAG, 'Unreachable code!');
1533      expect(null).assertFail();
1534      done();
1535    }
1536  });
1537
1538  /**
1539   * @tc.name UDSTest005
1540   * @tc.desc
1541   * @tc.type: FUNC
1542   * @tc.require:
1543   */
1544  it('UDSTest005', 0, async function (done) {
1545    const TAG = 'UDSTest005';
1546    console.info(TAG, 'start');
1547
1548    let systemDefinedDetails = {
1549      'key1': 'value1',
1550      'key2': 'value2',
1551    };
1552    let systemDefined = {
1553      uniformDataType: 'openharmony.app-item',
1554      appId: 'app-itemAppId',
1555      appName: 'app-itemAppName',
1556      appIconId: 'app-itemAppIconId',
1557      appLabelId: 'app-itemAppLabelId',
1558      bundleName: 'app-itemBundleName',
1559      abilityName: 'app-itemAbilityName',
1560      details: systemDefinedDetails
1561    };
1562    let record1 = new UDC.UnifiedRecord('openharmony.app-item', systemDefined);
1563    let unifiedData = new UDC.UnifiedData(record1);
1564
1565    try {
1566      UDC.insertData(optionsValid, unifiedData).then((data) => {
1567        console.info(TAG, `insert success. The key: ${data}`);
1568        let options = { key: data };
1569        console.info(TAG, `query start. The options: ${JSON.stringify(options)}`);
1570        UDC.queryData(options).then((data) => {
1571          console.info(TAG, 'query success.');
1572          expect(data.length).assertEqual(1);
1573          let records = data[0].getRecords();
1574          expect(records.length).assertEqual(1);
1575          let value = records[0].getValue();
1576          expect(value.uniformDataType).assertEqual(systemDefined.uniformDataType);
1577          expect(value.appId).assertEqual(systemDefined.appId);
1578          expect(value.appName).assertEqual(systemDefined.appName);
1579          expect(value.appIconId).assertEqual(systemDefined.appIconId);
1580          expect(value.appLabelId).assertEqual(systemDefined.appLabelId);
1581          expect(value.bundleName).assertEqual(systemDefined.bundleName);
1582          expect(value.abilityName).assertEqual(systemDefined.abilityName);
1583          expect(value.details.key1).assertEqual(systemDefined.details.key1);
1584          expect(value.details.key2).assertEqual(systemDefined.details.key2);
1585          UDC.deleteData(options).then((data) => {
1586            console.info(TAG, 'delete success.');
1587            expect(data.length).assertEqual(1);
1588            done();
1589          }).catch(() => {
1590            console.error(TAG, 'Unreachable code!');
1591            expect(null).assertFail();
1592            done();
1593          });
1594        }).catch(() => {
1595          console.error(TAG, 'Unreachable code!');
1596          expect(null).assertFail();
1597          done();
1598        });
1599      }).catch(() => {
1600        console.error(TAG, 'Unreachable code!');
1601        expect(null).assertFail();
1602        done();
1603      });
1604    } catch (e) {
1605      console.error(TAG, 'Unreachable code!');
1606      expect(null).assertFail();
1607      done();
1608    }
1609  });
1610
1611  /**
1612   * @tc.name ObjectTest001
1613   * @tc.desc
1614   * @tc.type: FUNC
1615   * @tc.require:
1616   */
1617  it('ObjectTest001', 0, async function (done) {
1618    const TAG = 'ObjectTest001';
1619    console.info(TAG, 'start');
1620
1621    const data = new ArrayBuffer(256);
1622    let view1 = new Uint32Array(data);
1623    view1[0] = 123456;
1624
1625    let ObjectDetails1 = {
1626      'key1': 'value001',
1627      'key2': data,
1628      'key3': undefined,
1629      'key4': null,
1630    };
1631    let ObjectDetails2 = {
1632      'key1': 'value100',
1633      'key2': data,
1634      'key3': undefined,
1635      'key4': null,
1636      details: ObjectDetails1
1637    };
1638    let systemDefined = {
1639      labelId: 'LabelId',
1640      details: ObjectDetails2
1641    };
1642    let record1 = new UDC.UnifiedRecord('self_defined_type', systemDefined);
1643    let unifiedData = new UDC.UnifiedData(record1);
1644
1645    try {
1646      UDC.insertData(optionsValid, unifiedData).then((data) => {
1647        console.info(TAG, `insert success. The key: ${data}`);
1648        let options = { key: data };
1649        console.info(TAG, `query start. The options: ${JSON.stringify(options)}`);
1650        UDC.queryData(options).then((data) => {
1651          console.info(TAG, 'query success.');
1652          expect(data.length).assertEqual(1);
1653          let records = data[0].getRecords();
1654          expect(records.length).assertEqual(1);
1655          let value = records[0].getValue();
1656          expect(value.labelId).assertEqual(systemDefined.labelId);
1657          expect(value.details.key1).assertEqual(systemDefined.details.key1);
1658          expect(value.details.key2.byteLength).assertEqual(systemDefined.details.key2.byteLength);
1659          let view2 = new Uint32Array(value.details.key2);
1660          expect(view2[0]).assertEqual(view1[0]);
1661          expect(value.details.key3).assertEqual(systemDefined.details.key3);
1662          expect(value.details.key4).assertEqual(systemDefined.details.key4);
1663          expect(value.details.details.key1).assertEqual(systemDefined.details.details.key1);
1664          expect(value.details.details.key2.byteLength).assertEqual(systemDefined.details.details.key2.byteLength);
1665          let view3 = new Uint32Array(value.details.details.key2);
1666          expect(view3[0]).assertEqual(view1[0]);
1667          expect(value.details.details.key3).assertEqual(systemDefined.details.details.key3);
1668          expect(value.details.details.key4).assertEqual(systemDefined.details.details.key4);
1669          UDC.deleteData(options).then((data) => {
1670            console.info(TAG, 'delete success.');
1671            expect(data.length).assertEqual(1);
1672            done();
1673          }).catch(() => {
1674            console.error(TAG, 'Unreachable code!');
1675            expect(null).assertFail();
1676            done();
1677          });
1678        }).catch(() => {
1679          console.error(TAG, 'Unreachable code!');
1680          expect(null).assertFail();
1681          done();
1682        });
1683      }).catch(() => {
1684        console.error(TAG, 'Unreachable code!');
1685        expect(null).assertFail();
1686        done();
1687      });
1688    } catch (e) {
1689      console.error(TAG, 'Unreachable code!');
1690      expect(null).assertFail();
1691      done();
1692    }
1693  });
1694});