Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
c1799ac5
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
c1799ac5
编写于
10月 21, 2022
作者:
O
openharmony_ci
提交者:
Gitee
10月 21, 2022
浏览文件
操作
浏览文件
下载
差异文件
!5906 fileIO模块open、read、stat、truncate、write接口用例增加
Merge pull request !5906 from gsl_1234/master
上级
b275bddf
7349fae1
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
3668 addition
and
2 deletion
+3668
-2
storage/storagefileiojstest/src/main/js/test/Common.js
storage/storagefileiojstest/src/main/js/test/Common.js
+3
-1
storage/storagefileiojstest/src/main/js/test/List.test.js
storage/storagefileiojstest/src/main/js/test/List.test.js
+11
-1
storage/storagefileiojstest/src/main/js/test/module_fileio/members/open_file.test.js
.../src/main/js/test/module_fileio/members/open_file.test.js
+490
-0
storage/storagefileiojstest/src/main/js/test/module_fileio/members/readV9.test.js
...est/src/main/js/test/module_fileio/members/readV9.test.js
+374
-0
storage/storagefileiojstest/src/main/js/test/module_fileio/members/statV9.test.js
...est/src/main/js/test/module_fileio/members/statV9.test.js
+2021
-0
storage/storagefileiojstest/src/main/js/test/module_fileio/members/truncateV9.test.js
...src/main/js/test/module_fileio/members/truncateV9.test.js
+318
-0
storage/storagefileiojstest/src/main/js/test/module_fileio/members/writeV9.test.js
...st/src/main/js/test/module_fileio/members/writeV9.test.js
+451
-0
未找到文件。
storage/storagefileiojstest/src/main/js/test/Common.js
浏览文件 @
c1799ac5
/*
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021
-2022
Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* You may obtain a copy of the License at
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
*/
*/
import
fileio
from
'
@ohos.fileio
'
;
import
fileio
from
'
@ohos.fileio
'
;
import
fileIO
from
'
@ohos.file.fs
'
;
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
export
const
FILE_CONTENT
=
'
hello world
'
;
export
const
FILE_CONTENT
=
'
hello world
'
;
...
@@ -126,6 +127,7 @@ function isInclude(error, message) {
...
@@ -126,6 +127,7 @@ function isInclude(error, message) {
export
{
export
{
fileio
,
fileio
,
fileIO
,
isIntNum
,
isIntNum
,
isString
,
isString
,
isBoolean
,
isBoolean
,
...
...
storage/storagefileiojstest/src/main/js/test/List.test.js
浏览文件 @
c1799ac5
/*
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Copyright (C) 2021
-2022
Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* You may obtain a copy of the License at
...
@@ -65,6 +65,11 @@ import fileioSymlink from './module_fileio/members/symlink.test.js'
...
@@ -65,6 +65,11 @@ import fileioSymlink from './module_fileio/members/symlink.test.js'
import
fileioTruncate
from
'
./module_fileio/members/truncate.test.js
'
import
fileioTruncate
from
'
./module_fileio/members/truncate.test.js
'
import
fileioUnlink
from
'
./module_fileio/members/unlink.test.js
'
import
fileioUnlink
from
'
./module_fileio/members/unlink.test.js
'
import
fileioWrite
from
'
./module_fileio/members/write.test.js
'
import
fileioWrite
from
'
./module_fileio/members/write.test.js
'
import
fileIOOpenFile
from
'
./module_fileio/members/open_file.test.js
'
import
fileIORead
from
'
./module_fileio/members/readV9.test.js
'
import
fileIOStat
from
'
./module_fileio/members/statV9.test.js
'
import
fileIOTruncate
from
'
./module_fileio/members/truncateV9.test.js
'
import
fileIOWrite
from
'
./module_fileio/members/writeV9.test.js
'
export
default
function
testsuite
()
{
export
default
function
testsuite
()
{
fileIOTest
()
fileIOTest
()
fileIOTestDir
()
fileIOTestDir
()
...
@@ -118,4 +123,9 @@ export default function testsuite() {
...
@@ -118,4 +123,9 @@ export default function testsuite() {
fileioTruncate
()
fileioTruncate
()
fileioUnlink
()
fileioUnlink
()
fileioWrite
()
fileioWrite
()
fileIOOpenFile
()
fileIORead
()
fileIOStat
()
fileIOTruncate
()
fileIOWrite
()
}
}
storage/storagefileiojstest/src/main/js/test/module_fileio/members/open_file.test.js
0 → 100644
浏览文件 @
c1799ac5
/*
* Copyright (C) 2022 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 from '@ohos.file.fs';
import
{
fileio
,
fileIO
,
FILE_CONTENT
,
prepareFile
,
nextFileName
,
isIntNum
,
describe
,
it
,
expect
,
}
from
'
../../Common
'
;
export
default
function
fileIOOpenFile
()
{
describe
(
'
fileIO_fs_open_file
'
,
function
()
{
/**
* @tc.number SUB_DF_FILEIO_OPENIO_SYNC_0000
* @tc.name fileIO_open_sync_000
* @tc.desc Test openSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_open_sync_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_open_sync_000
'
);
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
0o102
);
console
.
info
(
'
fileIO_open_sync_000, fd:
'
+
file
.
fd
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_open_sync_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPENIO_SYNC_0010
* @tc.name fileIO_open_sync_001
* @tc.desc Test openSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_open_sync_001
'
,
0
,
function
()
{
try
{
fileIO
.
openSync
();
expect
(
null
).
assertFail
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_open_sync_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
;
}
});
/**
* @tc.number SUB_DF_FILEIO_OPENIO_SYNC_0020
* @tc.name fileIO_open_sync_002
* @tc.desc Test openSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_open_sync_002
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_open_sync_002
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
0o202
);
console
.
info
(
'
fileIO_open_sync_002, fd:
'
+
file
.
fd
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_open_sync_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPENIO_SYNC_0030
* @tc.name fileIO_open_sync_003
* @tc.desc Test openSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_open_sync_003
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_open_sync_003
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
0o1002
);
console
.
info
(
'
fileIO_open_sync_003, fd:
'
+
file
.
fd
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_open_sync_003 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPENIO_SYNC_0040
* @tc.name fileIO_open_sync_004
* @tc.desc Test openSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_open_sync_004
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_open_sync_004
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
0o2002
);
console
.
info
(
'
fileIO_open_sync_004, fd:
'
+
file
.
fd
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
length
=
100
;
let
num
=
fileIO
.
writeSync
(
file
.
fd
,
new
ArrayBuffer
(
length
));
expect
(
num
==
length
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_open_sync_004 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPENIO_SYNC_0050
* @tc.name fileIO_open_sync_005
* @tc.desc Test openSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_open_sync_005
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_open_sync_005
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
0o4002
);
console
.
info
(
'
fileIO_open_sync_005, fd:
'
+
file
.
fd
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_open_sync_005 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPENIO_SYNC_0060
* @tc.name fileIO_open_sync_006
* @tc.desc Test openSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_open_sync_006
'
,
0
,
async
function
(
done
)
{
let
dpath
=
await
nextFileName
(
'
fileIO_open_sync_006
'
);
fileio
.
mkdirSync
(
dpath
);
try
{
let
file
=
fileIO
.
openSync
(
dpath
,
0o200000
);
console
.
info
(
'
fileIO_open_sync_006, fd:
'
+
file
.
fd
);
fileio
.
rmdirSync
(
dpath
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_open_sync_006 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
}
});
/**
* @tc.number SUB_DF_FILEIO_OPENIO_SYNC_0070
* @tc.name fileIO_open_sync_007
* @tc.desc Test openSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_open_sync_007
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_open_sync_007
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
0o400002
);
console
.
info
(
'
fileIO_open_sync_007, fd:
'
+
file
.
fd
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_open_sync_007 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPENIO_SYNC_0080
* @tc.name fileIO_open_sync_008
* @tc.desc Test openSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_open_sync_008
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_open_sync_008
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
0o4010002
);
console
.
info
(
'
fileIO_open_sync_008, fd:
'
+
file
.
fd
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_open_sync_008 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_FILE_ASYNC_0000
* @tc.name fileIO_open_async_000
* @tc.desc Test openAsync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_open_async_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_open_async_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
await
fileIO
.
open
(
fpath
,
0o102
);
console
.
info
(
'
fileIO_open_async_000, fd:
'
+
file
.
fd
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_open_async_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPENIO_ASYNC_0010
* @tc.name fileIO_open_async_001
* @tc.desc Test openAsync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_open_async_001
'
,
0
,
function
()
{
try
{
fileIO
.
openAsync
();
expect
(
null
).
assertFail
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_open_async_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
;
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_FILE_ASYNC_0020
* @tc.name fileIO_open_async_002
* @tc.desc Test openAsync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_open_async_002
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_open_async_002
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
await
fileIO
.
open
(
fpath
,
0o202
);
console
.
info
(
'
fileIO_open_async_002, fd:
'
+
file
.
fd
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_open_async_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_FILE_ASYNC_0030
* @tc.name fileIO_open_async_003
* @tc.desc Test openAsync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_open_async_003
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_open_async_003
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
await
fileIO
.
open
(
fpath
,
0o1002
);
console
.
info
(
'
fileIO_open_async_003, fd:
'
+
file
.
fd
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_open_async_003 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_FILE_ASYNC_0040
* @tc.name fileIO_open_async_004
* @tc.desc Test openAsync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_open_async_004
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_open_async_004
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
await
fileIO
.
open
(
fpath
,
0o2002
);
console
.
info
(
'
fileIO_open_async_004, fd:
'
+
file
.
fd
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
length
=
100
;
let
num
=
fileIO
.
writeSync
(
file
.
fd
,
new
ArrayBuffer
(
length
));
expect
(
num
==
length
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_open_async_004 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0050
* @tc.name fileIO_open_async_005
* @tc.desc Test openAsync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_open_async_005
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_open_async_005
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
await
fileIO
.
open
(
fpath
,
0o4002
);
console
.
info
(
'
fileIO_open_async_005, fd:
'
+
file
.
fd
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_open_async_005 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_FILE_ASYNC_0060
* @tc.name fileIO_open_async_006
* @tc.desc Test openAsync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_open_async_006
'
,
0
,
async
function
(
done
)
{
let
dpath
=
await
nextFileName
(
'
fileIO_open_async_006
'
);
fileio
.
mkdirSync
(
dpath
);
try
{
let
file
=
await
fileIO
.
open
(
dpath
,
0o200000
);
console
.
info
(
'
fileIO_open_async_006, fd:
'
+
file
.
fd
);
fileio
.
rmdirSync
(
dpath
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_open_async_006 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_FILE_ASYNC_0070
* @tc.name fileIO_open_async_007
* @tc.desc Test openAsync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_open_async_007
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_open_async_007
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
await
fileIO
.
open
(
fpath
,
0o400002
);
console
.
info
(
'
fileIO_open_async_007, fd:
'
+
file
.
fd
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_open_async_007 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_FILE_ASYNC_0080
* @tc.name fileIO_open_async_007
* @tc.desc Test openAsync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_open_async_008
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_open_async_008
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
await
fileIO
.
open
(
fpath
,
0o4010002
);
console
.
info
(
'
fileIO_open_async_008, fd:
'
+
file
.
fd
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_open_async_008 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPENIO_ASYNC_0090
* @tc.name fileIO_open_async_009
* @tc.desc Test openAsync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_open_async_009
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_open_async_009
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
fileIO
.
open
(
fpath
,
0o102
,
function
(
err
,
file
)
{
console
.
info
(
'
fileIO_open_async_009, fd:
'
+
file
.
fd
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_open_async_009 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
});
}
\ No newline at end of file
storage/storagefileiojstest/src/main/js/test/module_fileio/members/readV9.test.js
0 → 100644
浏览文件 @
c1799ac5
/*
* Copyright (C) 2022 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 from '@ohos.file.fs';
import
{
fileio
,
fileIO
,
FILE_CONTENT
,
prepareFile
,
nextFileName
,
isIntNum
,
describe
,
it
,
expect
,
}
from
'
../../Common
'
;
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.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_sync_000
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_sync_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
fd
=
fileio
.
openSync
(
fpath
,
0o2
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
let
len
=
fileIO
.
readSync
(
fd
,
new
ArrayBuffer
(
4096
));
expect
(
len
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_sync_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0010
* @tc.name fileIO_test_read_sync_001
* @tc.desc Test readSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_sync_001
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_sync_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
fd
=
fileio
.
openSync
(
fpath
,
0o2
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
let
len
=
fileIO
.
readSync
(
fd
,
new
ArrayBuffer
(
4096
),
{
length
:
1
,
});
expect
(
len
==
1
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_sync_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0020
* @tc.name fileIO_test_read_sync_002
* @tc.desc Test readSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_sync_002
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_sync_002
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
fd
=
fileio
.
openSync
(
fpath
,
0o2
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
let
len
=
fileIO
.
readSync
(
fd
,
new
ArrayBuffer
(
4096
),
{
offset
:
1
,
});
expect
(
len
==
FILE_CONTENT
.
length
-
1
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_sync_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0030
* @tc.name fileIO_test_read_sync_003
* @tc.desc Test readSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_sync_003
'
,
0
,
async
function
()
{
let
fd
;
const
invalidLength
=
9999
;
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_sync_003
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
fd
=
fileio
.
openSync
(
fpath
,
0o2
,
0o664
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
fileIO
.
readSync
(
fd
,
new
ArrayBuffer
(
4096
),
{
length
:
invalidLength
});
expect
(
null
).
assertFail
();
}
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
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0040
* @tc.name fileIO_test_read_sync_004
* @tc.desc Test readSync() interfaces.
* @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
'
);
try
{
fileIO
.
readSync
(
-
1
,
new
ArrayBuffer
(
4096
));
expect
(
null
).
assertFail
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_sync_004 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_0050
* @tc.name fileIO_test_read_sync_005
* @tc.desc Test readSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_sync_005
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_sync_005
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
fd
=
fileio
.
openSync
(
fpath
,
0o2
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
let
invalidPos
=
FILE_CONTENT
.
length
+
1
;
let
len
=
fileIO
.
readSync
(
fd
,
new
ArrayBuffer
(
4096
),
{
offset
:
invalidPos
,
});
expect
(
len
==
0
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_sync_005 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0000
* @tc.name fileIO_test_read_async_000
* @tc.desc Test readAsync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_async_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_async_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
fd
=
fileio
.
openSync
(
fpath
,
0o2
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
let
res
=
await
fileIO
.
read
(
fd
,
new
ArrayBuffer
(
4096
));
expect
(
res
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_async_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0010
* @tc.name fileIO_test_read_async_001
* @tc.desc Test readAsync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_async_001
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_async_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
fd
=
fileio
.
openSync
(
fpath
,
0o2
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
fileIO
.
read
(
fd
,
new
ArrayBuffer
(
4096
),
async
function
(
err
,
readlen
)
{
expect
(
readlen
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_async_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0020
* @tc.name fileIO_test_read_async_002
* @tc.desc Test readAsync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
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
();
try
{
let
fd
=
fileio
.
openSync
(
fpath
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
let
readlen
=
await
fileIO
.
read
(
fd
,
new
ArrayBuffer
(
4096
));
expect
(
readlen
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_async_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0030
* @tc.name fileIO_test_read_async_003
* @tc.desc Test readAsync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
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
();
try
{
let
fd
=
fileio
.
openSync
(
fpath
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
let
readlen
=
await
fileIO
.
read
(
fd
,
new
ArrayBuffer
(
4096
),
{
offset
:
1
,
});
expect
(
readlen
==
FILE_CONTENT
.
length
-
1
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_async_003 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0040
* @tc.name fileIO_test_read_async_004
* @tc.desc Test readAsync() interface.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_async_004
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_async_004
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
fd
=
fileio
.
openSync
(
fpath
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
let
readlen
=
await
fileIO
.
read
(
fd
,
new
ArrayBuffer
(
4096
),
{
length
:
3
,
});
expect
(
readlen
==
3
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_async_004 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0050
* @tc.name fileIO_test_read_async_005
* @tc.desc Test readAsync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_async_005
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_read_async_005
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
fd
=
fileio
.
openSync
(
fpath
,
0o2
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
let
len
=
await
fileIO
.
read
(
fd
,
new
ArrayBuffer
(
4096
),
{
offset
:
FILE_CONTENT
.
length
+
10
,
});
expect
(
isIntNum
(
len
)).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_async_005 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0060
* @tc.name fileIO_test_read_async_006
* @tc.desc Test readAsync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_read_async_006
'
,
0
,
async
function
(
done
)
{
try
{
await
fileIO
.
read
(
-
1
,
new
ArrayBuffer
(
4096
));
expect
(
null
).
assertFail
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_async_006 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900008
&&
e
.
message
==
'
Bad file descriptor
'
).
assertTrue
();
done
();
}
});
});
}
storage/storagefileiojstest/src/main/js/test/module_fileio/members/statV9.test.js
0 → 100644
浏览文件 @
c1799ac5
此差异已折叠。
点击以展开。
storage/storagefileiojstest/src/main/js/test/module_fileio/members/truncateV9.test.js
0 → 100644
浏览文件 @
c1799ac5
/*
* Copyright (C) 2022 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 from '@ohos.file.fs';
import
{
fileio
,
fileIO
,
FILE_CONTENT
,
prepareFile
,
nextFileName
,
isIntNum
,
describe
,
it
,
expect
,
}
from
'
../../Common
'
;
export
default
function
fileIOTruncate
()
{
describe
(
'
fileIO_fs_truncate
'
,
function
()
{
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0000
* @tc.name fileIO_truncate_async_000
* @tc.desc Test the truncateAsync() interface that receives the fpath parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_truncate_async_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_truncate_async_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
truncateLen
=
5
;
try
{
await
fileIO
.
truncate
(
fpath
,
truncateLen
);
let
fd
=
fileio
.
openSync
(
fpath
,
0o2
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
let
len
=
fileio
.
readSync
(
fd
,
new
ArrayBuffer
(
4096
));
expect
(
len
==
truncateLen
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
}
catch
(
e
)
{
console
.
info
(
'
fileIO_truncate_async_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0010
* @tc.name fileIO_truncate_async_001
* @tc.desc Test the truncateAsync() interface that receives the fd parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_truncate_async_001
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_truncate_async_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
fd
=
fileio
.
openSync
(
fpath
,
0o2
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
let
truncateLen
=
5
;
try
{
fileIO
.
truncate
(
fd
,
truncateLen
,
function
(
err
)
{
let
len
=
fileio
.
readSync
(
fd
,
new
ArrayBuffer
(
4096
));
expect
(
len
==
truncateLen
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
})
}
catch
(
e
)
{
console
.
log
(
'
fileIO_truncate_async_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0020
* @tc.name fileIO_truncate_async_002
* @tc.desc Test the truncateAsync() interface that receives the fpath parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_truncate_async_002
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_truncate_async_002
'
);
expect
(
prepareFile
(
fpath
,
'
truncate
'
)).
assertTrue
();
let
truncateLen
=
2
;
try
{
fileIO
.
truncate
(
fpath
,
truncateLen
)
.
then
(
function
(
err
)
{
expect
(
err
==
null
).
assertTrue
();
let
fd
=
fileio
.
openSync
(
fpath
,
0o2
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
let
len
=
fileio
.
readSync
(
fd
,
new
ArrayBuffer
(
4096
));
expect
(
len
==
truncateLen
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
})
.
catch
(
function
(
e
)
{
console
.
log
(
'
catch
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_truncate_async_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0030
* @tc.name fileIO_truncate_async_003
* @tc.desc Test the truncateAsync() interface that receives the fd parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_truncate_async_003
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_truncate_async_003
'
);
expect
(
prepareFile
(
fpath
,
'
truncate
'
)).
assertTrue
();
let
fd
=
fileio
.
openSync
(
fpath
,
0o2
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
let
truncateLen
=
2
;
try
{
fileIO
.
truncate
(
fd
,
truncateLen
)
.
then
(
function
(
err
)
{
expect
(
err
==
null
).
assertTrue
();
let
len
=
fileio
.
readSync
(
fd
,
new
ArrayBuffer
(
4096
));
expect
(
len
==
truncateLen
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
})
.
catch
(
function
(
e
)
{
console
.
log
(
'
catch
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
})
}
catch
(
e
)
{
console
.
log
(
'
fileIO_truncate_async_003 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0040
* @tc.name fileIO_truncate_async_004
* @tc.desc Test the truncateAsync() interface that receives the fpath parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_truncate_async_004
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_truncate_async_004
'
);
let
truncateLen
=
2
;
try
{
fileIO
.
truncate
(
fpath
,
truncateLen
,
function
(
err
)
{
done
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_truncate_async_004 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
!!
e
).
assertTrue
();
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0000
* @tc.name fileIO_test_truncate_sync_000
* @tc.desc Test the truncateSync() interface that receives the fpath parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_truncate_sync_000
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_truncate_sync_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
expect
(
fileIO
.
truncateSync
(
fpath
)
==
null
).
assertTrue
();
expect
(
fileio
.
statSync
(
fpath
).
size
==
0
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_truncate_sync_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0000
* @tc.name fileIO_test_truncate_sync_001
* @tc.desc Test the truncateSync() interface that receives the fd parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_truncate_sync_001
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_truncate_sync_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
fd
=
fileio
.
openSync
(
fpath
,
0o2
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
let
truncateLen
=
5
;
try
{
fileIO
.
truncateSync
(
fd
,
truncateLen
);
let
len
=
fileio
.
readSync
(
fd
,
new
ArrayBuffer
(
4096
));
expect
(
len
==
truncateLen
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_truncate_sync_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0010
* @tc.name fileIO_test_truncate_sync_002
* @tc.desc Test the truncateSync() interface that receives the fpath parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_truncate_sync_002
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_truncate_sync_002
'
);
try
{
let
stat
=
fileIO
.
truncateSync
(
fpath
);
console
.
info
(
'
fileIO_test_truncate_sync_002 =
'
+
stat
);
expect
(
null
).
assertFail
();
}
catch
(
e
)
{
expect
(
e
.
code
==
13900002
&&
e
.
message
==
'
No such file or directory
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0010
* @tc.name fileIO_test_truncate_sync_003
* @tc.desc Test the truncateSync() interface that receives the fd parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_truncate_sync_003
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_truncate_sync_003
'
);
expect
(
prepareFile
(
fpath
,
'
truncate
'
)).
assertTrue
();
let
fd
=
fileio
.
openSync
(
fpath
,
0o2
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
let
truncateLen
=
2
;
try
{
fileIO
.
truncateSync
(
fd
,
truncateLen
);
let
len
=
fileio
.
readSync
(
fd
,
new
ArrayBuffer
(
4096
));
expect
(
len
==
truncateLen
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_truncate_sync_003 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0020
* @tc.name fileIO_test_truncate_sync_004
* @tc.desc Test truncateSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_truncate_sync_004
'
,
0
,
function
()
{
try
{
let
stat
=
fileIO
.
truncateSync
();
console
.
info
(
'
fileIO_test_truncate_sync_004 =
'
+
stat
);
}
catch
(
e
)
{
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0020
* @tc.name fileio_test_truncate_sync_v9_005
* @tc.desc Test truncateSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileio_test_truncate_sync_005
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileio_test_truncate_sync_005
'
);
let
truncateLen
=
2
;
try
{
fileIO
.
truncateSync
(
fpath
,
truncateLen
);
}
catch
(
e
)
{
console
.
log
(
'
fileio_test_ftruncate_sync_005 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
!!
e
).
assertTrue
();
}
});
});
}
storage/storagefileiojstest/src/main/js/test/module_fileio/members/writeV9.test.js
0 → 100644
浏览文件 @
c1799ac5
/*
* Copyright (C) 2022 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 from '@ohos.file.fs';
import
{
fileio
,
fileIO
,
FILE_CONTENT
,
nextFileName
,
isIntNum
,
describe
,
it
,
expect
,
}
from
'
../../Common
'
;
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.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_sync_000
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_sync_000
'
);
try
{
let
fd
=
fileio
.
openSync
(
fpath
,
0o102
,
0o664
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
expect
(
fileIO
.
writeSync
(
fd
,
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_sync_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0010
* @tc.name fileIO_test_write_sync_001
* @tc.desc Test writeSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_sync_001
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_sync_001
'
);
try
{
let
fd
=
fileio
.
openSync
(
fpath
,
0o102
,
0o664
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
expect
(
fileIO
.
writeSync
(
fd
,
FILE_CONTENT
,
{
encoding
:
'
utf-8
'
,
})
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_sync_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0020
* @tc.name fileIO_test_write_sync_002
* @tc.desc Test writeSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_sync_002
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_sync_002
'
);
try
{
let
fd
=
fileio
.
openSync
(
fpath
,
0o102
,
0o664
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
expect
(
fileIO
.
writeSync
(
fd
,
FILE_CONTENT
,
{
length
:
FILE_CONTENT
.
length
-
1
,
})
==
FILE_CONTENT
.
length
-
1
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_sync_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0030
* @tc.name fileIO_test_write_sync_003
* @tc.desc Test writeSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_sync_003
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_sync_003
'
);
try
{
let
fd
=
fileio
.
openSync
(
fpath
,
0o102
,
0o664
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
expect
(
fileIO
.
writeSync
(
fd
,
FILE_CONTENT
,
{
length
:
1
,
})
==
1
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_sync_003 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0040
* @tc.name fileIO_test_write_sync_004
* @tc.desc Test writeSync() interfaces.
* @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
(
'
fileIO_test_write_sync_004
'
);
let
fd
=
fileio
.
openSync
(
fpath
,
0o102
,
0o664
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
const
invalidLength
=
9999
;
try
{
fileIO
.
writeSync
(
fd
,
FILE_CONTENT
,
{
length
:
invalidLength
,
})
expect
(
null
).
assertFail
();
}
catch
(
e
)
{
console
.
info
(
'
fileIO_test_write_sync_004 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0050
* @tc.name fileIO_test_write_sync_005
* @tc.desc Test writeSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_sync_005
'
,
0
,
function
()
{
try
{
fileIO
.
writeSync
(
-
1
,
FILE_CONTENT
);
expect
(
null
).
assertFail
();
}
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
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0060
* @tc.name fileIO_test_write_sync_006
* @tc.desc Test writeSync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_sync_006
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_sync_006
'
);
try
{
let
fd
=
fileio
.
openSync
(
fpath
,
0o102
,
0o664
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
let
writeNum
=
fileIO
.
writeSync
(
fd
,
new
ArrayBuffer
(
4096
));
expect
(
writeNum
==
4096
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_sync_006 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0000
* @tc.name fileIO_test_write_async_000
* @tc.desc Test writeAsync() interfaces.
* @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
'
);
try
{
let
fd
=
fileio
.
openSync
(
fpath
,
0o102
,
0o664
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
expect
(
await
fileIO
.
write
(
fd
,
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_write_async_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0010
* @tc.name fileIO_test_write_async_001
* @tc.desc Test writeAsync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_async_001
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_async_001
'
);
try
{
let
fd
=
fileio
.
openSync
(
fpath
,
0o102
,
0o664
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
let
writeNum
=
await
fileIO
.
write
(
fd
,
FILE_CONTENT
,
{
length
:
3
,
});
expect
(
writeNum
==
3
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_async_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0020
* @tc.name fileIO_test_write_async_002
* @tc.desc Test writeAsync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_async_002
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_async_002
'
);
try
{
let
fd
=
fileio
.
openSync
(
fpath
,
0o102
,
0o664
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
let
writeNum
=
await
fileIO
.
write
(
fd
,
FILE_CONTENT
,
{
length
:
3
,
offset
:
5
,
});
expect
(
writeNum
==
3
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_async_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0030
* @tc.name fileIO_test_write_async_003
* @tc.desc Test writeAsync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_async_003
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_async_003
'
);
try
{
let
fd
=
fileio
.
openSync
(
fpath
,
0o102
,
0o664
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
let
writeNum
=
await
fileIO
.
write
(
fd
,
FILE_CONTENT
,
{
length
:
4
,
offset
:
5
,
encoding
:
'
utf-8
'
,
});
expect
(
writeNum
==
4
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_async_003 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0040
* @tc.name fileIO_test_write_async_004
* @tc.desc Test writeAsync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_async_004
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_async_004
'
);
try
{
let
fd
=
fileio
.
openSync
(
fpath
,
0o102
,
0o664
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
await
fileIO
.
write
(
fd
,
new
ArrayBuffer
(
4096
),
function
(
error
,
bytesWritten
)
{
expect
(
bytesWritten
==
4096
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
});
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_async_004 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0050
* @tc.name fileIO_test_write_async_005
* @tc.desc Test writeAsync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_async_005
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_async_005
'
);
try
{
let
fd
=
fileio
.
openSync
(
fpath
,
0o102
,
0o664
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
await
fileIO
.
write
(
fd
,
FILE_CONTENT
,
{
length
:
5
,
},
function
(
error
,
bytesWritten
)
{
expect
(
bytesWritten
==
5
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
}
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_async_005 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0060
* @tc.name fileIO_test_write_async_006
* @tc.desc Test writeAsync() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_write_async_006
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_write_async_006
'
);
try
{
let
fd
=
fileio
.
openSync
(
fpath
,
0o102
,
0o664
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
await
fileIO
.
write
(
fd
,
FILE_CONTENT
,
{
length
:
5
,
offset
:
5
,
},
function
(
error
,
bytesWritten
)
{
expect
(
bytesWritten
==
5
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
}
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_async_006 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0070
* @tc.name fileIO_test_write_async_007
* @tc.desc Test writeAsync() interfaces.
* @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
'
);
try
{
let
fd
=
fileio
.
openSync
(
fpath
,
0o102
,
0o664
);
expect
(
isIntNum
(
fd
)).
assertTrue
();
await
fileIO
.
write
(
fd
,
FILE_CONTENT
,
{
length
:
5
,
offset
:
5
,
encoding
:
'
utf-8
'
,
},
function
(
error
,
bytesWritten
)
{
expect
(
bytesWritten
==
5
).
assertTrue
();
expect
(
fileio
.
closeSync
(
fd
)
==
null
).
assertTrue
();
expect
(
fileio
.
unlinkSync
(
fpath
)
==
null
).
assertTrue
();
done
();
}
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_async_007 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
null
).
assertFail
();
}
});
});
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录