| 1 |
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd. |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-3.0-or-later |
| 4 |
|
| 5 |
#include "test_titlewidget.h" |
| 6 |
|
| 7 |
#include <QTest> |
| 8 |
#include <QResizeEvent> |
| 9 |
#include <QKeyEvent> |
| 10 |
#include <QFocusEvent> |
| 11 |
|
| 12 |
test_titleWidget::test_titleWidget() |
| 13 |
{ |
| 14 |
|
| 15 |
} |
| 16 |
|
| 17 |
void test_titleWidget::SetUp() |
| 18 |
{ |
| 19 |
m_titleWidget = new CTitleWidget(); |
| 20 |
} |
| 21 |
|
| 22 |
void test_titleWidget::TearDown() |
| 23 |
{ |
| 24 |
delete m_titleWidget; |
| 25 |
m_titleWidget = nullptr; |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
TEST_F(test_titleWidget,resizeEvent) |
| 30 |
{ |
| 31 |
m_titleWidget->setFixedSize(600,30); |
| 32 |
QResizeEvent resizeEvent(QSize(500,30),QSize(600,30)); |
| 33 |
QApplication::sendEvent(m_titleWidget, &resizeEvent); |
| 34 |
|
| 35 |
m_titleWidget->setFixedSize(1900,30); |
| 36 |
QResizeEvent resizeEvent1(QSize(1920,30),QSize(1900,30)); |
| 37 |
QApplication::sendEvent(m_titleWidget, &resizeEvent1); |
| 38 |
} |
| 39 |
|
| 40 |
TEST_F(test_titleWidget,eventFilter) |
| 41 |
{ |
| 42 |
DButtonBoxButton *boxbtn = m_titleWidget->findChild<DButtonBoxButton *>(); |
| 43 |
if(boxbtn){ |
| 44 |
QKeyEvent keyevent(QEvent::KeyPress,Qt::Key_Return,Qt::NoModifier); |
| 45 |
QApplication::sendEvent(boxbtn,&keyevent); |
| 46 |
} |
| 47 |
|
| 48 |
DSearchEdit *edit = m_titleWidget->findChild<DSearchEdit *>(); |
| 49 |
if(edit){ |
| 50 |
QFocusEvent focusEvent_in( QEvent::FocusIn,Qt::FocusReason::TabFocusReason); |
| 51 |
QApplication::sendEvent(edit->lineEdit(),&focusEvent_in); |
| 52 |
QFocusEvent focusEvent_out( QEvent::FocusOut,Qt::FocusReason::TabFocusReason); |
| 53 |
QApplication::sendEvent(edit->lineEdit(),&focusEvent_out); |
| 54 |
} |
| 55 |
|
| 56 |
DButtonBox *buttonBox = m_titleWidget->findChild<DButtonBox *>(); |
| 57 |
if(buttonBox){ |
| 58 |
buttonBox->button(0)->setFocus(); |
| 59 |
buttonBox->button(0)->setChecked(true); |
| 60 |
QFocusEvent focusEvent_in(QEvent::FocusIn,Qt::FocusReason::ActiveWindowFocusReason); |
| 61 |
QApplication::sendEvent(buttonBox,&focusEvent_in); |
| 62 |
} |
| 63 |
} |