Skip to content

Commit

Permalink
Add tests for painting infinite progress bar.
Browse files Browse the repository at this point in the history
  • Loading branch information
przemek83 committed Dec 21, 2024
1 parent 2aac4c9 commit 41961f3
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ set(${PROJECT_TESTS}_SOURCES
ProgressBarInfiniteTest.cpp
)

qt_add_resources(${PROJECT_TESTS}_SOURCES testResources.qrc)

add_executable(${PROJECT_TESTS} ${${PROJECT_TESTS}_SOURCES})

target_link_libraries(${PROJECT_TESTS} PRIVATE wble Qt6::Core Qt6::Widgets Qt6::Test)
Expand Down
22 changes: 22 additions & 0 deletions tests/ProgressBarInfiniteTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,25 @@ void ProgressBarInfiniteTest::testReseting()
ProgressBarInfinite progressBar(QLatin1String(""));
ProgressBarCommon::checkReseting(progressBar);
}

void ProgressBarInfiniteTest::checkInitialPaint()
{
ProgressBarInfinite progressBar(QLatin1String("Initial"));
auto actual{progressBar.grab().toImage()};
QImage expected(":/infinityInitial.png");
expected = expected.convertToFormat(actual.format());
QCOMPARE(actual, expected);
}

void ProgressBarInfiniteTest::checkPaintAfterUpdate()
{
ProgressBarInfinite progressBar(QLatin1String("Updated"));
QTimerEvent event{0};
for (int i{0}; i < 10; ++i)
QApplication::sendEvent(&progressBar, &event);

auto actual{progressBar.grab().toImage()};
QImage expected(":/infinityUpdated.png");
expected = expected.convertToFormat(actual.format());
QCOMPARE(actual, expected);
}
4 changes: 4 additions & 0 deletions tests/ProgressBarInfiniteTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ private Q_SLOTS:
static void testStopping();

static void testReseting();

static void checkInitialPaint();

static void checkPaintAfterUpdate();
};
Binary file added tests/infinityInitial.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 added tests/infinityUpdated.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions tests/testResources.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<RCC>
<qresource prefix="/">
<file>infinityInitial.png</file>
<file>infinityUpdated.png</file>
</qresource>
</RCC>

0 comments on commit 41961f3

Please sign in to comment.