Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
a08a7c44
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看板
提交
a08a7c44
编写于
12月 29, 2022
作者:
Z
zhuhongtao66
提交者:
futurezhou
1月 14, 2023
1
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Modified XTS for read and write interface
Signed-off-by:
N
zhuhongtao66
<
zhuhongtao12@huawei.com
>
上级
eb82e5a8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
1274 addition
and
158 deletion
+1274
-158
storage/storagefileiov9jstest/src/main/js/test/Common.js
storage/storagefileiov9jstest/src/main/js/test/Common.js
+10
-3
storage/storagefileiov9jstest/src/main/js/test/members/read.test.js
...oragefileiov9jstest/src/main/js/test/members/read.test.js
+642
-56
storage/storagefileiov9jstest/src/main/js/test/members/write.test.js
...ragefileiov9jstest/src/main/js/test/members/write.test.js
+622
-99
未找到文件。
storage/storagefileiov9jstest/src/main/js/test/Common.js
浏览文件 @
a08a7c44
...
...
@@ -15,6 +15,7 @@
import
fileio
from
'
@ohos.fileio
'
;
import
fileIO
from
'
@ohos.file.fs
'
;
import
util
from
'
@ohos.util
'
;
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
export
const
FILE_CONTENT
=
'
hello world
'
;
...
...
@@ -53,7 +54,7 @@ export function prepareEmptyFile(fpath) {
export
function
fileToReadOnly
(
fpath
)
{
try
{
let
file
=
file
io
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
CREATE
)
let
file
=
file
IO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
CREATE
)
fileio
.
fchmodSync
(
file
.
fd
,
0o444
)
fileio
.
fsyncSync
(
file
.
fd
)
fileio
.
closeSync
(
file
.
fd
)
...
...
@@ -67,7 +68,7 @@ export function fileToReadOnly(fpath) {
export
function
fileToWriteOnly
(
fpath
)
{
try
{
let
file
=
file
io
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
CREATE
|
fileIO
.
OpenMode
.
WRITE_ONLY
)
let
file
=
file
IO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
CREATE
|
fileIO
.
OpenMode
.
WRITE_ONLY
)
fileio
.
fchmodSync
(
file
.
fd
,
0o222
)
fileio
.
fsyncSync
(
file
.
fd
)
fileio
.
closeSync
(
file
.
fd
)
...
...
@@ -117,6 +118,10 @@ function isIntNum(val) {
return
typeof
val
===
'
number
'
&&
val
%
1
===
0
;
}
function
isBigInt
(
val
)
{
return
typeof
val
===
'
bigint
'
;
}
function
isString
(
str
)
{
return
(
typeof
str
==
'
string
'
)
&&
str
.
constructor
==
String
;
}
...
...
@@ -133,10 +138,12 @@ export {
fileio
,
fileIO
,
isIntNum
,
isBigInt
,
isString
,
isBoolean
,
isInclude
,
describe
,
it
,
expect
expect
,
util
};
\ No newline at end of file
storage/storagefileiov9jstest/src/main/js/test/members/read.test.js
浏览文件 @
a08a7c44
...
...
@@ -15,16 +15,17 @@
import
{
fileio
,
fileIO
,
FILE_CONTENT
,
prepareFile
,
nextFileName
,
isIntNum
,
describe
,
it
,
expect
,
describe
,
it
,
expect
,
util
}
from
'
../Common
'
;
export
default
function
fileIORead
()
{
export
default
function
fileIORead
()
{
describe
(
'
fileIO_fs_read
'
,
function
()
{
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0000
* @tc.name fileIO_test_read_sync_000
* @tc.desc Test readSync() interfaces.
* Open the file in read-only mode, verifying the normal read function.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
...
...
@@ -37,8 +38,9 @@ import {
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
len
=
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
));
expect
(
len
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
))
==
FILE_CONTENT
.
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
...
...
@@ -51,6 +53,7 @@ import {
* @tc.number SUB_DF_FILEIO_READ_SYNC_0100
* @tc.name fileIO_test_read_sync_001
* @tc.desc Test readSync() interfaces.
* Open the file in read-only mode, reading the file with length = 1.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
...
...
@@ -63,10 +66,11 @@ import {
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
len
=
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
length
:
1
,
});
expect
(
len
==
1
).
assertTrue
();
expect
(
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
length
:
1
,
})
==
1
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
...
...
@@ -79,6 +83,7 @@ import {
* @tc.number SUB_DF_FILEIO_READ_SYNC_0200
* @tc.name fileIO_test_read_sync_002
* @tc.desc Test readSync() interfaces.
* Open the file in read-only mode, reading the file with length < 0(Read normal).
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
...
...
@@ -91,10 +96,10 @@ import {
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
l
en
=
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
offset
:
1
,
let
readL
en
=
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
length
:
-
1
,
});
expect
(
len
==
FILE_CONTENT
.
length
-
1
).
assertTrue
();
expect
(
readLen
==
FILE_CONTENT
.
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
...
...
@@ -107,6 +112,7 @@ import {
* @tc.number SUB_DF_FILEIO_READ_SYNC_0300
* @tc.name fileIO_test_read_sync_003
* @tc.desc Test readSync() interfaces.
* Open the file in read-only mode, reading the file with length > the content of file(Read normal).
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
...
...
@@ -115,19 +121,19 @@ import {
it
(
'
fileIO_test_read_sync_003
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_sync_003
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
;
const
invalidLength
=
9999
;
try
{
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
length
:
invalidLength
});
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_sync_003 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
expect
(
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
length
:
FILE_CONTENT
.
length
+
1
,
})
==
FILE_CONTENT
.
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_sync_003 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
...
...
@@ -135,19 +141,28 @@ import {
* @tc.number SUB_DF_FILEIO_READ_SYNC_0400
* @tc.name fileIO_test_read_sync_004
* @tc.desc Test readSync() interfaces.
* Read the file with invalid length > size of ArrayBuffer.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_sync_004
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_sync_004
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
try
{
fileIO
.
readSync
(
-
1
,
new
ArrayBuffer
(
4096
));
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
length
:
4097
,
});
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_read_sync_004 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
139000
08
&&
e
.
message
==
'
Bad file descriptor
'
).
assertTrue
();
expect
(
e
.
code
==
139000
20
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
});
...
...
@@ -155,6 +170,7 @@ import {
* @tc.number SUB_DF_FILEIO_READ_SYNC_0500
* @tc.name fileIO_test_read_sync_005
* @tc.desc Test readSync() interfaces.
* Open the file in read-only mode, reading the file with offset(position) = 1.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
...
...
@@ -167,11 +183,11 @@ import {
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
invalidPos
=
FILE_CONTENT
.
length
+
1
;
let
len
=
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
offset
:
invalidPos
,
});
expect
(
len
==
0
).
assertTrue
();
expect
(
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
offset
:
1
,
})
==
FILE_CONTENT
.
length
-
1
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
...
...
@@ -180,10 +196,153 @@ import {
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0600
* @tc.name fileIO_test_read_sync_006
* @tc.desc Test readSync() interfaces.
* Read the file with invalid offset = -1.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_sync_006
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_sync_006
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
try
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
offset
:
-
1
,
});
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_read_sync_006 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0700
* @tc.name fileIO_test_read_sync_007
* @tc.desc Test readSync() interfaces.
* Open the file in read-only mode, reading the file with offset(position) > the content of file(Read normal).
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_sync_007
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_sync_007
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
expect
(
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
offset
:
FILE_CONTENT
.
length
+
1
,
})
==
0
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_sync_007 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0800
* @tc.name fileIO_test_read_sync_008
* @tc.desc Test readSync() interfaces.
* Open the file in read-only mode, reading the file with offset(position) = 1, length = 10.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_sync_008
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_sync_008
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
expect
(
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
offset
:
1
,
length
:
FILE_CONTENT
.
length
-
1
,
})
==
FILE_CONTENT
.
length
-
1
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_sync_008 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0900
* @tc.name fileIO_test_read_sync_009
* @tc.desc Test readSync() interfaces.
* Read the file with invalid fd.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_sync_009
'
,
0
,
async
function
()
{
try
{
fileIO
.
readSync
(
-
1
,
new
ArrayBuffer
(
4096
));
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_sync_009 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900008
&&
e
.
message
==
'
Bad file descriptor
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_1000
* @tc.name fileIO_test_read_sync_010
* @tc.desc Test readSync() interfaces.
* Verify that the Chinese, English, and symbols can be read correctly.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_sync_010
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_sync_010
'
);
let
CONTENT
=
"
<?xml 你好, 世界 hello world>
"
expect
(
prepareFile
(
fpath
,
CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
buf
=
new
ArrayBuffer
(
4096
);
fileIO
.
readSync
(
file
.
fd
,
buf
);
let
textDecoder
=
new
util
.
TextDecoder
(
"
utf-8
"
,
{
ignoreBOM
:
true
});
let
resultPut
=
textDecoder
.
decode
(
new
Uint8Array
(
buf
),
{
stream
:
true
});
expect
(
resultPut
==
CONTENT
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_sync_010 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0000
* @tc.name fileIO_test_read_async_000
* @tc.desc Test read() interfaces.
* @tc.desc Test read() interfaces. Promise.
* Open the file in read-only mode, verifying the normal read function.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
...
...
@@ -196,8 +355,8 @@ import {
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
re
s
=
await
fileIO
.
read
(
file
.
fd
,
new
ArrayBuffer
(
4096
));
expect
(
re
s
==
FILE_CONTENT
.
length
).
assertTrue
();
let
re
adLen
=
await
fileIO
.
read
(
file
.
fd
,
new
ArrayBuffer
(
4096
));
expect
(
re
adLen
==
FILE_CONTENT
.
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
...
...
@@ -210,7 +369,8 @@ import {
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0100
* @tc.name fileIO_test_read_async_001
* @tc.desc Test read() interfaces.
* @tc.desc Test read() interfaces. Callback.
* Open the file in read-only mode, verifying the normal read function.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
...
...
@@ -223,7 +383,11 @@ import {
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
read
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
async
function
(
err
,
readlen
)
{
fileIO
.
read
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
(
err
,
readlen
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_read_async_001 err package:
'
+
JSON
.
stringify
(
err
));
expect
(
false
).
assertTrue
();
}
expect
(
readlen
==
FILE_CONTENT
.
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
...
...
@@ -238,7 +402,8 @@ import {
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0200
* @tc.name fileIO_test_read_async_002
* @tc.desc Test read() interfaces.
* @tc.desc Test read() interfaces. Promise.
* Open the file in write-only mode, verifying it is not readable.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
...
...
@@ -247,25 +412,26 @@ import {
it
(
'
fileIO_test_read_async_002
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_async_002
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
readlen
=
await
fileIO
.
read
(
file
.
fd
,
new
ArrayBuffer
(
4096
));
expect
(
readlen
==
FILE_CONTENT
.
length
).
assertTrue
();
await
fileIO
.
read
(
file
.
fd
,
new
ArrayBuffer
(
4096
));
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_async_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
expect
(
e
.
code
==
13900008
&&
e
.
message
==
'
Bad file descriptor
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0300
* @tc.name fileIO_test_read_async_003
* @tc.desc Test read() interfaces.
* @tc.desc Test read() interfaces. Callback.
* Open the file in write-only mode, verifying it is not readable.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
...
...
@@ -274,17 +440,20 @@ import {
it
(
'
fileIO_test_read_async_003
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_async_003
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
;
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ
_ONLY
);
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE
_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
readlen
=
await
fileIO
.
read
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
offset
:
1
,
fileIO
.
read
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
(
err
)
=>
{
if
(
err
)
{
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_read_async_003 error package: {
'
+
err
.
message
+
'
, code:
'
+
err
.
code
+
'
}
'
);
expect
(
err
.
code
==
13900008
&&
err
.
message
==
'
Bad file descriptor
'
).
assertTrue
();
done
();
}
});
expect
(
readlen
==
FILE_CONTENT
.
length
-
1
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_async_003 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
...
...
@@ -294,7 +463,8 @@ import {
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0400
* @tc.name fileIO_test_read_async_004
* @tc.desc Test read() interface.
* @tc.desc Test read() interfaces. Promise.
* Open the file in read-only mode, reading the file with offset(position) = 1.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
...
...
@@ -308,9 +478,9 @@ import {
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
readlen
=
await
fileIO
.
read
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
length
:
3
,
offset
:
1
,
});
expect
(
readlen
==
3
).
assertTrue
();
expect
(
readlen
==
FILE_CONTENT
.
length
-
1
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
...
...
@@ -323,7 +493,8 @@ import {
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0500
* @tc.name fileIO_test_read_async_005
* @tc.desc Test read() interfaces.
* @tc.desc Test read() interfaces. Callback.
* Open the file in read-only mode, reading the file with offset(position) = 1.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
...
...
@@ -333,40 +504,455 @@ import {
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_async_005
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
read
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
offset
:
1
,
},
(
err
,
readLen
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_read_async_005 err package
'
+
JSON
.
stringify
(
err
));
expect
(
false
).
assertTrue
();
}
expect
(
readLen
==
FILE_CONTENT
.
length
-
1
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_async_005 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0600
* @tc.name fileIO_test_read_async_006
* @tc.desc Test read() interface. Promise.
* Open the file in read-only mode, reading the file with length = 1.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_async_006
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_async_006
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
readLen
=
await
fileIO
.
read
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
length
:
3
,
});
expect
(
readLen
==
3
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_async_006 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0700
* @tc.name fileIO_test_read_async_007
* @tc.desc Test read() interface. Callback.
* Open the file in read-only mode, reading the file with length = 1.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_async_007
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_async_007
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
read
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
length
:
3
,
},
(
err
,
readLen
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_read_async_007 err package
'
+
JSON
.
stringify
(
err
));
expect
(
false
).
assertTrue
();
}
expect
(
readLen
==
3
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_async_007 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0800
* @tc.name fileIO_test_read_async_008
* @tc.desc Test read() interfaces. Promise.
* Open the file in read-only mode, reading the file with offset > the content of file(Read normal).
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_async_008
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_async_008
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
len
=
await
fileIO
.
read
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
offset
:
FILE_CONTENT
.
length
+
1
,
});
expect
(
isIntNum
(
len
)
).
assertTrue
();
expect
(
len
==
0
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_async_00
5
has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
console
.
log
(
'
fileIO_test_read_async_00
8
has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0600
* @tc.name fileIO_test_read_async_006
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0900
* @tc.name fileIO_test_read_async_009
* @tc.desc Test read() interfaces. Callback.
* Open the file in read-only mode, reading the file with offset > the content of file(Read normal).
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_async_009
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_async_009
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
read
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
offset
:
FILE_CONTENT
.
length
+
1
,
},
(
err
,
len
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_read_async_009 err package
'
+
JSON
.
stringify
(
err
));
expect
(
false
).
assertTrue
();
}
expect
(
len
==
0
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_async_009 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0100
* @tc.name fileIO_test_read_async_010
* @tc.desc Test read() interfaces.
* Open the file in read-only mode, reading the file with offset(position) = 1, length = 11.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_async_006
'
,
0
,
async
function
(
done
)
{
it
(
'
fileIO_test_read_async_010
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_async_010
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
readLen
=
await
fileIO
.
read
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
offset
:
1
,
length
:
FILE_CONTENT
.
length
,
});
expect
(
readLen
==
FILE_CONTENT
.
length
-
1
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_async_010 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_1100
* @tc.name fileIO_test_read_async_011
* @tc.desc Test read() interfaces. Callback.
* Open the file in read-only mode, reading the file with offset(position) = 1, length = 11.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_async_011
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_async_011
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
read
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
offset
:
1
,
length
:
FILE_CONTENT
.
length
,
},
(
err
,
readLen
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_read_async_011 err package:
'
+
JSON
.
stringify
(
err
));
expect
(
false
).
assertTrue
();
}
expect
(
readLen
==
FILE_CONTENT
.
length
-
1
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_async_011 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0120
* @tc.name fileIO_test_read_async_012
* @tc.desc Test read() interfaces. Promise.
* Read with invalid fd parameters.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_async_012
'
,
0
,
async
function
(
done
)
{
try
{
await
fileIO
.
read
(
-
1
,
new
ArrayBuffer
(
4096
));
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_async_0
06
has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
console
.
log
(
'
fileIO_test_read_async_0
12
has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900008
&&
e
.
message
==
'
Bad file descriptor
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_1300
* @tc.name fileIO_test_read_async_013
* @tc.desc Test read() interfaces. Callback.
* Read with invalid fd parameters.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_async_013
'
,
0
,
async
function
(
done
)
{
try
{
fileIO
.
read
(
-
1
,
new
ArrayBuffer
(
4096
),
(
err
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_read_async_013 error package: {
'
+
err
.
message
+
'
, code:
'
+
err
.
code
+
'
}
'
);
expect
(
err
.
code
==
13900008
&&
err
.
message
==
'
Bad file descriptor
'
).
assertTrue
();
done
();
}
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_async_013 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_1400
* @tc.name fileIO_test_read_async_014
* @tc.desc Test read() interfaces. Callback.
* Read with invalid offset < 0.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_async_014
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_async_014
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
const
invalidOffset
=
-
1
;
try
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
read
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
offset
:
invalidOffset
},
()
=>
{
expect
(
false
).
assertTrue
();
});
}
catch
(
e
)
{
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_read_async_014 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_1500
* @tc.name fileIO_test_read_async_015
* @tc.desc Test read() interfaces. Callback.
* Read with invalid length > size of ArrayBuffer(4096).
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_async_015
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_async_015
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
const
invalidLength
=
4097
;
try
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
read
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
length
:
invalidLength
},
()
=>
{
expect
(
false
).
assertTrue
();
});
}
catch
(
e
)
{
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_read_async_015 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_1600
* @tc.name fileIO_test_read_async_016
* @tc.desc Test read() interfaces. Promise.
* Open the file in read-only mode, reading the file with empty option.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_async_016
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_async_016
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
readLen
=
await
fileIO
.
read
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{});
expect
(
readLen
==
FILE_CONTENT
.
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_async_016 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0170
* @tc.name fileIO_test_read_async_017
* @tc.desc Test read() interfaces. Callback.
* Open the file in read-only mode, reading the file with empty option.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_async_017
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_async_017
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
read
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
},
(
err
,
readLen
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_read_async_017 err package
'
+
JSON
.
stringify
(
err
));
expect
(
false
).
assertTrue
();
}
expect
(
readLen
==
FILE_CONTENT
.
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_async_017 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0180
* @tc.name fileIO_test_read_async_018
* @tc.desc Test read() interfaces.
* Open the file in read-only mode, reading the file with length = -1(Read normal).
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_async_018
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_async_018
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
try
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
readLen
=
await
fileIO
.
read
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
length
:
-
1
,
})
expect
(
readLen
==
FILE_CONTENT
.
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_async_018 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0190
* @tc.name fileIO_test_read_async_019
* @tc.desc Test read() interfaces.
* Verify that the Chinese, English, and symbols can be read correctly.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_async_019
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_async_019
'
);
let
CONTENT
=
"
<?xml 你好, 世界 hello world>
"
expect
(
prepareFile
(
fpath
,
CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
buf
=
new
ArrayBuffer
(
4096
);
await
fileIO
.
read
(
file
.
fd
,
buf
);
let
textDecoder
=
new
util
.
TextDecoder
(
"
utf-8
"
,
{
ignoreBOM
:
true
});
let
resultPut
=
textDecoder
.
decodeWithStream
(
new
Uint8Array
(
buf
),
{
stream
:
true
});
expect
(
resultPut
==
CONTENT
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_async_019 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
});
}
storage/storagefileiov9jstest/src/main/js/test/members/write.test.js
浏览文件 @
a08a7c44
...
...
@@ -18,13 +18,14 @@ import {
describe
,
it
,
expect
,
}
from
'
../Common
'
;
export
default
function
fileIOWrite
()
{
export
default
function
fileIOWrite
()
{
describe
(
'
fileIO_fs_write
'
,
function
()
{
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0000
* @tc.name fileIO_test_write_sync_000
* @tc.desc Test writeSync() interfaces.
* Open the file in write-only mode, verifying the normal write function.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
...
...
@@ -37,7 +38,9 @@ import {
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
expect
(
fileIO
.
writeSync
(
file
.
fd
,
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
fileIO
.
writeSync
(
file
.
fd
,
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
...
...
@@ -50,6 +53,7 @@ import {
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0100
* @tc.name fileIO_test_write_sync_001
* @tc.desc Test writeSync() interfaces.
* Open the file in write-only mode, writing a string with encoding = 'utf-8'.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
...
...
@@ -75,11 +79,11 @@ import {
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0200
* @tc.name fileIO_test_write_sync_002
* @tc.desc Test writeSync() interfaces.
* Open the file in write-only mode, writing a string from offset(position) = 1.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
...
...
@@ -94,9 +98,9 @@ import {
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
expect
(
fileIO
.
writeSync
(
file
.
fd
,
FILE_CONTENT
,
{
length
:
FILE_CONTENT
.
length
-
1
,
offset
:
1
,
})
==
FILE_CONTENT
.
length
-
1
).
assertTrue
();
==
FILE_CONTENT
.
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
...
...
@@ -109,6 +113,7 @@ import {
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0300
* @tc.name fileIO_test_write_sync_003
* @tc.desc Test writeSync() interfaces.
* Open the file in write-only mode, writing a string of length = 1.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
...
...
@@ -138,29 +143,29 @@ import {
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0400
* @tc.name fileIO_test_write_sync_004
* @tc.desc Test writeSync() interfaces.
* Open the file in write-only mode, writing a string of length = 1 and offset(position) = 1.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO
_test_write_sync_004
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
file
IO
_test_write_sync_004
'
);
it
(
'
fileio
_test_write_sync_004
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
file
io
_test_write_sync_004
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
const
invalidLength
=
9999
;
let
file
;
try
{
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
writeSync
(
file
.
fd
,
FILE_CONTENT
,
{
length
:
invalidLength
,
})
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
expect
(
fileIO
.
writeSync
(
file
.
fd
,
FILE_CONTENT
,
{
offset
:
1
,
length
:
1
,
})
==
1
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
console
.
info
(
'
fileIO_test_write_sync_004 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileio_test_write_sync_004 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
...
...
@@ -168,18 +173,30 @@ import {
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0500
* @tc.name fileIO_test_write_sync_005
* @tc.desc Test writeSync() interfaces.
* Open the file in write-only mode, writing a string of length = 1, offset(position) = 1, encoding = 'utf-8'.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_sync_005
'
,
0
,
function
()
{
it
(
'
fileIO_test_write_sync_005
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_sync_005
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
fileIO
.
writeSync
(
-
1
,
FILE_CONTENT
);
expect
(
false
).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
expect
(
fileIO
.
writeSync
(
file
.
fd
,
FILE_CONTENT
,
{
offset
:
1
,
length
:
5
,
encoding
:
'
utf-8
'
,
})
==
5
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_sync_005 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900008
&&
e
.
message
==
'
Bad file descriptor
'
).
assertTrue
();
expect
(
null
).
assertFail
();
}
});
...
...
@@ -187,6 +204,7 @@ import {
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0600
* @tc.name fileIO_test_write_sync_006
* @tc.desc Test writeSync() interfaces.
* Write with invalid 'length' option.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
...
...
@@ -195,6 +213,55 @@ import {
it
(
'
fileIO_test_write_sync_006
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_sync_006
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
try
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
const
invalidLength
=
9999
;
fileIO
.
writeSync
(
file
.
fd
,
FILE_CONTENT
,
{
length
:
invalidLength
})
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
console
.
info
(
'
fileIO_test_write_sync_006 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0700
* @tc.name fileIO_test_write_sync_007
* @tc.desc Test writeSync() interfaces.
* Write with invalid fd parameters.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_sync_007
'
,
0
,
function
()
{
try
{
fileIO
.
writeSync
(
-
1
,
FILE_CONTENT
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_sync_007 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900008
&&
e
.
message
==
'
Bad file descriptor
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0800
* @tc.name fileIO_test_write_sync_008
* @tc.desc Test writeSync() interfaces.
* Open the file in write-only mode, writing an ArrayBuffer(4096).
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_sync_008
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_sync_008
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
...
...
@@ -204,33 +271,91 @@ import {
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_sync_00
6
has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
console
.
log
(
'
fileIO_test_write_sync_00
8
has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0900
* @tc.name fileIO_test_write_sync_009
* @tc.desc Test writeSync() interfaces.
* Write with invalid 'length' option.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_sync_009
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_sync_009
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
try
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
const
invalidLength
=
4097
;
fileIO
.
writeSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
length
:
invalidLength
})
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
console
.
info
(
'
fileIO_test_write_sync_009 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_1000
* @tc.name fileIO_test_write_sync_010
* @tc.desc Test writeSync() interfaces.
* Write with invalid 'offset' option.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_sync_010
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_sync_010
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
try
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
const
invalidOffset
=
-
1
;
fileIO
.
writeSync
(
file
.
fd
,
FILE_CONTENT
,
{
offset
:
invalidOffset
});
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
console
.
info
(
'
fileIO_test_write_sync_010 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0000
* @tc.name fileIO_test_write_async_000
* @tc.desc Test write() interfaces.
* @tc.desc Test write() interfaces. Promise.
* Open the file in write-only mode, verifying the normal write function.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_write_async_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_write_async_000
'
);
it
(
'
fileIO_
test_
write_async_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_
test_
write_async_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
expect
(
await
fileIO
.
write
(
file
.
fd
,
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
let
writeLen
=
await
fileIO
.
write
(
file
.
fd
,
FILE_CONTENT
);
expect
(
writeLen
==
FILE_CONTENT
.
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_write_async_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
console
.
log
(
'
fileIO_
test_
write_async_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
...
...
@@ -238,7 +363,8 @@ import {
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0100
* @tc.name fileIO_test_write_async_001
* @tc.desc Test write() interfaces.
* @tc.desc Test write() interfaces. Callback.
* Open the file in write-only mode, verifying the normal write function.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
...
...
@@ -251,10 +377,8 @@ import {
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
writeNum
=
await
fileIO
.
write
(
file
.
fd
,
FILE_CONTENT
,
{
length
:
3
,
});
expect
(
writeNum
==
3
).
assertTrue
();
let
writeLen
=
await
fileIO
.
write
(
file
.
fd
,
FILE_CONTENT
);
expect
(
writeLen
==
FILE_CONTENT
.
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
...
...
@@ -267,7 +391,8 @@ import {
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0200
* @tc.name fileIO_test_write_async_002
* @tc.desc Test write() interfaces.
* @tc.desc Test write() interfaces. Promise.
* Open the file in read-only mode, verifying that it is not writable.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
...
...
@@ -276,28 +401,26 @@ import {
it
(
'
fileIO_test_write_async_002
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_async_002
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
writeNum
=
await
fileIO
.
write
(
file
.
fd
,
FILE_CONTENT
,
{
length
:
3
,
offset
:
5
,
});
expect
(
writeNum
==
3
).
assertTrue
();
await
fileIO
.
write
(
file
.
fd
,
FILE_CONTENT
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_async_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
expect
(
e
.
code
==
13900008
&&
e
.
message
==
'
Bad file descriptor
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0300
* @tc.name fileIO_test_write_async_003
* @tc.desc Test write() interfaces.
* @tc.desc Test write() interfaces. Callback.
* Open the file in read-only mode, verifying that it is not writable.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
...
...
@@ -306,19 +429,19 @@ import {
it
(
'
fileIO_test_write_async_003
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_async_003
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
writeNum
=
await
fileIO
.
write
(
file
.
fd
,
FILE_CONTENT
,
{
length
:
4
,
offset
:
5
,
encoding
:
'
utf-8
'
,
fileIO
.
write
(
file
.
fd
,
FILE_CONTENT
,
(
err
)
=>
{
if
(
err
)
{
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_write_async_003 error package: {
'
+
err
.
message
+
'
, code:
'
+
err
.
code
+
'
}
'
);
expect
(
err
.
code
==
13900008
&&
err
.
message
==
'
Bad file descriptor
'
).
assertTrue
();
done
();
}
});
expect
(
writeNum
==
4
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_async_003 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
...
...
@@ -328,7 +451,8 @@ import {
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0400
* @tc.name fileIO_test_write_async_004
* @tc.desc Test write() interfaces.
* @tc.desc Test write() interfaces. Promise.
* Open the file in write-only mode, writing a string of length = 3.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
...
...
@@ -341,15 +465,12 @@ import {
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
await
fileIO
.
write
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
function
(
error
,
bytesWritten
)
{
expect
(
bytesWritten
==
4096
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
);
let
bytesWritten
=
await
fileIO
.
write
(
file
.
fd
,
FILE_CONTENT
,
{
length
:
3
,
});
expect
(
bytesWritten
==
3
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_async_004 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
...
...
@@ -360,31 +481,30 @@ import {
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0500
* @tc.name fileIO_test_write_async_005
* @tc.desc Test write() interfaces.
* @tc.desc Test write() interfaces. Callback.
* Open the file in write-only mode, writing a string of length = 3.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_async_005
'
,
0
,
async
function
(
done
)
{
it
(
'
fileIO_test_write_async_005
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_async_005
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
await
fileIO
.
write
(
file
.
fd
,
FILE_CONTENT
,
{
length
:
5
,
},
function
(
error
,
bytesWritten
)
{
expect
(
bytesWritten
==
5
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
fileIO
.
write
(
file
.
fd
,
FILE_CONTENT
,
{
length
:
3
},
(
err
,
bytesWritten
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_write_async_005 err package:
'
+
JSON
.
stringify
(
err
));
expect
(
false
).
assertTrue
();
}
);
expect
(
bytesWritten
==
3
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_async_005 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
...
...
@@ -394,62 +514,193 @@ import {
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0600
* @tc.name fileIO_test_write_async_006
* @tc.desc Test write() interfaces.
* @tc.desc Test write() interfaces. Promise.
* Open the file in write-only mode, writing a string from offset(position) = 5.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_async_006
'
,
0
,
async
function
(
done
)
{
it
(
'
fileIO_test_write_async_006
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_async_006
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
await
fileIO
.
write
(
file
.
fd
,
FILE_CONTENT
,
{
length
:
5
,
let
writeNum
=
await
fileIO
.
write
(
file
.
fd
,
FILE_CONTENT
,
{
offset
:
5
,
});
expect
(
writeNum
==
FILE_CONTENT
.
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_async_006 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0700
* @tc.name fileIO_test_write_async_007
* @tc.desc Test write() interfaces. Callback.
* Open the file in write-only mode, writing a string from offset(position) = 5.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_async_007
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_async_007
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
write
(
file
.
fd
,
FILE_CONTENT
,
{
offset
:
5
},
(
err
,
bytesWritten
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_write_async_007 err package:
'
+
JSON
.
stringify
(
err
));
expect
(
false
).
assertTrue
();
}
expect
(
bytesWritten
==
FILE_CONTENT
.
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_async_007 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0800
* @tc.name fileIO_test_write_async_008
* @tc.desc Test write() interfaces. Promise.
* Open the file in write-only mode, writing a string of with length = 3 and offset = 5.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_async_008
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_async_008
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
writeNum
=
await
fileIO
.
write
(
file
.
fd
,
FILE_CONTENT
,
{
length
:
3
,
offset
:
5
,
});
expect
(
writeNum
==
3
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_async_008 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0900
* @tc.name fileIO_test_write_async_009
* @tc.desc Test write() interfaces. Callback.
* Open the file in write-only mode, writing a string of with length = 3 and offset = 5.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_async_009
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_async_009
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
write
(
file
.
fd
,
FILE_CONTENT
,
{
length
:
3
,
offset
:
5
,
},
function
(
error
,
bytesWritten
)
{
expect
(
bytesWritten
==
5
).
assertTrue
();
},
(
err
,
writeNum
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_write_async_009 err package:
'
+
JSON
.
stringify
(
err
));
expect
(
false
).
assertTrue
();
}
expect
(
writeNum
==
3
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
);
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_async_00
6
has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
console
.
log
(
'
fileIO_test_write_async_00
9
has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_
07
00
* @tc.name fileIO_test_write_async_0
07
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_
10
00
* @tc.name fileIO_test_write_async_0
10
* @tc.desc Test write() interfaces.
* Open the file in write-only mode, writing a string of with length = 3, offset = 5 and encoding = 'utf-8'.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_async_007
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_async_0
07
'
);
it
(
'
fileIO_test_write_async_010
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_async_0
10
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
await
fileIO
.
write
(
file
.
fd
,
FILE_CONTENT
,
{
let
writeNum
=
await
fileIO
.
write
(
file
.
fd
,
FILE_CONTENT
,
{
length
:
4
,
offset
:
5
,
encoding
:
'
utf-8
'
,
});
expect
(
writeNum
==
4
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_async_010 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_1100
* @tc.name fileIO_test_write_async_011
* @tc.desc Test write() interfaces. Callback.
* Open the file in write-only mode, writing a string of with length = 3, offset = 5 and encoding = 'utf-8'.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_async_011
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_async_011
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
write
(
file
.
fd
,
FILE_CONTENT
,
{
length
:
5
,
offset
:
5
,
encoding
:
'
utf-8
'
,
},
function
(
error
,
bytesWritten
)
{
},
(
err
,
bytesWritten
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_write_async_011 err package:
'
+
JSON
.
stringify
(
err
));
expect
(
false
).
assertTrue
();
}
expect
(
bytesWritten
==
5
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
...
...
@@ -457,9 +708,281 @@ import {
}
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_async_007 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
console
.
log
(
'
fileIO_test_write_async_011 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_1200
* @tc.name fileIO_test_write_async_012
* @tc.desc Test write() interfaces. Promise.
* Open the file in write-only mode, writing an ArrayBuffer(4096).
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_async_012
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_async_012
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
bytesWritten
=
await
fileIO
.
write
(
file
.
fd
,
new
ArrayBuffer
(
4096
));
expect
(
bytesWritten
==
4096
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_async_012 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_1300
* @tc.name fileIO_test_write_async_013
* @tc.desc Test write() interfaces. Callback.
* Open the file in write-only mode, writing an ArrayBuffer(4096).
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_async_013
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_async_013
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
write
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
(
err
,
bytesWritten
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_write_async_013 err package:
'
+
JSON
.
stringify
(
err
));
expect
(
false
).
assertTrue
();
}
expect
(
bytesWritten
==
4096
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_async_013 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_1400
* @tc.name fileIO_test_write_async_014
* @tc.desc Test write() interfaces. Promise.
* Open the file in write-only mode, writing a string with empty option parameters.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_async_014
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_async_014
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
bytesWritten
=
await
fileIO
.
write
(
file
.
fd
,
FILE_CONTENT
,
{});
expect
(
bytesWritten
==
FILE_CONTENT
.
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_async_014 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_1500
* @tc.name fileIO_test_write_async_015
* @tc.desc Test write() interfaces. Callback.
* Open the file in write-only mode, writing a string with empty option parameters.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_async_015
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_async_015
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
write
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
},
(
err
,
bytesWritten
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_write_async_015 err package
'
+
JSON
.
stringify
(
err
));
expect
(
false
).
assertTrue
();
}
expect
(
bytesWritten
==
4096
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_async_015 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_1600
* @tc.name fileIO_test_write_async_016
* @tc.desc Test write() interfaces. Promise.
* Write with invalid fd parameters.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_async_016
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_async_016
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
await
fileIO
.
write
(
-
1
,
FILE_CONTENT
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileio
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_write_async_016 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900008
&&
e
.
message
==
'
Bad file descriptor
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_1700
* @tc.name fileIO_test_write_async_017
* @tc.desc Test write() interfaces. Callback.
* Write with invalid fd parameters.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_async_017
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_async_017
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
fileIO
.
write
(
-
1
,
FILE_CONTENT
,
(
err
)
=>
{
if
(
err
)
{
fileio
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_open_async_020 error package: {
'
+
err
.
message
+
'
, code:
'
+
err
.
code
+
'
}
'
);
expect
(
err
.
code
==
13900008
&&
err
.
message
==
'
Bad file descriptor
'
).
assertTrue
();
done
();
}
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_async_017 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_1800
* @tc.name fileIO_test_write_async_018
* @tc.desc Test write() interfaces. Callback.
* Write with invalid length parameters.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_async_018
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_async_018
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
try
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
const
invalidLength
=
9999
;
fileIO
.
write
(
file
.
fd
,
FILE_CONTENT
,
{
length
:
invalidLength
,
},
()
=>
{
expect
(
false
).
assertTrue
();
})
}
catch
(
e
)
{
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
console
.
info
(
'
fileIO_test_write_async_018 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_1900
* @tc.name fileIO_test_write_async_019
* @tc.desc Test write() interfaces. Callback.
* Write with invalid length parameters.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_async_019
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_async_019
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
try
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
const
invalidLength
=
4097
;
fileIO
.
write
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
length
:
invalidLength
,
},
()
=>
{
expect
(
false
).
assertTrue
();
})
}
catch
(
e
)
{
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
console
.
info
(
'
fileIO_test_write_async_019 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_2000
* @tc.name fileIO_test_write_async_020
* @tc.desc Test write() interfaces. Callback.
* Write with invalid length parameters.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_async_020
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_async_020
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
try
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
const
invalidOffset
=
-
1
;
fileIO
.
write
(
file
.
fd
,
FILE_CONTENT
,
{
offset
:
invalidOffset
,
},
()
=>
{
expect
(
false
).
assertTrue
();
})
}
catch
(
e
)
{
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
console
.
info
(
'
fileIO_test_write_async_020 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
done
();
}
});
})
}
鸿蒙社区
@harmonycommunity
mentioned in commit
dae79541
·
1月 17, 2023
mentioned in commit
dae79541
mentioned in commit dae795417c2d1b403037967ef99d514160c2dce9
开关提交列表
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录