Skip to content

Commit

Permalink
Tests: fix index out of range in applicationFilePath()
Browse files Browse the repository at this point in the history
Most probably in order to prevent instantiating QApplication despite
QtGui module was used, some test cases used QTEST_APPLESS_MAIN and
instantiated QCoreApplication manually, passing argc=0.
QCoreApplication::applicationFilePath() does not expect argc ever being
less than one.

Qt5 testlib comes with QTEST_GUILESS_MAIN which works as expected here.
For Qt4 build QTEST_GUILESS_MAIN definition is available from project
file.

This also fixes many failures to find a file at path relative to test
executable.

Note that in ft_locales.cpp QTEST_MAIN is used as QGuiApplication is
needed by the code.
  • Loading branch information
martyone authored and pvuorela committed Oct 7, 2014
1 parent a681185 commit 95a5e84
Show file tree
Hide file tree
Showing 30 changed files with 32 additions and 101 deletions.
8 changes: 8 additions & 0 deletions benchmarks/common_top.pri
Expand Up @@ -29,3 +29,11 @@ equals(QT_MAJOR_VERSION, 5): support_files.path = $$[QT_INSTALL_LIBS]/libmlocale
INSTALLS += support_files

CONFIG-=app_bundle

equals(QT_MAJOR_VERSION, 4): DEFINES += '\'QTEST_GUILESS_MAIN(TestObject)=\
int main(int argc, char *argv[]) \
{ \
QCoreApplication app(argc, argv); \
TestObject tc; \
return QTest::qExec(&tc, argc, argv); \
}\''
6 changes: 1 addition & 5 deletions benchmarks/pt_mcalendar/pt_mcalendar.cpp
Expand Up @@ -29,9 +29,6 @@ using ML10N::MCalendar;

void Pt_MCalendar::initTestCase()
{
static int argc = 0;
static char *argv[1] = { (char *) "" };
qap = new QCoreApplication(argc, argv);
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
#endif
Expand All @@ -48,7 +45,6 @@ void Pt_MCalendar::initTestCase()

void Pt_MCalendar::cleanupTestCase()
{
delete qap;
}

void Pt_MCalendar::init()
Expand Down Expand Up @@ -339,5 +335,5 @@ void Pt_MCalendar::benchmarkFormatDateTimeICU()
}
}

QTEST_APPLESS_MAIN(Pt_MCalendar);
QTEST_GUILESS_MAIN(Pt_MCalendar);

1 change: 0 additions & 1 deletion benchmarks/pt_mcalendar/pt_mcalendar.h
Expand Up @@ -31,7 +31,6 @@ class Pt_MCalendar : public QObject
Q_OBJECT

private:
QCoreApplication *qap;
QString icuPackageVersion;

private slots:
Expand Down
6 changes: 1 addition & 5 deletions benchmarks/pt_mcharsetdetector/pt_mcharsetdetector.cpp
Expand Up @@ -24,17 +24,13 @@ using ML10N::MCharsetMatch;

void Pt_MCharsetDetector::initTestCase()
{
static int argc = 0;
static char *argv[1] = { (char *) "" };
qap = new QCoreApplication(argc, argv);
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
#endif
}

void Pt_MCharsetDetector::cleanupTestCase()
{
delete qap;
}

void Pt_MCharsetDetector::init()
Expand Down Expand Up @@ -148,4 +144,4 @@ void Pt_MCharsetDetector::benchmarkDetection()
}
}

