Skip to content

Commit

Permalink
Add tests for painting moved handles and both handles together in Dou…
Browse files Browse the repository at this point in the history
…bleSlider.
  • Loading branch information
przemek83 committed Dec 24, 2024
1 parent 9fa9d21 commit d3a9391
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/DoubleSliderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,30 @@ void DoubleSliderTest::testPaintingDefaultState()
QCOMPARE(actual, expected);
}

void DoubleSliderTest::testPaintingMovedHandles()
{
DoubleSlider slider(MIN, MAX);
const double step{(MAX - MIN) / 4.};
slider.setCurrentMax(MAX - step);
slider.setCurrentMin(MIN + step);
auto actual{slider.grab().toImage()};
QImage expected(":/res/sliderMovedHandles.png");
expected = expected.convertToFormat(actual.format());
QCOMPARE(actual, expected);
}

void DoubleSliderTest::testPaintingBothHandlesTogether()
{
DoubleSlider slider(MIN, MAX);
const double step{(MAX - MIN) / 2.};
slider.setCurrentMax(MAX - step);
slider.setCurrentMin(slider.getCurrentMax());
auto actual{slider.grab().toImage()};
QImage expected(":/res/sliderBothHandlesTogether.png");
expected = expected.convertToFormat(actual.format());
QCOMPARE(actual, expected);
}

void DoubleSliderTest::moveHandle(DoubleSlider& slider, QPoint from,
QPoint to) const
{
Expand Down
4 changes: 4 additions & 0 deletions tests/DoubleSliderTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ private Q_SLOTS:

static void testPaintingDefaultState();

static void testPaintingMovedHandles();

static void testPaintingBothHandlesTogether();

private:
void moveHandle(DoubleSlider& slider, QPoint from, QPoint to) const;

Expand Down
Binary file added tests/res/sliderBothHandlesTogether.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/res/sliderMovedHandles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions tests/testResources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
<file>res/counterUpdated.png</file>
<file>res/counterFinished.png</file>
<file>res/sliderDefault.png</file>
<file>res/sliderMovedHandles.png</file>
<file>res/sliderBothHandlesTogether.png</file>
</qresource>
</RCC>

0 comments on commit d3a9391

Please sign in to comment.