From b7738f91800ccf72148ac4eb74244cb08fd403e5 Mon Sep 17 00:00:00 2001 From: raoxian Date: Fri, 10 Jun 2022 15:46:18 +0800 Subject: [PATCH] update storage sandbox path Signed-off-by: raoxian --- .../src/main/js/default/test/Common.js | 13 +- .../main/js/default/test/FileIOError.test.js | 99 ++++--- .../src/main/js/default/test/Common.js | 10 +- .../main/js/default/test/FileIOStream.test.js | 261 +++++++++++------- .../src/main/js/default/test/Common.js | 10 +- .../src/main/js/default/test/File.test.js | 4 - 6 files changed, 233 insertions(+), 164 deletions(-) diff --git a/storage/storagefileioerrorjstest/src/main/js/default/test/Common.js b/storage/storagefileioerrorjstest/src/main/js/default/test/Common.js index 7dea1745f..6c75b7050 100644 --- a/storage/storagefileioerrorjstest/src/main/js/default/test/Common.js +++ b/storage/storagefileioerrorjstest/src/main/js/default/test/Common.js @@ -14,6 +14,7 @@ */ import fileio from '@ohos.fileio' +import featureAbility from '@ohos.ability.featureAbility'; export const FILE_CONTENT = 'hello world' @@ -32,12 +33,16 @@ export function prepareFile(fpath, content) { } } -export function nextFileName(testName) { - const BASE_PATH = '/data/storage/el2/base/haps/entry/cache/' +export async function nextFileName(testName) { + let context = featureAbility.getContext(); + let data = await context.getCacheDir(); + let BASE_PATH = data + '/'; return BASE_PATH + testName } -export function fileName(testName) { - const BASE_PATH = '/data/storage/el2/base/haps/entry/files/' +export async function fileName(testName) { + let context = featureAbility.getContext(); + let data = await context.getFilesDir(); + let BASE_PATH = data + '/'; return BASE_PATH + testName } diff --git a/storage/storagefileioerrorjstest/src/main/js/default/test/FileIOError.test.js b/storage/storagefileioerrorjstest/src/main/js/default/test/FileIOError.test.js index 55b470f9a..4da75ac4d 100644 --- a/storage/storagefileioerrorjstest/src/main/js/default/test/FileIOError.test.js +++ b/storage/storagefileioerrorjstest/src/main/js/default/test/FileIOError.test.js @@ -38,8 +38,8 @@ describe('FileIOError', function () { * @tc.name fileio_test_error_000 * @tc.desc Function of API, Delete directories with files */ - it('fileio_test_error_000', 0, function () { - let dpath = fileName('fileio_test_error_000d'); + it('fileio_test_error_000', 0, async function (done) { + let dpath = await fileName('fileio_test_error_000d'); let fpath = dpath + '/fileio_test_error_000f'; fileio.mkdirSync(dpath); expect(prepareFile(fpath, 'hello')).assertTrue(); @@ -47,12 +47,13 @@ describe('FileIOError', function () { let fd = fileio.openSync(dpath); expect(isIntNum(fd)).assertTrue(); fileio.rmdirSync(dpath); - } + } 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(); fileio.unlinkSync(fpath); fileio.rmdirSync(dpath); + done(); } }); @@ -61,19 +62,20 @@ describe('FileIOError', function () { * @tc.name fileio_test_error_001 * @tc.desc Function of API, delete file */ - it('fileio_test_error_001', 0, function () { - let fpath = fileName('fileio_test_error_001f'); + it('fileio_test_error_001', 0, async function (done) { + let fpath = await fileName('fileio_test_error_001f'); expect(prepareFile(fpath, 'hello')).assertTrue(); try { let fd = fileio.openSync(fpath); expect(isIntNum(fd)).assertTrue(); fileio.rmdirSync(fpath); expect(null).assertFail(); - } + } 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(); fileio.unlinkSync(fpath); + done(); } }); @@ -82,17 +84,18 @@ describe('FileIOError', function () { * @tc.name fileio_test_error_002 * @tc.desc Function of API, flags=0o102. missing mode parameter. */ - it('fileio_test_error_002', 0, function () { - let fpath = nextFileName('fileio_test_error_002'); + it('fileio_test_error_002', 0, async function (done) { + let fpath = await nextFileName('fileio_test_error_002'); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { fileio.openSync(fpath, 0o102); expect(null).assertFail(); - } + } 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(); fileio.unlinkSync(fpath); + done(); } }); @@ -101,15 +104,16 @@ describe('FileIOError', function () { * @tc.name fileio_test_error_003 * @tc.desc Function of API, flags=0o102, missing mode parameter. */ - it('fileio_test_error_003', 0, function () { - let fpath = nextFileName('fileio_test_error_003'); + it('fileio_test_error_003', 0, async function (done) { + let fpath = await nextFileName('fileio_test_error_003'); try { fileio.openSync(fpath, 0o102); expect(null).assertFail(); - } + } 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(); + done(); } }); @@ -118,16 +122,17 @@ describe('FileIOError', function () { * @tc.name fileio_test_error_004 * @tc.desc Function of API, flags=0o302. The test file is exist. */ - it('fileio_test_error_004', 0, function () { - let fpath = nextFileName('fileio_test_error_004'); + it('fileio_test_error_004', 0, async function (done) { + let fpath = await nextFileName('fileio_test_error_004'); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { fileio.openSync(fpath, 0o302, 0o666); - } + } 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(); fileio.unlinkSync(fpath); + done(); } }); @@ -136,16 +141,17 @@ describe('FileIOError', function () { * @tc.name fileio_test_error_005 * @tc.desc Function of API, flags=0o100002. The test file is exist. */ - it('fileio_test_error_005', 0, function () { - let fpath = nextFileName('fileio_test_error_005'); + it('fileio_test_error_005', 0, async function (done) { + let fpath = await nextFileName('fileio_test_error_005'); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); try { fileio.openSync(fpath, 0o100002); expect(null).assertFail(); - } + } 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); + done(); } }); @@ -154,17 +160,18 @@ describe('FileIOError', function () { * @tc.name fileio_test_error_006 * @tc.desc Function of API, flags=0o40002 The test file is exist. */ - it('fileio_test_error_006', 0, function () { - let dpath = nextFileName('fileio_test_error_006'); + it('fileio_test_error_006', 0, async function (done) { + let dpath = await nextFileName('fileio_test_error_006'); fileio.mkdirSync(dpath); try { fileio.openSync(dpath, 0o40002); expect(null).assertFail(); - } + } 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(); fileio.rmdirSync(dpath); + done(); } }); @@ -173,17 +180,18 @@ describe('FileIOError', function () { * @tc.name fileio_test_error_007 * @tc.desc Function of API, flags=0o400002. The test file is exist. */ - it('fileio_test_error_007', 0, function () { - let fpath = nextFileName('fileio_test_error_007'); + it('fileio_test_error_007', 0, async function (done) { + let fpath = await nextFileName('fileio_test_error_007'); let txt = 'h' expect(prepareFile(fpath, txt)).assertTrue(); try { fileio.openSync(fpath, 0o400002); expect(null).assertFail(); - } + } 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); + done(); } }); @@ -192,17 +200,18 @@ describe('FileIOError', function () { * @tc.name fileio_test_error_008 * @tc.desc Function of API, flags=0o400002. The test file is exist. */ - it('fileio_test_error_008', 0, function () { - let fpath = nextFileName('fileio_test_error_008'); + it('fileio_test_error_008', 0, async function (done) { + let fpath = await nextFileName('fileio_test_error_008'); let txt = randomString(5000); expect(prepareFile(fpath, txt)).assertTrue(); try { fileio.openSync(fpath, 0o400002); expect(null).assertFail(); - } + } 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); + done(); } }); @@ -211,15 +220,16 @@ describe('FileIOError', function () { * @tc.name fileio_test_error_009 * @tc.desc Function of API, flags=0o10000102. The test file is exist. */ - it('fileio_test_error_009', 0, function () { - let fpath = nextFileName('fileio_test_error_009'); + it('fileio_test_error_009', 0, async function (done) { + let fpath = await nextFileName('fileio_test_error_009'); try { fileio.openSync(fpath, 0o10000102); expect(null).assertFail(); - } + } 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(); + done(); } }); @@ -228,17 +238,18 @@ describe('FileIOError', function () { * @tc.name fileio_test_error_010 * @tc.desc Function of API, flags=0o200000. Invalid argument. */ - it('fileio_test_error_010', 0, function () { - let dpath = fileName('fileio_test_error_010d'); + it('fileio_test_error_010', 0, async function (done) { + let dpath = await fileName('fileio_test_error_010d'); fileio.mkdirSync(dpath); try { fileio.openSync(dpath, 0o200000); expect(null).assertFail(); - } + } 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(); fileio.rmdirSync(dpath); + done(); } }); diff --git a/storage/storagefileiojstest/src/main/js/default/test/Common.js b/storage/storagefileiojstest/src/main/js/default/test/Common.js index 938e574c2..df933b5f7 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/Common.js +++ b/storage/storagefileiojstest/src/main/js/default/test/Common.js @@ -19,7 +19,7 @@ import featureAbility from '@ohos.ability.featureAbility'; export const FILE_CONTENT = 'hello world'; import { - describe, beforeAll, beforeEach, afterEach, afterAll, it, expect + describe, it, expect } from 'deccjsunit/index' @@ -77,8 +77,8 @@ export function fileToWriteOnly(fpath) { export async function nextFileName(testName) { let context = featureAbility.getContext(); - let data = await context.getFilesDir(); - let BASE_PATH = data.substring(0, data.length - 5) + 'cache/'; + let data = await context.getCacheDir(); + let BASE_PATH = data + '/'; return BASE_PATH + testName + '_' + randomString(testName.length); } export async function fileName(testName) { @@ -126,10 +126,6 @@ export { isString, isBoolean, describe, - beforeAll, - beforeEach, - afterEach, - afterAll, it, expect }; \ No newline at end of file diff --git a/storage/storagefileiojstest/src/main/js/default/test/FileIOStream.test.js b/storage/storagefileiojstest/src/main/js/default/test/FileIOStream.test.js index 8d7956715..64f02c724 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/FileIOStream.test.js +++ b/storage/storagefileiojstest/src/main/js/default/test/FileIOStream.test.js @@ -42,10 +42,10 @@ describe('fileIOTestStream', function () { expect(ss !== null).assertTrue(); ss.closeSync(); fileio.unlinkSync(fpath); - console.log('fileio_test_stream_create_stream_sync_000 is passed!'); + console.info('fileio_test_stream_create_stream_sync_000 is passed!'); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_000 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_000 has failed for ' + e); expect(null).assertFail(); } }); @@ -62,7 +62,7 @@ describe('fileIOTestStream', function () { expect(null).assertFail(); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_001 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_001 has failed for ' + e); } }); @@ -90,7 +90,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_002 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_002 has failed for ' + e); expect(null).assertFail(); } }); @@ -109,7 +109,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_003 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_003 has failed for ' + e); expect(null).assertFail(); } }); @@ -138,7 +138,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_004 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_004 has failed for ' + e); expect(null).assertFail(); } }); @@ -157,7 +157,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_005 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_005 has failed for ' + e); expect(null).assertFail(); } }); @@ -177,7 +177,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_006 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_006 has failed for ' + e); expect(null).assertFail(); } }); @@ -194,7 +194,8 @@ describe('fileIOTestStream', function () { expect(null).assertFail(); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_007 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_007 has failed for ' + e); + expect(e.message == 'No such file or directory').assertTrue(); } }); @@ -221,7 +222,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_008 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_008 has failed for ' + e); expect(null).assertFail(); } }); @@ -240,7 +241,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_009 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_009 has failed for ' + e); expect(null).assertFail(); } }); @@ -268,7 +269,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_010 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_010 has failed for ' + e); expect(null).assertFail(); } }); @@ -287,7 +288,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_011 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_011 has failed for ' + e); expect(null).assertFail(); } }); @@ -295,7 +296,7 @@ describe('fileIOTestStream', function () { /** * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_1200 * @tc.name fileio_test_stream_create_stream_sync_012 - * @tc.desc Function of API, mode = ab. The test file is exist. + * @tc.desc Function of API, mode = rb. The test file is exist. */ it('fileio_test_stream_create_stream_sync_012', 0, async function () { let fpath = await nextFileName('fileio_test_stream_create_stream_sync_012'); @@ -308,7 +309,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_012 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_012 has failed for ' + e); expect(null).assertFail(); } }); @@ -325,7 +326,8 @@ describe('fileIOTestStream', function () { expect(null).assertFail(); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_013 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_013 has failed for ' + e); + expect(e.message == 'No such file or directory').assertTrue(); } }); @@ -353,7 +355,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_014 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_014 has failed for ' + e); expect(null).assertFail(); } }); @@ -372,7 +374,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_015 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_015 has failed for ' + e); expect(null).assertFail(); } }); @@ -399,10 +401,10 @@ describe('fileIOTestStream', function () { expect(rlen == text.length + 1).assertTrue(); ss.closeSync(); fileio.unlinkSync(fpath); - console.log('fileio_test_stream_create_stream_sync_016 is passed!'); + console.info('fileio_test_stream_create_stream_sync_016 is passed!'); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_016 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_016 has failed for ' + e); expect(null).assertFail(); } }); @@ -421,7 +423,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_017 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_017 has failed for ' + e); expect(null).assertFail(); } }); @@ -441,7 +443,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_018 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_018 has failed for ' + e); expect(null).assertFail(); } }); @@ -458,7 +460,8 @@ describe('fileIOTestStream', function () { expect(null).assertFail(); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_019 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_019 has failed for ' + e); + expect(e.message == 'No such file or directory').assertTrue(); } }); @@ -485,7 +488,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_020 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_020 has failed for ' + e); expect(null).assertFail(); } }); @@ -504,7 +507,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_021 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_021 has failed for ' + e); expect(null).assertFail(); } }); @@ -532,7 +535,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_022 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_022 has failed for ' + e); expect(null).assertFail(); } }); @@ -551,7 +554,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_023 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_023 has failed for ' + e); expect(null).assertFail(); } }); @@ -567,7 +570,8 @@ describe('fileIOTestStream', function () { expect(null).assertFail(); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_024 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_024 has failed for ' + e); + expect(e.message == 'No such file or directory').assertTrue(); } }); @@ -584,7 +588,7 @@ describe('fileIOTestStream', function () { expect(null).assertFail(); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_025 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_025 has failed for ' + e); fileio.unlinkSync(fpath); } }); @@ -628,7 +632,7 @@ describe('fileIOTestStream', function () { expect(null).assertFail(); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_027 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_027 has failed for ' + e); } }); @@ -637,7 +641,7 @@ describe('fileIOTestStream', function () { * @tc.name fileio_test_stream_create_stream_sync_028 * @tc.desc Function of API, path too deep. */ - it('fileio_test_stream_create_stream_sync_028', 0, async function () { + it('fileio_test_stream_create_stream_sync_028', 0, async function () { let dpath = await nextFileName('fileio_test_stream_create_stream_sync_028'); fileio.mkdirSync(dpath); try { @@ -671,7 +675,58 @@ describe('fileIOTestStream', function () { expect(null).assertFail(); } catch (e) { - console.log('fileio_test_stream_create_stream_sync_029 has failed for ' + e); + console.info('fileio_test_stream_create_stream_sync_029 has failed for ' + e); + expect(e.message == 'No such file or directory').assertTrue(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_3000 + * @tc.name fileio_test_stream_create_stream_sync_030 + * @tc.desc Function of API, mode = w+. Test file length is cleared to 0. + */ + it('fileio_test_stream_create_stream_sync_030', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_030'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + let buf = new ArrayBuffer(4096); + let number = fileio.readSync(fd, buf); + expect(number == 11).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'w+'); + let num = ss.readSync(buf); + expect(num == 0).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_030 has failed for ' + e); + expect(null).assertFail(); + } + }); + + /** + * @tc.number SUB_STORAGE_FileIO_stream_CreateStreamSync_3100 + * @tc.name fileio_test_stream_create_stream_sync_031 + * @tc.desc Function of API, mode = w. Test file length is cleared to 0. + */ + it('fileio_test_stream_create_stream_sync_031', 0, async function () { + let fpath = await nextFileName('fileio_test_stream_create_stream_sync_031'); + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); + try { + let fd = fileio.openSync(fpath, 0o102, 0o666); + let buf = new ArrayBuffer(4096); + let number = fileio.readSync(fd, buf); + expect(number == 11).assertTrue(); + let ss = fileio.createStreamSync(fpath, 'w'); + let num = fileio.readSync(fd, buf); + expect(num == 0).assertTrue(); + ss.closeSync(); + fileio.unlinkSync(fpath); + } + catch (e) { + console.info('fileio_test_stream_create_stream_sync_031 has failed for ' + e); + expect(null).assertFail(); } }); @@ -692,7 +747,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_fdopen_stream_sync_000 has failed for ' + e); + console.info('fileio_test_stream_fdopen_stream_sync_000 has failed for ' + e); expect(null).assertFail(); } }); @@ -705,12 +760,12 @@ describe('fileIOTestStream', function () { it('fileio_test_stream_fdopen_stream_sync_001', 0, function () { try { let fd = -1; - let mode = 'r+'; + let mode = 'r'; fileio.fdopenStreamSync(fd, mode); expect(null).assertFail(); } catch (e) { - console.log('fileio_test_stream_fdopen_stream_sync_001 has failed for ' + e); + console.info('fileio_test_stream_fdopen_stream_sync_001 has failed for ' + e); } }); @@ -741,7 +796,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_fdopen_stream_sync_002 has failed for ' + e); + console.info('fileio_test_stream_fdopen_stream_sync_002 has failed for ' + e); expect(null).assertFail(); } }); @@ -761,7 +816,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_fdopen_stream_sync_003 has failed for ' + e); + console.info('fileio_test_stream_fdopen_stream_sync_003 has failed for ' + e); expect(null).assertFail(); } }); @@ -792,7 +847,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_fdopen_stream_sync_004 has failed for ' + e); + console.info('fileio_test_stream_fdopen_stream_sync_004 has failed for ' + e); expect(null).assertFail(); } }); @@ -812,7 +867,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_fdopen_stream_sync_005 has failed for ' + e); + console.info('fileio_test_stream_fdopen_stream_sync_005 has failed for ' + e); expect(null).assertFail(); } }); @@ -833,7 +888,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_fdopen_stream_sync_006 has failed for ' + e); + console.info('fileio_test_stream_fdopen_stream_sync_006 has failed for ' + e); expect(null).assertFail(); } }); @@ -849,7 +904,7 @@ describe('fileIOTestStream', function () { expect(null).assertFail(); } catch (e) { - console.log('fileio_test_stream_fdopen_stream_sync_007 has failed for ' + e); + console.info('fileio_test_stream_fdopen_stream_sync_007 has failed for ' + e); } }); @@ -878,7 +933,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_fdopen_stream_sync_008 has failed for ' + e); + console.info('fileio_test_stream_fdopen_stream_sync_008 has failed for ' + e); expect(null).assertFail(); } }); @@ -898,7 +953,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_fdopen_stream_sync_009 has failed for ' + e); + console.info('fileio_test_stream_fdopen_stream_sync_009 has failed for ' + e); expect(null).assertFail(); } }); @@ -928,7 +983,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_fdopen_stream_sync_010 has failed for ' + e); + console.info('fileio_test_stream_fdopen_stream_sync_010 has failed for ' + e); expect(null).assertFail(); } }); @@ -948,7 +1003,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_fdopen_stream_sync_011 has failed for ' + e); + console.info('fileio_test_stream_fdopen_stream_sync_011 has failed for ' + e); expect(null).assertFail(); } }); @@ -970,7 +1025,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_fdopen_stream_sync_012 has failed for ' + e); + console.info('fileio_test_stream_fdopen_stream_sync_012 has failed for ' + e); expect(null).assertFail(); } }); @@ -986,7 +1041,7 @@ describe('fileIOTestStream', function () { expect(null).assertFail(); } catch (e) { - console.log('fileio_test_stream_fdopen_stream_sync_013 has failed for ' + e); + console.info('fileio_test_stream_fdopen_stream_sync_013 has failed for ' + e); } }); @@ -1016,7 +1071,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_fdopen_stream_sync_014 has failed for ' + e); + console.info('fileio_test_stream_fdopen_stream_sync_014 has failed for ' + e); expect(null).assertFail(); } }); @@ -1036,7 +1091,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_fdopen_stream_sync_015 has failed for ' + e); + console.info('fileio_test_stream_fdopen_stream_sync_015 has failed for ' + e); expect(null).assertFail(); } }); @@ -1067,7 +1122,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_fdopen_stream_sync_016 has failed for ' + e); + console.info('fileio_test_stream_fdopen_stream_sync_016 has failed for ' + e); expect(null).assertFail(); } }); @@ -1087,7 +1142,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_fdopen_stream_sync_017 has failed for ' + e); + console.info('fileio_test_stream_fdopen_stream_sync_017 has failed for ' + e); expect(null).assertFail(); } }); @@ -1108,7 +1163,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_fdopen_stream_sync_018 has failed for ' + e); + console.info('fileio_test_stream_fdopen_stream_sync_018 has failed for ' + e); expect(null).assertFail(); } }); @@ -1124,7 +1179,7 @@ describe('fileIOTestStream', function () { expect(null).assertFail(); } catch (e) { - console.log('fileio_test_stream_fdopen_stream_sync_019 has failed for ' + e); + console.info('fileio_test_stream_fdopen_stream_sync_019 has failed for ' + e); } }); @@ -1153,7 +1208,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_fdopen_stream_sync_020 has failed for ' + e); + console.info('fileio_test_stream_fdopen_stream_sync_020 has failed for ' + e); expect(null).assertFail(); } }); @@ -1173,7 +1228,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_fdopen_stream_sync_021 has failed for ' + e); + console.info('fileio_test_stream_fdopen_stream_sync_021 has failed for ' + e); expect(null).assertFail(); } }); @@ -1203,7 +1258,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_fdopen_stream_sync_022 has failed for ' + e); + console.info('fileio_test_stream_fdopen_stream_sync_022 has failed for ' + e); expect(null).assertFail(); } }); @@ -1223,7 +1278,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_fdopen_stream_sync_023 has failed for ' + e); + console.info('fileio_test_stream_fdopen_stream_sync_023 has failed for ' + e); expect(null).assertFail(); } }); @@ -1239,7 +1294,8 @@ describe('fileIOTestStream', function () { expect(null).assertFail(); } catch (e) { - console.log('fileio_test_stream_fdopen_stream_sync_024 has failed for ' + e); + console.info('fileio_test_stream_fdopen_stream_sync_024 has failed for ' + e); + expect(e.message == 'Arg fd is required to be type integer').assertTrue(); } }); @@ -1257,7 +1313,7 @@ describe('fileIOTestStream', function () { expect(null).assertFail(); } catch (e) { - console.log('fileio_test_stream_fdopen_stream_sync_025 has failed for ' + e); + console.info('fileio_test_stream_fdopen_stream_sync_025 has failed for ' + e); fileio.unlinkSync(fpath); } }); @@ -1280,7 +1336,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_read_sync_000 has failed for ' + e); + console.info('fileio_test_stream_read_sync_000 has failed for ' + e); expect(null).assertFail(); } }); @@ -1305,7 +1361,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_read_sync_001 has failed for ' + e); + console.info('fileio_test_stream_read_sync_001 has failed for ' + e); expect(null).assertFail(); } }); @@ -1330,7 +1386,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_read_sync_002 has failed for ' + e); + console.info('fileio_test_stream_read_sync_002 has failed for ' + e); expect(null).assertFail(); } }); @@ -1354,7 +1410,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_read_sync_003 has failed for ' + e); + console.info('fileio_test_stream_read_sync_003 has failed for ' + e); expect(null).assertFail(); } }); @@ -1375,7 +1431,8 @@ describe('fileIOTestStream', function () { expect(null).assertFail(); } catch (e) { - console.log('fileio_test_stream_read_sync_004 has failed for ' + e); + console.info('fileio_test_stream_read_sync_004 has failed for ' + e); + expect(e.message == 'Invalid read buffer, expect arraybuffer').assertTrue(); ss.closeSync(); fileio.unlinkSync(fpath); } @@ -1423,7 +1480,8 @@ describe('fileIOTestStream', function () { expect(null).assertFail(); } catch (e) { - console.log('fileio_test_stream_read_sync_006 has failed for ' + e); + console.info('fileio_test_stream_read_sync_006 has failed for ' + e); + expect(e.message == 'Invalid option.offset, positive integer is desired').assertTrue(); ss.closeSync(); fileio.unlinkSync(fpath); } @@ -1444,10 +1502,10 @@ describe('fileIOTestStream', function () { expect(ss.writeSync(text) == text.length).assertTrue(); ss.closeSync(); fileio.unlinkSync(fpath); - console.log('---fileio_test_stream_write_sync_000 is passed!'); + console.info('---fileio_test_stream_write_sync_000 is passed!'); } catch (e) { - console.log('fileio_test_stream_write_sync_000 has failed for ' + e); + console.info('fileio_test_stream_write_sync_000 has failed for ' + e); expect(null).assertFail(); } }); @@ -1464,13 +1522,14 @@ describe('fileIOTestStream', function () { try { ss = fileio.createStreamSync(fpath, 'w+'); expect(ss !== null).assertTrue(); - expect(ss.writeSync(FILE_CONTENT, { + ss.writeSync(FILE_CONTENT, { encoding: 'ASCII' - }) !== null).assertTrue(); + }) expect(null).assertFail(); } catch (e) { - console.log('fileio_test_stream_write_sync_001 has failed for ' + e); + console.info('fileio_test_stream_write_sync_001 has failed for ' + e); + expect(e.message == 'Illegal write buffer or encoding').assertTrue(); ss.closeSync(); fileio.unlinkSync(fpath); } @@ -1500,7 +1559,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_write_sync_002 has failed for ' + e); + console.info('fileio_test_stream_write_sync_002 has failed for ' + e); expect(null).assertFail(); } }); @@ -1529,7 +1588,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_write_sync_003 has failed for ' + e); + console.info('fileio_test_stream_write_sync_003 has failed for ' + e); expect(null).assertFail(); } }); @@ -1556,7 +1615,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_write_sync_004 has failed for ' + e); + console.info('fileio_test_stream_write_sync_004 has failed for ' + e); expect(null).assertFail(); } }); @@ -1575,9 +1634,9 @@ describe('fileIOTestStream', function () { for (let i = 0; i < encodingArray.length; i++) { let ss = fileio.createStreamSync(fpath, 'w+'); expect(ss !== null).assertTrue(); - expect(ss.writeSync(writeStrArray[i], { + ss.writeSync(writeStrArray[i], { encoding: encodingArray[i] - }) !== null).assertTrue(); + }) ss.closeSync(); ss = fileio.createStreamSync(fpath, 'r+'); let rlen = ss.readSync(new ArrayBuffer(4096)); @@ -1587,7 +1646,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_write_sync_005 has failed for ' + e); + console.info('fileio_test_stream_write_sync_005 has failed for ' + e); expect(null).assertFail(); } }); @@ -1618,7 +1677,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_write_sync_006 has failed for ' + e); + console.info('fileio_test_stream_write_sync_006 has failed for ' + e); expect(null).assertFail(); } }); @@ -1649,7 +1708,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_write_sync_007 has failed for ' + e); + console.info('fileio_test_stream_write_sync_007 has failed for ' + e); expect(null).assertFail(); } }); @@ -1678,7 +1737,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_write_sync_008 has failed for ' + e); + console.info('fileio_test_stream_write_sync_008 has failed for ' + e); expect(null).assertFail(); } }); @@ -1698,8 +1757,9 @@ describe('fileIOTestStream', function () { expect(null).assertFail(); } catch (e) { + console.info('fileio_test_stream_write_sync_009 has failed for ' + e); + expect(e.message == 'Illegal write buffer or encoding').assertTrue(); fileio.unlinkSync(fpath); - console.log('fileio_test_stream_write_sync_009 has failed for ' + e); } }); @@ -1714,13 +1774,14 @@ describe('fileIOTestStream', function () { try { var ss = fileio.createStreamSync(fpath, 'r+'); expect(ss !== null).assertTrue(); - expect(ss.writeSync(FILE_CONTENT, { + ss.writeSync(FILE_CONTENT, { encoding: '' - }) == null).assertTrue(); + }) expect(null).assertFail(); } catch (e) { - console.log('fileio_test_stream_write_sync_010 has failed for ' + e); + console.info('fileio_test_stream_write_sync_010 has failed for ' + e); + expect(e.message == 'Illegal write buffer or encoding').assertTrue(); ss.closeSync(); fileio.unlinkSync(fpath); } @@ -1737,13 +1798,14 @@ describe('fileIOTestStream', function () { try { var ss = fileio.createStreamSync(fpath, 'r+'); expect(ss !== null).assertTrue(); - expect(ss.writeSync(FILE_CONTENT, { + ss.writeSync(FILE_CONTENT, { position: -1 - }) == null).assertTrue(); + }) expect(null).assertFail(); } catch (e) { - console.log('fileio_test_stream_write_sync_011 has failed for ' + e); + console.info('fileio_test_stream_write_sync_011 has failed for ' + e); + expect(e.message == 'option.position shall be positive number').assertTrue(); ss.closeSync(); fileio.unlinkSync(fpath); } @@ -1760,13 +1822,14 @@ describe('fileIOTestStream', function () { try { var ss = fileio.createStreamSync(fpath, 'r+'); expect(ss !== null).assertTrue(); - expect(ss.writeSync(FILE_CONTENT, { + ss.writeSync(FILE_CONTENT, { offset: -1 - }) == null).assertTrue(); + }) expect(null).assertFail(); } catch (e) { - console.log('fileio_test_stream_write_sync_012 has failed for ' + e); + console.info('fileio_test_stream_write_sync_012 has failed for ' + e); + expect(e.message == 'Invalid option.offset, positive integer is desired').assertTrue(); ss.closeSync(); fileio.unlinkSync(fpath); } @@ -1792,10 +1855,10 @@ describe('fileIOTestStream', function () { }) == 1).assertTrue(); ss.closeSync(); fileio.unlinkSync(fpath); - console.log('---fileio_test_stream_write_sync_013 is passed!'); + console.info('---fileio_test_stream_write_sync_013 is passed!'); } catch (e) { - console.log('fileio_test_stream_write_sync_013 has failed for ' + e); + console.info('fileio_test_stream_write_sync_013 has failed for ' + e); expect(null).assertFail(); } }); @@ -1818,10 +1881,10 @@ describe('fileIOTestStream', function () { }) == 2).assertTrue(); ss.closeSync(); fileio.unlinkSync(fpath); - console.log('---fileio_test_stream_write_sync_014 is passed!'); + console.info('---fileio_test_stream_write_sync_014 is passed!'); } catch (e) { - console.log('fileio_test_stream_write_sync_014 has failed for ' + e); + console.info('fileio_test_stream_write_sync_014 has failed for ' + e); expect(null).assertFail(); } }); @@ -1849,7 +1912,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_write_read_4k_sync has failed for ' + e); + console.info('fileio_test_stream_write_read_4k_sync has failed for ' + e); expect(null).assertFail(); } }); @@ -1872,7 +1935,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_flush_sync_001 has failed for ' + e); + console.info('fileio_test_stream_flush_sync_001 has failed for ' + e); expect(null).assertFail(); } }); @@ -1893,7 +1956,8 @@ describe('fileIOTestStream', function () { expect(null).assertFail(); } catch (e) { - console.log('fileio_test_stream_flush_sync_001 has failed for ' + e); + console.info('fileio_test_stream_flush_sync_001 has failed for ' + e); + expect(e.message == 'Stream may has been closed').assertTrue(); fileio.unlinkSync(fpath); } }); @@ -1912,7 +1976,7 @@ describe('fileIOTestStream', function () { fileio.unlinkSync(fpath); } catch (e) { - console.log('fileio_test_stream_close_sync_000 has failed for ' + e); + console.info('fileio_test_stream_close_sync_000 has failed for ' + e); expect(null).assertFail(); } }); @@ -1933,8 +1997,9 @@ describe('fileIOTestStream', function () { expect(null).assertFail(); } catch (e) { + console.info('fileio_test_stream_close_sync_001 has failed for ' + e); + expect(e.message == 'Stream may have been closed yet').assertTrue(); fileio.unlinkSync(fpath); - console.log('fileio_test_stream_close_sync_001 has failed for ' + e); } }); }); diff --git a/storage/storagefilejstest/src/main/js/default/test/Common.js b/storage/storagefilejstest/src/main/js/default/test/Common.js index 07b711fd7..0acf9a977 100644 --- a/storage/storagefilejstest/src/main/js/default/test/Common.js +++ b/storage/storagefilejstest/src/main/js/default/test/Common.js @@ -19,7 +19,7 @@ import featureAbility from '@ohos.ability.featureAbility' export const FILE_CONTENT = 'hello world'; import { - describe, beforeAll, beforeEach, afterEach, afterAll, it, expect + describe, it, expect } from 'deccjsunit/index' @@ -51,8 +51,8 @@ export function prepareEmptyFile(fpath) { export async function nextFileName(testName) { var context = featureAbility.getContext(); - let data = await context.getFilesDir(); - let BASE_PATH = data.substring(0, data.length - 5) + 'cache/'; + let data = await context.getCacheDir(); + let BASE_PATH = data + '/'; return BASE_PATH + testName } export async function fileName(testName) { @@ -91,10 +91,6 @@ export function randomString(num) { export { fileio, describe, - beforeAll, - beforeEach, - afterEach, - afterAll, it, expect }; \ No newline at end of file diff --git a/storage/storagefilejstest/src/main/js/default/test/File.test.js b/storage/storagefilejstest/src/main/js/default/test/File.test.js index 41d90b517..e7e8aa007 100644 --- a/storage/storagefilejstest/src/main/js/default/test/File.test.js +++ b/storage/storagefilejstest/src/main/js/default/test/File.test.js @@ -17,10 +17,6 @@ import fileio from '@ohos.fileio'; import file from '@system.file'; import { describe, - beforeAll, - beforeEach, - afterEach, - afterAll, it, expect } -- GitLab