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 "gtest/gtest.h" 17 18 #define private public 19 #define protected public 20 #include "test/mock/core/common/mock_container.h" 21 #include "test/mock/core/pipeline/mock_pipeline_context.h" 22 #include "test/unittest/interfaces/ace_kit/mock/mock_ace_kit_pattern.h" 23 #include "ui/base/agingadapation/aging_adapation_dialog_util.h" 24 #include "ui/view_factory/abstract_view_factory.h" 25 26 using namespace testing; 27 using namespace testing::ext; 28 using namespace OHOS::Ace::Kit; 29 namespace OHOS::Ace { 30 class AgingAdapationDialogUtilTest : public testing::Test { 31 public: SetUpTestSuite()32 static void SetUpTestSuite() 33 { 34 NG::MockPipelineContext::SetUp(); 35 MockContainer::SetUp(); 36 MockContainer::Current()->pipelineContext_ = PipelineBase::GetCurrentContext(); 37 } TearDownTestSuite()38 static void TearDownTestSuite() 39 { 40 MockContainer::Current()->pipelineContext_ = nullptr; 41 NG::MockPipelineContext::TearDown(); 42 } SetUp()43 void SetUp() {}; TearDown()44 void TearDown() {}; 45 }; 46 47 /** 48 * @tc.name: AgingAdapationDialogUtilTest001 49 * @tc.desc: Test ShowLongPressDialog when IconNodeType is SYMBOL 50 * @tc.type: Func 51 */ 52 HWTEST_F(AgingAdapationDialogUtilTest, AgingAdapationDialogUtilTest001, TestSize.Level1) 53 { 54 const std::string tag = "TEST1"; 55 const int32_t iconNodeId = 1001; 56 auto mockPattern = AceType::MakeRefPtr<MockAceKitPattern>(); 57 auto frameNode = AbstractViewFactory::CreateFrameNode(tag, iconNodeId, mockPattern); 58 ASSERT_NE(frameNode, nullptr); 59 60 std::string message = "Test Message"; 61 IconNodeType type = IconNodeType::SYMBOL; 62 RefPtr<FrameNode> result = AgingAdapationDialogUtil::ShowLongPressDialog(message, iconNodeId, type); 63 ASSERT_EQ(result, nullptr); 64 } 65 66 /** 67 * @tc.name: AgingAdapationDialogUtilTest002 68 * @tc.desc: Test ShowLongPressDialog when IconNodeType is IMAGE 69 * @tc.type: Func 70 */ 71 HWTEST_F(AgingAdapationDialogUtilTest, AgingAdapationDialogUtilTest002, TestSize.Level1) 72 { 73 const std::string tag = "TEST2"; 74 const int32_t iconNodeId = 1002; 75 auto mockPattern = AceType::MakeRefPtr<MockAceKitPattern>(); 76 auto frameNode = AbstractViewFactory::CreateFrameNode(tag, iconNodeId, mockPattern); 77 ASSERT_NE(frameNode, nullptr); 78 79 std::string message = "Test Message"; 80 IconNodeType type = IconNodeType::IMAGE; 81 RefPtr<FrameNode> result = AgingAdapationDialogUtil::ShowLongPressDialog(message, iconNodeId, type); 82 ASSERT_EQ(result, nullptr); 83 } 84 } // namespace OHOS::Ace 85