diff --git a/bundle.json b/bundle.json index 571944b86baa272f99cdf0dacf95f3a402faaac4..dab8e4353e7c78b8dd8e570bf17f599df6c98afe 100644 --- a/bundle.json +++ b/bundle.json @@ -41,7 +41,8 @@ } ], "test": [ - "//foundation/filemanagement/app_file_service/test/fuzztest:fuzztest" + "//foundation/filemanagement/app_file_service/test/fuzztest:fuzztest", + "//foundation/filemanagement/app_file_service/test/unittest:unittest" ] } } diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d81880b40dc7bac6fbbf07567b4158fb81ce316b --- /dev/null +++ b/test/unittest/BUILD.gn @@ -0,0 +1,17 @@ +# 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. + +group("unittest") { + testonly = true + deps = [ "remote_file_share:remote_file_share_test" ] +} diff --git a/test/unittest/remote_file_share/BUILD.gn b/test/unittest/remote_file_share/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a9c46ef1dbf2125968bc61c1a2661dc896cefd30 --- /dev/null +++ b/test/unittest/remote_file_share/BUILD.gn @@ -0,0 +1,34 @@ +# 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("//build/test.gni") + +ohos_unittest("remote_file_share_test") { + module_out_path = "filemanagement/app_file_service" + + resource_config_file = "../resource/ohos_test.xml" + + sources = [ "remote_file_share_test.cpp" ] + + include_dirs = [ + "include", + "../../../interfaces/innerkits/remote_file_share/native", + "//utils/system/safwk/native/include", + "//commonlibrary/c_utils/base/include", + ] + + deps = [ + "../../../interfaces/innerkits/remote_file_share/native:remote_file_share_native", + "//third_party/googletest:gtest_main", + ] +} diff --git a/test/unittest/remote_file_share/remote_file_share_test.cpp b/test/unittest/remote_file_share/remote_file_share_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ef9a87cfd96fd26c753b75c596bfb93d35b9b731 --- /dev/null +++ b/test/unittest/remote_file_share/remote_file_share_test.cpp @@ -0,0 +1,140 @@ +/* + * 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. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "remote_file_share.h" + +namespace { + using namespace std; + using namespace OHOS::AppFileService::ModuleRemoteFileShare; + + const int E_INVALID_ARGUMENT = 22; + const int E_OK = 0; + + class RemoteFileShareTest : public testing::Test { + public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; + }; + + /** + * @tc.name: remote_file_share_test_0000 + * @tc.desc: Test function of RemoteFileShare() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ + HWTEST_F(RemoteFileShareTest, Remote_file_share_RemoteFileShare_0000, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "RemoteFileShareTest-begin Remote_file_share_RemoteFileShare_0000"; + std::shared_ptr service = OHOS::DelayedSingleton::GetInstance(); + ASSERT_TRUE(service != nullptr) << "RemoteFileShare Construct Failed!"; + GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_RemoteFileShare_0000"; + } + + /** + * @tc.name: remote_file_share_test_0001 + * @tc.desc: Test function of CreateSharePath() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ + HWTEST_F(RemoteFileShareTest, Remote_file_share_CreateSharePath_0001, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "RemoteFileShareTest-begin Remote_file_share_CreateSharePath_0001"; + const int fd = -1; + const int userId = 100; + const string deviceId = "0"; + string sharePath = ""; + int ret = RemoteFileShare::CreateSharePath(fd, sharePath, userId, deviceId); + EXPECT_EQ(ret, E_INVALID_ARGUMENT); + GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_CreateSharePath_0001"; + } + + /** + * @tc.name: remote_file_share_test_0002 + * @tc.desc: Test function of CreateSharePath() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ + HWTEST_F(RemoteFileShareTest, Remote_file_share_CreateSharePath_0002, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "RemoteFileShareTest-begin Remote_file_share_CreateSharePath_0002"; + const int fd = 10; + const int userId = 90; + const string deviceId = "0"; + string sharePath = ""; + int ret = RemoteFileShare::CreateSharePath(fd, sharePath, userId, deviceId); + EXPECT_EQ(ret, E_INVALID_ARGUMENT); + GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_CreateSharePath_0002"; + } + + /** + * @tc.name: remote_file_share_test_0003 + * @tc.desc: Test function of CreateSharePath() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ + HWTEST_F(RemoteFileShareTest, Remote_file_share_CreateSharePath_0003, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "RemoteFileShareTest-begin Remote_file_share_CreateSharePath_0003"; + const int fd = 10; + const int userId = 100; + const string deviceId = "00"; + string sharePath = ""; + int ret = RemoteFileShare::CreateSharePath(fd, sharePath, userId, deviceId); + EXPECT_EQ(ret, E_INVALID_ARGUMENT); + GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_CreateSharePath_0003"; + } + + /** + * @tc.name: remote_file_share_test_0004 + * @tc.desc: Test function of CreateSharePath() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: SR000H63TL + */ + HWTEST_F(RemoteFileShareTest, Remote_file_share_CreateSharePath_0004, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "RemoteFileShareTest-begin Remote_file_share_CreateSharePath_0004"; + const string fileStr = "/mnt/hmdfs/100/account/merge_view/services/remote_file_share_test.txt"; + int fd = open(fileStr.c_str(), O_RDWR); + ASSERT_TRUE(fd != -1) << "RemoteFileShareTest Create File Failed!"; + const int userId = 100; + const string deviceId = "0"; + string sharePath = ""; + int ret = RemoteFileShare::CreateSharePath(fd, sharePath, userId, deviceId); + close(fd); + EXPECT_EQ(ret, E_OK); + GTEST_LOG_(INFO) << "RemoteFileShareTest Create Share Path " << sharePath; + GTEST_LOG_(INFO) << "RemoteFileShareTest-end Remote_file_share_CreateSharePath_0004"; + } +} diff --git a/test/unittest/resource/ohos_test.xml b/test/unittest/resource/ohos_test.xml new file mode 100644 index 0000000000000000000000000000000000000000..068c2bb10c4367472d35fd682b2eaeb535c6378d --- /dev/null +++ b/test/unittest/resource/ohos_test.xml @@ -0,0 +1,22 @@ + + + + + + + + diff --git a/test/unittest/resource/remote_file_share_test.txt b/test/unittest/resource/remote_file_share_test.txt new file mode 100644 index 0000000000000000000000000000000000000000..c658b9b65d5f8b5f3a7e5c3c3e7caf5caa8f7672 --- /dev/null +++ b/test/unittest/resource/remote_file_share_test.txt @@ -0,0 +1,13 @@ +# 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. +remote_file_share_test