Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
9ffb8c36
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
1 年多 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
9ffb8c36
编写于
5月 31, 2022
作者:
O
openharmony_ci
提交者:
Gitee
5月 31, 2022
浏览文件
操作
浏览文件
下载
差异文件
!3335 update fileio xts
Merge pull request !3335 from zhangxingxia/master
上级
01099ee0
09fe36ef
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
825 addition
and
176 deletion
+825
-176
storage/storagefileiojstest/src/main/js/default/test/FileIO.test.js
...oragefileiojstest/src/main/js/default/test/FileIO.test.js
+1
-1
storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/all.test.js
...in/js/default/test/module_fileio/class_stream/all.test.js
+80
-81
storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/close.test.js
.../js/default/test/module_fileio/class_stream/close.test.js
+46
-41
storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/flush.test.js
.../js/default/test/module_fileio/class_stream/flush.test.js
+49
-23
storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/read.test.js
...n/js/default/test/module_fileio/class_stream/read.test.js
+281
-14
storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/write.test.js
.../js/default/test/module_fileio/class_stream/write.test.js
+368
-16
未找到文件。
storage/storagefileiojstest/src/main/js/default/test/FileIO.test.js
浏览文件 @
9ffb8c36
...
...
@@ -2289,7 +2289,7 @@ describe('fileIOTest', function () {
fileio
.
copyFileSync
(
-
1
,
-
1
);
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_copy_file_sync_007 has failed for
'
+
err
);
expect
(
err
.
message
==
"
Invalid argument
"
).
assertTrue
();
expect
(
err
.
message
==
"
Invalid argument
"
||
err
.
message
==
"
Bad file descriptor
"
).
assertTrue
();
}
});
...
...
storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/all.test.js
浏览文件 @
9ffb8c36
...
...
@@ -23,8 +23,8 @@ describe('fileio_stream', function () {
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAMSYNC_0000
* @tc.name fileio_test_stream_create_stream_sync_000
* @tc.desc Test createStreamSync() interface.
* @tc.size MEDIUM
(中型)
* @tc.desc Test createStreamSync() interface
, Open read-write file
.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
...
...
@@ -36,19 +36,19 @@ describe('fileio_stream', function () {
try
{
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
expect
(
ss
.
closeSync
()
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
(
);
}
catch
(
e
)
{
console
.
log
(
'
fileio_test_stream_create_stream_sync_000 has failed for
'
+
e
);
ss
.
closeSync
();
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
rr
)
{
console
.
info
(
'
fileio_test_stream_create_stream_sync_000 has failed for
'
+
err
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAMSYNC_0
01
0
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAMSYNC_0
10
0
* @tc.name fileio_test_stream_create_stream_sync_001
* @tc.desc Test createStreamSync() interface.
* @tc.size MEDIUM
(中型)
* @tc.desc Test createStreamSync() interface
, When file does not exist
.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
...
...
@@ -58,17 +58,17 @@ describe('fileio_stream', function () {
try
{
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
null
).
assertFail
();
}
catch
(
e
)
{
console
.
log
(
'
fileio_test_stream_create_stream_sync_001 has failed for
'
+
e
);
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_create_stream_sync_001 has failed for
'
+
err
);
expect
(
err
.
message
==
"
No such file or directory
"
).
assertTrue
(
);
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAMSYNC_0
02
0
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAMSYNC_0
20
0
* @tc.name fileio_test_stream_create_stream_sync_002
* @tc.desc Test createStreamSync() interface.
* @tc.size MEDIUM
(中型)
* @tc.desc Test createStreamSync() interface
, When mode is invalid
.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
...
...
@@ -79,17 +79,18 @@ describe('fileio_stream', function () {
try
{
fileio
.
createStreamSync
(
fpath
,
'
ohos
'
);
expect
(
null
).
assertFail
();
}
catch
(
e
)
{
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_create_stream_sync_002 has failed for
'
+
err
);
expect
(
err
.
message
==
"
Invalid argument
"
).
assertTrue
();
fileio
.
unlinkSync
(
fpath
);
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0000
* @tc.name fileio_test_stream_read_sync_000
* @tc.desc Test readSync() interface.
* @tc.size MEDIUM
(中型)
* @tc.desc Test readSync() interface
, read data from stream file
.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
...
...
@@ -103,48 +104,46 @@ describe('fileio_stream', function () {
expect
(
ss
!==
null
).
assertTrue
();
let
len
=
ss
.
readSync
(
new
ArrayBuffer
(
4096
));
expect
(
len
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
ss
.
closeSync
()
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
(
);
}
catch
(
e
)
{
console
.
log
(
'
fileio_test_stream_read_sync_000 has failed for
'
+
e
);
ss
.
closeSync
();
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
rr
)
{
console
.
info
(
'
fileio_test_stream_read_sync_000 has failed for
'
+
err
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0
01
0
* @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0
10
0
* @tc.name fileio_test_stream_read_sync_001
* @tc.desc Test the readSync method of class Stream.
* @tc.size MEDIUM
(中型)
* @tc.desc Test the readSync method of class Stream
,When offset equals buffer length.
.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_read_sync_001
'
,
0
,
async
function
()
{
let
bufLen
=
5
;
expect
(
FILE_CONTENT
.
length
>
bufLen
).
assertTrue
();
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_read_sync_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
let
len
=
ss
.
readSync
(
new
ArrayBuffer
(
bufLen
),
{
offset
:
1
let
len
=
ss
.
readSync
(
new
ArrayBuffer
(
4096
),
{
offset
:
4096
});
expect
(
len
==
(
bufLen
-
1
)
).
assertTrue
();
expect
(
ss
.
closeSync
()
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
(
);
}
catch
(
e
)
{
console
.
log
(
'
fileio_test_stream_read_sync_001 has failed for
'
+
e
);
expect
(
len
==
0
).
assertTrue
();
ss
.
closeSync
();
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
rr
)
{
console
.
info
(
'
fileio_test_stream_read_sync_001 has failed for
'
+
err
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0
02
0
* @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0
20
0
* @tc.name fileio_test_stream_read_sync_002
* @tc.desc Test the readSync method of class Stream.
* @tc.size MEDIUM
(中型)
* @tc.desc Test the readSync method of class Stream
,When the length is 1
.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
...
...
@@ -159,19 +158,19 @@ describe('fileio_stream', function () {
length
:
1
});
expect
(
len
==
1
).
assertTrue
();
expect
(
ss
.
closeSync
()
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
(
);
}
catch
(
e
)
{
console
.
log
(
'
fileio_test_stream_read_sync_002 has failed for
'
+
e
);
ss
.
closeSync
();
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
rr
)
{
console
.
info
(
'
fileio_test_stream_read_sync_002 has failed for
'
+
err
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0
03
0
* @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0
30
0
* @tc.name fileio_test_stream_read_sync_003
* @tc.desc Test the readSync method of class Stream.
* @tc.size MEDIUM
(中型)
* @tc.desc Test the readSync method of class Stream
,When the position is 1
.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
...
...
@@ -186,73 +185,73 @@ describe('fileio_stream', function () {
position
:
1
});
expect
(
len
==
(
FILE_CONTENT
.
length
-
1
)).
assertTrue
();
expect
(
ss
.
closeSync
()
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
(
);
}
catch
(
e
)
{
console
.
log
(
'
fileio_test_stream_read_sync_003 has failed for
'
+
e
);
ss
.
closeSync
();
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
rr
)
{
console
.
info
(
'
fileio_test_stream_read_sync_003 has failed for
'
+
err
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0
04
0
* @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0
40
0
* @tc.name fileio_test_stream_read_sync_004
* @tc.desc Test the readSync method of class Stream.
* @tc.size MEDIUM
(中型)
* @tc.desc Test the readSync method of class Stream
,When the offset is greater than the buffer length
.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_read_sync_004
'
,
0
,
async
function
()
{
let
ss
;
const
invalidOffset
=
99999
;
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_read_sync_004
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
ss
.
readSync
(
new
ArrayBuffer
(
4096
),
{
offset
:
invalidOffset
offset
:
4097
});
expect
(
null
).
assertFail
();
}
catch
(
e
)
{
expect
(
ss
.
closeSync
()
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_read_sync_004 has failed for
'
+
err
);
expect
(
err
.
message
==
"
Invalid option.offset, buffer limit exceeded
"
).
assertTrue
();
ss
.
closeSync
();
fileio
.
unlinkSync
(
fpath
);
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0
05
0
* @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0
50
0
* @tc.name fileio_test_stream_read_sync_005
* @tc.desc Test the readSync method of class Stream.
* @tc.size MEDIUM
(中型)
* @tc.desc Test the readSync method of class Stream
, When the length is greater than the buffer length
.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_read_sync_005
'
,
0
,
async
function
()
{
let
ss
;
const
invalidLength
=
9999
;
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_read_sync_005
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
ss
.
readSync
(
new
ArrayBuffer
(
4096
),
{
length
:
invalidLength
length
:
4097
});
expect
(
null
).
assertFail
();
}
catch
(
e
)
{
expect
(
ss
.
closeSync
()
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_read_sync_005 has failed for
'
+
err
);
expect
(
err
.
message
==
"
Invalid option.length, buffer limit exceeded
"
).
assertTrue
();
ss
.
closeSync
();
fileio
.
unlinkSync
(
fpath
);
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0
06
0
* @tc.number SUB_DF_FILEIO_STREAM_READSYNC_0
60
0
* @tc.name fileio_test_stream_read_sync_006
* @tc.desc Test the readSync method of class Stream.
* @tc.size MEDIUM
(中型)
* @tc.desc Test the readSync method of class Stream
, When position is equal to the length of the file content plus one
.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
...
...
@@ -268,10 +267,10 @@ describe('fileio_stream', function () {
position
:
invalidPos
});
expect
(
len
==
0
).
assertTrue
();
expect
(
ss
.
closeSync
()
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
(
);
}
catch
(
e
)
{
console
.
log
(
'
fileio_test_stream_read_sync_006 has failed for
'
+
e
);
ss
.
closeSync
();
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
rr
)
{
console
.
info
(
'
fileio_test_stream_read_sync_006 has failed for
'
+
err
);
expect
(
null
).
assertFail
();
}
});
...
...
@@ -279,8 +278,8 @@ describe('fileio_stream', function () {
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITESYNC_0000
* @tc.name fileio_test_stream_write_sync_000
* @tc.desc Test writeSync() interface.
* @tc.size MEDIUM
(中型)
* @tc.desc Test writeSync() interface
, Write data to stream file
.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
...
...
@@ -293,10 +292,10 @@ describe('fileio_stream', function () {
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
expect
(
ss
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
ss
.
closeSync
()
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
(
);
}
catch
(
e
)
{
console
.
log
(
'
fileio_test_stream_write_sync_000 has failed for
'
+
e
);
ss
.
closeSync
();
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
rr
)
{
console
.
info
(
'
fileio_test_stream_write_sync_000 has failed for
'
+
err
);
expect
(
null
).
assertFail
();
}
});
...
...
storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/close.test.js
浏览文件 @
9ffb8c36
...
...
@@ -18,101 +18,106 @@ import {
describe
,
it
,
expect
,
}
from
'
../../Common
'
;
describe
(
'
fileio_stream
'
,
function
()
{
describe
(
'
fileio_stream
_close
'
,
function
()
{
/**
* @tc.number SUB_DF_FILEIO_STREAM_
FDOPENSTREAM
SYNC_0000
* @tc.name fileio_test_stream_
fdopen_stream
_sync_000
* @tc.desc Test
fdopenStreamSync() interface
* @tc.size MEDIUM
(中型)
* @tc.number SUB_DF_FILEIO_STREAM_
CLOSE
SYNC_0000
* @tc.name fileio_test_stream_
close
_sync_000
* @tc.desc Test
closeSync() interface,Close file stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_
fdopen_stream
_sync_000
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_
fdopen_stream
_sync_000
'
);
it
(
'
fileio_test_stream_
close
_sync_000
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_
close
_sync_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
fd
=
fileio
.
openSync
(
fpath
,
0o2
);
let
ss
=
fileio
.
fdopenStreamSync
(
fd
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
expect
(
ss
.
closeSync
()
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
(
);
}
catch
(
e
)
{
console
.
log
(
'
fileio_test_stream_fdopen_stream_sync_000 has failed for
'
+
e
);
ss
.
closeSync
();
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
rr
)
{
console
.
info
(
'
fileio_test_stream_close_sync_000 has failed for
'
+
err
);
expect
(
null
).
assertFail
();
}
})
/**
* @tc.number SUB_DF_FILEIO_STREAM_
FDOPENSTREAMSYNC_001
0
* @tc.name fileio_test_stream_
fdopen_stream
_sync_001
* @tc.desc Test
fdopenStreamSync() interface
* @tc.size MEDIUM
(中型)
* @tc.number SUB_DF_FILEIO_STREAM_
CLOSESYNC_010
0
* @tc.name fileio_test_stream_
close
_sync_001
* @tc.desc Test
closeSync() interface,When there are parameters.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_fdopen_stream_sync_001
'
,
0
,
function
()
{
it
(
'
fileio_test_stream_close_sync_001
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_close_sync_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
ss
=
fileio
.
fdopenStreamSync
(
-
1
,
'
r+
'
);
expect
(
null
).
assertFail
();
}
catch
(
e
)
{
console
.
log
(
'
fileio_test_stream_fdopen_stream_sync_001 has failed for
'
+
e
);
let
fd
=
fileio
.
openSync
(
fpath
,
0o2
);
let
ss
=
fileio
.
fdopenStreamSync
(
fd
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
ss
.
closeSync
(
1
);
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_close_sync_001 has failed for
'
+
err
);
expect
(
err
.
message
==
"
Number of arguments unmatched
"
).
assertTrue
();
fileio
.
unlinkSync
(
fpath
);
}
})
/**
* @tc.number SUB_DF_FILEIO_STREAM_
FDOPENSTREAM
ASYNC_0000
* @tc.name fileio_test_stream_
fdopen_stream
_async_000
* @tc.desc Test
fdopenStreamSync() interface
* @tc.size MEDIUM
(中型)
* @tc.number SUB_DF_FILEIO_STREAM_
CLOSE
ASYNC_0000
* @tc.name fileio_test_stream_
close
_async_000
* @tc.desc Test
close() interface,return in promise mode.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_
fdopen_stream
_async_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_
fdopen_stream
_async_000
'
);
it
(
'
fileio_test_stream_
close
_async_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_
close
_async_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
fd
=
await
fileio
.
openSync
(
fpath
,
0o2
);
let
ss
=
await
fileio
.
fdopenStreamSync
(
fd
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
expect
(
ss
.
closeSync
()
==
null
).
assertTru
e
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
(
);
await
ss
.
clos
e
();
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileio_test_stream_fdopen_stream_async_000 has failed for
'
+
e
);
}
catch
(
e
rr
)
{
console
.
info
(
'
fileio_test_stream_close_async_000 has failed for
'
+
err
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_
FDOPENSTREAMASYNC_001
0
* @tc.name fileio_test_stream_
fdopen_stream
_async_001
* @tc.desc Test
fdopenStreamSync() interface
* @tc.size MEDIUM
(中型)
* @tc.number SUB_DF_FILEIO_STREAM_
CLOSEASYNC_010
0
* @tc.name fileio_test_stream_
close
_async_001
* @tc.desc Test
close() interface,return in callback mode.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_
fdopen_stream
_async_001
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_
fdopen_stream
_async_001
'
);
it
(
'
fileio_test_stream_
close
_async_001
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_
close
_async_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
fd
=
await
fileio
.
openSync
(
fpath
,
0o2
);
let
ss
=
await
fileio
.
fdopenStreamSync
(
fd
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
ss
.
close
(
function
(
err
,
stream
)
{
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
(
);
ss
.
close
(
function
(
err
)
{
fileio
.
unlinkSync
(
fpath
);
})
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileio_test_stream_fdopen_stream_async_001 has failed for
'
+
e
);
}
catch
(
e
rr
)
{
console
.
info
(
'
fileio_test_stream_close_async_001 has failed for
'
+
err
);
expect
(
null
).
assertFail
();
}
});
...
...
storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/flush.test.js
浏览文件 @
9ffb8c36
...
...
@@ -18,13 +18,13 @@ import {
describe
,
it
,
expect
,
}
from
'
../../Common
'
;
describe
(
'
fileio_stream
'
,
function
()
{
describe
(
'
fileio_stream
_flush
'
,
function
()
{
/**
* @tc.number SUB_DF_FILEIO_STREAM_FLUSHSYNC_0000
* @tc.name fileio_test_stream_flush_sync_000
* @tc.desc Test flushSync() interface
* @tc.size MEDIUM
(中型)
* @tc.desc Test flushSync() interface
, refresh file stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
...
...
@@ -37,20 +37,46 @@ describe('fileio_stream', function () {
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
expect
(
ss
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
ss
.
flushSync
()
==
null
).
assertTrue
();
expect
(
ss
.
closeSync
()
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
(
);
}
catch
(
e
)
{
console
.
log
(
'
fileio_test_stream_flush_sync_000 has failed for
'
+
e
);
ss
.
flushSync
();
ss
.
closeSync
();
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
rr
)
{
console
.
info
(
'
fileio_test_stream_flush_sync_000 has failed for
'
+
err
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_FLUSHSYNC_0100
* @tc.name fileio_test_stream_flush_sync_001
* @tc.desc Test flushSync() interface, When there are parameters.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_flush_sync_001
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_flush_sync_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
expect
(
ss
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
try
{
ss
.
flushSync
(
1
);
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_flush_sync_001 has failed for
'
+
err
);
expect
(
err
.
message
==
"
Number of arguments unmatched
"
).
assertTrue
();
ss
.
closeSync
();
fileio
.
unlinkSync
(
fpath
);
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_FLUSHASYNC_0000
* @tc.name fileio_test_stream_flush_async_000
* @tc.desc Test flush
Sync() interface
* @tc.size MEDIUM
(中型)
* @tc.desc Test flush
() interface, refresh the file stream and return in promise mode.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
...
...
@@ -62,25 +88,24 @@ describe('fileio_stream', function () {
try
{
let
ss
=
await
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
expect
(
ss
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
ss
.
flush
().
then
(
function
(
err
)
{
expect
(
!
err
).
assertTrue
();
expect
(
ss
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
ss
.
closeSync
()
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
ss
.
closeSync
();
fileio
.
unlinkSync
(
fpath
);
})
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileio_test_stream_flush_async_000 has failed for
'
+
e
);
}
catch
(
e
rr
)
{
console
.
info
(
'
fileio_test_stream_flush_async_000 has failed for
'
+
err
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_FLUSHASYNC_0
01
0
* @tc.number SUB_DF_FILEIO_STREAM_FLUSHASYNC_0
10
0
* @tc.name fileio_test_stream_flush_async_001
* @tc.desc Test flush
Sync() interface
* @tc.size MEDIUM
(中型)
* @tc.desc Test flush
() interface, refresh the file stream and return in callback mode.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
...
...
@@ -94,13 +119,14 @@ describe('fileio_stream', function () {
expect
(
ss
!==
null
).
assertTrue
();
expect
(
ss
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
ss
.
flush
(
function
(
err
)
{
expect
(
ss
.
closeSync
()
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
(
);
ss
.
closeSync
();
fileio
.
unlinkSync
(
fpath
);
done
();
})
}
catch
(
e
)
{
console
.
log
(
'
fileio_test_stream_flush_async_001 has failed for
'
+
e
);
}
catch
(
e
rr
)
{
console
.
info
(
'
fileio_test_stream_flush_async_001 has failed for
'
+
err
);
expect
(
null
).
assertFail
();
}
});
});
storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/read.test.js
浏览文件 @
9ffb8c36
...
...
@@ -18,13 +18,13 @@ import {
describe
,
it
,
expect
,
}
from
'
../../Common
'
;
describe
(
'
fileio_stream
'
,
function
()
{
describe
(
'
fileio_stream
_read
'
,
function
()
{
/**
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0000
* @tc.name fileio_test_stream_read_async_000
* @tc.desc Test read
Async() interface
* @tc.size MEDIUM
(中型)
* @tc.desc Test read
() interface,return in promise mode.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
...
...
@@ -38,20 +38,20 @@ describe('fileio_stream', function () {
expect
(
ss
!==
null
).
assertTrue
();
let
readout
=
await
ss
.
read
(
new
ArrayBuffer
(
4096
));
expect
(
readout
.
bytesRead
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
ss
.
closeSync
()
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
(
);
ss
.
closeSync
();
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileio_test_stream_read_async_000 has failed for
'
+
e
);
}
catch
(
e
rr
)
{
console
.
info
(
'
fileio_test_stream_read_async_000 has failed for
'
+
err
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0
01
0
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0
10
0
* @tc.name fileio_test_stream_read_async_001
* @tc.desc Test read
Async() interface
* @tc.size MEDIUM
(中型)
* @tc.desc Test read
() interface, return in callback mode.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
...
...
@@ -65,12 +65,279 @@ describe('fileio_stream', function () {
expect
(
ss
!==
null
).
assertTrue
();
ss
.
read
(
new
ArrayBuffer
(
4096
),
null
,
function
(
err
,
readout
)
{
expect
(
readout
.
bytesRead
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
ss
.
closeSync
()
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
(
);
ss
.
closeSync
();
fileio
.
unlinkSync
(
fpath
);
});
}
catch
(
e
)
{
console
.
log
(
'
fileio_test_stream_read_async_001 has failed for
'
+
e
);
}
catch
(
e
rr
)
{
console
.
info
(
'
fileio_test_stream_read_async_001 has failed for
'
+
err
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0200
* @tc.name fileio_test_stream_read_async_002
* @tc.desc Test read() interface, When the offset is 1 and the length is 5.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_read_async_002
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_read_async_002
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
let
options
=
{
offset
:
1
,
length
:
5
}
let
readout
=
await
ss
.
read
(
new
ArrayBuffer
(
4096
),
options
);
expect
(
readout
.
bytesRead
==
5
).
assertTrue
();
ss
.
closeSync
();
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_read_async_002 has failed for
'
+
err
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0300
* @tc.name fileio_test_stream_read_async_003
* @tc.desc Test read() interface, When offset equals buffer length.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_read_async_003
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_read_async_003
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
let
readout
=
await
ss
.
read
(
new
ArrayBuffer
(
4096
),
{
offset
:
4096
});
expect
(
readout
.
bytesRead
==
0
).
assertTrue
();
ss
.
closeSync
();
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_read_async_003 has failed for
'
+
err
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0400
* @tc.name fileio_test_stream_read_async_004
* @tc.desc Test read() interface, When the offset is 1 and the position is 5.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_read_async_004
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_read_async_004
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
let
options
=
{
offset
:
1
,
position
:
5
}
let
readout
=
await
ss
.
read
(
new
ArrayBuffer
(
4096
),
options
);
expect
(
readout
.
bytesRead
==
FILE_CONTENT
.
length
).
assertTrue
();
ss
.
closeSync
();
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_read_async_004 has failed for
'
+
err
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0500
* @tc.name fileio_test_stream_read_async_005
* @tc.desc Test read() interface, When the offset is negative.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_read_async_005
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_read_async_005
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
try
{
await
ss
.
read
(
new
ArrayBuffer
(
4096
),
{
offset
:
-
1
});
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_read_async_005 has failed for
'
+
err
);
expect
(
err
.
message
==
"
Failed GetReadArg
"
).
assertTrue
();
ss
.
closeSync
();
fileio
.
unlinkSync
(
fpath
);
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0600
* @tc.name fileio_test_stream_read_async_006
* @tc.desc Test read() interface, When offset+length>buffer.size.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_read_async_006
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_read_async_006
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
try
{
await
ss
.
read
(
new
ArrayBuffer
(
4096
),
{
offset
:
1
,
length
:
4096
});
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_read_async_006 has failed for
'
+
err
);
expect
(
err
.
message
==
"
Failed GetReadArg
"
).
assertTrue
();
ss
.
closeSync
();
fileio
.
unlinkSync
(
fpath
);
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0700
* @tc.name fileio_test_stream_read_async_007
* @tc.desc Test read() interface, When the offset is greater than the buffer length.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_read_async_007
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_read_async_007
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
try
{
await
ss
.
read
(
new
ArrayBuffer
(
4096
),
{
offset
:
4097
});
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_read_async_007 has failed for
'
+
err
);
expect
(
err
.
message
==
"
Failed GetReadArg
"
).
assertTrue
();
ss
.
closeSync
();
fileio
.
unlinkSync
(
fpath
);
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0800
* @tc.name fileio_test_stream_read_async_008
* @tc.desc Test read() interface, When the length is greater than the buffer length.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_read_async_008
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_read_async_008
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
try
{
await
ss
.
read
(
new
ArrayBuffer
(
4096
),
{
length
:
4097
});
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_read_async_008 has failed for
'
+
err
);
expect
(
err
.
message
==
"
Failed GetReadArg
"
).
assertTrue
();
ss
.
closeSync
();
fileio
.
unlinkSync
(
fpath
);
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_0900
* @tc.name fileio_test_stream_read_async_009
* @tc.desc Test read() interface, When the length is negative.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_read_async_009
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_read_async_009
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
try
{
let
readout
=
await
ss
.
read
(
new
ArrayBuffer
(
4096
),
{
length
:
-
1
});
console
.
info
(
"
====>
"
+
readout
.
bytesRead
);
done
();
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_read_async_009 has failed for
'
+
err
);
expect
(
err
.
message
==
"
Failed GetReadArg
"
).
assertTrue
();
ss
.
closeSync
();
fileio
.
unlinkSync
(
fpath
);
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_1000
* @tc.name fileio_test_stream_read_async_010
* @tc.desc Test read() interface, When there are no parameters.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_read_async_010
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_read_async_010
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
try
{
await
ss
.
read
();
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_read_async_010 has failed for
'
+
err
);
expect
(
err
.
message
==
"
Number of arguments unmatched
"
).
assertTrue
();
ss
.
closeSync
();
fileio
.
unlinkSync
(
fpath
);
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_READASYNC_1100
* @tc.name fileio_test_stream_read_async_011
* @tc.desc Test read() interface, When length>FILE_CONTENT.length.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_read_async_011
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_read_async_011
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
try
{
let
readout
=
await
ss
.
read
(
new
ArrayBuffer
(
4096
),
{
length
:
FILE_CONTENT
.
length
+
1
});
expect
(
readout
.
bytesRead
==
FILE_CONTENT
.
length
).
assertTrue
();
ss
.
closeSync
();
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_read_async_011 has failed for
'
+
err
);
}
});
});
storage/storagefileiojstest/src/main/js/default/test/module_fileio/class_stream/write.test.js
浏览文件 @
9ffb8c36
...
...
@@ -18,13 +18,13 @@ import {
describe
,
it
,
expect
,
}
from
'
../../Common
'
;
describe
(
'
fileio_stream
'
,
function
()
{
describe
(
'
fileio_stream
_write
'
,
function
()
{
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0000
* @tc.name fileio_test_stream_write_async_000
* @tc.desc Test
Stream.write() interface
* @tc.size MEDIUM
(中型)
* @tc.desc Test
write() interface,When the position is 1,return in promise mode.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
...
...
@@ -41,21 +41,22 @@ describe('fileio_stream', function () {
position
:
1
}).
then
(
function
(
len
)
{
expect
(
len
==
length
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
fileio
.
unlinkSync
(
fpath
);
ss
.
closeSync
();
done
();
})
}
catch
(
e
)
{
console
.
log
(
'
fileio_test_stream_write_async_000 has failed for
'
+
e
);
}
catch
(
e
rr
)
{
console
.
info
(
'
fileio_test_stream_write_async_000 has failed for
'
+
err
);
expect
(
null
).
assertFail
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0
01
0
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0
10
0
* @tc.name fileio_test_stream_write_async_001
* @tc.desc Test
Stream.write() interface
* @tc.size MEDIUM
(中型)
* @tc.desc Test
write() interface,return in callback mode.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
...
...
@@ -67,17 +68,368 @@ describe('fileio_stream', function () {
try
{
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
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
();
ss
.
write
(
new
ArrayBuffer
(
4096
),
{
offset
:
1
,
encoding
:
'
utf-8
'
},
function
(
err
,
bytesWritten
)
{
expect
(
bytesWritten
==
4095
).
assertTrue
();
fileio
.
unlinkSync
(
fpath
);
ss
.
closeSync
();
done
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileio_test_stream_write_async_001 has failed for
'
+
e
);
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_write_async_001 has failed for
'
+
err
);
expect
(
null
).
assertFail
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0200
* @tc.name fileio_test_stream_write_async_002
* @tc.desc Test write() interface,When the offset is 1.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_write_async_002
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_write_async_002
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
let
content
=
"
hello, world
"
;
let
bytesWritten
=
await
ss
.
write
(
content
,
{
offset
:
1
,
length
:
5
,
encoding
:
'
utf-8
'
});
expect
(
bytesWritten
==
5
).
assertTrue
();
fileio
.
unlinkSync
(
fpath
);
ss
.
closeSync
();
done
();
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_write_async_002 has failed for
'
+
err
);
expect
(
null
).
assertFail
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0300
* @tc.name fileio_test_stream_write_async_003
* @tc.desc Test write() interface,When the length is 1.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_write_async_003
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_write_async_003
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
let
content
=
"
hello, world
"
;
let
bytesWritten
=
await
ss
.
write
(
content
,
{
length
:
1
,
encoding
:
'
utf-8
'
});
expect
(
bytesWritten
==
1
).
assertTrue
();
fileio
.
unlinkSync
(
fpath
);
ss
.
closeSync
();
done
();
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_write_async_003 has failed for
'
+
err
);
expect
(
null
).
assertFail
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0400
* @tc.name fileio_test_stream_write_async_004
* @tc.desc Test write() interface,When there is only the first parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_write_async_004
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_write_async_004
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
let
content
=
"
hello, world
"
;
let
bytesWritten
=
await
ss
.
write
(
content
);
expect
(
bytesWritten
==
content
.
length
).
assertTrue
();
fileio
.
unlinkSync
(
fpath
);
ss
.
closeSync
();
done
();
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_write_async_004 has failed for
'
+
err
);
expect
(
null
).
assertFail
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0500
* @tc.name fileio_test_stream_write_async_005
* @tc.desc Test write() interface,When offset equals buffer length.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_write_async_005
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_write_async_005
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
let
content
=
"
hello, world
"
;
let
bytesWritten
=
await
ss
.
write
(
content
,
{
offset
:
content
.
length
});
expect
(
bytesWritten
==
0
).
assertTrue
();
fileio
.
unlinkSync
(
fpath
);
ss
.
closeSync
();
done
();
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_write_async_005 has failed for
'
+
err
);
expect
(
null
).
assertFail
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0600
* @tc.name fileio_test_stream_write_async_006
* @tc.desc Test write() interface,When offset+length>buffer.size.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_write_async_006
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_write_async_006
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
try
{
let
content
=
"
hello, world
"
;
await
ss
.
write
(
content
,{
offset
:
5
,
length
:
10
});
done
();
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_write_async_006 has failed for
'
+
err
);
expect
(
err
.
message
==
"
Invalid option.length, buffer limit exceeded
"
).
assertTrue
();
fileio
.
unlinkSync
(
fpath
);
ss
.
closeSync
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0700
* @tc.name fileio_test_stream_write_async_007
* @tc.desc Test write() interface,When the offset is greater than the buffer length.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_write_async_007
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_write_async_007
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
try
{
let
content
=
"
hello, world
"
;
await
ss
.
write
(
content
,
{
offset
:
content
.
length
+
1
});
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_write_async_007 has failed for
'
+
err
);
expect
(
err
.
message
==
"
Invalid option.offset, buffer limit exceeded
"
).
assertTrue
();
fileio
.
unlinkSync
(
fpath
);
ss
.
closeSync
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0800
* @tc.name fileio_test_stream_write_async_008
* @tc.desc Test write() interface,when encoding invalid.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_write_async_008
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_write_async_008
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
try
{
await
ss
.
write
(
"
hello, world
"
,
{
encoding
:
'
GB2312
'
});
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_write_async_008 has failed for
'
+
err
);
expect
(
err
.
message
==
"
Illegal write buffer or encoding
"
).
assertTrue
();
ss
.
closeSync
();
fileio
.
unlinkSync
(
fpath
);
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_0900
* @tc.name fileio_test_stream_write_async_009
* @tc.desc Test write() interface,When there are no parameters.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_write_async_009
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_write_async_009
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
try
{
await
ss
.
write
();
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_write_async_009 has failed for
'
+
err
);
expect
(
err
.
message
==
"
Number of arguments unmatched
"
).
assertTrue
();
fileio
.
unlinkSync
(
fpath
);
ss
.
closeSync
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_1000
* @tc.name fileio_test_stream_write_async_010
* @tc.desc Test write() interface,When the offset is negative.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_write_async_010
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_write_async_010
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
try
{
let
content
=
"
hello, world
"
;
await
ss
.
write
(
content
,
{
offset
:
-
1
});
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_write_async_010 has failed for
'
+
err
);
expect
(
err
.
message
==
"
Invalid option.offset, positive integer is desired
"
).
assertTrue
();
fileio
.
unlinkSync
(
fpath
);
ss
.
closeSync
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_1100
* @tc.name fileio_test_stream_write_async_011
* @tc.desc Test write() interface,When the length is negative.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_write_async_011
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_write_async_011
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
try
{
let
content
=
"
hello, world
"
;
let
number
=
await
ss
.
write
(
content
,
{
length
:
-
1
});
console
.
info
(
"
====>
"
+
number
);
done
();
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_write_async_011 has failed for
'
+
err
);
expect
(
err
.
message
==
"
Invalid option.length, positive integer is desired
"
).
assertTrue
();
fileio
.
unlinkSync
(
fpath
);
ss
.
closeSync
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_1200
* @tc.name fileio_test_stream_write_async_012
* @tc.desc Test write() interface,When the buffer parameter type is wrong.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_write_async_012
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_write_async_012
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
try
{
await
ss
.
write
(
12
,
{
length
:
-
1
});
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_write_async_012 has failed for
'
+
err
);
expect
(
err
.
message
==
"
Illegal write buffer or encoding
"
).
assertTrue
();
fileio
.
unlinkSync
(
fpath
);
ss
.
closeSync
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_1300
* @tc.name fileio_test_stream_write_async_013
* @tc.desc Test write() interface,When the length is greater than the buffer length.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_write_async_013
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_write_async_013
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
try
{
await
ss
.
write
(
new
ArrayBuffer
(
4096
),
{
length
:
4097
});
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_write_async_013 has failed for
'
+
err
);
expect
(
err
.
message
==
"
Invalid option.length, buffer limit exceeded
"
).
assertTrue
();
fileio
.
unlinkSync
(
fpath
);
ss
.
closeSync
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_WRITEASYNC_1400
* @tc.name fileio_test_stream_write_async_014
* @tc.desc Test write() interface,When the length>content.length .
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_stream_write_async_014
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileio_test_stream_write_async_014
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
ss
=
fileio
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
try
{
let
content
=
"
hello,world
"
;
await
ss
.
write
(
content
,{
length
:
content
.
length
+
1
});
}
catch
(
err
)
{
console
.
info
(
'
fileio_test_stream_write_async_014 has failed for
'
+
err
);
expect
(
err
.
message
==
"
Invalid option.length, buffer limit exceeded
"
).
assertTrue
();
fileio
.
unlinkSync
(
fpath
);
ss
.
closeSync
();
done
();
}
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录