From 39450089567939258f696977564e1461ec882273 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 14 Apr 2020 15:10:04 +0200 Subject: [PATCH] [locale] Test the TZ image loader - QImage needs Qt5::Gui, so this isn't a guiless-test; it can use the offscreen QPA, though. - Check that the images are all the same size - Debugging / check code removed from timezonewidget --- src/modules/locale/CMakeLists.txt | 5 ++++ src/modules/locale/Tests.cpp | 28 ++++++++++++++++++- .../locale/timezonewidget/timezonewidget.cpp | 7 ----- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/modules/locale/CMakeLists.txt b/src/modules/locale/CMakeLists.txt index 5757cc9dd..9813d17b1 100644 --- a/src/modules/locale/CMakeLists.txt +++ b/src/modules/locale/CMakeLists.txt @@ -37,4 +37,9 @@ calamares_add_test( SOURCES Tests.cpp LocaleConfiguration.cpp + timezonewidget/TimeZoneImage.cpp + DEFINITIONS + SOURCE_DIR="${CMAKE_CURRENT_LIST_DIR}/images" + LIBRARIES + Qt5::Gui ) diff --git a/src/modules/locale/Tests.cpp b/src/modules/locale/Tests.cpp index d5a540b32..902297678 100644 --- a/src/modules/locale/Tests.cpp +++ b/src/modules/locale/Tests.cpp @@ -19,12 +19,13 @@ #include "Tests.h" #include "LocaleConfiguration.h" +#include "timezonewidget/TimeZoneImage.h" #include "locale/TimeZone.h" #include -QTEST_GUILESS_MAIN( LocaleTests ) +QTEST_MAIN( LocaleTests ) LocaleTests::LocaleTests() {} @@ -84,6 +85,31 @@ void LocaleTests::testTZImages() { Logger::setupLogLevel( Logger::LOGDEBUG ); + + // Number of zone images + // + // + auto images = TimeZoneImageList::fromDirectory( SOURCE_DIR ); + QCOMPARE( images.count(), images.zoneCount() ); + QCOMPARE( images.count(), 38 ); // counted by hand + + // All image sizes consistent + // + // + const QSize windowSize( 780, 340 ); + { + QImage background( SOURCE_DIR "/bg.png" ); + QVERIFY( !background.isNull() ); + QCOMPARE( background.size(), windowSize ); + } + for ( const auto& image : images ) + { + QCOMPARE( image.size(), windowSize ); + } + + // Check zones are uniquely-claimed + // + // using namespace CalamaresUtils::Locale; const CStringPairList& regions = TZRegion::fromZoneTab(); diff --git a/src/modules/locale/timezonewidget/timezonewidget.cpp b/src/modules/locale/timezonewidget/timezonewidget.cpp index 1e368271b..ba684f5f3 100644 --- a/src/modules/locale/timezonewidget/timezonewidget.cpp +++ b/src/modules/locale/timezonewidget/timezonewidget.cpp @@ -55,13 +55,6 @@ TimeZoneWidget::TimeZoneWidget( QWidget* parent ) background = QImage( ":/images/bg.png" ); pin = QImage( ":/images/pin.png" ); -#ifdef DEBUG_TIMEZONES - if ( background.size() != QSize( 780, 340 ) ) - { - cWarning() << "Timezone background size mismatch" << background.size(); - } -#endif - // Set size setMinimumSize( background.size() ); setMaximumSize( background.size() );