Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
add2ea84
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看板
未验证
提交
add2ea84
编写于
6月 09, 2022
作者:
O
openharmony_ci
提交者:
Gitee
6月 09, 2022
浏览文件
操作
浏览文件
下载
差异文件
!3486 【Distributeddatamgr】【Master】RdbStoreDataShareJsunit.test.js,List.test.js文件修改
Merge pull request !3486 from 杨立峰/master
上级
2eab72b8
410c8735
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
392 addition
and
0 deletion
+392
-0
distributeddatamgr/appdatamgrjstest/hap/src/main/js/default/test/List.test.js
...ppdatamgrjstest/hap/src/main/js/default/test/List.test.js
+2
-0
distributeddatamgr/appdatamgrjstest/hap/src/main/js/default/test/RdbStoreDataShareJsunit.test.js
.../src/main/js/default/test/RdbStoreDataShareJsunit.test.js
+390
-0
未找到文件。
distributeddatamgr/appdatamgrjstest/hap/src/main/js/default/test/List.test.js
浏览文件 @
add2ea84
...
...
@@ -28,5 +28,7 @@ require('./RdbstoreTransactionJsunit.test.js')
require
(
'
./RdbstorePredicatesJoinJsunit.test.js
'
)
require
(
'
./RdbStoreDistributedJsunit.test.js
'
)
require
(
'
./RdbstoreChangeEncryptKeyJsunit.test.js
'
)
require
(
'
./RdbStoreDataShareJsunit.test.js
'
)
distributeddatamgr/appdatamgrjstest/hap/src/main/js/default/test/RdbStoreDataShareJsunit.test.js
0 → 100644
浏览文件 @
add2ea84
/*
* 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
dataShare
from
'
@ohos.data.dataShare
'
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
DROP_TABLE_TEST
=
"
drop table test
"
const
STORE_CONFIG
=
{
name
:
"
DataShareTest.db
"
,
}
var
rdbStore
=
undefined
var
context
=
abilityFeatureAbility
.
getContext
()
describe
(
'
rdbStoreDataSharePredicatesTest
'
,
function
()
{
beforeAll
(
async
function
()
{
console
.
info
(
TAG
+
'
beforeAll
'
)
rdbStore
=
await
dataRdb
.
getRdbStore
(
context
,
STORE_CONFIG
,
1
)
})
beforeEach
(
async
function
()
{
console
.
info
(
TAG
+
'
beforeEach
'
)
await
rdbStore
.
executeSql
(
CREATE_TABLE_TEST
,
null
)
})
afterEach
(
async
function
()
{
console
.
info
(
TAG
+
'
afterEach
'
)
await
rdbStore
.
executeSql
(
DROP_TABLE_TEST
,
null
)
})
afterAll
(
async
function
()
{
console
.
info
(
TAG
+
'
afterAll
'
)
rdbStore
=
null
await
dataRdb
.
deleteRdbStore
(
context
,
"
DataShareTest.db
"
)
})
console
.
log
(
TAG
+
"
*************Unit Test Begin*************
"
)
/**
* @tc.name rdb DataShare insert test
* @tc.number SUB_DataShare_Rdb_Func0001
* @tc.desc rdb DataShare Func insert test
*/
it
(
'
testRdbStoreDataShareFunc0001
'
,
0
,
async
function
(
done
)
{
console
.
log
(
TAG
+
"
************* testRdbStoreDataShareFunc0001 start *************
"
)
let
u8
=
new
Uint8Array
([
1
,
2
,
3
])
const
valueBucket
=
{
"
name
"
:
"
zhangsan
"
,
"
age
"
:
18
,
"
salary
"
:
100.5
,
"
blobType
"
:
u8
,
}
let
insertPromise
=
rdbStore
.
insert
(
"
test
"
,
valueBucket
)
insertPromise
.
then
(
async
(
ret
)
=>
{
expect
(
1
).
assertEqual
(
ret
)
console
.
log
(
TAG
+
"
Insert done:
"
+
ret
)
}).
catch
((
err
)
=>
{
console
.
log
(
TAG
+
"
Insert err:
"
+
err
)
expect
(
false
).
assertTrue
()
})
await
insertPromise
console
.
log
(
"
insert end
"
)
let
predicates
=
new
dataRdb
.
RdbPredicates
(
"
test
"
)
predicates
.
equalTo
(
"
name
"
,
"
zhangsan
"
)
let
resultSet
=
await
rdbStore
.
query
(
predicates
)
try
{
console
.
log
(
TAG
+
"
resultSet query done
"
)
expect
(
true
).
assertEqual
(
resultSet
.
goToFirstRow
())
const
name
=
resultSet
.
getString
(
resultSet
.
getColumnIndex
(
"
name
"
))
const
age
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
age
"
))
const
salary
=
resultSet
.
getDouble
(
resultSet
.
getColumnIndex
(
"
salary
"
))
const
blobType
=
resultSet
.
getBlob
(
resultSet
.
getColumnIndex
(
"
blobType
"
))
expect
(
"
zhangsan
"
).
assertEqual
(
name
)
expect
(
18
).
assertEqual
(
age
)
expect
(
100.5
).
assertEqual
(
salary
)
expect
(
1
).
assertEqual
(
blobType
[
0
])
expect
(
2
).
assertEqual
(
blobType
[
1
])
expect
(
3
).
assertEqual
(
blobType
[
2
])
}
catch
(
err
)
{
expect
(
false
).
assertTrue
()
}
resultSet
=
null
done
()
console
.
log
(
TAG
+
"
************* testRdbStoreDataShareFunc0001 end *************
"
)
})
/**
* @tc.name rdb DataShare update test
* @tc.number SUB_DataShare_Rdb_Func0002
* @tc.desc rdb DataShare update promise Func test
*/
it
(
'
testRdbStoreDataShareFunc0002
'
,
0
,
async
function
(
done
)
{
console
.
log
(
TAG
+
"
************* testRdbStoreDataShareFunc0002 start *************
"
)
let
u8
=
new
Uint8Array
([
1
,
2
,
3
])
let
valueBucket
=
{
"
name
"
:
"
zhangsan
"
,
"
age
"
:
18
,
"
salary
"
:
100.5
,
"
blobType
"
:
u8
,
}
await
rdbStore
.
insert
(
"
test
"
,
valueBucket
)
u8
=
new
Uint8Array
([
4
,
5
,
6
])
valueBucket
=
{
"
name
"
:
"
lisi
"
,
"
age
"
:
28
,
"
salary
"
:
200.5
,
"
blobType
"
:
u8
,
}
let
predicates
=
new
dataShare
.
DataSharePredicates
()
predicates
.
equalTo
(
"
name
"
,
"
zhangsan
"
)
let
promiseUpdate
=
rdbStore
.
update
(
"
test
"
,
valueBucket
,
predicates
)
promiseUpdate
.
then
(
async
(
ret
)
=>
{
expect
(
1
).
assertEqual
(
ret
)
console
.
log
(
TAG
+
"
Update done:
"
+
ret
)
}).
catch
((
err
)
=>
{
console
.
log
(
TAG
+
"
Update err:
"
+
err
)
expect
(
false
).
assertTrue
()
})
await
promiseUpdate
let
rdbPredicates
=
await
new
dataRdb
.
RdbPredicates
(
"
test
"
)
rdbPredicates
.
equalTo
(
"
name
"
,
"
lisi
"
)
let
resultSet
=
await
rdbStore
.
query
(
rdbPredicates
)
expect
(
true
).
assertEqual
(
resultSet
.
goToFirstRow
())
const
id
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
id
"
))
const
name
=
resultSet
.
getString
(
resultSet
.
getColumnIndex
(
"
name
"
))
const
age
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
age
"
))
const
salary
=
resultSet
.
getDouble
(
resultSet
.
getColumnIndex
(
"
salary
"
))
const
blobType
=
resultSet
.
getBlob
(
resultSet
.
getColumnIndex
(
"
blobType
"
))
expect
(
"
lisi
"
).
assertEqual
(
name
)
expect
(
28
).
assertEqual
(
age
)
expect
(
200.5
).
assertEqual
(
salary
)
expect
(
4
).
assertEqual
(
blobType
[
0
])
expect
(
5
).
assertEqual
(
blobType
[
1
])
expect
(
6
).
assertEqual
(
blobType
[
2
])
console
.
log
(
TAG
+
"
dataShare update: {id=
"
+
id
+
"
, name=
"
+
name
+
"
,
"
+
"
age=
"
+
age
+
"
, salary=
"
+
salary
+
"
, blobType=
"
+
blobType
)
resultSet
=
null
done
()
console
.
log
(
TAG
+
"
************* testRdbStoreDataShareFunc0002 end *************
"
)
})
/**
* @tc.name rdb DataShare update test
* @tc.number SUB_DataShare_Rdb_Func0003
* @tc.desc rdb DataShare update callback Func test
*/
it
(
'
testRdbStoreDataShareFunc0003
'
,
0
,
async
function
(
done
)
{
console
.
log
(
TAG
+
"
************* testRdbStoreDataShareFunc0003 start *************
"
)
let
u8
=
new
Uint8Array
([
1
,
2
,
3
])
let
valueBucket
=
{
"
name
"
:
"
zhangsan
"
,
"
age
"
:
18
,
"
salary
"
:
100.5
,
"
blobType
"
:
u8
,
}
await
rdbStore
.
insert
(
"
test
"
,
valueBucket
)
u8
=
new
Uint8Array
([
4
,
5
,
6
])
valueBucket
=
{
"
name
"
:
"
lisi
"
,
"
age
"
:
28
,
"
salary
"
:
200.5
,
"
blobType
"
:
u8
,
}
let
predicates
=
new
dataShare
.
DataSharePredicates
()
predicates
.
equalTo
(
"
name
"
,
"
zhangsan
"
)
await
rdbStore
.
update
(
"
test
"
,
valueBucket
,
predicates
,
async
function
(
err
,
ret
)
{
if
(
err
)
{
console
.
info
(
"
Update err:
"
+
err
)
expect
(
false
).
assertTrue
()
}
expect
(
1
).
assertEqual
(
ret
)
console
.
log
(
"
Update done:
"
+
ret
)
let
rdbPredicates
=
await
new
dataRdb
.
RdbPredicates
(
"
test
"
)
rdbPredicates
.
equalTo
(
"
name
"
,
"
lisi
"
)
let
resultSet
=
await
rdbStore
.
query
(
rdbPredicates
)
expect
(
1
).
assertEqual
(
resultSet
.
rowCount
)
expect
(
true
).
assertEqual
(
resultSet
.
goToFirstRow
())
const
id
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
id
"
))
const
name
=
resultSet
.
getString
(
resultSet
.
getColumnIndex
(
"
name
"
))
const
age
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
age
"
))
const
salary
=
resultSet
.
getDouble
(
resultSet
.
getColumnIndex
(
"
salary
"
))
const
blobType
=
resultSet
.
getBlob
(
resultSet
.
getColumnIndex
(
"
blobType
"
))
expect
(
"
lisi
"
).
assertEqual
(
name
)
expect
(
28
).
assertEqual
(
age
)
expect
(
200.5
).
assertEqual
(
salary
)
expect
(
4
).
assertEqual
(
blobType
[
0
])
expect
(
5
).
assertEqual
(
blobType
[
1
])
expect
(
6
).
assertEqual
(
blobType
[
2
])
console
.
log
(
TAG
+
"
dataShare update: {id=
"
+
id
+
"
, name=
"
+
name
+
"
,
"
+
"
age=
"
+
age
+
"
, salary=
"
+
salary
+
"
, blobType=
"
+
blobType
)
resultSet
=
null
})
done
()
console
.
log
(
TAG
+
"
************* testRdbStoreDataShareFunc0003 end *************
"
)
})
/**
* @tc.name rdb DataShare query test
* @tc.number SUB_DataShare_Rdb_Func0004
* @tc.desc rdb DataShare query promise Func test
*/
it
(
'
testRdbStoreDataShareFunc0004
'
,
0
,
async
function
(
done
)
{
console
.
log
(
TAG
+
"
************* testRdbStoreDataShareFunc0004 start *************
"
)
let
u8
=
new
Uint8Array
([
4
,
5
,
6
])
let
valueBucket
=
{
"
name
"
:
"
zhangsan
"
,
"
age
"
:
18
,
"
salary
"
:
100.5
,
"
blobType
"
:
u8
,
}
await
rdbStore
.
insert
(
"
test
"
,
valueBucket
)
let
predicates
=
new
dataShare
.
DataSharePredicates
()
predicates
.
equalTo
(
"
name
"
,
"
zhangsan
"
)
let
queryPromise
=
rdbStore
.
query
(
"
test
"
,
predicates
)
queryPromise
.
then
((
resultSet
)
=>
{
console
.
log
(
TAG
+
"
DataShare Query done:
"
)
expect
(
true
).
assertEqual
(
resultSet
.
goToFirstRow
())
const
name
=
resultSet
.
getString
(
resultSet
.
getColumnIndex
(
"
name
"
))
const
age
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
age
"
))
const
salary
=
resultSet
.
getDouble
(
resultSet
.
getColumnIndex
(
"
salary
"
))
const
blobType
=
resultSet
.
getBlob
(
resultSet
.
getColumnIndex
(
"
blobType
"
))
expect
(
"
zhangsan
"
).
assertEqual
(
name
)
expect
(
18
).
assertEqual
(
age
)
expect
(
100.5
).
assertEqual
(
salary
)
expect
(
4
).
assertEqual
(
blobType
[
0
])
expect
(
5
).
assertEqual
(
blobType
[
1
])
expect
(
6
).
assertEqual
(
blobType
[
2
])
}).
catch
((
err
)
=>
{
console
.
log
(
TAG
+
"
Query err:
"
+
err
)
expect
(
false
).
assertTrue
()
})
await
queryPromise
done
()
console
.
log
(
TAG
+
"
************* testRdbStoreDataShareFunc0004 end *************
"
)
})
/**
* @tc.name rdb DataShare query test
* @tc.number SUB_DataShare_Rdb_Func0005
* @tc.desc rdb DataShare query callback Func test
*/
it
(
'
testRdbStoreDataShareFunc0005
'
,
0
,
async
function
(
done
)
{
console
.
log
(
TAG
+
"
************* testRdbStoreDataShareFunc0005 start *************
"
)
let
u8
=
new
Uint8Array
([
4
,
5
,
6
])
let
valueBucket
=
{
"
name
"
:
"
zhangsan
"
,
"
age
"
:
18
,
"
salary
"
:
100.5
,
"
blobType
"
:
u8
,
}
await
rdbStore
.
insert
(
"
test
"
,
valueBucket
)
let
predicates
=
new
dataShare
.
DataSharePredicates
()
predicates
.
equalTo
(
"
name
"
,
"
zhangsan
"
)
await
rdbStore
.
query
(
"
test
"
,
predicates
,
[
"
ID
"
,
"
NAME
"
,
"
AGE
"
,
"
SALARY
"
,
"
blobType
"
],
function
(
err
,
resultSet
)
{
if
(
err
)
{
console
.
info
(
"
Query err:
"
+
err
)
expect
(
false
).
assertTrue
()
}
expect
(
true
).
assertEqual
(
resultSet
.
goToFirstRow
())
const
name
=
resultSet
.
getString
(
resultSet
.
getColumnIndex
(
"
name
"
))
const
age
=
resultSet
.
getLong
(
resultSet
.
getColumnIndex
(
"
age
"
))
const
salary
=
resultSet
.
getDouble
(
resultSet
.
getColumnIndex
(
"
salary
"
))
const
blobType
=
resultSet
.
getBlob
(
resultSet
.
getColumnIndex
(
"
blobType
"
))
expect
(
"
zhangsan
"
).
assertEqual
(
name
)
expect
(
18
).
assertEqual
(
age
)
expect
(
100.5
).
assertEqual
(
salary
)
expect
(
4
).
assertEqual
(
blobType
[
0
])
expect
(
5
).
assertEqual
(
blobType
[
1
])
expect
(
6
).
assertEqual
(
blobType
[
2
])
})
done
()
console
.
log
(
TAG
+
"
************* testRdbStoreDataShareFunc0005 end *************
"
)
})
/**
* @tc.name rdb DataShare delete test
* @tc.number SUB_DataShare_Rdb_Func0006
* @tc.desc rdb DataShare delete Func test
*/
it
(
'
testRdbStoreDataShareFunc0006
'
,
0
,
async
function
(
done
)
{
console
.
log
(
TAG
+
"
************* testRdbStoreDataShareFunc0006 start *************
"
)
let
u8
=
new
Uint8Array
([
1
,
2
,
3
])
let
valueBucket
=
{
"
name
"
:
"
zhangsan
"
,
"
age
"
:
18
,
"
salary
"
:
100.5
,
"
blobType
"
:
u8
,
}
await
rdbStore
.
insert
(
"
test
"
,
valueBucket
)
let
predicates
=
new
dataShare
.
DataSharePredicates
()
predicates
.
equalTo
(
"
name
"
,
"
zhangsan
"
)
let
deletePromise
=
rdbStore
.
delete
(
"
test
"
,
predicates
)
deletePromise
.
then
(
async
(
ret
)
=>
{
expect
(
1
).
assertEqual
(
ret
)
console
.
log
(
TAG
+
"
Delete done:
"
+
ret
)
}).
catch
((
err
)
=>
{
console
.
log
(
TAG
+
"
Delete err:
"
+
err
)
expect
(
false
).
assertTrue
()
})
await
deletePromise
let
rdbPredicates
=
await
new
dataRdb
.
RdbPredicates
(
"
test
"
)
rdbPredicates
.
equalTo
(
"
name
"
,
"
zhangsan
"
)
let
resultSet
=
await
rdbStore
.
query
(
rdbPredicates
)
expect
(
false
).
assertEqual
(
resultSet
.
goToFirstRow
())
resultSet
=
null
done
()
console
.
log
(
TAG
+
"
************* testRdbStoreDataShareFunc0006 end *************
"
)
})
/**
* @tc.name rdb DataShare delete test
* @tc.number SUB_DataShare_Rdb_Func0007
* @tc.desc rdb DataShare delete Func test
*/
it
(
'
testRdbStoreDataShareFunc0007
'
,
0
,
async
function
(
done
)
{
console
.
log
(
TAG
+
"
************* testRdbStoreDataShareFunc0007 start *************
"
)
let
u8
=
new
Uint8Array
([
1
,
2
,
3
])
let
valueBucket
=
{
"
name
"
:
"
zhangsan
"
,
"
age
"
:
18
,
"
salary
"
:
100.5
,
"
blobType
"
:
u8
,
}
await
rdbStore
.
insert
(
"
test
"
,
valueBucket
)
let
predicates
=
new
dataShare
.
DataSharePredicates
()
predicates
.
equalTo
(
"
name
"
,
"
zhangsan
"
)
await
rdbStore
.
delete
(
"
test
"
,
predicates
,
async
function
(
err
,
ret
)
{
if
(
err
)
{
console
.
info
(
"
Delete err:
"
+
err
)
expect
(
false
).
assertTrue
()
}
expect
(
1
).
assertEqual
(
ret
)
console
.
log
(
"
Delete done:
"
+
ret
)
let
rdbPredicates
=
await
new
dataRdb
.
RdbPredicates
(
"
test
"
)
rdbPredicates
.
equalTo
(
"
name
"
,
"
zhangsan
"
)
let
resultSet
=
await
rdbStore
.
query
(
rdbPredicates
)
expect
(
false
).
assertEqual
(
resultSet
.
goToFirstRow
())
resultSet
=
null
})
done
()
console
.
log
(
TAG
+
"
************* testRdbStoreDataShareFunc0007 end *************
"
)
})
console
.
log
(
TAG
+
"
*************Unit Test End*************
"
)
})
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录