QTEST_APPLESS_MAIN(Pt_MCharsetDetector);
QTEST_GUILESS_MAIN(Pt_MCharsetDetector);
3 changes: 0 additions & 3 deletions benchmarks/pt_mcharsetdetector/pt_mcharsetdetector.h
Expand Up @@ -32,9 +32,6 @@ class Pt_MCharsetDetector : public QObject
{
Q_OBJECT

private:
QCoreApplication *qap;

private slots:
void initTestCase();
void cleanupTestCase();
Expand Down
6 changes: 1 addition & 5 deletions benchmarks/pt_mlocale/pt_mlocale.cpp
Expand Up @@ -26,9 +26,6 @@ using ML10N::MCollator;

void Pt_MLocale::initTestCase()
{
static int argc = 0;
static char *argv[1] = { (char *) "" };
qap = new QCoreApplication(argc, argv);
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
#endif
Expand All @@ -47,7 +44,6 @@ void Pt_MLocale::initTestCase()

void Pt_MLocale::cleanupTestCase()
{
delete qap;
}

void Pt_MLocale::init()
Expand Down Expand Up @@ -275,4 +271,4 @@ void Pt_MLocale::benchmarkCollatorStrengthSwitching()
}
}
#endif
QTEST_APPLESS_MAIN(Pt_MLocale);
QTEST_GUILESS_MAIN(Pt_MLocale);
1 change: 0 additions & 1 deletion benchmarks/pt_mlocale/pt_mlocale.h
Expand Up @@ -37,7 +37,6 @@ class Pt_MLocale : public QObject
Q_OBJECT

private:
QCoreApplication *qap;
QString icuPackageVersion;

private slots:
Expand Down
6 changes: 1 addition & 5 deletions benchmarks/pt_mlocationdatabase/pt_mlocationdatabase.cpp
Expand Up @@ -28,17 +28,13 @@ using ML10N::MLocationDatabase;

void Pt_MLocationDatabase::initTestCase()
{
static int argc = 0;
static char *argv[1] = { (char *) "" };
qap = new QCoreApplication(argc, argv);
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
#endif
}

void Pt_MLocationDatabase::cleanupTestCase()
{
delete qap;
}

void Pt_MLocationDatabase::init()
Expand Down Expand Up @@ -108,5 +104,5 @@ void Pt_MLocationDatabase::benchmarkMatchingCities()
}
}

QTEST_APPLESS_MAIN(Pt_MLocationDatabase);
QTEST_GUILESS_MAIN(Pt_MLocationDatabase);

3 changes: 0 additions & 3 deletions benchmarks/pt_mlocationdatabase/pt_mlocationdatabase.h
Expand Up @@ -28,9 +28,6 @@ class Pt_MLocationDatabase : public QObject
{
Q_OBJECT

private:
QCoreApplication *qap;

private slots:
void initTestCase();
void cleanupTestCase();
Expand Down
8 changes: 8 additions & 0 deletions tests/common_top.pri
Expand Up @@ -30,3 +30,11 @@ support_files.files =
equals(QT_MAJOR_VERSION, 4): support_files.path = $$[QT_INSTALL_LIBS]/libmlocale-tests
equals(QT_MAJOR_VERSION, 5): support_files.path = $$[QT_INSTALL_LIBS]/libmlocale-tests5
INSTALLS += support_files

equals(QT_MAJOR_VERSION, 4): DEFINES += '\'QTEST_GUILESS_MAIN(TestObject)=\
int main(int argc, char *argv[]) \
{ \
QCoreApplication app(argc, argv); \
TestObject tc; \
return QTest::qExec(&tc, argc, argv); \
}\''
6 changes: 1 addition & 5 deletions tests/ft_breakiterator/ft_breakiterator.cpp
Expand Up @@ -37,17 +37,13 @@ class TestBreakIterator : public MBreakIterator

void Ft_BreakIterator::initTestCase()
{
static int argc = 0;
static char *argv[1] = { (char *) "" };
qap = new QCoreApplication(argc, argv);
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
#endif
}

void Ft_BreakIterator::cleanupTestCase()
{
delete qap;
}

void Ft_BreakIterator::init()
Expand Down Expand Up @@ -334,4 +330,4 @@ void Ft_BreakIterator::peek()
}


