Skip to content

Commit

Permalink
Refactor plot tests to remove Windows-specific code and enable testRe…
Browse files Browse the repository at this point in the history
…set functionality.
  • Loading branch information
przemek83 committed Jan 12, 2025
1 parent 81ec664 commit fe77c3a
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 69 deletions.
21 changes: 1 addition & 20 deletions tests/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,28 +79,9 @@ QSize getPlotSize() { return {800, 600}; }

void checkPlot(QwtPlot& plot, const QString& expectedFileName)
{
QString expectedPath;
#ifdef Q_OS_WIN
expectedPath = QStringLiteral(":/windows/res/windows/");
// QLabel label("Running on Windows");
// qDebug() << "This code is compiled for Windows.";
#else
expectedPath = QStringLiteral(":/unix-like/res/unix-like/");
// QLabel label("Running on non-Windows OS");
// qDebug() << "This code is compiled for a non-Windows OS.";
#endif

const QImage actual{plot.grab().toImage()};
QString expectedPath{QStringLiteral(":/unix-like/res/unix-like/")};
QImage expected(expectedPath + expectedFileName);
expected = expected.convertToFormat(actual.format());
QCOMPARE(actual, expected);
}

void checkPlotCanvas(QwtPlot& plot, const QString& expectedFileName)
{
const QImage actual{plot.canvas()->grab().toImage()};
QImage expected(expectedFileName);
expected = expected.convertToFormat(actual.format());
QCOMPARE(actual, expected);
}
} // namespace common
2 changes: 0 additions & 2 deletions tests/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@ QVariant getItemInfo(QwtPlot& plot, const QString& text);
QSize getPlotSize();

void checkPlot(QwtPlot& plot, const QString& expectedFileName);

void checkPlotCanvas(QwtPlot& plot, const QString& expectedFileName);
} // namespace common
50 changes: 25 additions & 25 deletions tests/QuantilesPlotTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,36 +37,36 @@ void QuantilesPlotTest::testPlotWithoutData()
common::checkPlot(plot, expectedPath);
}

