提交 2be4c294 编写于 作者: S shuzhouhao

fileio stream write返回错误,测试用例对应修改

Signed-off-by: Nshuzhouhao <shuzhouhao@huawei.com>
上级 940d85e8
......@@ -96,15 +96,15 @@ export function fileToReadAndWrite(fpath) {
}
}
export function appName(testName) {
const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/'
const BASE_PATH = '/data/storage/el2/base/haps/entry/'
return BASE_PATH + testName
}
export function nextFileName(testName) {
const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/cache/'
const BASE_PATH = '/data/storage/el2/base/haps/entry/cache/'
return BASE_PATH + testName
}
export function fileName(testName) {
const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.stroage.fileio/files/'
const BASE_PATH = '/data/storage/el2/base/haps/entry/files/'
return BASE_PATH + testName
}
export function cacheFileName(testName) {
......
......@@ -13,7 +13,7 @@
* limitations under the License.
*/
import fileio from '@system.fileio'
import fileio from '@ohos.fileio'
import {
describe,
it,
......
......@@ -74,10 +74,7 @@ export function fileToWriteOnly(fpath) {
return false
}
}
export function nextFileName1(testName) {
const BASE_PATH = '/data/accounts/account_0/appdata/ohos.acts.storage.fileio/cache/'
return BASE_PATH + testName + '_' + randomString(testName.length);
}
export async function nextFileName(testName) {
let context = featureAbility.getContext();
let data = await context.getFilesDir();
......
......@@ -14,7 +14,7 @@
*/
import {
fileio, FILE_CONTENT, prepareFile, nextFileName1, nextFileName,
fileio, FILE_CONTENT, prepareFile, nextFileName,
describe, it, expect,
} from '../../Common';
......@@ -36,16 +36,18 @@ describe('fileio_stream', function () {
try {
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
ss.write(new ArrayBuffer(4096), {
let length = 4096;
ss.write(new ArrayBuffer(length), {
position: 1
}).then(function (len) {
expect(len == (FILE_CONTENT.length - 1)).assertTrue();
expect(len == length).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
})
done();
} catch (e) {
console.log('fileio_test_stream_write_async_000 has failed for ' + e);
expect(null).assertFail();
done();
}
});
......@@ -59,20 +61,23 @@ describe('fileio_stream', function () {
* @tc.require
*/
it('fileio_test_stream_write_async_001', 0, async function (done) {
let fpath = nextFileName1('fileio_test_stream_write_async_001');
let fpath = await nextFileName('fileio_test_stream_write_async_001');
expect(prepareFile(fpath, FILE_CONTENT)).assertTrue();
try {
let ss = fileio.createStreamSync(fpath, 'r+');
expect(ss !== null).assertTrue();
ss.write(new ArrayBuffer(4096), { offset: 1, encoding: 'utf-8' }, function (err, bytesWritten) {
expect(bytesWritten == (FILE_CONTENT.length - 1)).assertTrue();
let length = 4096;
let offset = 1;
ss.write(new ArrayBuffer(length), { offset: offset, encoding: 'utf-8' }, function (err, bytesWritten) {
expect(bytesWritten == (length - offset)).assertTrue();
expect(fileio.unlinkSync(fpath) == null).assertTrue();
done();
});
done();
} catch (e) {
console.log('fileio_test_stream_write_async_001 has failed for ' + e);
expect(null).assertFail();
done();
}
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册