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 <string> 18 #include <vector> 19 #include "cmd_utils.h" 20 #include "edm_permission.h" 21 #include "func_code.h" 22 #include "policy_info.h" 23 24 using namespace testing::ext; 25 using namespace testing; 26 27 namespace OHOS { 28 namespace EDM { 29 namespace TEST { 30 class EdmPermissionTest : public testing::Test { 31 protected: SetUp()32 void SetUp() override {} 33 TearDown()34 void TearDown() override {} 35 }; 36 37 /** 38 * @tc.name: TestEdmPermissionEqual 39 * @tc.desc: Test EdmPermission Equal func. 40 * @tc.type: FUNC 41 */ 42 HWTEST_F(EdmPermissionTest, TestEdmPermissionEqual, TestSize.Level1) 43 { 44 EdmPermission permission1; 45 EdmPermission permission2; 46 permission1.setAdminType(AdminType::NORMAL); 47 permission1.setPermissionName("ohos.permission.EDM_TEST_PERMISSION"); 48 permission2.setAdminType(AdminType::NORMAL); 49 permission2.setPermissionName("ohos.permission.EDM_TEST_PERMISSION"); 50 EXPECT_TRUE(permission1 == permission2); 51 permission2.setPermissionName("ohos.permission.EDM_TEST_PERMISSION_FAIL"); 52 EXPECT_FALSE(permission1 == permission2); 53 } 54 55 /** 56 * @tc.name: TestMarshalling 57 * @tc.desc: Test Marshalling func. 58 * @tc.type: FUNC 59 */ 60 HWTEST_F(EdmPermissionTest, TestMarshalling, TestSize.Level1) 61 { 62 EdmPermission permission1("ohos.permission.EDM_TEST_PERMISSION", AdminType::NORMAL); 63 Parcel parcel; 64 permission1.Marshalling(parcel); 65 EdmPermission *permission2 = permission1.Unmarshalling(parcel); 66 EXPECT_TRUE(permission2 != nullptr); 67 EXPECT_TRUE(permission1 == *permission2); 68 if (permission2) { 69 delete permission2; 70 } 71 } 72 } // namespace TEST 73 } // namespace EDM 74 } // namespace OHOS