From fd1732a78a2b3ae4e99542e71b50a5ce9048f674 Mon Sep 17 00:00:00 2001 From: xsterling Date: Thu, 6 Jan 2022 11:46:01 +0800 Subject: [PATCH] testcase update. Signed-off-by: xsterling --- .../test/DeviceKvStoreCallbackJsunit.test.js | 54 ++++++++++--------- .../test/DeviceKvStorePromiseJsunit.test.js | 37 +++++++++---- .../main/js/default/test/SchemaJsunit.test.js | 21 ++++++++ .../test/SingleKvStoreCallbackJsunit.test.js | 29 ++++++---- .../test/SingleKvStorePromiseJsunit.test.js | 36 ++++++++----- 5 files changed, 120 insertions(+), 57 deletions(-) diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/DeviceKvStoreCallbackJsunit.test.js b/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/DeviceKvStoreCallbackJsunit.test.js index 88d1c163c..ea5e7a77e 100644 --- a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/DeviceKvStoreCallbackJsunit.test.js +++ b/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/DeviceKvStoreCallbackJsunit.test.js @@ -854,19 +854,21 @@ describe('DeviceKvStoreCallbackTest', function () { await kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err,data) { console.log('testDeviceKvStoreOnSyncComplete101 put success'); expect(err == undefined).assertTrue(); + }).catch((error) => { + console.log('testDeviceKvStoreOnSyncComplete101 put failed:' + e); + expect(null).assertFail(); + }); + try { var devices = ['A12C1F9261528B21F95778D2FDC0B2E33943E6251AC5487F4473D005758905DB']; var mode = factory.SyncMode.PULL_ONLY; - try { - kvStore.sync(devices, mode); - } catch(e) { - console.log('testDeviceKvStoreOnSyncComplete101 sync no peer device :e:' + e); - } - done(); - }); + kvStore.sync(devices, mode); + } catch(e) { + console.log('testDeviceKvStoreOnSyncComplete101 sync no peer device :e:' + e); + } }catch(e) { console.log('testDeviceKvStoreOnSyncComplete101 no peer device :e:' + e); - done(); } + done(); }) /** @@ -883,19 +885,21 @@ describe('DeviceKvStoreCallbackTest', function () { await kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err,data) { console.log('testDeviceKvStoreOnSyncComplete102 put success'); expect(err == undefined).assertTrue(); + }).catch((error) => { + console.log('testDeviceKvStoreOnSyncComplete102 put failed:' + e); + expect(null).assertFail(); + }); + try { var devices = ['A12C1F9261528B21F95778D2FDC0B2E33943E6251AC5487F4473D005758905DB']; var mode = factory.SyncMode.PUSH_ONLY; - try { - kvStore.sync(devices, mode); - } catch(e) { - console.log('testDeviceKvStoreOnSyncComplete101 sync no peer device :e:' + e); - } - done(); - }); + kvStore.sync(devices, mode); + } catch(e) { + console.log('testDeviceKvStoreOnSyncComplete102 sync no peer device :e:' + e); + } }catch(e) { console.log('testDeviceKvStoreOnSyncComplete102 no peer device :e:' + e); - done(); } + done(); }) /** @@ -912,19 +916,21 @@ describe('DeviceKvStoreCallbackTest', function () { await kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err,data) { console.log('testDeviceKvStoreOnSyncComplete103 put success'); expect(err == undefined).assertTrue(); + }).catch((error) => { + console.log('testDeviceKvStoreOnSyncComplete103 put failed:' + e); + expect(null).assertFail(); + }); + try { var devices = ['A12C1F9261528B21F95778D2FDC0B2E33943E6251AC5487F4473D005758905DB']; var mode = factory.SyncMode.PUSH_PULL; - try { - kvStore.sync(devices, mode); - } catch(e) { - console.log('testDeviceKvStoreOnSyncComplete101 sync no peer device :e:' + e); - } - done(); - }); + kvStore.sync(devices, mode); + } catch(e) { + console.log('testDeviceKvStoreOnSyncComplete103 sync no peer device :e:' + e); + } }catch(e) { console.log('testDeviceKvStoreOnSyncComplete103 no peer device :e:' + e); - done(); } + done(); }) /** diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/DeviceKvStorePromiseJsunit.test.js b/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/DeviceKvStorePromiseJsunit.test.js index 29f13cdef..2a4b51aff 100644 --- a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/DeviceKvStorePromiseJsunit.test.js +++ b/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/DeviceKvStorePromiseJsunit.test.js @@ -860,14 +860,19 @@ describe('DeviceKvStorePromiseTest', function () { await kvStore.put(KEY_TEST_SYNC_ELEMENT, VALUE_TEST_SYNC_ELEMENT).then((data) => { console.log('testDeviceKvStoreOnSyncComplete001 put success'); expect(data == undefined).assertTrue(); + }).catch((error) => { + console.log('testDeviceKvStoreOnSyncComplete001 put failed:' + e); + expect(null).assertFail(); + }); + try { var devices = ['A12C1F9261528B21F95778D2FDC0B2E33943E6251AC5487F4473D005758905DB']; var mode = factory.SyncMode.PULL_ONLY; kvStore.sync(devices, mode); - }).catch((error) => { - console.log('testDeviceKvStoreOnSyncComplete001 no peer device :e:' + error); - }); - }catch(e) { - console.log('testDeviceKvStoreOnSyncComplete001 put e ' + e); + } catch (e) { + console.log('testDeviceKvStoreOnSyncComplete001 sync no peer device :e:' + e); + } + } catch(e) { + console.log('testDeviceKvStoreOnSyncComplete001 e ' + e); expect(null).assertFail(); } done(); @@ -887,13 +892,18 @@ describe('DeviceKvStorePromiseTest', function () { await kvStore.put(KEY_TEST_SYNC_ELEMENT, VALUE_TEST_SYNC_ELEMENT).then((data) => { console.log('testDeviceKvStoreOnSyncComplete002 put success'); expect(data == undefined).assertTrue(); + }).catch((error) => { + console.log('testDeviceKvStoreOnSyncComplete002 put failed:' + e); + expect(null).assertFail(); + }); + try { var devices = ['A12C1F9261528B21F95778D2FDC0B2E33943E6251AC5487F4473D005758905DB']; var mode = factory.SyncMode.PUSH_ONLY; kvStore.sync(devices, mode); - }).catch((error) => { + } catch(error) { console.log('testDeviceKvStoreOnSyncComplete002 no peer device :e:' + error); - }); - }catch(e) { + }; + } catch(e) { console.log('testDeviceKvStoreOnSyncComplete002 put e ' + e); expect(null).assertFail(); } @@ -914,13 +924,18 @@ describe('DeviceKvStorePromiseTest', function () { await kvStore.put(KEY_TEST_SYNC_ELEMENT, VALUE_TEST_SYNC_ELEMENT).then((data) => { console.log('testDeviceKvStoreOnSyncComplete003 put success'); expect(data == undefined).assertTrue(); + }).catch((error) => { + console.log('testDeviceKvStoreOnSyncComplete002 put failed:' + e); + expect(null).assertFail(); + }); + try { var devices = ['A12C1F9261528B21F95778D2FDC0B2E33943E6251AC5487F4473D005758905DB']; var mode = factory.SyncMode.PUSH_PULL; kvStore.sync(devices, mode); - }).catch((error) => { + } catch(error) { console.log('testDeviceKvStoreOnSyncComplete003 no peer device :e:' + error); - }); - }catch(e) { + }; + } catch(e) { console.log('testDeviceKvStoreOnSyncComplete003 put e ' + e); expect(null).assertFail(); } diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/SchemaJsunit.test.js b/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/SchemaJsunit.test.js index 2c19f8ded..af901a6f1 100644 --- a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/SchemaJsunit.test.js +++ b/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/SchemaJsunit.test.js @@ -262,4 +262,25 @@ describe('SchemaTest', function() { } done(); }) + + /** + * @tc.number SUB_DISTRIBUTEDDATAMGR_SCHEMA_TOJSONSTRING_0400 + * @tc.name [JS-API8]Schema.ToJsonString() + * @tc.desc Test Js Api Schema.ToJsonString() testcase 004 + */ + it('testToJsonString004', 0, async function(done) { + try { + let english = new ddm.FieldNode('english'); + english.type = ddm.ValueType.STRING; + + let schema = new ddm.Schema(); + schema.root.appendChild(english); + schema.indexes = []; // indexex set to empty array. + console.log("schema: " + schema.toJsonString()); + } catch (e) { + console.log("schema fail on exception: " + e); + expect(null).assertFail(); + } + done(); + }) }) \ No newline at end of file diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/SingleKvStoreCallbackJsunit.test.js b/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/SingleKvStoreCallbackJsunit.test.js index 9aa1dc4ee..9f428a3df 100755 --- a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/SingleKvStoreCallbackJsunit.test.js +++ b/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/SingleKvStoreCallbackJsunit.test.js @@ -821,11 +821,14 @@ describe('SingleKvStoreCallbackTest', function () { await kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err,data) { console.log('testSingleKvStoreOnSyncComplete101 put success'); expect(err == undefined).assertTrue(); + }); + try { var devices = ['A12C1F9261528B21F95778D2FDC0B2E33943E6251AC5487F4473D005758905DB']; var mode = factory.SyncMode.PULL_ONLY; kvStore.sync(devices, mode, 10); - done(); - }); + } catch (e) { + console.log('testSingleKvStoreOnSyncComplete101 sync no peer device :e:' + e); + } }catch(e) { console.log('testSingleKvStoreOnSyncComplete101 e' + e); expect(null).assertFail(); @@ -844,19 +847,22 @@ describe('SingleKvStoreCallbackTest', function () { console.log('testSingleKvStoreOnSyncComplete102 dataChange'); expect(data != null).assertTrue(); }); - await kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err,data) { + await kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync102', VALUE_TEST_SYNC_ELEMENT, function (err,data) { console.log('testSingleKvStoreOnSyncComplete102 put success'); expect(err == undefined).assertTrue(); + }); + try { var devices = ['A12C1F9261528B21F95778D2FDC0B2E33943E6251AC5487F4473D005758905DB']; var mode = factory.SyncMode.PUSH_ONLY; kvStore.sync(devices, mode, 10); - done(); - }); + } catch (e) { + console.log('testSingleKvStoreOnSyncComplete102 sync no peer device :e:' + e); + } }catch(e) { console.log('testSingleKvStoreOnSyncComplete102 e' + e); expect(null).assertFail(); - done(); } + done(); }) /** @@ -870,19 +876,22 @@ describe('SingleKvStoreCallbackTest', function () { console.log('testSingleKvStoreOnSyncComplete103 dataChange'); expect(data != null).assertTrue(); }); - await kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync101', VALUE_TEST_SYNC_ELEMENT, function (err,data) { + await kvStore.put(KEY_TEST_SYNC_ELEMENT + 'testSync103', VALUE_TEST_SYNC_ELEMENT, function (err,data) { console.log('testSingleKvStoreOnSyncComplete103 put success'); expect(err == undefined).assertTrue(); + }); + try { var devices = ['A12C1F9261528B21F95778D2FDC0B2E33943E6251AC5487F4473D005758905DB']; var mode = factory.SyncMode.PUSH_PULL; kvStore.sync(devices, mode, 10); - done(); - }); + } catch (e) { + console.log('testSingleKvStoreOnSyncComplete103 sync no peer device :e:' + e); + } }catch(e) { console.log('testSingleKvStoreOnSyncComplete103 e' + e); expect(null).assertFail(); - done(); } + done(); }) /** diff --git a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/SingleKvStorePromiseJsunit.test.js b/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/SingleKvStorePromiseJsunit.test.js index a1dd76880..68fdfd331 100755 --- a/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/SingleKvStorePromiseJsunit.test.js +++ b/distributeddatamgr/distributeddatamgrjstest/hap/src/main/js/default/test/SingleKvStorePromiseJsunit.test.js @@ -830,15 +830,19 @@ describe('SingleKvStorePromiseTest', function () { await kvStore.put(KEY_TEST_SYNC_ELEMENT, VALUE_TEST_SYNC_ELEMENT).then((data) => { console.log('testSingleKvStoreOnSyncComplete001 put success'); expect(data == undefined).assertTrue(); - var devices = ['A12C1F9261528B21F95778D2FDC0B2E33943E6251AC5487F4473D005758905DB']; - var mode = factory.SyncMode.PULL_ONLY; - kvStore.sync(devices, mode, 10); }).catch((error) => { console.log('testSingleKvStoreOnSyncComplete001 put fail ' + error); expect(null).assertFail(); }); + try { + var devices = ['A12C1F9261528B21F95778D2FDC0B2E33943E6251AC5487F4473D005758905DB']; + var mode = factory.SyncMode.PULL_ONLY; + kvStore.sync(devices, mode, 10); + } catch (e) { + console.log('testSingleKvStoreOnSyncComplete001 sync no peer device :e:' + e); + } }catch(e) { - console.log('testSingleKvStoreOnSyncComplete001 put e ' + e); + console.log('testSingleKvStoreOnSyncComplete001 e ' + e); expect(null).assertFail(); } done(); @@ -858,15 +862,19 @@ describe('SingleKvStorePromiseTest', function () { await kvStore.put(KEY_TEST_SYNC_ELEMENT, VALUE_TEST_SYNC_ELEMENT).then((data) => { console.log('testSingleKvStoreOnSyncComplete002 put success'); expect(data == undefined).assertTrue(); - var devices = ['A12C1F9261528B21F95778D2FDC0B2E33943E6251AC5487F4473D005758905DB']; - var mode = factory.SyncMode.PUSH_ONLY; - kvStore.sync(devices, mode, 10); }).catch((error) => { console.log('testSingleKvStoreOnSyncComplete002 put fail ' + error); expect(null).assertFail(); }); + try { + var devices = ['A12C1F9261528B21F95778D2FDC0B2E33943E6251AC5487F4473D005758905DB']; + var mode = factory.SyncMode.PUSH_ONLY; + kvStore.sync(devices, mode, 10); + } catch (e) { + console.log('testSingleKvStoreOnSyncComplete002 sync no peer device :e:' + e); + } }catch(e) { - console.log('testSingleKvStoreOnSyncComplete002 put e ' + e); + console.log('testSingleKvStoreOnSyncComplete002 e ' + e); expect(null).assertFail(); } done(); @@ -886,15 +894,19 @@ describe('SingleKvStorePromiseTest', function () { await kvStore.put(KEY_TEST_SYNC_ELEMENT, VALUE_TEST_SYNC_ELEMENT).then((data) => { console.log('testSingleKvStoreOnSyncComplete003 put success'); expect(data == undefined).assertTrue(); - var devices = ['A12C1F9261528B21F95778D2FDC0B2E33943E6251AC5487F4473D005758905DB']; - var mode = factory.SyncMode.PUSH_PULL; - kvStore.sync(devices, mode, 10); }).catch((error) => { console.log('testSingleKvStoreOnSyncComplete003 put fail ' + error); expect(null).assertFail(); }); + try { + var devices = ['A12C1F9261528B21F95778D2FDC0B2E33943E6251AC5487F4473D005758905DB']; + var mode = factory.SyncMode.PUSH_PULL; + kvStore.sync(devices, mode, 10); + } catch (e) { + console.log('testSingleKvStoreOnSyncComplete003 sync no peer device :e:' + e); + } }catch(e) { - console.log('testSingleKvStoreOnSyncComplete003 put e ' + e); + console.log('testSingleKvStoreOnSyncComplete003 e ' + e); expect(null).assertFail(); } done(); -- GitLab