Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
4cbef5cc
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看板
未验证
提交
4cbef5cc
编写于
2月 11, 2023
作者:
O
openharmony_ci
提交者:
Gitee
2月 11, 2023
浏览文件
操作
浏览文件
下载
差异文件
!7532 add filelock xts case
Merge pull request !7532 from caochuan/filelock
上级
a4b38504
fe5537e9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
648 addition
and
0 deletion
+648
-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/fileLock.test.js
...efileiov9jstest/src/main/js/test/members/fileLock.test.js
+646
-0
未找到文件。
storage/storagefileiov9jstest/src/main/js/test/List.test.js
浏览文件 @
4cbef5cc
...
...
@@ -14,6 +14,7 @@
*/
import
fileIOFdatasync
from
'
./members/fdatasync.test.js
'
import
fileIOFileLock
from
'
./members/fileLock.test.js
'
import
fileIOFsync
from
'
./members/fsync.test.js
'
import
fileIOListfile
from
'
./members/listFile.test.js
'
import
fileIOLstat
from
'
./members/lstat.test.js
'
...
...
@@ -26,6 +27,7 @@ import fileIOTruncate from './members/truncate.test.js'
import
fileIOWrite
from
'
./members/write.test.js
'
export
default
function
testsuite
()
{
fileIOFdatasync
()
fileIOFileLock
()
fileIOFsync
()
fileIOListfile
()
fileIOLstat
()
...
...
storage/storagefileiov9jstest/src/main/js/test/members/fileLock.test.js
0 → 100644
浏览文件 @
4cbef5cc
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import
{
fileIO
,
FILE_CONTENT
,
prepareFile
,
nextFileName
,
isIntNum
,
describe
,
it
,
expect
,
}
from
'
../Common
'
;
export
default
function
fileIOFileLock
()
{
describe
(
'
fileIO_fs_file_lock
'
,
function
()
{
/**
* @tc.number FILE_TEST_FILELOCK_PROMISE_0000
* @tc.name fileIO_test_filelock_promise_000
* @tc.desc Test lock() interfaces. argument is : default.
* Open the file, file lock() and unlock()
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_filelock_promise_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_filelock_promise_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
await
file
.
lock
();
file
.
unlock
();
expect
(
true
).
assertTrue
();
fileIO
.
closeSync
(
file
.
fd
);
fileIO
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_filelock_promise_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number FILE_TEST_FILELOCK_PROMISE_0100
* @tc.name fileIO_test_filelock_promise_001
* @tc.desc Test lock() interfaces. argument is : true.
* Open the file, file lock(true) and unlock()
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_filelock_promise_001
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_filelock_promise_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
await
file
.
lock
(
true
);
file
.
unlock
();
expect
(
true
).
assertTrue
();
fileIO
.
closeSync
(
file
.
fd
);
fileIO
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_filelock_promise_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number FILE_TEST_FILELOCK_PROMISE_0200
* @tc.name fileIO_test_filelock_promise_002
* @tc.desc Test lock() interfaces. argument is : false.
* Open the file, file lock(false) and unlock()
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_filelock_promise_002
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_filelock_promise_002
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
await
file
.
lock
(
false
);
file
.
unlock
();
expect
(
true
).
assertTrue
();
fileIO
.
closeSync
(
file
.
fd
);
fileIO
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_filelock_promise_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number FILE_TEST_FILELOCK_PROMISE_0300
* @tc.name fileIO_test_filelock_promise_003
* @tc.desc Test tryLock() interfaces. argument is : default.
* Open the file, file lock() ,tryLock() and unlock()
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_filelock_promise_003
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_filelock_promise_003
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
await
file
.
lock
();
file
.
tryLock
();
file
.
unlock
();
expect
(
true
).
assertTrue
();
fileIO
.
closeSync
(
file
.
fd
);
fileIO
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_filelock_promise_003 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number FILE_TEST_FILELOCK_PROMISE_0400
* @tc.name fileIO_test_filelock_promise_004
* @tc.desc Test tryLock() interfaces. argument is : true.
* Open the file, file lock() ,tryLock(true) and unlock()
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_filelock_promise_004
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_filelock_promise_004
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
await
file
.
lock
();
file
.
tryLock
(
true
);
file
.
unlock
();
expect
(
true
).
assertTrue
();
fileIO
.
closeSync
(
file
.
fd
);
fileIO
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_filelock_promise_004 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number FILE_TEST_FILELOCK_PROMISE_0500
* @tc.name fileIO_test_filelock_promise_005
* @tc.desc Test tryLock() interfaces. argument is : false.
* Open the file, file lock() ,tryLock(false) and unlock()
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_filelock_promise_005
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_filelock_promise_005
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
await
file
.
lock
();
file
.
tryLock
(
false
);
file
.
unlock
();
expect
(
true
).
assertTrue
();
fileIO
.
closeSync
(
file
.
fd
);
fileIO
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_filelock_promise_005 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number FILE_TEST_FILELOCK_PROMISE_0600
* @tc.name fileIO_test_filelock_promise_006
* @tc.desc Open the file, no file lock(), tryLock(), unlock(),
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_filelock_promise_006
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_filelock_promise_006
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
file
.
tryLock
();
file
.
unlock
();
expect
(
true
).
assertTrue
();
fileIO
.
closeSync
(
file
.
fd
);
fileIO
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_filelock_promise_006 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number FILE_TEST_FILELOCK_PROMISE_0700
* @tc.name fileIO_test_filelock_promise_007
* @tc.desc Open the file, no file lock(), no tryLock(), unlock(),
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_filelock_promise_007
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_filelock_promise_007
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
file
.
unlock
();
expect
(
true
).
assertTrue
();
fileIO
.
closeSync
(
file
.
fd
);
fileIO
.
unlinkSync
(
fpath
);
done
();
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_filelock_promise_007 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number FILE_TEST_FILELOCK_PROMISE_ABNORMAL_0000
* @tc.name fileIO_test_filelock_promise_abnormal_000
* @tc.desc Test lock() interfaces. argument is : null.
* Open the file, file lock(null).
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_filelock_promise_abnormal_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_filelock_promise_abnormal_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
;
try
{
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
await
file
.
lock
(
null
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileIO
.
closeSync
(
file
.
fd
);
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_filelock_promise_abnormal_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number FILE_TEST_FILELOCK_PROMISE_ABNORMAL_0100
* @tc.name fileIO_test_filelock_promise_abnormal_001
* @tc.desc Test lock() interfaces. argument is : true, true.
* Open the file, file lock(true, true).
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_filelock_promise_abnormal_001
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_filelock_promise_abnormal_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
;
try
{
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
await
file
.
lock
(
true
,
true
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileIO
.
closeSync
(
file
.
fd
);
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_filelock_promise_abnormal_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number FILE_TEST_FILELOCK_PROMISE_ABNORMAL_0200
* @tc.name fileIO_test_filelock_promise_abnormal_002
* @tc.desc Test lock() interfaces. argument is : -1.
* Open the file, file lock(-1).
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_filelock_promise_abnormal_002
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_filelock_promise_abnormal_002
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
;
try
{
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
await
file
.
lock
(
-
1
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileIO
.
closeSync
(
file
.
fd
);
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_filelock_promise_abnormal_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number FILE_TEST_FILELOCK_PROMISE_ABNORMAL_0300
* @tc.name fileIO_test_filelock_promise_abnormal_003
* @tc.desc Test tryLock() interfaces. argument is : null.
* Open the file, file lock(), tryLock(null).
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_filelock_promise_abnormal_003
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_filelock_promise_abnormal_003
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
;
try
{
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
await
file
.
lock
();
file
.
tryLock
(
null
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileIO
.
closeSync
(
file
.
fd
);
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_filelock_promise_abnormal_003 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number FILE_TEST_FILELOCK_PROMISE_ABNORMAL_0400
* @tc.name fileIO_test_filelock_promise_abnormal_004
* @tc.desc Test tryLock() interfaces. argument is : true, true.
* Open the file, file lock(), tryLock(true, true).
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_filelock_promise_abnormal_004
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_filelock_promise_abnormal_004
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
;
try
{
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
await
file
.
lock
();
file
.
tryLock
(
true
,
true
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileIO
.
closeSync
(
file
.
fd
);
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_filelock_promise_abnormal_004 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number FILE_TEST_FILELOCK_PROMISE_ABNORMAL_0500
* @tc.name fileIO_test_filelock_promise_abnormal_005
* @tc.desc Test tryLock() interfaces. argument is : -1.
* Open the file, file lock(), tryLock(-1).
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_filelock_promise_abnormal_005
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_filelock_promise_abnormal_005
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
;
try
{
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
await
file
.
lock
();
file
.
tryLock
(
-
1
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileIO
.
closeSync
(
file
.
fd
);
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_filelock_promise_abnormal_005 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number FILE_TEST_FILELOCK_PROMISE_ABNORMAL_0600
* @tc.name fileIO_test_filelock_promise_abnormal_006
* @tc.desc Test unlock() interfaces. argument is : true.
* Open the file, file lock(), tryLock(), unlock(true),
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_filelock_promise_abnormal_006
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_filelock_promise_abnormal_006
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
;
try
{
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
await
file
.
lock
();
file
.
tryLock
();
file
.
unlock
(
true
);
expect
(
false
).
assertTrue
();
}
catch
(
e
)
{
fileIO
.
closeSync
(
file
.
fd
);
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_filelock_promise_abnormal_006 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number FILE_TEST_FILELOCK_CALLBACK_0000
* @tc.name fileIO_test_filelock_callback_000
* @tc.desc Test lock() interfaces. argument is : default.
* Open the file, file lock() and unlock()
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_filelock_callback_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_filelock_callback_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
file
.
lock
((
err
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_filelock_callback_000 err
'
+
JSON
.
stringify
(
err
));
expect
(
false
).
assertTrue
();
}
file
.
unlock
();
expect
(
true
).
assertTrue
();
fileIO
.
closeSync
(
file
.
fd
);
fileIO
.
unlinkSync
(
fpath
);
done
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_filelock_callback_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number FILE_TEST_FILELOCK_CALLBACK_0100
* @tc.name fileIO_test_filelock_callback_001
* @tc.desc Test lock() interfaces. argument is : true.
* Open the file, file lock(true) and unlock()
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_filelock_callback_001
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_filelock_callback_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
file
.
lock
(
true
,
(
err
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_filelock_callback_001 err
'
+
JSON
.
stringify
(
err
));
expect
(
false
).
assertTrue
();
}
file
.
unlock
();
expect
(
true
).
assertTrue
();
fileIO
.
closeSync
(
file
.
fd
);
fileIO
.
unlinkSync
(
fpath
);
done
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_filelock_callback_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number FILE_TEST_FILELOCK_CALLBACK_0200
* @tc.name fileIO_test_filelock_callback_002
* @tc.desc Test lock() interfaces. argument is : false.
* Open the file, file lock(false) and unlock()
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_filelock_callback_002
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_filelock_callback_002
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
try
{
let
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
file
.
lock
(
false
,
(
err
)
=>
{
if
(
err
)
{
console
.
log
(
'
fileIO_test_filelock_callback_002 err
'
+
JSON
.
stringify
(
err
));
expect
(
false
).
assertTrue
();
}
file
.
unlock
();
expect
(
true
).
assertTrue
();
fileIO
.
closeSync
(
file
.
fd
);
fileIO
.
unlinkSync
(
fpath
);
done
();
});
}
catch
(
e
)
{
console
.
log
(
'
fileIO_test_filelock_callback_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
false
).
assertTrue
();
}
});
/**
* @tc.number FILE_TEST_FILELOCK_CALLBACK_ABNORMAL_0000
* @tc.name fileIO_test_filelock_callback_abnormal_000
* @tc.desc Test lock() interfaces. argument is : null.
* Open the file, file lock(null).
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_filelock_callback_abnormal_000
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_filelock_callback_abnormal_000
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
;
try
{
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
file
.
lock
(
null
,
(
err
)
=>
{
expect
(
false
).
assertTrue
();
});
}
catch
(
e
)
{
fileIO
.
closeSync
(
file
.
fd
);
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_filelock_callback_abnormal_000 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number FILE_TEST_FILELOCK_CALLBACK_ABNORMAL_0100
* @tc.name fileIO_test_filelock_callback_abnormal_001
* @tc.desc Test lock() interfaces. argument is : true, true.
* Open the file, file lock(true, true).
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_filelock_callback_abnormal_001
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_filelock_callback_abnormal_001
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
;
try
{
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
file
.
lock
(
true
,
true
,
(
err
)
=>
{
expect
(
false
).
assertTrue
();
});
}
catch
(
e
)
{
fileIO
.
closeSync
(
file
.
fd
);
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_filelock_callback_abnormal_001 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
done
();
}
});
/**
* @tc.number FILE_TEST_FILELOCK_CALLBACK_ABNORMAL_0200
* @tc.name fileIO_test_filelock_callback_abnormal_002
* @tc.desc Test lock() interfaces. argument is : -1.
* Open the file, file lock(-1).
* @tc.size MEDIUM
* @tc.type Functoin
* @tc.level Level 0
* @tc.require
*/
it
(
'
fileIO_test_filelock_callback_abnormal_002
'
,
0
,
async
function
(
done
)
{
let
fpath
=
await
nextFileName
(
'
fileIO_test_filelock_callback_abnormal_002
'
);
expect
(
prepareFile
(
fpath
,
FILE_CONTENT
)).
assertTrue
();
let
file
;
try
{
file
=
fileIO
.
openSync
(
fpath
,
fileIO
.
OpenMode
.
READ_WRITE
);
expect
(
isIntNum
(
file
.
fd
)).
assertTrue
();
file
.
lock
(
-
1
,
(
err
)
=>
{
expect
(
false
).
assertTrue
();
});
}
catch
(
e
)
{
fileIO
.
closeSync
(
file
.
fd
);
fileIO
.
unlinkSync
(
fpath
);
console
.
log
(
'
fileIO_test_filelock_callback_abnormal_002 has failed for
'
+
e
.
message
+
'
, code:
'
+
e
.
code
);
expect
(
e
.
code
==
13900020
&&
e
.
message
==
'
Invalid argument
'
).
assertTrue
();
done
();
}
});
});
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录