Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
0beda5cb
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
大约 1 年 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0beda5cb
编写于
8月 09, 2022
作者:
L
liangzhenyu123
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
liangzhenyu6@huawei.com
Signed-off-by:
N
liangzhenyu123
<
liangzhenyu6@huawei.com
>
上级
7c917232
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
2107 addition
and
100 deletion
+2107
-100
distributeddatamgr/kvStorejstest/hap/src/main/js/test/KvManagerPromiseJsunit.test.js
...stest/hap/src/main/js/test/KvManagerPromiseJsunit.test.js
+89
-0
distributeddatamgr/relationalStorejstest/hap/src/main/js/test/List.test.js
...r/relationalStorejstest/hap/src/main/js/test/List.test.js
+4
-0
distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreBackupRestoreCallbackJsunit.test.js
.../main/js/test/RdbstoreBackupRestoreCallbackJsunit.test.js
+459
-0
distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreBackupRestoreWithFAContextJsunit.test.js
.../js/test/RdbstoreBackupRestoreWithFAContextJsunit.test.js
+249
-77
distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreInsertJsunit.test.js
...ejstest/hap/src/main/js/test/RdbstoreInsertJsunit.test.js
+883
-4
distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreQuery.test.js
...nalStorejstest/hap/src/main/js/test/RdbstoreQuery.test.js
+349
-0
distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreRdbstoreJsunit.test.js
...stest/hap/src/main/js/test/RdbstoreRdbstoreJsunit.test.js
+74
-19
未找到文件。
distributeddatamgr/kvStorejstest/hap/src/main/js/test/KvManagerPromiseJsunit.test.js
浏览文件 @
0beda5cb
...
...
@@ -14,6 +14,10 @@
*/
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
import
factory
from
'
@ohos.data.distributedData
'
;
import
abilityFeatureAbility
from
'
@ohos.ability.featureAbility
'
;
var
context
=
abilityFeatureAbility
.
getContext
();
var
contextApplication
=
context
.
getApplicationContext
()
const
TEST_BUNDLE_NAME
=
'
ohos.acts.kvStore
'
;
const
TEST_STORE_ID
=
'
storeId
'
;
...
...
@@ -863,6 +867,91 @@ describe('kvManagerPromiseTest', function () {
}
done
();
})
/**
* @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_CONTEXT_1000
* @tc.name [JS-API9]KVManagerConfig.context
* @tc.desc Test Js Api createKVManager testcase 001
*/
it
(
'
testcreateKVManager001
'
,
0
,
async
function
(
done
)
{
console
.
info
(
'
testcreateKVManager001
'
);
const
config
=
{
bundleName
:
TEST_BUNDLE_NAME
,
userInfo
:
{
userId
:
'
0
'
,
userType
:
factory
.
UserType
.
SAME_USER_ID
},
context
:
context
}
try
{
await
factory
.
createKVManager
(
config
).
then
((
manager
)
=>
{
kvManager
=
manager
;
expect
(
manager
!=
null
).
assertTrue
();
console
.
info
(
'
testcreateKVManager001 createKVManager success
'
);
kvManager
.
getKVStore
(
TEST_STORE_ID
,
options
).
then
(
async
(
store
)
=>
{
console
.
info
(
"
testcreateKVManager001 getKVStore success
"
);
await
store
.
put
(
"
createKVManager
"
,
"
success
"
).
then
(
async
()
=>
{
await
store
.
get
(
"
craeteKVManager
"
,
"
defaultValue
"
).
then
((
data
)
=>
{
expect
(
"
success
"
).
assertEqual
(
data
)
console
.
info
(
"
testcreateKVManager001 put data success
"
)
})
})
}).
catch
((
err
)
=>
{
console
.
info
(
"
testcreateKVManager001 getKVStore err:
"
+
JSON
.
stringify
(
err
));
expect
(
null
).
assertFail
();
});
}).
catch
((
err
)
=>
{
console
.
info
(
'
testcreateKVManager001 createKVManager err
'
+
err
);
expect
(
null
).
assertFail
()
});
}
catch
(
e
)
{
console
.
info
(
'
testcreateKVManager001 promise delete fail err
'
+
err
);
expect
(
null
).
assertFail
();
}
done
();
})
/**
* @tc.number SUB_DISTRIBUTEDDATAMGR_KVMANAGER_CONTEXTAPPLICATION_1000
* @tc.name [JS-API9]KVManagerConfig.context
* @tc.desc Test Js Api createKVManager testcase 001
*/
it
(
'
testcreateKVManager002
'
,
0
,
async
function
(
done
)
{
console
.
info
(
'
testcreateKVManager002
'
);
const
config
=
{
bundleName
:
TEST_BUNDLE_NAME
,
userInfo
:
{
userId
:
'
0
'
,
userType
:
factory
.
UserType
.
SAME_USER_ID
},
context
:
contextApplication
}
try
{
await
factory
.
createKVManager
(
config
).
then
((
manager
)
=>
{
kvManager
=
manager
;
console
.
info
(
'
testcreateKVManager002 createKVManager success
'
);
kvManager
.
getKVStore
(
TEST_STORE_ID
,
options
).
then
(
async
(
store
)
=>
{
console
.
info
(
"
testcreateKVManager002 getKVStore success
"
);
await
store
.
put
(
"
createKVManager
"
,
"
success
"
).
then
(
async
()
=>
{
await
store
.
get
(
"
craeteKVManager
"
,
"
defaultValue
"
).
then
((
data
)
=>
{
expect
(
"
success
"
).
assertEqual
(
data
)
console
.
info
(
"
testcreateKVManager002 put data success
"
)
})
})
}).
catch
((
err
)
=>
{
console
.
info
(
"
testcreateKVManager002 getKVStore err:
"
+
JSON
.
stringify
(
err
));
expect
(
null
).
assertFail
();
});
}).
catch
((
err
)
=>
{
console
.
info
(
'
testcreateKVManager002 createKVManager err
'
+
err
);
expect
(
null
).
assertFail
()
});
}
catch
(
e
)
{
console
.
info
(
'
testcreateKVManager002 promise delete fail err
'
+
err
);
expect
(
null
).
assertFail
();
}
done
();
})
})
}
\ No newline at end of file
distributeddatamgr/relationalStorejstest/hap/src/main/js/test/List.test.js
浏览文件 @
0beda5cb
...
...
@@ -12,6 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
rdbStoreBackupRestoreCallbackTest
from
'
./RdbstoreBackupRestoreCallbackJsunit.test.js
'
import
rdbStoreBackupRestoreWithFAContextTest
from
'
./RdbstoreBackupRestoreWithFAContextJsunit.test.js
'
import
rdbstoreChangeEncryptKeyTest
from
'
./RdbstoreChangeEncryptKeyJsunit.test.js
'
import
rdbStoreDeleteTest
from
'
./RdbstoreDeleteJsunit.test.js
'
...
...
@@ -24,7 +25,9 @@ import rdbResultSetTest from './RdbStoreResultSetJsunit.test.js'
import
rdbstoreStoreExcuteSqlTest
from
'
./RdbstoreStoreExcuteSqlJsunit.test.js
'
import
rdbstoreTransactionTest
from
'
./RdbstoreTransactionJsunit.test.js
'
import
rdbStoreUpdateTest
from
'
./RdbstoreUpdateJsunit.test.js
'
import
rdbstoreQueryTest
from
'
./RdbstoreQuery.test.js
'
export
default
function
testsuite
()
{
rdbStoreBackupRestoreCallbackTest
()
rdbStoreBackupRestoreWithFAContextTest
()
rdbstoreChangeEncryptKeyTest
()
rdbStoreDeleteTest
()
...
...
@@ -37,4 +40,5 @@ rdbResultSetTest()
rdbstoreStoreExcuteSqlTest
()
rdbstoreTransactionTest
()
rdbStoreUpdateTest
()
rdbstoreQueryTest
()
}
distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreBackupRestoreCallbackJsunit.test.js
0 → 100644
浏览文件 @
0beda5cb
/*
* 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
*
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
import
dataRdb
from
'
@ohos.data.rdb
'
import
abilityFeatureAbility
from
'
@ohos.ability.featureAbility
'
import
fileio
from
'
@ohos.fileio
'
const
TAG
=
"
[RDB_JSKITS_TEST]
"
const
CREATE_TABLE_TEST
=
"
CREATE TABLE IF NOT EXISTS backupTest (
"
+
"
id INTEGER PRIMARY KEY AUTOINCREMENT,
"
+
"
name TEXT NOT NULL,
"
+
"
age INTEGER,
"
+
"
salary REAL,
"
+
"
blobType BLOB)
"
const
DATABASE_DIR
=
"
/data/storage/el2/database/entry/rdb/
"
var
RdbStore
var
context
const
STORE_CONFIG
=
{
name
:
"
BackupResotreTest.db
"
,
}
const
DATABASE_BACKUP_NAME
=
"
Backup.db
"
async
function
CreatRdbStore
(
context
,
STORE_CONFIG
)
{
let
RdbStore
=
await
dataRdb
.
getRdbStore
(
context
,
STORE_CONFIG
,
1
)
await
RdbStore
.
executeSql
(
CREATE_TABLE_TEST
,
null
)
let
u8
=
new
Uint8Array
([
1
,
2
,
3
])
{
const
valueBucket
=
{
"
name
"
:
"
zhangsan
"
,
"
age
"
:
18
,
"
salary
"
:
100.5
,
"
blobType
"
:
u8
,
}
await
RdbStore
.
insert
(
"
backupTest
"
,
valueBucket
)
}
{
const
valueBucket
=
{
"
name
"
:
"
lisi
"
,
"
age
"
:
28
,
"
salary
"
:
100.5
,
"
blobType
"
:
u8
,
}
await
RdbStore
.
insert
(
"
backupTest
"
,
valueBucket
)
}
{
const
valueBucket
=
{
"
name
"
:
"
wangwu
"
,
"
age
"
:
38
,
"
salary
"
:
90.0
,
"
blobType
"
:
u8
,
}
await
RdbStore
.
insert
(
"
backupTest
"
,
valueBucket
)
}
return
RdbStore
}
function
BackupCallbackTest
(
backupName
)
{
try
{
RdbStore
.
backup
(
backupName
,
(
err
,
data
)
=>
{
if
(
err
!=
null
){
console
.
info
(
TAG
+
"
Backup error:
"
+
err
)
expect
(
true
).
assertTrue
()
}
else
{
expect
(
false
).
assertTrue
();
}
})
}
catch
(
errInfo
){
console
.
info
(
TAG
+
"
BackupCallbackTest error:
"
+
errInfo
)
expect
(
true
).
assertTrue
()
}
RdbStore
=
null
}
function
ReStoreCallbackTest
(
restoreName
)
{
try
{
RdbStore
.
restore
(
restoreName
,
(
err
,
data
)
=>
{
if
(
err
!=
null
){
console
.
info
(
TAG
+
"
Restore error:
"
+
err
)
expect
(
true
).
assertTrue
()
}
else
{
expect
(
false
).
assertTrue
();
}
})
}
catch
(
errInfo
)
{
console
.
info
(
TAG
+
"
ReStoreCallbackTest error:
"
+
errInfo
)
expect
(
true
).
assertTrue
()
}
RdbStore
=
null
}
export
default
function
rdbStoreBackupRestoreCallbackTest
()
{
describe
(
'
rdbStoreBackupRestoreCallbackTest
'
,
function
()
{
beforeAll
(
async
function
()
{
console
.
info
(
TAG
+
'
beforeAll
'
)
})
beforeEach
(
async
function
()
{
console
.
info
(
TAG
+
'
beforeEach
'
)
context
=
abilityFeatureAbility
.
getContext
()
RdbStore
=
await
CreatRdbStore
(
context
,
STORE_CONFIG
)
})
afterEach
(
async
function
()
{
console
.
info
(
TAG
+
'
afterEach
'
)
await
dataRdb
.
deleteRdbStore
(
context
,
STORE_CONFIG
.
name
)
await
dataRdb
.
deleteRdbStore
(
context
,
DATABASE_BACKUP_NAME
)
await
dataRdb
.
deleteRdbStore
(
context
,
"
BackupTest003.db
"
)
})
afterAll
(
async
function
()
{
console
.
info
(
TAG
+
'
afterAll
'
)
})
console
.
info
(
TAG
+
"
*************Unit Test Begin*************
"
)
/**
* @tc.name RDB Backup Restore test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreCallbackTest_0100
* @tc.desc RDB backup and restore function test
*/
it
(
'
RdbBackupRestoreCallbackTest_0100
'
,
0
,
async
function
(
done
)
{
console
.
info
(
TAG
+
"
************* RdbBackupRestoreCallbackTest_0100 start *************
"
)
// RDB backup function test
await
RdbStore
.
backup
(
DATABASE_BACKUP_NAME
,
(
err
,
data
)
=>
{
if
(
err
!=
null
){
expect
(
false
).
assertTrue
()
}
else
{
try
{
fileio
.
accessSync
(
DATABASE_DIR
+
DATABASE_BACKUP_NAME
)
fileio
.
accessSync
(
DATABASE_DIR
+
STORE_CONFIG
.
name
)
}
catch
(
err
)
{
expect
(
false
).
assertTrue
()
}
}
})
// RDB before restored, delete data
let
deleteData
=
new
dataRdb
.
RdbPredicates
(
"
backupTest
"
)
deleteData
.
equalTo
(
"
name
"
,
"
zhangsan
"
)
await
RdbStore
.
delete
(
deleteData
)
// RDB restore function test
await
RdbStore
.
restore
(
DATABASE_BACKUP_NAME
,
async
(
err
,
data
)
=>
{
if
(
err
!=
null
){
expect
(
false
).
assertTrue
()
}
else
{
try
{
fileio
.
accessSync
(
DATABASE_DIR
+
DATABASE_BACKUP_NAME
)
expect
(
false
).
assertTrue
()
}
catch
(
err
)
{
expect
(
true
).
assertTrue
()
}
try
{
fileio
.
accessSync
(
DATABASE_DIR
+
STORE_CONFIG
.
name
)
}
catch
(
err
)
{
expect
(
false
).
assertTrue
()
}
let
predicates
=
new
dataRdb
.
RdbPredicates
(
"
backupTest
"
)
predicates
.
equalTo
(
"
name
"
,
"
zhangsan
"
)
let
resultSet
=
await
RdbStore
.
query
(
predicates
)
try
{
console
.
info
(
TAG
+
"
After restore resultSet query done
"
)
expect
(
true
).
assertEqual
(
resultSet
.
goToFirstRow
())
const
id
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
id
"
))
const
name
=
resultSet
.
getString
(
resultSet
.
getColumnIndex
(
"
name
"
))
const
blobType
=
resultSet
.
getBlob
(
resultSet
.
getColumnIndex
(
"
blobType
"
))
expect
(
1
).
assertEqual
(
id
)
expect
(
"
zhangsan
"
).
assertEqual
(
name
)
expect
(
1
).
assertEqual
(
blobType
[
0
])
}
catch
(
err
)
{
console
.
info
(
TAG
+
'
RdbBackupRestoreTest_0010 accessSync err4:
'
+
err
)
expect
(
false
).
assertTrue
()
}
resultSet
=
null
RdbStore
=
null
}
})
done
()
console
.
info
(
TAG
+
"
************* RdbBackupRestoreCallbackTest_0100 end *************
"
)
})
/**
* @tc.name RDB Backup test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreCallbackTest_0200
* @tc.desc RDB backup function test
*/
it
(
'
RdbBackupRestoreCallbackTest_0200
'
,
0
,
function
(
done
)
{
console
.
info
(
TAG
+
"
************* RdbBackupRestoreCallbackTest_0200 start *************
"
)
// RDB backup function test, backup file name empty
BackupCallbackTest
(
""
)
// RDB backup function test, backup file name already exists
BackupCallbackTest
(
STORE_CONFIG
.
name
)
done
()
console
.
info
(
TAG
+
"
************* RdbBackupRestoreCallbackTest_0200 end *************
"
)
})
/**
* @tc.name RDB BackupRestore test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0300
* @tc.desc RDB restore function test
*/
it
(
'
RdbBackupRestoreCallbackTest_0300
'
,
0
,
async
function
(
done
)
{
console
.
info
(
TAG
+
"
************* RdbBackupRestoreCallbackTest_0300 start *************
"
)
let
backupName
=
"
BackupTest003.db
"
await
RdbStore
.
backup
(
backupName
)
// RDB restore function test, backup file name empty
ReStoreCallbackTest
(
""
)
// RDB restore function test, backup file is specified to database name
ReStoreCallbackTest
(
STORE_CONFIG
.
name
)
done
()
console
.
info
(
TAG
+
"
************* RdbBackupRestoreCallbackTest_0300 end *************
"
)
})
/**
* @tc.name RDB BackupRestore test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreCallbackTest_0400
* @tc.desc RDB restore function test
*/
it
(
'
RdbBackupRestoreCallbackTest_0400
'
,
0
,
async
function
(
done
)
{
console
.
info
(
TAG
+
"
************* RdbBackupRestoreCallbackTest_0400 start *************
"
)
let
dbName
=
"
notExistName.db
"
// RDB restore function test, backup file does not exists
try
{
fileio
.
accessSync
(
DATABASE_DIR
+
dbName
)
expect
(
false
).
assertTrue
()
}
catch
{
ReStoreCallbackTest
(
dbName
)
}
done
()
console
.
info
(
TAG
+
"
************* RdbBackupRestoreCallbackTest_0400 end *************
"
)
})
/**
* @tc.name RDB BackupRestore test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreCallbackTest_0500
* @tc.desc RDB restore function test
*/
it
(
'
RdbBackupRestoreCallbackTest_0500
'
,
0
,
async
function
(
done
)
{
console
.
info
(
TAG
+
"
************* RdbBackupRestoreCallbackTest_0500 start *************
"
)
// RDB restore function test, backup file
RdbStore
.
backup
(
DATABASE_BACKUP_NAME
,
(
err
,
data
)
=>
{
if
(
err
!=
null
){
expect
(
false
).
assertTrue
(
0
)
}
else
{
try
{
console
.
info
(
TAG
+
'
Backup database success
'
)
fileio
.
accessSync
(
DATABASE_DIR
+
DATABASE_BACKUP_NAME
)
}
catch
(
err
){
expect
(
false
).
assertTrue
();
}
}
})
await
dataRdb
.
deleteRdbStore
(
context
,
DATABASE_BACKUP_NAME
).
then
(()
=>
{
try
{
fileio
.
accessSync
(
DATABASE_DIR
+
DATABASE_BACKUP_NAME
)
}
catch
(
err
){
console
.
info
(
TAG
+
'
error2
'
+
err
)
expect
(
true
).
assertTrue
();
}
})
RdbStore
.
backup
(
DATABASE_BACKUP_NAME
,
(
err
,
data
)
=>
{
if
(
err
!=
null
){
expect
(
false
).
assertTrue
(
0
)
}
else
{
try
{
console
.
info
(
TAG
+
'
Backup database success
'
)
fileio
.
accessSync
(
DATABASE_DIR
+
DATABASE_BACKUP_NAME
)
}
catch
(
err
){
expect
(
false
).
assertTrue
();
}
}
})
done
()
console
.
info
(
TAG
+
"
************* RdbBackupRestoreCallbackTest_0500 end *************
"
)
})
/**
* @tc.name RDB BackupRestore test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreCallbackTest_0600
* @tc.desc RDB restore function test
*/
it
(
'
RdbBackupRestoreCallbackTest_0600
'
,
0
,
async
function
(
done
)
{
console
.
info
(
TAG
+
"
************* RdbBackupRestoreCallbackTest_0600 start *************
"
)
// Backup file is specified to database name
RdbStore
.
backup
(
STORE_CONFIG
.
name
,
(
err
,
data
)
=>
{
if
(
err
!=
null
){
expect
(
true
).
assertTrue
()
}
else
{
expect
(
false
).
assertTrue
()
}
})
RdbStore
.
backup
(
STORE_CONFIG
.
name
,
(
err
,
data
)
=>
{
if
(
err
!=
null
){
expect
(
true
).
assertTrue
()
}
else
{
expect
(
false
).
assertTrue
()
}
})
done
();
console
.
info
(
TAG
+
"
************* RdbBackupRestoreCallbackTest_0600 end *************
"
)
})
/**
* @tc.name RDB BackupRestore test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreCallbackTest_0700
* @tc.desc RDB restore function test
*/
it
(
'
RdbBackupRestoreCallbackTest_0700
'
,
0
,
async
function
(
done
)
{
console
.
info
(
TAG
+
"
************* RdbBackupRestoreCallbackTest_0700 start *************
"
)
RdbStore
.
backup
(
DATABASE_BACKUP_NAME
,
(
err
,
data
)
=>
{
if
(
err
!=
null
){
expect
(
false
).
assertTrue
()
}
else
{
expect
(
true
).
assertTrue
()
}
})
await
dataRdb
.
deleteRdbStore
(
context
,
DATABASE_BACKUP_NAME
).
then
(()
=>
{
try
{
fileio
.
accessSync
(
DATABASE_DIR
+
DATABASE_BACKUP_NAME
)
}
catch
(
err
){
expect
(
true
).
assertTrue
();
}
})
RdbStore
.
restore
(
DATABASE_BACKUP_NAME
,
(
err
,
data
)
=>
{
if
(
err
!=
null
){
expect
(
true
).
assertTrue
()
}
})
done
();
console
.
info
(
TAG
+
"
************* RdbBackupRestoreCallbackTest_0700 end *************
"
)
})
/**
* @tc.name RDB BackupRestore test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreCallbackTest_0800
* @tc.desc RDB restore function test
*/
it
(
'
RdbBackupRestoreCallbackTest_0800
'
,
0
,
async
function
(
done
)
{
console
.
info
(
TAG
+
"
************* RdbBackupRestoreCallbackTest_0800 start *************
"
)
BackupCallbackTest
()
done
();
console
.
info
(
TAG
+
"
************* RdbBackupRestoreCallbackTest_0800 end *************
"
)
})
/**
* @tc.name RDB BackupRestore test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreCallbackTest_0900
* @tc.desc RDB restore function test
*/
it
(
'
RdbBackupRestoreCallbackTest_0900
'
,
0
,
async
function
(
done
)
{
console
.
info
(
TAG
+
"
************* RdbBackupRestoreCallbackTest_0900 start *************
"
)
BackupCallbackTest
([
DATABASE_BACKUP_NAME
])
done
();
console
.
info
(
TAG
+
"
************* RdbBackupRestoreCallbackTest_0900 end *************
"
)
})
/**
* @tc.name RDB BackupRestore test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreCallbackTest_1000
* @tc.desc RDB restore function test
*/
it
(
'
RdbBackupRestoreCallbackTest_1000
'
,
0
,
async
function
(
done
)
{
console
.
info
(
TAG
+
"
************* RdbBackupRestoreCallbackTest_1000 start *************
"
)
RdbStore
.
backup
(
DATABASE_BACKUP_NAME
,
(
err
,
data
)
=>
{
if
(
err
!=
null
){
expect
(
false
).
assertTrue
()
}
})
ReStoreCallbackTest
([
DATABASE_BACKUP_NAME
])
done
();
console
.
info
(
TAG
+
"
************* RdbBackupRestoreCallbackTest_1000 end *************
"
)
})
/**
* @tc.name RDB BackupRestore test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreCallbackTest_1100
* @tc.desc RDB restore function test
*/
it
(
'
RdbBackupRestoreCallbackTest_1100
'
,
0
,
async
function
(
done
)
{
console
.
info
(
TAG
+
"
************* RdbBackupRestoreCallbackTest_1100 start *************
"
)
RdbStore
.
backup
(
DATABASE_BACKUP_NAME
,
(
err
,
data
)
=>
{
if
(
err
!=
null
){
expect
(
false
).
assertTrue
()
}
})
ReStoreCallbackTest
()
done
();
console
.
info
(
TAG
+
"
************* RdbBackupRestoreCallbackTest_1100 end *************
"
)
})
/**
* @tc.name RDB BackupRestore test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreCallbackTest_1200
* @tc.desc RDB restore function test
*/
it
(
'
RdbBackupRestoreCallbackTest_1200
'
,
0
,
async
function
(
done
)
{
console
.
info
(
TAG
+
"
************* RdbBackupRestoreCallbackTest_1200 start *************
"
)
RdbStore
.
backup
(
DATABASE_BACKUP_NAME
,
(
err
,
data
)
=>
{
if
(
err
!=
null
){
expect
(
false
).
assertTrue
()
}
})
BackupCallbackTest
(
DATABASE_BACKUP_NAME
)
done
();
console
.
info
(
TAG
+
"
************* RdbBackupRestoreCallbackTest_1200 end *************
"
)
})
/**
* @tc.name RDB BackupRestore test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreCallbackTest_1300
* @tc.desc RDB restore function test
*/
it
(
'
RdbBackupRestoreCallbackTest_1300
'
,
0
,
async
function
(
done
)
{
console
.
info
(
TAG
+
"
************* RdbBackupRestoreCallbackTest_1300 start *************
"
)
RdbStore
.
backup
(
DATABASE_BACKUP_NAME
,
(
err
,
data
)
=>
{
if
(
err
!=
null
){
expect
(
false
).
assertTrue
()
}
else
{
RdbStore
.
restore
(
DATABASE_BACKUP_NAME
,
(
err
,
data
)
=>
{
if
(
err
!=
null
){
expect
(
false
).
assertTrue
()
}
else
{
ReStoreCallbackTest
(
DATABASE_BACKUP_NAME
)
}
})
}
})
done
();
console
.
info
(
TAG
+
"
************* RdbBackupRestoreCallbackTest_1300 end *************
"
)
})
console
.
info
(
TAG
+
"
*************Unit Test End*************
"
)
})
}
\ No newline at end of file
distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreBackupRestoreWithFAContextJsunit.test.js
浏览文件 @
0beda5cb
...
...
@@ -20,7 +20,7 @@ import fileio from '@ohos.fileio'
const
TAG
=
"
[RDB_JSKITS_TEST]
"
const
CREATE_TABLE_TEST
=
"
CREATE TABLE IF NOT EXISTS test (
"
+
"
id INTEGER PRIMARY KEY AUTOINCREMENT,
"
+
"
name TEXT NOT NULL,
"
+
"
age INTEGER,
"
+
"
salary REAL,
"
+
"
blobType BLOB)
"
const
DATABASE_DIR
=
"
/data/storage/el2/database/entry/db/
"
const
DATABASE_DIR
=
"
/data/storage/el2/database/entry/
r
db/
"
var
RdbStore
var
context
const
STORE_CONFIG
=
{
...
...
@@ -68,10 +68,12 @@ async function BackupTest(backupName) {
promiseRestore
.
then
(()
=>
{
expect
(
false
).
assertTrue
()
}).
catch
((
err
)
=>
{
console
.
info
(
TAG
+
"
Backup error:
"
+
err
)
expect
(
true
).
assertTrue
()
})
await
promiseRestore
}
catch
{
}
catch
(
errInfo
){
console
.
info
(
TAG
+
"
BackupTest error:
"
+
errInfo
)
expect
(
true
).
assertTrue
()
}
...
...
@@ -84,18 +86,20 @@ async function ReStoreTest(restoreName) {
promiseRestore
.
then
(()
=>
{
expect
(
false
).
assertTrue
()
}).
catch
((
err
)
=>
{
console
.
info
(
TAG
+
"
Restore error:
"
+
err
)
expect
(
true
).
assertTrue
()
})
await
promiseRestore
}
catch
{
}
catch
(
errInfo
)
{
console
.
info
(
TAG
+
"
ReStoreTest error:
"
+
errInfo
)
expect
(
true
).
assertTrue
()
}
RdbStore
=
null
}
export
default
function
rdbStoreBackupRestore
WithFAContext
Test
()
{
describe
(
'
rdbStoreBackupRestore
WithFAContext
Test
'
,
function
()
{
export
default
function
rdbStoreBackupRestore
Promise
Test
()
{
describe
(
'
rdbStoreBackupRestore
Promise
Test
'
,
function
()
{
beforeAll
(
async
function
()
{
console
.
info
(
TAG
+
'
beforeAll
'
)
})
...
...
@@ -119,70 +123,75 @@ describe('rdbStoreBackupRestoreWithFAContextTest', function () {
console
.
info
(
TAG
+
"
*************Unit Test Begin*************
"
)
// /**
// * @tc.name RDB Backup Restore test
// * @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0010
// * @tc.desc RDB backup and restore function test
// */
// it('RdbBackupRestoreTest_0010', 0, async function (done) {
// await console.info(TAG + "************* RdbBackupRestoreTest_0010 start *************")
// // RDB backup function test
// let promiseBackup = RdbStore.backup(DATABASE_BACKUP_NAME)
// promiseBackup.then(() => {
// try {
// fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
// fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name)
// } catch (err) {
// expect(false).assertTrue()
// }
// }).catch((err) => {
// expect(false).assertTrue()
// })
// await promiseBackup
// // RDB restore function test
// let promiseRestore = RdbStore.restore(DATABASE_BACKUP_NAME)
// promiseRestore.then(() => {
// try {
// fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
// expect(false).assertTrue()
// } catch (err) {
// expect(true).assertTrue()
// }
// try {
// fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name)
// expect(true).assertTrue()
// } catch (err) {
// expect(false).assertTrue()
// }
// }).catch((err) => {
// expect(false).assertTrue()
// })
// await promiseRestore
// // RDB after restored, data query test
// let predicates = new dataRdb.RdbPredicates("test")
// predicates.equalTo("name", "zhangsan")
// let resultSet = await RdbStore.query(predicates)
// try {
// console.info(TAG + "After restore resultSet query done")
// expect(true).assertEqual(resultSet.goToFirstRow())
// const id = resultSet.getLong(resultSet.getColumnIndex("id"))
// const name = resultSet.getString(resultSet.getColumnIndex("name"))
// const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType"))
// expect(1).assertEqual(id)
// expect("zhangsan").assertEqual(name)
// expect(1).assertEqual(blobType[0])
// } catch (err) {
// expect(false).assertTrue()
// }
// resultSet = null
// RdbStore = null
// done()
// await console.info(TAG + "************* RdbBackupRestoreTest_0010 end *************")
// })
/**
* @tc.name RDB Backup Restore test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0010
* @tc.desc RDB backup and restore function test
*/
it
(
'
RdbBackupRestoreTest_0010
'
,
0
,
async
function
(
done
)
{
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0010 start *************
"
)
// RDB backup function test
let
promiseBackup
=
RdbStore
.
backup
(
DATABASE_BACKUP_NAME
)
promiseBackup
.
then
(()
=>
{
try
{
fileio
.
accessSync
(
DATABASE_DIR
+
DATABASE_BACKUP_NAME
)
fileio
.
accessSync
(
DATABASE_DIR
+
STORE_CONFIG
.
name
)
}
catch
(
err
)
{
expect
(
false
).
assertTrue
()
}
}).
catch
((
err
)
=>
{
expect
(
false
).
assertTrue
()
})
await
promiseBackup
// RDB before restored, delete data
let
deleteData
=
new
dataRdb
.
RdbPredicates
(
"
test
"
)
deleteData
.
equalTo
(
"
name
"
,
"
zhangsan
"
)
await
RdbStore
.
delete
(
deleteData
)
// RDB restore function test
let
promiseRestore
=
RdbStore
.
restore
(
DATABASE_BACKUP_NAME
)
promiseRestore
.
then
(()
=>
{
try
{
fileio
.
accessSync
(
DATABASE_DIR
+
DATABASE_BACKUP_NAME
)
expect
(
false
).
assertTrue
()
}
catch
(
err
)
{
expect
(
true
).
assertTrue
()
}
try
{
fileio
.
accessSync
(
DATABASE_DIR
+
STORE_CONFIG
.
name
)
}
catch
(
err
)
{
expect
(
false
).
assertTrue
()
}
}).
catch
((
err
)
=>
{
expect
(
false
).
assertTrue
()
})
await
promiseRestore
// RDB after restored, data query test
let
predicates
=
new
dataRdb
.
RdbPredicates
(
"
test
"
)
predicates
.
equalTo
(
"
name
"
,
"
zhangsan
"
)
let
resultSet
=
await
RdbStore
.
query
(
predicates
)
try
{
console
.
info
(
TAG
+
"
After restore resultSet query done
"
)
expect
(
true
).
assertEqual
(
resultSet
.
goToFirstRow
())
const
id
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
id
"
))
const
name
=
resultSet
.
getString
(
resultSet
.
getColumnIndex
(
"
name
"
))
const
blobType
=
resultSet
.
getBlob
(
resultSet
.
getColumnIndex
(
"
blobType
"
))
expect
(
1
).
assertEqual
(
id
)
expect
(
"
zhangsan
"
).
assertEqual
(
name
)
expect
(
1
).
assertEqual
(
blobType
[
0
])
}
catch
(
err
)
{
console
.
info
(
TAG
+
'
RdbBackupRestoreTest_0010 accessSync err4:
'
+
err
)
expect
(
false
).
assertTrue
()
}
resultSet
=
null
RdbStore
=
null
done
()
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0010 end *************
"
)
})
/**
* @tc.name RDB Backup test
...
...
@@ -190,7 +199,7 @@ describe('rdbStoreBackupRestoreWithFAContextTest', function () {
* @tc.desc RDB backup function test
*/
it
(
'
RdbBackupRestoreTest_0020
'
,
0
,
async
function
(
done
)
{
await
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0020 start *************
"
)
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0020 start *************
"
)
// RDB backup function test, backup file name empty
BackupTest
(
""
)
...
...
@@ -198,7 +207,7 @@ describe('rdbStoreBackupRestoreWithFAContextTest', function () {
BackupTest
(
STORE_CONFIG
.
name
)
done
()
await
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0020 end *************
"
)
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0020 end *************
"
)
})
/**
...
...
@@ -207,7 +216,7 @@ describe('rdbStoreBackupRestoreWithFAContextTest', function () {
* @tc.desc RDB restore function test
*/
it
(
'
RdbBackupRestoreTest_0030
'
,
0
,
async
function
(
done
)
{
await
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0030 start *************
"
)
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0030 start *************
"
)
let
backupName
=
"
BackupTest003.db
"
await
RdbStore
.
backup
(
backupName
)
...
...
@@ -218,7 +227,7 @@ describe('rdbStoreBackupRestoreWithFAContextTest', function () {
ReStoreTest
(
STORE_CONFIG
.
name
)
done
()
await
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0030 end *************
"
)
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0030 end *************
"
)
})
/**
...
...
@@ -227,7 +236,7 @@ describe('rdbStoreBackupRestoreWithFAContextTest', function () {
* @tc.desc RDB restore function test
*/
it
(
'
RdbBackupRestoreTest_0040
'
,
0
,
async
function
(
done
)
{
await
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0040 start *************
"
)
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0040 start *************
"
)
let
dbName
=
"
notExistName.db
"
// RDB restore function test, backup file does not exists
...
...
@@ -239,10 +248,173 @@ describe('rdbStoreBackupRestoreWithFAContextTest', function () {
}
done
()
await
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0040 end *************
"
)
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0040 end *************
"
)
})
/**
* @tc.name RDB BackupRestore test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0050
* @tc.desc RDB restore function test
*/
it
(
'
RdbBackupRestoreTest_0050
'
,
0
,
async
function
(
done
)
{
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0050 start *************
"
)
// RDB restore function test, backup file
await
RdbStore
.
backup
(
DATABASE_BACKUP_NAME
).
then
(()
=>
{
try
{
console
.
info
(
TAG
+
'
Backup database success
'
)
fileio
.
accessSync
(
DATABASE_DIR
+
DATABASE_BACKUP_NAME
)
}
catch
(
err
){
expect
(
false
).
assertTrue
();
}
}).
then
(()
=>
{
dataRdb
.
deleteRdbStore
(
context
,
DATABASE_BACKUP_NAME
).
then
(()
=>
{
try
{
fileio
.
accessSync
(
DATABASE_DIR
+
DATABASE_BACKUP_NAME
)
}
catch
(
err
){
console
.
info
(
TAG
+
'
error2
'
+
err
)
expect
(
true
).
assertTrue
();
}
})
}).
then
(()
=>
{
RdbStore
.
backup
(
DATABASE_BACKUP_NAME
).
then
(()
=>
{
try
{
console
.
info
(
TAG
+
'
Backup database success
'
)
fileio
.
accessSync
(
DATABASE_DIR
+
DATABASE_BACKUP_NAME
)
}
catch
(
err
){
console
.
info
(
TAG
+
'
error3
'
+
err
)
expect
(
false
).
assertTrue
()
}
})
})
done
()
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0050 end *************
"
)
})
/**
* @tc.name RDB BackupRestore test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0060
* @tc.desc RDB restore function test
*/
it
(
'
RdbBackupRestoreTest_0060
'
,
0
,
async
function
(
done
)
{
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0060 start *************
"
)
// Backup file is specified to database name
await
RdbStore
.
backup
(
STORE_CONFIG
.
name
).
then
(()
=>
{
console
.
info
(
TAG
+
'
Backup database finish
'
)
}).
catch
((
err
)
=>
{
expect
(
true
).
assertTrue
()
})
// Backup file is specified to database name again
await
RdbStore
.
backup
(
STORE_CONFIG
.
name
).
then
(()
=>
{
console
.
info
(
TAG
+
'
Backup database finish
'
)
}).
catch
((
err
)
=>
{
expect
(
true
).
assertTrue
();
})
done
();
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0060 end *************
"
)
})
/**
* @tc.name RDB BackupRestore test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0070
* @tc.desc RDB restore function test
*/
it
(
'
RdbBackupRestoreTest_0070
'
,
0
,
async
function
(
done
)
{
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0070 start *************
"
)
await
RdbStore
.
backup
(
DATABASE_BACKUP_NAME
)
await
dataRdb
.
deleteRdbStore
(
context
,
DATABASE_BACKUP_NAME
).
then
(()
=>
{
try
{
fileio
.
accessSync
(
DATABASE_DIR
+
DATABASE_BACKUP_NAME
)
}
catch
(
err
){
expect
(
true
).
assertTrue
();
}
})
await
RdbStore
.
restore
(
DATABASE_BACKUP_NAME
).
catch
((
err
)
=>
{
console
.
info
(
TAG
+
'
Restore fail:
'
+
err
)
expect
(
true
).
assertTrue
();
})
done
();
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0070 end *************
"
)
})
/**
* @tc.name RDB BackupRestore test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0080
* @tc.desc RDB restore function test
*/
it
(
'
RdbBackupRestoreTest_0080
'
,
0
,
async
function
(
done
)
{
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0080 start *************
"
)
BackupTest
()
done
();
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0080 end *************
"
)
})
/**
* @tc.name RDB BackupRestore test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0090
* @tc.desc RDB restore function test
*/
it
(
'
RdbBackupRestoreTest_0090
'
,
0
,
async
function
(
done
)
{
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0090 start *************
"
)
BackupTest
([
DATABASE_BACKUP_NAME
])
done
();
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0090 end *************
"
)
})
/**
* @tc.name RDB BackupRestore test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0100
* @tc.desc RDB restore function test
*/
it
(
'
RdbBackupRestoreTest_0100
'
,
0
,
async
function
(
done
)
{
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0100 start *************
"
)
await
RdbStore
.
backup
(
DATABASE_BACKUP_NAME
)
ReStoreTest
([
DATABASE_BACKUP_NAME
])
done
();
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0100 end *************
"
)
})
/**
* @tc.name RDB BackupRestore test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0110
* @tc.desc RDB restore function test
*/
it
(
'
RdbBackupRestoreTest_0110
'
,
0
,
async
function
(
done
)
{
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0110 start *************
"
)
await
RdbStore
.
backup
(
DATABASE_BACKUP_NAME
)
ReStoreTest
()
done
();
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0110 end *************
"
)
})
/**
* @tc.name RDB BackupRestore test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0120
* @tc.desc RDB restore function test
*/
it
(
'
RdbBackupRestoreTest_0120
'
,
0
,
async
function
(
done
)
{
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0120 start *************
"
)
await
RdbStore
.
backup
(
DATABASE_BACKUP_NAME
)
BackupTest
(
DATABASE_BACKUP_NAME
)
done
();
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0120 end *************
"
)
})
/**
* @tc.name RDB BackupRestore test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0130
* @tc.desc RDB restore function test
*/
it
(
'
RdbBackupRestoreTest_0130
'
,
0
,
async
function
(
done
)
{
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0130 start *************
"
)
await
RdbStore
.
backup
(
DATABASE_BACKUP_NAME
)
await
RdbStore
.
restore
(
DATABASE_BACKUP_NAME
)
ReStoreTest
(
DATABASE_BACKUP_NAME
)
done
();
console
.
info
(
TAG
+
"
************* RdbBackupRestoreTest_0130 end *************
"
)
})
console
.
info
(
TAG
+
"
*************Unit Test End*************
"
)
}
)
})
}
distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreInsertJsunit.test.js
浏览文件 @
0beda5cb
此差异已折叠。
点击以展开。
distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreQuery.test.js
0 → 100644
浏览文件 @
0beda5cb
/*
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
import
dataRdb
from
'
@ohos.data.rdb
'
;
import
factory
from
'
@ohos.data.distributedData
'
import
abilityFeatureAbility
from
'
@ohos.ability.featureAbility
'
const
TAG
=
"
[RDB_JSKITS_TEST]
"
const
CREATE_TABLE_TEST
=
"
CREATE TABLE IF NOT EXISTS test (
"
+
"
id INTEGER PRIMARY KEY AUTOINCREMENT,
"
+
"
name TEXT NOT NULL,
"
+
"
age INTEGER,
"
+
"
salary REAL,
"
+
"
blobType BLOB)
"
const
DATABASE_DIR
=
"
/data/storage/el2/database/entry/rdb/
"
const
STORE_CONFIG
=
{
name
:
"
Query.db
"
,
}
const
TEST_BUNDLE_NAME
=
"
ohos.acts.relationalStorejstest
"
var
kvManager
=
null
;
var
kvStore
=
null
;
var
localDeviceId
=
null
;
var
rdbStore
let
context
=
abilityFeatureAbility
.
getContext
()
async
function
CreatRdbStore
(
context
,
STORE_CONFIG
)
{
let
RdbStore
=
await
dataRdb
.
getRdbStore
(
context
,
STORE_CONFIG
,
1
)
await
RdbStore
.
executeSql
(
CREATE_TABLE_TEST
,
null
)
let
u8
=
new
Uint8Array
([
1
,
2
,
3
])
{
const
valueBucket
=
{
"
name
"
:
"
zhangsan
"
,
"
age
"
:
18
,
"
salary
"
:
100.5
,
"
blobType
"
:
u8
,
}
await
RdbStore
.
insert
(
"
test
"
,
valueBucket
)
}
{
const
valueBucket
=
{
"
name
"
:
"
lisi
"
,
"
age
"
:
28
,
"
salary
"
:
100.5
,
"
blobType
"
:
u8
,
}
await
RdbStore
.
insert
(
"
test
"
,
valueBucket
)
}
{
const
valueBucket
=
{
"
name
"
:
"
wangwu
"
,
"
age
"
:
38
,
"
salary
"
:
90.0
,
"
blobType
"
:
u8
,
}
await
RdbStore
.
insert
(
"
test
"
,
valueBucket
)
}
return
RdbStore
}
async
function
getLocalDeviceId
(){
}
export
default
function
rdbstoreQueryTest
(){
describe
(
"
rdbstoreQueryTest
"
,
function
()
{
beforeAll
(
async
function
(
done
){
const
config
=
{
bundleName
:
TEST_BUNDLE_NAME
,
userInfo
:
{
userId
:
'
0
'
,
userType
:
factory
.
UserType
.
SAME_USER_ID
,
context
:
context
}
}
const
options
=
{
createIfMissing
:
true
,
encrypt
:
false
,
backup
:
false
,
autoSync
:
true
,
kvStoreType
:
factory
.
KVStoreType
.
DEVICE_COLLABORATION
,
schema
:
''
,
securityLevel
:
factory
.
SecurityLevel
.
S2
,
}
console
.
info
(
'
getLocalDeviceId config:
'
+
JSON
.
stringify
(
config
));
await
factory
.
createKVManager
(
config
).
then
((
manager
)
=>
{
kvManager
=
manager
;
console
.
info
(
'
getLocalDeviceId createKVManager success
'
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
getLocalDeviceId createKVManager err
'
+
err
);
});
await
kvManager
.
getKVStore
(
TEST_STORE_ID
,
options
).
then
((
store
)
=>
{
kvStore
=
store
;
console
.
info
(
'
getLocalDeviceId getKVStore for getDeviceId success
'
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
getLocalDeviceId getKVStore err
'
+
err
);
});
var
getDeviceId
=
new
Promise
((
resolve
,
reject
)
=>
{
kvStore
.
on
(
'
dataChange
'
,
0
,
function
(
data
)
{
console
.
info
(
'
getLocalDeviceId on data change:
'
+
JSON
.
stringify
(
data
));
resolve
(
data
.
deviceId
);
});
kvStore
.
put
(
"
getDeviceId
"
,
"
byPut
"
).
then
((
data
)
=>
{
console
.
info
(
'
getLocalDeviceId put success
'
);
expect
(
data
==
undefined
).
assertTrue
();
});
setTimeout
(()
=>
{
reject
(
new
Error
(
'
not resolved in 2 second, reject it.
'
))
},
2000
);
});
await
getDeviceId
.
then
(
function
(
deviceId
)
{
console
.
info
(
'
getLocalDeviceId getDeviceId
'
+
JSON
.
stringify
(
deviceId
));
localDeviceId
=
deviceId
;
}).
catch
((
error
)
=>
{
console
.
info
(
'
getLocalDeviceId can NOT getDeviceId, fail:
'
+
error
);
expect
(
null
).
assertFail
();
});
await
kvManager
.
closeKVStore
(
TEST_BUNDLE_NAME
,
TEST_STORE_ID
,
kvStore
);
await
kvManager
.
deleteKVStore
(
TEST_BUNDLE_NAME
,
TEST_STORE_ID
);
kvStore
=
null
;
console
.
info
(
'
getLocalDeviceId end
'
);
getLocalDeviceId
()
console
.
info
(
TAG
+
'
beforeAll
'
)
done
();
})
beforeEach
(
async
function
()
{
console
.
info
(
TAG
+
'
beforeEach
'
)
rdbStore
=
await
CreatRdbStore
(
context
,
STORE_CONFIG
)
})
afterEach
(
async
function
()
{
console
.
info
(
TAG
+
'
afterEach
'
)
await
dataRdb
.
deleteRdbStore
(
context
,
STORE_CONFIG
.
name
)
})
afterAll
(
async
function
()
{
console
.
info
(
TAG
+
'
afterAll
'
)
})
/**
* @tc.name RDB remotequery test
* @tc.number SUB_DDM_RDB_JS_RemoteQueryTest_Promise_0010
* @tc.desc RDB remotequery function test
*/
it
(
'
RdbRemoteQueryPromiseTest0010
'
,
0
,
async
function
(
done
){
console
.
info
(
TAG
+
"
RdbRemoteQueryPromiseTest0010 start
"
)
let
predicates
=
new
dataRdb
.
RdbPredicates
(
"
test
"
);
predicates
.
equalTo
(
"
name
"
,
"
zhangsan
"
)
await
rdbStore
.
remoteQuery
(
localDeviceId
,
"
test
"
,
predicates
,[
"
name
"
,
"
age
"
,
"
salary
"
]).
then
(
(
resultSet
)
=>
{
console
.
info
(
TAG
+
"
Remote query success
"
)
expect
(
false
).
assertTrue
();
}).
catch
((
err
)
=>
{
console
.
info
(
TAG
+
"
Remote query error:
"
+
err
)
expect
(
true
).
assertTrue
();
})
done
();
console
.
info
(
TAG
+
"
RdbRemoteQueryPromiseTest0010 end
"
)
})
/**
* @tc.name RDB remotequery test
* @tc.number SUB_DDM_RDB_JS_RemoteQueryTest_Promise_0020
* @tc.desc RDB remotequery function test
*/
it
(
'
RdbRemoteQueryPromiseTest0020
'
,
0
,
async
function
(
done
){
console
.
info
(
TAG
+
"
RdbRemoteQueryPromiseTest0020 start
"
)
let
predicates
=
new
dataRdb
.
RdbPredicates
(
"
test
"
);
predicates
.
equalTo
(
"
name
"
,
"
zhangsan
"
)
try
{
await
rdbStore
.
remoteQuery
([
localDeviceId
],
"
test
"
,
predicates
,[
"
name
"
,
"
age
"
,
"
salary
"
]).
then
((
resultSet
)
=>
{
console
.
info
(
TAG
+
"
Remote query success
"
)
expect
(
false
).
assertTrue
();
}).
catch
((
err
)
=>
{
console
.
info
(
TAG
+
"
Remote query error
"
+
err
)
})
}
catch
(
err
){
console
.
info
(
TAG
+
"
RdbRemoteQueryPromiseTest0020 error:
"
+
err
)
}
done
();
console
.
info
(
TAG
+
"
RdbRemoteQueryPromiseTest0020 end
"
)
})
/**
* @tc.name RDB remotequery test
* @tc.number SUB_DDM_RDB_JS_RemoteQueryTest_Promise_0030
* @tc.desc RDB remotequery function test
*/
it
(
'
RdbRemoteQueryPromiseTest0030
'
,
0
,
async
function
(
done
){
console
.
info
(
TAG
+
"
RdbRemoteQueryPromiseTest0030 start
"
)
let
predicates
=
new
dataRdb
.
RdbPredicates
(
"
test
"
);
predicates
.
equalTo
(
"
name
"
,
"
zhangsan
"
)
try
{
await
rdbStore
.
remoteQuery
(
localDeviceId
,[
"
test
"
],
predicates
,[
"
name
"
,
"
age
"
,
"
salary
"
]).
then
((
resultSet
)
=>
{
console
.
info
(
TAG
+
"
Remote query success
"
)
expect
(
false
).
assertTrue
();
}).
catch
((
err
)
=>
{
console
.
info
(
TAG
+
"
Remote query error
"
+
err
)
})
}
catch
(
err
){
console
.
info
(
TAG
+
"
RdbRemoteQueryPromiseTest0030 error:
"
+
err
)
}
done
();
console
.
info
(
TAG
+
"
RdbRemoteQueryPromiseTest0030 end
"
)
})
/**
* @tc.name RDB remotequery test
* @tc.number SUB_DDM_RDB_JS_RemoteQueryTest_Promise_0040
* @tc.desc RDB remotequery function test
*/
it
(
'
RdbRemoteQueryPromiseTest0040
'
,
0
,
async
function
(
done
){
console
.
info
(
TAG
+
"
RdbRemoteQueryPromiseTest0040 start
"
)
let
predicates
=
new
dataRdb
.
RdbPredicates
(
"
test
"
);
predicates
.
equalTo
(
"
name
"
,
"
zhangsan
"
)
try
{
await
rdbStore
.
remoteQuery
(
localDeviceId
,
"
test
"
,
predicates
,
"
age
"
).
then
((
resultSet
)
=>
{
console
.
info
(
TAG
+
"
Remote query success
"
)
expect
(
false
).
assertTrue
();
}).
catch
((
err
)
=>
{
console
.
info
(
TAG
+
"
Remote query error
"
+
err
)
})
}
catch
(
err
){
console
.
info
(
TAG
+
"
RdbRemoteQueryPromiseTest0040 error:
"
+
err
)
}
done
();
console
.
info
(
TAG
+
"
RdbRemoteQueryPromiseTest0040 end
"
)
})
/**
* @tc.name RDB remotequery test
* @tc.number SUB_DDM_RDB_JS_RemoteQueryTest_Callback_0010
* @tc.desc RDB remotequery function test
*/
it
(
'
RdbRemoteQueryCallbackTest0010
'
,
0
,
async
function
(
done
){
console
.
info
(
TAG
+
"
RdbRemoteQueryCallbackTest0010 start
"
)
let
predicates
=
new
dataRdb
.
RdbPredicates
(
"
test
"
);
predicates
.
equalTo
(
"
name
"
,
"
zhangsan
"
)
try
{
await
rdbStore
.
remoteQuery
(
localDeviceId
,
"
test
"
,
predicates
,[
"
name
"
,
"
age
"
,
"
salary
"
],
(
err
,
data
)
=>
{
if
(
err
!=
null
){
console
.
info
(
TAG
+
"
Remote query error
"
+
err
)
}
else
{
console
.
info
(
TAG
+
"
Remote query success
"
)
expect
(
false
).
assertTrue
();
}
})
}
catch
(
err
){
console
.
info
(
TAG
+
"
RdbRemoteQueryCallbackTest0010 error:
"
+
err
)
}
done
();
console
.
info
(
TAG
+
"
RdbRemoteQueryCallbackTest0010 end
"
)
})
/**
* @tc.name RDB remotequery test
* @tc.number SUB_DDM_RDB_JS_RemoteQueryTest_Callback_0020
* @tc.desc RDB remotequery function test
*/
it
(
'
RdbRemoteQueryCallbackTest0020
'
,
0
,
async
function
(
done
){
console
.
info
(
TAG
+
"
RdbRemoteQueryCallbackTest0020 start
"
)
let
predicates
=
new
dataRdb
.
RdbPredicates
(
"
test
"
);
predicates
.
equalTo
(
"
name
"
,
"
zhangsan
"
)
try
{
await
rdbStore
.
remoteQuery
([
localDeviceId
],
"
test
"
,
predicates
,[
"
name
"
,
"
age
"
,
"
salary
"
],
(
err
,
data
)
=>
{
if
(
err
!=
null
){
console
.
info
(
TAG
+
"
Remote query error
"
+
err
)
}
else
{
console
.
info
(
TAG
+
"
Remote query success
"
)
expect
(
false
).
assertTrue
();
}
})
}
catch
(
err
){
console
.
info
(
TAG
+
"
RdbRemoteQueryCallbackTest0020 error:
"
+
err
)
}
done
();
console
.
info
(
TAG
+
"
RdbRemoteQueryCallbackTest0020 end
"
)
})
/**
* @tc.name RDB remotequery test
* @tc.number SUB_DDM_RDB_JS_RemoteQueryTest_Callback_0030
* @tc.desc RDB remotequery function test
*/
it
(
'
RdbRemoteQueryCallbackTest0030
'
,
0
,
async
function
(
done
){
console
.
info
(
TAG
+
"
RdbRemoteQueryCallbackTest0020 start
"
)
let
predicates
=
new
dataRdb
.
RdbPredicates
(
"
test
"
);
predicates
.
equalTo
(
"
name
"
,
"
zhangsan
"
)
try
{
await
rdbStore
.
remoteQuery
(
localDeviceId
,
[
"
test
"
],
predicates
,[
"
name
"
,
"
age
"
,
"
salary
"
],
(
err
,
data
)
=>
{
if
(
err
!=
null
){
console
.
info
(
TAG
+
"
Remote query error
"
+
err
)
}
else
{
console
.
info
(
TAG
+
"
Remote query success
"
)
expect
(
false
).
assertTrue
();
}
})
}
catch
(
err
){
console
.
info
(
TAG
+
"
RdbRemoteQueryCallbackTest0030 error:
"
+
err
)
}
done
();
console
.
info
(
TAG
+
"
RdbRemoteQueryCallbackTest0030 end
"
)
})
/**
* @tc.name RDB remotequery test
* @tc.number SUB_DDM_RDB_JS_RemoteQueryTest_Callback_0040
* @tc.desc RDB remotequery function test
*/
it
(
'
RdbRemoteQueryCallbackTest0040
'
,
0
,
async
function
(
done
){
console
.
info
(
TAG
+
"
RdbRemoteQueryCallbackTest0040 start
"
)
let
predicates
=
new
dataRdb
.
RdbPredicates
(
"
test
"
);
predicates
.
equalTo
(
"
name
"
,
"
zhangsan
"
)
try
{
await
rdbStore
.
remoteQuery
(
localDeviceId
,
"
test
"
,
predicates
,
"
name
"
,
(
err
,
data
)
=>
{
if
(
err
!=
null
){
console
.
info
(
TAG
+
"
Remote query error
"
+
err
)
}
else
{
console
.
info
(
TAG
+
"
Remote query success
"
)
expect
(
false
).
assertTrue
();
}
})
}
catch
(
err
){
console
.
info
(
TAG
+
"
RdbRemoteQueryCallbackTest0040 error:
"
+
err
)
}
done
();
console
.
info
(
TAG
+
"
RdbRemoteQueryCallbackTest0040 end
"
)
})
})
}
\ No newline at end of file
distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreRdbstoreJsunit.test.js
浏览文件 @
0beda5cb
...
...
@@ -18,7 +18,7 @@ import dataRdb from '@ohos.data.rdb';
import
abilityFeatureAbility
from
'
@ohos.ability.featureAbility
'
;
var
context
=
abilityFeatureAbility
.
getContext
();
var
contextApplication
=
context
.
getApplicationContext
()
const
TAG
=
"
[RDB_JSKITS_TEST]
"
const
CREATE_TABLE_TEST
=
"
CREATE TABLE IF NOT EXISTS test (
"
+
"
id INTEGER PRIMARY KEY AUTOINCREMENT,
"
+
"
name TEXT NOT NULL,
"
+
"
age INTEGER,
"
+
"
salary REAL,
"
+
"
blobType BLOB)
"
;
...
...
@@ -183,7 +183,7 @@ describe('rdbStoreTest', function () {
console
.
info
(
TAG
+
"
************* testRdbStore0006 start *************
"
);
let
rdbstore
=
null
;
try
{
const
STORE_CONFIG
=
{
const
STORE_CONFIG
=
{
name
:
"
rdbstorecontext.db
"
,
}
console
.
info
(
TAG
+
"
first
"
)
...
...
@@ -210,23 +210,78 @@ describe('rdbStoreTest', function () {
* @tc.number SUB_DDM_AppDataFWK_JSRDB_RdbStore_0070
* @tc.desc rdb store getRdbStore test
*/
it
(
'
testRdbStore0007
'
,
0
,
async
function
(
done
)
{
console
.
info
(
TAG
+
"
************* testRdbStore0007 start *************
"
);
let
rdbstore
=
null
;
dataRdb
.
getRdbStore
(
context
,
STORE_CONFIG
,
1
,
(
data
,
err
)
=>
{
if
(
err
!=
undefined
){
expect
(
null
).
assertFail
()
}
else
{
rdbstore
=
data
;
console
.
info
(
TAG
+
"
getRdbStore success:
"
+
rdbstore
)
expect
(
rdbstore
).
assertNotNull
();
}
});
await
dataRdb
.
deleteRdbStore
(
STORE_CONFIG
.
name
)
rdbstore
=
null
;
done
();
console
.
info
(
TAG
+
"
************* testRdbStore0007 end *************
"
);
})
it
(
'
testRdbStore0007
'
,
0
,
async
function
(
done
)
{
console
.
info
(
TAG
+
"
************* testRdbStore0007 start *************
"
);
let
rdbstore
=
null
;
try
{
const
STORE_CONFIG
=
{
name
:
"
rdbstorecontext.db
"
,
}
console
.
info
(
TAG
+
"
first
"
)
await
dataRdb
.
getRdbStore
(
contextApplication
,
STORE_CONFIG
,
1
).
then
((
data
)
=>
{
console
.
info
(
TAG
+
"
Get rdbstore success
"
)
rdbstore
=
data
;
expect
(
rdbstore
!=
null
).
assertTrue
();
}).
catch
((
errInfo
)
=>
{
console
.
info
(
TAG
+
"
Get rdbstore fail
"
+
errInfo
)
expect
(
null
).
assertFail
();
})
}
catch
(
err
){
console
.
info
(
TAG
+
"
Get rdbstore fail catch err:
"
+
err
)
expect
(
null
).
assertFail
()
}
await
dataRdb
.
deleteRdbStore
(
STORE_CONFIG
.
name
)
rdbstore
=
null
;
done
();
console
.
info
(
TAG
+
"
************* testRdbStore0007 end *************
"
);
})
/**
* @tc.name rdb store deleteRdbStore test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_RdbStore_0080
* @tc.desc rdb store deleteRdbStore test
*/
it
(
'
testRdbStore0008
'
,
0
,
async
function
(
done
)
{
console
.
info
(
TAG
+
"
************* testRdbStore0008 start *************
"
);
let
rdbstore
=
null
;
dataRdb
.
getRdbStore
(
context
,
STORE_CONFIG
,
1
,
(
data
,
err
)
=>
{
if
(
err
!=
undefined
){
expect
(
null
).
assertFail
()
}
else
{
rdbstore
=
data
;
console
.
info
(
TAG
+
"
getRdbStore success:
"
+
rdbstore
)
expect
(
rdbstore
).
assertNotNull
();
}
});
await
dataRdb
.
deleteRdbStore
(
context
,
STORE_CONFIG
.
name
)
rdbstore
=
null
;
done
();
console
.
info
(
TAG
+
"
************* testRdbStore0008 end *************
"
);
})
/**
* @tc.name rdb store deleteRdbStore test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_RdbStore_0090
* @tc.desc rdb store deleteRdbStore test
*/
it
(
'
testRdbStore0009
'
,
0
,
async
function
(
done
){
console
.
info
(
TAG
+
"
************* testRdbStore0009 start *************
"
);
let
rdbstore
=
null
;
dataRdb
.
getRdbStore
(
contextApplication
,
STORE_CONFIG
,
1
,
(
data
,
err
)
=>
{
if
(
err
!=
undefined
){
expect
(
null
).
assertFail
()
}
else
{
rdbstore
=
data
;
console
.
info
(
TAG
+
"
getRdbStore success:
"
+
rdbstore
)
expect
(
rdbstore
).
assertNotNull
();
}
});
await
dataRdb
.
deleteRdbStore
(
contextApplication
,
STORE_CONFIG
.
name
)
rdbstore
=
null
;
done
();
console
.
info
(
TAG
+
"
************* testRdbStore0009 end *************
"
);
})
console
.
info
(
TAG
+
"
*************Unit Test End*************
"
);
})}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录