1/* 2 * Copyright (c) 2022 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 */ 15import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' 16import factory from '@ohos.data.distributedData'; 17 18const TEST_BUNDLE_NAME = 'com.example.myapplication'; 19const TEST_STORE_ID = 'storeId'; 20const STORE_KEY = 'key_test_string'; 21const STORE_VALUE = 'value-test-string'; 22var kvManager = null; 23var kvStore = null; 24 25describe('KvManagerCallbackTest', function () { 26 const config = { 27 bundleName : TEST_BUNDLE_NAME, 28 userInfo : { 29 userId : '0', 30 userType : factory.UserType.SAME_USER_ID 31 } 32 } 33 34 const options = { 35 createIfMissing : true, 36 encrypt : false, 37 backup : false, 38 autoSync : true, 39 kvStoreType : factory.KVStoreType.SINGLE_VERSION, 40 schema : '', 41 securityLevel : factory.SecurityLevel.S2, 42 } 43 44 beforeAll(async function (done) { 45 console.info('beforeAll'); 46 await factory.createKVManager(config, function (err, manager) { 47 kvManager = manager; 48 done(); 49 }); 50 console.info('beforeAll end'); 51 }) 52 53 afterAll(async function (done) { 54 console.info('afterAll'); 55 done(); 56 }) 57 58 beforeEach(async function (done) { 59 console.info('beforeEach'); 60 done(); 61 }) 62 63 afterEach(async function (done) { 64 console.info('afterEach'); 65 await kvManager.closeKVStore(TEST_BUNDLE_NAME, TEST_STORE_ID, kvStore, async function () { 66 console.info('afterEach closeKVStore success'); 67 await kvManager.deleteKVStore(TEST_BUNDLE_NAME, TEST_STORE_ID, function () { 68 console.info('afterEach deleteKVStore success'); 69 done(); 70 }); 71 }); 72 kvStore = null; 73 }) 74 75 /** 76 * @tc.name KVManagerGetKVStoreCallbackTest001 77 * @tc.desc Test Js Api KVManager.GetKVStore() testcase 001 78 * @tc.type: FUNC 79 * @tc.require: issueNumber 80 */ 81 it('KVManagerGetKVStoreCallbackTest001', 0, async function (done) { 82 console.info('KVManagerGetKVStoreCallbackTest001'); 83 try { 84 await kvManager.getKVStore(TEST_STORE_ID, options, function (err, store) { 85 console.info('KVManagerGetKVStoreCallbackTest001 getKVStore success'); 86 kvStore = store; 87 done(); 88 }); 89 } catch (e) { 90 console.error('KVManagerGetKVStoreCallbackTest001 getKVStore e ' + `, error code is ${e.code}, message is ${e.message}`); 91 expect(null).assertFail(); 92 done(); 93 } 94 }) 95 96 /** 97 * @tc.name KVManagerGetKVStoreCallbackTest002 98 * @tc.desc Test Js Api KVManager.GetKVStore() testcase 002 99 * @tc.type: FUNC 100 * @tc.require: issueNumber 101 */ 102 it('KVManagerGetKVStoreCallbackTest002', 0, async function (done) { 103 console.info('KVManagerGetKVStoreCallbackTest002'); 104 try { 105 await kvManager.getKVStore(options, function (err, store) { 106 if (err == undefined) { 107 console.info('KVManagerGetKVStoreCallbackTest002 getKVStore success'); 108 expect(null).assertFail(); 109 } else { 110 console.info('KVManagerGetKVStoreCallbackTest002 getKVStore fail'); 111 } 112 done(); 113 }); 114 } catch (e) { 115 console.error('KVManagerGetKVStoreCallbackTest002 getKVStore e ' + `, error code is ${e.code}, message is ${e.message}`); 116 done(); 117 } 118 }) 119 120 /** 121 * @tc.name KVManagerGetKVStoreCallbackTest003 122 * @tc.desc Test Js Api KVManager.GetKVStore() testcase 003 123 * @tc.type: FUNC 124 * @tc.require: issueNumber 125 */ 126 it('KVManagerGetKVStoreCallbackTest003', 0, async function (done) { 127 console.info('KVManagerGetKVStoreCallbackTest003'); 128 const optionsInfo = { 129 createIfMissing : true, 130 encrypt : false, 131 backup : false, 132 autoSync : true, 133 kvStoreType : factory.KVStoreType.DEVICE_COLLABORATION, 134 schema : '', 135 securityLevel : factory.SecurityLevel.NO_LEVEL, 136 } 137 try { 138 await kvManager.getKVStore(TEST_STORE_ID, optionsInfo, function (err, store) { 139 console.info('KVManagerGetKVStoreCallbackTest003 getKVStore success'); 140 console.info('KVManagerGetKVStoreCallbackTest003 err ' + err + ' store ' + store); 141 expect((err == undefined) && (store != null)).assertTrue(); 142 kvStore = store; 143 done(); 144 }); 145 } catch (e) { 146 console.error('KVManagerGetKVStoreCallbackTest003 getKVStore e ' + `, error code is ${e.code}, message is ${e.message}`); 147 expect(null).assertFail(); 148 done(); 149 } 150 }) 151 152 /** 153 * @tc.name KVManagerGetKVStoreCallbackTest004 154 * @tc.desc Test Js Api KVManager.GetKVStore() testcase 004 155 * @tc.type: FUNC 156 * @tc.require: issueNumber 157 */ 158 it('KVManagerGetKVStoreCallbackTest004', 0, async function (done) { 159 console.info('KVManagerGetKVStoreCallbackTest004'); 160 const optionsInfo = { 161 createIfMissing : false, 162 encrypt : false, 163 backup : false, 164 autoSync : true, 165 kvStoreType : factory.KVStoreType.DEVICE_COLLABORATION, 166 schema : '', 167 securityLevel : factory.SecurityLevel.S0, 168 } 169 try { 170 await kvManager.getKVStore(TEST_STORE_ID, optionsInfo, function (err, store) { 171 if (err == undefined) { 172 console.info('KVManagerGetKVStoreCallbackTest004 getKVStore success'); 173 expect(null).assertFail(); 174 } else { 175 console.info('KVManagerGetKVStoreCallbackTest004 getKVStore fail'); 176 } 177 done(); 178 }); 179 } catch (e) { 180 console.error('KVManagerGetKVStoreCallbackTest004 getKVStore e ' + `, error code is ${e.code}, message is ${e.message}`); 181 done(); 182 } 183 }) 184 185 /** 186 * @tc.name KVManagerGetKVStoreCallbackTest005 187 * @tc.desc Test Js Api KVManager.GetKVStore() testcase 005 188 * @tc.type: FUNC 189 * @tc.require: issueNumber 190 */ 191 it('KVManagerGetKVStoreCallbackTest005', 0, async function (done) { 192 console.info('KVManagerGetKVStoreCallbackTest005'); 193 const optionsInfo = { 194 createIfMissing : true, 195 encrypt : true, 196 backup : false, 197 autoSync : true, 198 kvStoreType : factory.KVStoreType.DEVICE_COLLABORATION, 199 schema : '', 200 securityLevel : factory.SecurityLevel.S1, 201 } 202 try { 203 await kvManager.getKVStore(TEST_STORE_ID, optionsInfo, function (err, store) { 204 console.info('KVManagerGetKVStoreCallbackTest005 getKVStore success'); 205 expect((err == undefined) && (store != null)).assertTrue(); 206 kvStore = store; 207 done(); 208 }); 209 } catch (e) { 210 console.error('KVManagerGetKVStoreCallbackTest005 getKVStore e ' + `, error code is ${e.code}, message is ${e.message}`); 211 expect(null).assertFail(); 212 done(); 213 } 214 }) 215 216 /** 217 * @tc.name KVManagerGetKVStoreCallbackTest006 218 * @tc.desc Test Js Api KVManager.GetKVStore() testcase 006 219 * @tc.type: FUNC 220 * @tc.require: issueNumber 221 */ 222 it('KVManagerGetKVStoreCallbackTest006', 0, async function (done) { 223 console.info('KVManagerGetKVStoreCallbackTest006'); 224 const optionsInfo = { 225 createIfMissing : true, 226 encrypt : false, 227 backup : false, 228 autoSync : true, 229 kvStoreType : factory.KVStoreType.DEVICE_COLLABORATION, 230 schema : '', 231 securityLevel : factory.SecurityLevel.S2, 232 } 233 try { 234 await kvManager.getKVStore(TEST_STORE_ID, optionsInfo, function (err, store) { 235 console.info('KVManagerGetKVStoreCallbackTest006 getKVStore success'); 236 expect((err == undefined) && (store != null)).assertTrue(); 237 kvStore = store; 238 done(); 239 }); 240 } catch (e) { 241 console.error('KVManagerGetKVStoreCallbackTest006 getKVStore e ' + `, error code is ${e.code}, message is ${e.message}`); 242 expect(null).assertFail(); 243 done(); 244 } 245 }) 246 247 /** 248 * @tc.name KVManagerGetKVStoreCallbackTest007 249 * @tc.desc Test Js Api KVManager.GetKVStore() testcase 007 250 * @tc.type: FUNC 251 * @tc.require: issueNumber 252 */ 253 it('KVManagerGetKVStoreCallbackTest007', 0, async function (done) { 254 console.info('KVManagerGetKVStoreCallbackTest007'); 255 const optionsInfo = { 256 createIfMissing : true, 257 encrypt : false, 258 backup : true, 259 autoSync : true, 260 kvStoreType : factory.KVStoreType.DEVICE_COLLABORATION, 261 schema : '', 262 securityLevel : factory.SecurityLevel.S3, 263 } 264 try { 265 await kvManager.getKVStore(TEST_STORE_ID, optionsInfo, function (err, store) { 266 console.info('KVManagerGetKVStoreCallbackTest007 getKVStore success'); 267 expect((err == undefined) && (store != null)).assertTrue(); 268 kvStore = store; 269 done(); 270 }); 271 } catch (e) { 272 console.error('KVManagerGetKVStoreCallbackTest007 getKVStore e ' + `, error code is ${e.code}, message is ${e.message}`); 273 expect(null).assertFail(); 274 done(); 275 } 276 }) 277 278 /** 279 * @tc.name KVManagerGetKVStoreCallbackTest008 280 * @tc.desc Test Js Api KVManager.GetKVStore() testcase 008 281 * @tc.type: FUNC 282 * @tc.require: issueNumber 283 */ 284 it('KVManagerGetKVStoreCallbackTest008', 0, async function (done) { 285 console.info('KVManagerGetKVStoreCallbackTest008'); 286 const optionsInfo = { 287 createIfMissing : true, 288 encrypt : false, 289 backup : false, 290 autoSync : true, 291 kvStoreType : factory.KVStoreType.DEVICE_COLLABORATION, 292 schema : '', 293 securityLevel : factory.SecurityLevel.S4, 294 } 295 try { 296 await kvManager.getKVStore(TEST_STORE_ID, optionsInfo, function (err, store) { 297 console.info('KVManagerGetKVStoreCallbackTest008 getKVStore success'); 298 expect((err == undefined) && (store != null)).assertTrue(); 299 kvStore = store; 300 done(); 301 }); 302 } catch (e) { 303 console.error('KVManagerGetKVStoreCallbackTest008 getKVStore e ' + `, error code is ${e.code}, message is ${e.message}`); 304 expect(null).assertFail(); 305 done(); 306 } 307 }) 308 309 /** 310 * @tc.name KVManagerGetKVStoreCallbackTest009 311 * @tc.desc Test Js Api KVManager.GetKVStore() testcase 009 312 * @tc.type: FUNC 313 * @tc.require: issueNumber 314 */ 315 it('KVManagerGetKVStoreCallbackTest009', 0, async function (done) { 316 console.info('KVManagerGetKVStoreCallbackTest009'); 317 const optionsInfo = { 318 createIfMissing : true, 319 encrypt : false, 320 backup : false, 321 autoSync : true, 322 kvStoreType : factory.KVStoreType.SINGLE_VERSION, 323 schema : '', 324 securityLevel : factory.SecurityLevel.NO_LEVEL, 325 } 326 try { 327 await kvManager.getKVStore(TEST_STORE_ID, optionsInfo, function (err, store) { 328 console.info('KVManagerGetKVStoreCallbackTest009 getKVStore success'); 329 expect((err == undefined) && (store != null)).assertTrue(); 330 kvStore = store; 331 done(); 332 }); 333 } catch (e) { 334 console.error('KVManagerGetKVStoreCallbackTest009 getKVStore e ' + `, error code is ${e.code}, message is ${e.message}`); 335 expect(null).assertFail(); 336 done(); 337 } 338 }) 339 340 /** 341 * @tc.name KVManagerGetKVStoreCallbackTest010 342 * @tc.desc Test Js Api KVManager.GetKVStore() testcase 010 343 * @tc.type: FUNC 344 * @tc.require: issueNumber 345 */ 346 it('KVManagerGetKVStoreCallbackTest010', 0, async function (done) { 347 console.info('KVManagerGetKVStoreCallbackTest010'); 348 const optionsInfo = { 349 createIfMissing : true, 350 encrypt : false, 351 backup : false, 352 autoSync : false, 353 kvStoreType : factory.KVStoreType.SINGLE_VERSION, 354 schema : '', 355 securityLevel : factory.SecurityLevel.S0, 356 } 357 try { 358 await kvManager.getKVStore(TEST_STORE_ID, optionsInfo, function (err, store) { 359 console.info('KVManagerGetKVStoreCallbackTest010 getKVStore success'); 360 expect((err == undefined) && (store != null)).assertTrue(); 361 kvStore = store; 362 done(); 363 }); 364 } catch (e) { 365 console.error('KVManagerGetKVStoreCallbackTest010 getKVStore e ' + `, error code is ${e.code}, message is ${e.message}`); 366 expect(null).assertFail(); 367 done(); 368 } 369 }) 370 371 /** 372 * @tc.name KVManagerGetKVStoreCallbackTest011 373 * @tc.desc Test Js Api KVManager.GetKVStore() testcase 011 374 * @tc.type: FUNC 375 * @tc.require: issueNumber 376 */ 377 it('KVManagerGetKVStoreCallbackTest011', 0, async function (done) { 378 console.info('KVManagerGetKVStoreCallbackTest011'); 379 const optionsInfo = { 380 createIfMissing : true, 381 encrypt : false, 382 backup : false, 383 autoSync : true, 384 kvStoreType : factory.KVStoreType.SINGLE_VERSION, 385 schema : '', 386 securityLevel : factory.SecurityLevel.S1, 387 } 388 try { 389 await kvManager.getKVStore(TEST_STORE_ID, optionsInfo, function (err, store) { 390 console.info('KVManagerGetKVStoreCallbackTest011 getKVStore success'); 391 expect((err == undefined) && (store != null)).assertTrue(); 392 kvStore = store; 393 done(); 394 }); 395 } catch (e) { 396 console.error('KVManagerGetKVStoreCallbackTest011 getKVStore e ' + `, error code is ${e.code}, message is ${e.message}`); 397 expect(null).assertFail(); 398 done(); 399 } 400 }) 401 402 /** 403 * @tc.name KVManagerGetKVStoreCallbackTest012 404 * @tc.desc Test Js Api KVManager.GetKVStore() testcase 012 405 * @tc.type: FUNC 406 * @tc.require: issueNumber 407 */ 408 it('KVManagerGetKVStoreCallbackTest012', 0, async function (done) { 409 console.info('KVManagerGetKVStoreCallbackTest012'); 410 const optionsInfo = { 411 createIfMissing : true, 412 encrypt : false, 413 backup : false, 414 autoSync : true, 415 kvStoreType : factory.KVStoreType.SINGLE_VERSION, 416 schema : '', 417 securityLevel : factory.SecurityLevel.S2, 418 } 419 try { 420 await kvManager.getKVStore(TEST_STORE_ID, optionsInfo, function (err, store) { 421 console.info('KVManagerGetKVStoreCallbackTest012 getKVStore success'); 422 expect((err == undefined) && (store != null)).assertTrue(); 423 kvStore = store; 424 done(); 425 }); 426 } catch (e) { 427 console.error('KVManagerGetKVStoreCallbackTest012 getKVStore e ' + `, error code is ${e.code}, message is ${e.message}`); 428 expect(null).assertFail(); 429 done(); 430 } 431 }) 432 433 /** 434 * @tc.name KVManagerGetKVStoreCallbackTest013 435 * @tc.desc Test Js Api KVManager.GetKVStore() testcase 013 436 * @tc.type: FUNC 437 * @tc.require: issueNumber 438 */ 439 it('KVManagerGetKVStoreCallbackTest013', 0, async function (done) { 440 console.info('KVManagerGetKVStoreCallbackTest013'); 441 const optionsInfo = { 442 createIfMissing : true, 443 encrypt : false, 444 backup : false, 445 autoSync : true, 446 kvStoreType : factory.KVStoreType.SINGLE_VERSION, 447 schema : '', 448 securityLevel : factory.SecurityLevel.S3, 449 } 450 try { 451 await kvManager.getKVStore(TEST_STORE_ID, optionsInfo, function (err, store) { 452 if (err == undefined) { 453 console.info('KVManagerGetKVStoreCallbackTest013 getKVStore success'); 454 expect((err == undefined) && (store != null)).assertTrue(); 455 } else { 456 console.info('KVManagerGetKVStoreCallbackTest013 getKVStore fail'); 457 expect(null).assertFail(); 458 } 459 done(); 460 }); 461 } catch (e) { 462 console.error('KVManagerGetKVStoreCallbackTest013 getKVStore e ' + `, error code is ${e.code}, message is ${e.message}`); 463 done(); 464 } 465 }) 466 467 /** 468 * @tc.name KVManagerGetKVStoreCallbackTest014 469 * @tc.desc Test Js Api KVManager.GetKVStore() testcase 014 470 * @tc.type: FUNC 471 * @tc.require: issueNumber 472 */ 473 it('KVManagerGetKVStoreCallbackTest014', 0, async function (done) { 474 console.info('KVManagerGetKVStoreCallbackTest014'); 475 const optionsInfo = { 476 createIfMissing : true, 477 encrypt : false, 478 backup : false, 479 autoSync : true, 480 kvStoreType : factory.KVStoreType.SINGLE_VERSION, 481 schema : '', 482 securityLevel : factory.SecurityLevel.S4, 483 } 484 try { 485 await kvManager.getKVStore(TEST_STORE_ID, optionsInfo, function (err, store) { 486 console.info('KVManagerGetKVStoreCallbackTest014 getKVStore success'); 487 expect((err == undefined) && (store != null)).assertTrue(); 488 kvStore = store; 489 done(); 490 }); 491 } catch (e) { 492 console.error('KVManagerGetKVStoreCallbackTest014 getKVStore e ' + `, error code is ${e.code}, message is ${e.message}`); 493 expect(null).assertFail(); 494 done(); 495 } 496 }) 497 498 /** 499 * @tc.name KVManagerGetKVStoreCallbackTest015 500 * @tc.desc Test Js Api KVManager.GetKVStore() testcase 015 501 * @tc.type: FUNC 502 * @tc.require: issueNumber 503 */ 504 it('KVManagerGetKVStoreCallbackTest015', 0, async function (done) { 505 console.info('KVManagerGetKVStoreCallbackTest015'); 506 const optionsInfo = { 507 createIfMissing : true, 508 encrypt : false, 509 backup : false, 510 autoSync : true, 511 kvStoreType : factory.KVStoreType.MULTI_VERSION, 512 schema : '', 513 securityLevel : factory.SecurityLevel.NO_LEVEL, 514 } 515 try { 516 await kvManager.getKVStore(TEST_STORE_ID, optionsInfo, function (err, store) { 517 console.info('KVManagerGetKVStoreCallbackTest015 getKVStore success'); 518 expect(true).assertTrue(); 519 done(); 520 }); 521 } catch (e) { 522 console.error('KVManagerGetKVStoreCallbackTest015 getKVStore e ' + `, error code is ${e.code}, message is ${e.message}`); 523 expect(null).assertFail(); 524 done(); 525 } 526 }) 527 528 /** 529 * @tc.name KVManagerGetKVStoreCallbackTest016 530 * @tc.desc Test Js Api KVManager.GetKVStore() testcase 016 531 * @tc.type: FUNC 532 * @tc.require: issueNumber 533 */ 534 it('KVManagerGetKVStoreCallbackTest016', 0, async function (done) { 535 console.info('KVManagerGetKVStoreCallbackTest016'); 536 const optionsInfo = { 537 createIfMissing : true, 538 encrypt : false, 539 backup : false, 540 autoSync : true, 541 kvStoreType : factory.KVStoreType.MULTI_VERSION, 542 schema : '', 543 securityLevel : factory.SecurityLevel.S0, 544 } 545 try { 546 await kvManager.getKVStore(TEST_STORE_ID, optionsInfo, function (err, store) { 547 console.info('KVManagerGetKVStoreCallbackTest016 getKVStore success'); 548 expect(true).assertTrue(); 549 done(); 550 }); 551 } catch (e) { 552 console.error('KVManagerGetKVStoreCallbackTest016 getKVStore e ' + `, error code is ${e.code}, message is ${e.message}`); 553 expect(null).assertFail(); 554 done(); 555 } 556 }) 557 558 /** 559 * @tc.name KVManagerGetKVStoreCallbackTest017 560 * @tc.desc Test Js Api KVManager.GetKVStore() testcase 017 561 * @tc.type: FUNC 562 * @tc.require: issueNumber 563 */ 564 it('KVManagerGetKVStoreCallbackTest017', 0, async function (done) { 565 console.info('KVManagerGetKVStoreCallbackTest017'); 566 const optionsInfo = { 567 createIfMissing : true, 568 encrypt : false, 569 backup : false, 570 autoSync : true, 571 kvStoreType : factory.KVStoreType.MULTI_VERSION, 572 schema : '', 573 securityLevel : factory.SecurityLevel.S1, 574 } 575 try { 576 await kvManager.getKVStore(TEST_STORE_ID, optionsInfo, function (err, store) { 577 console.info('KVManagerGetKVStoreCallbackTest017 getKVStore success'); 578 expect(true).assertTrue(); 579 done(); 580 }); 581 } catch (e) { 582 console.error('KVManagerGetKVStoreCallbackTest017 getKVStore e ' + `, error code is ${e.code}, message is ${e.message}`); 583 expect(null).assertFail(); 584 done(); 585 } 586 }) 587 588 /** 589 * @tc.name KVManagerGetKVStoreCallbackTest018 590 * @tc.desc Test Js Api KVManager.GetKVStore() testcase 018 591 * @tc.type: FUNC 592 * @tc.require: issueNumber 593 */ 594 it('KVManagerGetKVStoreCallbackTest018', 0, async function (done) { 595 console.info('KVManagerGetKVStoreCallbackTest018'); 596 const optionsInfo = { 597 createIfMissing : true, 598 encrypt : false, 599 backup : false, 600 autoSync : true, 601 kvStoreType : factory.KVStoreType.MULTI_VERSION, 602 schema : '', 603 securityLevel : factory.SecurityLevel.S2, 604 } 605 try { 606 await kvManager.getKVStore(TEST_STORE_ID, optionsInfo, function (err, store) { 607 console.info('KVManagerGetKVStoreCallbackTest018 getKVStore success'); 608 expect(true).assertTrue(); 609 done(); 610 }); 611 } catch (e) { 612 console.error('KVManagerGetKVStoreCallbackTest018 getKVStore e ' + `, error code is ${e.code}, message is ${e.message}`); 613 expect(null).assertFail(); 614 done(); 615 } 616 }) 617 618 /** 619 * @tc.name KVManagerGetKVStoreCallbackTest019 620 * @tc.desc Test Js Api KVManager.GetKVStore() testcase 019 621 * @tc.type: FUNC 622 * @tc.require: issueNumber 623 */ 624 it('KVManagerGetKVStoreCallbackTest019', 0, async function (done) { 625 console.info('KVManagerGetKVStoreCallbackTest019'); 626 const optionsInfo = { 627 createIfMissing : true, 628 encrypt : false, 629 backup : false, 630 autoSync : true, 631 kvStoreType : factory.KVStoreType.MULTI_VERSION, 632 schema : '', 633 securityLevel : factory.SecurityLevel.S3, 634 } 635 try { 636 await kvManager.getKVStore(TEST_STORE_ID, optionsInfo, function (err, store) { 637 console.info('KVManagerGetKVStoreCallbackTest019 getKVStore success'); 638 expect(true).assertTrue(); 639 done(); 640 }); 641 } catch (e) { 642 console.error('KVManagerGetKVStoreCallbackTest019 getKVStore e ' + `, error code is ${e.code}, message is ${e.message}`); 643 expect(null).assertFail(); 644 done(); 645 } 646 }) 647 648 /** 649 * @tc.name KVManagerGetKVStoreCallbackTest020 650 * @tc.desc Test Js Api KVManager.GetKVStore() testcase 020 651 * @tc.type: FUNC 652 * @tc.require: issueNumber 653 */ 654 it('KVManagerGetKVStoreCallbackTest020', 0, async function (done) { 655 console.info('KVManagerGetKVStoreCallbackTest020'); 656 const optionsInfo = { 657 createIfMissing : true, 658 encrypt : false, 659 backup : false, 660 autoSync : true, 661 kvStoreType : factory.KVStoreType.MULTI_VERSION, 662 schema : '', 663 securityLevel : factory.SecurityLevel.S4, 664 } 665 try { 666 await kvManager.getKVStore(TEST_STORE_ID, optionsInfo, function (err, store) { 667 console.info('KVManagerGetKVStoreCallbackTest020 getKVStore success'); 668 expect(true).assertTrue(); 669 done(); 670 }); 671 } catch (e) { 672 console.error('KVManagerGetKVStoreCallbackTest019 getKVStore e ' + `, error code is ${e.code}, message is ${e.message}`); 673 expect(null).assertFail(); 674 done(); 675 } 676 }) 677 678 /** 679 * @tc.name KVManagerCloseKVStoreCallbackTest001 680 * @tc.desc Test Js Api KVManager.CloseKVStore() testcase 001 681 * @tc.type: FUNC 682 * @tc.require: issueNumber 683 */ 684 it('KVManagerCloseKVStoreCallbackTest001', 0, async function (done) { 685 console.info('KVManagerCloseKVStoreCallbackTest001'); 686 try { 687 await kvManager.getKVStore(TEST_STORE_ID, options, async function (err, store) { 688 console.info('KVManagerCloseKVStoreCallbackTest001 getKVStore success'); 689 kvStore = store; 690 await kvManager.closeKVStore(TEST_BUNDLE_NAME, TEST_STORE_ID, kvStore, function (err, data) { 691 console.info('KVManagerCloseKVStoreCallbackTest001 closeKVStore success'); 692 expect((err == undefined) && (data == undefined)).assertTrue(); 693 done(); 694 }); 695 }); 696 } catch (e) { 697 console.error('KVManagerCloseKVStoreCallbackTest001 e ' + `, error code is ${e.code}, message is ${e.message}`); 698 expect(null).assertFail(); 699 done(); 700 } 701 }) 702 703 /** 704 * @tc.name KVManagerCloseKVStoreCallbackTest002 705 * @tc.desc Test Js Api KVManager.CloseKVStore() testcase 002 706 * @tc.type: FUNC 707 * @tc.require: issueNumber 708 */ 709 it('KVManagerCloseKVStoreCallbackTest002', 0, async function (done) { 710 console.info('KVManagerCloseKVStoreCallbackTest002'); 711 try { 712 await kvManager.getKVStore(TEST_STORE_ID, options, async function (err, store) { 713 console.info('KVManagerCloseKVStoreCallbackTest002 getKVStore success'); 714 kvStore = store; 715 try { 716 await kvManager.closeKVStore(TEST_BUNDLE_NAME, function (err, data) { 717 if (err == undefined) { 718 console.info('KVManagerCloseKVStoreCallbackTest002 closeKVStore success'); 719 expect(null).assertFail(); 720 } else { 721 console.info('KVManagerCloseKVStoreCallbackTest002 closeKVStore fail'); 722 } 723 done(); 724 }); 725 } catch (e) { 726 console.error('KVManagerCloseKVStoreCallbackTest002 closeKVStore e ' + `, error code is ${e.code}, message is ${e.message}`); 727 done(); 728 } 729 }); 730 } catch (ee) { 731 console.error('KVManagerCloseKVStoreCallbackTest002 getKVStore ee ' + `, error code is ${ee.code}, message is ${ee.message}`); 732 expect(null).assertFail(); 733 done(); 734 } 735 }) 736 737 /** 738 * @tc.name KVManagerCloseKVStoreCallbackTest003 739 * @tc.desc Test Js Api KVManager.CloseKVStore() testcase 003 740 * @tc.type: FUNC 741 * @tc.require: issueNumber 742 */ 743 it('KVManagerCloseKVStoreCallbackTest003', 0, async function (done) { 744 console.info('KVManagerCloseKVStoreCallbackTest003'); 745 try { 746 await kvManager.getKVStore(TEST_STORE_ID, options, async function (err, store) { 747 console.info('KVManagerCloseKVStoreCallbackTest003 getKVStore success'); 748 kvStore = store; 749 try { 750 await kvManager.closeKVStore(TEST_BUNDLE_NAME, TEST_STORE_ID, function (err, data) { 751 if (err == undefined) { 752 console.info('KVManagerCloseKVStoreCallbackTest003 closeKVStore success'); 753 expect(null).assertFail(); 754 } else { 755 console.info('KVManagerCloseKVStoreCallbackTest003 closeKVStore fail'); 756 } 757 done(); 758 }); 759 } catch (e) { 760 console.error('KVManagerCloseKVStoreCallbackTest003 closeKVStore e ' + `, error code is ${e.code}, message is ${e.message}`); 761 done(); 762 } 763 }); 764 } catch (ee) { 765 console.error('KVManagerCloseKVStoreCallbackTest003 getKVStore ee ' + `, error code is ${ee.code}, message is ${ee.message}`); 766 expect(null).assertFail(); 767 done(); 768 } 769 }) 770 771 /** 772 * @tc.name KVManagerCloseKVStoreCallbackTest004 773 * @tc.desc Test Js Api KVManager.CloseKVStore() testcase 004 774 * @tc.type: FUNC 775 * @tc.require: issueNumber 776 */ 777 it('KVManagerCloseKVStoreCallbackTest004', 0, async function (done) { 778 console.info('KVManagerCloseKVStoreCallbackTest004'); 779 try { 780 await kvManager.getKVStore(TEST_STORE_ID, options, async function (err, store) { 781 console.info('KVManagerCloseKVStoreCallbackTest004 getKVStore success'); 782 kvStore = store; 783 await kvManager.closeKVStore(TEST_BUNDLE_NAME, TEST_STORE_ID, kvStore); 784 }); 785 console.info('KVManagerCloseKVStoreCallbackTest004 closeKVStore redo.'); 786 await kvManager.closeKVStore(TEST_BUNDLE_NAME, TEST_STORE_ID, kvStore, function (err, data) { 787 console.error('KVManagerCloseKVStoreCallbackTest004 closeKVStore twice ' + `, error code is ${err.code}, message is ${err.message}`); 788 if (err == undefined) { 789 expect(null).assertFail(); 790 } 791 }); 792 } catch (e) { 793 console.error('KVManagerCloseKVStoreCallbackTest004 closeKVStore twice e ' + `, error code is ${e.code}, message is ${e.message}`); 794 expect(null).assertFail(); 795 } 796 done(); 797 }) 798 799 /** 800 * @tc.name KVManagerDeleteKVStoreCallbackTest001 801 * @tc.desc Test Js Api KVManager.DeleteKVStore() testcase 001 802 * @tc.type: FUNC 803 * @tc.require: issueNumber 804 */ 805 it('KVManagerDeleteKVStoreCallbackTest001', 0, async function (done) { 806 console.info('KVManagerDeleteKVStoreCallbackTest001'); 807 try { 808 await kvManager.getKVStore(TEST_STORE_ID, options, async function (err, store) { 809 console.info('KVManagerDeleteKVStoreCallbackTest001 getKVStore success'); 810 kvStore = store; 811 await kvManager.deleteKVStore(TEST_BUNDLE_NAME, TEST_STORE_ID, function (err, data) { 812 console.info('KVManagerDeleteKVStoreCallbackTest001 deleteKVStore success'); 813 expect((err == undefined) && (data == undefined)).assertTrue(); 814 done(); 815 }); 816 }); 817 } catch (e) { 818 console.error('KVManagerDeleteKVStoreCallbackTest001 e ' + `, error code is ${e.code}, message is ${e.message}`); 819 expect(null).assertFail(); 820 done(); 821 } 822 }) 823 824 /** 825 * @tc.name KVManagerDeleteKVStoreCallbackTest002 826 * @tc.desc Test Js Api KVManager.DeleteKVStore() testcase 002 827 * @tc.type: FUNC 828 * @tc.require: issueNumber 829 */ 830 it('KVManagerDeleteKVStoreCallbackTest002', 0, async function (done) { 831 console.info('KVManagerDeleteKVStoreCallbackTest002'); 832 try { 833 await kvManager.getKVStore(TEST_STORE_ID, options, async function (err, store) { 834 console.info('KVManagerDeleteKVStoreCallbackTest002 getKVStore success'); 835 kvStore = store; 836 try { 837 await kvManager.deleteKVStore(TEST_BUNDLE_NAME, function (err, data) { 838 if (err == undefined) { 839 console.info('KVManagerDeleteKVStoreCallbackTest002 deleteKVStore success'); 840 expect(null).assertFail(); 841 } else { 842 console.info('KVManagerDeleteKVStoreCallbackTest002 deleteKVStore fail'); 843 } 844 done(); 845 }); 846 } catch (e) { 847 console.error('KVManagerDeleteKVStoreCallbackTest002 deleteKVStore e ' + `, error code is ${e.code}, message is ${e.message}`); 848 done(); 849 } 850 }); 851 } catch (ee) { 852 console.error('KVManagerDeleteKVStoreCallbackTest002 getKVStore ee ' + `, error code is ${ee.code}, message is ${ee.message}`); 853 expect(null).assertFail(); 854 done(); 855 } 856 }) 857 858 /** 859 * @tc.name KVManagerDeleteKVStoreCallbackTest003 860 * @tc.desc Test Js Api KVManager.DeleteKVStore() testcase 003 861 * @tc.type: FUNC 862 * @tc.require: issueNumber 863 */ 864 it('KVManagerDeleteKVStoreCallbackTest003', 0, async function (done) { 865 console.info('KVManagerDeleteKVStoreCallbackTest003'); 866 try { 867 await kvManager.deleteKVStore(TEST_BUNDLE_NAME, TEST_STORE_ID, function (err, data) { 868 if (err == undefined){ 869 console.info('KVManagerDeleteKVStoreCallbackTest003 deleteKVStore success'); 870 expect(null).assertFail(); 871 } else { 872 console.info('KVManagerDeleteKVStoreCallbackTest003 deleteKVStore fail'); 873 } 874 done(); 875 }); 876 } catch (e) { 877 console.error('KVManagerDeleteKVStoreCallbackTest003 e ' + `, error code is ${e.code}, message is ${e.message}`); 878 done(); 879 } 880 }) 881 882 /** 883 * @tc.name KVManagerGetAllKVStoreIdCallbackTest001 884 * @tc.desc Test Js Api KVManager.GetAllKVStoreId() testcase 001 885 * @tc.type: FUNC 886 * @tc.require: issueNumber 887 */ 888 it('KVManagerGetAllKVStoreIdCallbackTest001', 0, async function (done) { 889 console.info('KVManagerGetAllKVStoreIdCallbackTest001'); 890 try { 891 await kvManager.getAllKVStoreId(TEST_BUNDLE_NAME, function (err, data) { 892 console.info('KVManagerGetAllKVStoreIdCallbackTest001 getAllKVStoreId success'); 893 console.info('KVManagerGetAllKVStoreIdCallbackTest001 size = ' + data.length); 894 expect(0).assertEqual(data.length); 895 done(); 896 }); 897 } catch (e) { 898 console.error('KVManagerGetAllKVStoreIdCallbackTest001 e ' + `, error code is ${e.code}, message is ${e.message}`); 899 expect(null).assertFail(); 900 done(); 901 } 902 }) 903 904 /** 905 * @tc.name KVManagerGetAllKVStoreIdCallbackTest002 906 * @tc.desc Test Js Api KVManager.GetAllKVStoreId() testcase 002 907 * @tc.type: FUNC 908 * @tc.require: issueNumber 909 */ 910 it('KVManagerGetAllKVStoreIdCallbackTest002', 0, async function (done) { 911 console.info('KVManagerGetAllKVStoreIdCallbackTest002'); 912 try { 913 await kvManager.getKVStore(TEST_STORE_ID, options, async function (err, store) { 914 console.info('KVManagerGetAllKVStoreIdCallbackTest002 getKVStore success'); 915 kvStore = store; 916 try { 917 await kvManager.getAllKVStoreId(TEST_BUNDLE_NAME, function (err, data) { 918 console.info('testKVManagerGetAllKVStoreId002 getKVStore success'); 919 console.info('testKVManagerGetAllKVStoreId002 getkvmanager success: ' + kvManager) 920 console.info('testKVManagerGetAllKVStoreId002 get kvstore: ' + store) 921 console.info('KVManagerGetAllKVStoreIdCallbackTest002 getAllKVStoreId success'); 922 console.info('KVManagerGetAllKVStoreIdCallbackTest002 size = ' + data.length); 923 expect(1).assertEqual(data.length); 924 console.info('KVManagerGetAllKVStoreIdCallbackTest002 data[0] = ' + data[0]); 925 expect(TEST_STORE_ID).assertEqual(data[0]); 926 done(); 927 }); 928 } catch (e) { 929 console.error('KVManagerGetAllKVStoreIdCallbackTest002 getAllKVStoreId e ' + `, error code is ${e.code}, message is ${e.message}`); 930 expect(null).assertFail(); 931 done(); 932 } 933 }); 934 } catch (ee) { 935 console.error('KVManagerGetAllKVStoreIdCallbackTest002 getKVStore ee ' + `, error code is ${ee.code}, message is ${ee.message}`); 936 expect(null).assertFail(); 937 done(); 938 } 939 }) 940 941 /** 942 * @tc.name KvStorePutTest001 943 * @tc.desc Test Js Api KVManager.Put() testcase 001 944 * @tc.type: FUNC 945 * @tc.require: issueNumber 946 */ 947 it('KvStorePutTest001', 0, async function (done) { 948 console.info('KvStorePutTest001'); 949 try { 950 await kvManager.getKVStore(TEST_STORE_ID, options, async function (err, store) { 951 console.info('KvStorePutTest001 getKVStore success'); 952 kvStore = store; 953 await kvStore.put(STORE_KEY, STORE_VALUE, function (err, data) { 954 if (err != undefined){ 955 console.info('KvStorePutTest001 put callback fail'); 956 expect(null).assertFail(); 957 } else { 958 console.info('KvStorePutTest001 put callback success'); 959 expect(true).assertTrue(); 960 } 961 done(); 962 }); 963 }); 964 965 } catch (e) { 966 console.error('KvStorePutTest001 callback e ' + `, error code is ${e.code}, message is ${e.message}`); 967 expect(null).assertFail(); 968 done(); 969 } 970 }) 971}) 972