Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
9d9711bc
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看板
未验证
提交
9d9711bc
编写于
8月 25, 2023
作者:
O
openharmony_ci
提交者:
Gitee
8月 25, 2023
浏览文件
操作
浏览文件
下载
差异文件
!9847 【Distributeddatamgr】【Master】preferences用例优化
Merge pull request !9847 from yanglifeng/master
上级
0c3b4e25
48180139
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
475 addition
and
535 deletion
+475
-535
distributeddatamgr/preferencesjstest/hap/src/main/js/test/PreferencesPromiseJsunit.test.js
...est/hap/src/main/js/test/PreferencesPromiseJsunit.test.js
+59
-86
distributeddatamgr/preferencesjstest/hap/src/main/js/test/StoragePromiseJsunit.test.js
...sjstest/hap/src/main/js/test/StoragePromiseJsunit.test.js
+416
-449
未找到文件。
distributeddatamgr/preferencesjstest/hap/src/main/js/test/PreferencesPromiseJsunit.test.js
浏览文件 @
9d9711bc
...
@@ -25,8 +25,8 @@ const KEY_TEST_STRING_ELEMENT = 'key_test_string';
...
@@ -25,8 +25,8 @@ const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const
KEY_TEST_NUMBER_ARRAY_ELEMENT
=
'
key_test_number_array
'
;
const
KEY_TEST_NUMBER_ARRAY_ELEMENT
=
'
key_test_number_array
'
;
const
KEY_TEST_STRING_ARRAY_ELEMENT
=
'
key_test_string_array
'
;
const
KEY_TEST_STRING_ARRAY_ELEMENT
=
'
key_test_string_array
'
;
const
KEY_TEST_BOOL_ARRAY_ELEMENT
=
'
key_test_bool_array
'
;
const
KEY_TEST_BOOL_ARRAY_ELEMENT
=
'
key_test_bool_array
'
;
var
mPreferences
;
let
mPreferences
;
var
context
;
let
context
;
export
default
function
preferencesPromiseTest
(){
export
default
function
preferencesPromiseTest
(){
describe
(
'
preferencesPromiseTest
'
,
function
()
{
describe
(
'
preferencesPromiseTest
'
,
function
()
{
...
@@ -49,20 +49,16 @@ export default function preferencesPromiseTest(){
...
@@ -49,20 +49,16 @@ export default function preferencesPromiseTest(){
it
(
'
testPreferencesPutStringArray0131
'
,
0
,
async
function
(
done
)
{
it
(
'
testPreferencesPutStringArray0131
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
await
mPreferences
.
clear
();
var
stringArr
=
[
'
1
'
,
'
2
'
,
'
3
'
];
var
stringArr
=
[
'
1
'
,
'
2
'
,
'
3
'
];
let
promise1
=
mPreferences
.
put
(
KEY_TEST_STRING_ARRAY_ELEMENT
,
stringArr
);
await
mPreferences
.
put
(
KEY_TEST_STRING_ARRAY_ELEMENT
,
stringArr
);
await
promise1
;
await
mPreferences
.
get
(
KEY_TEST_STRING_ARRAY_ELEMENT
,
[
'
123
'
,
'
321
'
]).
then
((
pre
)
=>
{
let
promise2
=
mPreferences
.
get
(
KEY_TEST_STRING_ARRAY_ELEMENT
,
[
'
123
'
,
'
321
'
]);
promise2
.
then
((
pre
)
=>
{
for
(
let
i
=
0
;
i
<
stringArr
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
stringArr
.
length
;
i
++
)
{
expect
(
stringArr
[
i
]).
assertEqual
(
pre
[
i
]);
expect
(
stringArr
[
i
]).
assertEqual
(
pre
[
i
]);
}
}
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
})
await
promise2
;
done
();
done
();
})
});
});
/**
/**
...
@@ -73,19 +69,16 @@ export default function preferencesPromiseTest(){
...
@@ -73,19 +69,16 @@ export default function preferencesPromiseTest(){
it
(
'
testPreferencesPutNumberArray0132
'
,
0
,
async
function
(
done
)
{
it
(
'
testPreferencesPutNumberArray0132
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
await
mPreferences
.
clear
();
var
numberArr
=
[
11
,
22
,
33
,
44
,
55
];
var
numberArr
=
[
11
,
22
,
33
,
44
,
55
];
let
promise1
=
mPreferences
.
put
(
KEY_TEST_NUMBER_ARRAY_ELEMENT
,
numberArr
);
await
mPreferences
.
put
(
KEY_TEST_NUMBER_ARRAY_ELEMENT
,
numberArr
);
await
promise1
;
await
mPreferences
.
get
(
KEY_TEST_NUMBER_ARRAY_ELEMENT
,
[
123
,
321
]).
then
((
pre
)
=>
{
let
promise2
=
mPreferences
.
get
(
KEY_TEST_NUMBER_ARRAY_ELEMENT
,
[
123
,
321
]);
promise2
.
then
((
pre
)
=>
{
for
(
let
i
=
0
;
i
<
numberArr
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
numberArr
.
length
;
i
++
)
{
expect
(
numberArr
[
i
]).
assertEqual
(
pre
[
i
]);
expect
(
numberArr
[
i
]).
assertEqual
(
pre
[
i
]);
}
}
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
})
await
promise2
;
done
();
done
();
})
});
});
/**
/**
...
@@ -96,19 +89,16 @@ export default function preferencesPromiseTest(){
...
@@ -96,19 +89,16 @@ export default function preferencesPromiseTest(){
it
(
'
testPreferencesPutBoolArray0133
'
,
0
,
async
function
(
done
)
{
it
(
'
testPreferencesPutBoolArray0133
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
await
mPreferences
.
clear
();
var
boolArr
=
[
true
,
true
,
false
];
var
boolArr
=
[
true
,
true
,
false
];
let
promise1
=
mPreferences
.
put
(
KEY_TEST_BOOL_ARRAY_ELEMENT
,
boolArr
);
await
mPreferences
.
put
(
KEY_TEST_BOOL_ARRAY_ELEMENT
,
boolArr
);
await
promise1
;
await
mPreferences
.
get
(
KEY_TEST_BOOL_ARRAY_ELEMENT
,
[
false
,
true
]).
then
((
pre
)
=>
{
let
promise2
=
mPreferences
.
get
(
KEY_TEST_BOOL_ARRAY_ELEMENT
,
[
false
,
true
]);
promise2
.
then
((
pre
)
=>
{
for
(
let
i
=
0
;
i
<
boolArr
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
boolArr
.
length
;
i
++
)
{
expect
(
boolArr
[
i
]).
assertEqual
(
pre
[
i
]);
expect
(
boolArr
[
i
]).
assertEqual
(
pre
[
i
]);
}
}
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
})
await
promise2
;
done
();
done
();
})
});
});
/**
/**
...
@@ -130,8 +120,7 @@ export default function preferencesPromiseTest(){
...
@@ -130,8 +120,7 @@ export default function preferencesPromiseTest(){
await
mPreferences
.
flush
();
await
mPreferences
.
flush
();
let
promise
=
mPreferences
.
getAll
();
await
mPreferences
.
getAll
().
then
((
obj
)
=>
{
promise
.
then
((
obj
)
=>
{
expect
(
false
).
assertEqual
(
obj
.
key_test_boolean
);
expect
(
false
).
assertEqual
(
obj
.
key_test_boolean
);
expect
(
"
123
"
).
assertEqual
(
obj
.
key_test_string
);
expect
(
"
123
"
).
assertEqual
(
obj
.
key_test_string
);
expect
(
123.1
).
assertEqual
(
obj
.
key_test_float
);
expect
(
123.1
).
assertEqual
(
obj
.
key_test_float
);
...
@@ -149,13 +138,12 @@ export default function preferencesPromiseTest(){
...
@@ -149,13 +138,12 @@ export default function preferencesPromiseTest(){
for
(
let
i
=
0
;
i
<
nArr
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
nArr
.
length
;
i
++
)
{
expect
(
nArr
[
i
]).
assertEqual
(
doubleArr
[
i
]);
expect
(
nArr
[
i
]).
assertEqual
(
doubleArr
[
i
]);
}
}
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
})
await
promise
;
done
();
done
();
})
})
})
/**
/**
* @tc.name clear promise interface test
* @tc.name clear promise interface test
...
@@ -165,15 +153,14 @@ export default function preferencesPromiseTest(){
...
@@ -165,15 +153,14 @@ export default function preferencesPromiseTest(){
it
(
'
testPreferencesClear0011
'
,
0
,
async
function
(
done
)
{
it
(
'
testPreferencesClear0011
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
put
(
KEY_TEST_STRING_ELEMENT
,
"
test
"
);
await
mPreferences
.
put
(
KEY_TEST_STRING_ELEMENT
,
"
test
"
);
await
mPreferences
.
flush
();
await
mPreferences
.
flush
();
const
promise
=
mPreferences
.
clear
();
await
mPreferences
.
clear
().
then
(
async
(
ret
)
=>
{
promise
.
then
(
async
(
ret
)
=>
{
let
per
=
await
mPreferences
.
get
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
);
let
per
=
await
mPreferences
.
get
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
);
expect
(
"
defaultvalue
"
).
assertEqual
(
per
);
expect
(
"
defaultvalue
"
).
assertEqual
(
per
);
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -183,14 +170,13 @@ export default function preferencesPromiseTest(){
...
@@ -183,14 +170,13 @@ export default function preferencesPromiseTest(){
*/
*/
it
(
'
testPreferencesHasKey0031
'
,
0
,
async
function
(
done
)
{
it
(
'
testPreferencesHasKey0031
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
put
(
KEY_TEST_STRING_ELEMENT
,
"
test
"
);
await
mPreferences
.
put
(
KEY_TEST_STRING_ELEMENT
,
"
test
"
);
const
promise
=
mPreferences
.
has
(
KEY_TEST_STRING_ELEMENT
);
await
mPreferences
.
has
(
KEY_TEST_STRING_ELEMENT
).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
true
).
assertEqual
(
ret
);
expect
(
true
).
assertEqual
(
ret
);
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -200,13 +186,13 @@ export default function preferencesPromiseTest(){
...
@@ -200,13 +186,13 @@ export default function preferencesPromiseTest(){
*/
*/
it
(
'
testPreferencesHasKey0032
'
,
0
,
async
function
(
done
)
{
it
(
'
testPreferencesHasKey0032
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
put
(
KEY_TEST_INT_ELEMENT
,
1
);
await
mPreferences
.
put
(
KEY_TEST_INT_ELEMENT
,
1
);
const
promise
=
mPreferences
.
has
(
KEY_TEST_INT_ELEMENT
);
await
mPreferences
.
has
(
KEY_TEST_INT_ELEMENT
).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
true
).
assertEqual
(
ret
);
expect
(
true
).
assertEqual
(
ret
);
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
done
();
});
});
await
promise
;
done
();
done
();
})
})
...
@@ -217,14 +203,13 @@ export default function preferencesPromiseTest(){
...
@@ -217,14 +203,13 @@ export default function preferencesPromiseTest(){
*/
*/
it
(
'
testPreferencesHasKey0033
'
,
0
,
async
function
(
done
)
{
it
(
'
testPreferencesHasKey0033
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
put
(
KEY_TEST_FLOAT_ELEMENT
,
2.0
);
await
mPreferences
.
put
(
KEY_TEST_FLOAT_ELEMENT
,
2.0
);
const
promise
=
mPreferences
.
has
(
KEY_TEST_FLOAT_ELEMENT
);
await
mPreferences
.
has
(
KEY_TEST_FLOAT_ELEMENT
).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
true
).
assertEqual
(
ret
);
expect
(
true
).
assertEqual
(
ret
);
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -234,14 +219,13 @@ export default function preferencesPromiseTest(){
...
@@ -234,14 +219,13 @@ export default function preferencesPromiseTest(){
*/
*/
it
(
'
testPreferencesHasKey0034
'
,
0
,
async
function
(
done
)
{
it
(
'
testPreferencesHasKey0034
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
put
(
KEY_TEST_BOOLEAN_ELEMENT
,
false
);
await
mPreferences
.
put
(
KEY_TEST_BOOLEAN_ELEMENT
,
false
);
const
promise
=
mPreferences
.
has
(
KEY_TEST_BOOLEAN_ELEMENT
);
await
mPreferences
.
has
(
KEY_TEST_BOOLEAN_ELEMENT
).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
true
).
assertEqual
(
ret
);
expect
(
true
).
assertEqual
(
ret
);
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -251,14 +235,14 @@ export default function preferencesPromiseTest(){
...
@@ -251,14 +235,14 @@ export default function preferencesPromiseTest(){
*/
*/
it
(
'
testPreferencesHasKey0035
'
,
0
,
async
function
(
done
)
{
it
(
'
testPreferencesHasKey0035
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
put
(
KEY_TEST_LONG_ELEMENT
,
0
);
await
mPreferences
.
put
(
KEY_TEST_LONG_ELEMENT
,
0
);
const
promise
=
mPreferences
.
has
(
KEY_TEST_LONG_ELEMENT
);
await
mPreferences
.
has
(
KEY_TEST_LONG_ELEMENT
).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
true
).
assertEqual
(
ret
);
expect
(
true
).
assertEqual
(
ret
);
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -268,14 +252,13 @@ export default function preferencesPromiseTest(){
...
@@ -268,14 +252,13 @@ export default function preferencesPromiseTest(){
*/
*/
it
(
'
testPreferencesGetDefValue0061
'
,
0
,
async
function
(
done
)
{
it
(
'
testPreferencesGetDefValue0061
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
await
mPreferences
.
clear
();
const
promise
=
mPreferences
.
get
(
KEY_TEST_STRING_ELEMENT
,
"
defaultValue
"
);
await
mPreferences
.
get
(
KEY_TEST_STRING_ELEMENT
,
"
defaultValue
"
).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
'
defaultValue
'
).
assertEqual
(
ret
);
expect
(
'
defaultValue
'
).
assertEqual
(
ret
);
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -286,14 +269,13 @@ export default function preferencesPromiseTest(){
...
@@ -286,14 +269,13 @@ export default function preferencesPromiseTest(){
it
(
'
testPreferencesGetFloat0071
'
,
0
,
async
function
(
done
)
{
it
(
'
testPreferencesGetFloat0071
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
await
mPreferences
.
clear
();
await
mPreferences
.
put
(
KEY_TEST_FLOAT_ELEMENT
,
3.0
);
await
mPreferences
.
put
(
KEY_TEST_FLOAT_ELEMENT
,
3.0
);
const
promise
=
mPreferences
.
get
(
KEY_TEST_FLOAT_ELEMENT
,
0.0
);
await
mPreferences
.
get
(
KEY_TEST_FLOAT_ELEMENT
,
0.0
).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
3.0
).
assertEqual
(
ret
);
expect
(
3.0
).
assertEqual
(
ret
);
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -304,14 +286,13 @@ export default function preferencesPromiseTest(){
...
@@ -304,14 +286,13 @@ export default function preferencesPromiseTest(){
it
(
'
testPreferencesGetInt0081
'
,
0
,
async
function
(
done
)
{
it
(
'
testPreferencesGetInt0081
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
await
mPreferences
.
clear
();
await
mPreferences
.
put
(
KEY_TEST_INT_ELEMENT
,
3
);
await
mPreferences
.
put
(
KEY_TEST_INT_ELEMENT
,
3
);
const
promise
=
mPreferences
.
get
(
KEY_TEST_INT_ELEMENT
,
0.0
);
await
mPreferences
.
get
(
KEY_TEST_INT_ELEMENT
,
0.0
).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
3
).
assertEqual
(
ret
);
expect
(
3
).
assertEqual
(
ret
);
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -322,14 +303,13 @@ export default function preferencesPromiseTest(){
...
@@ -322,14 +303,13 @@ export default function preferencesPromiseTest(){
it
(
'
testPreferencesGetLong0091
'
,
0
,
async
function
(
done
)
{
it
(
'
testPreferencesGetLong0091
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
await
mPreferences
.
clear
();
await
mPreferences
.
put
(
KEY_TEST_LONG_ELEMENT
,
3
);
await
mPreferences
.
put
(
KEY_TEST_LONG_ELEMENT
,
3
);
const
promise
=
mPreferences
.
get
(
KEY_TEST_LONG_ELEMENT
,
0
);
await
mPreferences
.
get
(
KEY_TEST_LONG_ELEMENT
,
0
).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
3
).
assertEqual
(
ret
);
expect
(
3
).
assertEqual
(
ret
);
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -341,14 +321,13 @@ export default function preferencesPromiseTest(){
...
@@ -341,14 +321,13 @@ export default function preferencesPromiseTest(){
await
mPreferences
.
clear
();
await
mPreferences
.
clear
();
await
mPreferences
.
put
(
KEY_TEST_STRING_ELEMENT
,
"
test
"
);
await
mPreferences
.
put
(
KEY_TEST_STRING_ELEMENT
,
"
test
"
);
await
mPreferences
.
flush
();
await
mPreferences
.
flush
();
const
promise
=
mPreferences
.
get
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
);
await
mPreferences
.
get
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
'
test
'
).
assertEqual
(
ret
);
expect
(
'
test
'
).
assertEqual
(
ret
);
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -358,8 +337,7 @@ export default function preferencesPromiseTest(){
...
@@ -358,8 +337,7 @@ export default function preferencesPromiseTest(){
*/
*/
it
(
'
testPreferencesPutBoolean0121
'
,
0
,
async
function
(
done
)
{
it
(
'
testPreferencesPutBoolean0121
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
await
mPreferences
.
clear
();
let
promise
=
mPreferences
.
put
(
KEY_TEST_BOOLEAN_ELEMENT
,
true
);
await
mPreferences
.
put
(
KEY_TEST_BOOLEAN_ELEMENT
,
true
);
await
promise
;
let
per
=
await
mPreferences
.
get
(
KEY_TEST_BOOLEAN_ELEMENT
,
false
);
let
per
=
await
mPreferences
.
get
(
KEY_TEST_BOOLEAN_ELEMENT
,
false
);
expect
(
true
).
assertEqual
(
per
);
expect
(
true
).
assertEqual
(
per
);
await
mPreferences
.
flush
();
await
mPreferences
.
flush
();
...
@@ -375,8 +353,7 @@ export default function preferencesPromiseTest(){
...
@@ -375,8 +353,7 @@ export default function preferencesPromiseTest(){
*/
*/
it
(
'
testPreferencesPutFloat0131
'
,
0
,
async
function
(
done
)
{
it
(
'
testPreferencesPutFloat0131
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
await
mPreferences
.
clear
();
const
promise
=
mPreferences
.
put
(
KEY_TEST_FLOAT_ELEMENT
,
4.0
);
await
mPreferences
.
put
(
KEY_TEST_FLOAT_ELEMENT
,
4.0
);
await
promise
;
let
per
=
await
mPreferences
.
get
(
KEY_TEST_FLOAT_ELEMENT
,
0.0
);
let
per
=
await
mPreferences
.
get
(
KEY_TEST_FLOAT_ELEMENT
,
0.0
);
expect
(
4.0
).
assertEqual
(
per
);
expect
(
4.0
).
assertEqual
(
per
);
await
mPreferences
.
flush
();
await
mPreferences
.
flush
();
...
@@ -392,8 +369,7 @@ export default function preferencesPromiseTest(){
...
@@ -392,8 +369,7 @@ export default function preferencesPromiseTest(){
*/
*/
it
(
'
testPreferencesPutInt0141
'
,
0
,
async
function
(
done
)
{
it
(
'
testPreferencesPutInt0141
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
await
mPreferences
.
clear
();
let
promise
=
mPreferences
.
put
(
KEY_TEST_INT_ELEMENT
,
4
);
await
mPreferences
.
put
(
KEY_TEST_INT_ELEMENT
,
4
);
await
promise
;
let
per
=
await
mPreferences
.
get
(
KEY_TEST_INT_ELEMENT
,
0
);
let
per
=
await
mPreferences
.
get
(
KEY_TEST_INT_ELEMENT
,
0
);
expect
(
4
).
assertEqual
(
per
);
expect
(
4
).
assertEqual
(
per
);
await
mPreferences
.
flush
();
await
mPreferences
.
flush
();
...
@@ -408,8 +384,7 @@ export default function preferencesPromiseTest(){
...
@@ -408,8 +384,7 @@ export default function preferencesPromiseTest(){
* @tc.desc put long promise interface test
* @tc.desc put long promise interface test
*/
*/
it
(
'
testPreferencesPutLong0151
'
,
0
,
async
function
(
done
)
{
it
(
'
testPreferencesPutLong0151
'
,
0
,
async
function
(
done
)
{
let
promise
=
mPreferences
.
put
(
KEY_TEST_LONG_ELEMENT
,
4
);
await
mPreferences
.
put
(
KEY_TEST_LONG_ELEMENT
,
4
);
await
promise
;
let
per
=
await
mPreferences
.
get
(
KEY_TEST_LONG_ELEMENT
,
0
);
let
per
=
await
mPreferences
.
get
(
KEY_TEST_LONG_ELEMENT
,
0
);
expect
(
4
).
assertEqual
(
per
);
expect
(
4
).
assertEqual
(
per
);
await
mPreferences
.
flush
();
await
mPreferences
.
flush
();
...
@@ -424,8 +399,7 @@ export default function preferencesPromiseTest(){
...
@@ -424,8 +399,7 @@ export default function preferencesPromiseTest(){
* @tc.desc put String promise interface test
* @tc.desc put String promise interface test
*/
*/
it
(
'
testPreferencesPutString0161
'
,
0
,
async
function
(
done
)
{
it
(
'
testPreferencesPutString0161
'
,
0
,
async
function
(
done
)
{
let
promise
=
mPreferences
.
put
(
KEY_TEST_STRING_ELEMENT
,
''
);
await
mPreferences
.
put
(
KEY_TEST_STRING_ELEMENT
,
''
);
await
promise
;
let
per
=
await
mPreferences
.
get
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
)
let
per
=
await
mPreferences
.
get
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
)
expect
(
''
).
assertEqual
(
per
);
expect
(
''
).
assertEqual
(
per
);
await
mPreferences
.
flush
();
await
mPreferences
.
flush
();
...
@@ -441,14 +415,13 @@ export default function preferencesPromiseTest(){
...
@@ -441,14 +415,13 @@ export default function preferencesPromiseTest(){
*/
*/
it
(
'
testPreferencesGetDefValue00162
'
,
0
,
async
function
(
done
)
{
it
(
'
testPreferencesGetDefValue00162
'
,
0
,
async
function
(
done
)
{
await
mPreferences
.
clear
();
await
mPreferences
.
clear
();
let
promise
=
mPreferences
.
get
(
KEY_TEST_BOOLEAN_ELEMENT
,
true
);
await
mPreferences
.
get
(
KEY_TEST_BOOLEAN_ELEMENT
,
true
).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
true
).
assertEqual
(
ret
);
expect
(
true
).
assertEqual
(
ret
);
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
})
})
}
}
\ No newline at end of file
distributeddatamgr/preferencesjstest/hap/src/main/js/test/StoragePromiseJsunit.test.js
浏览文件 @
9d9711bc
...
@@ -23,28 +23,22 @@ const KEY_TEST_BOOLEAN_ELEMENT = 'key_test_boolean';
...
@@ -23,28 +23,22 @@ const KEY_TEST_BOOLEAN_ELEMENT = 'key_test_boolean';
const
KEY_TEST_STRING_ELEMENT
=
'
key_test_string
'
;
const
KEY_TEST_STRING_ELEMENT
=
'
key_test_string
'
;
const
MAX_KEY_LENGTH
=
'
X
'
.
repeat
(
80
)
const
MAX_KEY_LENGTH
=
'
X
'
.
repeat
(
80
)
const
MAX_VALUE_LENGTH
=
'
y
'
.
repeat
(
8192
)
const
MAX_VALUE_LENGTH
=
'
y
'
.
repeat
(
8192
)
var
mPref
;
let
mPref
;
export
default
function
storagePromiseTest
()
{
export
default
function
storagePromiseTest
()
{
describe
(
'
storagePromiseTest
'
,
function
()
{
describe
(
'
storagePromiseTest
'
,
function
()
{
beforeAll
(
async
function
()
{
beforeAll
(
async
function
()
{
console
.
info
(
'
beforeAll
'
)
console
.
info
(
'
beforeAll
'
)
const
promise
=
storage
.
getStorage
(
PATH
);
await
storage
.
getStorage
(
PATH
).
then
((
Storage
)
=>
{
promise
.
then
((
Storage
)
=>
{
mPref
=
Storage
;
mPref
=
Storage
;
});
});
await
promise
;
done
();
})
})
afterAll
(
async
function
(
done
)
{
afterAll
(
async
function
(
)
{
console
.
info
(
'
afterAll
'
)
console
.
info
(
'
afterAll
'
)
const
promise
=
storage
.
deleteStorage
(
PATH
);
await
storage
.
deleteStorage
(
PATH
).
then
(()
=>
{
promise
.
then
(()
=>
{
console
.
info
(
'
Delete Storage finish
'
);
console
.
info
(
'
Delete Storage finish
'
);
});
});
await
promise
;
done
();
})
})
/**
/**
...
@@ -53,16 +47,15 @@ describe('storagePromiseTest', function () {
...
@@ -53,16 +47,15 @@ describe('storagePromiseTest', function () {
* @tc.desc clear promise interface test
* @tc.desc clear promise interface test
*/
*/
it
(
'
testClear0011
'
,
0
,
async
function
(
done
)
{
it
(
'
testClear0011
'
,
0
,
async
function
(
done
)
{
mPref
.
putSync
(
KEY_TEST_STRING_ELEMENT
,
"
test
"
);
await
mPref
.
putSync
(
KEY_TEST_STRING_ELEMENT
,
"
test
"
);
mPref
.
flushSync
();
await
mPref
.
flushSync
();
const
promise
=
mPref
.
clear
();
await
mPref
.
clear
().
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
"
defaultvalue
"
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
));
expect
(
"
defaultvalue
"
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
));
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -71,15 +64,14 @@ describe('storagePromiseTest', function () {
...
@@ -71,15 +64,14 @@ describe('storagePromiseTest', function () {
* @tc.desc has string interface test
* @tc.desc has string interface test
*/
*/
it
(
'
testHasKey0031
'
,
0
,
async
function
(
done
)
{
it
(
'
testHasKey0031
'
,
0
,
async
function
(
done
)
{
mPref
.
putSync
(
KEY_TEST_STRING_ELEMENT
,
"
test
"
);
await
mPref
.
putSync
(
KEY_TEST_STRING_ELEMENT
,
"
test
"
);
const
promise
=
mPref
.
has
(
KEY_TEST_STRING_ELEMENT
);
await
mPref
.
has
(
KEY_TEST_STRING_ELEMENT
).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
true
).
assertEqual
(
ret
);
expect
(
true
).
assertEqual
(
ret
);
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -88,15 +80,14 @@ describe('storagePromiseTest', function () {
...
@@ -88,15 +80,14 @@ describe('storagePromiseTest', function () {
* @tc.desc has int interface test
* @tc.desc has int interface test
*/
*/
it
(
'
testHasKey0032
'
,
0
,
async
function
(
done
)
{
it
(
'
testHasKey0032
'
,
0
,
async
function
(
done
)
{
mPref
.
putSync
(
KEY_TEST_INT_ELEMENT
,
1
);
await
mPref
.
putSync
(
KEY_TEST_INT_ELEMENT
,
1
);
const
promise
=
mPref
.
has
(
KEY_TEST_INT_ELEMENT
);
await
mPref
.
has
(
KEY_TEST_INT_ELEMENT
).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
true
).
assertEqual
(
ret
);
expect
(
true
).
assertEqual
(
ret
);
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -105,15 +96,14 @@ describe('storagePromiseTest', function () {
...
@@ -105,15 +96,14 @@ describe('storagePromiseTest', function () {
* @tc.desc has float interface test
* @tc.desc has float interface test
*/
*/
it
(
'
testHasKey0033
'
,
0
,
async
function
(
done
)
{
it
(
'
testHasKey0033
'
,
0
,
async
function
(
done
)
{
mPref
.
putSync
(
KEY_TEST_FLOAT_ELEMENT
,
2.0
);
await
mPref
.
putSync
(
KEY_TEST_FLOAT_ELEMENT
,
2.0
);
const
promise
=
mPref
.
has
(
KEY_TEST_FLOAT_ELEMENT
);
await
mPref
.
has
(
KEY_TEST_FLOAT_ELEMENT
).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
true
).
assertEqual
(
ret
);
expect
(
true
).
assertEqual
(
ret
);
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -122,15 +112,14 @@ describe('storagePromiseTest', function () {
...
@@ -122,15 +112,14 @@ describe('storagePromiseTest', function () {
* @tc.desc has boolean interface test
* @tc.desc has boolean interface test
*/
*/
it
(
'
testHasKey0034
'
,
0
,
async
function
(
done
)
{
it
(
'
testHasKey0034
'
,
0
,
async
function
(
done
)
{
mPref
.
putSync
(
KEY_TEST_BOOLEAN_ELEMENT
,
false
);
await
mPref
.
putSync
(
KEY_TEST_BOOLEAN_ELEMENT
,
false
);
const
promise
=
mPref
.
has
(
KEY_TEST_BOOLEAN_ELEMENT
);
await
mPref
.
has
(
KEY_TEST_BOOLEAN_ELEMENT
).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
true
).
assertEqual
(
ret
);
expect
(
true
).
assertEqual
(
ret
);
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -139,15 +128,14 @@ describe('storagePromiseTest', function () {
...
@@ -139,15 +128,14 @@ describe('storagePromiseTest', function () {
* @tc.desc has long interface test
* @tc.desc has long interface test
*/
*/
it
(
'
testHasKey0035
'
,
0
,
async
function
(
done
)
{
it
(
'
testHasKey0035
'
,
0
,
async
function
(
done
)
{
mPref
.
putSync
(
KEY_TEST_LONG_ELEMENT
,
0
);
await
mPref
.
putSync
(
KEY_TEST_LONG_ELEMENT
,
0
);
const
promise
=
mPref
.
has
(
KEY_TEST_LONG_ELEMENT
);
await
mPref
.
has
(
KEY_TEST_LONG_ELEMENT
).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
true
).
assertEqual
(
ret
);
expect
(
true
).
assertEqual
(
ret
);
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -156,15 +144,14 @@ describe('storagePromiseTest', function () {
...
@@ -156,15 +144,14 @@ describe('storagePromiseTest', function () {
* @tc.desc get string promise interface test
* @tc.desc get string promise interface test
*/
*/
it
(
'
testGetDefValue0061
'
,
0
,
async
function
(
done
)
{
it
(
'
testGetDefValue0061
'
,
0
,
async
function
(
done
)
{
mPref
.
clearSync
();
await
mPref
.
clearSync
();
const
promise
=
mPref
.
get
(
KEY_TEST_STRING_ELEMENT
,
"
defaultValue
"
);
await
mPref
.
get
(
KEY_TEST_STRING_ELEMENT
,
"
defaultValue
"
).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
'
defaultValue
'
).
assertEqual
(
ret
);
expect
(
'
defaultValue
'
).
assertEqual
(
ret
);
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -173,16 +160,15 @@ describe('storagePromiseTest', function () {
...
@@ -173,16 +160,15 @@ describe('storagePromiseTest', function () {
* @tc.desc get float promise interface test
* @tc.desc get float promise interface test
*/
*/
it
(
'
testGetFloat0071
'
,
0
,
async
function
(
done
)
{
it
(
'
testGetFloat0071
'
,
0
,
async
function
(
done
)
{
mPref
.
clearSync
();
await
mPref
.
clearSync
();
mPref
.
putSync
(
KEY_TEST_FLOAT_ELEMENT
,
3.0
);
await
mPref
.
putSync
(
KEY_TEST_FLOAT_ELEMENT
,
3.0
);
const
promise
=
mPref
.
get
(
KEY_TEST_FLOAT_ELEMENT
,
0.0
);
await
mPref
.
get
(
KEY_TEST_FLOAT_ELEMENT
,
0.0
).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
3.0
).
assertEqual
(
ret
);
expect
(
3.0
).
assertEqual
(
ret
);
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -191,16 +177,15 @@ describe('storagePromiseTest', function () {
...
@@ -191,16 +177,15 @@ describe('storagePromiseTest', function () {
* @tc.desc get int promise interface test
* @tc.desc get int promise interface test
*/
*/
it
(
'
testGetInt0081
'
,
0
,
async
function
(
done
)
{
it
(
'
testGetInt0081
'
,
0
,
async
function
(
done
)
{
mPref
.
clearSync
();
await
mPref
.
clearSync
();
mPref
.
putSync
(
KEY_TEST_INT_ELEMENT
,
3
);
await
mPref
.
putSync
(
KEY_TEST_INT_ELEMENT
,
3
);
const
promise
=
mPref
.
get
(
KEY_TEST_INT_ELEMENT
,
0.0
);
await
mPref
.
get
(
KEY_TEST_INT_ELEMENT
,
0.0
).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
3
).
assertEqual
(
ret
);
expect
(
3
).
assertEqual
(
ret
);
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -209,16 +194,15 @@ describe('storagePromiseTest', function () {
...
@@ -209,16 +194,15 @@ describe('storagePromiseTest', function () {
* @tc.desc get long promise interface test
* @tc.desc get long promise interface test
*/
*/
it
(
'
testGetLong0091
'
,
0
,
async
function
(
done
)
{
it
(
'
testGetLong0091
'
,
0
,
async
function
(
done
)
{
mPref
.
clearSync
();
await
mPref
.
clearSync
();
mPref
.
putSync
(
KEY_TEST_LONG_ELEMENT
,
3
);
await
mPref
.
putSync
(
KEY_TEST_LONG_ELEMENT
,
3
);
const
promise
=
mPref
.
get
(
KEY_TEST_LONG_ELEMENT
,
0
);
await
mPref
.
get
(
KEY_TEST_LONG_ELEMENT
,
0
).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
3
).
assertEqual
(
ret
);
expect
(
3
).
assertEqual
(
ret
);
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -227,17 +211,16 @@ describe('storagePromiseTest', function () {
...
@@ -227,17 +211,16 @@ describe('storagePromiseTest', function () {
* @tc.desc get String promise interface test
* @tc.desc get String promise interface test
*/
*/
it
(
'
testGetString101
'
,
0
,
async
function
(
done
)
{
it
(
'
testGetString101
'
,
0
,
async
function
(
done
)
{
mPref
.
clearSync
();
await
mPref
.
clearSync
();
mPref
.
putSync
(
KEY_TEST_STRING_ELEMENT
,
"
test
"
);
await
mPref
.
putSync
(
KEY_TEST_STRING_ELEMENT
,
"
test
"
);
mPref
.
flushSync
();
await
mPref
.
flushSync
();
const
promise
=
mPref
.
get
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
);
await
mPref
.
get
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
'
test
'
).
assertEqual
(
ret
);
expect
(
'
test
'
).
assertEqual
(
ret
);
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -246,17 +229,16 @@ describe('storagePromiseTest', function () {
...
@@ -246,17 +229,16 @@ describe('storagePromiseTest', function () {
* @tc.desc put boolean promise interface test
* @tc.desc put boolean promise interface test
*/
*/
it
(
'
testPutBoolean0121
'
,
0
,
async
function
(
done
)
{
it
(
'
testPutBoolean0121
'
,
0
,
async
function
(
done
)
{
mPref
.
clearSync
();
await
mPref
.
clearSync
();
const
promise
=
mPref
.
put
(
KEY_TEST_BOOLEAN_ELEMENT
,
true
);
await
mPref
.
put
(
KEY_TEST_BOOLEAN_ELEMENT
,
true
).
then
(
async
(
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
true
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_BOOLEAN_ELEMENT
,
false
));
expect
(
true
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_BOOLEAN_ELEMENT
,
false
));
mPref
.
flushSync
();
await
mPref
.
flushSync
();
expect
(
true
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_BOOLEAN_ELEMENT
,
false
));
expect
(
true
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_BOOLEAN_ELEMENT
,
false
));
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -265,17 +247,16 @@ describe('storagePromiseTest', function () {
...
@@ -265,17 +247,16 @@ describe('storagePromiseTest', function () {
* @tc.desc put float promise interface test
* @tc.desc put float promise interface test
*/
*/
it
(
'
testPutFloat0131
'
,
0
,
async
function
(
done
)
{
it
(
'
testPutFloat0131
'
,
0
,
async
function
(
done
)
{
mPref
.
clearSync
();
await
mPref
.
clearSync
();
const
promise
=
mPref
.
put
(
KEY_TEST_FLOAT_ELEMENT
,
4.0
);
await
mPref
.
put
(
KEY_TEST_FLOAT_ELEMENT
,
4.0
).
then
(
async
(
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
4.0
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_FLOAT_ELEMENT
,
0.0
));
expect
(
4.0
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_FLOAT_ELEMENT
,
0.0
));
mPref
.
flushSync
();
await
mPref
.
flushSync
();
expect
(
4.0
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_FLOAT_ELEMENT
,
0.0
));
expect
(
4.0
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_FLOAT_ELEMENT
,
0.0
));
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -284,17 +265,16 @@ describe('storagePromiseTest', function () {
...
@@ -284,17 +265,16 @@ describe('storagePromiseTest', function () {
* @tc.desc put int promise interface test
* @tc.desc put int promise interface test
*/
*/
it
(
'
testPutInt0141
'
,
0
,
async
function
(
done
)
{
it
(
'
testPutInt0141
'
,
0
,
async
function
(
done
)
{
mPref
.
clearSync
();
await
mPref
.
clearSync
();
const
promise
=
mPref
.
put
(
KEY_TEST_INT_ELEMENT
,
4
);
await
mPref
.
put
(
KEY_TEST_INT_ELEMENT
,
4
).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
4
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_INT_ELEMENT
,
0
));
expect
(
4
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_INT_ELEMENT
,
0
));
mPref
.
flushSync
();
mPref
.
flushSync
();
expect
(
4
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_INT_ELEMENT
,
0
));
expect
(
4
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_INT_ELEMENT
,
0
));
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -303,18 +283,17 @@ describe('storagePromiseTest', function () {
...
@@ -303,18 +283,17 @@ describe('storagePromiseTest', function () {
* @tc.desc put long promise interface test
* @tc.desc put long promise interface test
*/
*/
it
(
'
testPutLong0151
'
,
0
,
async
function
(
done
)
{
it
(
'
testPutLong0151
'
,
0
,
async
function
(
done
)
{
mPref
.
clearSync
();
await
mPref
.
clearSync
();
mPref
.
putSync
(
KEY_TEST_LONG_ELEMENT
,
4
);
await
mPref
.
putSync
(
KEY_TEST_LONG_ELEMENT
,
4
);
const
promise
=
mPref
.
put
(
KEY_TEST_LONG_ELEMENT
,
4
);
await
mPref
.
put
(
KEY_TEST_LONG_ELEMENT
,
4
).
then
(
async
(
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
4
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_LONG_ELEMENT
,
0
));
expect
(
4
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_LONG_ELEMENT
,
0
));
mPref
.
flushSync
();
await
mPref
.
flushSync
();
expect
(
4
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_LONG_ELEMENT
,
0
));
expect
(
4
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_LONG_ELEMENT
,
0
));
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -323,18 +302,17 @@ describe('storagePromiseTest', function () {
...
@@ -323,18 +302,17 @@ describe('storagePromiseTest', function () {
* @tc.desc put String promise interface test
* @tc.desc put String promise interface test
*/
*/
it
(
'
testPutString0161
'
,
0
,
async
function
(
done
)
{
it
(
'
testPutString0161
'
,
0
,
async
function
(
done
)
{
mPref
.
clearSync
();
await
mPref
.
clearSync
();
mPref
.
putSync
(
KEY_TEST_STRING_ELEMENT
,
"
abc
"
);
await
mPref
.
putSync
(
KEY_TEST_STRING_ELEMENT
,
"
abc
"
);
const
promise
=
mPref
.
put
(
KEY_TEST_STRING_ELEMENT
,
''
);
await
mPref
.
put
(
KEY_TEST_STRING_ELEMENT
,
''
).
then
(
async
(
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
''
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
));
expect
(
''
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
));
mPref
.
flushSync
();
await
mPref
.
flushSync
();
expect
(
''
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
));
expect
(
''
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
));
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -343,19 +321,16 @@ describe('storagePromiseTest', function () {
...
@@ -343,19 +321,16 @@ describe('storagePromiseTest', function () {
* @tc.desc deleteSync promise interface test
* @tc.desc deleteSync promise interface test
*/
*/
it
(
'
testPutString0171
'
,
0
,
async
function
(
done
)
{
it
(
'
testPutString0171
'
,
0
,
async
function
(
done
)
{
mPref
.
putSync
(
KEY_TEST_STRING_ELEMENT
,
"
abc
"
);
await
mPref
.
putSync
(
KEY_TEST_STRING_ELEMENT
,
"
abc
"
);
const
promise
=
mPref
.
put
(
KEY_TEST_STRING_ELEMENT
,
''
);
await
mPref
.
put
(
KEY_TEST_STRING_ELEMENT
,
''
).
then
(
async
(
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
''
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_STRING_ELEMENT
,
"
default
"
));
expect
(
''
).
await
mPref
.
deleteSync
(
KEY_TEST_STRING_ELEMENT
);
assertEqual
(
mPref
.
getSync
(
KEY_TEST_STRING_ELEMENT
,
"
default
"
));
expect
(
"
default
"
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_STRING_ELEMENT
,
"
default
"
));
mPref
.
deleteSync
(
KEY_TEST_STRING_ELEMENT
);
done
();
expect
(
"
default
"
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_STRING_ELEMENT
,
"
default
"
));
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
''
).
assertFail
();
expect
(
''
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -364,18 +339,17 @@ describe('storagePromiseTest', function () {
...
@@ -364,18 +339,17 @@ describe('storagePromiseTest', function () {
* @tc.desc flush promise interface test
* @tc.desc flush promise interface test
*/
*/
it
(
'
testFlush00181
'
,
0
,
async
function
(
done
)
{
it
(
'
testFlush00181
'
,
0
,
async
function
(
done
)
{
mPref
.
clearSync
();
await
mPref
.
clearSync
();
mPref
.
putSync
(
KEY_TEST_STRING_ELEMENT
,
"
abc
"
);
await
mPref
.
putSync
(
KEY_TEST_STRING_ELEMENT
,
"
abc
"
);
const
promise
=
mPref
.
put
(
KEY_TEST_STRING_ELEMENT
,
'
test
'
);
await
mPref
.
put
(
KEY_TEST_STRING_ELEMENT
,
'
test
'
).
then
(
async
(
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
'
test
'
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
));
expect
(
'
test
'
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
));
mPref
.
flush
();
await
mPref
.
flush
();
expect
(
'
test
'
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
));
expect
(
'
test
'
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
));
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -383,17 +357,16 @@ describe('storagePromiseTest', function () {
...
@@ -383,17 +357,16 @@ describe('storagePromiseTest', function () {
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Storage_0200
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Storage_0200
* @tc.desc Maximum length of key test
* @tc.desc Maximum length of key test
*/
*/
it
(
'
testMaxLengthofKey0200
'
,
0
,
async
function
(
done
)
{
it
(
'
testMaxLengthofKey0200
'
,
0
,
async
function
(
done
)
{
mPref
.
clearSync
();
await
mPref
.
clearSync
();
const
promise
=
mPref
.
put
(
MAX_KEY_LENGTH
,
"
value1
"
)
await
mPref
.
put
(
MAX_KEY_LENGTH
,
"
value1
"
).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
"
value1
"
).
assertEqual
(
mPref
.
getSync
(
MAX_KEY_LENGTH
,
"
defaultvalue
"
));
expect
(
"
value1
"
).
assertEqual
(
mPref
.
getSync
(
MAX_KEY_LENGTH
,
"
defaultvalue
"
))
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
})
await
promise
;
done
();
done
();
})
})
})
/**
/**
* @tc.name Maximum length of value test
* @tc.name Maximum length of value test
...
@@ -402,16 +375,15 @@ describe('storagePromiseTest', function () {
...
@@ -402,16 +375,15 @@ describe('storagePromiseTest', function () {
*/
*/
it
(
'
testMaxLengthofValue0210
'
,
0
,
async
function
(
done
)
{
it
(
'
testMaxLengthofValue0210
'
,
0
,
async
function
(
done
)
{
mPref
.
clearSync
();
await
mPref
.
clearSync
();
mPref
.
putSync
(
"
test
"
,
"
abc
"
);
await
mPref
.
putSync
(
"
test
"
,
"
abc
"
);
const
promise
=
mPref
.
put
(
"
test
"
,
MAX_VALUE_LENGTH
);
await
mPref
.
put
(
"
test
"
,
MAX_VALUE_LENGTH
).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
MAX_VALUE_LENGTH
).
assertEqual
(
mPref
.
getSync
(
"
test
"
,
"
defaultvalue
"
));
expect
(
MAX_VALUE_LENGTH
).
assertEqual
(
mPref
.
getSync
(
"
test
"
,
"
defaultvalue
"
));
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
...
@@ -422,16 +394,15 @@ describe('storagePromiseTest', function () {
...
@@ -422,16 +394,15 @@ describe('storagePromiseTest', function () {
*/
*/
it
(
'
testMaxLengthofValue0220
'
,
0
,
async
function
(
done
)
{
it
(
'
testMaxLengthofValue0220
'
,
0
,
async
function
(
done
)
{
mPref
.
clearSync
();
await
mPref
.
clearSync
();
mPref
.
putSync
(
"
test
"
,
MAX_VALUE_LENGTH
)
await
mPref
.
putSync
(
"
test
"
,
MAX_VALUE_LENGTH
);
const
promise
=
mPref
.
put
(
"
test
"
,
"
y
"
.
repeat
(
8192
));
await
mPref
.
put
(
"
test
"
,
"
y
"
.
repeat
(
8192
)).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
MAX_VALUE_LENGTH
).
assertEqual
(
mPref
.
getSync
(
"
test
"
,
"
defaultvalue
"
));
expect
(
MAX_VALUE_LENGTH
).
assertEqual
(
mPref
.
getSync
(
"
test
"
,
"
defaultvalue
"
));
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -441,16 +412,15 @@ describe('storagePromiseTest', function () {
...
@@ -441,16 +412,15 @@ describe('storagePromiseTest', function () {
*/
*/
it
(
'
testDelete0230
'
,
0
,
async
function
(
done
)
{
it
(
'
testDelete0230
'
,
0
,
async
function
(
done
)
{
mPref
.
putSync
(
KEY_TEST_STRING_ELEMENT
,
"
abc
"
);
await
mPref
.
putSync
(
KEY_TEST_STRING_ELEMENT
,
"
abc
"
);
expect
(
"
abc
"
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_STRING_ELEMENT
,
"
default
"
));
expect
(
"
abc
"
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_STRING_ELEMENT
,
"
default
"
));
const
promise
=
mPref
.
delete
(
KEY_TEST_STRING_ELEMENT
);
await
mPref
.
delete
(
KEY_TEST_STRING_ELEMENT
).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
"
default
"
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_STRING_ELEMENT
,
"
default
"
));
expect
(
"
default
"
).
assertEqual
(
mPref
.
getSync
(
KEY_TEST_STRING_ELEMENT
,
"
default
"
)
);
done
(
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
''
).
assertFail
();
expect
(
''
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -458,17 +428,16 @@ describe('storagePromiseTest', function () {
...
@@ -458,17 +428,16 @@ describe('storagePromiseTest', function () {
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Storage_0240
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Storage_0240
* @tc.desc Maximum length of key test
* @tc.desc Maximum length of key test
*/
*/
it
(
'
testMaxLengthofKey0240
'
,
0
,
async
function
(
done
)
{
it
(
'
testMaxLengthofKey0240
'
,
0
,
async
function
(
done
)
{
mPref
.
putSync
(
MAX_KEY_LENGTH
,
"
value1
"
);
await
mPref
.
putSync
(
MAX_KEY_LENGTH
,
"
value1
"
);
expect
(
"
value1
"
).
assertEqual
(
mPref
.
getSync
(
MAX_KEY_LENGTH
,
"
default
"
));
expect
(
"
value1
"
).
assertEqual
(
mPref
.
getSync
(
MAX_KEY_LENGTH
,
"
default
"
));
const
promise
=
mPref
.
delete
(
MAX_KEY_LENGTH
);
await
mPref
.
delete
(
MAX_KEY_LENGTH
).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
"
default
"
).
assertEqual
(
mPref
.
getSync
(
MAX_KEY_LENGTH
,
"
default
"
));
expect
(
"
default
"
).
assertEqual
(
mPref
.
getSync
(
MAX_KEY_LENGTH
,
"
default
"
)
);
done
(
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
/**
/**
...
@@ -478,16 +447,15 @@ describe('storagePromiseTest', function () {
...
@@ -478,16 +447,15 @@ describe('storagePromiseTest', function () {
*/
*/
it
(
'
testMaxLengthofValue0250
'
,
0
,
async
function
(
done
)
{
it
(
'
testMaxLengthofValue0250
'
,
0
,
async
function
(
done
)
{
mPref
.
clearSync
();
await
mPref
.
clearSync
();
mPref
.
putSync
(
"
test
"
,
MAX_VALUE_LENGTH
)
await
mPref
.
putSync
(
"
test
"
,
MAX_VALUE_LENGTH
)
const
promise
=
mPref
.
put
(
"
test
"
,
"
y
"
.
repeat
(
8192
));
await
mPref
.
put
(
"
test
"
,
"
y
"
.
repeat
(
8192
)).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
MAX_VALUE_LENGTH
).
assertEqual
(
mPref
.
getSync
(
"
test
"
,
"
defaultvalue
"
));
expect
(
MAX_VALUE_LENGTH
).
assertEqual
(
mPref
.
getSync
(
"
test
"
,
"
defaultvalue
"
));
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
done
();
});
});
await
promise
;
await
mPref
.
putSync
(
"
test
"
,
MAX_VALUE_LENGTH
)
mPref
.
putSync
(
"
test
"
,
MAX_VALUE_LENGTH
)
expect
(
MAX_VALUE_LENGTH
).
assertEqual
(
mPref
.
getSync
(
"
test
"
,
"
defaultvalue
"
));
expect
(
MAX_VALUE_LENGTH
).
assertEqual
(
mPref
.
getSync
(
"
test
"
,
"
defaultvalue
"
));
done
();
done
();
})
})
...
@@ -499,14 +467,13 @@ describe('storagePromiseTest', function () {
...
@@ -499,14 +467,13 @@ describe('storagePromiseTest', function () {
*/
*/
it
(
'
testGetDefValue0260
'
,
0
,
async
function
(
done
)
{
it
(
'
testGetDefValue0260
'
,
0
,
async
function
(
done
)
{
await
mPref
.
clear
();
await
mPref
.
clear
();
const
promise
=
mPref
.
get
(
KEY_TEST_BOOLEAN_ELEMENT
,
true
);
await
mPref
.
get
(
KEY_TEST_BOOLEAN_ELEMENT
,
true
).
then
((
ret
)
=>
{
promise
.
then
((
ret
)
=>
{
expect
(
true
).
assertEqual
(
ret
);
expect
(
true
).
assertEqual
(
ret
);
done
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
expect
(
null
).
assertFail
();
expect
(
null
).
assertFail
();
});
await
promise
;
done
();
done
();
});
})
})
})
})
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录