未验证 提交 3c7ed5a2 编写于 作者: O openharmony_ci 提交者: Gitee

!3518 update storage sandbox path

Merge pull request !3518 from raoxian/master
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
*/ */
import fileio from '@ohos.fileio' import fileio from '@ohos.fileio'
import featureAbility from '@ohos.ability.featureAbility';
export const FILE_CONTENT = 'hello world' export const FILE_CONTENT = 'hello world'
...@@ -32,12 +33,16 @@ export function prepareFile(fpath, content) { ...@@ -32,12 +33,16 @@ export function prepareFile(fpath, content) {
} }
} }
export function nextFileName(testName) { export async function nextFileName(testName) {
const BASE_PATH = '/data/storage/el2/base/haps/entry/cache/' let context = featureAbility.getContext();
let data = await context.getCacheDir();
let BASE_PATH = data + '/';
return BASE_PATH + testName return BASE_PATH + testName
} }
export function fileName(testName) { export async function fileName(testName) {
const BASE_PATH = '/data/storage/el2/base/haps/entry/files/' let context = featureAbility.getContext();
let data = await context.getFilesDir();
let BASE_PATH = data + '/';
return BASE_PATH + testName return BASE_PATH + testName
} }
......
...@@ -38,8 +38,8 @@ describe('FileIOError', function () { ...@@ -38,8 +38,8 @@ describe('FileIOError', function () {
* @tc.name fileio_test_error_000 * @tc.name fileio_test_error_000
* @tc.desc Function of API, Delete directories with files * @tc.desc Function of API, Delete directories with files
*/ */
it('fileio_test_error_000', 0, function () { it('fileio_test_error_000', 0, async function (done) {
let dpath = fileName('fileio_test_error_000d'); let dpath = await fileName('fileio_test_error_000d');
let fpath = dpath + '/fileio_test_error_000f'; let fpath = dpath + '/fileio_test_error_000f';
fileio.mkdirSync(dpath); fileio.mkdirSync(dpath);
expect(prepareFile(fpath, 'hello')).assertTrue(); expect(prepareFile(fpath, 'hello')).assertTrue();
...@@ -49,10 +49,11 @@ describe('FileIOError', function () { ...@@ -49,10 +49,11 @@ describe('FileIOError', function () {
fileio.rmdirSync(dpath); fileio.rmdirSync(dpath);
} }
catch (err) { catch (err) {
console.log('fileio_test_error_000 has failed for ' + err); console.info('fileio_test_error_000 has failed for ' + err);
expect(isInclude(err.message, 'Directory not empty')).assertTrue(); expect(isInclude(err.message, 'Directory not empty')).assertTrue();
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
fileio.rmdirSync(dpath); fileio.rmdirSync(dpath);
done();
} }
}); });
...@@ -61,8 +62,8 @@ describe('FileIOError', function () { ...@@ -61,8 +62,8 @@ describe('FileIOError', function () {
* @tc.name fileio_test_error_001 * @tc.name fileio_test_error_001
* @tc.desc Function of API, delete file * @tc.desc Function of API, delete file
*/ */
it('fileio_test_error_001', 0, function () { it('fileio_test_error_001', 0, async function (done) {
let fpath = fileName('fileio_test_error_001f'); let fpath = await fileName('fileio_test_error_001f');
expect(prepareFile(fpath, 'hello')).assertTrue(); expect(prepareFile(fpath, 'hello')).assertTrue();
try { try {
let fd = fileio.openSync(fpath); let fd = fileio.openSync(fpath);
...@@ -71,9 +72,10 @@ describe('FileIOError', function () { ...@@ -71,9 +72,10 @@ describe('FileIOError', function () {
expect(null).assertFail(); expect(null).assertFail();
} }
catch (err) { catch (err) {
console.log('fileio_test_error_001 has failed for ' + err); console.info('fileio_test_error_001 has failed for ' + err);
expect(isInclude(err.message, 'Not a directory')).assertTrue(); expect(isInclude(err.message, 'Not a directory')).assertTrue();
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
done();
} }
}); });
...@@ -82,17 +84,18 @@ describe('FileIOError', function () { ...@@ -82,17 +84,18 @@ describe('FileIOError', function () {
* @tc.name fileio_test_error_002 * @tc.name fileio_test_error_002
* @tc.desc Function of API, flags=0o102. missing mode parameter. * @tc.desc Function of API, flags=0o102. missing mode parameter.
*/ */
it('fileio_test_error_002', 0, function () { it('fileio_test_error_002', 0, async function (done) {
let fpath = nextFileName('fileio_test_error_002'); let fpath = await nextFileName('fileio_test_error_002');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
fileio.openSync(fpath, 0o102); fileio.openSync(fpath, 0o102);
expect(null).assertFail(); expect(null).assertFail();
} }
catch (err) { catch (err) {
console.log('fileio_test_error_002 has failed for ' + err); console.info('fileio_test_error_002 has failed for ' + err);
expect(isInclude(err.message, 'called with O_CREAT/O_TMPFILE but no mode')).assertTrue(); expect(isInclude(err.message, 'called with O_CREAT/O_TMPFILE but no mode')).assertTrue();
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
done();
} }
}); });
...@@ -101,15 +104,16 @@ describe('FileIOError', function () { ...@@ -101,15 +104,16 @@ describe('FileIOError', function () {
* @tc.name fileio_test_error_003 * @tc.name fileio_test_error_003
* @tc.desc Function of API, flags=0o102, missing mode parameter. * @tc.desc Function of API, flags=0o102, missing mode parameter.
*/ */
it('fileio_test_error_003', 0, function () { it('fileio_test_error_003', 0, async function (done) {
let fpath = nextFileName('fileio_test_error_003'); let fpath = await nextFileName('fileio_test_error_003');
try { try {
fileio.openSync(fpath, 0o102); fileio.openSync(fpath, 0o102);
expect(null).assertFail(); expect(null).assertFail();
} }
catch (err) { catch (err) {
console.log('fileio_test_error_003 has failed for ' + err); console.info('fileio_test_error_003 has failed for ' + err);
expect(isInclude(err.message, 'called with O_CREAT/O_TMPFILE but no mode')).assertTrue(); expect(isInclude(err.message, 'called with O_CREAT/O_TMPFILE but no mode')).assertTrue();
done();
} }
}); });
...@@ -118,16 +122,17 @@ describe('FileIOError', function () { ...@@ -118,16 +122,17 @@ describe('FileIOError', function () {
* @tc.name fileio_test_error_004 * @tc.name fileio_test_error_004
* @tc.desc Function of API, flags=0o302. The test file is exist. * @tc.desc Function of API, flags=0o302. The test file is exist.
*/ */
it('fileio_test_error_004', 0, function () { it('fileio_test_error_004', 0, async function (done) {
let fpath = nextFileName('fileio_test_error_004'); let fpath = await nextFileName('fileio_test_error_004');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
fileio.openSync(fpath, 0o302, 0o666); fileio.openSync(fpath, 0o302, 0o666);
} }
catch (err) { catch (err) {
console.log('fileio_test_error_004 has failed for ' + err); console.info('fileio_test_error_004 has failed for ' + err);
expect(isInclude(err.message, 'File exists')).assertTrue(); expect(isInclude(err.message, 'File exists')).assertTrue();
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
done();
} }
}); });
...@@ -136,16 +141,17 @@ describe('FileIOError', function () { ...@@ -136,16 +141,17 @@ describe('FileIOError', function () {
* @tc.name fileio_test_error_005 * @tc.name fileio_test_error_005
* @tc.desc Function of API, flags=0o100002. The test file is exist. * @tc.desc Function of API, flags=0o100002. The test file is exist.
*/ */
it('fileio_test_error_005', 0, function () { it('fileio_test_error_005', 0, async function (done) {
let fpath = nextFileName('fileio_test_error_005'); let fpath = await nextFileName('fileio_test_error_005');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try { try {
fileio.openSync(fpath, 0o100002); fileio.openSync(fpath, 0o100002);
expect(null).assertFail(); expect(null).assertFail();
} }
catch (err) { catch (err) {
console.log('fileio_test_error_005 has failed for ' + err); console.info('fileio_test_error_005 has failed for ' + err);
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
done();
} }
}); });
...@@ -154,17 +160,18 @@ describe('FileIOError', function () { ...@@ -154,17 +160,18 @@ describe('FileIOError', function () {
* @tc.name fileio_test_error_006 * @tc.name fileio_test_error_006
* @tc.desc Function of API, flags=0o40002 The test file is exist. * @tc.desc Function of API, flags=0o40002 The test file is exist.
*/ */
it('fileio_test_error_006', 0, function () { it('fileio_test_error_006', 0, async function (done) {
let dpath = nextFileName('fileio_test_error_006'); let dpath = await nextFileName('fileio_test_error_006');
fileio.mkdirSync(dpath); fileio.mkdirSync(dpath);
try { try {
fileio.openSync(dpath, 0o40002); fileio.openSync(dpath, 0o40002);
expect(null).assertFail(); expect(null).assertFail();
} }
catch (err) { catch (err) {
console.log('fileio_test_error_006 has failed for ' + err); console.info('fileio_test_error_006 has failed for ' + err);
expect(isInclude(err.message, 'called with O_CREAT/O_TMPFILE but no mode')).assertTrue(); expect(isInclude(err.message, 'called with O_CREAT/O_TMPFILE but no mode')).assertTrue();
fileio.rmdirSync(dpath); fileio.rmdirSync(dpath);
done();
} }
}); });
...@@ -173,8 +180,8 @@ describe('FileIOError', function () { ...@@ -173,8 +180,8 @@ describe('FileIOError', function () {
* @tc.name fileio_test_error_007 * @tc.name fileio_test_error_007
* @tc.desc Function of API, flags=0o400002. The test file is exist. * @tc.desc Function of API, flags=0o400002. The test file is exist.
*/ */
it('fileio_test_error_007', 0, function () { it('fileio_test_error_007', 0, async function (done) {
let fpath = nextFileName('fileio_test_error_007'); let fpath = await nextFileName('fileio_test_error_007');
let txt = 'h' let txt = 'h'
expect(prepareFile(fpath, txt)).assertTrue(); expect(prepareFile(fpath, txt)).assertTrue();
try { try {
...@@ -182,8 +189,9 @@ describe('FileIOError', function () { ...@@ -182,8 +189,9 @@ describe('FileIOError', function () {
expect(null).assertFail(); expect(null).assertFail();
} }
catch (err) { catch (err) {
console.log('fileio_test_error_007 has failed for ' + err); console.info('fileio_test_error_007 has failed for ' + err);
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
done();
} }
}); });
...@@ -192,8 +200,8 @@ describe('FileIOError', function () { ...@@ -192,8 +200,8 @@ describe('FileIOError', function () {
* @tc.name fileio_test_error_008 * @tc.name fileio_test_error_008
* @tc.desc Function of API, flags=0o400002. The test file is exist. * @tc.desc Function of API, flags=0o400002. The test file is exist.
*/ */
it('fileio_test_error_008', 0, function () { it('fileio_test_error_008', 0, async function (done) {
let fpath = nextFileName('fileio_test_error_008'); let fpath = await nextFileName('fileio_test_error_008');
let txt = randomString(5000); let txt = randomString(5000);
expect(prepareFile(fpath, txt)).assertTrue(); expect(prepareFile(fpath, txt)).assertTrue();
try { try {
...@@ -201,8 +209,9 @@ describe('FileIOError', function () { ...@@ -201,8 +209,9 @@ describe('FileIOError', function () {
expect(null).assertFail(); expect(null).assertFail();
} }
catch (err) { catch (err) {
console.log('fileio_test_error_008 has failed for ' + err); console.info('fileio_test_error_008 has failed for ' + err);
fileio.unlinkSync(fpath); fileio.unlinkSync(fpath);
done();
} }
}); });
...@@ -211,15 +220,16 @@ describe('FileIOError', function () { ...@@ -211,15 +220,16 @@ describe('FileIOError', function () {
* @tc.name fileio_test_error_009 * @tc.name fileio_test_error_009
* @tc.desc Function of API, flags=0o10000102. The test file is exist. * @tc.desc Function of API, flags=0o10000102. The test file is exist.
*/ */
it('fileio_test_error_009', 0, function () { it('fileio_test_error_009', 0, async function (done) {
let fpath = nextFileName('fileio_test_error_009'); let fpath = await nextFileName('fileio_test_error_009');
try { try {
fileio.openSync(fpath, 0o10000102); fileio.openSync(fpath, 0o10000102);
expect(null).assertFail(); expect(null).assertFail();
} }
catch (err) { catch (err) {
console.log('fileio_test_error_009 has failed for ' + err); console.info('fileio_test_error_009 has failed for ' + err);
expect(isInclude(err.message, 'called with O_CREAT/O_TMPFILE but no mode')).assertTrue(); expect(isInclude(err.message, 'called with O_CREAT/O_TMPFILE but no mode')).assertTrue();
done();
} }
}); });
...@@ -228,17 +238,18 @@ describe('FileIOError', function () { ...@@ -228,17 +238,18 @@ describe('FileIOError', function () {
* @tc.name fileio_test_error_010 * @tc.name fileio_test_error_010
* @tc.desc Function of API, flags=0o200000. Invalid argument. * @tc.desc Function of API, flags=0o200000. Invalid argument.
*/ */
it('fileio_test_error_010', 0, function () { it('fileio_test_error_010', 0, async function (done) {
let dpath = fileName('fileio_test_error_010d'); let dpath = await fileName('fileio_test_error_010d');
fileio.mkdirSync(dpath); fileio.mkdirSync(dpath);
try { try {
fileio.openSync(dpath, 0o200000); fileio.openSync(dpath, 0o200000);
expect(null).assertFail(); expect(null).assertFail();
} }
catch (err) { catch (err) {
console.log('fileio_test_error_010 has failed for ' + err); console.info('fileio_test_error_010 has failed for ' + err);
expect(isInclude(err.message, 'Invalid argument')).assertTrue(); expect(isInclude(err.message, 'Invalid argument')).assertTrue();
fileio.rmdirSync(dpath); fileio.rmdirSync(dpath);
done();
} }
}); });
......
...@@ -19,7 +19,7 @@ import featureAbility from '@ohos.ability.featureAbility'; ...@@ -19,7 +19,7 @@ import featureAbility from '@ohos.ability.featureAbility';
export const FILE_CONTENT = 'hello world'; export const FILE_CONTENT = 'hello world';
import { import {
describe, beforeAll, beforeEach, afterEach, afterAll, it, expect describe, it, expect
} }
from 'deccjsunit/index' from 'deccjsunit/index'
...@@ -77,8 +77,8 @@ export function fileToWriteOnly(fpath) { ...@@ -77,8 +77,8 @@ export function fileToWriteOnly(fpath) {
export async function nextFileName(testName) { export async function nextFileName(testName) {
let context = featureAbility.getContext(); let context = featureAbility.getContext();
let data = await context.getFilesDir(); let data = await context.getCacheDir();
let BASE_PATH = data.substring(0, data.length - 5) + 'cache/'; let BASE_PATH = data + '/';
return BASE_PATH + testName + '_' + randomString(testName.length); return BASE_PATH + testName + '_' + randomString(testName.length);
} }
export async function fileName(testName) { export async function fileName(testName) {
...@@ -126,10 +126,6 @@ export { ...@@ -126,10 +126,6 @@ export {
isString, isString,
isBoolean, isBoolean,
describe, describe,
beforeAll,
beforeEach,
afterEach,
afterAll,
it, it,
expect expect
}; };
\ No newline at end of file
...@@ -19,7 +19,7 @@ import featureAbility from '@ohos.ability.featureAbility' ...@@ -19,7 +19,7 @@ import featureAbility from '@ohos.ability.featureAbility'
export const FILE_CONTENT = 'hello world'; export const FILE_CONTENT = 'hello world';
import { import {
describe, beforeAll, beforeEach, afterEach, afterAll, it, expect describe, it, expect
} }
from 'deccjsunit/index' from 'deccjsunit/index'
...@@ -51,8 +51,8 @@ export function prepareEmptyFile(fpath) { ...@@ -51,8 +51,8 @@ export function prepareEmptyFile(fpath) {
export async function nextFileName(testName) { export async function nextFileName(testName) {
var context = featureAbility.getContext(); var context = featureAbility.getContext();
let data = await context.getFilesDir(); let data = await context.getCacheDir();
let BASE_PATH = data.substring(0, data.length - 5) + 'cache/'; let BASE_PATH = data + '/';
return BASE_PATH + testName return BASE_PATH + testName
} }
export async function fileName(testName) { export async function fileName(testName) {
...@@ -91,10 +91,6 @@ export function randomString(num) { ...@@ -91,10 +91,6 @@ export function randomString(num) {
export { export {
fileio, fileio,
describe, describe,
beforeAll,
beforeEach,
afterEach,
afterAll,
it, it,
expect expect
}; };
\ No newline at end of file
...@@ -17,10 +17,6 @@ import fileio from '@ohos.fileio'; ...@@ -17,10 +17,6 @@ import fileio from '@ohos.fileio';
import file from '@system.file'; import file from '@system.file';
import { import {
describe, describe,
beforeAll,
beforeEach,
afterEach,
afterAll,
it, it,
expect expect
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册