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

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

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