diff --git a/distributeddatamgr/distributedKVStoretest/distributedKVStorejstest/hap/src/main/js/test/FieldNodeJsTest.js b/distributeddatamgr/distributedKVStoretest/distributedKVStorejstest/hap/src/main/js/test/FieldNodeJsTest.js index 3ca426cf3f5bd4f26d6eac5459a12d472e827ca5..c1a3da7d192f324523ee7ed9ff7718fc7105cd23 100644 --- a/distributeddatamgr/distributedKVStoretest/distributedKVStorejstest/hap/src/main/js/test/FieldNodeJsTest.js +++ b/distributeddatamgr/distributedKVStoretest/distributedKVStorejstest/hap/src/main/js/test/FieldNodeJsTest.js @@ -30,18 +30,22 @@ describe('FieldNodeTest', function() { let child1 = new ddm.FieldNode("child1"); let child2 = new ddm.FieldNode("child2"); let child3 = new ddm.FieldNode("child3"); - node.appendChild(child1); - node.appendChild(child2); - node.appendChild(child3); + let res1 = node.appendChild(child1); + let res2 = node.appendChild(child2); + let res3 = node.appendChild(child3); + expect(res1).assertTrue(); + expect(res2).assertTrue(); + expect(res3).assertTrue(); child1 = null; child2 = null; child3 = null; node = null; + done(); } catch (e) { - console.info("SUB_DDM_DKV_FIELDNODE_APPENDCHILD_0100 " + e); + console.info("SUB_DDM_DKV_FIELDNODE_APPENDCHILD_0100 e=" + e); expect(null).assertFail(); + done(); } - done(); }) /** @@ -54,14 +58,16 @@ describe('FieldNodeTest', function() { try { let node = new ddm.FieldNode("root"); let child = new ddm.FieldNode("child"); - node.appendChild(child); + let res1 = node.appendChild(child); + expect(res1).assertTrue(); child = null; node = null; + done(); } catch (e) { - console.info("SUB_DDM_DKV_FIELDNODE_APPENDCHILD_0200 " + e); + console.info("SUB_DDM_DKV_FIELDNODE_APPENDCHILD_0200 e=" + e); expect(null).assertFail(); + done(); } - done(); }) /** @@ -76,10 +82,11 @@ describe('FieldNodeTest', function() { let child = new ddm.FieldNode(); node.appendChild(child); expect(null).assertFail(); + done(); } catch (e) { console.info("SUB_DDM_DKV_FIELDNODE_APPENDCHILD_0300 is ok :" + e); + done(); } - done(); }) /** @@ -92,11 +99,13 @@ describe('FieldNodeTest', function() { try { let node = new ddm.FieldNode("root"); let child = new ddm.FieldNode("child"); - node.appendChild(child); + let res1 = node.appendChild(child); + expect(res1).assertTrue(); + done(); } catch (e) { expect(null).assertFail(); + done(); } - done(); }) /** @@ -109,11 +118,13 @@ describe('FieldNodeTest', function() { try { let node = new ddm.FieldNode("root"); let child = new ddm.FieldNode("child"); - node.appendChild(child); + let res1 = node.appendChild(child); + expect(res1).assertTrue(); + done(); } catch (e) { expect(null).assertFail(); + done(); } - done(); }) /** @@ -128,10 +139,11 @@ describe('FieldNodeTest', function() { let child = new ddm.FieldNode(); node.appendChild(child); expect(null).assertFail(); + done(); } catch (e) { console.info("SUB_DDM_DKV_FIELDNODE_TOJSON_0300 is ok : " + e); + done(); } - done(); }) /** @@ -145,29 +157,33 @@ describe('FieldNodeTest', function() { let node = new ddm.FieldNode('first'); node.default = 'first name'; console.info('defaultValue = ' + node.default); - expect(node.default === 'first name').assertTrue() + expect(node.default === 'first name').assertTrue(); + done(); } catch (e) { console.info("SUB_DDM_DKV_FIELDNODE_DEFAULT_0100 fail on exception: " + e); + expect(null).assertFail(); + done(); } - done(); }) /** - * @tc.name SUB_DDM_DKV_FIELDNODE_DEFAULT_0100 + * @tc.name SUB_DDM_DKV_FIELDNODE_NULLABLE_0100 * @tc.desc Test Js Api FieldNode.nullable testcase 001 * @tc.type: FUNC * @tc.number: SUB_DDM_DKV_FIELDNODE_NULLABLE_0100 */ - it('SUB_DDM_DKV_FIELDNODE_DEFAULT_0100', 0, async function(done) { + it('SUB_DDM_DKV_FIELDNODE_NULLABLE_0100', 0, async function(done) { try { let node = new ddm.FieldNode('first'); node.nullable = false; console.info('nullable = ' + node.nullable); - expect(node.nullable === false).assertTrue() + expect(node.nullable === false).assertTrue(); + done(); } catch (e) { - console.info("SUB_DDM_DKV_FIELDNODE_DEFAULT_0100 fail on exception: " + e); + console.info("SUB_DDM_DKV_FIELDNODE_NULLABLE_0100 fail on exception: " + e); + expect(null).assertFail(); + done(); } - done(); }) /** @@ -182,11 +198,12 @@ describe('FieldNodeTest', function() { node.type = ddm.ValueType.STRING; console.info('SUB_DDM_DKV_FIELDNODE_TYPE_0100 type = ' + node.type); expect(node.type === ddm.ValueType.STRING).assertTrue(); + done(); } catch (e) { console.info("SUB_DDM_DKV_FIELDNODE_TYPE_0100 fail on exception: " + e); expect(null).assertFail(); + done(); } - done(); }) /** @@ -201,11 +218,12 @@ describe('FieldNodeTest', function() { node.type = ddm.ValueType.INTEGER; console.info('SUB_DDM_DKV_FIELDNODE_TYPE_0200 type = ' + node.type); expect(node.type === ddm.ValueType.INTEGER).assertTrue(); + done(); } catch (e) { console.info("SUB_DDM_DKV_FIELDNODE_TYPE_0200 fail on exception: " + e); expect(null).assertFail(); + done(); } - done(); }) /** @@ -220,11 +238,12 @@ describe('FieldNodeTest', function() { node.type = ddm.ValueType.FLOAT; console.info('SUB_DDM_DKV_FIELDNODE_TYPE_0300 type = ' + node.type); expect(node.type === ddm.ValueType.FLOAT).assertTrue(); + done(); } catch (e) { console.info("SUB_DDM_DKV_FIELDNODE_TYPE_0300 fail on exception: " + e); expect(null).assertFail(); + done(); } - done(); }) /** @@ -239,11 +258,12 @@ describe('FieldNodeTest', function() { node.type = ddm.ValueType.BYTE_ARRAY; console.info('SUB_DDM_DKV_FIELDNODE_TYPE_0400 type = ' + node.type); expect(node.type === ddm.ValueType.BYTE_ARRAY).assertTrue(); + done(); } catch (e) { console.info("SUB_DDM_DKV_FIELDNODE_TYPE_0400 fail on exception: " + e); expect(null).assertFail(); + done(); } - done(); }) /** @@ -258,11 +278,12 @@ describe('FieldNodeTest', function() { node.type = ddm.ValueType.BOOLEAN; console.info('SUB_DDM_DKV_FIELDNODE_TYPE_0500 type = ' + node.type); expect(node.type === ddm.ValueType.BOOLEAN).assertTrue(); + done(); } catch (e) { console.info("SUB_DDM_DKV_FIELDNODE_TYPE_0500 fail on exception: " + e); expect(null).assertFail(); + done(); } - done(); }) /** @@ -277,11 +298,12 @@ describe('FieldNodeTest', function() { node.type = ddm.ValueType.DOUBLE; console.info('SUB_DDM_DKV_FIELDNODE_TYPE_0600 type = ' + node.type); expect(node.type === ddm.ValueType.DOUBLE).assertTrue(); + done(); } catch (e) { console.info("SUB_DDM_DKV_FIELDNODE_TYPE_0600 fail on exception: " + e); expect(null).assertFail(); + done(); } - done(); }) }) } diff --git a/distributeddatamgr/distributedKVStoretest/distributedKVStorejstest/hap/src/main/js/test/KvManagerKVCallbackJsTest.js b/distributeddatamgr/distributedKVStoretest/distributedKVStorejstest/hap/src/main/js/test/KvManagerKVCallbackJsTest.js index 417eb504a66b9e82392066967b808374d86a6704..6025842b34b920567919da83fb865ae8e880f2f6 100644 --- a/distributeddatamgr/distributedKVStoretest/distributedKVStorejstest/hap/src/main/js/test/KvManagerKVCallbackJsTest.js +++ b/distributeddatamgr/distributedKVStoretest/distributedKVStorejstest/hap/src/main/js/test/KvManagerKVCallbackJsTest.js @@ -73,7 +73,7 @@ describe('kvManagerCallbackTest', function () { * @tc.number SUB_DDM_DKV_KVMANAGER_GETKVSTORE_0100 * @tc.desc Test Js Api KVManager.GetKVStore() testcase 001 * @tc.type: FUNC - * @tc.name Test Js Api KVManager.GetKVStore() testcase 00 + * @tc.name Test Js Api KVManager.GetKVStore() testcase 001 */ it('SUB_DDM_DKV_KVMANAGER_GETKVSTORE_0100', 0, async function (done) { console.info('SUB_DDM_DKV_KVMANAGER_GETKVSTORE_0100'); @@ -108,14 +108,16 @@ describe('kvManagerCallbackTest', function () { if (err == undefined) { console.info('SUB_DDM_DKV_KVMANAGER_GETKVSTORE_0200 getKVStore success'); expect(null).assertFail(); + done(); } else { - expect((err.code == 401)).assertTrue(); - console.info('getKVStore fail' + `, error code is ${err.code}, message is ${err.message}`); + console.error('SUB_DDM_DKV_KVMANAGER_GETKVSTORE_0200 getKVStore err ' + `, error code is ${err.code}, message is ${err.message}`); + expect(null).assertFail(); + done(); } - done(); }); } catch (e) { console.error('SUB_DDM_DKV_KVMANAGER_GETKVSTORE_0200 getKVStore e ' + `, error code is ${e.code}, message is ${e.message}`); + expect(e.code == 401).assertTrue(); done(); } }) @@ -171,7 +173,7 @@ describe('kvManagerCallbackTest', function () { try { await kvManager.getKVStore(TEST_STORE_ID, optionsInfo, function (err, store) { console.info('SUB_DDM_DKV_KVMANAGER_GETKVSTORE_0400 getKVStore success'); - expect(true).assertTrue(); + expect((err == undefined) && (store != null)).assertTrue(); done(); }); } catch (e) { @@ -201,7 +203,7 @@ describe('kvManagerCallbackTest', function () { try { await kvManager.getKVStore(TEST_STORE_ID, optionsInfo, function (err, store) { console.info('SUB_DDM_DKV_KVMANAGER_GETKVSTORE_0500 getKVStore success'); - expect(true).assertTrue(); + expect((err == undefined) && (store != null)).assertTrue(); done(); }); } catch (e) { @@ -231,7 +233,7 @@ describe('kvManagerCallbackTest', function () { try { await kvManager.getKVStore(TEST_STORE_ID, optionsInfo, function (err, store) { console.info('SUB_DDM_DKV_KVMANAGER_GETKVSTORE_0600 getKVStore success'); - expect(true).assertTrue(); + expect((err == undefined) && (store != null)).assertTrue(); done(); }); } catch (e) { @@ -261,7 +263,7 @@ describe('kvManagerCallbackTest', function () { try { await kvManager.getKVStore(TEST_STORE_ID, optionsInfo, function (err, store) { console.info('SUB_DDM_DKV_KVMANAGER_GETKVSTORE_0700 getKVStore success'); - expect(true).assertTrue(); + expect((err == undefined) && (store != null)).assertTrue(); done(); }); } catch (e) { @@ -282,6 +284,7 @@ describe('kvManagerCallbackTest', function () { try { await kvManager.getKVStore(TEST_STORE_ID, options, async function (err, store) { console.info('SUB_DDM_DKV_KVMANAGER_CLOSEKVSTORE_0100 getKVStore success'); + expect((err == undefined) && (store != null)).assertTrue(); kvStore = store; await kvManager.closeKVStore(TEST_BUNDLE_NAME, TEST_STORE_ID, kvStore, function (err, data) { console.info('SUB_DDM_DKV_KVMANAGER_CLOSEKVSTORE_0100 closeKVStore success'); @@ -313,13 +316,16 @@ describe('kvManagerCallbackTest', function () { if (err == undefined) { console.info('SUB_DDM_DKV_KVMANAGER_CLOSEKVSTORE_0200 closeKVStore success'); expect(null).assertFail(); + done(); } else { - console.info('SUB_DDM_DKV_KVMANAGER_CLOSEKVSTORE_0200 closeKVStore fail'); + console.error('SUB_DDM_DKV_KVMANAGER_CLOSEKVSTORE_0200 closeKVStore err ' + `, error code is ${err.code}, message is ${err.message}`); + expect(null).assertFail(); + done(); } - done(); }); } catch (e) { console.error('SUB_DDM_DKV_KVMANAGER_CLOSEKVSTORE_0200 closeKVStore e ' + `, error code is ${e.code}, message is ${e.message}`); + expect(e.code == 401).assertTrue(); done(); } }); @@ -339,20 +345,23 @@ describe('kvManagerCallbackTest', function () { it('SUB_DDM_DKV_KVMANAGER_CLOSEKVSTORE_0300', 0, async function (done) { console.info('SUB_DDM_DKV_KVMANAGER_CLOSEKVSTORE_0300'); try { - await kvManager.getKVStore(TEST_STORE_ID, options, async function (err) { + await kvManager.getKVStore(TEST_STORE_ID, options, async function (err, store) { console.info('SUB_DDM_DKV_KVMANAGER_CLOSEKVSTORE_0300 getKVStore success'); try { - await kvManager.closeKVStore(TEST_BUNDLE_NAME, TEST_STORE_ID, function (err) { + await kvManager.closeKVStore(TEST_STORE_ID, function (err) { if (err == undefined) { console.info('SUB_DDM_DKV_KVMANAGER_CLOSEKVSTORE_0300 closeKVStore success'); - expect(true).assertTrue(); + expect(null).assertFail(); + done(); } else { - console.info('SUB_DDM_DKV_KVMANAGER_CLOSEKVSTORE_0300 closeKVStore fail'); + console.error('SUB_DDM_DKV_KVMANAGER_CLOSEKVSTORE_0300 closeKVStore err ' + `, error code is ${err.code}, message is ${err.message}`); + expect(null).assertFail(); + done(); } - done(); }); } catch (e) { console.error('SUB_DDM_DKV_KVMANAGER_CLOSEKVSTORE_0300 closeKVStore e ' + `, error code is ${e.code}, message is ${e.message}`); + expect(e.code == 401).assertTrue(); done(); } }); @@ -374,20 +383,24 @@ describe('kvManagerCallbackTest', function () { try { await kvManager.getKVStore(TEST_STORE_ID, options, async function (err, store) { console.info('SUB_DDM_DKV_KVMANAGER_CLOSEKVSTORE_0400 getKVStore success'); + kvManager.closeKVStore(TEST_BUNDLE_NAME, TEST_STORE_ID, function (err, data) { - if (err != undefined) { - console.info(`Fail to close KVStore.code is ${err.code},message is ${err.message}`); + if (err == undefined) { + console.info('SUB_DDM_DKV_KVMANAGER_CLOSEKVSTORE_0300 closeKVStore success'); + expect(err == undefined).assertTrue(); + done(); + } else { + console.error('SUB_DDM_DKV_KVMANAGER_CLOSEKVSTORE_0300 closeKVStore err ' + `, error code is ${err.code}, message is ${err.message}`); + expect(null).assertFail(); + done(); } - expect(err == undefined).assertTrue(); - console.info('SUB_DDM_DKV_KVMANAGER_CLOSEKVSTORE_0400 closeKVStore1 done'); - done(); - console.info('SUB_DDM_DKV_KVMANAGER_CLOSEKVSTORE_0400 closeKVStore redo.'); }) }); } catch (e) { console.error('SUB_DDM_DKV_KVMANAGER_CLOSEKVSTORE_0400 closeKVStore twice e ' + `, error code is ${e.code}, message is ${e.message}`); - // expect(null).assertFail(); + expect(null).assertFail(); + done(); } }) @@ -408,13 +421,16 @@ describe('kvManagerCallbackTest', function () { if (err == undefined) { console.info('SUB_DDM_DKV_KVMANAGER_DLETEKVSTORE_0100 deleteKVStore success'); expect(null).assertFail(); + done(); } else { console.info('SUB_DDM_DKV_KVMANAGER_DLETEKVSTORE_0100 deleteKVStore fail'); + expect(null).assertFail(); + done(); } - done(); }); } catch (e) { console.error('SUB_DDM_DKV_KVMANAGER_DLETEKVSTORE_0100 deleteKVStore e ' + `, error code is ${e.code}, message is ${e.message}`); + expect(e.code == 401).assertTrue(); done(); } }); @@ -438,13 +454,16 @@ describe('kvManagerCallbackTest', function () { if (err == undefined){ console.info('SUB_DDM_DKV_KVMANAGER_DLETEKVSTORE_0200 deleteKVStore success'); expect(null).assertFail(); + done(); } else { - console.info('SUB_DDM_DKV_KVMANAGER_DLETEKVSTORE_0200 deleteKVStore fail'); + console.error('SUB_DDM_DKV_KVMANAGER_DLETEKVSTORE_0200 err ' + `, error code is ${err.code}, message is ${err.message}`); + expect(err.code == 15100004).assertTrue(); + done(); } - done(); }); } catch (e) { console.error('SUB_DDM_DKV_KVMANAGER_DLETEKVSTORE_0200 e ' + `, error code is ${e.code}, message is ${e.message}`); + expect(null).assertFail(); done(); } }) @@ -462,6 +481,7 @@ describe('kvManagerCallbackTest', function () { console.info('SUB_DDM_DKV_KVMANAGER_GETALLKVSTOREID_0100 getAllKVStoreId success'); console.info('SUB_DDM_DKV_KVMANAGER_GETALLKVSTOREID_0100 size = ' + data.length); console.info('SUB_DDM_DKV_KVMANAGER_GETALLKVSTOREID_0100 err is: ' + err); + expect(err == undefined).assertTrue(); expect(0).assertEqual(data.length); done(); }); @@ -485,17 +505,11 @@ describe('kvManagerCallbackTest', function () { console.info('SUB_DDM_DKV_KVMANAGER_PUT_0100 getKVStore success'); kvStore = store; await kvStore.put(STORE_KEY, STORE_VALUE, function (err, data) { - if (err != undefined){ - console.info('SUB_DDM_DKV_KVMANAGER_PUT_0100 put callback fail'); - expect(null).assertFail(); - } else { - console.info('SUB_DDM_DKV_KVMANAGER_PUT_0100 put callback success'); - expect(true).assertTrue(); - } + console.info('SUB_DDM_DKV_KVMANAGER_PUT_0100 put callback success'); + expect(err == undefined).assertTrue(); done(); }); }); - } catch (e) { console.error('SUB_DDM_DKV_KVMANAGER_PUT_0100 callback e ' + `, error code is ${e.code}, message is ${e.message}`); expect(null).assertFail(); @@ -503,6 +517,7 @@ describe('kvManagerCallbackTest', function () { } }) + /** * @tc.number SUB_DDM_DKV_KVMANAGER_CREATEKVMANAGER_0100 * @tc.desc Test Js Api createKVManager() testcase 001 @@ -510,19 +525,21 @@ describe('kvManagerCallbackTest', function () { * @tc.name Test Js Api createKVManager() testcase 001 */ it('SUB_DDM_DKV_KVMANAGER_CREATEKVMANAGER_0100', 0, async function (done) { - console.info('SUB_DDM_DKV_KVMANAGER_CREATEKVMANAGER_0100 start'); - let kvManagerConfig = { - bundleName : [TEST_BUNDLE_NAME], - context: context + console.info('SUB_DDM_DKV_KVMANAGER_CREATEKVMANAGER_0100'); + const config = { + bundleName: [TEST_BUNDLE_NAME], + context:context } - try{ - factory.createKVManager(kvManagerConfig); - expect(false).assertTrue(); - }catch(err){ - console.info(`Create kvManager error: error code is ${err.code}, error message is ${err.message}`); - expect(err.code).assertEqual("401"); + try { + kvManager = factory.createKVManager(config); + console.info('Create kvManager success'); + expect(null).assertFail(); + done(); + }catch (e) { + console.error('SUB_DDM_DKV_KVMANAGER_CREATEKVMANAGER_0100 fail err' + `, error code is ${e.code}, message is ${e.message}`); + expect(e.code == 401).assertTrue(); + done(); } - done(); }) /** @@ -532,19 +549,22 @@ describe('kvManagerCallbackTest', function () { * @tc.name Test Js Api createKVManager() testcase 002 */ it('SUB_DDM_DKV_KVMANAGER_CREATEKVMANAGER_0200', 0, async function (done) { - console.info('SUB_DDM_DKV_KVMANAGER_CREATEKVMANAGER_0200 start '); - let kvManagerConfig = { - bundleName : TEST_BUNDLE_NAME, - context: "context" + console.info('SUB_DDM_DKV_KVMANAGER_CREATEKVMANAGER_0200'); + const config = { + bundleName: TEST_BUNDLE_NAME, + context:"context" } - try{ - factory.createKVManager(kvManagerConfig); - expect(false).assertTrue(); - }catch(err){ - console.info(`Create kvManager error: error code is ${err.code}, error message is ${err.message}`); - expect(err.code).assertEqual("401"); + try { + kvManager = factory.createKVManager(config); + console.info('Create kvManager success'); + expect(null).assertFail(); + done(); + }catch (e) { + console.error('SUB_DDM_DKV_KVMANAGER_CREATEKVMANAGER_0200 fail err' + `, error code is ${e.code}, message is ${e.message}`); + expect(e.code == 401).assertTrue(); + done(); } - done(); + }) /** @@ -555,14 +575,16 @@ describe('kvManagerCallbackTest', function () { */ it('SUB_DDM_DKV_KVMANAGER_CREATEKVMANAGER_0300', 0, async function (done) { console.info('SUB_DDM_DKV_KVMANAGER_CREATEKVMANAGER_0300 start '); - try{ - factory.createKVManager("kvManagerConfig"); - expect(false).assertTrue(); - }catch(err){ - console.info(`Create kvManager error: error code is ${err.code}, error message is ${err.message}`); - expect(err.code).assertEqual("401"); + try { + kvManager = factory.createKVManager("kvManagerConfig"); + console.info('Create kvManager success'); + expect(null).assertFail(); + done(); + }catch (e) { + console.error('SUB_DDM_DKV_KVMANAGER_CREATEKVMANAGER_0300 fail err' + `, error code is ${e.code}, message is ${e.message}`); + expect(e.code == 401).assertTrue(); + done(); } - done(); }) /** @@ -573,14 +595,16 @@ describe('kvManagerCallbackTest', function () { */ it('SUB_DDM_DKV_KVMANAGER_CREATEKVMANAGER_0400', 0, async function (done) { console.info('SUB_DDM_DKV_KVMANAGER_CREATEKVMANAGER_0400 start '); - try{ - factory.createKVManager(); - expect(false).assertTrue(); - }catch(err){ - console.info(`Create kvManager error: error code is ${err.code}, error message is ${err.message}`); - expect(err.code).assertEqual("401"); + try { + kvManager = factory.createKVManager(); + console.info('Create kvManager success'); + expect(null).assertFail(); + done(); + }catch (e) { + console.error('SUB_DDM_DKV_KVMANAGER_CREATEKVMANAGER_0300 fail err' + `, error code is ${e.code}, message is ${e.message}`); + expect(e.code == 401).assertTrue(); + done(); } - done(); }) }) } \ No newline at end of file