Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
5b551af6
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看板
提交
5b551af6
编写于
8月 04, 2022
作者:
L
liangzhenyu123
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
kv_store部件xts用例适配新框架
Signed-off-by:
N
liangzhenyu123
<
liangzhenyu6@huawei.com
>
上级
5fd1c9d3
变更
33
隐藏空白更改
内联
并排
Showing
33 changed file
with
1359 addition
and
80 deletion
+1359
-80
distributeddatamgr/kvStorejstest/hap/BUILD.gn
distributeddatamgr/kvStorejstest/hap/BUILD.gn
+4
-2
distributeddatamgr/kvStorejstest/hap/Test.json
distributeddatamgr/kvStorejstest/hap/Test.json
+5
-3
distributeddatamgr/kvStorejstest/hap/src/main/config.json
distributeddatamgr/kvStorejstest/hap/src/main/config.json
+40
-8
distributeddatamgr/kvStorejstest/hap/src/main/js/MainAbility/app.js
...ddatamgr/kvStorejstest/hap/src/main/js/MainAbility/app.js
+0
-0
distributeddatamgr/kvStorejstest/hap/src/main/js/MainAbility/i18n/en-US.json
...kvStorejstest/hap/src/main/js/MainAbility/i18n/en-US.json
+0
-0
distributeddatamgr/kvStorejstest/hap/src/main/js/MainAbility/i18n/zh-CN.json
...kvStorejstest/hap/src/main/js/MainAbility/i18n/zh-CN.json
+0
-0
distributeddatamgr/kvStorejstest/hap/src/main/js/MainAbility/pages/index/index.css
...ejstest/hap/src/main/js/MainAbility/pages/index/index.css
+0
-0
distributeddatamgr/kvStorejstest/hap/src/main/js/MainAbility/pages/index/index.hml
...ejstest/hap/src/main/js/MainAbility/pages/index/index.hml
+0
-0
distributeddatamgr/kvStorejstest/hap/src/main/js/MainAbility/pages/index/index.js
...rejstest/hap/src/main/js/MainAbility/pages/index/index.js
+0
-6
distributeddatamgr/kvStorejstest/hap/src/main/js/TestAbility/app.js
...ddatamgr/kvStorejstest/hap/src/main/js/TestAbility/app.js
+31
-0
distributeddatamgr/kvStorejstest/hap/src/main/js/TestAbility/i18n/en-US.json
...kvStorejstest/hap/src/main/js/TestAbility/i18n/en-US.json
+8
-0
distributeddatamgr/kvStorejstest/hap/src/main/js/TestAbility/i18n/zh-CN.json
...kvStorejstest/hap/src/main/js/TestAbility/i18n/zh-CN.json
+8
-0
distributeddatamgr/kvStorejstest/hap/src/main/js/TestAbility/pages/index/index.css
...ejstest/hap/src/main/js/TestAbility/pages/index/index.css
+30
-0
distributeddatamgr/kvStorejstest/hap/src/main/js/TestAbility/pages/index/index.hml
...ejstest/hap/src/main/js/TestAbility/pages/index/index.hml
+5
-0
distributeddatamgr/kvStorejstest/hap/src/main/js/TestAbility/pages/index/index.js
...rejstest/hap/src/main/js/TestAbility/pages/index/index.js
+26
-0
distributeddatamgr/kvStorejstest/hap/src/main/js/TestRunner/OpenHarmonyTestRunner.js
...stest/hap/src/main/js/TestRunner/OpenHarmonyTestRunner.js
+59
-0
distributeddatamgr/kvStorejstest/hap/src/main/js/test/DeviceKvStoreCallbackJsunit.test.js
.../hap/src/main/js/test/DeviceKvStoreCallbackJsunit.test.js
+5
-4
distributeddatamgr/kvStorejstest/hap/src/main/js/test/DeviceKvStorePromiseJsunit.test.js
...t/hap/src/main/js/test/DeviceKvStorePromiseJsunit.test.js
+7
-8
distributeddatamgr/kvStorejstest/hap/src/main/js/test/FieldNodeJsunit.test.js
...vStorejstest/hap/src/main/js/test/FieldNodeJsunit.test.js
+5
-3
distributeddatamgr/kvStorejstest/hap/src/main/js/test/KvManagerCallbackJsunit.test.js
...test/hap/src/main/js/test/KvManagerCallbackJsunit.test.js
+4
-15
distributeddatamgr/kvStorejstest/hap/src/main/js/test/KvManagerPromiseJsunit.test.js
...stest/hap/src/main/js/test/KvManagerPromiseJsunit.test.js
+8
-8
distributeddatamgr/kvStorejstest/hap/src/main/js/test/KvStoreResultSetJsunit.test.js
...stest/hap/src/main/js/test/KvStoreResultSetJsunit.test.js
+5
-3
distributeddatamgr/kvStorejstest/hap/src/main/js/test/List.test.js
...eddatamgr/kvStorejstest/hap/src/main/js/test/List.test.js
+39
-0
distributeddatamgr/kvStorejstest/hap/src/main/js/test/QueryJsunit.test.js
...gr/kvStorejstest/hap/src/main/js/test/QueryJsunit.test.js
+5
-3
distributeddatamgr/kvStorejstest/hap/src/main/js/test/SchemaJsunit.test.js
...r/kvStorejstest/hap/src/main/js/test/SchemaJsunit.test.js
+4
-3
distributeddatamgr/kvStorejstest/hap/src/main/js/test/SingleKvStoreCallbackJsunit.test.js
.../hap/src/main/js/test/SingleKvStoreCallbackJsunit.test.js
+5
-3
distributeddatamgr/kvStorejstest/hap/src/main/js/test/SingleKvStoreEnumJsunit.test.js
...test/hap/src/main/js/test/SingleKvStoreEnumJsunit.test.js
+5
-3
distributeddatamgr/kvStorejstest/hap/src/main/js/test/SingleKvStorePromiseJsunit.test.js
...t/hap/src/main/js/test/SingleKvStorePromiseJsunit.test.js
+8
-7
distributeddatamgr/kvStorejstest/hap/src/main/resources/base/element/string.json
...orejstest/hap/src/main/resources/base/element/string.json
+17
-1
distributeddatamgr/preferencesjstest/hap/src/main/js/test/List.test.js
...tamgr/preferencesjstest/hap/src/main/js/test/List.test.js
+6
-0
distributeddatamgr/preferencesjstest/hap/src/main/js/test/PreferencesCallBackJsunit.test.js
...st/hap/src/main/js/test/PreferencesCallBackJsunit.test.js
+417
-0
distributeddatamgr/preferencesjstest/hap/src/main/js/test/PreferencesHelperJsunit.test.js
...test/hap/src/main/js/test/PreferencesHelperJsunit.test.js
+149
-0
distributeddatamgr/preferencesjstest/hap/src/main/js/test/PreferencesPromiseJsunit.test.js
...est/hap/src/main/js/test/PreferencesPromiseJsunit.test.js
+454
-0
未找到文件。
distributeddatamgr/kvStorejstest/hap/BUILD.gn
浏览文件 @
5b551af6
...
...
@@ -20,12 +20,14 @@ ohos_js_hap_suite("kvStore_js_test") {
":kvStore_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActKvStoreJsTest"
hap_name = "Act
s
KvStoreJsTest"
subsystem_name = "distributeddatamgr"
part_name = "distributeddatamgr"
}
ohos_js_assets("kvStore_js_assets") {
source_dir = "./src/main/js/default"
js2abc = true
hap_profile = "./src/main/config.json"
source_dir = "./src/main/js"
}
ohos_resources("kvStore_resources") {
sources = [ "./src/main/resources" ]
...
...
distributeddatamgr/kvStorejstest/hap/Test.json
浏览文件 @
5b551af6
{
"description"
:
"Configuration for hjunit demo Tests"
,
"driver"
:
{
"type"
:
"JSUnitTest"
,
"type"
:
"
OH
JSUnitTest"
,
"test-timeout"
:
"1200000"
,
"package"
:
"ohos.acts.kvStore"
,
"testcase-timeout"
:
60000
,
"bundle-name"
:
"ohos.acts.kvStore"
,
"package-name"
:
"ohos.acts.kvStore"
,
"shell-timeout"
:
"60000"
},
"kits"
:
[
{
"test-file-name"
:
[
"ActKvStoreJsTest.hap"
"Act
s
KvStoreJsTest.hap"
],
"type"
:
"AppInstallKit"
,
"cleanup-apps"
:
true
...
...
distributeddatamgr/kvStorejstest/hap/src/main/config.json
浏览文件 @
5b551af6
...
...
@@ -14,8 +14,9 @@
"deviceConfig"
:
{},
"module"
:
{
"package"
:
"ohos.acts.kvStore"
,
"name"
:
".MyApplication"
,
"mainAbility"
:
"ohos.acts.kvStore.MainAbility"
,
"name"
:
".entry"
,
"mainAbility"
:
".MainAbility"
,
"srcPath"
:
""
,
"deviceType"
:
[
"phone"
],
...
...
@@ -27,7 +28,6 @@
},
"abilities"
:
[
{
"visible"
:
true
,
"skills"
:
[
{
"entities"
:
[
...
...
@@ -38,13 +38,31 @@
]
}
],
"name"
:
"ohos.acts.kvStore.MainAbility"
,
"orientation"
:
"unspecified"
,
"formsEnabled"
:
false
,
"name"
:
".MainAbility"
,
"srcLanguage"
:
"js"
,
"srcPath"
:
"MainAbility"
,
"icon"
:
"$media:icon"
,
"description"
:
"$string:MainAbility_desc"
,
"label"
:
"$string:MainAbility_label"
,
"type"
:
"page"
,
"visible"
:
true
,
"launchType"
:
"standard"
},
{
"orientation"
:
"unspecified"
,
"formsEnabled"
:
false
,
"name"
:
".TestAbility"
,
"srcLanguage"
:
"js"
,
"srcPath"
:
"TestAbility"
,
"icon"
:
"$media:icon"
,
"description"
:
"$string:
mainability_description
"
,
"label"
:
"$string:
app_name
"
,
"description"
:
"$string:
TestAbility_desc
"
,
"label"
:
"$string:
TestAbility_label
"
,
"type"
:
"page"
,
"visible"
:
true
,
"launchType"
:
"standard"
}
}
],
"js"
:
[
{
...
...
@@ -56,7 +74,21 @@
"designWidth"
:
720
,
"autoDesignWidth"
:
true
}
},
{
"pages"
:
[
"pages/index/index"
],
"name"
:
".TestAbility"
,
"window"
:
{
"designWidth"
:
720
,
"autoDesignWidth"
:
false
}
}
]
],
"testRunner"
:
{
"name"
:
"OpenHarmonyTestRunner"
,
"srcPath"
:
"TestRunner"
}
}
}
\ No newline at end of file
distributeddatamgr/kvStorejstest/hap/src/main/js/
default
/app.js
→
distributeddatamgr/kvStorejstest/hap/src/main/js/
MainAbility
/app.js
浏览文件 @
5b551af6
文件已移动
distributeddatamgr/kvStorejstest/hap/src/main/js/
default
/i18n/en-US.json
→
distributeddatamgr/kvStorejstest/hap/src/main/js/
MainAbility
/i18n/en-US.json
浏览文件 @
5b551af6
文件已移动
distributeddatamgr/kvStorejstest/hap/src/main/js/
default
/i18n/zh-CN.json
→
distributeddatamgr/kvStorejstest/hap/src/main/js/
MainAbility
/i18n/zh-CN.json
浏览文件 @
5b551af6
文件已移动
distributeddatamgr/kvStorejstest/hap/src/main/js/
default
/pages/index/index.css
→
distributeddatamgr/kvStorejstest/hap/src/main/js/
MainAbility
/pages/index/index.css
浏览文件 @
5b551af6
文件已移动
distributeddatamgr/kvStorejstest/hap/src/main/js/
default
/pages/index/index.hml
→
distributeddatamgr/kvStorejstest/hap/src/main/js/
MainAbility
/pages/index/index.hml
浏览文件 @
5b551af6
文件已移动
distributeddatamgr/kvStorejstest/hap/src/main/js/
default
/pages/index/index.js
→
distributeddatamgr/kvStorejstest/hap/src/main/js/
MainAbility
/pages/index/index.js
浏览文件 @
5b551af6
...
...
@@ -12,8 +12,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
{
Core
}
from
'
deccjsunit/index
'
const
injectRef
=
Object
.
getPrototypeOf
(
global
)
||
global
injectRef
.
regeneratorRuntime
=
require
(
'
@babel/runtime/regenerator
'
)
...
...
@@ -26,10 +24,6 @@ export default {
},
onShow
()
{
console
.
info
(
'
onShow finish
'
)
const
core
=
Core
.
getInstance
()
core
.
init
()
require
(
'
../../test/List.test
'
)
core
.
execute
()
},
onReady
()
{
},
...
...
distributeddatamgr/kvStorejstest/hap/src/main/js/TestAbility/app.js
0 → 100644
浏览文件 @
5b551af6
/*
* 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
AbilityDelegatorRegistry
from
'
@ohos.application.abilityDelegatorRegistry
'
import
{
Hypium
}
from
'
@ohos/hypium
'
import
testsuite
from
'
../test/List.test
'
export
default
{
onCreate
()
{
console
.
info
(
'
TestApplication onCreate
'
)
var
abilityDelegator
=
AbilityDelegatorRegistry
.
getAbilityDelegator
()
var
abilityDelegatorArguments
=
AbilityDelegatorRegistry
.
getArguments
()
console
.
info
(
'
start run testcase!!!
'
)
Hypium
.
hypiumTest
(
abilityDelegator
,
abilityDelegatorArguments
,
testsuite
)
},
onDestroy
()
{
console
.
info
(
"
TestApplication onDestroy
"
);
}
};
distributeddatamgr/kvStorejstest/hap/src/main/js/TestAbility/i18n/en-US.json
0 → 100644
浏览文件 @
5b551af6
{
"strings"
:
{
"hello"
:
"Hello"
,
"world"
:
"World"
},
"Files"
:
{
}
}
\ No newline at end of file
distributeddatamgr/kvStorejstest/hap/src/main/js/TestAbility/i18n/zh-CN.json
0 → 100644
浏览文件 @
5b551af6
{
"strings"
:
{
"hello"
:
"您好"
,
"world"
:
"世界"
},
"Files"
:
{
}
}
\ No newline at end of file
distributeddatamgr/kvStorejstest/hap/src/main/js/TestAbility/pages/index/index.css
0 → 100644
浏览文件 @
5b551af6
.container
{
display
:
flex
;
flex-direction
:
column
;
justify-content
:
center
;
align-items
:
center
;
left
:
0px
;
top
:
0px
;
width
:
100%
;
height
:
100%
;
}
.title
{
font-size
:
60px
;
text-align
:
center
;
width
:
100%
;
height
:
40%
;
margin
:
10px
;
}
@media
screen
and
(
device-type
:
phone
)
and
(
orientation
:
landscape
)
{
.title
{
font-size
:
60px
;
}
}
@media
screen
and
(
device-type
:
tablet
)
and
(
orientation
:
landscape
)
{
.title
{
font-size
:
100px
;
}
}
\ No newline at end of file
distributeddatamgr/kvStorejstest/hap/src/main/js/TestAbility/pages/index/index.hml
0 → 100644
浏览文件 @
5b551af6
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
distributeddatamgr/kvStorejstest/hap/src/main/js/TestAbility/pages/index/index.js
0 → 100644
浏览文件 @
5b551af6
/*
* 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.
*/
export
default
{
data
:
{
title
:
""
},
onInit
()
{
this
.
title
=
this
.
$t
(
'
strings.world
'
);
}
}
distributeddatamgr/kvStorejstest/hap/src/main/js/TestRunner/OpenHarmonyTestRunner.js
0 → 100644
浏览文件 @
5b551af6
/*
* 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
AbilityDelegatorRegistry
from
'
@ohos.application.abilityDelegatorRegistry
'
function
translateParamsToString
(
parameters
)
{
const
keySet
=
new
Set
([
'
-s class
'
,
'
-s notClass
'
,
'
-s suite
'
,
'
-s itName
'
,
'
-s level
'
,
'
-s testType
'
,
'
-s size
'
,
'
-s timeout
'
,
'
-s package
'
,
'
-s dryRun
'
])
let
targetParams
=
''
;
for
(
const
key
in
parameters
)
{
if
(
keySet
.
has
(
key
))
{
targetParams
+=
'
'
+
key
+
'
'
+
parameters
[
key
]
}
}
return
targetParams
.
trim
()
}
export
default
{
onPrepare
()
{
console
.
info
(
'
OpenHarmonyTestRunner OnPrepare
'
)
},
onRun
()
{
console
.
log
(
'
OpenHarmonyTestRunner onRun run
'
)
var
abilityDelegatorArguments
=
AbilityDelegatorRegistry
.
getArguments
()
var
abilityDelegator
=
AbilityDelegatorRegistry
.
getAbilityDelegator
()
var
testAbilityName
=
abilityDelegatorArguments
.
parameters
[
'
-p
'
]
+
'
.TestAbility
'
var
cmd
=
'
aa start -d 0 -a
'
+
testAbilityName
+
'
-b
'
+
abilityDelegatorArguments
.
bundleName
cmd
+=
'
'
+
translateParamsToString
(
abilityDelegatorArguments
.
parameters
)
var
debug
=
abilityDelegatorArguments
.
parameters
[
"
-D
"
]
console
.
info
(
'
debug value :
'
+
debug
)
if
(
debug
==
'
true
'
)
{
cmd
+=
'
-D
'
}
console
.
info
(
'
cmd :
'
+
cmd
)
abilityDelegator
.
executeShellCommand
(
cmd
,
(
err
,
data
)
=>
{
console
.
info
(
'
executeShellCommand : err :
'
+
JSON
.
stringify
(
err
));
console
.
info
(
'
executeShellCommand : data :
'
+
data
.
stdResult
);
console
.
info
(
'
executeShellCommand : data :
'
+
data
.
exitCode
);
})
}
};
distributeddatamgr/kvStorejstest/hap/src/main/js/
default/
test/DeviceKvStoreCallbackJsunit.test.js
→
distributeddatamgr/kvStorejstest/hap/src/main/js/test/DeviceKvStoreCallbackJsunit.test.js
浏览文件 @
5b551af6
...
...
@@ -12,7 +12,7 @@
* 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
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
import
factory
from
'
@ohos.data.distributedData
'
const
KEY_TEST_INT_ELEMENT
=
'
key_test_int_2
'
;
...
...
@@ -54,8 +54,8 @@ function putBatchString(len, prefix) {
}
return
entries
;
}
describe
(
'
D
eviceKvStoreCallbackTest
'
,
function
()
{
export
default
function
deviceKvStoreCallbackTest
(){
describe
(
'
d
eviceKvStoreCallbackTest
'
,
function
()
{
const
config
=
{
bundleName
:
TEST_BUNDLE_NAME
,
userInfo
:
{
...
...
@@ -2299,4 +2299,5 @@ describe('DeviceKvStoreCallbackTest', function () {
}
done
();
})
})
\ No newline at end of file
})
}
\ No newline at end of file
distributeddatamgr/kvStorejstest/hap/src/main/js/
default/
test/DeviceKvStorePromiseJsunit.test.js
→
distributeddatamgr/kvStorejstest/hap/src/main/js/test/DeviceKvStorePromiseJsunit.test.js
浏览文件 @
5b551af6
...
...
@@ -12,7 +12,7 @@
* 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
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
import
factory
from
'
@ohos.data.distributedData
'
const
KEY_TEST_INT_ELEMENT
=
'
key_test_int
'
;
...
...
@@ -54,8 +54,8 @@ function putBatchString(len, prefix) {
}
return
entries
;
}
describe
(
'
D
eviceKvStorePromiseTest
'
,
function
()
{
export
default
function
deviceKvStorePromiseTest
(){
describe
(
'
d
eviceKvStorePromiseTest
'
,
function
()
{
const
config
=
{
bundleName
:
TEST_BUNDLE_NAME
,
userInfo
:
{
...
...
@@ -1071,10 +1071,9 @@ describe('DeviceKvStorePromiseTest', function () {
kvStore
.
on
(
'
syncComplete
'
,
func
);
kvStore
.
on
(
'
syncComplete
'
,
func1
);
kvStore
.
off
(
'
syncComplete
'
,
func
);
expect
(
null
).
assertFail
();
}
catch
(
e
)
{
console
.
info
(
'
testDeviceKvStoreOffSyncComplete002 put e
'
+
e
);
expect
(
true
).
assertTrue
();
expect
(
null
).
assertFail
();
}
done
();
})
...
...
@@ -1097,10 +1096,9 @@ describe('DeviceKvStorePromiseTest', function () {
kvStore
.
on
(
'
syncComplete
'
,
func1
);
kvStore
.
off
(
'
syncComplete
'
,
func
);
kvStore
.
off
(
'
syncComplete
'
,
func1
);
expect
(
null
).
assertFail
();
}
catch
(
e
)
{
console
.
info
(
'
testDeviceKvStoreOffSyncComplete003 put e
'
+
e
);
expect
(
true
).
assertTrue
();
expect
(
null
).
assertFail
();
}
done
();
})
...
...
@@ -2532,4 +2530,5 @@ describe('DeviceKvStorePromiseTest', function () {
}
done
();
})
})
\ No newline at end of file
})
}
\ No newline at end of file
distributeddatamgr/kvStorejstest/hap/src/main/js/
default/
test/FieldNodeJsunit.test.js
→
distributeddatamgr/kvStorejstest/hap/src/main/js/test/FieldNodeJsunit.test.js
浏览文件 @
5b551af6
...
...
@@ -12,10 +12,11 @@
* 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
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
import
ddm
from
'
@ohos.data.distributedData
'
;
describe
(
'
FieldNodeTest
'
,
function
()
{
export
default
function
fieldNodeTest
(){
describe
(
'
fieldNodeTest
'
,
function
()
{
/**
* @tc.number SUB_DISTRIBUTEDDATAMGR_FIELDNODE_APPENDCHILD_0100
...
...
@@ -261,4 +262,5 @@ describe('FieldNodeTest', function() {
}
done
();
})
})
\ No newline at end of file
})
}
\ No newline at end of file
distributeddatamgr/kvStorejstest/hap/src/main/js/
default/
test/KvManagerCallbackJsunit.test.js
→
distributeddatamgr/kvStorejstest/hap/src/main/js/test/KvManagerCallbackJsunit.test.js
浏览文件 @
5b551af6
...
...
@@ -22,7 +22,8 @@ const STORE_VALUE = 'value-test-string';
var
kvManager
=
null
;
var
kvStore
=
null
;
describe
(
'
KVManagerCallbackTest
'
,
function
()
{
export
default
function
kvManagerCallbackTest
(){
describe
(
'
kvManagerCallbackTest
'
,
function
()
{
const
config
=
{
bundleName
:
TEST_BUNDLE_NAME
,
userInfo
:
{
...
...
@@ -935,17 +936,5 @@ describe('KVManagerCallbackTest', function () {
done
();
}
})
/**
* @tc.number SUB_DISTRIBUTEDDATAMGR_KVSTORE_ON_1100
* @tc.name [JS-API8]KVStore.On
* @tc.desc Test Js Api KVManager.On testcase 101
*/
// it('testKVStoreOn101', 0, async function (done) {
// kvStoreNew.on('syncComplete', function (data) {
// console.info("testKVStoreOn101 callback call data: " + data);
// expect(true).assertTrue();
// });
// done();
// })
})
\ No newline at end of file
})
}
\ No newline at end of file
distributeddatamgr/kvStorejstest/hap/src/main/js/
default/
test/KvManagerPromiseJsunit.test.js
→
distributeddatamgr/kvStorejstest/hap/src/main/js/test/KvManagerPromiseJsunit.test.js
浏览文件 @
5b551af6
...
...
@@ -12,7 +12,7 @@
* 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
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
import
factory
from
'
@ohos.data.distributedData
'
;
const
TEST_BUNDLE_NAME
=
'
ohos.acts.kvStore
'
;
...
...
@@ -23,7 +23,8 @@ const STORE_KEY = 'key_test_string';
const
STORE_VALUE
=
'
value-test-string
'
;
var
kvStoreNew
=
null
;
describe
(
'
KVManagerPromiseTest
'
,
function
()
{
export
default
function
kvManagerPromiseTest
(){
describe
(
'
kvManagerPromiseTest
'
,
function
()
{
const
config
=
{
bundleName
:
TEST_BUNDLE_NAME
,
userInfo
:
{
...
...
@@ -413,9 +414,9 @@ describe('KVManagerPromiseTest', function () {
try
{
await
kvManager
.
getKVStore
(
TEST_STORE_ID
,
optionsInfo
).
then
((
store
)
=>
{
console
.
info
(
'
testKVManagerGetKVStore013 getKVStore success
'
);
expect
(
null
).
assertFail
();
}).
catch
((
err
)
=>
{
console
.
info
(
'
testKVManagerGetKVStore013 getKVStore err
'
+
err
);
expect
(
null
).
assertFail
();
});
}
catch
(
e
)
{
console
.
info
(
'
testKVManagerGetKVStore013 getKVStore e
'
+
e
);
...
...
@@ -610,8 +611,8 @@ describe('KVManagerPromiseTest', function () {
console
.
info
(
'
testKVManagerDeleteKVStore001
'
);
await
kvManager
.
deleteKVStore
(
TEST_BUNDLE_NAME
,
TEST_STORE_ID
).
then
(()
=>
{
console
.
info
(
'
testKVManagerDeleteKVStore001 deleteKVStore success
'
);
expect
(
null
).
assertFail
();
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
console
.
info
(
'
testKVManagerDeleteKVStore001 deleteKVStore err
'
+
err
);
});
done
();
...
...
@@ -862,7 +863,6 @@ describe('KVManagerPromiseTest', function () {
}
done
();
})
})
\ No newline at end of file
})
}
\ No newline at end of file
distributeddatamgr/kvStorejstest/hap/src/main/js/
default/
test/KvStoreResultSetJsunit.test.js
→
distributeddatamgr/kvStorejstest/hap/src/main/js/test/KvStoreResultSetJsunit.test.js
浏览文件 @
5b551af6
...
...
@@ -12,7 +12,7 @@
* 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
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
import
factory
from
'
@ohos.data.distributedData
'
;
const
TEST_BUNDLE_NAME
=
'
ohos.acts.kvStore
'
;
...
...
@@ -21,7 +21,8 @@ var kvManager = null;
var
kvStore
=
null
;
var
resultSet
=
null
;
describe
(
'
KvStoreResultSetTest
'
,
function
()
{
export
default
function
kvStoreResultSetTest
(){
describe
(
'
kvStoreResultSetTest
'
,
function
()
{
const
config
=
{
bundleName
:
TEST_BUNDLE_NAME
,
userInfo
:
{
...
...
@@ -1084,4 +1085,5 @@ describe('KvStoreResultSetTest', function() {
}
done
();
})
})
\ No newline at end of file
})
}
\ No newline at end of file
distributeddatamgr/kvStorejstest/hap/src/main/js/
default/
test/List.test.js
→
distributeddatamgr/kvStorejstest/hap/src/main/js/test/List.test.js
浏览文件 @
5b551af6
...
...
@@ -12,14 +12,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
require
(
'
./DeviceKvStorePromiseJsunit.test.js
'
)
require
(
'
./DeviceKvStoreCallbackJsunit.test.js
'
)
require
(
'
./SingleKvStorePromiseJsunit.test.js
'
)
require
(
'
./SingleKvStoreCallbackJsunit.test.js
'
)
require
(
'
./SingleKvStoreEnumJsunit.test.js
'
)
require
(
'
./KvManagerPromiseJsunit.test.js
'
)
require
(
'
./KvManagerCallbackJsunit.test.js
'
)
require
(
'
./KvStoreResultSetJsunit.test.js
'
)
require
(
'
./QueryJsunit.test.js
'
)
require
(
'
./FieldNodeJsunit.test.js
'
)
require
(
'
./SchemaJsunit.test.js
'
)
\ No newline at end of file
import
deviceKvStorePromiseTest
from
'
./DeviceKvStorePromiseJsunit.test.js
'
import
deviceKvStoreCallbackTest
from
'
./DeviceKvStoreCallbackJsunit.test.js
'
import
singleKvStorePromiseTest
from
'
./SingleKvStorePromiseJsunit.test.js
'
import
singleKvStoreCallbackTest
from
'
./SingleKvStoreCallbackJsunit.test.js
'
import
singleKvStoreEnumTest
from
'
./SingleKvStoreEnumJsunit.test.js
'
import
kvManagerPromiseTest
from
'
./KvManagerPromiseJsunit.test.js
'
import
kvManagerCallbackTest
from
'
./KvManagerCallbackJsunit.test.js
'
import
kvStoreResultSetTest
from
'
./KvStoreResultSetJsunit.test.js
'
import
queryTest
from
'
./QueryJsunit.test.js
'
import
fieldNodeTest
from
'
./FieldNodeJsunit.test.js
'
import
schemaTest
from
'
./SchemaJsunit.test.js
'
export
default
function
testsuite
()
{
deviceKvStoreCallbackTest
()
deviceKvStorePromiseTest
()
singleKvStorePromiseTest
()
singleKvStoreCallbackTest
()
singleKvStoreEnumTest
()
kvManagerPromiseTest
()
kvManagerCallbackTest
()
kvStoreResultSetTest
()
queryTest
()
fieldNodeTest
()
schemaTest
()
}
\ No newline at end of file
distributeddatamgr/kvStorejstest/hap/src/main/js/
default/
test/QueryJsunit.test.js
→
distributeddatamgr/kvStorejstest/hap/src/main/js/test/QueryJsunit.test.js
浏览文件 @
5b551af6
...
...
@@ -12,10 +12,11 @@
* 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
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
import
ddm
from
'
@ohos.data.distributedData
'
;
describe
(
'
QueryTest
'
,
function
()
{
export
default
function
queryTest
(){
describe
(
'
queryTest
'
,
function
()
{
/**
* @tc.number SUB_DISTRIBUTEDDATAMGR_QUERY_RESET_0100
...
...
@@ -2361,4 +2362,5 @@ describe('QueryTest', function() {
query
=
null
;
done
();
})
})
\ No newline at end of file
})
}
\ No newline at end of file
distributeddatamgr/kvStorejstest/hap/src/main/js/
default/
test/SchemaJsunit.test.js
→
distributeddatamgr/kvStorejstest/hap/src/main/js/test/SchemaJsunit.test.js
浏览文件 @
5b551af6
...
...
@@ -12,7 +12,7 @@
* 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
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
import
ddm
from
'
@ohos.data.distributedData
'
;
const
TEST_BUNDLE_NAME
=
'
ohos.acts.kvStore
'
;
...
...
@@ -83,7 +83,8 @@ async function testPutAndGet(kvManager, options) {
}
}
describe
(
'
SchemaTest
'
,
function
()
{
export
default
function
schemaTest
(){
describe
(
'
schemaTest
'
,
function
()
{
const
config
=
{
bundleName
:
TEST_BUNDLE_NAME
,
userInfo
:
{
...
...
@@ -372,4 +373,4 @@ describe('SchemaTest', function() {
done
();
})
})
}
distributeddatamgr/kvStorejstest/hap/src/main/js/
default/
test/SingleKvStoreCallbackJsunit.test.js
→
distributeddatamgr/kvStorejstest/hap/src/main/js/test/SingleKvStoreCallbackJsunit.test.js
浏览文件 @
5b551af6
...
...
@@ -12,7 +12,7 @@
* 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
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
import
factory
from
'
@ohos.data.distributedData
'
const
KEY_TEST_INT_ELEMENT
=
'
key_test_int_2
'
;
...
...
@@ -54,7 +54,8 @@ function putBatchString(len, prefix) {
return
entries
;
}
describe
(
'
SingleKvStoreCallbackTest
'
,
function
()
{
export
default
function
singleKvStoreCallbackTest
(){
describe
(
'
singleKvStoreCallbackTest
'
,
function
()
{
const
config
=
{
bundleName
:
TEST_BUNDLE_NAME
,
userInfo
:
{
...
...
@@ -2435,4 +2436,5 @@ describe('SingleKvStoreCallbackTest', function () {
}
done
();
})
})
\ No newline at end of file
})
}
\ No newline at end of file
distributeddatamgr/kvStorejstest/hap/src/main/js/
default/
test/SingleKvStoreEnumJsunit.test.js
→
distributeddatamgr/kvStorejstest/hap/src/main/js/test/SingleKvStoreEnumJsunit.test.js
浏览文件 @
5b551af6
...
...
@@ -12,10 +12,11 @@
* 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
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
import
factory
from
'
@ohos.data.distributedData
'
;
describe
(
'
KvStoreEnumTest
'
,
function
()
{
export
default
function
singleKvStoreEnumTest
(){
describe
(
'
singleKvStoreEnumTest
'
,
function
()
{
/**
* @tc.number SUB_DISTRIBUTEDDATAMGR_USERTYPE_SAMEUSERID_0100
...
...
@@ -339,4 +340,5 @@ describe('KvStoreEnumTest', function () {
console
.
info
(
'
s4 =
'
+
s4
);
expect
(
s4
==
6
).
assertTrue
()
})
})
\ No newline at end of file
})
}
\ No newline at end of file
distributeddatamgr/kvStorejstest/hap/src/main/js/
default/
test/SingleKvStorePromiseJsunit.test.js
→
distributeddatamgr/kvStorejstest/hap/src/main/js/test/SingleKvStorePromiseJsunit.test.js
浏览文件 @
5b551af6
...
...
@@ -12,7 +12,7 @@
* 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
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
import
factory
from
'
@ohos.data.distributedData
'
const
KEY_TEST_INT_ELEMENT
=
'
key_test_int
'
;
...
...
@@ -54,7 +54,8 @@ function putBatchString(len, prefix) {
return
entries
;
}
describe
(
'
SingleKvStorePromiseTest
'
,
function
()
{
export
default
function
singleKvStorePromiseTest
(){
describe
(
'
singleKvStorePromiseTest
'
,
function
()
{
const
config
=
{
bundleName
:
TEST_BUNDLE_NAME
,
userInfo
:
{
...
...
@@ -942,6 +943,7 @@ describe('SingleKvStorePromiseTest', function () {
*/
it
(
'
testSingleKvStoreOffChange002
'
,
0
,
async
function
(
done
)
{
console
.
info
(
'
testSingleKvStoreOffChange002
'
);
let
ret
=
false
;
try
{
var
func
=
function
(
data
)
{
console
.
info
(
'
testSingleKvStoreOffChange002
'
+
JSON
.
stringify
(
data
));
...
...
@@ -1041,10 +1043,9 @@ describe('SingleKvStorePromiseTest', function () {
kvStore
.
on
(
'
syncComplete
'
,
func
);
kvStore
.
on
(
'
syncComplete
'
,
func1
);
kvStore
.
off
(
'
syncComplete
'
,
func
);
expect
(
null
).
assertFail
();
}
catch
(
e
)
{
console
.
info
(
'
testSingleKvStoreOffSyncComplete002 put e
'
+
e
);
expect
(
true
).
assertTrue
();
expect
(
null
).
assertFail
();
}
done
();
})
...
...
@@ -1067,10 +1068,9 @@ describe('SingleKvStorePromiseTest', function () {
kvStore
.
on
(
'
syncComplete
'
,
func1
);
kvStore
.
off
(
'
syncComplete
'
,
func
);
kvStore
.
off
(
'
syncComplete
'
,
func1
);
expect
(
null
).
assertFail
();
}
catch
(
e
)
{
console
.
info
(
'
testSingleKvStoreOffSyncComplete003 put e
'
+
e
);
expect
(
true
).
assertTrue
();
expect
(
null
).
assertFail
();
}
done
();
})
...
...
@@ -2732,4 +2732,5 @@ describe('SingleKvStorePromiseTest', function () {
});
done
();
})
})
\ No newline at end of file
})
}
\ No newline at end of file
distributeddatamgr/kvStorejstest/hap/src/main/resources/base/element/string.json
浏览文件 @
5b551af6
...
...
@@ -7,6 +7,22 @@
{
"name"
:
"mainability_description"
,
"value"
:
"hap sample empty page"
}
},
{
"name"
:
"MainAbility_desc"
,
"value"
:
"description"
},
{
"name"
:
"MainAbility_label"
,
"value"
:
"label"
},
{
"name"
:
"TestAbility_desc"
,
"value"
:
"description"
},
{
"name"
:
"TestAbility_label"
,
"value"
:
"label"
}
]
}
distributeddatamgr/preferencesjstest/hap/src/main/js/test/List.test.js
浏览文件 @
5b551af6
...
...
@@ -13,6 +13,9 @@
* limitations under the License.
*/
import
preferencesCallBackTest
from
'
./PreferencesCallBackJsunit.test.js
'
import
preferencesHelperTest
from
'
./PreferencesHelperJsunit.test.js
'
import
preferencesPromiseTest
from
'
./PreferencesPromiseJsunit.test.js
'
import
storageCallBackTest
from
'
./StorageCallBackJsunit.test.js
'
import
storageHelperTest
from
'
./StorageHelperJsunit.test.js
'
import
storagePromiseTest
from
'
./StoragePromiseJsunit.test.js
'
...
...
@@ -24,4 +27,7 @@ storageHelperTest()
storagePromiseTest
()
storageSyncTest
()
systemStorageTest
()
preferencesCallBackTest
()
preferencesHelperTest
()
preferencesPromiseTest
()
}
distributeddatamgr/preferencesjstest/hap/src/main/js/test/PreferencesCallBackJsunit.test.js
0 → 100644
浏览文件 @
5b551af6
/*
* 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
'
deccjsunit/index
'
import
dataPreferences
from
'
@ohos.data.preferences
'
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
const
NAME
=
'
test_preferences
'
;
const
KEY_TEST_INT_ELEMENT
=
'
key_test_int
'
;
const
KEY_TEST_LONG_ELEMENT
=
'
key_test_long
'
;
const
KEY_TEST_FLOAT_ELEMENT
=
'
key_test_float
'
;
const
KEY_TEST_BOOLEAN_ELEMENT
=
'
key_test_boolean
'
;
const
KEY_TEST_STRING_ELEMENT
=
'
key_test_string
'
;
const
KEY_TEST_NUMBER_ARRAY_ELEMENT
=
'
key_test_number_array
'
;
const
KEY_TEST_STRING_ARRAY_ELEMENT
=
'
key_test_string_array
'
;
const
KEY_TEST_BOOL_ARRAY_ELEMENT
=
'
key_test_bool_array
'
;
var
mPreferences
;
var
context
;
const
TAG
=
'
[PREFERENCES_CALLBACK_JSUNIT_TEST]
'
export
default
function
preferencesCallBackTest
(){
describe
(
'
preferencesCallBackTest
'
,
function
()
{
beforeAll
(
async
function
()
{
console
.
info
(
'
beforeAll
'
)
context
=
featureAbility
.
getContext
()
mPreferences
=
await
dataPreferences
.
getPreferences
(
context
,
NAME
);
})
afterAll
(
async
function
()
{
console
.
info
(
'
afterAll
'
)
await
dataPreferences
.
deletePreferences
(
context
,
NAME
);
})
/**
* @tc.name clear callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0010
* @tc.desc clear callback interface test
*/
it
(
'
testPreferencesClear0012
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
put
(
KEY_TEST_STRING_ELEMENT
,
"
test
"
);
await
mPreferences
.
flush
();
await
mPreferences
.
clear
(
async
function
(
err
,
ret
)
{
let
pre
=
await
mPreferences
.
get
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
)
expect
(
"
defaultvalue
"
).
assertEqual
(
pre
);
done
();
});
})
/**
* @tc.name has string callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0020
* @tc.desc has string callback interface test
*/
it
(
'
testPreferencesHasKey0032
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
put
(
KEY_TEST_STRING_ELEMENT
,
"
test
"
);
await
mPreferences
.
has
(
KEY_TEST_STRING_ELEMENT
,
function
(
err
,
ret
)
{
expect
(
true
).
assertEqual
(
ret
);
done
();
})
})
/**
* @tc.name has int callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0130
* @tc.desc has int callback interface test
*/
it
(
'
testPreferencesHasKey0033
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
put
(
KEY_TEST_INT_ELEMENT
,
1
);
await
mPreferences
.
has
(
KEY_TEST_INT_ELEMENT
,
function
(
err
,
ret
)
{
expect
(
true
).
assertEqual
(
ret
);
done
();
})
})
/**
* @tc.name has float callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0140
* @tc.desc has float callback interface test
*/
it
(
'
testPreferencesHasKey0034
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
put
(
KEY_TEST_FLOAT_ELEMENT
,
1.1
);
await
mPreferences
.
has
(
KEY_TEST_FLOAT_ELEMENT
,
function
(
err
,
ret
)
{
expect
(
true
).
assertEqual
(
ret
);
done
();
})
})
/**
* @tc.name has long callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0150
* @tc.desc has long callback interface test
*/
it
(
'
testPreferencesHasKey0035
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
put
(
KEY_TEST_LONG_ELEMENT
,
0
);
await
mPreferences
.
has
(
KEY_TEST_LONG_ELEMENT
,
function
(
err
,
ret
)
{
expect
(
true
).
assertEqual
(
ret
);
done
();
})
})
/**
* @tc.name has boolean callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0160
* @tc.desc has boolean callback interface test
*/
it
(
'
testPreferencesHasKey0036
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
put
(
KEY_TEST_BOOLEAN_ELEMENT
,
false
);
await
mPreferences
.
has
(
KEY_TEST_BOOLEAN_ELEMENT
,
function
(
err
,
ret
)
{
expect
(
true
).
assertEqual
(
ret
);
done
();
})
})
/**
* @tc.name get defaultValue callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0030
* @tc.desc get defaultValue callback interface test
*/
it
(
'
testPreferencesGetDefValue0062
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
await
mPreferences
.
get
(
KEY_TEST_STRING_ELEMENT
,
"
defaultValue
"
,
function
(
err
,
ret
)
{
expect
(
'
defaultValue
'
).
assertEqual
(
ret
);
done
();
})
})
/**
* @tc.name get float callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0040
* @tc.desc get float callback interface test
*/
it
(
'
testPreferencesGetFloat0072
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
await
mPreferences
.
put
(
KEY_TEST_FLOAT_ELEMENT
,
3.0
);
await
mPreferences
.
get
(
KEY_TEST_FLOAT_ELEMENT
,
0.0
,
function
(
err
,
ret
)
{
expect
(
3.0
).
assertEqual
(
ret
);
done
();
})
})
/**
* @tc.name get int callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0050
* @tc.desc get int callback interface test
*/
it
(
'
testPreferencesGetInt0082
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
await
mPreferences
.
put
(
KEY_TEST_INT_ELEMENT
,
3
);
await
mPreferences
.
get
(
KEY_TEST_INT_ELEMENT
,
0.0
,
function
(
err
,
ret
)
{
expect
(
3
).
assertEqual
(
ret
);
done
();
})
})
/**
* @tc.name get long callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0060
* @tc.desc get long callback interface test
*/
it
(
'
testPreferencesGetLong0092
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
await
mPreferences
.
put
(
KEY_TEST_LONG_ELEMENT
,
3
);
let
pref
=
await
mPreferences
.
get
(
KEY_TEST_LONG_ELEMENT
,
0
)
expect
(
3
).
assertEqual
(
pref
);
await
mPreferences
.
get
(
KEY_TEST_LONG_ELEMENT
,
0
,
function
(
err
,
ret
)
{
expect
(
3
).
assertEqual
(
ret
);
done
();
});
})
/**
* @tc.name get String callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0070
* @tc.desc get String callback interface test
*/
it
(
'
testPreferencesGetString102
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
await
mPreferences
.
put
(
KEY_TEST_STRING_ELEMENT
,
"
test
"
);
await
mPreferences
.
flush
();
await
mPreferences
.
get
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
,
function
(
err
,
ret
)
{
expect
(
'
test
'
).
assertEqual
(
ret
);
done
();
});
})
/**
* @tc.name put boolean callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0080
* @tc.desc put boolean callback interface test
*/
it
(
'
testPreferencesPutBoolean0122
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
await
mPreferences
.
put
(
KEY_TEST_BOOLEAN_ELEMENT
,
true
,
async
function
(
err
,
ret
)
{
let
pre
=
await
mPreferences
.
get
(
KEY_TEST_BOOLEAN_ELEMENT
,
false
);
expect
(
true
).
assertEqual
(
pre
);
await
mPreferences
.
flush
();
let
pre2
=
await
mPreferences
.
get
(
KEY_TEST_BOOLEAN_ELEMENT
,
false
)
expect
(
true
).
assertEqual
(
pre2
);
done
();
});
})
/**
* @tc.name put float callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0090
* @tc.desc put float callback interface test
*/
it
(
'
testPreferencesPutFloat0132
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
await
mPreferences
.
put
(
KEY_TEST_FLOAT_ELEMENT
,
4.0
,
async
function
(
err
,
ret
)
{
let
pre
=
await
mPreferences
.
get
(
KEY_TEST_FLOAT_ELEMENT
,
0.0
);
expect
(
4.0
).
assertEqual
(
pre
);
await
mPreferences
.
flush
();
let
pre2
=
await
mPreferences
.
get
(
KEY_TEST_FLOAT_ELEMENT
,
0.0
);
expect
(
4.0
).
assertEqual
(
pre2
);
done
();
});
})
/**
* @tc.name put int callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0100
* @tc.desc put int callback interface test
*/
it
(
'
testPreferencesPutInt0142
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
await
mPreferences
.
put
(
KEY_TEST_INT_ELEMENT
,
4
,
async
function
(
err
,
ret
)
{
let
pre
=
await
mPreferences
.
get
(
KEY_TEST_INT_ELEMENT
,
0
);
expect
(
4
).
assertEqual
(
pre
);
await
mPreferences
.
flush
();
let
pre2
=
await
mPreferences
.
get
(
KEY_TEST_INT_ELEMENT
,
0
);
expect
(
4
).
assertEqual
(
pre2
);
done
();
});
})
/**
* @tc.name put long callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0110
* @tc.desc put long callback interface test
*/
it
(
'
testPreferencesPutLong0152
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
await
mPreferences
.
put
(
KEY_TEST_LONG_ELEMENT
,
4
);
await
mPreferences
.
put
(
KEY_TEST_LONG_ELEMENT
,
4
,
async
function
(
err
,
ret
)
{
let
pre
=
await
mPreferences
.
get
(
KEY_TEST_LONG_ELEMENT
,
0
);
expect
(
4
).
assertEqual
(
pre
);
await
mPreferences
.
flush
();
let
pre2
=
await
mPreferences
.
get
(
KEY_TEST_LONG_ELEMENT
,
0
);
expect
(
4
).
assertEqual
(
pre2
);
done
();
});
})
/**
* @tc.name put String callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0120
* @tc.desc put String callback interface test
*/
it
(
'
testPreferencesPutString0162
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
await
mPreferences
.
put
(
KEY_TEST_STRING_ELEMENT
,
''
,
async
function
(
err
,
ret
)
{
let
pre
=
await
mPreferences
.
get
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
)
expect
(
''
).
assertEqual
(
pre
);
await
mPreferences
.
flush
();
let
pre2
=
await
mPreferences
.
get
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
)
expect
(
''
).
assertEqual
(
pre2
);
done
();
});
})
/**
* @tc.name clear、put、get、flush String callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0120
* @tc.desc flush String callback interface test
*/
it
(
'
testPreferencesCallback0172
'
,
0
,
function
(
done
)
{
console
.
log
(
TAG
+
"
testPreferencesCallback0172 begin.
"
);
mPreferences
.
clear
(
function
(
err
,
val
)
{
if
(
err
){
expect
(
null
).
assertEqual
();
}
mPreferences
.
put
(
KEY_TEST_STRING_ELEMENT
,
''
,
function
(
err
,
ret
)
{
if
(
err
){
expect
(
null
).
assertEqual
();
}
mPreferences
.
get
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
,
function
(
err
,
pre
)
{
if
(
err
){
expect
(
null
).
assertEqual
();
}
expect
(
''
).
assertEqual
(
pre
);
mPreferences
.
flush
(
function
(
err
,
val
)
{
if
(
err
){
expect
(
null
).
assertEqual
();
}
mPreferences
.
get
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
,
function
(
err
,
pre2
)
{
if
(
err
){
expect
(
null
).
assertEqual
();
}
expect
(
''
).
assertEqual
(
pre2
);
done
();
console
.
log
(
TAG
+
"
testPreferencesCallback0172 end.
"
);
})
});
})
});
});
})
/**
* @tc.name put StringArray callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0001
* @tc.desc put String callback interface test
*/
it
(
'
testPreferencesPutStringArray0001
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
var
stringArr
=
[
'
11
'
,
'
22
'
,
'
33
'
]
await
mPreferences
.
put
(
KEY_TEST_STRING_ARRAY_ELEMENT
,
stringArr
,
async
function
(
err
,
ret
)
{
let
pre
=
await
mPreferences
.
get
(
KEY_TEST_STRING_ARRAY_ELEMENT
,
[
'
123
'
,
'
321
'
])
for
(
let
i
=
0
;
i
<
stringArr
.
length
;
i
++
)
{
expect
(
stringArr
[
i
]).
assertEqual
(
pre
[
i
]);
}
done
();
});
})
/**
* @tc.name put NumberArray callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0002
* @tc.desc put String callback interface test
*/
it
(
'
testPreferencesPutNumArray0001
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
var
doubleArr
=
[
11
,
22
,
33
]
await
mPreferences
.
put
(
KEY_TEST_NUMBER_ARRAY_ELEMENT
,
doubleArr
,
async
function
(
err
,
ret
)
{
let
pre
=
await
mPreferences
.
get
(
KEY_TEST_NUMBER_ARRAY_ELEMENT
,
[
123
,
321
])
for
(
let
i
=
0
;
i
<
doubleArr
.
length
;
i
++
)
{
expect
(
doubleArr
[
i
]).
assertEqual
(
pre
[
i
]);
}
done
();
});
})
/**
* @tc.name put BoolArray callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0003
* @tc.desc put String callback interface test
*/
it
(
'
testPreferencesPutBoolArray0001
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
let
boolArr
=
[
true
,
false
,
false
,
true
]
await
mPreferences
.
put
(
KEY_TEST_BOOL_ARRAY_ELEMENT
,
boolArr
,
async
function
(
err
,
ret
)
{
let
pre
=
await
mPreferences
.
get
(
KEY_TEST_BOOL_ARRAY_ELEMENT
,
[
true
,
false
])
for
(
let
i
=
0
;
i
<
boolArr
.
length
;
i
++
)
{
expect
(
boolArr
[
i
]).
assertEqual
(
pre
[
i
]);
}
done
();
});
})
/**
* @tc.name getAll callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0004
* @tc.desc getAll callback interface test
*/
it
(
'
testPreferencesGetAll0001
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
let
doubleArr
=
[
11
,
22
,
33
]
let
stringArr
=
[
'
11
'
,
'
22
'
,
'
33
'
]
let
boolArr
=
[
true
,
false
,
false
,
true
]
await
mPreferences
.
put
(
KEY_TEST_STRING_ARRAY_ELEMENT
,
stringArr
)
await
mPreferences
.
put
(
KEY_TEST_BOOL_ARRAY_ELEMENT
,
boolArr
)
await
mPreferences
.
put
(
KEY_TEST_NUMBER_ARRAY_ELEMENT
,
doubleArr
)
await
mPreferences
.
put
(
KEY_TEST_BOOLEAN_ELEMENT
,
false
)
await
mPreferences
.
put
(
KEY_TEST_STRING_ELEMENT
,
"
123
"
)
await
mPreferences
.
put
(
KEY_TEST_FLOAT_ELEMENT
,
123.1
)
await
mPreferences
.
flush
()
await
mPreferences
.
getAll
(
function
(
err
,
obj
)
{
expect
(
false
).
assertEqual
(
obj
.
key_test_boolean
)
expect
(
"
123
"
).
assertEqual
(
obj
.
key_test_string
)
expect
(
123.1
).
assertEqual
(
obj
.
key_test_float
)
let
sArr
=
obj
.
key_test_string_array
for
(
let
i
=
0
;
i
<
sArr
.
length
;
i
++
)
{
expect
(
sArr
[
i
]).
assertEqual
(
stringArr
[
i
]);
}
let
bArr
=
obj
.
key_test_bool_array
for
(
let
i
=
0
;
i
<
bArr
.
length
;
i
++
)
{
expect
(
bArr
[
i
]).
assertEqual
(
boolArr
[
i
]);
}
let
nArr
=
obj
.
key_test_number_array
for
(
let
i
=
0
;
i
<
nArr
.
length
;
i
++
)
{
expect
(
nArr
[
i
]).
assertEqual
(
doubleArr
[
i
]);
}
done
()
})
})
})
}
\ No newline at end of file
distributeddatamgr/preferencesjstest/hap/src/main/js/test/PreferencesHelperJsunit.test.js
0 → 100644
浏览文件 @
5b551af6
// @ts-nocheck
/*
* 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
dataPreferences
from
'
@ohos.data.preferences
'
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
const
NAME
=
'
test_preferences
'
;
const
KEY_TEST_STRING_ELEMENT
=
'
key_test_string
'
;
var
mPreferences
;
var
context
;
export
default
function
preferencesHelperTest
(){
describe
(
'
preferencesHelperTest
'
,
function
()
{
beforeAll
(
async
function
()
{
console
.
info
(
'
beforeAll
'
)
context
=
featureAbility
.
getContext
()
mPreferences
=
await
dataPreferences
.
getPreferences
(
context
,
NAME
);
})
afterAll
(
async
function
()
{
console
.
info
(
'
afterAll
'
)
await
dataPreferences
.
deletePreferences
(
context
,
NAME
);
})
/**
* @tc.name getPreferencesSync interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0010
* @tc.desc getPreferencesSync interface test
*/
it
(
'
testGetPreferencesHelper001
'
,
0
,
async
function
()
{
mPreferences
=
await
dataPreferences
.
getPreferences
(
context
,
NAME
);
await
mPreferences
.
put
(
'
test
'
,
2
);
await
mPreferences
.
flush
();
var
value
=
await
mPreferences
.
get
(
'
test
'
,
0
);
expect
(
value
).
assertEqual
(
2
);
})
/**
* @tc.name getPreferences interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0020
* @tc.desc getPreferences interface test
*/
it
(
'
testGetPreferencesHelper002
'
,
0
,
async
function
(
done
)
{
const
promise
=
dataPreferences
.
getPreferences
(
context
,
NAME
);
promise
.
then
(
async
(
pref
)
=>
{
await
pref
.
put
(
'
test
'
,
2
);
await
pref
.
flush
();
var
value
=
await
mPreferences
.
get
(
'
test
'
,
0
);
expect
(
value
).
assertEqual
(
2
);
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
})
/**
* @tc.name removePreferencesFromCache interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0030
* @tc.desc removePreferencesFromCache interface test
*/
it
(
'
testRemovePreferencesFromCache001
'
,
0
,
async
function
(
done
)
{
let
perf
=
await
dataPreferences
.
getPreferences
(
context
,
NAME
);
perf
=
null
;
const
promise
=
dataPreferences
.
removePreferencesFromCache
(
context
,
NAME
);
promise
.
then
((
pref
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
})
/**
* @tc.name deletePreferences interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0060
* @tc.desc deletePreferences interface test
*/
it
(
'
testDeletePreferencesHelper002
'
,
0
,
async
function
(
done
)
{
let
perf
=
await
dataPreferences
.
getPreferences
(
context
,
NAME
);
perf
=
null
;
const
promise
=
dataPreferences
.
deletePreferences
(
context
,
NAME
);
promise
.
then
((
pref
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
})
/**
* @tc.name put interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_0140
* @tc.desc put interface test
*/
it
(
'
testPreferencesRegisterObserver001
'
,
0
,
async
function
()
{
await
mPreferences
.
clear
();
var
observer
=
function
(
key
)
{
console
.
info
(
'
testPreferencesRegisterObserver001 key
'
+
key
);
expect
(
'
abcd
'
).
assertEqual
(
key
);
};
await
mPreferences
.
on
(
'
change
'
,
observer
);
await
mPreferences
.
put
(
KEY_TEST_STRING_ELEMENT
,
"
abcd
"
);
})
/**
* @tc.name repeat on interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_0150
* @tc.desc repeat on interface test
*/
it
(
'
testPreferencesRegisterObserver002
'
,
0
,
async
function
()
{
await
mPreferences
.
clear
();
var
observer
=
function
(
key
)
{
console
.
info
(
'
testPreferencesRegisterObserver002 key
'
+
key
);
expect
(
'
abc
'
).
assertEqual
(
key
);
};
await
mPreferences
.
on
(
'
change
'
,
observer
);
await
mPreferences
.
on
(
'
change
'
,
observer
);
await
mPreferences
.
put
(
KEY_TEST_STRING_ELEMENT
,
"
abc
"
);
})
/**
* @tc.name off interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_0160
* @tc.desc off interface test
*/
it
(
'
testPreferencesUnRegisterObserver001
'
,
0
,
async
function
()
{
var
observer
=
function
(
key
)
{
console
.
info
(
'
testPreferencesUnRegisterObserver001 key
'
+
key
);
expect
(
''
).
assertEqual
(
key
);
};
await
mPreferences
.
on
(
'
change
'
,
observer
);
await
mPreferences
.
off
(
'
change
'
,
observer
);
await
mPreferences
.
put
(
KEY_TEST_STRING_ELEMENT
,
"
abc
"
);
})
})
}
\ No newline at end of file
distributeddatamgr/preferencesjstest/hap/src/main/js/test/PreferencesPromiseJsunit.test.js
0 → 100644
浏览文件 @
5b551af6
/*
* 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
'
deccjsunit/index
'
import
dataPreferences
from
'
@ohos.data.preferences
'
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
const
NAME
=
'
test_preferences
'
;
const
KEY_TEST_INT_ELEMENT
=
'
key_test_int
'
;
const
KEY_TEST_LONG_ELEMENT
=
'
key_test_long
'
;
const
KEY_TEST_FLOAT_ELEMENT
=
'
key_test_float
'
;
const
KEY_TEST_BOOLEAN_ELEMENT
=
'
key_test_boolean
'
;
const
KEY_TEST_STRING_ELEMENT
=
'
key_test_string
'
;
const
KEY_TEST_NUMBER_ARRAY_ELEMENT
=
'
key_test_number_array
'
const
KEY_TEST_STRING_ARRAY_ELEMENT
=
'
key_test_string_array
'
const
KEY_TEST_BOOL_ARRAY_ELEMENT
=
'
key_test_bool_array
'
var
mPreferences
;
var
context
;
export
default
function
preferencesPromiseTest
(){
describe
(
'
preferencesPromiseTest
'
,
function
()
{
beforeAll
(
async
function
()
{
console
.
info
(
'
beforeAll
'
)
context
=
featureAbility
.
getContext
()
mPreferences
=
await
dataPreferences
.
getPreferences
(
context
,
NAME
);
})
afterAll
(
async
function
()
{
console
.
info
(
'
afterAll
'
)
await
dataPreferences
.
deletePreferences
(
context
,
NAME
);
})
/**
* @tc.name put StringArray promise interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0131
* @tc.desc put StringArray promise interface test
*/
it
(
'
testPreferencesPutStringArray0131
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
var
stringArr
=
[
'
1
'
,
'
2
'
,
'
3
'
]
let
promise1
=
mPreferences
.
put
(
KEY_TEST_STRING_ARRAY_ELEMENT
,
stringArr
)
await
promise1
let
promise2
=
mPreferences
.
get
(
KEY_TEST_STRING_ARRAY_ELEMENT
,
[
'
123
'
,
'
321
'
])
promise2
.
then
((
pre
)
=>
{
for
(
let
i
=
0
;
i
<
stringArr
.
length
;
i
++
)
{
expect
(
stringArr
[
i
]).
assertEqual
(
pre
[
i
]);
}
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
})
await
promise2
done
();
});
/**
* @tc.name put NumberArray promise interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0132
* @tc.desc put NumberArray promise interface test
*/
it
(
'
testPreferencesPutNumberArray0132
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
var
numberArr
=
[
11
,
22
,
33
,
44
,
55
]
let
promise1
=
mPreferences
.
put
(
KEY_TEST_NUMBER_ARRAY_ELEMENT
,
numberArr
)
await
promise1
let
promise2
=
mPreferences
.
get
(
KEY_TEST_NUMBER_ARRAY_ELEMENT
,
[
123
,
321
])
promise2
.
then
((
pre
)
=>
{
for
(
let
i
=
0
;
i
<
numberArr
.
length
;
i
++
)
{
expect
(
numberArr
[
i
]).
assertEqual
(
pre
[
i
]);
}
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
})
await
promise2
done
();
});
/**
* @tc.name put BoolArray promise interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0133
* @tc.desc put BoolArray promise interface test
*/
it
(
'
testPreferencesPutBoolArray0133
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
var
boolArr
=
[
true
,
true
,
false
]
let
promise1
=
mPreferences
.
put
(
KEY_TEST_BOOL_ARRAY_ELEMENT
,
boolArr
)
await
promise1
let
promise2
=
mPreferences
.
get
(
KEY_TEST_BOOL_ARRAY_ELEMENT
,
[
false
,
true
])
promise2
.
then
((
pre
)
=>
{
for
(
let
i
=
0
;
i
<
boolArr
.
length
;
i
++
)
{
expect
(
boolArr
[
i
]).
assertEqual
(
pre
[
i
]);
}
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
})
await
promise2
done
();
});
/**
* @tc.name getAll promise interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0133
* @tc.desc getAll promise interface test
*/
it
(
'
testPreferencesGetAll0001
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
let
doubleArr
=
[
11
,
22
,
33
]
let
stringArr
=
[
'
11
'
,
'
22
'
,
'
33
'
]
let
boolArr
=
[
true
,
false
,
false
,
true
]
await
mPreferences
.
put
(
KEY_TEST_STRING_ARRAY_ELEMENT
,
stringArr
)
await
mPreferences
.
put
(
KEY_TEST_BOOL_ARRAY_ELEMENT
,
boolArr
)
await
mPreferences
.
put
(
KEY_TEST_NUMBER_ARRAY_ELEMENT
,
doubleArr
)
await
mPreferences
.
put
(
KEY_TEST_BOOLEAN_ELEMENT
,
false
)
await
mPreferences
.
put
(
KEY_TEST_STRING_ELEMENT
,
"
123
"
)
await
mPreferences
.
put
(
KEY_TEST_FLOAT_ELEMENT
,
123.1
)
await
mPreferences
.
flush
()
let
promise
=
mPreferences
.
getAll
()
promise
.
then
((
obj
)
=>
{
expect
(
false
).
assertEqual
(
obj
.
key_test_boolean
)
expect
(
"
123
"
).
assertEqual
(
obj
.
key_test_string
)
expect
(
123.1
).
assertEqual
(
obj
.
key_test_float
)
let
sArr
=
obj
.
key_test_string_array
for
(
let
i
=
0
;
i
<
sArr
.
length
;
i
++
)
{
expect
(
sArr
[
i
]).
assertEqual
(
stringArr
[
i
]);
}
let
bArr
=
obj
.
key_test_bool_array
for
(
let
i
=
0
;
i
<
bArr
.
length
;
i
++
)
{
expect
(
bArr
[
i
]).
assertEqual
(
boolArr
[
i
]);
}
let
nArr
=
obj
.
key_test_number_array
for
(
let
i
=
0
;
i
<
nArr
.
length
;
i
++
)
{
expect
(
nArr
[
i
]).
assertEqual
(
doubleArr
[
i
]);
}
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
})
await
promise
done
();
})
/**
* @tc.name clear promise interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Promise_0010
* @tc.desc clear promise interface test
*/
it
(
'
testPreferencesClear0011
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
put
(
KEY_TEST_STRING_ELEMENT
,
"
test
"
);
await
mPreferences
.
flush
();
const
promise
=
mPreferences
.
clear
();
promise
.
then
(
async
(
ret
)
=>
{
let
per
=
await
mPreferences
.
get
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
);
expect
(
"
defaultvalue
"
).
assertEqual
(
per
);
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
})
/**
* @tc.name has string interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0020
* @tc.desc has string interface test
*/
it
(
'
testPreferencesHasKey0031
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
put
(
KEY_TEST_STRING_ELEMENT
,
"
test
"
);
const
promise
=
mPreferences
.
has
(
KEY_TEST_STRING_ELEMENT
);
promise
.
then
((
ret
)
=>
{
expect
(
true
).
assertEqual
(
ret
);
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
})
/**
* @tc.name has int interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0140
* @tc.desc has int interface test
*/
it
(
'
testPreferencesHasKey0032
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
put
(
KEY_TEST_INT_ELEMENT
,
1
);
const
promise
=
mPreferences
.
has
(
KEY_TEST_INT_ELEMENT
);
promise
.
then
((
ret
)
=>
{
expect
(
true
).
assertEqual
(
ret
);
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
})
/**
* @tc.name has float interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0150
* @tc.desc has float interface test
*/
it
(
'
testPreferencesHasKey0033
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
put
(
KEY_TEST_FLOAT_ELEMENT
,
2.0
);
const
promise
=
mPreferences
.
has
(
KEY_TEST_FLOAT_ELEMENT
);
promise
.
then
((
ret
)
=>
{
expect
(
true
).
assertEqual
(
ret
);
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
})
/**
* @tc.name has boolean interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0160
* @tc.desc has boolean interface test
*/
it
(
'
testPreferencesHasKey0034
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
put
(
KEY_TEST_BOOLEAN_ELEMENT
,
false
);
const
promise
=
mPreferences
.
has
(
KEY_TEST_BOOLEAN_ELEMENT
);
promise
.
then
((
ret
)
=>
{
expect
(
true
).
assertEqual
(
ret
);
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
})
/**
* @tc.name has long interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0170
* @tc.desc has long interface test
*/
it
(
'
testPreferencesHasKey0035
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
put
(
KEY_TEST_LONG_ELEMENT
,
0
);
const
promise
=
mPreferences
.
has
(
KEY_TEST_LONG_ELEMENT
);
promise
.
then
((
ret
)
=>
{
expect
(
true
).
assertEqual
(
ret
);
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
})
/**
* @tc.name get string promise interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0030
* @tc.desc get string promise interface test
*/
it
(
'
testPreferencesGetDefValue0061
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
const
promise
=
mPreferences
.
get
(
KEY_TEST_STRING_ELEMENT
,
"
defaultValue
"
);
promise
.
then
((
ret
)
=>
{
expect
(
'
defaultValue
'
).
assertEqual
(
ret
);
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
})
/**
* @tc.name get float promise interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0040
* @tc.desc get float promise interface test
*/
it
(
'
testPreferencesGetFloat0071
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
await
mPreferences
.
put
(
KEY_TEST_FLOAT_ELEMENT
,
3.0
);
const
promise
=
mPreferences
.
get
(
KEY_TEST_FLOAT_ELEMENT
,
0.0
);
promise
.
then
((
ret
)
=>
{
expect
(
3.0
).
assertEqual
(
ret
);
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
})
/**
* @tc.name get int promise interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0050
* @tc.desc get int promise interface test
*/
it
(
'
testPreferencesGetInt0081
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
await
mPreferences
.
put
(
KEY_TEST_INT_ELEMENT
,
3
);
const
promise
=
mPreferences
.
get
(
KEY_TEST_INT_ELEMENT
,
0.0
);
promise
.
then
((
ret
)
=>
{
expect
(
3
).
assertEqual
(
ret
);
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
})
/**
* @tc.name get long promise interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0060
* @tc.desc get long promise interface test
*/
it
(
'
testPreferencesGetLong0091
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
await
mPreferences
.
put
(
KEY_TEST_LONG_ELEMENT
,
3
);
const
promise
=
mPreferences
.
get
(
KEY_TEST_LONG_ELEMENT
,
0
);
promise
.
then
((
ret
)
=>
{
expect
(
3
).
assertEqual
(
ret
);
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
})
/**
* @tc.name get String promise interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0070
* @tc.desc get String promise interface test
*/
it
(
'
tesPreferencesGetString101
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
await
mPreferences
.
put
(
KEY_TEST_STRING_ELEMENT
,
"
test
"
);
await
mPreferences
.
flush
();
const
promise
=
mPreferences
.
get
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
);
promise
.
then
((
ret
)
=>
{
expect
(
'
test
'
).
assertEqual
(
ret
);
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
})
/**
* @tc.name put boolean promise interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0090
* @tc.desc put boolean promise interface test
*/
it
(
'
testPreferencesPutBoolean0121
'
,
0
,
async
function
(
done
)
{
const
promise
=
mPreferences
.
put
(
KEY_TEST_BOOLEAN_ELEMENT
,
true
);
promise
.
then
(
async
(
ret
)
=>
{
let
per
=
await
mPreferences
.
get
(
KEY_TEST_BOOLEAN_ELEMENT
,
false
);
expect
(
true
).
assertEqual
(
per
);
await
mPreferences
.
flush
();
let
per2
=
await
mPreferences
.
get
(
KEY_TEST_BOOLEAN_ELEMENT
,
false
);
expect
(
true
).
assertEqual
(
per2
);
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
})
/**
* @tc.name put float promise interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0100
* @tc.desc put float promise interface test
*/
it
(
'
testPreferencesPutFloat0131
'
,
0
,
async
function
(
done
)
{
const
promise
=
mPreferences
.
put
(
KEY_TEST_FLOAT_ELEMENT
,
4.0
);
promise
.
then
(
async
(
ret
)
=>
{
let
per
=
await
mPreferences
.
get
(
KEY_TEST_FLOAT_ELEMENT
,
0.0
);
expect
(
4.0
).
assertEqual
(
per
);
await
mPreferences
.
flush
();
let
per2
=
await
mPreferences
.
get
(
KEY_TEST_FLOAT_ELEMENT
,
0.0
);
expect
(
4.0
).
assertEqual
(
per2
);
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
})
/**
* @tc.name put int promise interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0110
* @tc.desc put int promise interface test
*/
it
(
'
testPreferencesPutInt0141
'
,
0
,
async
function
(
done
)
{
const
promise
=
mPreferences
.
put
(
KEY_TEST_INT_ELEMENT
,
4
);
promise
.
then
(
async
(
ret
)
=>
{
let
per
=
await
mPreferences
.
get
(
KEY_TEST_INT_ELEMENT
,
0
);
expect
(
4
).
assertEqual
(
per
);
await
mPreferences
.
flush
();
let
per2
=
await
mPreferences
.
get
(
KEY_TEST_INT_ELEMENT
,
0
);
expect
(
4
).
assertEqual
(
per2
);
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
})
/**
* @tc.name put long promise interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0120
* @tc.desc put long promise interface test
*/
it
(
'
testPreferencesPutLong0151
'
,
0
,
async
function
(
done
)
{
const
promise
=
mPreferences
.
put
(
KEY_TEST_LONG_ELEMENT
,
4
);
promise
.
then
(
async
(
ret
)
=>
{
let
per
=
await
mPreferences
.
get
(
KEY_TEST_LONG_ELEMENT
,
0
);
expect
(
4
).
assertEqual
(
per
);
await
mPreferences
.
flush
();
let
per2
=
await
mPreferences
.
get
(
KEY_TEST_LONG_ELEMENT
,
0
);
expect
(
4
).
assertEqual
(
per2
);
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
})
/**
* @tc.name put String promise interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0130
* @tc.desc put String promise interface test
*/
it
(
'
testPreferencesPutString0161
'
,
0
,
async
function
(
done
)
{
const
promise
=
mPreferences
.
put
(
KEY_TEST_STRING_ELEMENT
,
''
);
promise
.
then
(
async
(
ret
)
=>
{
let
per
=
await
mPreferences
.
get
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
)
expect
(
''
).
assertEqual
(
per
);
await
mPreferences
.
flush
();
let
per2
=
await
mPreferences
.
get
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
)
expect
(
''
).
assertEqual
(
per2
);
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
})
})
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录