diff --git a/interfaces/test/unittest/BUILD.gn b/interfaces/test/unittest/BUILD.gn index 3a6c6eb263f86b72ed9418d085f89ade25f70f08..1c1ca95da3386de462fb78cd5bcf6e9c765b9c73 100644 --- a/interfaces/test/unittest/BUILD.gn +++ b/interfaces/test/unittest/BUILD.gn @@ -17,7 +17,10 @@ group("file_api_unittest") { "class_file:class_file_test", "filemgmt_libn_test:filemgmt_libn_test", "js:ani_file_fs_test", + "js:ani_file_fs_mock_test", "remote_uri:remote_uri_test", "task_signal:task_signal_test", + "js:ani_file_hash_test", + "js:ani_file_securitylabel_test", ] } diff --git a/interfaces/test/unittest/js/BUILD.gn b/interfaces/test/unittest/js/BUILD.gn index a22cb0a2b7c27d01c14e9d238930fb1c01014702..2ca2e73dd0e261970fbeb5ef5b6d36bda240e7b6 100644 --- a/interfaces/test/unittest/js/BUILD.gn +++ b/interfaces/test/unittest/js/BUILD.gn @@ -64,4 +64,114 @@ ohos_unittest("ani_file_fs_test") { defines = [ "private=public", ] + + cflags_cc = [ "-DENABLE_NAPI_MOCK" ] +} + +ohos_unittest("ani_file_fs_mock_test") { + branch_protector_ret = "pac_ret" + testonly = true + + module_out_path = "file_api/file_api" + + resource_config_file = "../resource/ohos_test.xml" + + include_dirs = [ + "${file_api_path}/interfaces/kits/js/src/mod_fs/class_atomicfile", + "${file_api_path}/interfaces/kits/js/src/mod_fs/class_file", + "${file_api_path}/interfaces/kits/js/src/mod_fs/class_randomaccessfile", + "${file_api_path}/interfaces/kits/js/src/mod_fs/class_readeriterator", + "${file_api_path}/interfaces/kits/js/src/mod_fs/class_stat", + "${file_api_path}/interfaces/kits/js/src/mod_fs/class_stream", + "${file_api_path}/interfaces/kits/js/src/mod_fs/properties", + "${file_api_path}/interfaces/test/unittest/js/mod_fs/class_stream/mock", + "${file_api_path}/interfaces/test/unittest/js/mod_fs/properties/mock", + ] + + sources = [ + "mod_fs/class_stream/fs_stream_mock_test.cpp", + "mod_fs/class_stream/mock/c_mock.cpp", + ] + + deps = [ + "${file_api_path}/interfaces/kits/native:remote_uri_native", + "${file_api_path}/interfaces/kits/native:task_signal_native", + "${file_api_path}/interfaces/kits/rust:rust_file", + "${utils_path}/filemgmt_libfs:filemgmt_libfs", + "${utils_path}/filemgmt_libhilog:filemgmt_libhilog", + "${file_api_path}/interfaces/kits/js:ani_file_fs", + ] + + external_deps = [ + "ability_runtime:ability_manager", + "app_file_service:fileuri_native", + "c_utils:utils", + "googletest:gmock_main", + "googletest:gtest_main", + "hilog:libhilog", + "ipc:ipc_core", + "libuv:uv", + ] + + defines = [ + "private=public", + ] +} + +ohos_unittest("ani_file_hash_test") { + module_out_path = "file_api/file_api" + + resource_config_file = "../resource/ohos_test.xml" + + sources = [ + "mod_hash/hash_core_test.cpp", + ] + + include_dirs = [ + "mock/libuv", + "${file_api_path}/interfaces/kits/js/src/mod_hash", + ] + + deps = [ + "${utils_path}/filemgmt_libhilog:filemgmt_libhilog", + "${utils_path}/filemgmt_libfs:filemgmt_libfs", + "${file_api_path}/interfaces/kits/js:ani_file_hash", + ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "libuv:uv", + "googletest:gmock_main", + "googletest:gtest_main", + ] +} + +ohos_unittest("ani_file_securitylabel_test") { + module_out_path = "file_api/file_api" + + resource_config_file = "../resource/ohos_test.xml" + + sources = [ + "mod_securitylabel/securitylabel_core_test.cpp", + ] + + include_dirs = [ + "mock/libuv", + "${file_api_path}/interfaces/kits/js/src/mod_securitylabel", + ] + + deps = [ + "${utils_path}/filemgmt_libhilog:filemgmt_libhilog", + "${utils_path}/filemgmt_libfs:filemgmt_libfs", + "${file_api_path}/interfaces/kits/js:ani_file_securitylabel", + ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "libuv:uv", + "googletest:gmock_main", + "googletest:gtest_main", + ] } \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/class_stream/fs_stream_mock_test.cpp b/interfaces/test/unittest/js/mod_fs/class_stream/fs_stream_mock_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7e04b342a4ef8ee2a28607db1d70517a41a8fc30 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/class_stream/fs_stream_mock_test.cpp @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2025 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. + */ + +#include +#include "c_mock.h" +#include "create_stream_core.h" +#include "fs_utils.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +using namespace std; + +static const string g_streamFilePath = "/data/test/FsStreamCoreTest.txt"; + +class FsStreamMockTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + mock_ = std::make_shared(); + ICMock::ins = mock_; + int32_t fd = open(g_streamFilePath.c_str(), CREATE | O_RDWR, 0644); + close(fd); + }; + static void TearDownTestCase() + { + ICMock::ins = nullptr; + mock_ = nullptr; + rmdir(g_streamFilePath.c_str()); + }; + void SetUp() {}; + void TearDown() {}; + + static inline std::shared_ptr mock_ = nullptr; +}; + +/** + * @tc.name: FsStreamSeekTest_0001 + * @tc.desc: Test function of Seek() interface for fail fseek. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(FsStreamMockTest, FsStreamSeekTest_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FsStreamMockTest-begin FsStreamSeekTest_0001"; + auto ret = CreateStreamCore::DoCreateStream(g_streamFilePath, "r+"); + ASSERT_TRUE(ret.IsSuccess()); + auto result = ret.GetData().value(); + + EXPECT_CALL(*mock_, fseek(testing::_, testing::_, testing::_)).WillOnce(testing::Return(-1)); + + auto retSk = result->Seek(1); + EXPECT_FALSE(retSk.IsSuccess()); + + auto retCs = result->Close(); + ASSERT_TRUE(retCs.IsSuccess()); + + GTEST_LOG_(INFO) << "FsStreamMockTest-end FsStreamSeekTest_0001"; +} + +/** + * @tc.name: FsStreamSeekTest_0002 + * @tc.desc: Test function of Seek() interface for fail ftell. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(FsStreamMockTest, FsStreamSeekTest_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FsStreamMockTest-begin FsStreamSeekTest_0002"; + auto ret = CreateStreamCore::DoCreateStream(g_streamFilePath, "r+"); + ASSERT_TRUE(ret.IsSuccess()); + auto result = ret.GetData().value(); + + EXPECT_CALL(*mock_, fseek(testing::_, testing::_, testing::_)).WillOnce(testing::Return(0)); + EXPECT_CALL(*mock_, ftell(testing::_)).WillOnce(testing::Return(-1)); + + auto retSk = result->Seek(1); + EXPECT_FALSE(retSk.IsSuccess()); + + auto retCs = result->Close(); + ASSERT_TRUE(retCs.IsSuccess()); + + GTEST_LOG_(INFO) << "FsStreamMockTest-end FsStreamSeekTest_0002"; +} + +/** + * @tc.name: FsStreamWriteTest_0001 + * @tc.desc: Test function of Write() interface for string fail fseek. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(FsStreamMockTest, FsStreamWriteTest_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FsStreamMockTest-begin FsStreamWriteTest_0001"; + auto ret = CreateStreamCore::DoCreateStream(g_streamFilePath, "w+"); + ASSERT_TRUE(ret.IsSuccess()); + auto result = ret.GetData().value(); + + EXPECT_CALL(*mock_, fseek(testing::_, testing::_, testing::_)).WillOnce(testing::Return(-1)); + + WriteOptions opt; + opt.offset = 5; + auto retWr = result->Write("FsStreamWriteTest_0001", opt); + EXPECT_FALSE(retWr.IsSuccess()); + + auto retCs = result->Close(); + ASSERT_TRUE(retCs.IsSuccess()); + + GTEST_LOG_(INFO) << "FsStreamMockTest-end FsStreamWriteTest_0001"; +} + +/** + * @tc.name: FsStreamWriteTest_0002 + * @tc.desc: Test function of Write() interface for ArrayBuffer fail fseek. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(FsStreamMockTest, FsStreamWriteTest_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FsStreamMockTest-begin FsStreamWriteTest_0002"; + auto ret = CreateStreamCore::DoCreateStream(g_streamFilePath, "w+"); + ASSERT_TRUE(ret.IsSuccess()); + auto result = ret.GetData().value(); + + EXPECT_CALL(*mock_, fseek(testing::_, testing::_, testing::_)).WillOnce(testing::Return(-1)); + + WriteOptions opt; + opt.offset = 5; + string buf = "FsStreamWriteTest_0002"; + auto retWr = result->Write(ArrayBuffer(static_cast(buf.data()), buf.length()), opt); + EXPECT_FALSE(retWr.IsSuccess()); + + auto retCs = result->Close(); + ASSERT_TRUE(retCs.IsSuccess()); + + GTEST_LOG_(INFO) << "FsStreamMockTest-end FsStreamWriteTest_0002"; +} + +/** + * @tc.name: FsStreamReadTest_0001 + * @tc.desc: Test function of Read() interface for fail fseek. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(FsStreamMockTest, FsStreamReadTest_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FsStreamMockTest-begin FsStreamReadTest_0001"; + auto ret = CreateStreamCore::DoCreateStream(g_streamFilePath, "r+"); + ASSERT_TRUE(ret.IsSuccess()); + auto result = ret.GetData().value(); + + void *buffer = std::malloc(4096); + ArrayBuffer arrayBuffer(buffer, 4096); + + EXPECT_CALL(*mock_, fseek(testing::_, testing::_, testing::_)).WillOnce(testing::Return(-1)); + + ReadOptions opt; + opt.offset = 5; + auto retRd = result->Read(arrayBuffer, opt); + EXPECT_FALSE(retRd.IsSuccess()); + + delete buffer; + auto retCs = result->Close(); + ASSERT_TRUE(retCs.IsSuccess()); + + GTEST_LOG_(INFO) << "FsStreamMockTest-end FsStreamReadTest_0001"; +} + +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/class_stream/mock/c_mock.cpp b/interfaces/test/unittest/js/mod_fs/class_stream/mock/c_mock.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f9567b0d5eba004b7c7856a3296f0fef100795c3 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/class_stream/mock/c_mock.cpp @@ -0,0 +1,31 @@ +/* +* Copyright (C) 2025 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. +*/ + +#include "c_mock.h" + +using namespace OHOS::FileManagement::ModuleFileIO; + +extern "C" { + +int fseek(FILE *stream, long len, int offset) +{ + return ICMock::ins->fseek(stream, len, offset); +} + +long ftell(FILE *stream) +{ + return ICMock::ins->ftell(stream); +} +} \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/class_stream/mock/c_mock.h b/interfaces/test/unittest/js/mod_fs/class_stream/mock/c_mock.h new file mode 100644 index 0000000000000000000000000000000000000000..8f2bbe88eb071174fa229693ab76b25b75ec45fa --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/class_stream/mock/c_mock.h @@ -0,0 +1,42 @@ +/* +* Copyright (C) 2025 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. +*/ + +#ifndef INTERFACES_TEST_UNITTEST_JS_MOD_FS_CLASS_STREAM_MOCK_C_MOCK_H +#define INTERFACES_TEST_UNITTEST_JS_MOD_FS_CLASS_STREAM_MOCK_C_MOCK_H + +#include +#include +#include + +namespace OHOS::FileManagement::ModuleFileIO { + +class ICMock { +public: + static inline std::shared_ptr ins = nullptr; +public: + virtual ~ICMock() = default; + virtual int fseek(FILE *, long, int) = 0; + virtual long ftell(FILE *) = 0; +}; + +class CMock : public ICMock { +public: + MOCK_METHOD(int, fseek, (FILE *, long, int), (override)); + MOCK_METHOD(long, ftell, (FILE *), (override)); +}; + + +} // OHOS::FileManagement::ModuleFileIO +#endif // INTERFACES_TEST_UNITTEST_JS_MOD_FS_CLASS_STREAM_MOCK_C_MOCK_H \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_hash/hash_core_test.cpp b/interfaces/test/unittest/js/mod_hash/hash_core_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..069a3230e9d756b9f4a145bbd6e918432ddfa557 --- /dev/null +++ b/interfaces/test/unittest/js/mod_hash/hash_core_test.cpp @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2025 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. + */ + +#include +#include +#include +#include "hash_core.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +using namespace std; + +static const string g_filePath = "/data/test/HashCoreTest.txt"; +class HashCoreTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + int32_t fd = open(g_filePath.c_str(), O_CREAT | O_RDWR, 0644); + close(fd); + }; + static void TearDownTestCase() + { + rmdir(g_filePath.c_str()); + }; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: DoHashTest_0001 + * @tc.desc: Test function of DoHash() interface for invalid alg. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(HashCoreTest, DoHashTest_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "HashCoreTest-begin DoHashTest_0001"; + string alg = "sha128"; + auto ret = HashCore::DoHash(g_filePath, alg); + EXPECT_FALSE(ret.IsSuccess()); + + auto err = ret.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900020); + + GTEST_LOG_(INFO) << "HashCoreTest-end DoHashTest_0001"; +} + +/** + * @tc.name: DoHashTest_0002 + * @tc.desc: Test function of DoHash() interface for md5 success. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(HashCoreTest, DoHashTest_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "HashCoreTest-begin DoHashTest_0002"; + auto ret = HashCore::DoHash(g_filePath, "md5"); + ASSERT_TRUE(ret.IsSuccess()); + + GTEST_LOG_(INFO) << "HashCoreTest-end DoHashTest_0002"; +} + +/** + * @tc.name: DoHashTest_0003 + * @tc.desc: Test function of DoHash() interface for sha1 success. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(HashCoreTest, DoHashTest_0003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "HashCoreTest-begin DoHashTest_0003"; + auto ret = HashCore::DoHash(g_filePath, "sha1"); + ASSERT_TRUE(ret.IsSuccess()); + + GTEST_LOG_(INFO) << "HashCoreTest-end DoHashTest_0003"; +} + +/** + * @tc.name: DoHashTest_0004 + * @tc.desc: Test function of DoHash() interface for sha256 success. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(HashCoreTest, DoHashTest_0004, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "HashCoreTest-begin DoHashTest_0004"; + auto ret = HashCore::DoHash(g_filePath, "sha256"); + ASSERT_TRUE(ret.IsSuccess()); + + GTEST_LOG_(INFO) << "HashCoreTest-end DoHashTest_0004"; +} + +/** + * @tc.name: DoHashTest_0005 + * @tc.desc: Test function of DoHash() interface for no such file or directory. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(HashCoreTest, DoHashTest_0005, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "HashCoreTest-begin DoHashTest_0005"; + auto ret = HashCore::DoHash("/data/local/tmp/azuxyicayhyskjeh", "sha256"); + EXPECT_FALSE(ret.IsSuccess()); + + auto err = ret.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900002); + + GTEST_LOG_(INFO) << "HashCoreTest-end DoHashTest_0005"; +} + +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_securitylabel/securitylabel_core_test.cpp b/interfaces/test/unittest/js/mod_securitylabel/securitylabel_core_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f320af0371ac30c73381a072a2a449b71ebe3a99 --- /dev/null +++ b/interfaces/test/unittest/js/mod_securitylabel/securitylabel_core_test.cpp @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2025 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. + */ + +#include +#include +#include +#include "securitylabel_core.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleSecurityLabel { +using namespace std; +using namespace OHOS::FileManagement::ModuleFileIO; + +static const string g_filePath = "/data/test/SecurityLabelCoreTest.txt"; +static const string g_validFilePath = "/data/test/validFilePath"; + +class SecurityLabelCoreTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + int32_t fd = open(g_filePath.c_str(), O_CREAT | O_RDWR, 0644); + close(fd); + }; + static void TearDownTestCase() + { + rmdir(g_filePath.c_str()); + }; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.name: DoSetSecurityLabel_0001 + * @tc.desc: Test function of DoSetSecurityLabel() interface for invalid level. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(SecurityLabelCoreTest, DoSetSecurityLabel_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "SecurityLabelCoreTest-begin DoSetSecurityLabel_0001"; + auto ret = DoSetSecurityLabel(g_filePath, "abc"); + EXPECT_FALSE(ret.IsSuccess()); + + auto err = ret.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900020); + + GTEST_LOG_(INFO) << "SecurityLabelCoreTest-end DoSetSecurityLabel_0001"; +} + +/** + * @tc.name: DoSetSecurityLabel_0002 + * @tc.desc: Test function of DoSetSecurityLabel() interface for invalid path. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(SecurityLabelCoreTest, DoSetSecurityLabel_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "SecurityLabelCoreTest-begin DoSetSecurityLabel_0002"; + auto ret = DoSetSecurityLabel(g_validFilePath, "s1"); + EXPECT_FALSE(ret.IsSuccess()); + + auto err = ret.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900002); + + GTEST_LOG_(INFO) << "SecurityLabelCoreTest-end DoSetSecurityLabel_0002"; +} + +/** + * @tc.name: DoSetSecurityLabel_0003 + * @tc.desc: Test function of DoSetSecurityLabel() interface for success. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(SecurityLabelCoreTest, DoSetSecurityLabel_0003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "SecurityLabelCoreTest-begin DoSetSecurityLabel_0003"; + auto ret = DoSetSecurityLabel(g_filePath, "s2"); + ASSERT_TRUE(ret.IsSuccess()); + + GTEST_LOG_(INFO) << "SecurityLabelCoreTest-end DoSetSecurityLabel_0003"; +} + +/** + * @tc.name: DoGetSecurityLabel_0001 + * @tc.desc: Test function of DoGetSecurityLabel() interface for invalid path. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(SecurityLabelCoreTest, DoGetSecurityLabel_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "SecurityLabelCoreTest-begin DoGetSecurityLabel_0001"; + auto ret = DoGetSecurityLabel(g_validFilePath); + EXPECT_TRUE(ret.IsSuccess()); + + const string level = ret.GetData().value(); + EXPECT_EQ(level, "s3"); + + GTEST_LOG_(INFO) << "SecurityLabelCoreTest-end DoGetSecurityLabel_0001"; +} + +/** + * @tc.name: DoGetSecurityLabel_0002 + * @tc.desc: Test function of DoGetSecurityLabel() interface for success. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000IGDNF + */ +HWTEST_F(SecurityLabelCoreTest, DoGetSecurityLabel_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "SecurityLabelCoreTest-begin DoGetSecurityLabel_0002"; + auto ret = DoGetSecurityLabel(g_filePath); + EXPECT_TRUE(ret.IsSuccess()); + + const string level = ret.GetData().value(); + EXPECT_EQ(level, "s2"); + + GTEST_LOG_(INFO) << "SecurityLabelCoreTest-end DoGetSecurityLabel_0002"; +} + +} // namespace ModuleSecurityLabel +} // namespace FileManagement +} // namespace OHOS \ No newline at end of file