提交 9e580e06 编写于 作者: J jinhai

【storage】增加storagestatisticsjstest测试套

Signed-off-by: Njinhai <jinhai2@huawei.com>
Change-Id: Ic957fff49ec8175bf0afac93317c1eac1887e609
上级 fde7060c
......@@ -21,6 +21,7 @@ group("storage") {
"storagefileiojstest:storagefileio_js_test",
"storagefilejstest:storagefile_js_test",
"storagestatfsjstest:storagestatfs_js_test",
"storagestatisticsjstest:storagestatistics_js_test",
"storagevolumesjstest:storagevolumes_js_test",
]
}
......
# 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("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("storagestatistics_js_test") {
hap_profile = "./src/main/config.json"
deps = [
":storagestatistics_js_assets",
":storagestatistics_js_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsStorageStatisticsJsTest"
}
ohos_js_assets("storagestatistics_js_assets") {
source_dir = "./src/main/js/default"
}
ohos_resources("storagestatistics_js_resources") {
sources = [ "./src/main/resources" ]
hap_profile = "./src/main/config.json"
}
{
"description": "Configuration for storage statistics Tests",
"driver": {
"type": "JSUnitTest",
"test-timeout": "60000",
"package": "ohos.acts.storage.statistics",
"shell-timeout": "60000"
},
"kits": [
{
"test-file-name": [
"ActsStorageStatisticsJsTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "ohos.acts.storage.statistics",
"vendor": "acts",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 4,
"target": 5
}
},
"deviceConfig": {},
"module": {
"package": "ohos.acts.storage.statistics",
"name": ".MyApplication",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry",
"installationFree": true
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"visible": true,
"name": "ohos.acts.storage.statistics.MainAbility",
"icon": "$media:icon",
"description": "$string:mainability_description",
"label": "$string:entry_MainAbility",
"type": "page",
"launchType": "standard"
}
],
"js": [
{
"pages": [
"pages/index/index"
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": true
}
}
]
}
}
\ No newline at end of file
/*
* 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.
*/
export default {
onCreate() {
console.info('ohos.acts.storage.statistics onCreate');
},
onDestroy() {
console.info('ohos.acts.storage.statistics onDestroy');
}
};
\ No newline at end of file
{
"strings": {
"hello": "Hello",
"world": "Test"
}
}
\ No newline at end of file
{
"strings": {
"hello": "您好",
"world": "测试"
}
}
\ No newline at end of file
.container {
flex-direction: column;
justify-content: center;
align-items: center;
}
.title {
font-size: 100px;
}
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
/*
* 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 app from '@system.app'
import {Core} from 'deccjsunit/index'
const injectRef = Object.getPrototypeOf(global) || global
injectRef.regeneratorRuntime = require('@babel/runtime/regenerator')
export default {
data: {
title: ''
},
onInit() {
this.title = this.$t('strings.world');
},
onShow() {
console.info('onShow finish')
const core = Core.getInstance()
core.init()
const configService = core.getDefaultService('config')
configService.setConfig(this)
require('../../test/List.test')
core.execute()
},
onReady() {
},
}
\ No newline at end of file
/*
* 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 storageStatistics from "@ohos.storagestatistics";
import volumeManager from "@ohos.volumemanager";
import featureAbility from '@ohos.ability.featureAbility';
import {
describe,
beforeAll,
beforeEach,
afterEach,
afterAll,
it,
expect,
} from "deccjsunit/index";
export function randomString(num) {
let len = num;
var $chars = "helloWord";
var maxPos = $chars.length;
var pwd = "";
for (var i = 0; i < len; i++) {
pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
}
return pwd;
}
function isIntNum(val) {
return typeof val === "number" && val % 1 === 0;
}
function isNegativeNum(val) {
return val < 0;
}
function isString(str) {
return typeof str == "string" && str.constructor == String;
}
function isBoolean(val) {
return typeof val == "boolean";
}
function isInclude(error, message) {
return error.toString().indexOf(message) != -1;
}
function isArray(object) {
return object && typeof object === 'object' && Array == object.constructor;
}
async function getPackageName() {
console.log("featureAbility:" + JSON.stringify(featureAbility));
let want = await featureAbility.getWant();
return want.bundleName;
}
export {
isIntNum,
isNegativeNum,
isString,
isBoolean,
isInclude,
isArray,
getPackageName,
describe,
beforeAll,
beforeEach,
afterEach,
afterAll,
it,
expect,
storageStatistics,
volumeManager,
};
/*
* 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.
*/
require('./StorageStatistics.test.js')
/*
* 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 {
isIntNum,
isNegativeNum,
describe,
it,
expect,
storageStatistics,
getPackageName,
} from "./Common";
describe("storageStatistics", function () {
/**
* @tc.number SUB_DF_STORAGE_STATISTICS_GET_BUNDLE_STAT_0000
* @tc.name storage_statistics_test_get_bundle_stat_async_000
* @tc.desc Test getBundleStats() interfaces, returned in promise mode.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it("storage_statistics_test_get_bundle_stat_async_000", 0, async function (done) {
try {
let packageName = await getPackageName();
let bundleStat = await storageStatistics.getBundleStats("id", packageName);
expect(bundleStat != null).assertTrue();
expect(isIntNum(bundleStat.appSize) && !isNegativeNum(bundleStat.appSize)).assertTrue();
expect(isIntNum(bundleStat.cacheSize) && !isNegativeNum(bundleStat.cacheSize)).assertTrue();
expect(isIntNum(bundleStat.dataSize) && !isNegativeNum(bundleStat.dataSize)).assertTrue();
console.log(`promise bundleStat ===---=== ${JSON.stringify(bundleStat)}`);
} catch (e) {
console.log("storage_statistics_test_get_bundle_stat_async_000 has failed for " + e);
expect(null).assertFail();
}
done();
});
/**
* @tc.number SUB_DF_STORAGE_STATISTICS_GET_BUNDLE_STAT_0010
* @tc.name storage_statistics_test_get_bundle_stat_async_001
* @tc.desc Test getBundleStats() interfaces , returned in callback mode.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it("storage_statistics_test_get_bundle_stat_async_001", 0, async function (done) {
try {
let packageName = await getPackageName();
storageStatistics.getBundleStats("id", packageName, (error, bundleStat) => {
expect(bundleStat != null).assertTrue();
expect(isIntNum(bundleStat.appSize) && !isNegativeNum(bundleStat.appSize)).assertTrue();
expect(isIntNum(bundleStat.cacheSize) && !isNegativeNum(bundleStat.cacheSize)).assertTrue();
expect(isIntNum(bundleStat.dataSize) && !isNegativeNum(bundleStat.dataSize)).assertTrue();
console.log(`callback bundleStat ===---=== ${JSON.stringify(bundleStat)}`);
});
} catch (e) {
console.log("storage_statistics_test_get_bundle_stat_async_001 has failed for " + e);
expect(null).assertFail();
}
done();
});
/**
* @tc.number SUB_DF_STORAGE_STATISTICS_GET_BUNDLE_STAT_0020
* @tc.name storage_statistics_test_get_bundle_stat_async_002
* @tc.desc Test getBundleStats() interfaces, the parameter packagename is errors, returning error results.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it("storage_statistics_test_get_bundle_stat_async_002", 0, async function (done) {
try {
let bundleStat = await storageStatistics.getBundleStats("id", "packageName");
expect(bundleStat != null).assertTrue();
expect(bundleStat.appSize == 0).assertTrue();
expect(bundleStat.cacheSize == 0).assertTrue();
expect(bundleStat.dataSize == 0).assertTrue();
console.log(`async_002 bundleStat ===---=== ${JSON.stringify(bundleStat)}`);
} catch (e) {
console.log("storage_statistics_test_get_bundle_stat_async_002 has failed for " + e);
expect(!!e).assertTrue();
}
done();
});
/**
* @tc.number SUB_DF_STORAGE_STATISTICS_GET_BUNDLE_STAT_0030
* @tc.name storage_statistics_test_get_bundle_stat_async_003
* @tc.desc Test getBundleStats() interfaces, No parameters, returns the correct result.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it("storage_statistics_test_get_bundle_stat_async_003", 0, async function (done) {
try {
let packageName = await getPackageName();
let bundleStat = await storageStatistics.getBundleStats("", packageName);
expect(bundleStat != null).assertTrue();
expect(isIntNum(bundleStat.appSize) && !isNegativeNum(bundleStat.appSize)).assertTrue();
expect(isIntNum(bundleStat.cacheSize) && !isNegativeNum(bundleStat.cacheSize)).assertTrue();
expect(isIntNum(bundleStat.dataSize) && !isNegativeNum(bundleStat.dataSize)).assertTrue();
console.log(`async_003 bundleStat ===---=== ${JSON.stringify(bundleStat)}`);
} catch (e) {
console.log("storage_statistics_test_get_bundle_stat_async_003 has failed for " + e);
expect(!!e).assertTrue();
}
done();
});
/**
* @tc.number SUB_DF_STORAGE_STATISTICS_GET_BUNDLE_STAT_0040
* @tc.name storage_statistics_test_get_bundle_stat_async_004
* @tc.desc Test getBundleStats() interfaces, the parameter packagename does not exist, returning error results.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it("storage_statistics_test_get_bundle_stat_async_004", 0, async function (done) {
try {
let bundleStat = await storageStatistics.getBundleStats("id", "");
expect(bundleStat != null).assertTrue();
expect(bundleStat.appSize == 0).assertTrue();
expect(bundleStat.cacheSize == 0).assertTrue();
expect(bundleStat.dataSize == 0).assertTrue();
console.log(`async_004 bundleStat ===---=== ${JSON.stringify(bundleStat)}`);
} catch (e) {
console.log("storage_statistics_test_get_bundle_stat_async_004 has failed for " + e);
expect(!!e).assertTrue();
}
done();
});
});
{
"string": [
{
"name": "entry_MainAbility",
"value": "statistics"
},
{
"name": "mainability_description",
"value": "JS_Grid Ability"
}
]
}
\ No newline at end of file
......@@ -26,6 +26,7 @@ import {
} from "./Common";
describe("volumeManager", function () {
/**
* @tc.number SUB_DF_VOLUME_MANAGER_GET_ALL_VOLUMES_0000
* @tc.name volume_manager_test_get_all_volumes_async_000
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册