// void QuantilesPlotTest::testReset()
// {
// QuantilesPlot plot;
// preparePlot(plot);
void QuantilesPlotTest::testReset()
{
QuantilesPlot plot;
preparePlot(plot);

// QwtPlotPanner panner(plot.canvas());
// panner.setMouseButton(Qt::LeftButton);
QwtPlotPanner panner(plot.canvas());
panner.setMouseButton(Qt::LeftButton);

// plot.show();
// const QPoint endPos(50, 50);
// const QPoint startPos(100, 100);
plot.show();
const QPoint endPos(50, 50);
const QPoint startPos(100, 100);

// // Force showing label.
// QTest::mousePress(plot.canvas(), Qt::LeftButton, Qt::NoModifier, endPos);
// QTest::mouseMove(plot.canvas(), endPos);
// QTest::mouseRelease(plot.canvas(), Qt::LeftButton, Qt::NoModifier, endPos);
// Force showing label.
QTest::mousePress(plot.canvas(), Qt::LeftButton, Qt::NoModifier, endPos);
QTest::mouseMove(plot.canvas(), endPos);
QTest::mouseRelease(plot.canvas(), Qt::LeftButton, Qt::NoModifier, endPos);

// QImage beforeMove{plot.grab().toImage()};
QImage beforeMove{plot.grab().toImage()};

// QTest::mousePress(plot.canvas(), Qt::LeftButton, Qt::NoModifier, startPos);
// QTest::mouseMove(plot.canvas(), endPos);
// QTest::mouseRelease(plot.canvas(), Qt::LeftButton, Qt::NoModifier, endPos);
QTest::mousePress(plot.canvas(), Qt::LeftButton, Qt::NoModifier, startPos);
QTest::mouseMove(plot.canvas(), endPos);
QTest::mouseRelease(plot.canvas(), Qt::LeftButton, Qt::NoModifier, endPos);

// QImage afterMove{plot.grab().toImage()};
// QCOMPARE_NE(beforeMove, afterMove);
QImage afterMove{plot.grab().toImage()};
QCOMPARE_NE(beforeMove, afterMove);

// QMouseEvent customEvent(QEvent::MouseButtonDblClick, endPos, endPos,
// Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
// QCoreApplication::sendEvent(plot.canvas(), &customEvent);
QMouseEvent customEvent(QEvent::MouseButtonDblClick, endPos, endPos,
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QCoreApplication::sendEvent(plot.canvas(), &customEvent);

// const QImage afterReset{plot.grab().toImage()};
// QCOMPARE(beforeMove, afterReset);
// }
const QImage afterReset{plot.grab().toImage()};
QCOMPARE(beforeMove, afterReset);
}
2 changes: 1 addition & 1 deletion tests/QuantilesPlotTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ class QuantilesPlotTest : public QObject
private Q_SLOTS:
static void testPlotWithData();
static void testPlotWithoutData();
// static void testReset();
static void testReset();
};
20 changes: 11 additions & 9 deletions tests/Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,6 @@ int main(int argc, char* argv[])
{
const QApplication app(argc, argv);

QStyle* style{QStyleFactory::create(QStringLiteral("Fusion"))};
QApplication::setStyle(style);
setLightPalette();

const QLocale locale(QLocale::English, QLocale::UnitedStates);
QLocale::setDefault(locale);

setupFont();

int status{EXIT_SUCCESS};
UtilitiesTest utilitiesTest;
status |= QTest::qExec(&utilitiesTest);
Expand All @@ -78,6 +69,16 @@ int main(int argc, char* argv[])
QuantilesTest quantilesTest;
status |= QTest::qExec(&quantilesTest);

#ifndef Q_OS_WIN
QStyle* style{QStyleFactory::create(QStringLiteral("Fusion"))};
QApplication::setStyle(style);
setLightPalette();

const QLocale locale(QLocale::English, QLocale::UnitedStates);
QLocale::setDefault(locale);

setupFont();

BasicDataPlotTest basicDataPlotTest;
status |= QTest::qExec(&basicDataPlotTest);

Expand All @@ -89,6 +90,7 @@ int main(int argc, char* argv[])

QuantilesPlotTest quantilesPlotTest;
status |= QTest::qExec(&quantilesPlotTest);
#endif

return status;
}
Binary file removed tests/res/windows/BasicDataPlotDefault.png
Binary file not shown.
Binary file removed tests/res/windows/BasicDataPlotEmpty.png
Binary file not shown.
Binary file removed tests/res/windows/BasicDataPlotItemChecked.png
Binary file not shown.
Binary file removed tests/res/windows/GroupPlotDefault.png
Binary file not shown.
Binary file removed tests/res/windows/GroupPlotPlotWithoutData.png
Binary file not shown.
Binary file removed tests/res/windows/HistogramPlotDefault.png
Binary file not shown.
Binary file removed tests/res/windows/HistogramPlotItemChecked.png
Binary file not shown.
Binary file removed tests/res/windows/HistogramPlotWithoutData.png
Binary file not shown.
Binary file removed tests/res/windows/QuantilesPlotDefault.png
Binary file not shown.
Binary file removed tests/res/windows/QuantilesPlotWithoutData.png
Binary file not shown.
12 changes: 0 additions & 12 deletions tests/testResources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,4 @@
<file>res/unix-like/QuantilesPlotDefault.png</file>
<file>res/unix-like/QuantilesPlotWithoutData.png</file>
</qresource>
<qresource prefix="/windows">
<file>res/windows/BasicDataPlotDefault.png</file>
<file>res/windows/BasicDataPlotEmpty.png</file>
<file>res/windows/BasicDataPlotItemChecked.png</file>
<file>res/windows/HistogramPlotDefault.png</file>
<file>res/windows/HistogramPlotWithoutData.png</file>
<file>res/windows/HistogramPlotItemChecked.png</file>
<file>res/windows/GroupPlotDefault.png</file>
<file>res/windows/GroupPlotPlotWithoutData.png</file>
<file>res/windows/QuantilesPlotDefault.png</file>
<file>res/windows/QuantilesPlotWithoutData.png</file>
</qresource>
</RCC>

0 comments on commit fe77c3a

Please sign in to comment.