Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
1270caa9
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看板
未验证
提交
1270caa9
编写于
7月 13, 2023
作者:
O
openharmony_ci
提交者:
Gitee
7月 13, 2023
浏览文件
操作
浏览文件
下载
差异文件
!9309 【Distributeddatamgr】【Master】PreferencesSync接口用例补充
Merge pull request !9309 from yanglifeng/master
上级
5eed63a7
8e5f8251
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
385 addition
and
1 deletion
+385
-1
distributeddatamgr/preferencesjstest/hap/src/main/js/test/List.test.js
...tamgr/preferencesjstest/hap/src/main/js/test/List.test.js
+3
-1
distributeddatamgr/preferencesjstest/hap/src/main/js/test/PreferencesSyncJsunit.test.js
...jstest/hap/src/main/js/test/PreferencesSyncJsunit.test.js
+382
-0
未找到文件。
distributeddatamgr/preferencesjstest/hap/src/main/js/test/List.test.js
浏览文件 @
1270caa9
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022
-2023
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
...
...
@@ -23,6 +23,7 @@ import storageSyncTest from './StorageSyncJsunit.test.js'
import
systemStorageTest
from
'
./SystemStorageJsunit.test.js
'
import
preferencesV9CallbackTest
from
'
./V9_PreferencesCallBackJsunit.test.js
'
import
preferencesV9PromiseTest
from
'
./V9_PreferencesPromiseJsunit.test.js
'
import
PreferencesSyncTest
from
'
./PreferencesSyncJsunit.test.js
'
export
default
function
testsuite
()
{
storageCallBackTest
()
...
...
@@ -35,4 +36,5 @@ export default function testsuite() {
preferencesPromiseTest
()
preferencesV9CallbackTest
()
preferencesV9PromiseTest
()
PreferencesSyncTest
()
}
distributeddatamgr/preferencesjstest/hap/src/main/js/test/PreferencesSyncJsunit.test.js
0 → 100644
浏览文件 @
1270caa9
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
@ohos/hypium
'
;
import
data_preferences
from
'
@ohos.data.preferences
'
;
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
const
NAME
=
'
test_preferences_store
'
;
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
'
;
let
mPreferences
;
let
context
;
export
default
function
PreferencesSyncTest
()
{
describe
(
'
PreferencesSyncTest
'
,
function
()
{
beforeAll
(
async
function
()
{
console
.
info
(
'
beforeAll
'
);
context
=
featureAbility
.
getContext
();
mPreferences
=
await
data_preferences
.
getPreferences
(
context
,
NAME
);
})
afterAll
(
async
function
()
{
console
.
info
(
'
afterAll
'
);
await
data_preferences
.
deletePreferences
(
context
,
NAME
);
})
/**
* @tc.number SUB_DDM_Preferences_PutSync_0100
* @tc.name putSync StringArray interface test
* @tc.desc putSync StringArray interface test
*/
it
(
'
SUB_DDM_Preferences_PutSync_0100
'
,
0
,
function
(
done
)
{
mPreferences
.
clearSync
();
const
stringArr
=
[
'
1
'
,
'
2
'
,
'
3
'
];
mPreferences
.
putSync
(
KEY_TEST_STRING_ARRAY_ELEMENT
,
stringArr
);
let
rc
=
mPreferences
.
getSync
(
KEY_TEST_STRING_ARRAY_ELEMENT
,
[]);
for
(
let
i
=
0
;
i
<
stringArr
.
length
;
i
++
)
{
console
.
info
(
'
ttt stringArr =
'
+
stringArr
[
i
]
+
'
rc =
'
+
rc
[
i
]);
expect
(
stringArr
[
i
]).
assertEqual
(
rc
[
i
]);
}
done
();
});
/**
* @tc.number SUB_DDM_Preferences_PutSync_0200
* @tc.name putSync numberArr interface test
* @tc.desc putSync numberArr interface test
*/
it
(
'
SUB_DDM_Preferences_PutSync_0200
'
,
0
,
async
function
(
done
)
{
mPreferences
.
clearSync
();
const
numberArr
=
[
1
,
2
,
3
];
mPreferences
.
putSync
(
KEY_TEST_NUMBER_ARRAY_ELEMENT
,
numberArr
);
let
rc
=
mPreferences
.
getSync
(
KEY_TEST_NUMBER_ARRAY_ELEMENT
,
[]);
for
(
let
i
=
0
;
i
<
numberArr
.
length
;
i
++
)
{
console
.
info
(
'
ttt stringArr =
'
+
numberArr
[
i
]
+
'
rc =
'
+
rc
[
i
]);
expect
(
numberArr
[
i
]).
assertEqual
(
rc
[
i
]);
}
done
();
});
/**
* @tc.number SUB_DDM_Preferences_PutSync_0300
* @tc.name putSync boolArr interface test
* @tc.desc putSync boolArr interface test
*/
it
(
'
SUB_DDM_Preferences_PutSync_0300
'
,
0
,
async
function
(
done
)
{
mPreferences
.
clearSync
();
const
boolArr
=
[
true
,
true
,
false
];
mPreferences
.
putSync
(
KEY_TEST_BOOL_ARRAY_ELEMENT
,
boolArr
);
let
rc
=
mPreferences
.
getSync
(
KEY_TEST_BOOL_ARRAY_ELEMENT
,
[
false
,
true
]);
for
(
let
i
=
0
;
i
<
boolArr
.
length
;
i
++
)
{
console
.
info
(
'
ttt stringArr =
'
+
boolArr
[
i
]
+
'
rc =
'
+
rc
[
i
]);
expect
(
boolArr
[
i
]).
assertEqual
(
rc
[
i
]);
}
done
();
});
/**
* @tc.number SUB_DDM_Preferences_GetAllSync_0100
* @tc.name getAllSync interface test
* @tc.desc getAllSync interface test
*/
it
(
'
SUB_DDM_Preferences_GetAllSync_0100
'
,
0
,
async
function
(
done
)
{
mPreferences
.
clearSync
();
const
doubleArr
=
[
11
,
22
,
33
];
const
stringArr
=
[
'
11
'
,
'
22
'
,
'
33
'
];
const
boolArr
=
[
true
,
false
,
false
,
true
];
mPreferences
.
putSync
(
KEY_TEST_STRING_ARRAY_ELEMENT
,
stringArr
);
mPreferences
.
putSync
(
KEY_TEST_BOOL_ARRAY_ELEMENT
,
boolArr
);
mPreferences
.
putSync
(
KEY_TEST_NUMBER_ARRAY_ELEMENT
,
doubleArr
);
mPreferences
.
putSync
(
KEY_TEST_BOOLEAN_ELEMENT
,
false
);
mPreferences
.
putSync
(
KEY_TEST_STRING_ELEMENT
,
"
123
"
);
mPreferences
.
putSync
(
KEY_TEST_FLOAT_ELEMENT
,
123.1
);
await
mPreferences
.
flush
();
let
obj
=
mPreferences
.
getAllSync
();
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
();
})
/**
* @tc.number SUB_DDM_Preferences_ClearSync_0100
* @tc.name clearSync interface test
* @tc.desc clearSync interface test
*/
it
(
'
SUB_DDM_Preferences_ClearSync_0100
'
,
0
,
async
function
(
done
)
{
mPreferences
.
clearSync
();
mPreferences
.
putSync
(
KEY_TEST_STRING_ELEMENT
,
"
test
"
);
await
mPreferences
.
flush
();
mPreferences
.
clearSync
();
let
per
=
mPreferences
.
getSync
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
);
expect
(
"
defaultvalue
"
).
assertEqual
(
per
);
done
();
})
/**
* @tc.number SUB_DDM_Preferences_HasSync_0100
* @tc.name hasSync interface test
* @tc.desc hasSync interface test
*/
it
(
'
SUB_DDM_Preferences_HasSync_0100
'
,
0
,
async
function
(
done
)
{
mPreferences
.
clearSync
();
mPreferences
.
putSync
(
KEY_TEST_STRING_ELEMENT
,
"
test
"
);
const
ret
=
mPreferences
.
hasSync
(
KEY_TEST_STRING_ELEMENT
);
expect
(
true
).
assertEqual
(
ret
);
done
();
})
/**
* @tc.number SUB_DDM_Preferences_HasSync_0200
* @tc.name hasSync interface test
* @tc.desc hasSync interface test
*/
it
(
'
SUB_DDM_Preferences_HasSync_0200
'
,
0
,
async
function
(
done
)
{
mPreferences
.
clearSync
();
mPreferences
.
putSync
(
KEY_TEST_INT_ELEMENT
,
1
);
const
ret
=
mPreferences
.
hasSync
(
KEY_TEST_INT_ELEMENT
);
expect
(
true
).
assertEqual
(
ret
);
done
();
})
/**
* @tc.number SUB_DDM_Preferences_HasSync_0300
* @tc.name hasSync interface test
* @tc.desc hasSync interface test
*/
it
(
'
SUB_DDM_Preferences_HasSync_0300
'
,
0
,
async
function
(
done
)
{
mPreferences
.
clearSync
();
mPreferences
.
putSync
(
KEY_TEST_FLOAT_ELEMENT
,
2.0
);
const
ret
=
mPreferences
.
hasSync
(
KEY_TEST_FLOAT_ELEMENT
);
expect
(
true
).
assertEqual
(
ret
);
done
();
})
/**
* @tc.number SUB_DDM_Preferences_HasSync_0400
* @tc.name hasSync interface test
* @tc.desc hasSync interface test
*/
it
(
'
SUB_DDM_Preferences_HasSync_0400
'
,
0
,
async
function
(
done
)
{
mPreferences
.
clearSync
();
mPreferences
.
putSync
(
KEY_TEST_BOOLEAN_ELEMENT
,
false
);
const
ret
=
mPreferences
.
hasSync
(
KEY_TEST_BOOLEAN_ELEMENT
);
expect
(
true
).
assertEqual
(
ret
);
done
();
})
/**
* @tc.number SUB_DDM_Preferences_HasSync_0500
* @tc.name hasSync interface test
* @tc.desc hasSync interface test
*/
it
(
'
SUB_DDM_Preferences_HasSync_0500
'
,
0
,
async
function
(
done
)
{
mPreferences
.
clearSync
();
mPreferences
.
putSync
(
KEY_TEST_LONG_ELEMENT
,
0
);
const
ret
=
mPreferences
.
hasSync
(
KEY_TEST_LONG_ELEMENT
);
expect
(
true
).
assertEqual
(
ret
);
done
();
})
/**
* @tc.number SUB_DDM_Preferences_HasSync_0600
* @tc.name hasSync interface test
* @tc.desc hasSync interface test
*/
it
(
'
SUB_DDM_Preferences_HasSync_0600
'
,
0
,
async
function
(
done
)
{
mPreferences
.
clearSync
();
const
ret
=
mPreferences
.
hasSync
(
KEY_TEST_LONG_ELEMENT
);
console
.
info
(
'
ret =
'
+
ret
);
expect
(
ret
===
false
).
assertTrue
();
done
();
})
/**
* @tc.number SUB_DDM_Preferences_GetSync_0100
* @tc.name getSync interface test
* @tc.desc getSync interface test
*/
it
(
'
SUB_DDM_Preferences_GetSync_0100
'
,
0
,
async
function
(
done
)
{
mPreferences
.
clearSync
();
const
ret
=
mPreferences
.
getSync
(
KEY_TEST_STRING_ELEMENT
,
"
defaultValue
"
);
expect
(
'
defaultValue
'
).
assertEqual
(
ret
);
done
();
})
/**
* @tc.number SUB_DDM_Preferences_GetSync_0200
* @tc.name getSync interface test
* @tc.desc getSync interface test
*/
it
(
'
SUB_DDM_Preferences_GetSync_0200
'
,
0
,
async
function
(
done
)
{
mPreferences
.
clearSync
();
mPreferences
.
putSync
(
KEY_TEST_FLOAT_ELEMENT
,
3.0
);
const
ret
=
mPreferences
.
getSync
(
KEY_TEST_FLOAT_ELEMENT
,
0.0
);
expect
(
3.0
).
assertEqual
(
ret
);
done
();
})
/**
* @tc.number SUB_DDM_Preferences_GetSync_0300
* @tc.name getSync interface test
* @tc.desc getSync interface test
*/
it
(
'
SUB_DDM_Preferences_GetSync_0300
'
,
0
,
async
function
(
done
)
{
mPreferences
.
clearSync
();
mPreferences
.
putSync
(
KEY_TEST_INT_ELEMENT
,
3
);
const
ret
=
mPreferences
.
getSync
(
KEY_TEST_INT_ELEMENT
,
0.0
);
expect
(
3
).
assertEqual
(
ret
);
done
();
})
/**
* @tc.number SUB_DDM_Preferences_GetSync_0400
* @tc.name getSync interface test
* @tc.desc getSync interface test
*/
it
(
'
SUB_DDM_Preferences_GetSync_0400
'
,
0
,
async
function
(
done
)
{
mPreferences
.
clearSync
();
mPreferences
.
putSync
(
KEY_TEST_LONG_ELEMENT
,
3
);
const
ret
=
mPreferences
.
getSync
(
KEY_TEST_LONG_ELEMENT
,
0
);
expect
(
3
).
assertEqual
(
ret
);
done
();
})
/**
* @tc.number SUB_DDM_Preferences_GetSync_0500
* @tc.name getSync interface test
* @tc.desc getSync interface test
*/
it
(
'
SUB_DDM_Preferences_GetSync_0500
'
,
0
,
async
function
(
done
)
{
mPreferences
.
clearSync
();
mPreferences
.
putSync
(
KEY_TEST_STRING_ELEMENT
,
"
test
"
);
await
mPreferences
.
flush
();
const
ret
=
mPreferences
.
getSync
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
);
expect
(
'
test
'
).
assertEqual
(
ret
);
done
();
})
/**
* @tc.number SUB_DDM_Preferences_PutSync_0400
* @tc.name putSync interface test
* @tc.desc putSync interface test
*/
it
(
'
SUB_DDM_Preferences_PutSync_0400
'
,
0
,
async
function
(
done
)
{
mPreferences
.
clearSync
();
mPreferences
.
putSync
(
KEY_TEST_BOOLEAN_ELEMENT
,
true
);
let
per
=
mPreferences
.
getSync
(
KEY_TEST_BOOLEAN_ELEMENT
,
false
);
expect
(
true
).
assertEqual
(
per
);
await
mPreferences
.
flush
();
let
per2
=
mPreferences
.
getSync
(
KEY_TEST_BOOLEAN_ELEMENT
,
false
);
expect
(
true
).
assertEqual
(
per2
);
done
();
})
/**
* @tc.number SUB_DDM_Preferences_PutSync_0500
* @tc.name putSync interface test
* @tc.desc putSync interface test
*/
it
(
'
SUB_DDM_Preferences_PutSync_0500
'
,
0
,
async
function
(
done
)
{
mPreferences
.
clearSync
();
mPreferences
.
putSync
(
KEY_TEST_FLOAT_ELEMENT
,
4.0
);
let
per
=
mPreferences
.
getSync
(
KEY_TEST_FLOAT_ELEMENT
,
0.0
);
expect
(
4.0
).
assertEqual
(
per
);
await
mPreferences
.
flush
();
let
per2
=
mPreferences
.
getSync
(
KEY_TEST_FLOAT_ELEMENT
,
0.0
);
expect
(
4.0
).
assertEqual
(
per2
);
done
();
})
/**
* @tc.number SUB_DDM_Preferences_PutSync_0600
* @tc.name putSync interface test
* @tc.desc putSync interface test
*/
it
(
'
SUB_DDM_Preferences_PutSync_0600
'
,
0
,
async
function
(
done
)
{
mPreferences
.
clearSync
();
mPreferences
.
putSync
(
KEY_TEST_INT_ELEMENT
,
4
);
let
per
=
mPreferences
.
getSync
(
KEY_TEST_INT_ELEMENT
,
0
);
expect
(
4
).
assertEqual
(
per
);
await
mPreferences
.
flush
();
let
per2
=
mPreferences
.
getSync
(
KEY_TEST_INT_ELEMENT
,
0
);
expect
(
4
).
assertEqual
(
per2
);
done
();
})
/**
* @tc.number SUB_DDM_Preferences_PutSync_0700
* @tc.name putSync interface test
* @tc.desc putSync interface test
*/
it
(
'
SUB_DDM_Preferences_PutSync_0700
'
,
0
,
async
function
(
done
)
{
mPreferences
.
clearSync
();
mPreferences
.
putSync
(
KEY_TEST_LONG_ELEMENT
,
4
);
let
per
=
mPreferences
.
getSync
(
KEY_TEST_LONG_ELEMENT
,
0
);
expect
(
4
).
assertEqual
(
per
);
await
mPreferences
.
flush
();
let
per2
=
mPreferences
.
getSync
(
KEY_TEST_LONG_ELEMENT
,
0
);
expect
(
4
).
assertEqual
(
per2
);
done
();
})
/**
* @tc.number SUB_DDM_Preferences_PutSync_0800
* @tc.name putSync interface test
* @tc.desc putSync interface test
*/
it
(
'
SUB_DDM_Preferences_PutSync_0800
'
,
0
,
async
function
(
done
)
{
mPreferences
.
clearSync
();
mPreferences
.
putSync
(
KEY_TEST_STRING_ELEMENT
,
''
);
let
per
=
mPreferences
.
getSync
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
);
expect
(
''
).
assertEqual
(
per
);
await
mPreferences
.
flush
();
let
per2
=
mPreferences
.
getSync
(
KEY_TEST_STRING_ELEMENT
,
"
defaultvalue
"
);
expect
(
''
).
assertEqual
(
per2
);
done
();
})
/**
* @tc.number SUB_DDM_Preferences_deleteSync_0100
* @tc.name deleteSync interface test
* @tc.desc deleteSync interface test
*/
it
(
'
SUB_DDM_Preferences_deleteSync_0100
'
,
0
,
async
function
(
done
)
{
mPreferences
.
putSync
(
KEY_TEST_STRING_ELEMENT
,
"
abc
"
);
expect
(
"
abc
"
).
assertEqual
(
mPreferences
.
getSync
(
KEY_TEST_STRING_ELEMENT
,
"
default
"
));
mPreferences
.
deleteSync
(
KEY_TEST_STRING_ELEMENT
);
expect
(
"
default
"
).
assertEqual
(
mPreferences
.
getSync
(
KEY_TEST_STRING_ELEMENT
,
"
default
"
));
done
();
})
})
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录