Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
378295ac
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看板
未验证
提交
378295ac
编写于
6月 29, 2022
作者:
O
openharmony_ci
提交者:
Gitee
6月 29, 2022
浏览文件
操作
浏览文件
下载
差异文件
!3924 【Distributeddatamgr】【monthly_20220614】覆盖率补齐
Merge pull request !3924 from 梁梁/monthly_20220614
上级
75901ca5
b4b3fddf
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
258 addition
and
6 deletion
+258
-6
distributeddatamgr/appdatamgrjstest/hap/src/main/js/default/test/List.test.js
...ppdatamgrjstest/hap/src/main/js/default/test/List.test.js
+1
-1
distributeddatamgr/appdatamgrjstest/hap/src/main/js/default/test/RdbstoreBackupRestoreWithFAContextJsunit.test.js
...ult/test/RdbstoreBackupRestoreWithFAContextJsunit.test.js
+246
-0
distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/default/test/ObjectStoreJsunit.test.js
...st/hap/src/main/js/default/test/ObjectStoreJsunit.test.js
+11
-5
未找到文件。
distributeddatamgr/appdatamgrjstest/hap/src/main/js/default/test/List.test.js
浏览文件 @
378295ac
...
...
@@ -29,6 +29,6 @@ require('./RdbstorePredicatesJoinJsunit.test.js')
require
(
'
./RdbStoreDistributedJsunit.test.js
'
)
require
(
'
./RdbstoreChangeEncryptKeyJsunit.test.js
'
)
require
(
'
./RdbStoreDataShareJsunit.test.js
'
)
require
(
'
./RdbstoreBackupRestoreWithFAContextJsunit.test.js
'
)
distributeddatamgr/appdatamgrjstest/hap/src/main/js/default/test/RdbstoreBackupRestoreWithFAContextJsunit.test.js
0 → 100644
浏览文件 @
378295ac
/*
* 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
'
deccjsunit/index
'
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 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/
"
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
(
"
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
BackupTest
(
backupName
)
{
try
{
let
promiseRestore
=
RdbStore
.
backup
(
backupName
)
promiseRestore
.
then
(()
=>
{
expect
(
false
).
assertTrue
()
}).
catch
((
err
)
=>
{
expect
(
true
).
assertTrue
()
})
await
promiseRestore
}
catch
{
expect
(
true
).
assertTrue
()
}
RdbStore
=
null
}
async
function
ReStoreTest
(
restoreName
)
{
try
{
let
promiseRestore
=
RdbStore
.
restore
(
restoreName
)
promiseRestore
.
then
(()
=>
{
expect
(
false
).
assertTrue
()
}).
catch
((
err
)
=>
{
expect
(
true
).
assertTrue
()
})
await
promiseRestore
}
catch
{
expect
(
true
).
assertTrue
()
}
RdbStore
=
null
}
describe
(
'
rdbStoreBackupRestoreWithFAContextTest
'
,
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
.
log
(
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
.
log
(
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
.
log
(
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
.
log
(
TAG
+
"
************* RdbBackupRestoreTest_0010 end *************
"
)
})
/**
* @tc.name RDB Backup test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0020
* @tc.desc RDB backup function test
*/
it
(
'
RdbBackupRestoreTest_0020
'
,
0
,
async
function
(
done
)
{
await
console
.
log
(
TAG
+
"
************* RdbBackupRestoreTest_0020 start *************
"
)
// RDB backup function test, backup file name empty
BackupTest
(
""
)
// RDB backup function test, backup file name already exists
BackupTest
(
STORE_CONFIG
.
name
)
done
()
await
console
.
log
(
TAG
+
"
************* RdbBackupRestoreTest_0020 end *************
"
)
})
/**
* @tc.name RDB BackupRestore test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0030
* @tc.desc RDB restore function test
*/
it
(
'
RdbBackupRestoreTest_0030
'
,
0
,
async
function
(
done
)
{
await
console
.
log
(
TAG
+
"
************* RdbBackupRestoreTest_0030 start *************
"
)
let
backupName
=
"
BackupTest003.db
"
await
RdbStore
.
backup
(
backupName
)
// RDB restore function test, backup file name empty
ReStoreTest
(
""
)
// RDB restore function test, backup file is specified to database name
ReStoreTest
(
STORE_CONFIG
.
name
)
done
()
await
console
.
log
(
TAG
+
"
************* RdbBackupRestoreTest_0030 end *************
"
)
})
/**
* @tc.name RDB BackupRestore test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0040
* @tc.desc RDB restore function test
*/
it
(
'
RdbBackupRestoreTest_0040
'
,
0
,
async
function
(
done
)
{
await
console
.
log
(
TAG
+
"
************* RdbBackupRestoreTest_0040 start *************
"
)
let
dbName
=
"
notExistName.db
"
// RDB restore function test, backup file does not exists
try
{
fileio
.
accessSync
(
DATABASE_DIR
+
dbName
)
expect
(
false
).
assertTrue
()
}
catch
{
ReStoreTest
(
dbName
)
}
done
()
await
console
.
log
(
TAG
+
"
************* RdbBackupRestoreTest_0040 end *************
"
)
})
console
.
log
(
TAG
+
"
*************Unit Test End*************
"
)
}
)
distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/default/test/ObjectStoreJsunit.test.js
浏览文件 @
378295ac
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
...
...
@@ -679,6 +680,7 @@ describe('objectStoreTest', function () {
*/
it
(
'
testSave001
'
,
0
,
async
function
(
done
)
{
console
.
info
(
TAG
+
"
************* testSave001 start *************
"
);
var
gObject
=
distributedObject
.
createDistributedObject
({
name
:
"
Amy
"
,
age
:
18
,
isVis
:
false
});
gObject
.
setSessionId
(
"
tmpsession1
"
);
let
result
=
await
gObject
.
save
(
"
local
"
);
...
...
@@ -706,13 +708,15 @@ describe('objectStoreTest', function () {
*/
it
(
'
testSave002
'
,
0
,
function
(
done
)
{
console
.
log
(
TAG
+
"
************* testSave002 start *************
"
);
let
SaveSuccessResponse
var
gObject
=
distributedObject
.
createDistributedObject
({
name
:
"
Amy
"
,
age
:
18
,
isVis
:
false
});
gObject
.
setSessionId
(
"
tmpsession1
"
);
gObject
.
save
(
"
local
"
,(
result
)
=>
{
expect
(
result
!=
null
).
assertTrue
();
expect
(
result
.
sessionId
==
"
tmpsession1
"
).
assertEqual
(
false
);
expect
(
result
.
version
==
gObject
.
__version
).
assertEqual
(
false
);
expect
(
result
.
deviceId
==
"
local
"
).
assertEqual
(
false
);
SaveSuccessResponse
=
result
expect
(
SaveSuccessResponse
!=
null
).
assertTrue
();
expect
(
SaveSuccessResponse
.
sessionId
==
"
tmpsession1
"
).
assertEqual
(
false
);
expect
(
SaveSuccessResponse
.
version
==
gObject
.
__version
).
assertEqual
(
false
);
expect
(
SaveSuccessResponse
.
deviceId
==
"
local
"
).
assertEqual
(
false
);
});
gObject
.
setSessionId
(
""
);
...
...
@@ -761,9 +765,11 @@ describe('objectStoreTest', function () {
expect
(
result
.
sessionId
!=
"
123456
"
).
assertEqual
(
true
);
expect
(
result
.
version
!=
gObject
.
__version
).
assertEqual
(
true
);
expect
(
result
.
deviceId
!=
"
local
"
).
assertEqual
(
true
);
let
RevokeSaveSuccessResponse
=
undefined
;
gObject
.
revokeSave
((
err
,
ret
)
=>
{
RevokeSaveSuccessResponse
=
ret
;
expect
(
err
==
null
).
assertTrue
();
expect
(
RevokeSaveSuccessResponse
==
undefined
).
assertTrue
();
});
done
();
console
.
log
(
TAG
+
"
************* testRevokeSave002 end *************
"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录