1 /* 2 * Copyright (c) 2022 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 <gtest/gtest.h> 17 #include <ipc_skeleton.h> 18 #include "edm_log.h" 19 #include "func_code_utils.h" 20 21 using namespace testing::ext; 22 using namespace OHOS::EDM; 23 24 namespace OHOS { 25 namespace EDM { 26 namespace TEST { 27 class UtilsTest : public testing::Test {}; 28 29 /** 30 * @tc.name: Test_FuncCodeUtils_ConvertSystemFlag 31 * @tc.desc: Test FuncCodeUtils::ConvertOperateType. 32 * @tc.type: FUNC 33 */ 34 HWTEST_F(UtilsTest, Test_FuncCodeUtils_ConvertSystemFlag, TestSize.Level1) 35 { 36 FuncOperateType type = FuncCodeUtils::ConvertOperateType(0); 37 ASSERT_EQ(type, FuncOperateType::GET); 38 type = FuncCodeUtils::ConvertOperateType(1); 39 ASSERT_EQ(type, FuncOperateType::SET); 40 type = FuncCodeUtils::ConvertOperateType(2); 41 ASSERT_EQ(type, FuncOperateType::REMOVE); 42 } 43 44 /** 45 * @tc.name: Test_ArrayPolicyUtils_RemovePolicy 46 * @tc.desc: Test ArrayPolicyUtils::RemovePolicy. 47 * @tc.type: FUNC 48 */ 49 HWTEST_F(UtilsTest, Test_ArrayPolicyUtils_RemovePolicy, TestSize.Level1) 50 { 51 std::vector<std::string> removeData; 52 std::vector<std::string> currentData; 53 54 removeData = { "19216811" }; 55 currentData = { "19216811", "19216812", "19216813" }; 56 ArrayPolicyUtils::RemovePolicy(removeData, currentData); 57 ASSERT_TRUE(currentData.size() == 2); 58 59 removeData = { "19216811" }; 60 currentData = {}; 61 ArrayPolicyUtils::RemovePolicy(removeData, currentData); 62 ASSERT_TRUE(currentData.empty()); 63 64 removeData = {}; 65 currentData = { "19216811", "19216812", "19216813" }; 66 ArrayPolicyUtils::RemovePolicy(removeData, currentData); 67 ASSERT_TRUE(currentData.size() == 3); 68 69 removeData = { "19216814" }; 70 currentData = { "19216811", "19216812", "19216813" }; 71 ArrayPolicyUtils::RemovePolicy(removeData, currentData); 72 ASSERT_TRUE(currentData.size() == 3); 73 } 74 75 /** 76 * @tc.name: Test_ArrayPolicyUtils_ArrayStringContains 77 * @tc.desc: Test ArrayPolicyUtils::ArrayStringContains. 78 * @tc.type: FUNC 79 */ 80 HWTEST_F(UtilsTest, Test_ArrayPolicyUtils_ArrayStringContains, TestSize.Level1) 81 { 82 std::vector<std::string> data; 83 std::string find = "19216812"; 84 data = { "19216811", "19216812", "19216813" }; 85 ASSERT_TRUE(ArrayPolicyUtils::ArrayStringContains(data, find)); 86 87 find = "19216814"; 88 data = { "19216811", "19216812", "19216813" }; 89 ASSERT_FALSE(ArrayPolicyUtils::ArrayStringContains(data, find)); 90 91 find = "19216814"; 92 data = {}; 93 ASSERT_FALSE(ArrayPolicyUtils::ArrayStringContains(data, find)); 94 } 95 96 /** 97 * @tc.name: Test_ArrayPolicyUtils_RemovePolicy_002 98 * @tc.desc: Test ArrayPolicyUtils::RemovePolicy. 99 * @tc.type: FUNC 100 */ 101 HWTEST_F(UtilsTest, Test_ArrayPolicyUtils_RemovePolicy_002, TestSize.Level1) 102 { 103 std::vector<std::map<std::string, std::string>> removeData = { 104 { 105 {"id", "1"}, 106 {"name", "leon"}, 107 }, 108 { 109 {"id", "2"}, 110 {"name", "james"}, 111 }}; 112 std::vector<std::map<std::string, std::string>> data = { 113 { 114 {"id", "3"}, 115 {"name", "fox"}, 116 }, 117 { 118 {"id", "1"}, 119 {"name", "leon"}, 120 }, 121 }; 122 // leon should be remove 123 ArrayPolicyUtils::RemovePolicy(removeData, data); 124 ASSERT_TRUE(data.size() == 1); 125 126 removeData = { 127 { 128 {"id", "1"}, 129 {"name", "leon"}, 130 }, 131 { 132 {"id", "2"}, 133 {"name", "james"}, 134 } 135 }; 136 data = { 137 { 138 {"id", "3"}, 139 {"name", "fox"}, 140 }, 141 { 142 {"id", "4"}, 143 {"name", "leon"}, 144 }, 145 }; 146 ArrayPolicyUtils::RemovePolicy(removeData, data); 147 ASSERT_TRUE(data.size() == 2); 148 } 149 } // namespace TEST 150 } // namespace EDM 151 } // namespace OHOS 152