| 1 |
// SPDX-FileCopyrightText: 2019 - 2026 UnionTech Software Technology Co., Ltd. |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-3.0-or-later |
| 4 |
|
| 5 |
#include "test_todaybutton.h" |
| 6 |
|
| 7 |
#include <QTest> |
| 8 |
#include <QFocusEvent> |
| 9 |
#include <QEnterEvent> |
| 10 |
//#include <QLeaveEvent> |
| 11 |
|
| 12 |
test_todaybutton::test_todaybutton() |
| 13 |
{ |
| 14 |
|
| 15 |
} |
| 16 |
|
| 17 |
void test_todaybutton::SetUp() |
| 18 |
{ |
| 19 |
mTodayButton = new CTodayButton(); |
| 20 |
} |
| 21 |
|
| 22 |
void test_todaybutton::TearDown() |
| 23 |
{ |
| 24 |
delete mTodayButton; |
| 25 |
mTodayButton = nullptr; |
| 26 |
} |
| 27 |
|
| 28 |
//void CTodayButton::setBColor(QColor normalC, QColor hoverC, QColor pressc, QColor normalC1, QColor hoverC1, QColor pressc1) |
| 29 |
TEST_F(test_todaybutton, setBColor) |
| 30 |
{ |
| 31 |
mTodayButton->setBColor("#FFFFFF", "#000000", "#000000", "#FFFFFF", "#000000", "#000000"); |
| 32 |
} |
| 33 |
|
| 34 |
//void CTodayButton::setTColor(QColor normalC, QColor hoverC, QColor pressc) |
| 35 |
TEST_F(test_todaybutton, setTColor) |
| 36 |
{ |
| 37 |
mTodayButton->setTColor(Qt::red, "#001A2E", "#0081FF"); |
| 38 |
} |
| 39 |
|
| 40 |
//void CTodayButton::setshadowColor(QColor sc) |
| 41 |
TEST_F(test_todaybutton, setshadowColor) |
| 42 |
{ |
| 43 |
mTodayButton->setshadowColor("#FFFFFF"); |
| 44 |
} |
| 45 |
|
| 46 |
//test mouse event |
| 47 |
TEST_F(test_todaybutton, mouseEventTest) |
| 48 |
{ |
| 49 |
QTest::mousePress(mTodayButton, Qt::LeftButton); |
| 50 |
QTest::mouseRelease(mTodayButton, Qt::LeftButton); |
| 51 |
|
| 52 |
QWidget *testWidget = new QWidget(); |
| 53 |
CTodayButton *toDayButton = new CTodayButton(testWidget); |
| 54 |
toDayButton->setGeometry(10, 10, 20, 20); |
| 55 |
testWidget->setFixedSize(50, 50); |
| 56 |
toDayButton->setFocus(Qt::TabFocusReason); |
| 57 |
QTest::mouseMove(testWidget, QPoint(2, 2)); |
| 58 |
QTest::mouseMove(testWidget, QPoint(15, 15)); |
| 59 |
QTest::mouseMove(testWidget, QPoint(45, 45)); |
| 60 |
QTest::keyClick(testWidget, Qt::Key_Tab); |
| 61 |
QTest::keyClick(testWidget->focusWidget(), Qt::Key_Tab); |
| 62 |
QTest::keyClick(testWidget->focusWidget(), Qt::Key_Tab); |
| 63 |
delete testWidget; |
| 64 |
} |
| 65 |
|
| 66 |
//test key event |
| 67 |
TEST_F(test_todaybutton, keyEventTest) |
| 68 |
{ |
| 69 |
QTest::keyClick(mTodayButton, Qt::Key_Enter); |
| 70 |
QTest::keyClick(mTodayButton, Qt::Key_Tab); |
| 71 |
} |
| 72 |
|
| 73 |
//QTEST_MAIN(testGUI_toDayButton) |
| 74 |
TEST_F(test_todaybutton,focusOutEvent) |
| 75 |
{ |
| 76 |
mTodayButton->setFocus(); |
| 77 |
QFocusEvent focusEvent_out( QEvent::FocusOut,Qt::FocusReason::TabFocusReason); |
| 78 |
QApplication::sendEvent(mTodayButton,&focusEvent_out); |
| 79 |
} |
| 80 |
|
| 81 |
TEST_F(test_todaybutton,enterEvent) |
| 82 |
{ |
| 83 |
QEnterEvent enterEvent(QPointF(10,2),QPointF(11,3),QPointF(12,4)); |
| 84 |
QApplication::sendEvent(mTodayButton,&enterEvent); |
| 85 |
QEvent event(QEvent::Leave); |
| 86 |
QApplication::sendEvent(mTodayButton,&event); |
| 87 |
} |
| 88 |
|
| 89 |
TEST_F(test_todaybutton,keypressEvent) |
| 90 |
{ |
| 91 |
QKeyEvent keyevent(QEvent::KeyPress,Qt::Key_Return,Qt::NoModifier); |
| 92 |
QApplication::sendEvent(mTodayButton,&keyevent); |
| 93 |
} |