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 #include "window_session_property.h"
18
19 using namespace testing;
20 using namespace testing::ext;
21
22 namespace OHOS {
23 namespace Rosen {
24
25 class WindowSessionPropertyRotationTest : public testing::Test {
26 public:
27 static void SetUpTestCase();
28 static void TearDownTestCase();
29 };
30
SetUpTestCase()31 void WindowSessionPropertyRotationTest::SetUpTestCase() {}
32
TearDownTestCase()33 void WindowSessionPropertyRotationTest::TearDownTestCase() {}
34
35 namespace {
36 /**
37 * @tc.name: SetRequestedOrientation
38 * @tc.desc: SetRequestedOrientation test
39 * @tc.type: FUNC
40 */
41 HWTEST_F(WindowSessionPropertyRotationTest, SetRequestedOrientation, TestSize.Level1)
42 {
43 Orientation orientation = Orientation::REVERSE_HORIZONTAL;
44 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
45 ASSERT_NE(nullptr, property);
46 property->SetRequestedOrientation(orientation);
47 Orientation ret = property->GetRequestedOrientation();
48 ASSERT_EQ(ret, orientation);
49
50 property->SetRequestedOrientation(Orientation::AUTO_ROTATION_UNSPECIFIED);
51 Orientation ret1 = property->GetRequestedOrientation();
52 ASSERT_EQ(ret1, Orientation::AUTO_ROTATION_UNSPECIFIED);
53
54 property->SetRequestedOrientation(Orientation::USER_ROTATION_PORTRAIT);
55 Orientation ret2 = property->GetRequestedOrientation();
56 ASSERT_EQ(ret2, Orientation::USER_ROTATION_PORTRAIT);
57
58 property->SetRequestedOrientation(Orientation::USER_ROTATION_LANDSCAPE);
59 Orientation ret3 = property->GetRequestedOrientation();
60 ASSERT_EQ(ret3, Orientation::USER_ROTATION_LANDSCAPE);
61
62 property->SetRequestedOrientation(Orientation::USER_ROTATION_PORTRAIT_INVERTED);
63 Orientation ret4 = property->GetRequestedOrientation();
64 ASSERT_EQ(ret4, Orientation::USER_ROTATION_PORTRAIT_INVERTED);
65
66 property->SetRequestedOrientation(Orientation::USER_ROTATION_LANDSCAPE_INVERTED);
67 Orientation ret5 = property->GetRequestedOrientation();
68 ASSERT_EQ(ret5, Orientation::USER_ROTATION_LANDSCAPE_INVERTED);
69
70 property->SetRequestedOrientation(Orientation::FOLLOW_DESKTOP);
71 Orientation ret6 = property->GetRequestedOrientation();
72 ASSERT_EQ(ret6, Orientation::FOLLOW_DESKTOP);
73 }
74
75 /**
76 * @tc.name: SetDefaultRequestedOrientation
77 * @tc.desc: SetDefaultRequestedOrientation test
78 * @tc.type: FUNC
79 */
80 HWTEST_F(WindowSessionPropertyRotationTest, SetDefaultRequestedOrientation, TestSize.Level1)
81 {
82 Orientation orientation = Orientation::REVERSE_HORIZONTAL;
83 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
84 ASSERT_NE(nullptr, property);
85 property->SetDefaultRequestedOrientation(orientation);
86 Orientation ret = property->GetDefaultRequestedOrientation();
87 ASSERT_EQ(ret, orientation);
88 }
89 } // namespace
90 } // namespace Rosen
91 } // namespace OHOS