Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
0a4b7048
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看板
提交
0a4b7048
编写于
6月 26, 2023
作者:
F
fengjq
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add dup interface for file_api
Signed-off-by:
N
fengjq
<
fengjunqing@huawei.com
>
上级
64ea3045
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
187 addition
and
0 deletion
+187
-0
storage/storagefileiov9jstest/src/main/js/test/List.test.js
storage/storagefileiov9jstest/src/main/js/test/List.test.js
+2
-0
storage/storagefileiov9jstest/src/main/js/test/members/dup.test.js
...toragefileiov9jstest/src/main/js/test/members/dup.test.js
+185
-0
未找到文件。
storage/storagefileiov9jstest/src/main/js/test/List.test.js
浏览文件 @
0a4b7048
...
@@ -18,6 +18,7 @@ import fileIOClose from './members/close.test.js'
...
@@ -18,6 +18,7 @@ import fileIOClose from './members/close.test.js'
import
fileIOCopyDir
from
'
./members/copyDir.test
'
import
fileIOCopyDir
from
'
./members/copyDir.test
'
import
fileIOCopyfile
from
'
./members/copyFile.test.js
'
import
fileIOCopyfile
from
'
./members/copyFile.test.js
'
import
fileIOCreateStream
from
'
./members/createStream.test.js
'
import
fileIOCreateStream
from
'
./members/createStream.test.js
'
import
fileIODup
from
'
./members/dup.test.js
'
import
fileIOFdatasync
from
'
./members/fdatasync.test.js
'
import
fileIOFdatasync
from
'
./members/fdatasync.test.js
'
import
fileIOFdOpenStream
from
'
./members/fdopenStream.test.js
'
import
fileIOFdOpenStream
from
'
./members/fdopenStream.test.js
'
import
fileIOFileLock
from
'
./members/fileLock.test.js
'
import
fileIOFileLock
from
'
./members/fileLock.test.js
'
...
@@ -50,6 +51,7 @@ export default function testsuite() {
...
@@ -50,6 +51,7 @@ export default function testsuite() {
fileIOCopyDir
()
fileIOCopyDir
()
fileIOCopyfile
()
fileIOCopyfile
()
fileIOCreateStream
()
fileIOCreateStream
()
fileIODup
()
fileIOFdatasync
()
fileIOFdatasync
()
fileIOFdOpenStream
()
fileIOFdOpenStream
()
fileIOFileLock
()
fileIOFileLock
()
...
...
storage/storagefileiov9jstest/src/main/js/test/members/dup.test.js
0 → 100644
浏览文件 @
0a4b7048
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
{
fileIO
,
FILE_CONTENT
,
prepareFile
,
nextFileName
,
describe
,
it
,
expect
,
}
from
'
../Common
'
;
export
default
function
fileIODup
()
{
describe
(
'
fileIO_fs_dup
'
,
function
()
{
/**
* @tc.number SUB_DF_FILEIO_DUP_SYNC_0000
* @tc.name fileIO_test_dup_sync_000
* @tc.desc Test dup() interfaces.
* Verifing the old and new fds share the same file offset.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_dup_sync_000
'
,
0
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_dup_sync_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
let
newFile
=
fileIO
.
dup
(
file
.
fd
);
expect
(
newFile
.
path
==
fpath
).
assertTrue
();
let
bytesWritten
=
fileIO
.
writeSync
(
newFile
.
fd
,
new
ArrayBuffer
(
20
));
expect
(
bytesWritten
==
20
).
assertTrue
();
let
readlen
=
fileIO
.
readSync
(
file
.
fd
,
new
ArrayBuffer
(
4096
));
expect
(
readlen
==
0
).
assertTrue
();
fileIO
.
closeSync
(
file
);
fileIO
.
closeSync
(
newFile
);
fileIO
.
unlinkSync
(
fpath
);
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_dup_sync_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_DUP_SYNC_0100
* @tc.name fileIO_test_dup_sync_001
* @tc.desc Test dup() interfaces.
* Open the file in read-only mode, verifying the new fd is readable.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_dup_sync_001
'
,
3
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_dup_sync_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
newFile
;
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_ONLY
);
newFile
=
fileIO
.
dup
(
file
.
fd
);
fileIO
.
closeSync
(
file
);
expect
(
newFile
.
path
==
fpath
).
assertTrue
();
let
readlen
=
fileIO
.
readSync
(
newFile
.
fd
,
new
ArrayBuffer
(
4096
));
expect
(
readlen
==
FILE_CONTENT
.
length
).
assertTrue
();
fileIO
.
writeSync
(
newFile
.
fd
,
FILE_CONTENT
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileIO
.
closeSync
(
newFile
);
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_dup_sync_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900008
&&
e
.
message
==
'
Bad file descriptor
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_DUP_SYNC_0200
* @tc.name fileIO_test_dup_sync_002
* @tc.desc Test dup() interfaces.
* Open the file in write-only mode, verifying the new fd is writable.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_dup_sync_002
'
,
3
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_dup_sync_002
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
newFile
;
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
WRITE_ONLY
);
newFile
=
fileIO
.
dup
(
file
.
fd
);
fileIO
.
closeSync
(
file
);
expect
(
newFile
.
path
==
fpath
).
assertTrue
();
let
bytesWritten
=
fileIO
.
writeSync
(
newFile
.
fd
,
FILE_CONTENT
);
expect
(
bytesWritten
==
FILE_CONTENT
.
length
).
assertTrue
();
fileIO
.
readSync
(
newFile
.
fd
,
new
ArrayBuffer
(
4096
));
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileIO
.
closeSync
(
newFile
);
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_dup_sync_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900008
&&
e
.
message
==
'
Bad file descriptor
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_DUP_SYNC_0300
* @tc.name fileIO_test_dup_sync_003
* @tc.desc Test dup() interfaces. Missing parameters.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_dup_sync_003
'
,
3
,
function
()
{
try
{
fileIO
.
dup
();
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_dup_sync_003 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_DUP_SYNC_0400
* @tc.name fileIO_test_dup_sync_004
* @tc.desc Test dup() interfaces.
* The file descriptor must be valid(fd > 0).
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_dup_sync_004
'
,
3
,
async
function
()
{
try
{
fileIO
.
dup
(
-
1
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_dup_sync_004 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
}
});
/**
* @tc.number SUB_DF_FILEIO_DUP_SYNC_0500
* @tc.name fileIO_test_dup_sync_005
* @tc.desc Test dup() interfaces.
* The file has been closed and the file descriptor is invalid.
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 3
* @tc.require
*/
it
(
'
fileIO_test_dup_sync_005
'
,
3
,
async
function
()
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_dup_sync_005
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
let
fd
=
file
.
fd
;
fileIO
.
closeSync
(
file
);
let
newFile
=
fileIO
.
dup
(
fd
);
fileIO
.
writeSync
(
newFile
.
fd
,
new
ArrayBuffer
(
20
));
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_dup_sync_005 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900008
&&
e
.
message
==
'
Bad file descriptor
'
).
assertTrue
();
}
});
});
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录