From 6f3ba5ba4c4d0b2620007de9240c819367af3f99 Mon Sep 17 00:00:00 2001 From: lina123456 Date: Fri, 17 Mar 2023 10:23:15 +0800 Subject: [PATCH] Signed-off-by: lina123456 --- .../hap/src/main/js/test/SchemaJsTest.js | 2 +- .../ets/test/relationalStoreEtsunit.test.ets | 485 +++++++++--------- 2 files changed, 240 insertions(+), 247 deletions(-) diff --git a/distributeddatamgr/distributedKVStoretest/distributedKVStorejstest/hap/src/main/js/test/SchemaJsTest.js b/distributeddatamgr/distributedKVStoretest/distributedKVStorejstest/hap/src/main/js/test/SchemaJsTest.js index d0993bdd6..b374ad2a0 100644 --- a/distributeddatamgr/distributedKVStoretest/distributedKVStorejstest/hap/src/main/js/test/SchemaJsTest.js +++ b/distributeddatamgr/distributedKVStoretest/distributedKVStorejstest/hap/src/main/js/test/SchemaJsTest.js @@ -19,7 +19,7 @@ import abilityFeatureAbility from '@ohos.ability.featureAbility' var context = abilityFeatureAbility.getContext(); const TEST_BUNDLE_NAME = 'ohos.acts.distributedKvStore'; -const TEST_STORE_ID = 'storeId'; +const TEST_STORE_ID = 'SchemaStoreId'; var kvManager = null; var kvStore = null; diff --git a/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/test/relationalStoreEtsunit.test.ets b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/test/relationalStoreEtsunit.test.ets index e090a2471..31b9d4a47 100644 --- a/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/test/relationalStoreEtsunit.test.ets +++ b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/test/relationalStoreEtsunit.test.ets @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. + * Copyright (C) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -24,119 +24,113 @@ function sleep(ms) { } export default function relationalStoreTest(context){ -describe('relationalStoreTest', function () { - beforeAll(async function () { - console.info(TAG + 'beforeAll') - }) + describe('relationalStoreTest', function () { + beforeAll(async function () { + console.info(TAG + 'beforeAll') + }) - beforeEach(function () { - console.info(TAG + 'beforeEach') - }) + beforeEach(function () { + console.info(TAG + 'beforeEach') + }) - afterEach(function () { - console.info(TAG + 'afterEach') - }) + afterEach(function () { + console.info(TAG + 'afterEach') + }) - afterAll(async function () { - console.info(TAG + 'afterAll') - }) + afterAll(async function () { + console.info(TAG + 'afterAll') + }) - console.log(TAG + "*************Unit Test Begin*************"); + console.log(TAG + "*************Unit Test Begin*************"); - /** - * @tc.name rdb store getRdbStore with securityLevel S1 - * @tc.number SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0100 - * @tc.desc rdb store getRdbStore with securityLevel S1 - * @tc.require: I5PIL6 - */ - it('SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0100', 0, async function (done) { - console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0100 start *************"); - let config = { - name: "secure.db", - securityLevel: dataRdb.SecurityLevel.S1 - } - let storePromise = dataRdb.getRdbStore(context, config); - storePromise.then(async (store) => { - try { - await store.executeSql(CREATE_TABLE_TEST); - } catch (err) { - expect(null).assertFail(); + /** + * @tc.name rdb store getRdbStore with securityLevel S1 + * @tc.number SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0100 + * @tc.desc rdb store getRdbStore with securityLevel S1 + * @tc.require: I5PIL6 + */ + it('SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0100', 0, async function (done) { + console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0100 start *************"); + let config = { + name: "secure.db", + securityLevel: dataRdb.SecurityLevel.S1 } - }).catch((err) => { - expect(null).assertFail(); + let storePromise = dataRdb.getRdbStore(context, config); + storePromise.then(async (store) => { + try { + await store.executeSql(CREATE_TABLE_TEST); + } catch (err) { + expect(null).assertFail(); + } + await dataRdb.deleteRdbStore(context,"secure.db"); + done(); + }).catch((err) => { + expect(null).assertFail(); + }) + console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0100 end *************"); }) - await storePromise - storePromise = null - await dataRdb.deleteRdbStore(context,"secure.db"); - done(); - console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0100 end *************"); - }) - /** - * @tc.name rdb store getRdbStore with securityLevel S2 - * @tc.number SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0200 - * @tc.desc rdb store getRdbStore with securityLevel S2 - * @tc.require: I5PIL6 - */ - it('SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0200', 0, async function (done) { - console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0200 start *************"); - let config = { - name: "secure.db", - securityLevel: dataRdb.SecurityLevel.S2 - } - let storePromise = dataRdb.getRdbStore(context, config); - storePromise.then(async (store) => { - try { - await store.executeSql(CREATE_TABLE_TEST); - } catch (err) { - expect(null).assertFail(); + /** + * @tc.name rdb store getRdbStore with securityLevel S2 + * @tc.number SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0200 + * @tc.desc rdb store getRdbStore with securityLevel S2 + * @tc.require: I5PIL6 + */ + it('SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0200', 0, async function (done) { + console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0200 start *************"); + let config = { + name: "secure.db", + securityLevel: dataRdb.SecurityLevel.S2 } - }).catch((err) => { - expect(null).assertFail(); + let storePromise = dataRdb.getRdbStore(context, config); + storePromise.then(async (store) => { + try { + await store.executeSql(CREATE_TABLE_TEST); + } catch (err) { + expect(null).assertFail(); + } + await dataRdb.deleteRdbStore(context,"secure.db"); + done(); + }).catch((err) => { + expect(null).assertFail(); + }) + console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0200 end *************"); }) - await storePromise - storePromise = null - await dataRdb.deleteRdbStore(context,"secure.db"); - done(); - console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0200 end *************"); - }) - /** - * @tc.name rdb store getRdbStore with securityLevel S3 - * @tc.number SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0300 - * @tc.desc rdb store getRdbStore with securityLevel S3 - * @tc.require: I5PIL6 - */ - it('SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0300', 0, async function (done) { - console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0300 start *************"); - let config = { - name: "secure.db", - securityLevel: dataRdb.SecurityLevel.S3 - } - let storePromise = dataRdb.getRdbStore(context, config); - storePromise.then(async (store) => { - try { - await store.executeSql(CREATE_TABLE_TEST); - } catch (err) { - expect(null).assertFail(); + /** + * @tc.name rdb store getRdbStore with securityLevel S3 + * @tc.number SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0300 + * @tc.desc rdb store getRdbStore with securityLevel S3 + * @tc.require: I5PIL6 + */ + it('SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0300', 0, async function (done) { + console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0300 start *************"); + let config = { + name: "secure.db", + securityLevel: dataRdb.SecurityLevel.S3 } - }).catch((err) => { - expect(null).assertFail(); + let storePromise = dataRdb.getRdbStore(context, config); + storePromise.then(async (store) => { + try { + await store.executeSql(CREATE_TABLE_TEST); + } catch (err) { + expect(null).assertFail(); + } + await dataRdb.deleteRdbStore(context,"secure.db"); + done(); + }).catch((err) => { + expect(null).assertFail(); + }) + console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0300 end *************"); }) - await storePromise - storePromise = null - await dataRdb.deleteRdbStore(context,"secure.db"); - done(); - console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0300 end *************"); - }) - /** - * @tc.name rdb store getRdbStore with securityLevel S4 - * @tc.number SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0400 - * @tc.desc rdb store getRdbStore with securityLevel S4 - * @tc.require: I5PIL6 - */ - it('SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0400', 0, async function (done) { + /** + * @tc.name rdb store getRdbStore with securityLevel S4 + * @tc.number SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0400 + * @tc.desc rdb store getRdbStore with securityLevel S4 + * @tc.require: I5PIL6 + */ + it('SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0400', 0, async function (done) { console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0400 start *************"); let config = { name: "secure.db", @@ -157,164 +151,163 @@ describe('relationalStoreTest', function () { console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0400 end *************"); }) - /** - * @tc.name rdb store getRdbStore with securityLevel S1 - * @tc.number SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0100 - * @tc.desc rdb store getRdbStore with securityLevel S1 - * @tc.require: I5PIL6 - */ - it('SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0100', 0, async function (done) { - console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0100 start *************"); - let config = { - name: "secure.db", - securityLevel: dataRdb.SecurityLevel.S1 - } - dataRdb.getRdbStore(context, config, async (err,data) => { - if(err != null){ - console.info(TAG + "get rdb store error" + err.message) - expect(null).assertFail(); - }else{ - console.info(TAG + "create table success") + /** + * @tc.name rdb store getRdbStore with securityLevel S1 + * @tc.number SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0100 + * @tc.desc rdb store getRdbStore with securityLevel S1 + * @tc.require: I5PIL6 + */ + it('SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0100', 0, async function (done) { + console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0100 start *************"); + let config = { + name: "secure.db", + securityLevel: dataRdb.SecurityLevel.S1 } - dataRdb.deleteRdbStore(context,"secure.db").then(()=>{ - console.info(TAG + "Delete rdbstore success") - done(); - console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0100 end *************"); - }) - }); - }) + dataRdb.getRdbStore(context, config, async (err,data) => { + if(err != null){ + console.info(TAG + "get rdb store error" + err.message) + expect(null).assertFail(); + }else{ + console.info(TAG + "create table success") + } + dataRdb.deleteRdbStore(context,"secure.db").then(()=>{ + console.info(TAG + "Delete rdbstore success") + done(); + console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0100 end *************"); + }) + }); + }) - /** - * @tc.name rdb store getRdbStore with securityLevel S2 - * @tc.number SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0200 - * @tc.desc rdb store getRdbStore with securityLevel S2 - * @tc.require: I5PIL6 - */ - it('SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0200', 0, async function (done) { - console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0200 start *************"); - let config = { - name: "secure.db", - securityLevel: dataRdb.SecurityLevel.S2 - } - dataRdb.getRdbStore(context, config,async (err,data) => { - if(err != null){ - console.info(TAG + "get rdb store error") - expect(null).assertFail(); - }else{ - console.info(TAG + "create table success") + /** + * @tc.name rdb store getRdbStore with securityLevel S2 + * @tc.number SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0200 + * @tc.desc rdb store getRdbStore with securityLevel S2 + * @tc.require: I5PIL6 + */ + it('SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0200', 0, async function (done) { + console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0200 start *************"); + let config = { + name: "secure.db", + securityLevel: dataRdb.SecurityLevel.S2 } - dataRdb.deleteRdbStore(context, "secure.db").then(() => { - done(); - console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0200 end *************"); - }) - }); - }) + dataRdb.getRdbStore(context, config,async (err,data) => { + if(err != null){ + console.info(TAG + "get rdb store error") + expect(null).assertFail(); + }else{ + console.info(TAG + "create table success") + } + dataRdb.deleteRdbStore(context, "secure.db").then(() => { + done(); + console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0200 end *************"); + }) + }); + }) - /** - * @tc.name rdb store getRdbStore with securityLevel S3 - * @tc.number SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0300 - * @tc.desc rdb store getRdbStore with securityLevel S3 - * @tc.require: I5PIL6 - */ - it('SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0300', 0, async function (done) { - console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0300 start *************"); - let config = { - name: "secure.db", - securityLevel: dataRdb.SecurityLevel.S3 - } - dataRdb.getRdbStore(context, config,async (err,data) => { - if(err != null){ - console.info(TAG + "get rdb store error") - expect(null).assertFail(); - }else{ - console.info(TAG + "create table success") + /** + * @tc.name rdb store getRdbStore with securityLevel S3 + * @tc.number SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0300 + * @tc.desc rdb store getRdbStore with securityLevel S3 + * @tc.require: I5PIL6 + */ + it('SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0300', 0, async function (done) { + console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0300 start *************"); + let config = { + name: "secure.db", + securityLevel: dataRdb.SecurityLevel.S3 } - dataRdb.deleteRdbStore(context, "secure.db").then(() => { - done(); - console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0300 end *************"); - }) - }); - }) + dataRdb.getRdbStore(context, config,async (err,data) => { + if(err != null){ + console.info(TAG + "get rdb store error") + expect(null).assertFail(); + }else{ + console.info(TAG + "create table success") + } + dataRdb.deleteRdbStore(context, "secure.db").then(() => { + done(); + console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0300 end *************"); + }) + }); + }) - /** - * @tc.name rdb store getRdbStore with securityLevel S4 - * @tc.number SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0400 - * @tc.desc rdb store getRdbStore with securityLevel S4 - * @tc.require: I5PIL6 - */ - it('SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0400', 0, async function (done) { - console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0400 start *************"); - let config = { - name: "secure.db", - securityLevel: dataRdb.SecurityLevel.S4 - } - dataRdb.getRdbStore(context, config,async (err,data) => { - if(err != null){ - console.info(TAG + "get rdb store error") - expect(null).assertFail(); - }else{ - console.info(TAG + "get rdb store success") + /** + * @tc.name rdb store getRdbStore with securityLevel S4 + * @tc.number SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0400 + * @tc.desc rdb store getRdbStore with securityLevel S4 + * @tc.require: I5PIL6 + */ + it('SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0400', 0, async function (done) { + console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0400 start *************"); + let config = { + name: "secure.db", + securityLevel: dataRdb.SecurityLevel.S4 + } + dataRdb.getRdbStore(context, config,async (err,data) => { + if(err != null){ + console.info(TAG + "get rdb store error") + expect(null).assertFail(); + }else{ + console.info(TAG + "get rdb store success") + } + dataRdb.deleteRdbStore(context,"secure.db").then(() => { + done(); + console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0400 end *************"); + }) + }); + }) + + /** + * @tc.name rdb store deleteRdbStore + * @tc.number SUB_DDM_RELATIONALETS_DELETERDBSTORE_PROMISE_0100 + * @tc.desc rdb store deleteRdbStore + * @tc.require: I5PIL6 + */ + it('SUB_DDM_RELATIONALETS_DELETERDBSTORE_PROMISE_0100', 0, async function (done) { + console.log(TAG + "************* SUB_DDM_RELATIONALETS_DELETERDBSTORE_PROMISE_0100 start *************"); + let config = { + name: "secure.db", + securityLevel: dataRdb.SecurityLevel.S4 } - dataRdb.deleteRdbStore(context,"secure.db").then(() => { + let deleteResult = false + await dataRdb.getRdbStore(context, config).then(async (store) => { + console.info(TAG + "create table success") + await dataRdb.deleteRdbStore(context,"secure.db").then(() => { + deleteResult = true + console.info(`${TAG} delete rdb store success,result is ${deleteResult}`) + }); + expect(deleteResult).assertTrue(); done(); - console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_CALLBACK_0400 end *************"); }) - }); - }) - - /** - * @tc.name rdb store deleteRdbStore - * @tc.number SUB_DDM_RELATIONALETS_DELETERDBSTORE_PROMISE_0100 - * @tc.desc rdb store deleteRdbStore - * @tc.require: I5PIL6 - */ - it('SUB_DDM_RELATIONALETS_DELETERDBSTORE_PROMISE_0100', 0, async function (done) { - console.log(TAG + "************* SUB_DDM_RELATIONALETS_DELETERDBSTORE_PROMISE_0100 start *************"); - let config = { - name: "secure.db", - securityLevel: dataRdb.SecurityLevel.S4 - } - let deleteResult = false - await dataRdb.getRdbStore(context, config).then(async (store) => { - console.info(TAG + "create table success") + console.log(TAG + "************* SUB_DDM_RELATIONALETS_DELETERDBSTORE_PROMISE_0100 end *************"); }) - await dataRdb.deleteRdbStore(context,"secure.db").then(() => { - deleteResult = true - console.info(`${TAG} delete rdb store success,result is ${deleteResult}`) - }); - expect(deleteResult).assertTrue(); - done(); - console.log(TAG + "************* SUB_DDM_RELATIONALETS_DELETERDBSTORE_PROMISE_0100 end *************"); - }) - /** - * @tc.name rdb store deleteRdbStore - * @tc.number SUB_DDM_RELATIONALETS_DELETERDBSTORE_CALLBACK_0100 - * @tc.desc rdb store deleteRdbStore - * @tc.require: I5PIL6 - */ - it('SUB_DDM_RELATIONALETS_DELETERDBSTORE_CALLBACK_0100', 0, async function (done) { - console.log(TAG + "************* SUB_DDM_RELATIONALETS_DELETERDBSTORE_CALLBACK_0100 start *************"); - let config = { - name: "secure.db", - securityLevel: dataRdb.SecurityLevel.S1 - } - let deleteResult = false - await dataRdb.getRdbStore(context, config).then(async (store) => { - console.info(TAG + "create rdb store success") - }) - dataRdb.deleteRdbStore(context,"secure.db", (err, data) => { - if(err == undefined){ - deleteResult = true - console.info(`${TAG} delete rdb store success,result is ${deleteResult}`) + /** + * @tc.name rdb store deleteRdbStore + * @tc.number SUB_DDM_RELATIONALETS_DELETERDBSTORE_CALLBACK_0100 + * @tc.desc rdb store deleteRdbStore + * @tc.require: I5PIL6 + */ + it('SUB_DDM_RELATIONALETS_DELETERDBSTORE_CALLBACK_0100', 0, async function (done) { + console.log(TAG + "************* SUB_DDM_RELATIONALETS_DELETERDBSTORE_CALLBACK_0100 start *************"); + let config = { + name: "secure.db", + securityLevel: dataRdb.SecurityLevel.S1 } - done(); + let deleteResult = false + await dataRdb.getRdbStore(context, config).then(async (store) => { + console.info(TAG + "create rdb store success") + dataRdb.deleteRdbStore(context,"secure.db", (err, data) => { + if(err == undefined){ + deleteResult = true + console.info(`${TAG} delete rdb store success,result is ${deleteResult}`) + } + }) + await sleep(1000) + expect(deleteResult).assertTrue(); + done(); + }) + console.log(TAG + "************* SUB_DDM_RELATIONALETS_DELETERDBSTORE_CALLBACK_0100 end *************"); }) - await sleep(1000) - expect(deleteResult).assertTrue(); - done(); - console.log(TAG + "************* SUB_DDM_RELATIONALETS_DELETERDBSTORE_CALLBACK_0100 end *************"); + console.log(TAG + "*************Unit Test End*************"); }) - console.log(TAG + "*************Unit Test End*************"); -}) } \ No newline at end of file -- GitLab