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