1 /* 2 * Copyright (c) 2023 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 "gmock/gmock.h" 18 #define private public 19 #define protected public 20 #include "ans_inner_errors.h" 21 #include "notification_clone_util.h" 22 #undef private 23 #undef protected 24 25 using namespace testing::ext; 26 using namespace testing; 27 using namespace OHOS; 28 using namespace Notification; 29 30 // Test suite class 31 class NotificationCloneUtilTest : public ::testing::Test { 32 protected: SetUp()33 void SetUp() override 34 { 35 // Initialize objects and dependencies 36 notificationCloneUtil = new NotificationCloneUtil(); 37 } 38 TearDown()39 void TearDown() override 40 { 41 delete notificationCloneUtil; 42 notificationCloneUtil = nullptr; 43 } 44 45 NotificationCloneUtil* notificationCloneUtil; 46 }; 47 48 /** 49 * @tc.name: GetBundleUid_Test_001 50 * @tc.desc: Test that error is reported when appIndex is -1 51 * @tc.type: FUNC 52 * @tc.require: issue 53 */ 54 HWTEST_F(NotificationCloneUtilTest, GetBundleUid_Test_001, Function | SmallTest | Level1) 55 { 56 // Arrange 57 std::string bundleName = "com.example.app"; 58 int32_t userId = 100; 59 int32_t appIndex = -1; 60 61 int32_t actualUid = notificationCloneUtil->GetBundleUid(bundleName, userId, appIndex); 62 63 EXPECT_EQ(actualUid, 1000); 64 } 65 66 /** 67 * @tc.name: GetBundleUid_Test_002 68 * @tc.desc: Test that error is reported when appIndex is 0 69 * @tc.type: FUNC 70 * @tc.require: issue 71 */ 72 HWTEST_F(NotificationCloneUtilTest, GetBundleUid_Test_002, Function | SmallTest | Level1) 73 { 74 // Arrange 75 std::string bundleName = "com.example.app"; 76 int32_t userId = 100; 77 int32_t appIndex = 0; 78 79 int32_t actualUid = notificationCloneUtil->GetBundleUid(bundleName, userId, appIndex); 80 81 EXPECT_EQ(actualUid, -1); 82 }