1 /* 2 * Copyright (c) 2024 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_TEST_LAYOUT_SAFE_AREA_TEST_NG_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_TEST_LAYOUT_SAFE_AREA_TEST_NG_H 18 19 #include <cstdint> 20 #include <map> 21 #include <memory> 22 23 #include "gtest/gtest.h" 24 25 #include "test/unittest/core/pattern/test_ng.h" 26 27 #include "base/geometry/offset.h" 28 #include "core/components_ng/pattern/stage/page_pattern.h" 29 30 namespace OHOS::Ace::NG { 31 using namespace testing; 32 using namespace testing::ext; 33 struct AvoidConfig { 34 bool isAtomicService = false; 35 bool isFullScreen = false; 36 bool isNeedAvoidWindow = false; 37 bool ignoreSafeArea = false; 38 bool keyboardSafeAreaEnabled = false; ToStringAvoidConfig39 std::string ToString() 40 { 41 std::string result; 42 result.append("isAtomicService: "); 43 result.append(isAtomicService ? "True" : "False"); 44 result.append(", isFullScreen: "); 45 result.append(isFullScreen ? "True" : "False"); 46 result.append(", isNeedAvoidWindow: "); 47 result.append(isNeedAvoidWindow ? "True" : "False"); 48 result.append(", ignoreSafeArea: "); 49 result.append(ignoreSafeArea ? "True" : "False"); 50 result.append(", keyboardSafeAreaEnabled: "); 51 result.append(keyboardSafeAreaEnabled ? "True" : "False"); 52 return result; 53 } 54 }; 55 class ExpandSafeAreaTestNg : public TestNG { 56 protected: 57 static void SetUpTestSuite(); 58 static void TearDownTestSuite(); 59 void SetUp() override; 60 void TearDown() override; 61 virtual void GetInstance(); 62 63 void Create(const std::function<void()>& callback = nullptr, bool flushLayout = true); 64 void CreateWithItem(const std::function<void()>& callback = nullptr); 65 void AddItems(int32_t number); 66 static void CreateItem(int32_t number = 10, bool defineSize = false); 67 static void CreateItemWithHeight(float height); 68 static void InitSafeArea(SafeAreaExpandOpts opts); 69 static SafeAreaInsets GetSafeAreaInsets(); 70 static void InitSafeAreaManager(AvoidConfig config); 71 72 // page 73 RefPtr<FrameNode> frameNode_; 74 RefPtr<Pattern> pagePattern_; 75 }; 76 } // namespace OHOS::Ace::NG 77 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_TEST_LAYOUT_SAFE_AREA_TEST_NG_H 78