From 85f52dff2f7ca9fac635be0b9f4591cddb91ccc1 Mon Sep 17 00:00:00 2001 From: zkx Date: Fri, 21 Apr 2023 16:59:07 +0800 Subject: [PATCH] Add FileUri Tdd Test Moudle. Signed-off-by: zkx --- test/unittest/BUILD.gn | 1 + test/unittest/file_uri_native/BUILD.gn | 26 +++ .../file_uri_native/file_uri_test.cpp | 219 ++++++++++++++++++ 3 files changed, 246 insertions(+) create mode 100644 test/unittest/file_uri_native/BUILD.gn create mode 100644 test/unittest/file_uri_native/file_uri_test.cpp diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index bce4a610a..53d8db6d1 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -15,6 +15,7 @@ group("unittest") { testonly = true deps = [ "file_share_native:file_share_test", + "file_uri_native:file_uri_test", "remote_file_share:remote_file_share_test", ] } diff --git a/test/unittest/file_uri_native/BUILD.gn b/test/unittest/file_uri_native/BUILD.gn new file mode 100644 index 000000000..c12c979c3 --- /dev/null +++ b/test/unittest/file_uri_native/BUILD.gn @@ -0,0 +1,26 @@ +# 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("//build/test.gni") + +ohos_unittest("file_uri_test") { + module_out_path = "filemanagement/app_file_service" + sources = [ "file_uri_test.cpp" ] + deps = [ "//third_party/googletest:gtest_main" ] + external_deps = [ + "ability_base:zuri", + "app_file_service:fileuri_native", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + ] +} diff --git a/test/unittest/file_uri_native/file_uri_test.cpp b/test/unittest/file_uri_native/file_uri_test.cpp new file mode 100644 index 000000000..e18920d20 --- /dev/null +++ b/test/unittest/file_uri_native/file_uri_test.cpp @@ -0,0 +1,219 @@ +/* + * 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. + */ + +#include +#include +#include +#include +#include +#include + +#include "file_uri.h" + +namespace { + using namespace std; + using namespace OHOS::AppFileService::ModuleFileUri; + + class FileUriTest : public testing::Test { + public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; + }; + + /** + * @tc.name: File_Uri_GetNetworkId_0000 + * @tc.desc: Test function of GetNetworkId() interface for success. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ + HWTEST_F(FileUriTest, File_Uri_GetNetworkId_0000, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "FileUriTest-begin File_Uri_GetNetworkId_0000"; + string fileUri_ = "file://media/image/7#networkid=3456"; + string resultId = "3456"; + string networkId = FileUri(fileUri_).GetNetworkId(); + ASSERT_TRUE(!networkId.empty()) << "networkId is " << networkId; + EXPECT_EQ(networkId, resultId); + GTEST_LOG_(INFO) << "FileUriTest-end File_Uri_GetNetworkId_0000"; + } + + /** + * @tc.name: File_Uri_GetNetworkId_0001 + * @tc.desc: Test function of GetNetworkId() interface for success. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ + HWTEST_F(FileUriTest, File_Uri_GetNetworkId_0001, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "FileUriTest-begin File_Uri_GetNetworkId_0001"; + string fileUri_ = "file://media/image/7#networkid=654321&test=789&test1=456&test2=123"; + string resultId = "654321"; + string networkId = FileUri(fileUri_).GetNetworkId(); + ASSERT_TRUE(!networkId.empty()) << "networkId is " << networkId; + EXPECT_EQ(networkId, resultId); + GTEST_LOG_(INFO) << "FileUriTest-end File_Uri_GetNetworkId_0001"; + } + + /** + * @tc.name: File_Uri_GetNetworkId_0002 + * @tc.desc: Test function of GetNetworkId() interface for fail. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ + HWTEST_F(FileUriTest, File_Uri_GetNetworkId_0002, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "FileUriTest-begin File_Uri_GetNetworkId_0002"; + string fileUri_ = "file://media/image/12"; + string resultId = ""; + string networkId = FileUri(fileUri_).GetNetworkId(); + ASSERT_TRUE(networkId.empty()) << "networkId is empty!"; + EXPECT_EQ(networkId, resultId); + GTEST_LOG_(INFO) << "FileUriTest-end File_Uri_GetNetworkId_0002"; + } + + /** + * @tc.name: File_Uri_GetNetworkId_0003 + * @tc.desc: Test function of GetNetworkId() interface for success. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ + HWTEST_F(FileUriTest, File_Uri_GetNetworkId_0003, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "FileUriTest-begin File_Uri_GetNetworkId_0003"; + string fileUri_ = "data://media/image/12#networkid=3456"; + string resultId = "3456"; + string networkId = FileUri(fileUri_).GetNetworkId(); + ASSERT_TRUE(!networkId.empty()) << "networkId is " << networkId; + EXPECT_EQ(networkId, resultId); + GTEST_LOG_(INFO) << "FileUriTest-end File_Uri_GetNetworkId_0003"; + } + + /** + * @tc.name: File_Uri_GetNetworkId_0004 + * @tc.desc: Test function of GetNetworkId() interface for success. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ + HWTEST_F(FileUriTest, File_Uri_GetNetworkId_0004, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "FileUriTest-begin File_Uri_GetNetworkId_0004"; + string fileUri_ = "data://media/image/12#networkid=654321&test=789&test1=456&test2=123"; + string resultId = "654321"; + string networkId = FileUri(fileUri_).GetNetworkId(); + ASSERT_TRUE(!networkId.empty()) << "networkId is " << networkId; + EXPECT_EQ(networkId, resultId); + GTEST_LOG_(INFO) << "FileUriTest-end File_Uri_GetNetworkId_0004"; + } + + /** + * @tc.name: File_Uri_GetNetworkId_0005 + * @tc.desc: Test function of GetNetworkId() interface for fail. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ + HWTEST_F(FileUriTest, File_Uri_GetNetworkId_0005, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "FileUriTest-begin File_Uri_GetNetworkId_0005"; + string fileUri_ = "data://media/image/12"; + string resultId = ""; + string networkId = FileUri(fileUri_).GetNetworkId(); + ASSERT_TRUE(networkId.empty()) << "networkId is empty!"; + EXPECT_EQ(networkId, resultId); + GTEST_LOG_(INFO) << "FileUriTest-end File_Uri_GetNetworkId_0005"; + } + + /** + * @tc.name: File_Uri_IsMediaUri_0000 + * @tc.desc: Test function of IsMediaUri() interface for success. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ + HWTEST_F(FileUriTest, File_Uri_IsMediaUri_0000, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "FileUriTest-begin File_Uri_IsMediaUri_0000"; + string dataShareUri = "datashare:///media/image/12"; + ASSERT_TRUE(FileUri(dataShareUri).IsMediaUri()) << " uri is media type"; + GTEST_LOG_(INFO) << "FileUriTest-end File_Uri_IsMediaUri_0000"; + } + + /** + * @tc.name: File_Uri_IsMediaUri_0001 + * @tc.desc: Test function of IsMediaUri() interface for success. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ + HWTEST_F(FileUriTest, File_Uri_IsMediaUri_0001, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "FileUriTest-begin File_Uri_IsMediaUri_0001"; + string fileUri_ = "file://media/image/12"; + ASSERT_TRUE(FileUri(fileUri_).IsMediaUri()) << " uri is media type"; + GTEST_LOG_(INFO) << "FileUriTest-end File_Uri_IsMediaUri_0001"; + } + + /** + * @tc.name: File_Uri_IsMediaUri_0002 + * @tc.desc: Test function of IsMediaUri() interface for fail. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ + HWTEST_F(FileUriTest, File_Uri_IsMediaUri_0002, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "FileUriTest-begin File_Uri_IsMediaUri_0002"; + string fileUri = "data://media/image/12"; + ASSERT_TRUE(!FileUri(fileUri).IsMediaUri()) << " uri not is media type"; + GTEST_LOG_(INFO) << "FileUriTest-end File_Uri_IsMediaUri_0002"; + } + + /** + * @tc.name: File_Uri_IsMediaUri_0003 + * @tc.desc: Test function of IsMediaUri() interface for fail. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ + HWTEST_F(FileUriTest, File_Uri_IsMediaUri_0003, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "FileUriTest-begin File_Uri_IsMediaUri_0003"; + string fileUri = "datashare://medi/image/12"; + ASSERT_TRUE(!FileUri(fileUri).IsMediaUri()) << " uri not is media type"; + GTEST_LOG_(INFO) << "FileUriTest-end File_Uri_IsMediaUri_0003"; + } + + /** + * @tc.name: File_Uri_IsMediaUri_0004 + * @tc.desc: Test function of IsMediaUri() interface for fail. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ + HWTEST_F(FileUriTest, File_Uri_IsMediaUri_0004, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "FileUriTest-begin File_Uri_IsMediaUri_0004"; + string fileUri = "datashare:///media"; + ASSERT_TRUE(!FileUri(fileUri).IsMediaUri()) << " uri not is media type"; + GTEST_LOG_(INFO) << "FileUriTest-end File_Uri_IsMediaUri_0004"; + } +} \ No newline at end of file -- Gitee