1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "preprocess_utils.h" 17 #include "gtest/gtest.h" 18 #include "text.h" 19 20 namespace OHOS::UDMF { 21 using namespace testing::ext; 22 class UdmfPreProcessUtilsTest : public testing::Test { 23 public: SetUpTestCase(void)24 static void SetUpTestCase(void) {} TearDownTestCase(void)25 static void TearDownTestCase(void) {} SetUp()26 void SetUp() {} TearDown()27 void TearDown() {} 28 }; 29 30 /** 31 * @tc.name: RuntimeDataImputation001 32 * @tc.desc: Abnormal test of RuntimeDataImputation, option is invalid 33 * @tc.type: FUNC 34 * @tc.require: 35 */ 36 HWTEST_F(UdmfPreProcessUtilsTest, RuntimeDataImputation001, TestSize.Level1) 37 { 38 UnifiedData data; 39 CustomOption option; 40 PreProcessUtils preProcessUtils; 41 int32_t ret = preProcessUtils.RuntimeDataImputation(data, option); 42 EXPECT_EQ(ret, E_ERROR); 43 } 44 45 /** 46 * @tc.name: GetHapUidByToken001 47 * @tc.desc: Abnormal test of GetHapUidByToken, tokenId is invalid 48 * @tc.type: FUNC 49 * @tc.require: 50 */ 51 HWTEST_F(UdmfPreProcessUtilsTest, GetHapUidByToken001, TestSize.Level1) 52 { 53 uint32_t tokenId = 0; 54 int userId = 0; 55 PreProcessUtils preProcessUtils; 56 int32_t ret = preProcessUtils.GetHapUidByToken(tokenId, userId); 57 EXPECT_EQ(ret, E_ERROR); 58 } 59 60 /** 61 * @tc.name: SetRemoteData001 62 * @tc.desc: Abnormal test of SetRemoteData, data is null 63 * @tc.type: FUNC 64 * @tc.require: 65 */ 66 HWTEST_F(UdmfPreProcessUtilsTest, SetRemoteData001, TestSize.Level1) 67 { 68 UnifiedData data; 69 PreProcessUtils preProcessUtils; 70 EXPECT_NO_FATAL_FAILURE(preProcessUtils.SetRemoteData(data)); 71 } 72 73 /** 74 * @tc.name: SetRemoteData002 75 * @tc.desc: Normal test of SetRemoteData 76 * @tc.type: FUNC 77 * @tc.require: 78 */ 79 HWTEST_F(UdmfPreProcessUtilsTest, SetRemoteData002, TestSize.Level1) 80 { 81 UnifiedData data; 82 std::vector<std::shared_ptr<UnifiedRecord>> inputRecords; 83 for (int32_t i = 0; i < 512; ++i) { 84 inputRecords.emplace_back(std::make_shared<Text>()); 85 } 86 data.SetRecords(inputRecords); 87 data.runtime_ = std::make_shared<Runtime>(); 88 PreProcessUtils preProcessUtils; 89 EXPECT_NO_FATAL_FAILURE(preProcessUtils.SetRemoteData(data)); 90 } 91 92 /** 93 * @tc.name: IsFileType001 94 * @tc.desc: Abnormal test of IsFileType, record is nullptr 95 * @tc.type: FUNC 96 * @tc.require: 97 */ 98 HWTEST_F(UdmfPreProcessUtilsTest, IsFileType001, TestSize.Level1) 99 { 100 std::shared_ptr<UnifiedRecord> record = nullptr; 101 PreProcessUtils preProcessUtils; 102 bool ret = preProcessUtils.IsFileType(record); 103 EXPECT_EQ(ret, false); 104 } 105 106 /** 107 * @tc.name: GetDfsUrisFromLocal001 108 * @tc.desc: Abnormal test of GetDfsUrisFromLocal, uris is null 109 * @tc.type: FUNC 110 * @tc.require: 111 */ 112 HWTEST_F(UdmfPreProcessUtilsTest, GetDfsUrisFromLocal001, TestSize.Level1) 113 { 114 const std::vector<std::string> uris; 115 int32_t userId = 0; 116 UnifiedData data; 117 PreProcessUtils preProcessUtils; 118 int32_t ret = preProcessUtils.GetDfsUrisFromLocal(uris, userId, data); 119 EXPECT_EQ(ret, E_FS_ERROR); 120 } 121 122 /** 123 * @tc.name: CheckUriAuthorization001 124 * @tc.desc: Abnormal test of CheckUriAuthorization, uris is invalid 125 * @tc.type: FUNC 126 * @tc.require: 127 */ 128 HWTEST_F(UdmfPreProcessUtilsTest, CheckUriAuthorization001, TestSize.Level1) 129 { 130 const std::vector<std::string> uris = {"test"}; 131 uint32_t tokenId = 0; 132 PreProcessUtils preProcessUtils; 133 bool ret = preProcessUtils.CheckUriAuthorization(uris, tokenId); 134 EXPECT_EQ(ret, false); 135 } 136 137 /** 138 * @tc.name: GetInstIndex001 139 * @tc.desc: Normal test of GetInstIndex 140 * @tc.type: FUNC 141 * @tc.require: 142 */ 143 HWTEST_F(UdmfPreProcessUtilsTest, GetInstIndex001, TestSize.Level1) 144 { 145 uint32_t tokenId = 0; 146 int32_t instIndex = 0; 147 PreProcessUtils preProcessUtils; 148 bool ret = preProcessUtils.GetInstIndex(tokenId, instIndex); 149 EXPECT_EQ(instIndex, 0); 150 EXPECT_EQ(ret, true); 151 } 152 153 /** 154 * @tc.name: ProcessFileType001 155 * @tc.desc: Abnormal test of ProcessFileType, records is nullptr 156 * @tc.type: FUNC 157 * @tc.require: 158 */ 159 HWTEST_F(UdmfPreProcessUtilsTest, ProcessFileType001, TestSize.Level1) 160 { 161 std::vector<std::shared_ptr<UnifiedRecord>> records = { nullptr }; 162 std::function<bool(std::shared_ptr<Object>)> callback; 163 PreProcessUtils preProcessUtils; 164 EXPECT_NO_FATAL_FAILURE(preProcessUtils.ProcessFileType(records, callback)); 165 } 166 167 /** 168 * @tc.name: GetHtmlFileUris001 169 * @tc.desc: Abnormal test of GetHtmlFileUris, uris is invalid 170 * @tc.type: FUNC 171 * @tc.require: 172 */ 173 HWTEST_F(UdmfPreProcessUtilsTest, GetHtmlFileUris001, TestSize.Level1) 174 { 175 uint32_t tokenId = 0; 176 UnifiedData data; 177 bool isLocal = false; 178 std::vector<std::string> uris = {"test"}; 179 PreProcessUtils preProcessUtils; 180 EXPECT_NO_FATAL_FAILURE(preProcessUtils.GetHtmlFileUris(tokenId, data, isLocal, uris)); 181 } 182 }; // namespace UDMF