diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/js/test/V9_PreferencesCallBackJsunit.test.js b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/V9_PreferencesCallBackJsunit.test.js index 7285535249eaa9faf926d2960831ef4bc4b6360e..42ee07fd66ae5209e2e99edd1ea90704f09dd881 100644 --- a/distributeddatamgr/preferencesjstest/hap/src/main/js/test/V9_PreferencesCallBackJsunit.test.js +++ b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/V9_PreferencesCallBackJsunit.test.js @@ -328,13 +328,13 @@ describe('preferencesV9CallbackTest', async function () { expect(false).assertTrue() } }) - - /** - * @tc.name mPreference.clear() + + /** + * @tc.name mPreference.on() * @tc.number SUB_DDM_JSPREFERENCEV9_CALLBACK_1300 - * @tc.desc mPreference.clear() + * @tc.desc mPreference.on() */ - it('SUB_DDM_JSPREFERENCEV9_CALLBACK_1300', 0, async function () { + it('SUB_DDM_JSPREFERENCEV9_CALLBACK_1300', 0, async function () { console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_1300 begin.") try { mPreference.clear(); @@ -347,78 +347,80 @@ describe('preferencesV9CallbackTest', async function () { }; await mPreference.on('change', observer); await mPreference.put(KEY_TEST_STRING_ELEMENT, "abcd"); + mPreference.off('change', observer); } catch (error) { console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message) expect(false).assertTrue() } }) - - /** - * @tc.name mPreference.clear() + + /** + * @tc.name mPreference.on() * @tc.number SUB_DDM_JSPREFERENCEV9_CALLBACK_1400 - * @tc.desc mPreference.clear() + * @tc.desc mPreference.on() */ - it('SUB_DDM_JSPREFERENCEV9_CALLBACK_1400', 0, async function () { + it('SUB_DDM_JSPREFERENCEV9_CALLBACK_1400', 0, async function (done) { console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_1400 begin.") + await mPreference.clear(); try { var observer = function (key) { - if (key) { - console.info('SUB_DDM_JSPREFERENCEV9_CALLBACK_1400 key' + key); - expect(false).assertTrue() - } - expect("abcd").assertEqual(key); + console.info('SUB_DDM_JSPREFERENCEV9_CALLBACK_1400 key' + key); + done(); + expect(KEY_TEST_STRING_ELEMENT).assertEqual(key); }; - mPreference.clear(); - await mPreference.on('sschange', observer); - await mPreference.put(KEY_TEST_STRING_ELEMENT, "abcd"); - } catch (error) { + mPreference.on('change', observer); + await mPreference.put(KEY_TEST_STRING_ELEMENT, "abc"); + await mPreference.flush(); + } catch (err) { console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message) - done() expect(false).assertTrue() + } finally { + mPreference.off('change', observer); } }) - /** - * @tc.name mPreference.on() + /** + * @tc.name mPreference.off() * @tc.number SUB_DDM_JSPREFERENCEV9_CALLBACK_1500 - * @tc.desc mPreference.on() + * @tc.desc mPreference.off() */ - it('SUB_DDM_JSPREFERENCEV9_CALLBACK_1500', 0, async function () { + it('SUB_DDM_JSPREFERENCEV9_CALLBACK_1500', 0, async function (done) { + console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_1500 begin.") + await mPreference.clear(); try { - console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_1500 begin.") var observer = function (key) { console.info('SUB_DDM_JSPREFERENCEV9_CALLBACK_1500 key' + key); - expect('').assertEqual(key); + expect(KEY_TEST_STRING_ELEMENT).assertEqual(key); }; - await mPreference.on('change', observer); - await mPreference.off('change', observer); - await mPreference.put(KEY_TEST_STRING_ELEMENT, "abc"); - } catch (error) { - console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message) + mPreference.on('sschange', observer); expect(false).assertTrue() + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message) + done(); } }) - /** - * @tc.name mPreference.off() + /** + * @tc.name mPreference.off() * @tc.number SUB_DDM_JSPREFERENCEV9_CALLBACK_1600 - * @tc.desc mPreference.off() + * @tc.desc mPreference.off() */ - it('SUB_DDM_JSPREFERENCEV9_CALLBACK_1600', 0, async function () { + it('SUB_DDM_JSPREFERENCEV9_CALLBACK_1600', 0, async function (done) { + console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_1600 begin.") try { - console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_1600 begin.") var observer = function (key) { console.info('SUB_DDM_JSPREFERENCEV9_CALLBACK_1600 key' + key); - expect('').assertEqual(key); + expect(false).assertTrue() }; - await mPreference.on('change', observer); - await mPreference.off('123change', observer); - await mPreference.put(KEY_TEST_STRING_ELEMENT, "abc"); - } catch (error) { + mPreference.on('change', observer); + mPreference.off('change', observer); + await mPreference.put(KEY_TEST_STRING_ELEMENT, "abb"); + await mPreference.flush(); + } catch (err) { console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message) - done() expect(false).assertTrue() } + done(); }) }) } \ No newline at end of file diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/js/test/V9_PreferencesPromiseJsunit.test.js b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/V9_PreferencesPromiseJsunit.test.js index 8aef1cc331ac4a03fd930edd373ada5fd48d7352..449ca7b18a7a21bc697934d9c79071cb543aead0 100644 --- a/distributeddatamgr/preferencesjstest/hap/src/main/js/test/V9_PreferencesPromiseJsunit.test.js +++ b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/V9_PreferencesPromiseJsunit.test.js @@ -34,6 +34,12 @@ describe('preferencesV9PromiseTest', async function () { await data_preferences.deletePreferences(context, NAME) }) + beforeEach(async function () { + console.info('beforeEach') + await mPreference.clear(); + await mPreference.flush(); + }) + /** * @tc.name has、delete、get、flush String callback interface test * @tc.number SUB_DDM_JSPREFERENCEV9_PROMISE_0100 @@ -113,12 +119,13 @@ describe('preferencesV9PromiseTest', async function () { * @tc.number SUB_DDM_JSPREFERENCEV9_PROMISE_0300 * @tc.desc mPreference.get() */ - it('SUB_DDM_JSPREFERENCEV9_PROMISE_0300', 0, function (done) { + it('SUB_DDM_JSPREFERENCEV9_PROMISE_0300', 0, async function (done) { console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_0300 begin.") try{ - mPreference.get(KEY_TEST_STRING_ELEMENT, KEY_TEST_INT_ELEMENT).then((ret)=>{ - expect('123').assertEqual(ret) + await mPreference.put(KEY_TEST_STRING_ELEMENT, '123'); + mPreference.get(KEY_TEST_STRING_ELEMENT, KEY_TEST_INT_ELEMENT).then((ret) => { done() + expect('123').assertEqual(ret) console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_0300 end.") }).catch((err) => { console.log("get err =" + err + ", code =" + err.code +", message =" + err.message) @@ -327,17 +334,21 @@ describe('preferencesV9PromiseTest', async function () { * @tc.number SUB_DDM_JSPREFERENCEV9_PROMISE_1300 * @tc.desc mPreference.on() */ - it('SUB_DDM_JSPREFERENCEV9_PROMISE_1300', 0, async function () { + it('SUB_DDM_JSPREFERENCEV9_PROMISE_1300', 0, async function () { console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_1300 begin.") - await mPreference.clear(); try { + mPreference.clear(); var observer = function (key) { - console.info('SUB_DDM_JSPREFERENCEV9_PROMISE_1300 key' + key); - expect('abc').assertEqual(key); + if (key) { + console.info('SUB_DDM_JSPREFERENCEV9_PROMISE_1300 key' + key); + expect(false).assertTrue() + } + expect("abcd").assertEqual(key); }; - mPreference.on('change', observer); - mPreference.put(KEY_TEST_STRING_ELEMENT, "abc"); - } catch (err) { + await mPreference.on('change', observer); + await mPreference.put(KEY_TEST_STRING_ELEMENT, "abcd"); + mPreference.off('change', observer); + } catch (error) { console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message) expect(false).assertTrue() } @@ -348,20 +359,23 @@ describe('preferencesV9PromiseTest', async function () { * @tc.number SUB_DDM_JSPREFERENCEV9_PROMISE_1400 * @tc.desc mPreference.on() */ - it('SUB_DDM_JSPREFERENCEV9_PROMISE_1400', 0, async function () { + it('SUB_DDM_JSPREFERENCEV9_PROMISE_1400', 0, async function (done) { console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_1400 begin.") await mPreference.clear(); try { var observer = function (key) { console.info('SUB_DDM_JSPREFERENCEV9_PROMISE_1400 key' + key); - expect('abc').assertEqual(key); + done(); + expect(KEY_TEST_STRING_ELEMENT).assertEqual(key); }; - mPreference.on('sschange', observer); - mPreference.put(KEY_TEST_STRING_ELEMENT, "abc"); + mPreference.on('change', observer); + await mPreference.put(KEY_TEST_STRING_ELEMENT, "abc"); + await mPreference.flush(); } catch (err) { console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message) - done() expect(false).assertTrue() + } finally { + mPreference.off('change', observer); } }) @@ -370,41 +384,43 @@ describe('preferencesV9PromiseTest', async function () { * @tc.number SUB_DDM_JSPREFERENCEV9_PROMISE_1500 * @tc.desc mPreference.off() */ - it('SUB_DDM_JSPREFERENCEV9_PROMISE_1500', 0, async function () { + it('SUB_DDM_JSPREFERENCEV9_PROMISE_1500', 0, async function (done) { console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_1500 begin.") + await mPreference.clear(); try { var observer = function (key) { console.info('SUB_DDM_JSPREFERENCEV9_PROMISE_1500 key' + key); - expect('').assertEqual(key); + expect(KEY_TEST_STRING_ELEMENT).assertEqual(key); }; - mPreference.on('change', observer); - mPreference.off('change', observer); - mPreference.put(KEY_TEST_STRING_ELEMENT, "abc"); + mPreference.on('sschange', observer); + expect(false).assertTrue() } catch (err) { console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message) - expect(false).assertTrue() + done(); } }) + /** * @tc.name mPreference.off() * @tc.number SUB_DDM_JSPREFERENCEV9_PROMISE_1600 * @tc.desc mPreference.off() */ - it('SUB_DDM_JSPREFERENCEV9_PROMISE_1600', 0, async function () { + it('SUB_DDM_JSPREFERENCEV9_PROMISE_1600', 0, async function (done) { console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_1600 begin.") try { var observer = function (key) { console.info('SUB_DDM_JSPREFERENCEV9_PROMISE_1600 key' + key); - expect('').assertEqual(key); + expect(false).assertTrue() }; mPreference.on('change', observer); - mPreference.off('sschange', observer); - mPreference.put(KEY_TEST_STRING_ELEMENT, "abc"); + mPreference.off('change', observer); + await mPreference.put(KEY_TEST_STRING_ELEMENT, "abb"); + await mPreference.flush(); } catch (err) { console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message) - done() expect(false).assertTrue() } + done(); }) }) } \ No newline at end of file