Debian Codegraph @

tests/src/ut_logdetailedit.cpp

raw symbols SCIP
1 // SPDX-FileCopyrightText: 2020 - 2022 UnionTech Software Technology Co., Ltd.
2 //
3 // SPDX-License-Identifier: GPL-3.0-or-later
4
5 #include "logdetailedit.h"
6 #include <stub.h>
7
8 #include <QGestureEvent>
9 #include <QMouseEvent>
10
11 #include <gtest/gtest.h>
12
13 Qt::MouseEventSource stud_source()
14 {
15 return Qt::MouseEventSynthesizedByQt;
16 }
17
18 class ut_logDetailEdit_Test : public ::testing::Test
19 {
20 // Test interface
21 protected:
22 void SetUp()
23 {
24 m_infoTextEdit = new logDetailEdit;
25 }
26 void TearDown()
27 {
28 delete m_infoTextEdit;
29 }
30
31 logDetailEdit *m_infoTextEdit = nullptr;
32 };
33
34 TEST_F(ut_logDetailEdit_Test, ShowInstallInfoTextEdit_UT_slideGesture)
35 {
36 m_infoTextEdit->slideGesture(5);
37 }
38
39 TEST_F(ut_logDetailEdit_Test, ShowInstallInfoTextEdit_UT_onSelectionArea)
40 {
41 m_infoTextEdit->m_gestureAction = logDetailEdit::GA_tap;
42 QTextCursor cursor = m_infoTextEdit->textCursor();
43 cursor.selectedText() = "//";
44 m_infoTextEdit->onSelectionArea();
45 }
46
47 TEST(FlashTween_TEST, FlashTween_UT_start)
48 {
49 FlashTween flash;
50 EXPECT_EQ(flash.sinusoidalEaseOut(1.0, 1.0, 1.0, 1.0), 1.0 * sin(1.0 / 1.0 * (3.14 / 2)) + 1.0);
51 flash.start(0, 0, 1, 0, 0);
52 flash.start(0, 0, 1, 1, 0);
53 flash.m_timer->start(5);
54 usleep(5000);
55 flash.m_timer->stop();
56 }
57
58 int states = 1;
59
60 int state()
61 {
62 return states;
63 }
64
65 TEST_F(ut_logDetailEdit_Test, ShowInstallInfoTextEdit_UT_tapGestureTriggered)
66 {
67 Stub stub;
68 stub.set(ADDR(QGesture, state), state);
69
70 while (states <= 4) {
71 QTapGesture tap;
72 tap.setPosition(QPointF(10, 10));
73 m_infoTextEdit->tapGestureTriggered(&tap);
74 if (states != 2 && states != 4) {
75 QTapAndHoldGesture tapAndHold;
76 tapAndHold.setPosition(QPointF(10, 10));
77 m_infoTextEdit->tapAndHoldGestureTriggered(&tapAndHold);
78 }
79
80 states++;
81 }
82 }
83
84 TEST_F(ut_logDetailEdit_Test, ShowInstallInfoTextEdit_UT_gestureEvent)
85 {
86 QGesture *gesture = new QGesture();
87
88 QGestureEvent gestureEvent(QList<QGesture *> {gesture, gesture});
89 m_infoTextEdit->gestureEvent(&gestureEvent);
90 delete gesture;
91 }
92
93 TEST_F(ut_logDetailEdit_Test, ShowInstallInfoTextEdit_UT_mouseReleaseEvent)
94 {
95 QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(0, 0), QPoint(0, 0), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
96 m_infoTextEdit->mouseReleaseEvent(&releaseEvent);
97 }
98
99 TEST_F(ut_logDetailEdit_Test, ShowInstallInfoTextEdit_UT_mouseMoveEvent)
100 {
101 QMouseEvent moveEvent(QEvent::MouseMove, QPoint(0, 0), QPoint(10, 0), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
102 m_infoTextEdit->mouseMoveEvent(&moveEvent);
103 }
104
105 TEST_F(ut_logDetailEdit_Test, ShowInstallInfoTextEdit_UT_mouseMoveEvent_source)
106 {
107 Stub stub;
108 stub.set(ADDR(QMouseEvent, source), stud_source);
109
110 m_infoTextEdit->m_gestureAction = logDetailEdit::GA_slide;
111 QMouseEvent moveEvent(QEvent::MouseMove, QPoint(0, 0), QPoint(10, 0), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
112 m_infoTextEdit->mouseMoveEvent(&moveEvent);
113 }