1 /*
2 * Copyright (c) 2022 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 #include "base/memory/ace_type.h"
19 #include "interfaces/inner_api/ace/viewport_config.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23
24 namespace OHOS::Ace {
25 class ViewportConfigTest : public testing::Test {
26 public:
27 static void SetUpTestCase();
28 static void TearDownTestCase();
29 void SetUp();
30 void TearDown();
31 };
32
SetUpTestCase()33 void ViewportConfigTest::SetUpTestCase()
34 {
35 GTEST_LOG_(INFO) << "ViewportConfigTest SetUpTestCase";
36 }
37
TearDownTestCase()38 void ViewportConfigTest::TearDownTestCase()
39 {
40 GTEST_LOG_(INFO) << "ViewportConfigTest TearDownTestCase";
41 }
42
SetUp()43 void ViewportConfigTest::SetUp()
44 {
45 GTEST_LOG_(INFO) << "ViewportConfigTest SetUp";
46 }
47
TearDown()48 void ViewportConfigTest::TearDown()
49 {
50 GTEST_LOG_(INFO) << "ViewportConfigTest TearDown";
51 }
52
53 /**
54 * @tc.name: ViewportConfigTest001
55 * @tc.desc: Verify SetSize, SetPosition, SetDensity and SetOrientation api for ViewportConfig
56 * @tc.type: FUNC
57 */
58 HWTEST_F(ViewportConfigTest, ViewportConfigTest001, TestSize.Level1)
59 {
60 ViewportConfig viewConfig;
61 viewConfig.SetSize(1, 2);
62 ASSERT_EQ(viewConfig.Width(), 1);
63 ASSERT_EQ(viewConfig.Height(), 2);
64
65 viewConfig.SetPosition(1, 2);
66 ASSERT_EQ(viewConfig.Left(), 1);
67 ASSERT_EQ(viewConfig.Top(), 2);
68
69 viewConfig.SetDensity(1.0f);
70 ASSERT_EQ(viewConfig.Density(), 1.0f);
71
72 viewConfig.SetOrientation(1);
73 ASSERT_EQ(viewConfig.Orientation(), 1);
74
75 viewConfig.SetTransformHint(90);
76 ASSERT_EQ(viewConfig.TransformHint(), 90);
77 }
78
79 /**
80 * @tc.name: ViewportConfigTest002
81 * @tc.desc: Verify ToString api for ViewportConfig
82 * @tc.type: FUNC
83 */
84 HWTEST_F(ViewportConfigTest, ViewportConfigTest002, TestSize.Level1)
85 {
86 ViewportConfig viewConfig = ViewportConfig(0, 1, 1.0f);
87 auto toString = viewConfig.ToString();
88 ASSERT_EQ(
89 toString, "Viewport config: size: (0, 1) orientation: 0 density: 1.000000 position: (0, 0) transformHint: 0");
90 }
91 } // namespace OHOS::Ace