Skip to content

Commit

Permalink
Fix failing tests from BasicDataPlotTest class by using only canvas f…
Browse files Browse the repository at this point in the history
…or comparison. Font seems to difficult to match between OSes.
  • Loading branch information
przemek83 committed Jan 12, 2025
1 parent 8ddd993 commit 0abc299
Showing 7 changed files with 16 additions and 5 deletions.
7 changes: 3 additions & 4 deletions tests/BasicDataPlotTest.cpp
Original file line number Diff line number Diff line change
@@ -61,11 +61,10 @@ void BasicDataPlotTest::testPlotWithData()
{
BasicDataPlot plot;
preparePlot(plot);
plot.setAxisVisible(QwtPlot::xBottom, false);

const QString expectedPath{
QString::fromLatin1(":/res/BasicDataPlotDefault.png")};
common::checkPlot(plot, expectedPath);
common::checkPlotCanvas(plot, expectedPath);
}

void BasicDataPlotTest::testPlotWithoutData()
@@ -78,7 +77,7 @@ void BasicDataPlotTest::testPlotWithoutData()

const QString expectedPath{
QString::fromLatin1(":/res/BasicDataPlotEmpty.png")};
common::checkPlot(plot, expectedPath);
common::checkPlotCanvas(plot, expectedPath);
}

void BasicDataPlotTest::testLegendItemsChecking()
@@ -92,5 +91,5 @@ void BasicDataPlotTest::testLegendItemsChecking()

const QString expectedPath{
QString::fromLatin1(":/res/BasicDataPlotItemChecked.png")};
common::checkPlot(plot, expectedPath);
common::checkPlotCanvas(plot, expectedPath);
}
8 changes: 8 additions & 0 deletions tests/Common.cpp
Original file line number Diff line number Diff line change
@@ -84,4 +84,12 @@ void checkPlot(QwtPlot& plot, const QString& expectedPath)
expected = expected.convertToFormat(actual.format());
QCOMPARE(actual, expected);
}

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

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

void checkPlotCanvas(QwtPlot& plot, const QString& expectedPath);
} // namespace common
4 changes: 3 additions & 1 deletion tests/Tests.cpp
Original file line number Diff line number Diff line change
@@ -48,7 +48,9 @@ void setupFont()
const QString family{QFontDatabase::applicationFontFamilies(id).at(0)};
QFont font(family);
font.setPixelSize(12);
font.setStyleStrategy(QFont::NoAntialias);
font.setStyleStrategy(static_cast<QFont::StyleStrategy>(QFont::NoAntialias |
QFont::PreferBitmap | QFont::NoSubpixelAntialias |
QFont::PreferNoShaping | QFont::NoFontMerging));
QApplication::setFont(font);
}
} // namespace
Binary file modified tests/res/BasicDataPlotDefault.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/res/BasicDataPlotEmpty.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/res/BasicDataPlotItemChecked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0abc299

Please sign in to comment.