From 78c960a3f3ce94974c607555672607352d18d57f Mon Sep 17 00:00:00 2001 From: YOUR_NAME <2864429926@qq.com> Date: Wed, 25 Aug 2021 07:25:25 +0000 Subject: [PATCH] zzy --- entry/src/main/js/test/List.test.js | 3 +- .../js/test/rdbstore_resultset_unit.test.js | 262 ++++++++++++++++++ 2 files changed, 264 insertions(+), 1 deletion(-) create mode 100755 entry/src/main/js/test/rdbstore_resultset_unit.test.js diff --git a/entry/src/main/js/test/List.test.js b/entry/src/main/js/test/List.test.js index ec5f11a..1f9ebfe 100644 --- a/entry/src/main/js/test/List.test.js +++ b/entry/src/main/js/test/List.test.js @@ -1,3 +1,4 @@ require('./rdbstore_insert_unit.test.js') require('./rdbstore_update_unit.test.js') -require('./rdbstore_replace_unit.test.js') \ No newline at end of file +require('./rdbstore_replace_unit.test.js') +require('./rdbstore_resultset_unit.test.js') \ No newline at end of file diff --git a/entry/src/main/js/test/rdbstore_resultset_unit.test.js b/entry/src/main/js/test/rdbstore_resultset_unit.test.js new file mode 100755 index 0000000..804a581 --- /dev/null +++ b/entry/src/main/js/test/rdbstore_resultset_unit.test.js @@ -0,0 +1,262 @@ +/* + * Copyright (C) 2021 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * limitations under the License. + */ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' +import ohos_data_rdb from '@ohos.data.rdb'; + +const ROW_COUNT = 3; +const TAG = "[RDB_JSKITS_TEST]"; +const ERRCODE=1000; +const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "BlogType Uint8Array, " + "inType int, " + "longType long, " + "flotType float," + "doubleType double," + "stringType text," + "byteArray blob)"; + +const STORE_CONFIG = { + path: "/data/accounts/account_0/appdata/ohos.samples.jshelloworld/database/Resultset.db", + storageMode: 0, // ohos_data_rdb.StorageMode.MODE_DISK, + readOnly: false, + fileType: 0, // ohos_data_rdb.DatabaseFileType.NORMAL, + encryptKey: [1, 2, 3, 4, 5, 6, 7], + journalMode: 0, // ohos_data_rdb.JournalMode.MODE_DELETE, + syncMode: 0, //ohos_data_rdb.SyncMode.MODE_OFF +} + +const CALL_BACK = { + onCreate: () => { + console.info(TAG + "onCreate on called") + }, + onUpgrade: (versionAction) => { + console.info(TAG + "onUpgrade on called:currentVersion = " + versionAction.currentVersion + ", targetVersion = " + versionAction.targetVersion) + }, + onDowngrade: (versionAction) => { + console.info(TAG + "onDowngrade on called:currentVersion = " + versionAction.currentVersion + ", targetVersion = " + versionAction.targetVersion) + }, + onOpen: () => { + console.info(TAG + "onOpen on called") + }, + onCorruption: (databaseFile) => { + console.info(TAG + "onOpen on called:databaseFile = " + databaseFile) + }, +} +var rdbStore = null; + +describe('rdbResultSetTest', function () { + beforeAll(async function () { + console.info(TAG + 'beforeAll') + rdbStore = await ohos_data_rdb.getRdbStore(STORE_CONFIG, 1, CALL_BACK); + await rdbStore.executeSql(CREATE_TABLE_TEST, null); + }) + + beforeEach(function () { + console.info(TAG + 'beforeEach') + }) + + afterEach(function () { + console.info(TAG + 'afterEach') + }) + + afterAll(async function () { + console.info(TAG + 'afterAll') + rdbStore = null + await ohos_data_rdb.deleteRdbStore("data/accounts/account_0/appdata/ohos.samples.jshelloworld/database/Resultset.db"); + }) + //getColumnCount + it('rdbResultgetColumnCount', 0, async function (done) { + console.log(TAG + "************* rdbResultgetColumnCount start *************"); + { + + expect(8).assertEqual(resultSet.getColumnCount()); + console.log("we got 8"); + done(); + await console.log(TAG + "************* rdbResultgetColumnCount end *************"); + } + }) + //getColumnTypeForIndex + it('rdbResultgetColumnTypeForIndex', 0, async function (done) { + console.log(TAG + "************* rdbResultgetColumnCount start *************"); + { + + expect(1).assertEqual(resultSet.getColumnTypeForIndex("INTEGER")) + expect(2).assertEqual(resultSet.getColumnTypeForIndex("Uint8Array")) + await console.log("getColumnTypeForIndex done") + + done(); + await console.log(TAG + "************* rdbResultgetColumnTypeForIndex end *************"); + } + }) + //getRowIndex + it('rdbResultgetRowIndex', 0, async function (done) { + console.log(TAG + "************* getRowIndex start *************"); + { + const valueBucket = { + "blobType": [1,2,3], + "longType": 26123456, + "doubleType": 26.3, + "stringType": "123" + }; + let insertPromise = await rdbStore.insert("test", valueBucket); + expect(1).assertEqual(insertPromise); + await console.log(TAG + "insert first done: " + insertPromise); + } + { + const valueBucket = { + "blobType": [2,3,4], + "longType": 36456456, + "doubleType": 26.3, + "stringType": "123" + }; + let insertPromise = await rdbStore.insert("test", valueBucket); + expect(2).assertEqual(insertPromise); + await console.log(TAG + "insert second done: " + insertPromise); + } + { + const valueBucket = { + "blobType": [4,5,6], + "longType": 46789789, + "doubleType": 26.3, + "stringType": "123" + }; + let insertPromise = await rdbStore.insert("test", valueBucket); + expect(3).assertEqual(insertPromise); + await console.log(TAG + "insert third done: " + insertPromise); + } + + { expect(true).assertEqual(resultSet.gotoFirstRow()); + expect(true).assertEqual(resultSet.gotoNextRow()); + expect(2).assertEqual(resultSet.getRowIndex()); + await console.log("getRowIndex done"); + + done(); + await console.log(TAG + "************* rdbResultgetRowIndex end *************");} + + }) + //getRowCount + it('rdbResultgetgetRowCount', 0, async function (done) { + console.log(TAG + "************* rdbResultgetgetRowCount start *************"); + { + expect(true).assertEqual(resultSet.gotoFirstRow()) + expect(3).assertEqual(resultSet.getRowCount()) + await console.log("we got 3") + done(); + await console.log(TAG + "************* rdbResultgetgetRowCount end *************"); + } + }) + + + //getRowIndex + it('rdbResultgoToPreviousRow', 0, async function (done) { + console.log(TAG + "************* rdbResultgoToPreviousRow start *************"); + { + expect(true).assertEqual(resultSet.gotoFirstRow()) + expect(true).assertEqual(resultSet.gotoNextRow()) + expect(true).assertEqual(resultSet.gotoNextRow()) + expect(true).assertEqual(resultSet.goToPreviousRow()) + expect(2).assertEqual(resultSet.getRowIndex()) + await console.log("we got 2") + done(); + await console.log(TAG + "************* rdbResultgoToPreviousRow end *************"); + } + }) + //isAtFirstRow + it('rdbResultisAtFirstRow', 0, async function (done) { + console.log(TAG + "************* rdbResultisAtFirstRow start *************"); + { + expect(true).assertEqual(resultSet.gotoFirstRow()); + try { + expect(true).assertEqual(resultSet.gotoNextRow()); + expect(true).assertEqual(resultSet.gotoNextRow()); + expect(false).assertEqual(resultSet.isAtFirstRow()); + await console.log(" not AtFirstRow"); + } catch (error) { + expect(null).assertFail(); + } + + + await console.log("not firstrow"); + done(); + await console.log(TAG + "************* rdbResultisAtFirstRow end *************"); + } + }) + + //isAtLastRow + it('rdbResultisAtFirstRow', 0, async function (done) { + console.log(TAG + "************* isAtLastRow start *************"); + { + expect(true).assertEqual(resultSet.gotoLastRow()); + try { + expect(true).assertEqual(resultSet.isAtLastRow()); + await console.log("at LastRow") + } catch (error) { + expect(null).assertFail(); + } + + done(); + await console.log(TAG + "************* isAtLastRow end *************"); + } + }) + + //GoToPreviousRow + it('rdbResultGoToPreviousRow', 0, async function (done) { + console.log(TAG + "************* rdbResultGoToPreviousRow start *************"); + { + expect(true).assertEqual(resultSet.gotoLastRow()); + try { + expect(2).assertEqual(resultSet.GoToPreviousRow()); + await console.log("go to line2"); + } catch (error) { + expect(null).assertFail(); + } + + done(); + await console.log(TAG + "************* rdbResultGoToPreviousRow end *************"); + } + }) + + //GoToRow + it('rdbResultGoToRow', 0, async function (done) { + console.log(TAG + "************* rdbResultGoToRow start *************"); + { + try { + let queryPromise = await rdbStore.querSql("SELECT * FROM test", null); + expect(2).assertEqual(resultSet.GoToRow(2)) + const id = queryPromise.getLong(queryPromise.getColumnIndexForName("id")) + const blobType = queryPromise.getBlob(queryPromise.getColumnIndexForName("blobType")) + const longType = queryPromise.getString(queryPromise.getColumnIndexForName("longType")) + const doubleType = queryPromise.getLong(queryPromise.getColumnIndexForName("doubleType")) + const stringType = queryPromise.getDouble(queryPromise.getColumnIndexForName("stringType")) + await console.log(TAG + "{id=" + id + ", blobType=" + blobType + ", longType=" + longType + ", doubleType=" + doubleType + ", stringType=" + stringType); + expect(2).assertEqual(id); + expect([2,3,4]).assertEqual(blobType); + expect(36456456).assertEqual(longType); + expect(26.3).assertEqual(doubleType); + expect("123").assertEqual(stringType); + } catch (error) { + expect(null).assertFail(); + } + done(); + await console.log(TAG + "************* GoToRow end *************"); + } + }) + //GetInt + it('rdbResultGetInt', 0, async function (done) { + console.log(TAG + "************* rdbResultGetInt start *************"); + expect(0).resultSet.getColumnIndexForName("id",1) + expect(0).resultSet.GetInt(1,1); + await console.log("rdbResultGetInt done"); + }) + //GetLong + it('rdbResultGetLong', 0, async function (done) { + console.log(TAG + "************* rdbResultGetLong start *************"); + expect(0).resultSet.getColumnIndexForName("LongType",2) + expect(0).resultSet.GetInt(2,26123456); + await console.log("rdbResultGetLong done"); + }) +}) -- Gitee