1 /*
2 * Copyright (c) 2020-2021 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 "components/ui_qrcode.h"
17
18 #include <climits>
19 #include <gtest/gtest.h>
20
21 using namespace testing::ext;
22 namespace OHOS {
23 namespace {
24 const int16_t WIDTH = 100;
25 const int16_t HEIGHT = 100;
26 }
27 class UIQrcodeTest : public testing::Test {
28 public:
29 static void SetUpTestCase(void);
30 static void TearDownTestCase(void);
31 static UIQrcode* qrcode_;
32 };
33
34 UIQrcode* UIQrcodeTest::qrcode_ = nullptr;
35
SetUpTestCase()36 void UIQrcodeTest::SetUpTestCase()
37 {
38 if (qrcode_ == nullptr) {
39 qrcode_ = new UIQrcode();
40 }
41 }
42
TearDownTestCase()43 void UIQrcodeTest::TearDownTestCase()
44 {
45 if (qrcode_ != nullptr) {
46 delete qrcode_;
47 qrcode_ = nullptr;
48 }
49 }
50
51 /**
52 * @tc.name: Graphic_UIQrcodeTest_Test_GetViewType_001
53 * @tc.desc: Verify GetViewType function.
54 * @tc.type: FUNC
55 * @tc.require: AR000F4E5M
56 */
57 HWTEST_F(UIQrcodeTest, Graphic_UIQrcodeTest_Test_GetViewType_001, TestSize.Level1)
58 {
59 if (qrcode_ == nullptr) {
60 EXPECT_NE(0, 0);
61 return;
62 }
63 EXPECT_EQ(qrcode_->GetViewType(), UI_QRCODE);
64 }
65
66 /**
67 * @tc.name: Graphic_UIQrcodeTest_Test_SetWidth_001
68 * @tc.desc: Verify SetWidth function.
69 * @tc.type: FUNC
70 * @tc.require: AR000F4E5M
71 */
72 HWTEST_F(UIQrcodeTest, Graphic_UIQrcodeTest_Test_SetWidth_001, TestSize.Level0)
73 {
74 if (qrcode_ == nullptr) {
75 EXPECT_NE(0, 0);
76 return;
77 }
78 qrcode_->SetWidth(WIDTH);
79 EXPECT_EQ(qrcode_->GetWidth(), WIDTH);
80 }
81
82 /**
83 * @tc.name: Graphic_UIQrcodeTest_Test_SetHeight_001
84 * @tc.desc: Verify SetHeight function.
85 * @tc.type: FUNC
86 * @tc.require: SR000F3PEF
87 */
88 HWTEST_F(UIQrcodeTest, Graphic_UIQrcodeTest_Test_SetHeight_001, TestSize.Level0)
89 {
90 if (qrcode_ == nullptr) {
91 EXPECT_NE(0, 0);
92 return;
93 }
94 qrcode_->SetHeight(HEIGHT);
95 EXPECT_EQ(qrcode_->GetHeight(), HEIGHT);
96 }
97 } // namespace OHOS
98