QTEST_APPLESS_MAIN(Ft_BreakIterator);
QTEST_GUILESS_MAIN(Ft_BreakIterator);
3 changes: 0 additions & 3 deletions tests/ft_breakiterator/ft_breakiterator.h
Expand Up @@ -37,9 +37,6 @@ class Ft_BreakIterator : public QObject
{
Q_OBJECT

private:
QCoreApplication *qap;

private slots:
void initTestCase();
void cleanupTestCase();
Expand Down
5 changes: 1 addition & 4 deletions tests/ft_localedata/ft_localedata.cpp
Expand Up @@ -23,9 +23,6 @@ using ML10N::MLocale;

void Ft_LocaleData::initTestCase()
{
static int argc = 0;
static char *argv[1] = { (char *) "" };
app = new QCoreApplication(argc, argv);
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
#endif
Expand Down Expand Up @@ -99,4 +96,4 @@ void Ft_LocaleData::testNumberData()
QCOMPARE(locale.formatNumber(value), result);
}

QTEST_APPLESS_MAIN(Ft_LocaleData);
QTEST_GUILESS_MAIN(Ft_LocaleData);
3 changes: 0 additions & 3 deletions tests/ft_localedata/ft_localedata.h
Expand Up @@ -35,9 +35,6 @@ class Ft_LocaleData : public QObject
{
Q_OBJECT

private:
QCoreApplication *app;

private slots:
void initTestCase();

Expand Down
6 changes: 1 addition & 5 deletions tests/ft_locales/ft_locales.cpp
Expand Up @@ -31,9 +31,6 @@ class TestLocale : public MLocale

void Ft_Locales::initTestCase()
{
static int dummyArgc = 1;
static char *dummyArgv[1] = { (char *) "ft_locales" };
qap = new QCoreApplication(dummyArgc, dummyArgv);
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
#endif
Expand All @@ -50,7 +47,6 @@ void Ft_Locales::initTestCase()

void Ft_Locales::cleanupTestCase()
{
delete qap;
}

void Ft_Locales::init()
Expand Down Expand Up @@ -4860,4 +4856,4 @@ void Ft_Locales::checkAvailableLocales()
}
}

QTEST_APPLESS_MAIN(Ft_Locales);
QTEST_MAIN(Ft_Locales);
1 change: 0 additions & 1 deletion tests/ft_locales/ft_locales.h
Expand Up @@ -55,7 +55,6 @@ class Ft_Locales : public QObject
Q_OBJECT

private:
QCoreApplication *qap;
QString libqtcore4PackageVersion;

private slots:
Expand Down
6 changes: 1 addition & 5 deletions tests/ft_mcharsetdetector/ft_mcharsetdetector.cpp
Expand Up @@ -26,17 +26,13 @@ using ML10N::MCharsetDetector;

void Ft_MCharsetDetector::initTestCase()
{
static int dummyArgc = 1;
static char *dummyArgv[1] = { (char *) "ft_mcharsetdetector" };
qap = new QCoreApplication(dummyArgc, dummyArgv);
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
#endif
}

void Ft_MCharsetDetector::cleanupTestCase()
{
delete qap;
}

void Ft_MCharsetDetector::init()
Expand Down Expand Up @@ -2001,4 +1997,4 @@ void Ft_MCharsetDetector::testDetection()
}
}

