Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
0c2ff958
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看板
未验证
提交
0c2ff958
编写于
11月 04, 2022
作者:
O
openharmony_ci
提交者:
Gitee
11月 04, 2022
浏览文件
操作
浏览文件
下载
差异文件
!6335 【版本回合】xts回合monthly_1018
Merge pull request !6335 from gsl_1234/cherry-pick-1667444801
上级
c84c4f5b
92731ba0
变更
27
隐藏空白更改
内联
并排
Showing
27 changed file
with
4501 addition
and
0 deletion
+4501
-0
storage/BUILD.gn
storage/BUILD.gn
+1
-0
storage/storagefileiov9jstest/BUILD.gn
storage/storagefileiov9jstest/BUILD.gn
+35
-0
storage/storagefileiov9jstest/Test.json
storage/storagefileiov9jstest/Test.json
+17
-0
storage/storagefileiov9jstest/signature/openharmony_sx.p7b
storage/storagefileiov9jstest/signature/openharmony_sx.p7b
+0
-0
storage/storagefileiov9jstest/src/main/config.json
storage/storagefileiov9jstest/src/main/config.json
+95
-0
storage/storagefileiov9jstest/src/main/js/MainAbility/app.js
storage/storagefileiov9jstest/src/main/js/MainAbility/app.js
+23
-0
storage/storagefileiov9jstest/src/main/js/MainAbility/i18n/en-US.json
...agefileiov9jstest/src/main/js/MainAbility/i18n/en-US.json
+6
-0
storage/storagefileiov9jstest/src/main/js/MainAbility/i18n/zh-CN.json
...agefileiov9jstest/src/main/js/MainAbility/i18n/zh-CN.json
+6
-0
storage/storagefileiov9jstest/src/main/js/MainAbility/pages/index/index.css
...eiov9jstest/src/main/js/MainAbility/pages/index/index.css
+9
-0
storage/storagefileiov9jstest/src/main/js/MainAbility/pages/index/index.hml
...eiov9jstest/src/main/js/MainAbility/pages/index/index.hml
+5
-0
storage/storagefileiov9jstest/src/main/js/MainAbility/pages/index/index.js
...leiov9jstest/src/main/js/MainAbility/pages/index/index.js
+33
-0
storage/storagefileiov9jstest/src/main/js/TestAbility/app.js
storage/storagefileiov9jstest/src/main/js/TestAbility/app.js
+31
-0
storage/storagefileiov9jstest/src/main/js/TestAbility/i18n/en-US.json
...agefileiov9jstest/src/main/js/TestAbility/i18n/en-US.json
+8
-0
storage/storagefileiov9jstest/src/main/js/TestAbility/i18n/zh-CN.json
...agefileiov9jstest/src/main/js/TestAbility/i18n/zh-CN.json
+8
-0
storage/storagefileiov9jstest/src/main/js/TestAbility/pages/index/index.css
...eiov9jstest/src/main/js/TestAbility/pages/index/index.css
+30
-0
storage/storagefileiov9jstest/src/main/js/TestAbility/pages/index/index.hml
...eiov9jstest/src/main/js/TestAbility/pages/index/index.hml
+5
-0
storage/storagefileiov9jstest/src/main/js/TestAbility/pages/index/index.js
...leiov9jstest/src/main/js/TestAbility/pages/index/index.js
+23
-0
storage/storagefileiov9jstest/src/main/js/TestRunner/OpenHarmonyTestRunner.js
...ov9jstest/src/main/js/TestRunner/OpenHarmonyTestRunner.js
+59
-0
storage/storagefileiov9jstest/src/main/js/test/Common.js
storage/storagefileiov9jstest/src/main/js/test/Common.js
+142
-0
storage/storagefileiov9jstest/src/main/js/test/List.test.js
storage/storagefileiov9jstest/src/main/js/test/List.test.js
+27
-0
storage/storagefileiov9jstest/src/main/js/test/members/open.test.js
...oragefileiov9jstest/src/main/js/test/members/open.test.js
+738
-0
storage/storagefileiov9jstest/src/main/js/test/members/read.test.js
...oragefileiov9jstest/src/main/js/test/members/read.test.js
+372
-0
storage/storagefileiov9jstest/src/main/js/test/members/stat.test.js
...oragefileiov9jstest/src/main/js/test/members/stat.test.js
+2013
-0
storage/storagefileiov9jstest/src/main/js/test/members/truncate.test.js
...efileiov9jstest/src/main/js/test/members/truncate.test.js
+322
-0
storage/storagefileiov9jstest/src/main/js/test/members/write.test.js
...ragefileiov9jstest/src/main/js/test/members/write.test.js
+465
-0
storage/storagefileiov9jstest/src/main/resources/base/element/string.json
...ileiov9jstest/src/main/resources/base/element/string.json
+28
-0
storage/storagefileiov9jstest/src/main/resources/base/media/icon.png
...ragefileiov9jstest/src/main/resources/base/media/icon.png
+0
-0
未找到文件。
storage/BUILD.gn
浏览文件 @
0c2ff958
...
...
@@ -18,6 +18,7 @@ group("storage") {
deps = [
"storagefileioerrorjstest:storagefileioerror_js_test",
"storagefileiojstest:storagefileio_js_test",
"storagefileiov9jstest:storagefileiov9_js_test",
"storagefilejstest:storagefile_js_test",
"storagesecuritylabeljstest:storagesecuritylabel_js_test",
"storagestatfsjstest:storagestatfs_js_test",
...
...
storage/storagefileiov9jstest/BUILD.gn
0 → 100644
浏览文件 @
0c2ff958
# 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("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("storagefileiov9_js_test") {
hap_profile = "./src/main/config.json"
deps = [
":storagefileiov9_js_assets",
":storagefileiov9_js_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsStorageFileIoV9JSTest"
subsystem_name = "filemanagement"
part_name = "file_api"
}
ohos_js_assets("storagefileiov9_js_assets") {
js2abc = true
hap_profile = "./src/main/config.json"
source_dir = "./src/main/js"
}
ohos_resources("storagefileiov9_js_resources") {
sources = [ "./src/main/resources" ]
hap_profile = "./src/main/config.json"
}
storage/storagefileiov9jstest/Test.json
0 → 100644
浏览文件 @
0c2ff958
{
"description"
:
"Configuration for storage filefs Tests"
,
"driver"
:
{
"type"
:
"OHJSUnitTest"
,
"test-timeout"
:
"600000"
,
"shell-timeout"
:
"600000"
,
"bundle-name"
:
"ohos.acts.storage.fileiov9"
,
"package-name"
:
"ohos.acts.storage.fileiov9"
},
"kits"
:
[
{
"test-file-name"
:
[
"ActsStorageFileIoV9JSTest.hap"
],
"type"
:
"AppInstallKit"
,
"cleanup-apps"
:
true
}
]
}
\ No newline at end of file
storage/storagefileiov9jstest/signature/openharmony_sx.p7b
0 → 100644
浏览文件 @
0c2ff958
文件已添加
storage/storagefileiov9jstest/src/main/config.json
0 → 100644
浏览文件 @
0c2ff958
{
"app"
:
{
"bundleName"
:
"ohos.acts.storage.fileiov9"
,
"vendor"
:
"example"
,
"version"
:
{
"code"
:
1000000
,
"name"
:
"1.0.0"
},
"apiVersion"
:
{
"compatible"
:
4
,
"target"
:
5
}
},
"deviceConfig"
:
{},
"module"
:
{
"package"
:
"ohos.acts.storage.fileiov9"
,
"name"
:
".entry"
,
"deviceType"
:
[
"default"
,
"phone"
],
"distro"
:
{
"deliveryWithInstall"
:
true
,
"moduleName"
:
"entry"
,
"moduleType"
:
"entry"
,
"installationFree"
:
true
},
"abilities"
:
[
{
"skills"
:
[
{
"entities"
:
[
"entity.system.home"
],
"actions"
:
[
"action.system.home"
]
}
],
"orientation"
:
"unspecified"
,
"formsEnabled"
:
false
,
"name"
:
".MainAbility"
,
"srcLanguage"
:
"js"
,
"srcPath"
:
"MainAbility"
,
"icon"
:
"$media:icon"
,
"description"
:
"$string:MainAbility_desc"
,
"label"
:
"$string:MainAbility_label"
,
"type"
:
"page"
,
"visible"
:
true
,
"launchType"
:
"standard"
},
{
"orientation"
:
"unspecified"
,
"formsEnabled"
:
false
,
"name"
:
".TestAbility"
,
"srcLanguage"
:
"js"
,
"srcPath"
:
"TestAbility"
,
"icon"
:
"$media:icon"
,
"description"
:
"$string:TestAbility_desc"
,
"label"
:
"$string:TestAbility_label"
,
"type"
:
"page"
,
"visible"
:
true
,
"launchType"
:
"standard"
}
],
"js"
:
[
{
"pages"
:
[
"pages/index/index"
],
"name"
:
"default"
,
"window"
:
{
"designWidth"
:
720
,
"autoDesignWidth"
:
false
}
},
{
"pages"
:
[
"pages/index/index"
],
"name"
:
".TestAbility"
,
"window"
:
{
"designWidth"
:
720
,
"autoDesignWidth"
:
false
}
}
],
"testRunner"
:
{
"name"
:
"OpenHarmonyTestRunner"
,
"srcPath"
:
"TestRunner"
},
"mainAbility"
:
".MainAbility"
,
"srcPath"
:
""
}
}
\ No newline at end of file
storage/storagefileiov9jstest/src/main/js/MainAbility/app.js
0 → 100644
浏览文件 @
0c2ff958
/*
* 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.
*/
export
default
{
onCreate
()
{
console
.
info
(
'
ohos.acts.storage.fileio onCreate
'
);
},
onDestroy
()
{
console
.
info
(
'
ohos.acts.storage.fileio onDestroy
'
);
}
};
storage/storagefileiov9jstest/src/main/js/MainAbility/i18n/en-US.json
0 → 100644
浏览文件 @
0c2ff958
{
"strings"
:
{
"hello"
:
"Hello"
,
"world"
:
"Test"
}
}
\ No newline at end of file
storage/storagefileiov9jstest/src/main/js/MainAbility/i18n/zh-CN.json
0 → 100644
浏览文件 @
0c2ff958
{
"strings"
:
{
"hello"
:
"您好"
,
"world"
:
"测试"
}
}
\ No newline at end of file
storage/storagefileiov9jstest/src/main/js/MainAbility/pages/index/index.css
0 → 100644
浏览文件 @
0c2ff958
.container
{
flex-direction
:
column
;
justify-content
:
center
;
align-items
:
center
;
}
.title
{
font-size
:
100px
;
}
storage/storagefileiov9jstest/src/main/js/MainAbility/pages/index/index.hml
0 → 100644
浏览文件 @
0c2ff958
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
storage/storagefileiov9jstest/src/main/js/MainAbility/pages/index/index.js
0 → 100644
浏览文件 @
0c2ff958
/*
* 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
app
from
'
@system.app
'
const
injectRef
=
Object
.
getPrototypeOf
(
global
)
||
global
injectRef
.
regeneratorRuntime
=
require
(
'
@babel/runtime/regenerator
'
)
export
default
{
data
:
{
title
:
''
},
onInit
()
{
this
.
title
=
this
.
$t
(
'
strings.world
'
);
},
onShow
()
{
console
.
info
(
'
onShow finish
'
)
},
onReady
()
{
},
}
storage/storagefileiov9jstest/src/main/js/TestAbility/app.js
0 → 100644
浏览文件 @
0c2ff958
/*
* 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
AbilityDelegatorRegistry
from
'
@ohos.application.abilityDelegatorRegistry
'
import
{
Hypium
}
from
'
@ohos/hypium
'
import
testsuite
from
'
../test/List.test
'
export
default
{
onCreate
()
{
console
.
info
(
'
TestApplication onCreate
'
)
var
abilityDelegator
=
AbilityDelegatorRegistry
.
getAbilityDelegator
()
var
abilityDelegatorArguments
=
AbilityDelegatorRegistry
.
getArguments
()
console
.
info
(
'
start run testcase!!!
'
)
Hypium
.
hypiumTest
(
abilityDelegator
,
abilityDelegatorArguments
,
testsuite
)
},
onDestroy
()
{
console
.
info
(
"
TestApplication onDestroy
"
);
}
};
storage/storagefileiov9jstest/src/main/js/TestAbility/i18n/en-US.json
0 → 100644
浏览文件 @
0c2ff958
{
"strings"
:
{
"hello"
:
"Hello"
,
"world"
:
"World"
},
"Files"
:
{
}
}
\ No newline at end of file
storage/storagefileiov9jstest/src/main/js/TestAbility/i18n/zh-CN.json
0 → 100644
浏览文件 @
0c2ff958
{
"strings"
:
{
"hello"
:
"您好"
,
"world"
:
"世界"
},
"Files"
:
{
}
}
\ No newline at end of file
storage/storagefileiov9jstest/src/main/js/TestAbility/pages/index/index.css
0 → 100644
浏览文件 @
0c2ff958
.container
{
display
:
flex
;
flex-direction
:
column
;
justify-content
:
center
;
align-items
:
center
;
left
:
0px
;
top
:
0px
;
width
:
100%
;
height
:
100%
;
}
.title
{
font-size
:
60px
;
text-align
:
center
;
width
:
100%
;
height
:
40%
;
margin
:
10px
;
}
@media
screen
and
(
device-type
:
phone
)
and
(
orientation
:
landscape
)
{
.title
{
font-size
:
60px
;
}
}
@media
screen
and
(
device-type
:
tablet
)
and
(
orientation
:
landscape
)
{
.title
{
font-size
:
100px
;
}
}
\ No newline at end of file
storage/storagefileiov9jstest/src/main/js/TestAbility/pages/index/index.hml
0 → 100644
浏览文件 @
0c2ff958
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
storage/storagefileiov9jstest/src/main/js/TestAbility/pages/index/index.js
0 → 100644
浏览文件 @
0c2ff958
/*
* 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.
*/
export
default
{
data
:
{
title
:
""
},
onInit
()
{
this
.
title
=
this
.
$t
(
'
strings.world
'
);
}
}
storage/storagefileiov9jstest/src/main/js/TestRunner/OpenHarmonyTestRunner.js
0 → 100644
浏览文件 @
0c2ff958
/*
* 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
AbilityDelegatorRegistry
from
'
@ohos.application.abilityDelegatorRegistry
'
function
translateParamsToString
(
parameters
)
{
const
keySet
=
new
Set
([
'
-s class
'
,
'
-s notClass
'
,
'
-s suite
'
,
'
-s itName
'
,
'
-s level
'
,
'
-s testType
'
,
'
-s size
'
,
'
-s timeout
'
,
'
-s package
'
,
'
-s dryRun
'
])
let
targetParams
=
''
;
for
(
const
key
in
parameters
)
{
if
(
keySet
.
has
(
key
))
{
targetParams
+=
'
'
+
key
+
'
'
+
parameters
[
key
]
}
}
return
targetParams
.
trim
()
}
export
default
{
onPrepare
()
{
console
.
info
(
'
OpenHarmonyTestRunner OnPrepare
'
)
},
onRun
()
{
console
.
log
(
'
OpenHarmonyTestRunner onRun run
'
)
var
abilityDelegatorArguments
=
AbilityDelegatorRegistry
.
getArguments
()
var
abilityDelegator
=
AbilityDelegatorRegistry
.
getAbilityDelegator
()
var
testAbilityName
=
abilityDelegatorArguments
.
parameters
[
'
-p
'
]
+
'
.TestAbility
'
var
cmd
=
'
aa start -d 0 -a
'
+
testAbilityName
+
'
-b
'
+
abilityDelegatorArguments
.
bundleName
cmd
+=
'
'
+
translateParamsToString
(
abilityDelegatorArguments
.
parameters
)
var
debug
=
abilityDelegatorArguments
.
parameters
[
"
-D
"
]
console
.
info
(
'
debug value :
'
+
debug
)
if
(
debug
==
'
true
'
)
{
cmd
+=
'
-D
'
}
console
.
info
(
'
cmd :
'
+
cmd
)
abilityDelegator
.
executeShellCommand
(
cmd
,
(
err
,
data
)
=>
{
console
.
info
(
'
executeShellCommand : err :
'
+
JSON
.
stringify
(
err
));
console
.
info
(
'
executeShellCommand : data :
'
+
data
.
stdResult
);
console
.
info
(
'
executeShellCommand : data :
'
+
data
.
exitCode
);
})
}
};
storage/storagefileiov9jstest/src/main/js/test/Common.js
0 → 100644
浏览文件 @
0c2ff958
/*
* 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.fileio
'
;
import
fileIO
from
'
@ohos.file.fs
'
;
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
export
const
FILE_CONTENT
=
'
hello world
'
;
import
{
describe
,
it
,
expect
}
from
'
@ohos/hypium
'
export
function
prepareFile
(
fpath
,
content
)
{
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
CREATE
|
fileIO
.
OpenMode
.
READ_WRITE
)
fileIO
.
truncateSync
(
file
.
fd
)
fileIO
.
writeSync
(
file
.
fd
,
content
)
fileio
.
fsyncSync
(
file
.
fd
)
fileio
.
closeSync
(
file
.
fd
)
return
true
}
catch
(
e
)
{
console
.
log
(
'
Failed to prepareFile for
'
+
e
)
return
false
}
}
export
function
prepareEmptyFile
(
fpath
)
{
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
CREATE
|
fileIO
.
OpenMode
.
READ_WRITE
)
fileio
.
closeSync
(
file
.
fd
)
return
true
}
catch
(
e
)
{
console
.
log
(
'
Failed to prepareFile for
'
+
e
)
return
false
}
}
export
function
fileToReadOnly
(
fpath
)
{
try
{
let
file
=
fileio
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
CREATE
)
fileio
.
fchmodSync
(
file
.
fd
,
0o444
)
fileio
.
fsyncSync
(
file
.
fd
)
fileio
.
closeSync
(
file
.
fd
)
return
true
}
catch
(
e
)
{
console
.
log
(
'
Failed to fileToReadOnly for
'
+
e
);
return
false
}
}
export
function
fileToWriteOnly
(
fpath
)
{
try
{
let
file
=
fileio
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
CREATE
|
fileIO
.
OpenMode
.
WRITE_ONLY
)
fileio
.
fchmodSync
(
file
.
fd
,
0o222
)
fileio
.
fsyncSync
(
file
.
fd
)
fileio
.
closeSync
(
file
.
fd
)
return
true
}
catch
(
e
)
{
console
.
log
(
'
Failed to fileToWriteOnly
'
+
e
)
return
false
}
}
export
async
function
nextFileName
(
testName
)
{
let
context
=
featureAbility
.
getContext
();
let
data
=
await
context
.
getCacheDir
();
let
BASE_PATH
=
data
+
'
/
'
;
return
BASE_PATH
+
testName
+
'
_
'
+
randomString
(
testName
.
length
);
}
export
async
function
fileName
(
testName
)
{
let
context
=
featureAbility
.
getContext
();
let
data
=
await
context
.
getFilesDir
();
let
BASE_PATH
=
data
+
'
/
'
;
return
BASE_PATH
+
testName
+
'
_
'
+
randomString
(
testName
.
length
);
}
export
function
randomString
(
num
)
{
let
len
=
num
;
var
$chars
=
'
aaaabbbbcccc
'
;
var
maxPos
=
$chars
.
length
;
var
pwd
=
''
;
for
(
var
i
=
0
;
i
<
len
;
i
++
)
{
pwd
+=
$chars
.
charAt
(
Math
.
floor
(
Math
.
random
()
*
maxPos
));
}
return
pwd
;
}
export
function
forceRemoveDir
(
path
,
num
)
{
for
(
let
i
=
num
;
i
>=
0
;
i
--
)
{
if
(
i
<
num
)
{
path
=
path
.
replace
(
`/d
${
i
}
`
,
""
);
}
fileio
.
rmdirSync
(
path
);
}
}
function
isIntNum
(
val
)
{
return
typeof
val
===
'
number
'
&&
val
%
1
===
0
;
}
function
isString
(
str
)
{
return
(
typeof
str
==
'
string
'
)
&&
str
.
constructor
==
String
;
}
function
isBoolean
(
val
)
{
return
typeof
val
==
'
boolean
'
;
}
function
isInclude
(
error
,
message
)
{
return
error
.
toString
().
indexOf
(
message
)
!=
-
1
;
}
export
{
fileio
,
fileIO
,
isIntNum
,
isString
,
isBoolean
,
isInclude
,
describe
,
it
,
expect
};
\ No newline at end of file
storage/storagefileiov9jstest/src/main/js/test/List.test.js
0 → 100644
浏览文件 @
0c2ff958
/*
* 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
fileIOOpen
from
'
./members/open.test.js
'
import
fileIORead
from
'
./members/read.test.js
'
import
fileIOStat
from
'
./members/stat.test.js
'
import
fileIOTruncate
from
'
./members/truncate.test.js
'
import
fileIOWrite
from
'
./members/write.test.js
'
export
default
function
testsuite
()
{
fileIOOpen
()
fileIORead
()
fileIOStat
()
fileIOTruncate
()
fileIOWrite
()
}
storage/storagefileiov9jstest/src/main/js/test/members/open.test.js
0 → 100644
浏览文件 @
0c2ff958
/*
* 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
,
fileIO
,
FILE_CONTENT
,
prepareFile
,
nextFileName
,
isIntNum
,
describe
,
it
,
expect
,
}
from
'
../Common
'
;
export
default
function
fileIOOpen
()
{
describe
(
'
fileIO_fs_open
'
,
function
()
{
/**
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_0000
* @tc.name fileIO_test_open_sync_000
* @tc.desc Test openSync() interfaces. mode=0o0.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_sync_000
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_open_sync_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
readlen
=
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
));
expect
(
readlen
==
FILE_CONTENT
.
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_open_sync_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_0100
* @tc.name fileIO_test_open_sync_001
* @tc.desc Test openSync() interfaces. mode=0o1.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_sync_001
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_open_sync_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
length
=
20
;
let
num
=
fileIO
.
writeSync
(
file
.
fd
,
new
ArrayBuffer
(
length
));
expect
(
num
==
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_open_sync_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_0200
* @tc.name fileIO_test_open_sync_002
* @tc.desc Test openSync() interfaces. mode=0o2.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_sync_002
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_open_sync_002
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
readlen
=
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
));
expect
(
readlen
==
FILE_CONTENT
.
length
).
assertTrue
();
let
length
=
20
;
let
num
=
fileIO
.
writeSync
(
file
.
fd
,
new
ArrayBuffer
(
length
));
expect
(
num
==
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_open_sync_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_0300
* @tc.name fileIO_test_open_sync_003
* @tc.desc Test openSync() interfaces. Missing Parameter.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_sync_003
'
,
0
,
function
()
{
try
{
fileIO
.
openSync
();
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_open_sync_003 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
;
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_0400
* @tc.name fileIO_test_open_sync_004
* @tc.desc Test openSync() interfaces. mode=0o102.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_sync_004
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_open_sync_004
'
);
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
CREATE
|
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_open_sync_004 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_0500
* @tc.name fileIO_test_open_sync_005
* @tc.desc Test openSync() interfaces. mode=0o1002.
* If the file exists and the file is opened for write-only or read-write, trim its length to zero.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_sync_005
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_open_sync_005
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
TRUNC
|
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
number
=
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
));
expect
(
number
==
0
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_open_sync_005 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_0600
* @tc.name fileIO_test_open_sync_006
* @tc.desc Test openSync() interfaces. mode=0o2002.
* Open as append, subsequent writes will append to the end of the file.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_sync_006
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_open_sync_006
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
APPEND
|
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
length
=
100
;
let
num
=
fileIO
.
writeSync
(
file
.
fd
,
new
ArrayBuffer
(
length
));
expect
(
num
==
length
).
assertTrue
();
let
number
=
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
offset
:
0
});
expect
(
number
==
length
+
FILE_CONTENT
.
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_open_sync_006 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_0700
* @tc.name fileIO_test_open_sync_007
* @tc.desc Test openSync() interfaces. mode=0o4002.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_sync_007
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_open_sync_007
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
NONBLOCK
|
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_open_sync_007 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_0800
* @tc.name fileIO_test_open_sync_008
* @tc.desc Test openSync() interfaces. mode=0o200000.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_sync_008
'
,
0
,
async
function
()
{
let
dpath
=
await
nextFileName
(
'
fileIO_test_open_sync_008
'
);
fileio
.
mkdirSync
(
dpath
);
try
{
let
file
=
fileIO
.
openSync
(
dpath
,
fileIO
.
OpenMode
.
DIR
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileio
.
rmdirSync
(
dpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_open_sync_008 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_0900
* @tc.name fileIO_test_open_sync_009
* @tc.desc Test openSync() interfaces. mode=0o200000. Not a directory.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_sync_009
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_open_sync_009
'
);
expect
(
prepareFile
(
fpath
,
''
)).
assertTrue
();
try
{
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
DIR
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_open_sync_009 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900002
&&
e
.
message
==
'
No such file or directory
'
).
assertTrue
;
fileio
.
unlinkSync
(
fpath
);
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_1000
* @tc.name fileIO_test_open_sync_010
* @tc.desc Test openSync() interfaces. mode=0o400002.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_sync_010
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_open_sync_010
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
NOFOLLOW
|
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_open_sync_010 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_1100
* @tc.name fileIO_test_open_sync_011
* @tc.desc Test openSync() interfaces. mode=0o400002. Shouldn't be Symbolic link.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_sync_011
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_open_sync_011
'
);
let
ffpath
=
fpath
+
'
aaaa
'
;
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
fileio
.
symlinkSync
(
fpath
,
ffpath
);
fileIO
.
openSync
(
ffpath
,
fileIO
.
OpenMode
.
NOFOLLOW
|
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_open_sync_011 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900033
&&
e
.
message
==
'
Too many symbolic links encountered
'
).
assertTrue
;
fileio
.
unlinkSync
(
fpath
);
fileio
.
unlinkSync
(
ffpath
);
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_SYNC_1200
* @tc.name fileIO_test_open_sync_012
* @tc.desc Test openSync() interfaces. mode=0o4010002.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_sync_012
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_open_sync_012
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
SYNC
|
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_open_sync_012 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0000
* @tc.name fileIO_test_open_async_000
* @tc.desc Test open() interfaces. mode=0o0.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_async_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_open_async_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
fileIO
.
open
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
,
function
(
err
,
file
)
{
fileIO
.
read
(
file
.
fd
,
new
ArrayBuffer
(
4096
))
.
then
(
function
(
res
)
{
expect
(
res
==
FILE_CONTENT
.
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
});
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_open_async_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0100
* @tc.name fileIO_test_open_async_001
* @tc.desc Test open() interfaces. mode=0o2. No such file.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_async_001
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_open_async_001
'
);
try
{
await
fileIO
.
open
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_open_async_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900002
&&
e
.
message
==
'
No such file or directory
'
).
assertTrue
;
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0200
* @tc.name fileIO_test_open_async_002
* @tc.desc Test open() interfaces. Invalid fp.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_async_002
'
,
0
,
async
function
(
done
)
{
try
{
await
fileIO
.
open
(
-
1
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_open_async_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0300
* @tc.name fileIO_test_open_async_003
* @tc.desc Test open() interfaces. mode=0o1.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_async_003
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_open_async_003
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
await
fileIO
.
open
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
length
=
20
;
let
num
=
fileIO
.
writeSync
(
file
.
fd
,
new
ArrayBuffer
(
length
));
expect
(
num
==
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_open_async_003 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0400
* @tc.name fileIO_test_open_async_004
* @tc.desc Test open() interfaces. mode=0o2.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_async_004
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_open_async_004
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
await
fileIO
.
open
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
readlen
=
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
));
expect
(
readlen
==
FILE_CONTENT
.
length
).
assertTrue
();
let
length
=
20
;
let
num
=
fileIO
.
writeSync
(
file
.
fd
,
new
ArrayBuffer
(
length
));
expect
(
num
==
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_open_async_004 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0500
* @tc.name fileIO_test_open_async_005
* @tc.desc Test open() interfaces. mode=0o102. Promise.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_async_005
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_open_async_005
'
);
try
{
let
file
=
await
fileIO
.
open
(
fpath
,
fileIO
.
OpenMode
.
CREATE
|
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_open_async_005 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0600
* @tc.name fileIO_test_open_async_006
* @tc.desc Test open() interfaces. mode=0o102. Callback.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_async_006
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_open_async_006
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
fileIO
.
open
(
fpath
,
fileIO
.
OpenMode
.
CREATE
|
fileIO
.
OpenMode
.
READ_WRITE
,
function
(
err
,
file
)
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_open_async_006 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0700
* @tc.name fileIO_test_open_async_007
* @tc.desc Test open() interfaces. mode=0o1002.
* If the file exists and the file is opened for write-only or read-write, trim its length to zero.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_async_007
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_open_async_007
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
await
fileIO
.
open
(
fpath
,
fileIO
.
OpenMode
.
TRUNC
|
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
number
=
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
));
expect
(
number
==
0
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_open_async_007 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0800
* @tc.name fileIO_test_open_async_008
* @tc.desc Test open() interfaces. mode=0o2002.
* Open as append, subsequent writes will append to the end of the file.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_async_008
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_open_async_008
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
await
fileIO
.
open
(
fpath
,
fileIO
.
OpenMode
.
APPEND
|
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
length
=
100
;
let
num
=
fileIO
.
writeSync
(
file
.
fd
,
new
ArrayBuffer
(
length
));
expect
(
num
==
length
).
assertTrue
();
let
number
=
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
offset
:
0
});
expect
(
number
==
length
+
FILE_CONTENT
.
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_open_async_008 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_0900
* @tc.name fileIO_test_open_async_009
* @tc.desc Test open() interfaces. mode=0o4002.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_async_009
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_open_async_009
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
await
fileIO
.
open
(
fpath
,
fileIO
.
OpenMode
.
NONBLOCK
|
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_open_async_009 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_1000
* @tc.name fileIO_test_open_async_010
* @tc.desc Test open() interfaces. mode=0o200000.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_async_010
'
,
0
,
async
function
(
done
)
{
let
dpath
=
await
nextFileName
(
'
fileIO_test_open_async_010
'
);
fileio
.
mkdirSync
(
dpath
);
try
{
let
file
=
await
fileIO
.
open
(
dpath
,
fileIO
.
OpenMode
.
DIR
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileio
.
rmdirSync
(
dpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_open_async_010 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_1100
* @tc.name fileIO_test_open_async_011
* @tc.desc Test open() interfaces. mode=0o200000. Not a directory.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_async_011
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_open_async_011
'
);
expect
(
prepareFile
(
fpath
,
''
)).
assertTrue
();
try
{
await
fileIO
.
open
(
fpath
,
fileIO
.
OpenMode
.
DIR
|
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileio
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_open_async_011 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900002
&&
e
.
message
==
'
No such file or directory
'
).
assertTrue
;
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_1200
* @tc.name fileIO_test_open_async_012
* @tc.desc Test open() interfaces. mode=0o400002.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_async_012
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_open_async_012
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
await
fileIO
.
open
(
fpath
,
fileIO
.
OpenMode
.
NOFOLLOW
|
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_open_async_012 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_1300
* @tc.name fileIO_test_open_async_013
* @tc.desc Test open() interfaces. mode=0o400002. Shouldn't be Symbolic link.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_async_013
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_open_async_013
'
);
let
ffpath
=
fpath
+
'
aaaa
'
;
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
fileio
.
symlinkSync
(
fpath
,
ffpath
);
await
fileIO
.
open
(
ffpath
,
fileIO
.
OpenMode
.
NOFOLLOW
|
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_open_async_013 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900033
&&
e
.
message
==
'
Too many symbolic links encountered
'
).
assertTrue
;
fileio
.
unlinkSync
(
fpath
);
fileio
.
unlinkSync
(
ffpath
);
done
();
}
});
/**
* @tc.number SUB_DF_FILEIO_OPEN_ASYNC_1400
* @tc.name fileIO_test_open_async_014
* @tc.desc Test open() interfaces. mode=0o4010002.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_open_async_014
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_open_async_014
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
fileIO
.
open
(
fpath
,
fileIO
.
OpenMode
.
SYNC
|
fileIO
.
OpenMode
.
READ_WRITE
,
function
(
err
,
file
)
{
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
});
}
catch
(
err
)
{
console
.
log
(
'
fileIO_test_open_async_014 has failed for
'
+
err
.
message
+
'
, code:
'
+
err
.
code
);
expect
(
false
).
assertTrue
();
}
});
});
}
storage/storagefileiov9jstest/src/main/js/test/members/read.test.js
0 → 100644
浏览文件 @
0c2ff958
/*
* 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
,
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
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
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_sync_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0100
* @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
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
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_sync_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0200
* @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
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
len
=
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
{
offset
:
1
,
});
expect
(
len
==
FILE_CONTENT
.
length
-
1
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_sync_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0300
* @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
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
);
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
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_SYNC_0400
* @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
()
{
try
{
fileIO
.
readSync
(
-
1
,
new
ArrayBuffer
(
4096
));
expect
(
false
).
assertTrue
();
}
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_0500
* @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
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
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_sync_005 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.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
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
res
=
await
fileIO
.
read
(
file
.
fd
,
new
ArrayBuffer
(
4096
));
expect
(
res
==
FILE_CONTENT
.
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_async_000 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_001
* @tc.desc Test read() 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
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
read
(
file
.
fd
,
new
ArrayBuffer
(
4096
),
async
function
(
err
,
readlen
)
{
expect
(
readlen
==
FILE_CONTENT
.
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_read_async_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0200
* @tc.name fileIO_test_read_async_002
* @tc.desc Test read() 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
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_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0300
* @tc.name fileIO_test_read_async_003
* @tc.desc Test read() 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
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
,
});
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
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0400
* @tc.name fileIO_test_read_async_004
* @tc.desc Test read() 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
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_004 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_READ_ASYNC_0500
* @tc.name fileIO_test_read_async_005
* @tc.desc Test read() 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
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
();
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() 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
(
false
).
assertTrue
();
}
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/storagefileiov9jstest/src/main/js/test/members/stat.test.js
0 → 100644
浏览文件 @
0c2ff958
/*
* 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
,
fileIO
,
FILE_CONTENT
,
prepareFile
,
nextFileName
,
isIntNum
,
isBoolean
,
describe
,
it
,
expect
,
}
from
'
../Common
'
;
export
default
function
fileIOStat
()
{
describe
(
'
fileIO_fs_stat
'
,
function
()
{
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_0000
* @tc.name fileIO_stat_sync_000
* @tc.desc Test Stat.statSync() interfaces.
* This interface shall work properly in normal case.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_000
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
stat
!==
null
).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
stat2
!==
null
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_sync_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_0100
* @tc.name fileIO_stat_sync_001
* @tc.desc Test Stat.statSync() interfaces.
* This interface shall throw an exception when the file isnt's exist.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_001
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_001
'
);
try
{
fileIO
.
statSync
(
fpath
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
expect
(
e
.
code
==
13900002
&&
e
.
message
==
'
No such file or directory
'
).
assertTrue
();
console
.
log
(
'
fileIO_stat_sync_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_0200
* @tc.name fileIO_stat_sync_002
* @tc.desc Test Stat.statSync() interfaces.
* This interface shall throw an exception when the file isnt's exist.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_002
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_002
'
);
try
{
fileIO
.
statSync
();
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
console
.
log
(
'
fileIO_stat_sync_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_INO_0000
* @tc.name fileIO_stat_sync_ino_000
* @tc.desc Test Stat.statSync_Ino() interfaces.
* @tc.desc Test the ino member of class Stat
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_ino_000
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_ino_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
isIntNum
(
stat
.
ino
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
isIntNum
(
stat2
.
ino
)).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
info
(
'
fileIO_stat_sync_ino_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_MODE_0000
* @tc.name fileIO_stat_sync_mode_000
* @tc.desc Test Stat.statSync_Mode() interfaces.
* @tc.desc Test the mode member of class Stat
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_mode_000
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_mode_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
isIntNum
(
stat
.
mode
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
isIntNum
(
stat2
.
mode
)).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
info
(
'
fileIO_stat_sync_mode_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_UID_0000
* @tc.name fileIO_stat_sync_uid_000
* @tc.desc Test Stat.statSync_Uid() interfaces.
* @tc.desc Test the uid member of class Stat
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_uid_000
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_uid_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
isIntNum
(
stat
.
uid
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
isIntNum
(
stat2
.
uid
)).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_sync_uid_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_GID_0000
* @tc.name fileIO_stat_sync_gid_000
* @tc.desc Test Stat.statSync_Gid() interfaces.
* @tc.desc Test the gid member of class Stat
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_gid_000
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_gid_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
isIntNum
(
stat
.
gid
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
isIntNum
(
stat2
.
gid
)).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_sync_gid_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_SIZE_0000
* @tc.name fileIO_stat_sync_size_000
* @tc.desc Test Stat.statSync_Size() interfaces.
* @tc.desc Test the size member of class Stat
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_size_000
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_size_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
isIntNum
(
stat
.
size
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
isIntNum
(
stat2
.
size
)).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_sync_size_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_BLKSIZE_0000
* @tc.name fileIO_stat_sync_blksize_000
* @tc.desc Test Stat.statSync_Blksize() interfaces.
* @tc.desc Test the blksize member of class Stat
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_blksize_000
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_blksize_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
isIntNum
(
stat
.
blksize
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
isIntNum
(
stat2
.
blksize
)).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_sync_blksize_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ATIME_0000
* @tc.name fileIO_stat_sync_atime_000
* @tc.desc Test Stat.statSync_Atime() interfaces.
* @tc.desc Test the atime member of class Stat
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_atime_000
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_atime_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
isIntNum
(
stat
.
atime
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
isIntNum
(
stat2
.
atime
)).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_sync_atime_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_MTIME_0000
* @tc.name fileIO_stat_sync_mtime_000
* @tc.desc Test Stat.statSync_Mtime() interfaces.
* @tc.desc Test the mtime member of class Stat
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_mtime_000
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_mtime_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
isIntNum
(
stat
.
mtime
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
isIntNum
(
stat2
.
mtime
)).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_sync_mtime_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_CTIME_0000
* @tc.name fileIO_stat_sync_ctime_000
* @tc.desc Test Stat.statSync_Ctime() interfaces.
* @tc.desc Test the ctime member of class Stat
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_ctime_000
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_ctime_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
isIntNum
(
stat
.
ctime
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
isIntNum
(
stat2
.
ctime
)).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_sync_ctime_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISBLOCKDEVICE_0000
* @tc.name fileIO_stat_sync_is_block_device_000
* @tc.desc Test Stat.statSync_IsBlockDevice() interfaces.
* @tc.desc Test the isBlockDevice() method of class Stat.
* This interface shall return a boolean variable.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_block_device_000
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_block_device_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
isBoolean
(
stat
.
isBlockDevice
())).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
isBoolean
(
stat2
.
isBlockDevice
())).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_sync_is_block_device_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISBLOCKDEVICE_0100
* @tc.name fileIO_stat_sync_is_block_device_001
* @tc.desc Test Stat.statSync_IsBlockDevice() interfaces.
* @tc.desc Test the isBlockDevice() method of class Stat.
* This interface shall not treat a normal file as a block special device.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_block_device_001
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_block_device_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
stat
.
isBlockDevice
()
===
false
).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
stat2
.
isBlockDevice
()
===
false
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_sync_is_block_device_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISBLOCKDEVICE_0200
* @tc.name fileIO_stat_sync_is_block_device_002
* @tc.desc Test Stat.statSync_IsBlockDevice() interfaces.
* @tc.desc Test the isBlockDevice() method of class Stat.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_block_device_002
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_block_device_002
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
stat
.
isBlockDevice
(
-
1
)
===
false
).
assertTrue
();
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
info
(
'
fileIO_stat_sync_is_block_device_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
fileio
.
unlinkSync
(
fpath
);
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISBLOCKDEVICE_0300
* @tc.name fileIO_stat_sync_is_block_device_003
* @tc.desc Test Stat.statSync_IsBlockDevice() interfaces.
* @tc.desc Test the isBlockDevice() method of class Stat.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_block_device_003
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_block_device_003
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
;
try
{
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
stat2
.
isBlockDevice
(
-
1
)
===
false
).
assertTrue
();
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
console
.
info
(
'
fileIO_stat_sync_is_block_device_003 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISCHARACTER_DEVICE_0000
* @tc.name fileIO_stat_sync_is_character_device_000
* @tc.desc Test Stat.statsync_IsCharacterDevice() interfaces.
* This interface shall return a boolean variable.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_character_device_000
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_character_device_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
isBoolean
(
stat
.
isCharacterDevice
())).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
isBoolean
(
stat2
.
isCharacterDevice
())).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_sync_is_character_device_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISCHARACTER_DEVICE_0100
* @tc.name fileIO_stat_sync_is_character_device_001
* @tc.desc Test Stat.statsync_IsCharacterDevice() interfaces.
* This interface shall not treat a normal file as a character special device.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_character_device_001
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_character_device_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
stat
.
isCharacterDevice
()
===
false
).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
stat2
.
isCharacterDevice
()
===
false
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_sync_is_character_device_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISCHARACTER_DEVICE_0200
* @tc.name fileIO_stat_sync_is_character_device_002
* @tc.desc Test Stat.statsync_IsCharacterDevice() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_character_device_002
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_character_device_002
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
stat
.
isCharacterDevice
(
-
1
)
===
false
).
assertTrue
();
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileio
.
unlinkSync
(
fpath
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISCHARACTER_DEVICE_0300
* @tc.name fileIO_stat_sync_is_character_device_003
* @tc.desc Test Stat.statsync_IsCharacterDevice() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_character_device_003
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_character_device_003
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
;
try
{
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
stat2
.
isCharacterDevice
(
-
1
)
===
false
).
assertTrue
();
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISDIRECTORY_0000
* @tc.name fileIO_stat_sync_is_directory_000
* @tc.desc Test Stat.statsync_isDirectory() interfaces.
* This interface shall return a boolean variable.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_directory_000
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_directory_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
isBoolean
(
stat
.
isDirectory
())).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
isBoolean
(
stat2
.
isDirectory
())).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_sync_is_directory_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISDIRECTORY_0100
* @tc.name fileIO_stat_sync_is_directory_001
* @tc.desc Test Stat.statsync_isDirectory() interfaces.
* This interface shall not treat a normal file as a directory.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_directory_001
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_directory_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
stat
.
isDirectory
()
===
false
).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
stat2
.
isDirectory
()
===
false
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_sync_is_directory_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISDIRECTORY_0200
* @tc.name fileIO_stat_sync_is_directory_002
* @tc.desc Test Stat.statsync_isDirectory() interfaces.
* This interface shall treat a directory as a directory.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_directory_002
'
,
0
,
async
function
()
{
let
dpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_directory_002
'
);
try
{
fileio
.
mkdirSync
(
dpath
);
let
stat
=
fileIO
.
statSync
(
dpath
);
expect
(
stat
.
isDirectory
()).
assertTrue
();
let
file
=
fileIO
.
openSync
(
dpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
stat2
.
isDirectory
()).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
rmdirSync
(
dpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_sync_is_directory_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISDIRECTORY_0300
* @tc.name fileIO_stat_sync_is_directory_003
* @tc.desc Test Stat.statsync_isDirectory() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_directory_003
'
,
0
,
async
function
()
{
let
dpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_directory_003
'
)
+
'
d
'
;
try
{
fileio
.
mkdirSync
(
dpath
);
let
stat
=
fileIO
.
statSync
(
dpath
);
expect
(
stat
.
isDirectory
(
-
1
)
===
false
).
assertTrue
();
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileio
.
rmdirSync
(
dpath
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISDIRECTORY_0400
* @tc.name fileIO_stat_sync_is_directory_004
* @tc.desc Test Stat.statsync_isDirectory() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_directory_004
'
,
0
,
async
function
()
{
let
dpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_directory_004
'
)
+
'
d
'
;
let
file
;
try
{
fileio
.
mkdirSync
(
dpath
);
file
=
fileIO
.
openSync
(
dpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
stat2
.
isDirectory
(
-
1
)
===
false
).
assertTrue
();
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileio
.
closeSync
(
file
.
fd
);
fileio
.
rmdirSync
(
dpath
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFIFO_0000
* @tc.name fileIO_stat_sync_is_fifo_000
* @tc.desc Test Stat.statsync_isFIFO() interfaces.
* This interface shall return a boolean variable.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_fifo_000
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_fifo_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
isBoolean
(
stat
.
isFIFO
())).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
isBoolean
(
stat2
.
isFIFO
())).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_sync_is_fifo_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFIFO_0100
* @tc.name fileIO_stat_sync_is_fifo_001
* @tc.desc Test Stat.statsync_isFIFO() interfaces.
* This interface shall not treat a normal file as a FIFO.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_fifo_001
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_fifo_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
stat
.
isFIFO
()
===
false
).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
stat2
.
isFIFO
()
===
false
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_sync_is_fifo_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFIFO_0200
* @tc.name fileIO_stat_sync_is_fifo_002
* @tc.desc Test Stat.statsync_isFIFO() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_fifo_002
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_fifo_002
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
stat
.
isFile
(
-
1
)
===
false
).
assertTrue
();
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileio
.
unlinkSync
(
fpath
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFIFO_0300
* @tc.name fileIO_stat_sync_is_fifo_003
* @tc.desc Test Stat.statsync_isFIFO() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_fifo_003
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_fifo_003
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
stat2
.
isFile
(
-
1
)
===
false
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileio
.
unlinkSync
(
fpath
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFILE_0000
* @tc.name fileIO_stat_sync_is_file_000
* @tc.desc Test Stat.statsync_isFile() interfaces.
* This interface shall return a boolean variable.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_file_000
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_file_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
isBoolean
(
stat
.
isFile
())).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
isBoolean
(
stat2
.
isFile
())).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_sync_is_file_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFILE_0100
* @tc.name fileIO_stat_sync_is_file_001
* @tc.desc Test Stat.statsync_isFile() interfaces.
* This interface shall treat a normal file as a normal file.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_file_001
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_file_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
stat
.
isFile
()).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
stat2
.
isFile
()).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_sync_is_file_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFILE_0200
* @tc.name fileIO_stat_sync_is_file_002
* @tc.desc Test Stat.statsync_isFile() interfaces.
* This interface shall not treat a directory as a normal file.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_file_002
'
,
0
,
async
function
()
{
let
dpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_file_002
'
);
try
{
fileio
.
mkdirSync
(
dpath
);
let
stat
=
fileIO
.
statSync
(
dpath
);
expect
(
stat
.
isFile
()
===
false
).
assertTrue
();
let
file
=
fileIO
.
openSync
(
dpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
stat2
.
isFile
()
===
false
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
rmdirSync
(
dpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_sync_is_file_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFILE_0300
* @tc.name fileIO_stat_sync_is_file_003
* @tc.desc Test Stat.statsync_isFile() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_file_003
'
,
0
,
async
function
()
{
let
dpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_file_003
'
);
try
{
fileio
.
mkdirSync
(
dpath
);
let
stat
=
fileIO
.
statSync
(
dpath
);
expect
(
stat
.
isFile
(
-
1
)
===
false
).
assertTrue
();
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileio
.
rmdirSync
(
dpath
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISFILE_0400
* @tc.name fileIO_stat_sync_is_file_004
* @tc.desc Test Stat.statsync_isFile() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_file_004
'
,
0
,
async
function
()
{
let
dpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_file_004
'
);
let
file
;
try
{
fileio
.
mkdirSync
(
dpath
);
file
=
fileIO
.
openSync
(
dpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
stat2
.
isFile
(
-
1
)
===
false
).
assertTrue
();
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileio
.
closeSync
(
file
.
fd
);
fileio
.
rmdirSync
(
dpath
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSOCKET_0000
* @tc.name fileIO_stat_sync_is_socket_000
* @tc.desc Test Stat.statsync_isSocket() interfaces.
* This interface shall return a boolean variable.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_socket_000
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_socket_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
isBoolean
(
stat
.
isSocket
())).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
isBoolean
(
stat2
.
isSocket
())).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_sync_is_socket_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSOCKET_0100
* @tc.name fileIO_stat_sync_is_socket_001
* @tc.desc Test Stat.statsync_isSocket() interfaces.
* This interface shall not treat a file as a socket.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_socket_001
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_socket_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
stat
.
isSocket
()
===
false
).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
stat2
.
isSocket
()
===
false
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_sync_is_socket_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSOCKET_0200
* @tc.name fileIO_stat_sync_is_socket_002
* @tc.desc Test Stat.statsync_isSocket() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_socket_002
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_socket_002
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
stat
.
isSocket
(
-
1
)
===
false
).
assertTrue
();
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileio
.
unlinkSync
(
fpath
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSOCKET_0300
* @tc.name fileIO_stat_sync_is_socket_003
* @tc.desc Test Stat.statsync_isSocket() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_socket_003
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_socket_003
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
;
try
{
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
stat2
.
isSocket
(
-
1
)
===
false
).
assertTrue
();
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSYMBOLICLINK_0000
* @tc.name fileIO_stat_sync_is_symbolic_link_000
* @tc.desc Test Stat.statasync_isSymbolicLink() interfaces.
* This interface shall return a boolean variable.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_symbolic_link_000
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_symbolic_link_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
isBoolean
(
stat
.
isSymbolicLink
())).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
isBoolean
(
stat2
.
isSymbolicLink
())).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_sync_is_symbolic_link_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSYMBOLICLINK_0100
* @tc.name fileIO_stat_sync_is_symbolic_link_001
* @tc.desc Test Stat.statasync_isSymbolicLink() interfaces.
* This interface shall not treat a normal file as a symbolic link.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_symbolic_link_001
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_symbolic_link_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
stat
.
isSymbolicLink
()
===
false
).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
stat2
.
isSymbolicLink
()
===
false
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_sync_is_symbolic_link_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSYMBOLICLINK_0200
* @tc.name fileIO_stat_sync_is_symbolic_link_002
* @tc.desc Test Stat.isSymbolicLink() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_symbolic_link_002
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_symbolic_link_002
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
stat
.
isSymbolicLink
(
-
1
)
===
false
).
assertTrue
();
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileio
.
unlinkSync
(
fpath
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_ISSYMBOLICLINK_0300
* @tc.name fileIO_stat_sync_is_symbolic_link_003
* @tc.desc Test Stat.isSymbolicLink() interfaces.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_sync_is_symbolic_link_003
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_sync_is_symbolic_link_003
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
;
try
{
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
stat2
.
isSymbolicLink
(
-
1
)
===
false
).
assertTrue
();
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_ASYNC_0000
* @tc.name fileIO_stat_async_000
* @tc.desc Test Stat.statAsync() interface.
* This interface shall work properly in normal case when providing the promise async model.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_async_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_async_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
fileIO
.
stat
(
fpath
).
then
((
stat
)
=>
{
expect
(
stat
!==
null
).
assertTrue
();
});
let
file
=
fileIO
.
openSync
(
fpath
);
fileIO
.
stat
(
file
.
fd
).
then
((
stat2
)
=>
{
expect
(
stat2
!==
null
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
});
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_async_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_ASYNC_0100
* @tc.name fileIO_stat_async_001
* @tc.desc Test Stat.statAsync() interface.
* This interface shall work properly in normal case when providing the callback async model.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_async_001
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_async_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
fileIO
.
stat
(
fpath
,
function
(
error
)
{
fileio
.
unlinkSync
(
fpath
);
done
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_async_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_ASYNC_0200
* @tc.name fileIO_stat_async_002
* @tc.desc Test Stat.statAsync() interface.
* This interface shall work properly in normal case when providing the callback async model.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_async_002
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_async_002
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
);
fileIO
.
stat
(
file
.
fd
,
function
(
error
)
{
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_async_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_ASYNC_INO_0000
* @tc.name fileIO_stat_async_ino_000
* @tc.desc Test the ino member of class Stat.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_async_ino_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_async_ino_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
await
fileIO
.
stat
(
fpath
);
expect
(
isIntNum
(
stat
.
ino
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
await
fileIO
.
stat
(
file
.
fd
);
expect
(
isIntNum
(
stat2
.
ino
)).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_async_ino_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_ASYNC_MODE_0000
* @tc.name fileIO_stat_async_mode_000
* @tc.desc Test the mode member of class Stat.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_async_mode_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_async_mode_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
await
fileIO
.
stat
(
fpath
);
expect
(
isIntNum
(
stat
.
mode
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
await
fileIO
.
stat
(
file
.
fd
);
expect
(
isIntNum
(
stat2
.
mode
)).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_async_mode_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_ASYNC_UID_0000
* @tc.name fileIO_stat_async_uid_000
* @tc.desc Test the uid member of class Stat.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_async_uid_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_async_uid_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
await
fileIO
.
stat
(
fpath
);
expect
(
isIntNum
(
stat
.
uid
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
await
fileIO
.
stat
(
file
.
fd
);
expect
(
isIntNum
(
stat2
.
uid
)).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_async_uid_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_ASYNC_GID_0000
* @tc.name fileIO_stat_async_gid_000
* @tc.desc Test the gid member of class Stat.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_async_gid_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_async_gid_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
await
fileIO
.
stat
(
fpath
);
expect
(
isIntNum
(
stat
.
gid
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
await
fileIO
.
stat
(
file
.
fd
);
expect
(
isIntNum
(
stat2
.
gid
)).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_async_gid_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_ASYNC_SIZE_0000
* @tc.name fileIO_stat_async_size_000
* @tc.desc Test the size member of class Stat.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_async_size_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_async_size_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
await
fileIO
.
stat
(
fpath
);
expect
(
isIntNum
(
stat
.
size
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
await
fileIO
.
stat
(
file
.
fd
);
expect
(
isIntNum
(
stat2
.
size
)).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_async_size_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_ASYNC_ATIME_0000
* @tc.name fileIO_stat_async_atime_000
* @tc.desc Test Stat.atime() interface.
* @tc.desc Test the atime member of class Stat.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_async_atime_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_async_atime_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
await
fileIO
.
stat
(
fpath
);
expect
(
isIntNum
(
stat
.
atime
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
await
fileIO
.
stat
(
file
.
fd
);
expect
(
isIntNum
(
stat2
.
atime
)).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_async_atime_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_ASYNC_MTIME_0000
* @tc.name fileIO_stat_async_mtime_000
* @tc.desc Test Stat.mtime() interface.
* @tc.desc Test the mtime member of class Stat.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_async_mtime_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_async_mtime_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
await
fileIO
.
stat
(
fpath
);
expect
(
isIntNum
(
stat
.
mtime
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
await
fileIO
.
stat
(
file
.
fd
);
expect
(
isIntNum
(
stat2
.
mtime
)).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_async_mtime_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_ASYNC_CTIME_0000
* @tc.name fileIO_stat_async_ctime_000
* @tc.desc Test the ctime member of class Stat.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_async_ctime_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_async_ctime_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
await
fileIO
.
stat
(
fpath
);
expect
(
isIntNum
(
stat
.
ctime
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
await
fileIO
.
stat
(
file
.
fd
);
expect
(
isIntNum
(
stat2
.
ctime
)).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_async_ctime_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISBLOCKDEVICE_0000
* @tc.name fileIO_stat_async_is_block_device_000
* @tc.desc Test the isBlockDevice method of class Stat.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_async_is_block_device_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_async_is_block_device_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
await
fileIO
.
stat
(
fpath
);
expect
(
isBoolean
(
stat
.
isBlockDevice
())).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
await
fileIO
.
stat
(
file
.
fd
);
expect
(
isBoolean
(
stat2
.
isBlockDevice
())).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_async_is_block_device_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISBLOCKDEVICE_0100
* @tc.name fileIO_stat_async_is_block_device_001
* @tc.desc Test the isBlockDevice method of class Stat.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_async_is_block_device_001
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_async_is_block_device_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
await
fileIO
.
stat
(
fpath
);
expect
(
stat
.
isBlockDevice
()
===
false
).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
await
fileIO
.
stat
(
file
.
fd
);
expect
(
stat2
.
isBlockDevice
()
===
false
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_async_is_block_device_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISCHARACTERDEVICE_0000
* @tc.name fileIO_stat_async_is_character_device_000
* @tc.desc Test the isCharacterDevice method of class Stat.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_async_is_character_device_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_async_is_character_device_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
await
fileIO
.
stat
(
fpath
);
expect
(
isBoolean
(
stat
.
isCharacterDevice
())).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
await
fileIO
.
stat
(
file
.
fd
);
expect
(
isBoolean
(
stat2
.
isCharacterDevice
())).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_async_is_character_device_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISCHARACTERDEVICE_0100
* @tc.name fileIO_stat_async_is_character_device_001
* @tc.desc Test the isCharacterDevice method of class Stat.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_async_is_character_device_001
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_async_is_character_device_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
await
fileIO
.
stat
(
fpath
);
expect
(
stat
.
isCharacterDevice
()
===
false
).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
await
fileIO
.
stat
(
file
.
fd
);
expect
(
stat2
.
isCharacterDevice
()
===
false
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_async_is_character_device_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISDIRECTORY_0000
* @tc.name fileIO_stat_async_is_directory_000
* @tc.desc Test Stat.isDirectory() interface.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_async_is_directory_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_async_is_directory_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
await
fileIO
.
stat
(
fpath
);
expect
(
isBoolean
(
stat
.
isDirectory
())).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
await
fileIO
.
stat
(
file
.
fd
);
expect
(
isBoolean
(
stat2
.
isDirectory
())).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_async_is_directory_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISDIRECTORY_0100
* @tc.name fileIO_stat_async_is_directory_001
* @tc.desc Test Stat.isDirectory() interface.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_async_is_directory_001
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_async_is_directory_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
await
fileIO
.
stat
(
fpath
);
expect
(
stat
.
isDirectory
()
===
false
).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
await
fileIO
.
stat
(
file
.
fd
);
expect
(
stat2
.
isDirectory
()
===
false
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_async_is_directory_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISDIRECTORY_0200
* @tc.name fileIO_stat_async_is_directory_002
* @tc.desc Test Stat.isDirectory() interface.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_async_is_directory_002
'
,
0
,
async
function
(
done
)
{
let
dpath
=
await
nextFileName
(
'
fileIO_stat_async_is_directory_002
'
)
+
'
d
'
;
try
{
fileio
.
mkdirSync
(
dpath
);
let
stat
=
await
fileIO
.
stat
(
dpath
);
expect
(
stat
.
isDirectory
()).
assertTrue
();
let
file
=
fileIO
.
openSync
(
dpath
);
let
stat2
=
await
fileIO
.
stat
(
file
.
fd
);
expect
(
stat2
.
isDirectory
()).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
rmdirSync
(
dpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_async_is_directory_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISFIFO_0000
* @tc.name fileIO_stat_async_is_fifo_000
* @tc.desc Test Stat.isFIFO() interface.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_async_is_fifo_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_async_is_fifo_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
await
fileIO
.
stat
(
fpath
);
expect
(
isBoolean
(
stat
.
isFIFO
())).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
await
fileIO
.
stat
(
file
.
fd
);
expect
(
isBoolean
(
stat2
.
isFIFO
())).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_async_is_fifo_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISFIFO_0100
* @tc.name fileIO_stat_async_is_fifo_001
* @tc.desc Test Stat.isFIFO() interface.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_async_is_fifo_001
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_async_is_fifo_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
await
fileIO
.
stat
(
fpath
);
expect
(
stat
.
isFIFO
()
===
false
).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
await
fileIO
.
stat
(
file
.
fd
);
expect
(
stat2
.
isFIFO
()
===
false
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_async_is_fifo_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISFILE_0000
* @tc.name fileIO_stat_async_is_file_000
* @tc.desc Test Stat.isFile() interface.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_async_is_file_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_async_is_file_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
await
fileIO
.
stat
(
fpath
);
expect
(
isBoolean
(
stat
.
isFile
())).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
await
fileIO
.
stat
(
file
.
fd
);
expect
(
isBoolean
(
stat2
.
isFile
())).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_async_is_file_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISFILE_0100
* @tc.name fileIO_stat_async_is_file_001
* @tc.desc Test Stat.isFile() interface.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_async_is_file_001
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_async_is_file_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
await
fileIO
.
stat
(
fpath
);
expect
(
stat
.
isFile
()).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
await
fileIO
.
stat
(
file
.
fd
);
expect
(
stat2
.
isFile
()).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_async_is_file_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISFILE_0200
* @tc.name fileIO_stat_async_is_file_002
* @tc.desc Test Stat.isFile() interface.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_async_is_file_002
'
,
0
,
async
function
(
done
)
{
let
dpath
=
await
nextFileName
(
'
fileIO_stat_async_is_file_002
'
);
try
{
fileio
.
mkdirSync
(
dpath
);
let
stat
=
await
fileIO
.
stat
(
dpath
);
expect
(
stat
.
isFile
()
===
false
).
assertTrue
();
let
file
=
fileIO
.
openSync
(
dpath
);
let
stat2
=
await
fileIO
.
stat
(
file
.
fd
);
expect
(
stat2
.
isFile
()
===
false
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
rmdirSync
(
dpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_async_is_file_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISSOCKET_0000
* @tc.name fileIO_stat_async_is_socket_000
* @tc.desc Test Stat.isSocket() interface.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_async_is_socket_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_async_is_socket_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
await
fileIO
.
stat
(
fpath
);
expect
(
isBoolean
(
stat
.
isSocket
())).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
await
fileIO
.
stat
(
file
.
fd
);
expect
(
isBoolean
(
stat2
.
isSocket
())).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_async_is_socket_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISSOCKET_0100
* @tc.name fileIO_stat_async_is_socket_001
* @tc.desc Test Stat.isSocket() interface.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_async_is_socket_001
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_async_is_socket_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
await
fileIO
.
stat
(
fpath
);
expect
(
stat
.
isSocket
()
===
false
).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
await
fileIO
.
stat
(
file
.
fd
);
expect
(
stat2
.
isSocket
()
===
false
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_async_is_socket_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISSYMBOLICLINK_0000
* @tc.name fileIO_stat_async_is_symbolic_link_000
* @tc.desc Test Stat.isSymbolicLink() interface.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_async_is_symbolic_link_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_async_is_symbolic_link_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
await
fileIO
.
stat
(
fpath
);
expect
(
isBoolean
(
stat
.
isSymbolicLink
())).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
await
fileIO
.
stat
(
file
.
fd
);
expect
(
isBoolean
(
stat2
.
isSymbolicLink
())).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_async_is_symbolic_link_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_ASYNC_ISSYMBOLICLINK_0100
* @tc.name fileIO_stat_async_is_symbolic_link_001
* @tc.desc Test Stat.isSymbolicLink() interface.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_stat_async_is_symbolic_link_001
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_stat_async_is_symbolic_link_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
await
fileIO
.
stat
(
fpath
);
expect
(
stat
.
isSymbolicLink
()
===
false
).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
);
let
stat2
=
await
fileIO
.
stat
(
file
.
fd
);
expect
(
stat2
.
isSymbolicLink
()
===
false
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_stat_async_is_symbolic_link_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_APPEND_FILE_SYNC_0000
* @tc.name fileIO_stat_sync_append_file_sync_000
* @tc.desc Test Stat.statSync() interface.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_append_file_sync_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_append_file_sync_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
isIntNum
(
stat
.
size
)).
assertTrue
();
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
APPEND
|
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
expect
(
fileIO
.
writeSync
(
file
.
fd
,
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
stat
=
fileIO
.
statSync
(
fpath
);
expect
(
stat
.
size
==
FILE_CONTENT
.
length
*
2
).
assertTrue
();
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_append_file_sync_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
done
();
});
/**
* @tc.number SUB_DF_FILEIO_STAT_SYNC_APPEND_FILE_SYNC_0100
* @tc.name fileIO_stat_sync_append_file_sync_001
* @tc.desc Test Stat.statSync() interface.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_append_file_sync_001
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_append_file_sync_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
APPEND
|
fileIO
.
OpenMode
.
READ_WRITE
);
let
stat
=
fileIO
.
statSync
(
file
.
fd
);
expect
(
isIntNum
(
stat
.
size
)).
assertTrue
();
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
expect
(
fileIO
.
writeSync
(
file
.
fd
,
FILE_CONTENT
)
==
FILE_CONTENT
.
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
let
file2
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
stat
=
fileIO
.
statSync
(
file2
.
fd
);
expect
(
stat
.
size
==
FILE_CONTENT
.
length
*
2
).
assertTrue
();
fileio
.
closeSync
(
file2
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_append_file_sync_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
done
();
});
});
}
storage/storagefileiov9jstest/src/main/js/test/members/truncate.test.js
0 → 100644
浏览文件 @
0c2ff958
/*
* 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
,
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 truncate() 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
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
len
=
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
));
expect
(
len
==
truncateLen
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
info
(
'
fileIO_truncate_async_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0100
* @tc.name fileIO_truncate_async_001
* @tc.desc Test the truncate() 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
file
;
let
truncateLen
=
5
;
try
{
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
truncate
(
file
.
fd
,
truncateLen
,
function
(
err
)
{
let
len
=
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
));
expect
(
len
==
truncateLen
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
})
}
catch
(
e
)
{
console
.
log
(
'
fileIO_truncate_async_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0200
* @tc.name fileIO_truncate_async_002
* @tc.desc Test the truncate() 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
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
len
=
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
));
expect
(
len
==
truncateLen
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
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
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0300
* @tc.name fileIO_truncate_async_003
* @tc.desc Test the truncate() 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
file
;
let
truncateLen
=
2
;
try
{
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
truncate
(
file
.
fd
,
truncateLen
)
.
then
(
function
(
err
)
{
expect
(
err
==
null
).
assertTrue
();
let
len
=
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
));
expect
(
len
==
truncateLen
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
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
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_ASYNC_0400
* @tc.name fileIO_truncate_async_004
* @tc.desc Test the truncate() 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
{
fileIO
.
truncateSync
(
fpath
);
expect
(
fileIO
.
statSync
(
fpath
).
size
==
0
).
assertTrue
();
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_truncate_sync_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0100
* @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
file
;
let
truncateLen
=
5
;
try
{
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
truncateSync
(
file
.
fd
,
truncateLen
);
let
len
=
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
));
expect
(
len
==
truncateLen
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_truncate_sync_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0200
* @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
(
false
).
assertTrue
();
}
catch
(
e
)
{
expect
(
e
.
code
==
13900002
&&
e
.
message
==
'
No such file or directory
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0300
* @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
file
;
let
truncateLen
=
2
;
try
{
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
fileIO
.
truncateSync
(
file
.
fd
,
truncateLen
);
let
len
=
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
));
expect
(
len
==
truncateLen
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_truncate_sync_003 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0400
* @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
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_TRUNCATE_SYNC_0500
* @tc.name fileIO_test_truncate_sync_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_truncate_sync_005 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
!!
e
).
assertTrue
();
}
});
});
}
storage/storagefileiov9jstest/src/main/js/test/members/write.test.js
0 → 100644
浏览文件 @
0c2ff958
/*
* 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
,
fileIO
,
FILE_CONTENT
,
prepareFile
,
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
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
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
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_sync_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0100
* @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
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
expect
(
fileIO
.
writeSync
(
file
.
fd
,
FILE_CONTENT
,
{
encoding
:
'
utf-8
'
,
})
==
FILE_CONTENT
.
length
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_sync_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0200
* @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
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
expect
(
fileIO
.
writeSync
(
file
.
fd
,
FILE_CONTENT
,
{
length
:
FILE_CONTENT
.
length
-
1
,
})
==
FILE_CONTENT
.
length
-
1
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_sync_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0300
* @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
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
expect
(
fileIO
.
writeSync
(
file
.
fd
,
FILE_CONTENT
,
{
length
:
1
,
})
==
1
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_sync_003 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0400
* @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
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
const
invalidLength
=
9999
;
let
file
;
try
{
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
)
{
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
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_SYNC_0500
* @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
(
false
).
assertTrue
();
}
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_0600
* @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
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
let
writeNum
=
fileIO
.
writeSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
));
expect
(
writeNum
==
4096
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_sync_006 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0000
* @tc.name fileIO_test_write_async_000
* @tc.desc Test write() 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
'
);
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
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_write_async_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0100
* @tc.name fileIO_test_write_async_001
* @tc.desc Test write() 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
'
);
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
,
});
expect
(
writeNum
==
3
).
assertTrue
();
fileio
.
closeSync
(
file
.
fd
);
fileio
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_async_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0200
* @tc.name fileIO_test_write_async_002
* @tc.desc Test write() 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
'
);
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_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0300
* @tc.name fileIO_test_write_async_003
* @tc.desc Test write() 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
'
);
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
:
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_003 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0400
* @tc.name fileIO_test_write_async_004
* @tc.desc Test write() 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
'
);
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
,
new
ArrayBuffer
(
4096
),
function
(
error
,
bytesWritten
)
{
expect
(
bytesWritten
==
4096
).
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
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0500
* @tc.name fileIO_test_write_async_005
* @tc.desc Test write() 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
'
);
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
();
}
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_write_async_005 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_WRITE_ASYNC_0600
* @tc.name fileIO_test_write_async_006
* @tc.desc Test write() 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
'
);
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
,
offset
:
5
,
},
function
(
error
,
bytesWritten
)
{
expect
(
bytesWritten
==
5
).
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.
* @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
();
await
fileIO
.
write
(
file
.
fd
,
FILE_CONTENT
,
{
length
:
5
,
offset
:
5
,
encoding
:
'
utf-8
'
,
},
function
(
error
,
bytesWritten
)
{
expect
(
bytesWritten
==
5
).
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
();
}
});
});
}
storage/storagefileiov9jstest/src/main/resources/base/element/string.json
0 → 100644
浏览文件 @
0c2ff958
{
"string"
:
[
{
"name"
:
"app_name"
,
"value"
:
"storagefilefsjstest"
},
{
"name"
:
"mainability_description"
,
"value"
:
"JS_Phone_Empty Feature Ability"
},
{
"name"
:
"MainAbility_desc"
,
"value"
:
"description"
},
{
"name"
:
"MainAbility_label"
,
"value"
:
"label"
},
{
"name"
:
"TestAbility_desc"
,
"value"
:
"description"
},
{
"name"
:
"TestAbility_label"
,
"value"
:
"label"
}
]
}
storage/storagefileiov9jstest/src/main/resources/base/media/icon.png
0 → 100644
浏览文件 @
0c2ff958
6.6 KB
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录