Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
a96eda29
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看板
未验证
提交
a96eda29
编写于
2月 17, 2023
作者:
O
openharmony_ci
提交者:
Gitee
2月 17, 2023
浏览文件
操作
浏览文件
下载
差异文件
!7518 Add XTS for creatStream and fdopenStream interfacec of mod_fs
Merge pull request !7518 from zhuhongtao666/creat_fdopenStream
上级
eccbee5b
7eb34259
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
2066 addition
and
0 deletion
+2066
-0
storage/storagefileiov9jstest/src/main/js/test/List.test.js
storage/storagefileiov9jstest/src/main/js/test/List.test.js
+32
-0
storage/storagefileiov9jstest/src/main/js/test/members/createStream.test.js
...eiov9jstest/src/main/js/test/members/createStream.test.js
+1093
-0
storage/storagefileiov9jstest/src/main/js/test/members/fdopenStream.test.js
...eiov9jstest/src/main/js/test/members/fdopenStream.test.js
+941
-0
未找到文件。
storage/storagefileiov9jstest/src/main/js/test/List.test.js
浏览文件 @
a96eda29
...
@@ -13,29 +13,61 @@
...
@@ -13,29 +13,61 @@
* limitations under the License.
* limitations under the License.
*/
*/
import
fileIOAccess
from
'
./members/access.test.js
'
import
fileIOClose
from
'
./members/close.test.js
'
import
fileIOCopyfile
from
'
./members/copyFile.test.js
'
import
fileIOCreateStream
from
'
./members/createStream.test.js
'
import
fileIOFdatasync
from
'
./members/fdatasync.test.js
'
import
fileIOFdatasync
from
'
./members/fdatasync.test.js
'
import
fileIOFdOpenStream
from
'
./members/fdopenStream.test.js
'
import
fileIOFileLock
from
'
./members/fileLock.test.js
'
import
fileIOFileLock
from
'
./members/fileLock.test.js
'
import
fileIOFsync
from
'
./members/fsync.test.js
'
import
fileIOFsync
from
'
./members/fsync.test.js
'
import
fileIOHash
from
'
./members/hash.test.js
'
import
fileIOListfile
from
'
./members/listFile.test.js
'
import
fileIOListfile
from
'
./members/listFile.test.js
'
import
fileIOLstat
from
'
./members/lstat.test.js
'
import
fileIOLstat
from
'
./members/lstat.test.js
'
import
fileIOMkdir
from
'
./members/mkdir.test.js
'
import
fileIOMkdtemp
from
'
./members/mkdtemp.test.js
'
import
fileIOMoveFile
from
'
./members/moveFile.test.js
'
import
fileIOMoveFile
from
'
./members/moveFile.test.js
'
import
fileIOOpen
from
'
./members/open.test.js
'
import
fileIOOpen
from
'
./members/open.test.js
'
import
fileIORead
from
'
./members/read.test.js
'
import
fileIORead
from
'
./members/read.test.js
'
import
fileIOReadtext
from
'
./members/readtext.test.js
'
import
fileIORename
from
'
./members/rename.test.js
'
import
fileIORmdir
from
'
./members/rmdir.test
'
import
fileIOStat
from
'
./members/stat.test.js
'
import
fileIOStat
from
'
./members/stat.test.js
'
import
fileIOStreamClose
from
'
./class_stream/close.test.js
'
import
fileIOStreamFlush
from
'
./class_stream/flush.test.js
'
import
fileIOStreamRead
from
'
./class_stream/read.test.js
'
import
fileIOStreamWrite
from
'
./class_stream/write.test.js
'
import
fileIOSymlink
from
'
./members/symlink.test.js
'
import
fileIOSymlink
from
'
./members/symlink.test.js
'
import
fileIOTruncate
from
'
./members/truncate.test.js
'
import
fileIOTruncate
from
'
./members/truncate.test.js
'
import
fileIOUnlink
from
'
./members/unlink.test.js
'
import
fileIOWrite
from
'
./members/write.test.js
'
import
fileIOWrite
from
'
./members/write.test.js
'
export
default
function
testsuite
()
{
export
default
function
testsuite
()
{
fileIOAccess
()
fileIOClose
()
fileIOCopyfile
()
fileIOCreateStream
()
fileIOFdatasync
()
fileIOFdatasync
()
fileIOFdOpenStream
()
fileIOFileLock
()
fileIOFileLock
()
fileIOFsync
()
fileIOFsync
()
fileIOHash
()
fileIOListfile
()
fileIOListfile
()
fileIOLstat
()
fileIOLstat
()
fileIOMkdir
()
fileIOMkdtemp
()
fileIOMoveFile
()
fileIOMoveFile
()
fileIOOpen
()
fileIOOpen
()
fileIORead
()
fileIORead
()
fileIOReadtext
()
fileIORename
()
fileIORmdir
()
fileIOStat
()
fileIOStat
()
fileIOStreamClose
()
fileIOStreamFlush
()
fileIOStreamRead
()
fileIOStreamWrite
()
fileIOSymlink
()
fileIOSymlink
()
fileIOTruncate
()
fileIOTruncate
()
fileIOUnlink
()
fileIOWrite
()
fileIOWrite
()
}
}
storage/storagefileiov9jstest/src/main/js/test/members/createStream.test.js
0 → 100644
浏览文件 @
a96eda29
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
{
fileIO
,
FILE_CONTENT
,
prepareFile
,
nextFileName
,
describe
,
it
,
expect
,
}
from
'
../Common
'
;
export
default
function
fileIOCreateStream
()
{
describe
(
'
fileIO_fs_createStream
'
,
function
()
{
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_0000
* @tc.name fileIO_test_create_stream_sync_000
* @tc.desc Test createStreamSync() interface.
* Create stream in 'r' mode and read data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_sync_000
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_sync_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
ss
=
fileIO
.
createStreamSync
(
fpath
,
'
r
'
);
try
{
expect
(
ss
!==
null
).
assertTrue
();
expect
(
ss
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
).
assertTrue
();
ss
.
writeSync
(
FILE_CONTENT
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
ss
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_create_stream_sync_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900005
&&
e
.
message
==
'
I/O error
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_0100
* @tc.name fileIO_test_create_stream_sync_001
* @tc.desc Test createStreamSync() interface.
* File does not exist.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_sync_001
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_sync_001
'
);
try
{
fileIO
.
createStreamSync
(
fpath
,
'
r
'
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_sync_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900002
&&
e
.
message
==
'
No such file or directory
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_0200
* @tc.name fileIO_test_create_stream_sync_002
* @tc.desc Test createStreamSync() interface.
* Create stream in 'r+' mode, reading and writing data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_create_stream_sync_002
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_sync_002
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
ss
=
fileIO
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
expect
(
ss
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
ss
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
ss
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_sync_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_0300
* @tc.name fileIO_test_create_stream_sync_003
* @tc.desc Test createStreamSync() interface.
* Create stream in 'r+' mode, file does not exist.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_sync_003
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_sync_003
'
);
try
{
fileIO
.
createStreamSync
(
fpath
,
'
r+
'
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_sync_003 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900002
&&
e
.
message
==
'
No such file or directory
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_0400
* @tc.name fileIO_test_create_stream_sync_004
* @tc.desc Test createStreamSync() interface.
* Invalid mode.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_sync_004
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_sync_004
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
fileIO
.
createStreamSync
(
fpath
,
'
ohos
'
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_sync_004 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
fileIO
.
unlinkSync
(
fpath
);
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_0500
* @tc.name fileIO_test_create_stream_sync_005
* @tc.desc Test createStreamSync() interface.
* Missing parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_sync_005
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_sync_005
'
);
try
{
fileIO
.
createStreamSync
(
fpath
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_sync_005 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_0600
* @tc.name fileIO_test_create_stream_sync_006
* @tc.desc Test createStreamSync() interface.
* Create stream in 'w' mode, writing data to file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_sync_006
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_sync_006
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
sw
=
fileIO
.
createStreamSync
(
fpath
,
'
w
'
);
try
{
expect
(
sw
!==
null
).
assertTrue
();
expect
(
sw
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
sw
.
readSync
(
new
ArrayBuffer
(
4096
));
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
sw
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_create_stream_sync_006 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900005
&&
e
.
message
==
'
I/O error
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_0700
* @tc.name fileIO_test_create_stream_sync_007
* @tc.desc Test createStreamSync() interface.
* Create stream in 'w' mode and empty contents.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_sync_007
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_sync_007
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
sw
=
fileIO
.
createStreamSync
(
fpath
,
'
w
'
);
expect
(
sw
!==
null
).
assertTrue
();
expect
(
sw
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
sw
.
closeSync
();
let
sr
=
fileIO
.
createStreamSync
(
fpath
,
'
r
'
);
expect
(
sr
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
).
assertTrue
();
sr
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_sync_007 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_0800
* @tc.name fileIO_test_create_stream_sync_008
* @tc.desc Test createStreamSync() interface.
* Create stream in 'w' mode, creat a file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_sync_008
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_sync_008
'
);
try
{
let
sw
=
fileIO
.
createStreamSync
(
fpath
,
'
w
'
);
expect
(
sw
!==
null
).
assertTrue
();
expect
(
sw
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
sw
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_sync_008 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_0900
* @tc.name fileIO_test_create_stream_sync_009
* @tc.desc Test createStreamSync() interface.
* Create stream in 'w+' mode and empty contents.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_sync_009
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_sync_009
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
ss
=
fileIO
.
createStreamSync
(
fpath
,
'
w+
'
);
expect
(
ss
!==
null
).
assertTrue
();
expect
(
ss
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
ss
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
).
assertTrue
();
ss
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_sync_009 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_1000
* @tc.name fileIO_test_create_stream_sync_010
* @tc.desc Test createStreamSync() interface.
* Create stream in 'w+' mode and creat a file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_sync_010
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_sync_010
'
);
try
{
let
ss
=
fileIO
.
createStreamSync
(
fpath
,
'
w+
'
);
expect
(
ss
!==
null
).
assertTrue
();
expect
(
ss
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
ss
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
).
assertTrue
();
ss
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_sync_010 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_1100
* @tc.name fileIO_test_create_stream_sync_011
* @tc.desc Test createStreamSync() interface.
* Create stream in 'a' mode and append contents.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_sync_011
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_sync_011
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
ss
=
fileIO
.
createStreamSync
(
fpath
,
'
a
'
);
expect
(
ss
!==
null
).
assertTrue
();
expect
(
ss
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
ss
.
closeSync
();
let
sr
=
fileIO
.
createStreamSync
(
fpath
,
'
r
'
);
expect
(
sr
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
*
2
).
assertTrue
();
sr
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_sync_011 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_1200
* @tc.name fileIO_test_create_stream_sync_012
* @tc.desc Test createStreamSync() interface.
* Create stream in 'a' mode and creat a file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_sync_012
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_sync_012
'
);
try
{
let
ss
=
fileIO
.
createStreamSync
(
fpath
,
'
a
'
);
expect
(
ss
!==
null
).
assertTrue
();
expect
(
ss
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
ss
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_sync_012 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_1300
* @tc.name fileIO_test_create_stream_sync_013
* @tc.desc Test createStreamSync() interface.
* Create stream in 'a' mode and write data to file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_sync_013
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_sync_013
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
ss
=
fileIO
.
createStreamSync
(
fpath
,
'
a
'
);
try
{
expect
(
ss
!==
null
).
assertTrue
();
expect
(
ss
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
ss
.
readSync
(
new
ArrayBuffer
(
4096
));
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
ss
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_create_stream_sync_013 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900005
&&
e
.
message
==
'
I/O error
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_1400
* @tc.name fileIO_test_create_stream_sync_014
* @tc.desc Test createStreamSync() interface.
* Create stream in 'a+' mode and append contents.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_sync_014
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_sync_014
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
ss
=
fileIO
.
createStreamSync
(
fpath
,
'
a+
'
);
expect
(
ss
!==
null
).
assertTrue
();
expect
(
ss
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
ss
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
*
2
).
assertTrue
();
ss
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_sync_014 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STREAM_CREATESTREAM_SYNC_1500
* @tc.name fileIO_test_create_stream_sync_015
* @tc.desc Test createStreamSync() interface.
* Create stream in 'a+' mode and creat a file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_sync_015
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_sync_015
'
);
try
{
let
ss
=
fileIO
.
createStreamSync
(
fpath
,
'
a+
'
);
expect
(
ss
!==
null
).
assertTrue
();
expect
(
ss
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
ss
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
).
assertTrue
();
ss
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_sync_015 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_0000
* @tc.name fileIO_test_create_stream_async_000
* @tc.desc Test createStream() interfaces. Promise.
* Create stream in 'r' mode and read data from stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_async_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_async_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
ss
=
await
fileIO
.
createStream
(
fpath
,
'
r
'
);
try
{
expect
(
ss
!==
null
).
assertTrue
();
expect
(
ss
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
).
assertTrue
();
ss
.
writeSync
(
FILE_CONTENT
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
ss
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_create_stream_async_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900005
&&
e
.
message
==
'
I/O error
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_0100
* @tc.name fileIO_test_create_stream_async_001
* @tc.desc Test createStream() interfaces. Callback.
* Create stream in 'r' mode and read data from stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_async_001
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_async_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
fileIO
.
createStream
(
fpath
,
'
r
'
,
(
err
,
ss
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_create_stream_async_001 error package:
'
+
JSON
.
stringify
(
err
));
expect
(
false
).
assertTrue
();
}
expect
(
ss
!==
null
).
assertTrue
();
expect
(
ss
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
).
assertTrue
();
ss
.
write
(
FILE_CONTENT
,
(
err
)
=>
{
if
(
err
)
{
ss
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_create_stream_async_001 error: {message:
'
+
err
.
message
+
'
, code:
'
+
err
.
code
+
'
}
'
);
expect
(
err
.
code
==
13900005
&&
err
.
message
==
'
I/O error
'
).
assertTrue
();
done
();
}
else
{
expect
(
false
).
assertTrue
();
}
});
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_async_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_0200
* @tc.name fileIO_test_create_stream_async_002
* @tc.desc Test createStream() interfaces. Promise.
* Create stream in 'r' mode, file does not exist.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_async_002
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_async_002
'
);
try
{
await
fileIO
.
createStream
(
fpath
,
'
r
'
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_async_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900002
&&
e
.
message
==
'
No such file or directory
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_0300
* @tc.name fileIO_test_create_stream_async_003
* @tc.desc Test createStream() interfaces. Callback.
* Create stream in 'r' mode, file does not exist.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_async_003
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_async_003
'
);
try
{
fileIO
.
createStream
(
fpath
,
'
r
'
,
(
err
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_create_stream_async_003 error: {message:
'
+
err
.
message
+
'
, code:
'
+
err
.
code
+
'
}
'
);
expect
(
err
.
code
==
13900002
&&
err
.
message
==
'
No such file or directory
'
).
assertTrue
();
done
();
}
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_async_003 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_0400
* @tc.name fileIO_test_create_stream_async_004
* @tc.desc Test createStream() interfaces. Promise.
* Create stream in 'r+' mode, reading and writing data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
* @tc.require
*/
it
(
'
fileIO_test_create_stream_async_004
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_async_004
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
ss
=
await
fileIO
.
createStream
(
fpath
,
'
r+
'
);
expect
(
ss
!==
null
).
assertTrue
();
expect
(
ss
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
ss
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
ss
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_async_004 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_0500
* @tc.name fileIO_test_create_stream_async_005
* @tc.desc Test createStream() interfaces. Callback.
* Create stream in 'r+' mode, reading and writing data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
* @tc.require
*/
it
(
'
fileIO_test_create_stream_async_005
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_async_005
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
fileIO
.
createStream
(
fpath
,
'
r+
'
,
(
err
,
ss
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_create_stream_async_005 error package:
'
+
JSON
.
stringify
(
err
));
expect
(
false
).
assertTrue
();
}
expect
(
ss
!==
null
).
assertTrue
();
expect
(
ss
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
ss
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
ss
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
done
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_async_005 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_0600
* @tc.name fileIO_test_create_stream_async_006
* @tc.desc Test createStream() interfaces. Promise.
* Create stream in 'r+' mode, File does not exist.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_async_006
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_async_006
'
);
try
{
await
fileIO
.
createStream
(
fpath
,
'
r+
'
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_async_006 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900002
&&
e
.
message
==
'
No such file or directory
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_0700
* @tc.name fileIO_test_create_stream_async_007
* @tc.desc Test createStream() interfaces. Callback.
* Create stream in 'r+' mode, file does not exist.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_async_007
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_async_007
'
);
try
{
fileIO
.
createStream
(
fpath
,
'
r+
'
,
(
err
)
=>
{
console
.
log
(
'
fileIO_test_create_stream_async_007 error: {message:
'
+
err
.
message
+
'
, code:
'
+
err
.
code
+
'
}
'
);
expect
(
err
.
code
==
13900002
&&
err
.
message
==
'
No such file or directory
'
).
assertTrue
();
done
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_async_007 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_0800
* @tc.name fileIO_test_create_stream_async_008
* @tc.desc Test createStream() interfaces. Promise.
* Invalid mode.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_async_008
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_async_008
'
);
try
{
await
fileIO
.
createStream
(
fpath
,
'
ohos
'
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_async_008 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_0900
* @tc.name fileIO_test_create_stream_async_009
* @tc.desc Test createStream() interfaces. Promise.
* Missing parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_async_009
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_async_009
'
);
try
{
await
fileIO
.
createStream
(
fpath
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_async_009 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_1000
* @tc.name fileIO_test_create_stream_async_010
* @tc.desc Test createStream() interfaces. Promise.
* Create stream in 'w' mode and write data to file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_async_010
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_async_010
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
sw
=
await
fileIO
.
createStream
(
fpath
,
'
w
'
);
expect
(
sw
!==
null
).
assertTrue
();
expect
(
sw
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
sw
.
closeSync
();
let
sr
=
fileIO
.
createStreamSync
(
fpath
,
'
r
'
);
expect
(
sr
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
).
assertTrue
();
sr
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_async_010 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_1100
* @tc.name fileIO_test_create_stream_async_011
* @tc.desc Test createStream() interfaces. Promise.
* Create stream in 'w' mode, can't to read data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_async_011
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_async_011
'
);
let
sw
=
await
fileIO
.
createStream
(
fpath
,
'
w
'
);
try
{
expect
(
sw
!==
null
).
assertTrue
();
expect
(
sw
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
sw
.
readSync
(
new
ArrayBuffer
(
4096
));
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
sw
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_create_stream_async_011 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900005
&&
e
.
message
==
'
I/O error
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_1200
* @tc.name fileIO_test_create_stream_async_012
* @tc.desc Test createStream() interfaces. Callback.
* Create stream in 'w' mode, can't to read data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_async_012
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_async_012
'
);
try
{
fileIO
.
createStream
(
fpath
,
'
w
'
,
(
err
,
sw
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_create_stream_async_012 error package:
'
+
JSON
.
stringify
(
err
));
expect
(
false
).
assertTrue
();
}
expect
(
sw
!==
null
).
assertTrue
();
expect
(
sw
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
sw
.
read
(
new
ArrayBuffer
(
4096
),
(
err
)
=>
{
if
(
err
)
{
sw
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_create_stream_async_012 error: {message:
'
+
err
.
message
+
'
, code:
'
+
err
.
code
+
'
}
'
);
expect
(
err
.
code
==
13900005
&&
err
.
message
==
'
I/O error
'
).
assertTrue
();
done
();
}
else
{
expect
(
false
).
assertTrue
();
}
});
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_async_012 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_1300
* @tc.name fileIO_test_create_stream_async_013
* @tc.desc Test createStream() interfaces. Promise.
* Create stream in 'w+' mode and write/read data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_async_013
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_async_013
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
ss
=
await
fileIO
.
createStream
(
fpath
,
'
w+
'
);
expect
(
ss
!==
null
).
assertTrue
();
expect
(
ss
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
ss
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
).
assertTrue
();
ss
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_async_013 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_1400
* @tc.name fileIO_test_create_stream_async_014
* @tc.desc Test createStream() interfaces. Promise.
* Create stream in 'w+' mode and creat a file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_async_014
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_async_014
'
);
try
{
let
ss
=
await
fileIO
.
createStream
(
fpath
,
'
w+
'
);
expect
(
ss
!==
null
).
assertTrue
();
expect
(
ss
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
ss
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
).
assertTrue
();
ss
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_async_014 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_1500
* @tc.name fileIO_test_create_stream_async_015
* @tc.desc Test createStream() interfaces. Callback.
* Create stream in 'w+' mode and creat a file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_async_015
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_async_015
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
fileIO
.
createStream
(
fpath
,
'
w+
'
,
(
err
,
ss
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_create_stream_async_015 error package:
'
+
JSON
.
stringify
(
err
));
expect
(
false
).
assertTrue
();
}
expect
(
ss
!==
null
).
assertTrue
();
expect
(
ss
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
ss
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
).
assertTrue
();
ss
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
done
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_async_015 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_1600
* @tc.name fileIO_test_create_stream_async_016
* @tc.desc Test createStream() interfaces. Promise.
* Create stream in 'a' mode and append content to file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_async_016
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_async_016
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
sa
=
await
fileIO
.
createStream
(
fpath
,
'
a
'
);
expect
(
sa
!==
null
).
assertTrue
();
expect
(
sa
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
sa
.
closeSync
();
let
sr
=
fileIO
.
createStreamSync
(
fpath
,
'
r
'
);
expect
(
sr
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
*
2
).
assertTrue
();
sr
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_async_016 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_1700
* @tc.name fileIO_test_create_stream_async_017
* @tc.desc Test createStream() interfaces. Promise.
* Create stream in 'a' mode and can't to read data from stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_async_017
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_async_017
'
);
let
sa
=
await
fileIO
.
createStream
(
fpath
,
'
a
'
);
try
{
expect
(
sa
!==
null
).
assertTrue
();
expect
(
sa
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
sa
.
readSync
(
new
ArrayBuffer
(
4096
));
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
sa
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_create_stream_async_017 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900005
&&
e
.
message
==
'
I/O error
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_1800
* @tc.name fileIO_test_create_stream_async_018
* @tc.desc Test createStream() interfaces. Callback.
* Create stream in 'a' mode and can't to read data from stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_async_018
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_async_018
'
);
try
{
fileIO
.
createStream
(
fpath
,
'
a
'
,
(
err
,
sa
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_create_stream_async_018 error package:
'
+
JSON
.
stringify
(
err
));
expect
(
false
).
assertTrue
();
}
expect
(
sa
!==
null
).
assertTrue
();
expect
(
sa
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
sa
.
read
(
new
ArrayBuffer
(
4096
),
(
err
)
=>
{
if
(
err
)
{
sa
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_create_stream_async_018 error: {message:
'
+
err
.
message
+
'
, code:
'
+
err
.
code
+
'
}
'
);
expect
(
err
.
code
==
13900005
&&
err
.
message
==
'
I/O error
'
).
assertTrue
();
done
();
}
else
{
expect
(
false
).
assertTrue
();
}
})
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_async_018 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_1900
* @tc.name fileIO_test_create_stream_async_019
* @tc.desc Test createStream() interfaces. Promise.
* Create stream in 'a+' mode and append content to file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_async_019
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_async_019
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
sa
=
await
fileIO
.
createStream
(
fpath
,
'
a+
'
);
expect
(
sa
!==
null
).
assertTrue
();
expect
(
sa
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
sa
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
*
2
).
assertTrue
();
sa
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_async_019 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_2000
* @tc.name fileIO_test_create_stream_async_020
* @tc.desc Test createStream() interfaces. Promise.
* Create stream in 'a+' mode and creat a file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_async_020
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_async_019
'
);
try
{
let
sa
=
await
fileIO
.
createStream
(
fpath
,
'
a+
'
);
expect
(
sa
!==
null
).
assertTrue
();
expect
(
sa
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
sa
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
).
assertTrue
();
sa
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_async_020 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_CREATE_CREATESTREAM_ASYNC_2100
* @tc.name fileIO_test_create_stream_async_021
* @tc.desc Test createStream() interfaces. Callback.
* Create stream in 'a+' mode and append content to file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_create_stream_async_021
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_create_stream_async_021
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
fileIO
.
createStream
(
fpath
,
'
a+
'
,
(
err
,
sa
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_create_stream_async_021 error package:
'
+
JSON
.
stringify
(
err
));
expect
(
false
).
assertTrue
();
}
expect
(
sa
!==
null
).
assertTrue
();
expect
(
sa
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
sa
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
*
2
).
assertTrue
();
sa
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
done
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_create_stream_async_021 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
});
}
storage/storagefileiov9jstest/src/main/js/test/members/fdopenStream.test.js
0 → 100644
浏览文件 @
a96eda29
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
{
fileIO
,
FILE_CONTENT
,
prepareFile
,
nextFileName
,
isIntNum
,
describe
,
it
,
expect
,
}
from
'
../Common
'
;
export
default
function
fileIOFdOpenStream
()
{
describe
(
'
fileIO_fs_FdOpenStream
'
,
async
function
()
{
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0000
* @tc.name fileIO_test_fdopenstream_sync_000
* @tc.desc Test fdopenStreamSync() interface.
* Create a file stream in 'r' mode and read data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_sync_000
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_fdopenstream_sync_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
fp
=
fileIO
.
fdopenStreamSync
(
file
.
fd
,
'
r
'
);
try
{
expect
(
fp
!==
null
).
assertTrue
();
expect
(
fp
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
).
assertTrue
();
fp
.
writeSync
(
FILE_CONTENT
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fp
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_fdopenstream_sync_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900005
&&
e
.
message
==
'
I/O error
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0010
* @tc.name fileIO_test_fdopenstream_sync_001
* @tc.desc Test fdopenStreamSync() interface.
* Invalid file descriptor.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_sync_001
'
,
0
,
async
function
()
{
try
{
fileIO
.
fdopenStreamSync
(
-
1
,
'
r
'
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_fdopenstream_sync_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0200
* @tc.name fileIO_test_fdopenstream_sync_002
* @tc.desc Test fdopenStreamSync() interface.
* Create a file stream in 'r+' mode, reading and writing data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_sync_002
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_fdopenstream_sync_002
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
try
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
fp
=
fileIO
.
fdopenStreamSync
(
file
.
fd
,
'
r+
'
);
expect
(
fp
!==
null
).
assertTrue
();
expect
(
fp
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
fp
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
fp
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_fdopenstream_sync_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0300
* @tc.name fileIO_test_fdopenstream_sync_003
* @tc.desc Test fdopenStreamSync() interface.
* Invalid file descriptor.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_sync_003
'
,
0
,
async
function
()
{
try
{
fileIO
.
fdopenStreamSync
(
-
1
,
'
r+
'
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_fdopenstream_sync_003 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0400
* @tc.name fileIO_test_fdopenstream_sync_004
* @tc.desc Test fdopenStreamSync() interface.
* Invalid mode.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_sync_004
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_fdopenstream_sync_004
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
try
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
fdopenStreamSync
(
file
.
fd
,
'
ohos
'
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_fdopenstream_sync_004 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0500
* @tc.name fileIO_test_fdopenstream_sync_005
* @tc.desc Test fdopenStreamSync() interface.
* Missing parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_sync_005
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_fdopenstream_sync_005
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
try
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
fdopenStreamSync
(
file
.
fd
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_fdopenstream_sync_005 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0600
* @tc.name fileIO_test_fdopenstream_sync_006
* @tc.desc Test fdopenStreamSync() interface.
* Create a file stream in 'w' mode, writing data to file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_sync_006
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_fdopenstream_sync_006
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
fpw
=
fileIO
.
fdopenStreamSync
(
file
.
fd
,
'
w
'
);
try
{
expect
(
fpw
!==
null
).
assertTrue
();
expect
(
fpw
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
fpw
.
readSync
(
new
ArrayBuffer
(
4096
));
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fpw
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_fdopenstream_sync_006 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900005
&&
e
.
message
==
'
I/O error
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0700
* @tc.name fileIO_test_fdopenstream_sync_007
* @tc.desc Test fdopenStreamSync() interface.
* Create a file stream in 'w' mode and empty contents.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_sync_007
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_fdopenstream_sync_007
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file1
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
expect
(
isIntNum
(
file1
.
fd
)).
assertTrue
();
let
fpw
=
fileIO
.
fdopenStreamSync
(
file1
.
fd
,
'
w
'
);
expect
(
fpw
!==
null
).
assertTrue
();
expect
(
fpw
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
fpw
.
closeSync
();
let
file2
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
let
sr
=
fileIO
.
fdopenStreamSync
(
file2
.
fd
,
'
r
'
);
expect
(
sr
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
).
assertTrue
();
sr
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_fdopenstream_sync_007 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0800
* @tc.name fileIO_test_fdopenstream_sync_008
* @tc.desc Test fdopenStreamSync() interface.
* Create a file stream in 'w+' mode and empty contents.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_sync_008
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_fdopenstream_sync_008
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
try
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
fpw
=
fileIO
.
fdopenStreamSync
(
file
.
fd
,
'
w+
'
);
expect
(
fpw
!==
null
).
assertTrue
();
expect
(
fpw
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
fpw
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
).
assertTrue
();
fpw
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_fdopenstream_sync_008 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0900
* @tc.name fileIO_test_fdopenstream_sync_009
* @tc.desc Test fdopenStreamSync() interface.
* Create a file stream in 'a' mode and append contents.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_sync_009
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_fdopenstream_sync_009
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file1
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file1
.
fd
)).
assertTrue
();
let
fpw
=
fileIO
.
fdopenStreamSync
(
file1
.
fd
,
'
a
'
);
expect
(
fpw
!==
null
).
assertTrue
();
expect
(
fpw
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
fpw
.
closeSync
();
let
file2
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
let
sr
=
fileIO
.
fdopenStreamSync
(
file2
.
fd
,
'
r
'
);
expect
(
sr
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
*
2
).
assertTrue
();
sr
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_fdopenstream_sync_009 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0100
* @tc.name fileIO_test_fdopenstream_sync_010
* @tc.desc Test fdopenStreamSync() interface.
* Create a file stream in 'a' mode and write data to file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_sync_010
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_fdopenstream_sync_010
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
sa
=
fileIO
.
fdopenStreamSync
(
file
.
fd
,
'
a
'
);
try
{
expect
(
sa
!==
null
).
assertTrue
();
expect
(
sa
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
sa
.
readSync
(
new
ArrayBuffer
(
4096
));
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
sa
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_fdopenstream_sync_010 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900005
&&
e
.
message
==
'
I/O error
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_SYNC_0110
* @tc.name fileIO_test_fdopenstream_sync_011
* @tc.desc Test fdopenStreamSync() interface.
* Create a file stream in 'a+' mode and append contents.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_sync_011
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_fdopenstream_sync_011
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
try
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
sa
=
fileIO
.
fdopenStreamSync
(
file
.
fd
,
'
a+
'
);
expect
(
sa
!==
null
).
assertTrue
();
expect
(
sa
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
sa
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
*
2
).
assertTrue
();
sa
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_fdopenstream_sync_011 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_0000
* @tc.name fileIO_test_fdopenstream_async_000
* @tc.desc Test fdopenStream() interface. Promise.
* Create a file stream in 'r' mode and read data from stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_async_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_fdopenstream_async_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
let
fp
=
await
fileIO
.
fdopenStream
(
file
.
fd
,
'
r
'
);
try
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
expect
(
fp
!==
null
).
assertTrue
();
expect
(
fp
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
).
assertTrue
();
fp
.
writeSync
(
FILE_CONTENT
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fp
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_fdopenstream_async_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900005
&&
e
.
message
==
'
I/O error
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_0100
* @tc.name fileIO_test_fdopenstream_async_001
* @tc.desc Test fdopenStream() interface. Callback.
* Create a file stream in 'r' mode and read data from stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_async_001
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_fdopenstream_async_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
try
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
fdopenStream
(
file
.
fd
,
'
r
'
,
(
err
,
fp
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_fdopenstream_async_001 error package:
'
+
JSON
.
stringify
(
err
));
expect
(
false
).
assertTrue
();
}
expect
(
fp
!==
null
).
assertTrue
();
expect
(
fp
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
).
assertTrue
();
fp
.
write
(
FILE_CONTENT
,
(
err
)
=>
{
if
(
err
)
{
fp
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_fdopenstream_async_001 error: {message:
'
+
err
.
message
+
'
, code:
'
+
err
.
code
+
'
}
'
);
expect
(
err
.
code
==
13900005
&&
err
.
message
==
'
I/O error
'
).
assertTrue
();
done
();
}
else
{
expect
(
false
).
assertTrue
();
}
});
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_fdopenstream_async_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_0200
* @tc.name fileIO_test_fdopenstream_async_002
* @tc.desc Test fdopenStream() interface.
* Invalid file descriptor.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_async_002
'
,
0
,
async
function
(
done
)
{
try
{
await
fileIO
.
fdopenStream
(
-
1
,
'
r
'
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_fdopenstream_async_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_0300
* @tc.name fileIO_test_fdopenstream_async_003
* @tc.desc Test fdopenStream() interface.
* Invalid file descriptor.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_async_003
'
,
0
,
async
function
(
done
)
{
try
{
fileIO
.
fdopenStream
(
-
1
,
'
r
'
,
(
err
)
=>
{
expect
(
false
).
assertTrue
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_fdopenstream_async_003 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_0400
* @tc.name fileIO_test_fdopenstream_async_004
* @tc.desc Test fdopenStream() interface. Promise.
* Create a file stream in 'r+' mode, reading and writing data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_async_004
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_fdopenstream_async_004
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
try
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
fp
=
await
fileIO
.
fdopenStream
(
file
.
fd
,
'
r+
'
);
expect
(
fp
!==
null
).
assertTrue
();
expect
(
fp
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
fp
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
).
assertTrue
();
fp
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_fdopenstream_async_004 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_0500
* @tc.name fileIO_test_fdopenstream_async_005
* @tc.desc Test fdopenStream() interface. Callback.
* Create a file stream in 'r+' mode, reading and writing data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 1
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_async_005
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_fdopenstream_async_005
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
try
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
fdopenStream
(
file
.
fd
,
'
r+
'
,
(
err
,
fp
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_fdopenstream_async_005 error package:
'
+
JSON
.
stringify
(
err
));
expect
(
false
).
assertTrue
();
}
expect
(
fp
!==
null
).
assertTrue
();
expect
(
fp
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
fp
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
).
assertTrue
();
fp
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
done
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_fdopenstream_async_005 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_0600
* @tc.name fileIO_test_fdopenstream_async_006
* @tc.desc Test fdopenStream() interface. Promise.
* Invalid mode.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_async_006
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_fdopenstream_async_006
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
try
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
await
fileIO
.
fdopenStream
(
file
.
fd
,
'
ohos
'
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_fdopenstream_async_006 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_0700
* @tc.name fileIO_test_fdopenstream_async_007
* @tc.desc Test fdopenStream() interface. Promise.
* Missing parameter.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_async_007
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_fdopenstream_async_007
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
try
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
await
fileIO
.
fdopenStream
(
file
.
fd
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_fdopenstream_async_007 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_0800
* @tc.name fileIO_test_fdopenstream_async_008
* @tc.desc Test fdopenStream() interface. Promise.
* Create a file stream in 'w' mode, can't to read data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_async_008
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_fdopenstream_async_008
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
fpw
=
await
fileIO
.
fdopenStream
(
file
.
fd
,
'
w
'
);
try
{
expect
(
fpw
!==
null
).
assertTrue
();
expect
(
fpw
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
fpw
.
readSync
(
new
ArrayBuffer
(
4096
));
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fpw
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_fdopenstream_async_008 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900005
&&
e
.
message
==
'
I/O error
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_0900
* @tc.name fileIO_test_fdopenstream_async_009
* @tc.desc Test fdopenStream() interface. Callback.
* Create a file stream in 'w' mode, can't to read data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_async_009
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_fdopenstream_async_009
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
try
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
fdopenStream
(
file
.
fd
,
'
w
'
,
(
err
,
fpw
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_fdopenstream_async_009 error package:
'
+
JSON
.
stringify
(
err
));
expect
(
false
).
assertTrue
();
}
expect
(
fpw
!==
null
).
assertTrue
();
expect
(
fpw
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
fpw
.
read
(
new
ArrayBuffer
(
4096
),
(
err
)
=>
{
if
(
err
)
{
fpw
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_fdopenstream_async_009 error: {message:
'
+
err
.
message
+
'
, code:
'
+
err
.
code
+
'
}
'
);
expect
(
err
.
code
==
13900005
&&
err
.
message
==
'
I/O error
'
).
assertTrue
();
done
();
}
else
{
expect
(
false
).
assertTrue
();
}
});
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_fdopenstream_async_009 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_1000
* @tc.name fileIO_test_fdopenstream_async_010
* @tc.desc Test fdopenStream() interface. Promise.
* Create a file stream in 'w' mode and write data to file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_async_010
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_fdopenstream_async_010
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file1
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
let
fpw
=
await
fileIO
.
fdopenStream
(
file1
.
fd
,
'
w
'
);
expect
(
fpw
!==
null
).
assertTrue
();
expect
(
fpw
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
fpw
.
closeSync
();
let
file2
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
let
sr
=
await
fileIO
.
fdopenStream
(
file2
.
fd
,
'
r
'
);
expect
(
sr
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
).
assertTrue
();
sr
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_fdopenstream_async_010 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_1100
* @tc.name fileIO_test_fdopenstream_async_011
* @tc.desc Test fdopenStream() interface. Promise.
* Create a file stream in 'w+' mode and write/read data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_async_011
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_fdopenstream_async_011
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
try
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
fpw
=
await
fileIO
.
fdopenStream
(
file
.
fd
,
'
w+
'
);
expect
(
fpw
!==
null
).
assertTrue
();
expect
(
fpw
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
fpw
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
).
assertTrue
();
fpw
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_fdopenstream_async_011 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_1200
* @tc.name fileIO_test_fdopenstream_async_012
* @tc.desc Test fdopenStream() interface. Callback.
* Create a file stream in 'w+' mode and write/read data from this stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_async_012
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_fdopenstream_async_012
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
try
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
fdopenStream
(
file
.
fd
,
'
w+
'
,
(
err
,
fpw
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_fdopenstream_async_012 error package:
'
+
JSON
.
stringify
(
err
));
expect
(
false
).
assertTrue
();
}
expect
(
fpw
!==
null
).
assertTrue
();
expect
(
fpw
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
fpw
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
).
assertTrue
();
fpw
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
done
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_fdopenstream_async_012 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_1300
* @tc.name fileIO_test_fdopenstream_async_013
* @tc.desc Test fdopenStream() interface. Promise.
* Create a file stream in 'a' mode and append content to file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_async_013
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_fdopenstream_async_013
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file1
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
let
fpw
=
await
fileIO
.
fdopenStream
(
file1
.
fd
,
'
a
'
);
expect
(
fpw
!==
null
).
assertTrue
();
expect
(
fpw
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
fpw
.
closeSync
();
let
file2
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
let
sr
=
await
fileIO
.
fdopenStream
(
file2
.
fd
,
'
r
'
);
expect
(
sr
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
*
2
).
assertTrue
();
sr
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_fdopenstream_async_013 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_1400
* @tc.name fileIO_test_fdopenstream_async_014
* @tc.desc Test fdopenStream() interface. Promise.
* Create a file stream in 'a' mode and can't to read data from stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_async_014
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_fdopenstream_async_014
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
sa
=
await
fileIO
.
fdopenStream
(
file
.
fd
,
'
a
'
);
try
{
expect
(
sa
!==
null
).
assertTrue
();
expect
(
sa
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
sa
.
readSync
(
new
ArrayBuffer
(
4096
));
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
sa
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_fdopenstream_async_014 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900005
&&
e
.
message
==
'
I/O error
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_1500
* @tc.name fileIO_test_fdopenstream_async_015
* @tc.desc Test fdopenStream() interface. Callback.
* Create a file stream in 'a' mode and can't to read data from stream.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_async_015
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_fdopenstream_async_015
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
try
{
fileIO
.
fdopenStream
(
file
.
fd
,
'
a
'
,
(
err
,
sa
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_fdopenstream_async_015 error package:
'
+
JSON
.
stringify
(
err
));
expect
(
false
).
assertTrue
();
}
expect
(
sa
!==
null
).
assertTrue
();
expect
(
sa
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
sa
.
read
(
new
ArrayBuffer
(
4096
),
(
err
)
=>
{
if
(
err
)
{
sa
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_fdopenstream_async_015 error: {message:
'
+
err
.
message
+
'
, code:
'
+
err
.
code
+
'
}
'
);
expect
(
err
.
code
==
13900005
&&
err
.
message
==
'
I/O error
'
).
assertTrue
();
done
();
}
else
{
expect
(
false
).
assertTrue
();
}
});
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_fdopenstream_async_015 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_1600
* @tc.name fileIO_test_fdopenstream_async_016
* @tc.desc Test fdopenStream() interface. Promise.
* Create a file stream in 'a+' mode and append content to file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_async_016
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_fdopenstream_async_016
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
try
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
sa
=
await
fileIO
.
fdopenStream
(
file
.
fd
,
'
a+
'
);
expect
(
sa
!==
null
).
assertTrue
();
expect
(
sa
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
sa
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
*
2
).
assertTrue
();
sa
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_fdopenstream_async_016 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_FDOPENSTREAM_ASYNC_1700
* @tc.name fileIO_test_fdopenstream_async_017
* @tc.desc Test fdopenStream() interface. Callback.
* Create a file stream in 'a+' mode and append content to file.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_fdopenstream_async_017
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_fdopenstream_async_017
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
try
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
fdopenStream
(
file
.
fd
,
'
a+
'
,
(
err
,
sa
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_fdopenstream_async_017 error package:
'
+
JSON
.
stringify
(
err
));
expect
(
false
).
assertTrue
();
}
expect
(
sa
!==
null
).
assertTrue
();
expect
(
sa
.
writeSync
(
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
sa
.
readSync
(
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
*
2
).
assertTrue
();
sa
.
closeSync
();
fileIO
.
unlinkSync
(
fpath
);
done
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_fdopenstream_async_017 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
});
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录