[locale] Add test for Config initialization

- needs some massaging because Config otherwise depends on
  ModuleManager which is a UI class (for the Reasons),
  but we already have a BUILD_AS_TEST define for that purpose.
- demonstrate a nullptr deref.
This commit is contained in:
Adriaan de Groot 2020-08-06 12:32:48 +02:00
parent 04e53be934
commit b36ad4c7f4
3 changed files with 18 additions and 1 deletions

View File

@ -36,7 +36,9 @@ calamares_add_test(
localetest
SOURCES
Tests.cpp
Config.cpp
LocaleConfiguration.cpp
SetTimezoneJob.cpp
timezonewidget/TimeZoneImage.cpp
DEFINITIONS
SOURCE_DIR="${CMAKE_CURRENT_LIST_DIR}/images"

View File

@ -436,11 +436,13 @@ Config::setConfigurationMap( const QVariantMap& configurationMap )
getStartingTimezone( configurationMap, m_startingTimezone );
getGeoIP( configurationMap, m_geoip );
#ifndef BUILD_AS_TEST
if ( m_geoip && m_geoip->isValid() )
{
connect(
Calamares::ModuleManager::instance(), &Calamares::ModuleManager::modulesLoaded, this, &Config::startGeoIP );
}
#endif
}
Calamares::JobList

View File

@ -16,7 +16,7 @@
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Config.h"
#include "LocaleConfiguration.h"
#include "timezonewidget/TimeZoneImage.h"
@ -45,6 +45,9 @@ private Q_SLOTS:
void testTZImages(); // No overlaps in images
void testTZLocations(); // No overlaps in locations
void testSpecificLocations();
// Check the Config loading
void testConfigInitialization();
};
QTEST_MAIN( LocaleTests )
@ -251,6 +254,16 @@ LocaleTests::testSpecificLocations()
QVERIFY( gpos.y() < cpos.y() ); // Gibraltar is north of Ceuta
}
void
LocaleTests::testConfigInitialization()
{
Config c;
QVERIFY( !c.currentLocation() );
QVERIFY( !c.currentLocationStatus().isEmpty() );
}
#include "utils/moc-warnings.h"
#include "Tests.moc"