QTEST_APPLESS_MAIN(Ft_MCharsetDetector);
QTEST_GUILESS_MAIN(Ft_MCharsetDetector);
3 changes: 0 additions & 3 deletions tests/ft_mcharsetdetector/ft_mcharsetdetector.h
Expand Up @@ -34,9 +34,6 @@ class Ft_MCharsetDetector : public QObject
{
Q_OBJECT

private:
QCoreApplication *qap;

private slots:
void initTestCase();
void cleanupTestCase();
Expand Down
8 changes: 1 addition & 7 deletions tests/ft_mlocalebuckets/ft_mlocalebuckets.cpp
Expand Up @@ -38,16 +38,11 @@ using std::endl;
using ML10N::MLocale;
using ML10N::MLocaleBuckets;

QCoreApplication *app = 0;
QStringList inputItems;


void Ft_MLocaleBuckets::initTestCase()
{
static char *argv[] = { (char *) "./ft_mlocalebuckets" };
static int argc = 1;
app = new QCoreApplication(argc, argv);

// This is important for string constants with non-ASCII characters:
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
Expand All @@ -74,7 +69,6 @@ void Ft_MLocaleBuckets::initTestCase()

void Ft_MLocaleBuckets::cleanupTestCase()
{
delete app;
}


Expand Down Expand Up @@ -868,4 +862,4 @@ void Ft_MLocaleBuckets::sortTestFiles()
testOutputFile.close();
}

QTEST_APPLESS_MAIN(Ft_MLocaleBuckets)
QTEST_GUILESS_MAIN(Ft_MLocaleBuckets)
6 changes: 1 addition & 5 deletions tests/ft_mstringsearch/ft_mstringsearch.cpp
Expand Up @@ -27,17 +27,13 @@ using ML10N::MStringSearch;

void Ft_MStringSearch::initTestCase()
{
static int dummyArgc = 1;
static char *dummyArgv[1] = { (char *) "ft_mstringsearch" };
qap = new QCoreApplication(dummyArgc, dummyArgv);
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
#endif
}

void Ft_MStringSearch::cleanupTestCase()
{
delete qap;
}

void Ft_MStringSearch::init()
Expand Down Expand Up @@ -682,5 +678,5 @@ void Ft_MStringSearch::testSearch()
QCOMPARE(matchText, firstMatchText);
}

QTEST_APPLESS_MAIN(Ft_MStringSearch);
QTEST_GUILESS_MAIN(Ft_MStringSearch);

3 changes: 0 additions & 3 deletions tests/ft_mstringsearch/ft_mstringsearch.h
Expand Up @@ -37,9 +37,6 @@ class Ft_MStringSearch : public QObject
{
Q_OBJECT

private:
QCoreApplication *qap;

private slots:
void initTestCase();
void cleanupTestCase();
Expand Down
6 changes: 1 addition & 5 deletions tests/ft_numbers/ft_numbers.cpp
Expand Up @@ -25,9 +25,6 @@ using ML10N::MLocale;

void Ft_Numbers::initTestCase()
{
static int argc = 0;
static char *argv[1] = { (char *) "" };
qap = new QCoreApplication(argc, argv);
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
#endif
Expand All @@ -44,7 +41,6 @@ void Ft_Numbers::initTestCase()

void Ft_Numbers::cleanupTestCase()
{
delete qap;
}

void Ft_Numbers::init()
Expand Down Expand Up @@ -3286,5 +3282,5 @@ void Ft_Numbers::testToLocalizedNumbers()
QCOMPARE(result, expectedResult);
}

QTEST_APPLESS_MAIN(Ft_Numbers);
QTEST_GUILESS_MAIN(Ft_Numbers);

1 change: 0 additions & 1 deletion tests/ft_numbers/ft_numbers.h
Expand Up @@ -41,7 +41,6 @@ class Ft_Numbers : public QObject
Q_OBJECT

private:
QCoreApplication *qap;
QString icuPackageVersion;

private slots:
Expand Down
5 changes: 1 addition & 4 deletions tests/ft_sorting/ft_sorting.cpp
Expand Up @@ -38,9 +38,6 @@ class TestCollator : public MCollator

void Ft_Sorting::initTestCase()
{
static int argc = 0;
static char *argv[1] = { (char *) "" };
qap = new QCoreApplication(argc, argv);
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
#endif
Expand Down Expand Up @@ -536,4 +533,4 @@ void Ft_Sorting::testCompareWithLocale()
QVERIFY2(mcomp.compare(loc2, str1, str2) == result, "Compare failed");
}

QTEST_APPLESS_MAIN(Ft_Sorting);
QTEST_GUILESS_MAIN(Ft_Sorting);

0 comments on commit 95a5e84

Please sign in to comment.