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 "test/mock/core/common/mock_container.h" 17 #include "test/unittest/core/pattern/test_ng.h" 18 19 #define protected public 20 #define private public 21 22 #include "frameworks/bridge/common/media_query/media_query_info.h" 23 24 namespace OHOS::Ace::NG { 25 using namespace testing; 26 using namespace testing::ext; 27 using namespace std; 28 29 class MediaQueryTest : public TestNG {}; 30 31 /** 32 * @tc.name: GetOrientationTest1 33 * @tc.desc: Test GetOrientation 34 * @tc.type: FUNC 35 */ 36 HWTEST_F(MediaQueryTest, GetOrientationTest1, TestSize.Level1) 37 { 38 auto container = MockContainer::Current(); 39 ASSERT_TRUE(container); 40 container->SetCurrentDisplayOrientation(DisplayOrientation::PORTRAIT); 41 EXPECT_EQ(Framework::MediaQueryInfo::GetOrientation(container), "portrait"); 42 43 container->SetCurrentDisplayOrientation(DisplayOrientation::PORTRAIT_INVERTED); 44 EXPECT_EQ(Framework::MediaQueryInfo::GetOrientation(container), "portrait"); 45 46 container->SetCurrentDisplayOrientation(DisplayOrientation::LANDSCAPE); 47 EXPECT_EQ(Framework::MediaQueryInfo::GetOrientation(container), "landscape"); 48 49 container->SetCurrentDisplayOrientation(DisplayOrientation::LANDSCAPE_INVERTED); 50 EXPECT_EQ(Framework::MediaQueryInfo::GetOrientation(container), "landscape"); 51 } 52 53 /** 54 * @tc.name: GetOrientationTest2 55 * @tc.desc: Test GetOrientation, container == nullptr. 56 * @tc.type: FUNC 57 */ 58 HWTEST_F(MediaQueryTest, GetOrientationTest2, TestSize.Level1) 59 { 60 SystemProperties::SetDeviceOrientation(0); 61 EXPECT_EQ(Framework::MediaQueryInfo::GetOrientation(nullptr), "portrait"); 62 63 SystemProperties::SetDeviceOrientation(1); 64 EXPECT_EQ(Framework::MediaQueryInfo::GetOrientation(nullptr), "landscape"); 65 66 // outliers don't change 67 SystemProperties::SetDeviceOrientation(-1); 68 EXPECT_EQ(Framework::MediaQueryInfo::GetOrientation(nullptr), "landscape"); 69 } 70 } // namespace OHOS::Ace::NG 71