Skip to content

Commit

Permalink
fix: unit test error under qt5
Browse files Browse the repository at this point in the history
Log: 修复qt5下单元测试的错误
  • Loading branch information
heyuming authored and ComixHe committed Jun 21, 2023
1 parent caa5e19 commit e19d7fb
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 15 deletions.
4 changes: 2 additions & 2 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Standards-Version: 3.9.8

Package: libdtkwidget5
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, libdtkcommon,
Depends: ${shlibs:Depends}, ${misc:Depends}, libdtkcommon, libdtkdata,
libqt5widgets5(>= 5.11.3.33) | libqt5widgets5(<= 5.11.3.28)
Multi-Arch: same
Description: Deepin graphical user interface library
Expand Down Expand Up @@ -47,7 +47,7 @@ Description: Deepin graphical user interface library
Package: dtkwidget5-examples
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends},
libdtkwidget5( =${binary:Version})
libdtkwidget5( =${binary:Version}), libdtkdata
Description: dtkwidget-examples is generated by dtkwidget.
DtkWidget is Deepin graphical user interface for deepin desktop development.
.
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/daboutdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void DAboutDialogPrivate::init()
mainContent->setLayout(mainLayout);
q->addContent(mainScrollArea);

DConfig config("org.deepin.dtkwidget.feature-display");
DConfig config("org.deepin.dtk.preference");
bool isUpdated = config.value("featureUpdated", false).toBool();
redPointLabel->setVisible(isUpdated);
// make active
Expand Down Expand Up @@ -218,7 +218,7 @@ void DAboutDialogPrivate::_q_onLinkActivated(const QString &link)
void DAboutDialogPrivate::_q_onFeatureActivated(const QString &)
{
D_Q(DAboutDialog);
DConfig config("org.deepin.dtkwidget.feature-display");
DConfig config("org.deepin.dtk.preference");
if (config.value("featureUpdated", false).toBool()) {
config.setValue("featureUpdated", false);
redPointLabel->setVisible(false);
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/dmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ DMainWindow::DMainWindow(QWidget *parent)
if (DGuiApplicationHelper::isTabletEnvironment()) {
setWindowFlags(windowFlags() & ~(Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint));
}
DConfig config("org.deepin.dtkwidget.feature-display");
DConfig config("org.deepin.dtk.preference");
bool isAutoDisplayFeature = config.value("autoDisplayFeature", false).toBool();
if (isAutoDisplayFeature) {
connect(this->windowHandle(), SIGNAL(activeChanged()), this, SLOT(_q_autoShowFeatureDialog()));
Expand Down
6 changes: 3 additions & 3 deletions src/widgets/dtitlebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@ void DTitlebarPrivate::init()
optionButton = new DWindowOptionButton;
}

auto config = new DConfig("org.deepin.dtkwidget.feature-display", "", q);
auto config = new DConfig("org.deepin.dtk.preference", "", q);
bool isUpdated = config->value("featureUpdated", false).toBool();
DStyle::setRedPointVisible(optionButton, isUpdated);

uiPreferDonfig = new DConfig("org.deepin.dtk.ui.preference", "", q);
uiPreferDonfig = new DConfig("org.deepin.dtk.preference", "", q);
updateTitlebarHeight();

separatorTop = new DHorizontalLine(q);
Expand Down Expand Up @@ -1004,7 +1004,7 @@ void DTitlebar::showMenu()
action->setChecked(true);
}

DConfig config("org.deepin.dtkwidget.feature-display");
DConfig config("org.deepin.dtk.preference");
bool isUpdated = config.value("featureUpdated", false).toBool();
DStyle::setRedPointVisible(d->aboutAction, isUpdated);

Expand Down
13 changes: 6 additions & 7 deletions tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,23 @@
/**
添加Qt事件循环,兼容gtest.
*/
int runTest(QCoreApplication &app)
int runTest(Dtk::Widget::DApplication &app)
{
int ret = 0;
QTimer::singleShot(0, &app, [&app, &ret](){
ret = RUN_ALL_TESTS();
app.quit();
QTimer::singleShot(0, &app, [&app, &ret]() {
ret = RUN_ALL_TESTS();
app.quit();
});
app.exec();
return ret;
}

int main(int argc, char *argv[])
{
// gerrit编译时没有显示器,需要指定环境变量
qputenv("QT_QPA_PLATFORM", "offscreen");

Dtk::Widget::DApplication app(argc, argv);
::testing::InitGoogleTest(&argc, argv);
// gerrit编译时没有显示器,需要指定环境变量
qputenv("QT_QPA_PLATFORM", "offscreen");

#ifdef QT_DEBUG
__sanitizer_set_report_path("asan.log");
Expand Down
4 changes: 4 additions & 0 deletions tests/testcases/widgets/ut_daboutdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ TEST_F(ut_DAboutDialog, setAcknowledgementVisible)
TEST_F(ut_DAboutDialog, setCompanyLogo)
{
widget->setCompanyLogo(QPixmap(50, 50));
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
ASSERT_EQ(widget->companyLogo()->size(), QSize(50, 50));
#else
ASSERT_EQ(widget->companyLogo().size(), QSize(50, 50));
#endif
};

TEST_F(ut_DAboutDialog, setDescription)
Expand Down
34 changes: 34 additions & 0 deletions tests/testcases/widgets/ut_dimageviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include <QSignalSpy>
#include <QTouchEvent>
#include <QGraphicsSceneMouseEvent>
#if QT_VERSION > QT_VERSION_CHECK(6, 0, 0)
#include <QWindow>
#include <private/qeventpoint_p.h>
#endif

#include "dimageviewer.h"
#include "private/dimagevieweritems_p.h"
Expand Down Expand Up @@ -422,6 +426,7 @@ TEST_F(ut_DImageViewer, testRequestPreviousImage)
QSignalSpy changeSignal(viewer, &DImageViewer::requestPreviousImage);

// Simulate event trigger.
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QTouchEvent::TouchPoint point;
point.setStartPos(QPointF(0, 0));
point.setLastPos(QPointF(300, 0));
Expand All @@ -434,6 +439,20 @@ TEST_F(ut_DImageViewer, testRequestPreviousImage)
QTouchEvent touchEvent2(QEvent::TouchEnd, nullptr, Qt::NoModifier, Qt::TouchPointReleased, {point});
viewer->event(&touchEvent2);
ASSERT_EQ(changeSignal.count(), 1);
#else
QMutableEventPoint point;
point.setGlobalPosition({0,0});
point.setGlobalLastPosition({300,0});
QTouchEvent touchEvent{QEvent::TouchEnd,nullptr,Qt::NoModifier,{point}};

viewer->event(&touchEvent);
ASSERT_EQ(changeSignal.count(), 1);

point.setGlobalLastPosition({100,0});
QTouchEvent touchEvent2{QEvent::TouchEnd, nullptr, Qt::NoModifier, {point}};
viewer->event(&touchEvent2);
ASSERT_EQ(changeSignal.count(), 1);
#endif
}

TEST_F(ut_DImageViewer, testRequestNextImage)
Expand All @@ -442,6 +461,7 @@ TEST_F(ut_DImageViewer, testRequestNextImage)
QSignalSpy changeSignal(viewer, &DImageViewer::requestNextImage);

// Simulate event trigger.
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QTouchEvent::TouchPoint point;
point.setStartPos(QPointF(0, 0));
point.setLastPos(QPointF(-300, 0));
Expand All @@ -454,6 +474,20 @@ TEST_F(ut_DImageViewer, testRequestNextImage)
QTouchEvent touchEvent2(QEvent::TouchEnd, nullptr, Qt::NoModifier, Qt::TouchPointReleased, {point, point});
viewer->event(&touchEvent2);
ASSERT_EQ(changeSignal.count(), 1);
#else
QMutableEventPoint point;
point.setGlobalPosition({0,0});
point.setGlobalLastPosition({-300, 0});
QTouchEvent touchEvent(QEvent::TouchEnd, nullptr, Qt::NoModifier,{point});

viewer->event(&touchEvent);
ASSERT_EQ(changeSignal.count(), 1);

// Test multi point touch.
QTouchEvent touchEvent2(QEvent::TouchEnd, nullptr, Qt::NoModifier, {point, point});
viewer->event(&touchEvent2);
ASSERT_EQ(changeSignal.count(), 1);
#endif
}

TEST_F(ut_DImageViewer, testCropImageFinished)
Expand Down

0 comments on commit e19d7fb

Please sign in to comment.