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