Debian Codegraph @

tests/src/ut_lognormalbutton.cpp

raw symbols SCIP
1 // SPDX-FileCopyrightText: 2019 - 2022 UnionTech Software Technology Co., Ltd.
2 //
3 // SPDX-License-Identifier: GPL-3.0-or-later
4
5 #include "lognormalbutton.h"
6
7 #include <gtest/gtest.h>
8 #include <stub.h>
9
10 #include <QKeyEvent>
11 #include <QDebug>
12 #include <QPaintEvent>
13 TEST(LogNormalButton_Constructor_UT, LogNormalButton_Constructor_UT_001)
14 {
15 LogNormalButton *p = new LogNormalButton(nullptr);
16 EXPECT_NE(p, nullptr);
17
18 p->deleteLater();
19 }
20
21 TEST(LogNormalButton_Constructor_UT, LogNormalButton_Constructor_UT_002)
22 {
23 LogNormalButton *p = new LogNormalButton("aa", nullptr);
24 EXPECT_NE(p, nullptr);
25
26 p->deleteLater();
27 }
28
29 TEST(LogNormalButton_Constructor_UT, LogNormalButton_Constructor_UT_003)
30 {
31 LogNormalButton *p = new LogNormalButton(QIcon(""), "aa", nullptr);
32 EXPECT_NE(p, nullptr);
33
34 p->deleteLater();
35 }
36
37 class LogNormalButton_keyPressEvent_UT_Param
38 {
39 public:
40 explicit LogNormalButton_keyPressEvent_UT_Param(int iKey)
41 {
42 key = iKey;
43 }
44 int key;
45 };
46
47 class LogNormalButton_keyPressEvent_UT : public ::testing::TestWithParam<LogNormalButton_keyPressEvent_UT_Param>
48 {
49 };
50
51 INSTANTIATE_TEST_CASE_P(LogNormalButton, LogNormalButton_keyPressEvent_UT, ::testing::Values(LogNormalButton_keyPressEvent_UT_Param(Qt::Key_Enter), LogNormalButton_keyPressEvent_UT_Param(Qt::Key_Return), LogNormalButton_keyPressEvent_UT_Param(Qt::Key_0)));
52
53 TEST_P(LogNormalButton_keyPressEvent_UT, LogNormalButton_keyPressEvent_UT_001)
54 {
55 LogNormalButton_keyPressEvent_UT_Param param = GetParam();
56 LogNormalButton *p = new LogNormalButton(nullptr);
57 EXPECT_NE(p, nullptr);
58
59 QKeyEvent keyEvent(QEvent::KeyPress, param.key, Qt::NoModifier);
60 p->keyPressEvent(&keyEvent);
61 p->deleteLater();
62 }
63
64 class LogNormalButton_keyReleaseEvent_UT_Param
65 {
66 public:
67 explicit LogNormalButton_keyReleaseEvent_UT_Param(int iKey)
68 {
69 key = iKey;
70 }
71 int key;
72 };
73
74 class LogNormalButton_keyReleaseEvent_UT : public ::testing::TestWithParam<LogNormalButton_keyReleaseEvent_UT_Param>
75 {
76 };
77
78 INSTANTIATE_TEST_CASE_P(LogNormalButton, LogNormalButton_keyReleaseEvent_UT, ::testing::Values(LogNormalButton_keyReleaseEvent_UT_Param(Qt::Key_Enter), LogNormalButton_keyReleaseEvent_UT_Param(Qt::Key_Return), LogNormalButton_keyReleaseEvent_UT_Param(Qt::Key_0)));
79
80 TEST_P(LogNormalButton_keyReleaseEvent_UT, LogNormalButton_keyReleaseEvent_UT_001)
81 {
82 LogNormalButton_keyReleaseEvent_UT_Param param = GetParam();
83 LogNormalButton *p = new LogNormalButton(nullptr);
84 EXPECT_NE(p, nullptr);
85
86 QKeyEvent keyEvent(QEvent::KeyPress, param.key, Qt::NoModifier);
87 p->keyReleaseEvent(&keyEvent);
88 p->deleteLater();
89 }
90
91 //TEST(LogNormalButton_paintEvent_UT, LogNormalButton_paintEventr_UT)
92 //{
93 // LogNormalButton *p = new LogNormalButton("aa", nullptr);
94 // EXPECT_NE(p, nullptr);
95 // p->paintEvent(new QPaintEvent(p->rect()));
96 // p->deleteLater();
97 //}
98
99 class LogNormalButton_focusInEvent_UT_Param
100 {
101 public:
102 explicit LogNormalButton_focusInEvent_UT_Param(Qt::FocusReason iReason)
103 : reason(iReason)
104 {
105 }
106 Qt::FocusReason reason;
107 };
108
109 class LogNormalButton_focusInEvent_UT : public ::testing::TestWithParam<LogNormalButton_focusInEvent_UT_Param>
110 {
111 };
112
113 INSTANTIATE_TEST_CASE_P(LogNormalButton, LogNormalButton_focusInEvent_UT, ::testing::Values(LogNormalButton_focusInEvent_UT_Param(Qt::ActiveWindowFocusReason), LogNormalButton_focusInEvent_UT_Param(Qt::NoFocusReason)));
114
115 TEST_P(LogNormalButton_focusInEvent_UT, LogNormalButton_focusInEvent_UT_001)
116 {
117 LogNormalButton_focusInEvent_UT_Param param = GetParam();
118 LogNormalButton *p = new LogNormalButton(nullptr);
119 EXPECT_NE(p, nullptr);
120
121 QFocusEvent *focusEvent = new QFocusEvent(QEvent::FocusIn, param.reason);
122 p->focusInEvent(focusEvent);
123 delete focusEvent;
124 p->deleteLater();
125 }