diff --git a/storage/storagefileiojstest/Test.json b/storage/storagefileiojstest/Test.json index 3ff1ae7e58a6b21605a82ff9a648d2bc81d64135..d32ddf4ac3eb41aad30acecbb26114a86fd50198 100644 --- a/storage/storagefileiojstest/Test.json +++ b/storage/storagefileiojstest/Test.json @@ -2,7 +2,7 @@ "description": "Configuration for storage file and fileio Tests", "driver": { "type": "JSUnitTest", - "test-timeout": "600000", + "test-timeout": "1800000", "package": "ohos.acts.storage.fileio", "shell-timeout": "60000" }, diff --git a/storage/storagefileiojstest/src/main/js/default/test/FileIO.test.js b/storage/storagefileiojstest/src/main/js/default/test/FileIO.test.js index a8aa3726c44bea36fe0c82d4e7af51cea864c9bd..4fe84792b0549fa3cc4c27d377133ada45239532 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/FileIO.test.js +++ b/storage/storagefileiojstest/src/main/js/default/test/FileIO.test.js @@ -3745,12 +3745,11 @@ describe('fileIOTest', function () { let fpath = await nextFileName('fileio_test_fchown_sync_006'); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); let stat = fileio.statSync(fpath); - let UID = stat.uid - let GID = null + let UID = stat.uid; let fd; try { fd = fileio.openSync(fpath); - expect(fileio.fchownSync(fd, UID, GID)); + fileio.fchownSync(fd, UID, 0); expect(null).assertFail(); } catch (e) { @@ -3769,11 +3768,9 @@ describe('fileIOTest', function () { let fpath = await nextFileName('fileio_test_fchown_sync_007'); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); let fd; - let UID = null - let GID = null try { fd = fileio.openSync(fpath, 0o2); - expect(fileio.fchownSync(fd, UID, GID)); + fileio.fchownSync(fd, 0, 0); expect(null).assertFail(); } catch (e) { diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/read.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/read.test.js index 6fe33a8e218c7f791f3319decf36acc1172e31b0..cfbec7c01ff9c23677d169ff98af55c1ee228d6f 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/read.test.js +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/read.test.js @@ -447,7 +447,7 @@ describe('fileio_read', function () { */ it('fileio_test_read_async_006', 0, async function (done) { let fd; - const invalidOffset = 99999; + const invalidOffset = 999; let fpath = await nextFileName('fileio_test_read_async_006'); expect(prepareFile(fpath, FILE_CONTENT)).assertTrue(); @@ -458,6 +458,7 @@ describe('fileio_read', function () { offset: invalidOffset, }); expect(null).assertFail(); + done(); } catch (e) { expect(fileio.closeSync(fd) == null).assertTrue(); expect(fileio.unlinkSync(fpath) == null).assertTrue(); diff --git a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/readtext.test.js b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/readtext.test.js index 27a889c3796c73b0de64bf327b2b2a471d211df2..9f30bd64462603ea40db3ae77a35431124146ac5 100644 --- a/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/readtext.test.js +++ b/storage/storagefileiojstest/src/main/js/default/test/module_fileio/members/readtext.test.js @@ -59,8 +59,7 @@ describe('fileio_readtext', function () { try { let str = fileio.readTextSync(fpath, { position: pos }); - console.log(str); - expect(str == FILE_CONTENT.substr(pos, FILE_CONTENT.length)).assertTrue(); + expect(str == FILE_CONTENT.substring(pos, FILE_CONTENT.length + 1)).assertTrue(); expect(fileio.unlinkSync(fpath) == null).assertTrue(); } catch (e) { console.log('fileio_test_readtext_sync_001 has failed for ' + e); @@ -85,7 +84,7 @@ describe('fileio_readtext', function () { try { let str = fileio.readTextSync(fpath, { position: pos, length: len }); - expect(str == FILE_CONTENT.substr(pos, len)).assertTrue(); + expect(str == FILE_CONTENT.substring(pos, len + 1)).assertTrue(); expect(fileio.unlinkSync(fpath) == null).assertTrue(); } catch (e) { console.log('fileio_test_readtext_sync_002 has failed for ' + e); diff --git a/storage/storagefilejstest/Test.json b/storage/storagefilejstest/Test.json index a92c9b8198b965bedc60978fe68fbb1e7d949c96..02aef3b4c95b9418fe9e37eeffb0ef6cbbe6857a 100644 --- a/storage/storagefilejstest/Test.json +++ b/storage/storagefilejstest/Test.json @@ -2,7 +2,7 @@ "description": "Configuration for storage file Tests", "driver": { "type": "JSUnitTest", - "test-timeout": "60000", + "test-timeout": "600000", "package": "ohos.acts.storage.file", "shell-timeout": "60000" }, diff --git a/storage/storagefilejstest/src/main/js/default/test/Common.js b/storage/storagefilejstest/src/main/js/default/test/Common.js index 7c61d3f763983576594a68db06d835721a765bea..07b711fd7a4b64597c752edf918725c568b4c721 100644 --- a/storage/storagefilejstest/src/main/js/default/test/Common.js +++ b/storage/storagefilejstest/src/main/js/default/test/Common.js @@ -14,7 +14,7 @@ */ import fileio from '@ohos.fileio'; -import featureAbility from '@ohos.ability.featureAbility'; +import featureAbility from '@ohos.ability.featureAbility' export const FILE_CONTENT = 'hello world'; @@ -31,7 +31,7 @@ export function prepareFile(fpath, content) { fileio.fsyncSync(fd) fileio.closeSync(fd) return true - } + } catch (e) { console.log('Failed to prepareFile for ' + e) return false @@ -48,46 +48,21 @@ export function prepareEmptyFile(fpath) { return false } } -export function fileToReadOnly(fpath) { - try { - let fd = fileio.openSync(fpath, 0o1) - fileio.fchmodSync(fd, 0o444) - fileio.fsyncSync(fd) - fileio.closeSync(fd) - return true - } - catch (e) { - console.log('Failed to fileToReadOnly for ' + e); - return false - } -} -export function fileToWriteOnly(fpath) { - try { - let fd = fileio.openSync(fpath, 0o2) - fileio.fchmodSync(fd, 0o222) - fileio.fsyncSync(fd) - fileio.closeSync(fd) - return true - } - catch (e) { - console.log('Failed to fileToWriteOnly ' + e) - return false - } -} + export async function nextFileName(testName) { - let context = featureAbility.getContext(); + var context = featureAbility.getContext(); let data = await context.getFilesDir(); let BASE_PATH = data.substring(0, data.length - 5) + 'cache/'; return BASE_PATH + testName } export async function fileName(testName) { - let context = featureAbility.getContext(); + var context = featureAbility.getContext(); let data = await context.getFilesDir(); let BASE_PATH = data + '/'; return BASE_PATH + testName } export async function cacheFileName(testName) { - let context = featureAbility.getContext(); + var context = featureAbility.getContext(); let data = await context.getFilesDir(); let BASE_PATH = data + '/cache/'; return BASE_PATH + testName @@ -101,6 +76,7 @@ export function sleep(n) { } } } + export function randomString(num) { let len= num; var $chars = 'aaaabbbbcccc'; @@ -112,23 +88,8 @@ export function randomString(num) { return pwd; } -function isIntNum(val) { - return typeof val === 'number' && val % 1 === 0; -} - -function isString(str) { - return (typeof str == 'string') && str.constructor == String; -} - -function isBoolean(val) { - return typeof val == 'boolean'; -} - export { fileio, - isIntNum, - isString, - isBoolean, describe, beforeAll, beforeEach, 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 7c685c36e0c728bea37182da287af001515c1436..6edbf40445ac1610d6c6b39e6b4b8afd7c703879 100644 --- a/storage/storagefilejstest/src/main/js/default/test/File.test.js +++ b/storage/storagefilejstest/src/main/js/default/test/File.test.js @@ -24,7 +24,7 @@ import { it, expect } - from 'deccjsunit/index' +from 'deccjsunit/index' import { FILE_CONTENT, prepareFile, @@ -35,7 +35,7 @@ import { nextFileName, sleep } - from './Common' +from './Common' describe('fileTest', function () { @@ -1006,18 +1006,18 @@ describe('fileTest', function () { */ it('File_writeArrayBuffer_009', 0, async function (done) { let buf = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]); - file.writeArrayBuffer({ - uri: 'internal://cache/File_writeArrayBuffer_009', - buffer: buf, - success: function () { - console.log('File_writeArrayBuffer_009 call success'); - done(); - }, - fail: function (data, code) { - console.log('File_writeArrayBuffer_009 fail'); - expect(null).assertFail(); - }, - }); + file.writeArrayBuffer({ + uri: 'internal://cache/File_writeArrayBuffer_009', + buffer: buf, + success: function () { + console.log('File_writeArrayBuffer_009 call success'); + done(); + }, + fail: function (data, code) { + console.log('File_writeArrayBuffer_009 fail'); + expect(null).assertFail(); + }, + }); file.readArrayBuffer({ uri: 'internal://cache/File_writeArrayBuffer_009', success: function (data) { @@ -1318,9 +1318,7 @@ describe('fileTest', function () { done(); }, fail: function (data, code) { - console.error( - "call fail callback fail, code: " + code + ", data: " + data - ); + console.error("call fail callback fail, code: " + code + ", data: " + data); expect(null).assertFail(); }, }); @@ -2823,7 +2821,7 @@ describe('fileTest', function () { }, fail: function (data, code) { console.log('File_Copy_005 , code: ' + code + ', data: ' + data); - expect(code == 301).assertTrue(); + expect(code == 300).assertTrue(); done(); }, }); @@ -3332,7 +3330,7 @@ describe('fileTest', function () { expect(prepareFile(fpath, FILE_CONTENT) !== null).assertTrue(); expect(prepareFile(ffpath, FILE_CONTENT) !== null).assertTrue(); expect(prepareFile(fffpath, FILE_CONTENT) !== null).assertTrue(); - } + } catch (e) { console.log('File_List_010 has failed for ' + e); expect(null).assertFail();