summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/image
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2014-07-09 14:25:26 +0200
committerFriedemann Kleint <Friedemann.Kleint@digia.com>2014-07-10 07:07:30 +0200
commit72024fd50cdead8d890886dba32fd81ac54ff3ae (patch)
tree15a8e2183babb6ba22938622fa1c4300ee054599 /tests/auto/gui/image
parent745448d3eaa178ff1b7b75bdd577ad31e9177cd6 (diff)
Reduce repetitive invocations of QFINDTESTDATA.
Store the file names in variables instead. Task-number: QTBUG-38890 Change-Id: I65f28bb62674f14aa099e935a9d7a4e9e6e90ba9 Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com> Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Diffstat (limited to 'tests/auto/gui/image')
-rw-r--r--tests/auto/gui/image/qimage/tst_qimage.cpp50
-rw-r--r--tests/auto/gui/image/qpixmap/tst_qpixmap.cpp100
2 files changed, 72 insertions, 78 deletions
diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp
index e2135ad6f0..d885ab6dd4 100644
--- a/tests/auto/gui/image/qimage/tst_qimage.cpp
+++ b/tests/auto/gui/image/qimage/tst_qimage.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the test suite of the Qt Toolkit.
@@ -62,6 +62,7 @@ public:
tst_QImage();
private slots:
+ void initTestCase();
void swap();
void create();
void createInvalidXPM();
@@ -178,11 +179,19 @@ private slots:
void convertToImageFormat();
void cleanupFunctions();
+
+private:
+ const QString m_prefix;
};
tst_QImage::tst_QImage()
+ : m_prefix(QFINDTESTDATA("images/"))
+{
+}
+void tst_QImage::initTestCase()
{
+ QVERIFY(!m_prefix.isEmpty());
}
void tst_QImage::swap()
@@ -291,21 +300,17 @@ void tst_QImage::formatHandlersInput_data()
QTest::addColumn<QString>("testFormat");
QTest::addColumn<QString>("testFile");
- const QString prefix = QFINDTESTDATA("images/");
- if (prefix.isEmpty())
- QFAIL("can not find images directory!");
-
// add a new line here when a file is added
- QTest::newRow("ICO") << "ICO" << prefix + "image.ico";
- QTest::newRow("PNG") << "PNG" << prefix + "image.png";
- QTest::newRow("GIF") << "GIF" << prefix + "image.gif";
- QTest::newRow("BMP") << "BMP" << prefix + "image.bmp";
- QTest::newRow("JPEG") << "JPEG" << prefix + "image.jpg";
- QTest::newRow("PBM") << "PBM" << prefix + "image.pbm";
- QTest::newRow("PGM") << "PGM" << prefix + "image.pgm";
- QTest::newRow("PPM") << "PPM" << prefix + "image.ppm";
- QTest::newRow("XBM") << "XBM" << prefix + "image.xbm";
- QTest::newRow("XPM") << "XPM" << prefix + "image.xpm";
+ QTest::newRow("ICO") << "ICO" << m_prefix + "image.ico";
+ QTest::newRow("PNG") << "PNG" << m_prefix + "image.png";
+ QTest::newRow("GIF") << "GIF" << m_prefix + "image.gif";
+ QTest::newRow("BMP") << "BMP" << m_prefix + "image.bmp";
+ QTest::newRow("JPEG") << "JPEG" << m_prefix + "image.jpg";
+ QTest::newRow("PBM") << "PBM" << m_prefix + "image.pbm";
+ QTest::newRow("PGM") << "PGM" << m_prefix + "image.pgm";
+ QTest::newRow("PPM") << "PPM" << m_prefix + "image.ppm";
+ QTest::newRow("XBM") << "XBM" << m_prefix + "image.xbm";
+ QTest::newRow("XPM") << "XPM" << m_prefix + "image.xpm";
}
void tst_QImage::formatHandlersInput()
@@ -1085,10 +1090,7 @@ void tst_QImage::copy()
void tst_QImage::load()
{
- const QString prefix = QFINDTESTDATA("images/");
- if (prefix.isEmpty())
- QFAIL("can not find images directory!");
- const QString filePath = prefix + QLatin1String("image.jpg");
+ const QString filePath = m_prefix + QLatin1String("image.jpg");
QImage dest(filePath);
QVERIFY(!dest.isNull());
@@ -1100,10 +1102,7 @@ void tst_QImage::load()
void tst_QImage::loadFromData()
{
- const QString prefix = QFINDTESTDATA("images/");
- if (prefix.isEmpty())
- QFAIL("can not find images directory!");
- const QString filePath = prefix + QLatin1String("image.jpg");
+ const QString filePath = m_prefix + QLatin1String("image.jpg");
QImage original(filePath);
QVERIFY(!original.isNull());
@@ -1129,10 +1128,7 @@ void tst_QImage::loadFromData()
#if !defined(QT_NO_DATASTREAM)
void tst_QImage::loadFromDataStream()
{
- const QString prefix = QFINDTESTDATA("images/");
- if (prefix.isEmpty())
- QFAIL("can not find images directory!");
- const QString filePath = prefix + QLatin1String("image.jpg");
+ const QString filePath = m_prefix + QLatin1String("image.jpg");
QImage original(filePath);
QVERIFY(!original.isNull());
diff --git a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp
index b9d0adcd21..0c5d9f23b9 100644
--- a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp
+++ b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the test suite of the Qt Toolkit.
@@ -78,6 +78,7 @@ public:
public slots:
void init();
void cleanup();
+ void initTestCase();
void cleanupTestCase();
private slots:
@@ -171,6 +172,11 @@ private slots:
void detachOnLoad_QTBUG29639();
void copyOnNonAlignedBoundary();
+
+private:
+ const QString m_prefix;
+ const QString m_convertFromImage;
+ const QString m_loadFromData;
};
static bool lenientCompare(const QPixmap &actual, const QPixmap &expected)
@@ -207,6 +213,9 @@ static bool lenientCompare(const QPixmap &actual, const QPixmap &expected)
tst_QPixmap::tst_QPixmap()
+ : m_prefix(QFINDTESTDATA("images/"))
+ , m_convertFromImage(QFINDTESTDATA("convertFromImage"))
+ , m_loadFromData(QFINDTESTDATA("loadFromData"))
{
}
@@ -222,6 +231,13 @@ void tst_QPixmap::cleanup()
{
}
+void tst_QPixmap::initTestCase()
+{
+ QVERIFY(!m_prefix.isEmpty());
+ QVERIFY(!m_convertFromImage.isEmpty());
+ QVERIFY(!m_loadFromData.isEmpty());
+}
+
void tst_QPixmap::cleanupTestCase()
{
QFile::remove(QLatin1String("temp_image.png"));
@@ -312,22 +328,21 @@ void tst_QPixmap::convertFromImage_data()
{
QTest::addColumn<QImage>("img1");
QTest::addColumn<QImage>("img2");
- const QString prefix = QFINDTESTDATA("convertFromImage");
{
QImage img1;
QImage img2;
- QVERIFY(img1.load(prefix + "/task31722_0/img1.png"));
- QVERIFY(img2.load(prefix + "/task31722_0/img2.png"));
- QVERIFY(img1.load(prefix + "/task31722_0/img1.png"));
- QVERIFY(img2.load(prefix + "/task31722_0/img2.png"));
+ QVERIFY(img1.load(m_convertFromImage + "/task31722_0/img1.png"));
+ QVERIFY(img2.load(m_convertFromImage + "/task31722_0/img2.png"));
+ QVERIFY(img1.load(m_convertFromImage + "/task31722_0/img1.png"));
+ QVERIFY(img2.load(m_convertFromImage + "/task31722_0/img2.png"));
QTest::newRow("Task 31722 0") << img1 << img2;
}
{
QImage img1;
QImage img2;
- QVERIFY(img1.load(prefix + "/task31722_1/img1.png"));
- QVERIFY(img2.load(prefix + "/task31722_1/img2.png"));
+ QVERIFY(img1.load(m_convertFromImage + "/task31722_1/img1.png"));
+ QVERIFY(img2.load(m_convertFromImage + "/task31722_1/img2.png"));
QTest::newRow("Task 31722 1") << img1 << img2;
}
}
@@ -346,11 +361,10 @@ void tst_QPixmap::convertFromImage()
void tst_QPixmap::convertFromImageShouldDetach()
{
- const QString prefix = QFINDTESTDATA("convertFromImage");
QImage img1;
QImage img2;
- QVERIFY(img1.load(prefix + "/task31722_0/img1.png"));
- QVERIFY(img2.load(prefix + "/task31722_0/img2.png"));
+ QVERIFY(img1.load(m_convertFromImage + "/task31722_0/img1.png"));
+ QVERIFY(img2.load(m_convertFromImage + "/task31722_0/img2.png"));
QPixmap pix = QPixmap::fromImage(img1);
QPixmap pix1 = pix;
pix.convertFromImage(img2);
@@ -1202,10 +1216,7 @@ void tst_QPixmap::transformed2()
void tst_QPixmap::load()
{
- const QString prefix = QFINDTESTDATA("images/");
- if (prefix.isEmpty())
- QFAIL("can not find images directory!");
- const QString filePath = prefix + QLatin1String("designer.png");
+ const QString filePath = m_prefix + QLatin1String("designer.png");
QPixmap dest(filePath);
QVERIFY(!dest.isNull());
@@ -1217,10 +1228,7 @@ void tst_QPixmap::load()
void tst_QPixmap::loadFromData()
{
- const QString prefix = QFINDTESTDATA("images/");
- if (prefix.isEmpty())
- QFAIL("can not find images directory!");
- const QString filePath = prefix + QLatin1String("designer.png");
+ const QString filePath = m_prefix + QLatin1String("designer.png");
QPixmap original(filePath);
QVERIFY(!original.isNull());
@@ -1246,10 +1254,7 @@ void tst_QPixmap::loadFromData()
#if !defined(QT_NO_DATASTREAM)
void tst_QPixmap::loadFromDataStream()
{
- const QString prefix = QFINDTESTDATA("images/");
- if (prefix.isEmpty())
- QFAIL("can not find images directory!");
- const QString filePath = prefix + QLatin1String("designer.png");
+ const QString filePath = m_prefix + QLatin1String("designer.png");
QPixmap original(filePath);
QVERIFY(!original.isNull());
@@ -1344,17 +1349,15 @@ void tst_QPixmap::loadFromDataImage_data()
{
QTest::addColumn<QString>("imagePath");
- const QString prefix = QFINDTESTDATA("loadFromData");
-
- QTest::newRow("designer_argb32.png") << prefix + "/designer_argb32.png";
+ QTest::newRow("designer_argb32.png") << m_loadFromData + "/designer_argb32.png";
// When no extension is provided we try all extensions that has been registered by image providers
- QTest::newRow("designer_argb32") << prefix + "/designer_argb32.png";
- QTest::newRow("designer_indexed8_no_alpha.png") << prefix + "/designer_indexed8_no_alpha.png";
- QTest::newRow("designer_indexed8_with_alpha.png") << prefix + "/designer_indexed8_with_alpha.png";
- QTest::newRow("designer_rgb32.png") << prefix + "/designer_rgb32.png";
- QTest::newRow("designer_indexed8_no_alpha.gif") << prefix + "/designer_indexed8_no_alpha.gif";
- QTest::newRow("designer_indexed8_with_alpha.gif") << prefix + "/designer_indexed8_with_alpha.gif";
- QTest::newRow("designer_rgb32.jpg") << prefix + "/designer_rgb32.jpg";
+ QTest::newRow("designer_argb32") << m_loadFromData + "/designer_argb32.png";
+ QTest::newRow("designer_indexed8_no_alpha.png") << m_loadFromData + "/designer_indexed8_no_alpha.png";
+ QTest::newRow("designer_indexed8_with_alpha.png") << m_loadFromData + "/designer_indexed8_with_alpha.png";
+ QTest::newRow("designer_rgb32.png") << m_loadFromData + "/designer_rgb32.png";
+ QTest::newRow("designer_indexed8_no_alpha.gif") << m_loadFromData + "/designer_indexed8_no_alpha.gif";
+ QTest::newRow("designer_indexed8_with_alpha.gif") << m_loadFromData + "/designer_indexed8_with_alpha.gif";
+ QTest::newRow("designer_rgb32.jpg") << m_loadFromData + "/designer_rgb32.jpg";
}
void tst_QPixmap::loadFromDataImage()
@@ -1378,17 +1381,15 @@ void tst_QPixmap::fromImageReader_data()
{
QTest::addColumn<QString>("imagePath");
- const QString prefix = QFINDTESTDATA("loadFromData");
-
- QTest::newRow("designer_argb32.png") << prefix + "/designer_argb32.png";
- QTest::newRow("designer_indexed8_no_alpha.png") << prefix + "/designer_indexed8_no_alpha.png";
- QTest::newRow("designer_indexed8_with_alpha.png") << prefix + "/designer_indexed8_with_alpha.png";
- QTest::newRow("designer_rgb32.png") << prefix + "/designer_rgb32.png";
- QTest::newRow("designer_indexed8_no_alpha.gif") << prefix + "/designer_indexed8_no_alpha.gif";
- QTest::newRow("designer_indexed8_with_alpha.gif") << prefix + "/designer_indexed8_with_alpha.gif";
- QTest::newRow("designer_rgb32.jpg") << prefix + "/designer_rgb32.jpg";
- QTest::newRow("designer_indexed8_with_alpha_animated") << prefix + "/designer_indexed8_with_alpha_animated.gif";
- QTest::newRow("designer_indexed8_no_alpha_animated") << prefix + "/designer_indexed8_no_alpha_animated.gif";
+ QTest::newRow("designer_argb32.png") << m_loadFromData + "/designer_argb32.png";
+ QTest::newRow("designer_indexed8_no_alpha.png") << m_loadFromData + "/designer_indexed8_no_alpha.png";
+ QTest::newRow("designer_indexed8_with_alpha.png") << m_loadFromData + "/designer_indexed8_with_alpha.png";
+ QTest::newRow("designer_rgb32.png") << m_loadFromData + "/designer_rgb32.png";
+ QTest::newRow("designer_indexed8_no_alpha.gif") << m_loadFromData + "/designer_indexed8_no_alpha.gif";
+ QTest::newRow("designer_indexed8_with_alpha.gif") << m_loadFromData + "/designer_indexed8_with_alpha.gif";
+ QTest::newRow("designer_rgb32.jpg") << m_loadFromData + "/designer_rgb32.jpg";
+ QTest::newRow("designer_indexed8_with_alpha_animated") << m_loadFromData + "/designer_indexed8_with_alpha_animated.gif";
+ QTest::newRow("designer_indexed8_no_alpha_animated") << m_loadFromData + "/designer_indexed8_no_alpha_animated.gif";
}
void tst_QPixmap::fromImageReader()
@@ -1416,8 +1417,7 @@ void tst_QPixmap::fromImageReaderAnimatedGif()
{
QFETCH(QString, imagePath);
- const QString prefix = QFINDTESTDATA("loadFromData");
- const QString path = prefix + imagePath;
+ const QString path = m_loadFromData + imagePath;
QImageReader referenceReader(path);
QImageReader pixmapReader(path);
@@ -1533,14 +1533,12 @@ void tst_QPixmap::scaled_QTBUG19157()
void tst_QPixmap::detachOnLoad_QTBUG29639()
{
- const QString prefix = QFINDTESTDATA("convertFromImage");
-
QPixmap a;
- a.load(prefix + "/task31722_0/img1.png");
- a.load(prefix + "/task31722_0/img2.png");
+ a.load(m_convertFromImage + "/task31722_0/img1.png");
+ a.load(m_convertFromImage + "/task31722_0/img2.png");
QPixmap b;
- b.load(prefix + "/task31722_0/img1.png");
+ b.load(m_convertFromImage + "/task31722_0/img1.png");
QVERIFY(a.toImage() != b.toImage());
}