summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@theqtcompany.com>2015-11-23 07:13:00 +0100
committerLiang Qi <liang.qi@theqtcompany.com>2015-11-23 07:13:00 +0100
commit1ed7a67a4cef8350103e4ea33b4bbd084f5d4c2d (patch)
tree03dd7b6f8d9ccc02da6d0d882793ec62c71b00f7 /tests/auto
parentdbb7817e13bc7f7ccb8f04b00a65eb3dcf8d25f8 (diff)
parent6a2b17eeec2d171d2afa17bdbc36456346bfd13b (diff)
Merge remote-tracking branch 'origin/5.6' into dev
Conflicts: src/corelib/kernel/qcoreapplication.cpp src/corelib/thread/qthread_unix.cpp Change-Id: Ia08d613c3f0bd08cb6dc3e3a57257207dfd4a099
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/gui/image/qimagereader/images/longcomment.pgm12
-rw-r--r--tests/auto/gui/image/qimagereader/tst_qimagereader.cpp1
-rw-r--r--tests/auto/other/compiler/tst_compiler.cpp187
-rw-r--r--tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp13
-rw-r--r--tests/auto/tools/qmake/testdata/findDeps/findDeps.pro2
-rw-r--r--tests/auto/tools/qmake/testdata/findDeps/main.cpp9
-rw-r--r--tests/auto/tools/qmake/testdata/findDeps/needed.cpp1
-rw-r--r--tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp74
8 files changed, 278 insertions, 21 deletions
diff --git a/tests/auto/gui/image/qimagereader/images/longcomment.pgm b/tests/auto/gui/image/qimagereader/images/longcomment.pgm
new file mode 100644
index 0000000000..a5624b6c73
--- /dev/null
+++ b/tests/auto/gui/image/qimagereader/images/longcomment.pgm
@@ -0,0 +1,12 @@
+P2
+# A short comment
+# A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment A very long comment
+24 7
+15
+0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+0 3 3 3 3 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 15 15 15 0
+0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 15 0
+0 3 3 3 0 0 0 7 7 7 0 0 0 11 11 11 0 0 0 15 15 15 15 0
+0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 0 0
+0 3 0 0 0 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 0 0 0 0
+0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
diff --git a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp
index 2eb9b4fc2d..1425ce3c2f 100644
--- a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp
+++ b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp
@@ -224,6 +224,7 @@ void tst_QImageReader::readImage_data()
QTest::newRow("PPM: runners") << QString("runners.ppm") << true << QByteArray("ppm");
QTest::newRow("PPM: test") << QString("test.ppm") << true << QByteArray("ppm");
QTest::newRow("XBM: gnus") << QString("gnus.xbm") << true << QByteArray("xbm");
+ QTest::newRow("PGM: longcomment") << QString("longcomment.pgm") << true << QByteArray("pgm");
QTest::newRow("JPEG: beavis") << QString("beavis.jpg") << true << QByteArray("jpeg");
QTest::newRow("JPEG: qtbug13653") << QString("qtbug13653-no_eoi.jpg") << true << QByteArray("jpeg");
diff --git a/tests/auto/other/compiler/tst_compiler.cpp b/tests/auto/other/compiler/tst_compiler.cpp
index 2c95002cb2..af0fa4682d 100644
--- a/tests/auto/other/compiler/tst_compiler.cpp
+++ b/tests/auto/other/compiler/tst_compiler.cpp
@@ -979,6 +979,20 @@ void tst_Compiler::cxx11_nullptr()
#endif
}
+namespace SomeNamespace {
+class AdlOnly {
+ QVector<int> v;
+public:
+ AdlOnly() : v(5) { std::fill_n(v.begin(), v.size(), 42); }
+
+private:
+ friend QVector<int>::const_iterator begin(const AdlOnly &x) { return x.v.begin(); }
+ friend QVector<int>::const_iterator end(const AdlOnly &x) { return x.v.end(); }
+ friend QVector<int>::iterator begin(AdlOnly &x) { return x.v.begin(); }
+ friend QVector<int>::iterator end(AdlOnly &x) { return x.v.end(); }
+};
+}
+
void tst_Compiler::cxx11_range_for()
{
#ifndef Q_COMPILER_RANGE_FOR
@@ -998,6 +1012,85 @@ void tst_Compiler::cxx11_range_for()
l << 2;
for (int i : ll)
QCOMPARE(i, 2);
+
+ {
+ const int array[] = { 0, 1, 2, 3, 4 };
+ int i = 0;
+ for (const int &e : array)
+ QCOMPARE(e, array[i++]);
+ i = 0;
+ for (int e : array)
+ QCOMPARE(e, array[i++]);
+ i = 0;
+ for (const int e : array)
+ QCOMPARE(e, array[i++]);
+#ifdef Q_COMPILER_AUTO_TYPE
+ i = 0;
+ for (const auto &e : array)
+ QCOMPARE(e, array[i++]);
+ i = 0;
+ for (auto &e : array) // auto deducing const
+ QCOMPARE(e, array[i++]);
+ i = 0;
+ for (auto e : array)
+ QCOMPARE(e, array[i++]);
+ i = 0;
+ for (const auto e : array)
+ QCOMPARE(e, array[i++]);
+#endif
+ }
+
+ {
+ int array[] = { 0, 1, 2, 3, 4 };
+ const int array2[] = { 10, 11, 12, 13, 14 };
+ int i = 0;
+ for (const int &e : array)
+ QCOMPARE(e, array[i++]);
+ i = 0;
+ for (int &e : array)
+ QCOMPARE(e, array[i++]);
+ i = 0;
+ for (int e : array)
+ QCOMPARE(e, array[i++]);
+ i = 0;
+ for (const int e : array)
+ QCOMPARE(e, array[i++]);
+#ifdef Q_COMPILER_AUTO_TYPE
+ i = 0;
+ for (const auto &e : array)
+ QCOMPARE(e, array[i++]);
+ i = 0;
+ for (auto &e : array)
+ QCOMPARE(e, array[i++]);
+ i = 0;
+ for (auto e : array)
+ QCOMPARE(e, array[i++]);
+ i = 0;
+ for (const auto e : array)
+ QCOMPARE(e, array[i++]);
+#endif
+ for (int &e : array)
+ e += 10;
+ i = 0;
+ for (const int &e : array)
+ QCOMPARE(e, array2[i++]);
+ }
+
+ {
+ const SomeNamespace::AdlOnly x;
+ for (const int &e : x)
+ QCOMPARE(e, 42);
+ }
+
+ {
+ SomeNamespace::AdlOnly x;
+ for (const int &e : x)
+ QCOMPARE(e, 42);
+ for (int &e : x)
+ e += 10;
+ for (const int &e : x)
+ QCOMPARE(e, 52);
+ }
#endif
}
@@ -1035,24 +1128,88 @@ void tst_Compiler::cxx11_ref_qualifiers()
#endif
}
+class MoveDefinedQString {
+ QString s;
+public:
+ MoveDefinedQString() : s() {}
+ explicit MoveDefinedQString(const QString &s) : s(s) {}
+ MoveDefinedQString(const MoveDefinedQString &other) : s(other.s) {}
+#ifdef Q_COMPILER_RVALUE_REFS
+ MoveDefinedQString(MoveDefinedQString &&other) : s(std::move(other.s)) { other.s.clear(); }
+ MoveDefinedQString &operator=(MoveDefinedQString &&other)
+ { s = std::move(other.s); other.s.clear(); return *this; }
+#endif
+ MoveDefinedQString &operator=(const MoveDefinedQString &other) { s = other.s; return *this; }
+
+private:
+ friend bool operator==(const MoveDefinedQString &lhs, const MoveDefinedQString &rhs)
+ { return lhs.s == rhs.s; }
+ friend bool operator!=(const MoveDefinedQString &lhs, const MoveDefinedQString &rhs)
+ { return !operator==(lhs, rhs); }
+ friend char* toString(const MoveDefinedQString &mds)
+ { using namespace QTest; return toString(mds.s); }
+};
+
void tst_Compiler::cxx11_rvalue_refs()
{
#ifndef Q_COMPILER_RVALUE_REFS
QSKIP("Compiler does not support C++11 feature");
#else
- int i = 1;
- i = std::move(i);
-
- QString s = "Hello";
- QString t = std::move(s);
- QCOMPARE(t, QString("Hello"));
+ // we require std::move:
+ {
+ int i = 1;
+ i = std::move(i);
+
+ MoveDefinedQString s("Hello");
+ MoveDefinedQString t = std::move(s);
+ QCOMPARE(t, MoveDefinedQString("Hello"));
+ QCOMPARE(s, MoveDefinedQString());
+
+ s = t;
+ t = std::move(s);
+ QCOMPARE(t, MoveDefinedQString("Hello"));
+ QCOMPARE(s, MoveDefinedQString());
+
+ MoveDefinedQString &&r = std::move(t); // no actual move!
+ QCOMPARE(r, MoveDefinedQString("Hello"));
+ QCOMPARE(t, MoveDefinedQString("Hello")); // so 't' is unchanged
+ }
- s = t;
- t = std::move(s);
- QCOMPARE(t, QString("Hello"));
+ // we require std::forward:
+ {
+ MoveDefinedQString s("Hello");
+ MoveDefinedQString s2 = std::forward<MoveDefinedQString>(s); // forward as rvalue
+ QCOMPARE(s2, MoveDefinedQString("Hello"));
+ QCOMPARE(s, MoveDefinedQString());
+
+ MoveDefinedQString s3 = std::forward<MoveDefinedQString&>(s2); // forward as lvalue
+ QCOMPARE(s2, MoveDefinedQString("Hello"));
+ QCOMPARE(s3, MoveDefinedQString("Hello"));
+ }
- QString &&r = std::move(s);
- QCOMPARE(r, QString("Hello"));
+ // supported by MSVC only from November 2013 CTP, but only check for VC2015:
+# if !defined(Q_CC_MSVC) || defined(Q_CC_INTEL) || _MSC_VER >= 1900 // VS14 == VC2015
+ // we require automatic generation of move special member functions:
+ {
+ struct M { MoveDefinedQString s1, s2; };
+ M m1 = { MoveDefinedQString("Hello"), MoveDefinedQString("World") };
+ QCOMPARE(m1.s1, MoveDefinedQString("Hello"));
+ QCOMPARE(m1.s2, MoveDefinedQString("World"));
+ M m2 = std::move(m1);
+ QCOMPARE(m1.s1, MoveDefinedQString());
+ QCOMPARE(m1.s2, MoveDefinedQString());
+ QCOMPARE(m2.s1, MoveDefinedQString("Hello"));
+ QCOMPARE(m2.s2, MoveDefinedQString("World"));
+ M m3;
+ QCOMPARE(m3.s1, MoveDefinedQString());
+ QCOMPARE(m3.s2, MoveDefinedQString());
+ m3 = std::move(m2);
+ QCOMPARE(m2.s1, MoveDefinedQString());
+ QCOMPARE(m2.s2, MoveDefinedQString());
+ QCOMPARE(m3.s1, MoveDefinedQString("Hello"));
+ QCOMPARE(m3.s2, MoveDefinedQString("World"));
+ }
+# endif // MSVC < 2015
#endif
}
@@ -1265,9 +1422,11 @@ void tst_Compiler::cxx14_decltype_auto()
}
#if __cpp_return_type_deduction >= 201304
-auto returnTypeDeduction()
+auto returnTypeDeduction(bool choice)
{
- return 1U;
+ if (choice)
+ return 1U;
+ return returnTypeDeduction(!choice);
}
#endif
@@ -1276,7 +1435,7 @@ void tst_Compiler::cxx14_return_type_deduction()
#if __cpp_return_type_deduction-0 < 201304
QSKIP("Compiler does not support this C++14 feature");
#else
- QCOMPARE(returnTypeDeduction(), 1U);
+ QCOMPARE(returnTypeDeduction(false), 1U);
#endif
}
diff --git a/tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp b/tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp
index ae2f8dde5f..52baa0070b 100644
--- a/tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp
+++ b/tests/auto/sql/models/qsqlquerymodel/tst_qsqlquerymodel.cpp
@@ -593,7 +593,7 @@ public:
connect(this, SIGNAL(modelReset()), this, SLOT(modelResetSlot()));
}
- void testme()
+ void testNested()
{
// Only the outermost beginResetModel/endResetModel should
// emit signals.
@@ -618,6 +618,14 @@ public:
QCOMPARE(gotReset, true);
}
+ void testClear() // QTBUG-49404: Basic test whether clear() emits signals.
+ {
+ gotAboutToBeReset = gotReset = false;
+ clear();
+ QVERIFY(gotAboutToBeReset);
+ QVERIFY(gotReset);
+ }
+
private slots:
void modelAboutToBeResetSlot() { gotAboutToBeReset = true; }
void modelResetSlot() { gotReset = true; }
@@ -634,7 +642,8 @@ void tst_QSqlQueryModel::nestedResets()
CHECK_DATABASE(db);
NestedResetsTest t;
- t.testme();
+ t.testClear();
+ t.testNested();
}
// For task 180617
diff --git a/tests/auto/tools/qmake/testdata/findDeps/findDeps.pro b/tests/auto/tools/qmake/testdata/findDeps/findDeps.pro
index 442c9c767f..2713296f5b 100644
--- a/tests/auto/tools/qmake/testdata/findDeps/findDeps.pro
+++ b/tests/auto/tools/qmake/testdata/findDeps/findDeps.pro
@@ -9,4 +9,4 @@ HEADERS += object1.h \
object7.h \
object8.h \
object9.h
-SOURCES += main.cpp
+SOURCES += main.cpp needed.cpp
diff --git a/tests/auto/tools/qmake/testdata/findDeps/main.cpp b/tests/auto/tools/qmake/testdata/findDeps/main.cpp
index e4aa5c6251..0df3f9b7c3 100644
--- a/tests/auto/tools/qmake/testdata/findDeps/main.cpp
+++ b/tests/auto/tools/qmake/testdata/findDeps/main.cpp
@@ -31,6 +31,9 @@
**
****************************************************************************/
+#define spurious \
+ / #include "needed.cpp"
+// if not ignored, symbol needed() won't be available ...
#include <moc_object1.cpp>
/**/ #include <moc_object2.cpp>
@@ -49,5 +52,7 @@ static void function2(); /**/
static void function3(); //
#include <moc_object9.cpp>
-int main () {}
-
+int main () {
+ extern int needed(void);
+ return needed();
+}
diff --git a/tests/auto/tools/qmake/testdata/findDeps/needed.cpp b/tests/auto/tools/qmake/testdata/findDeps/needed.cpp
new file mode 100644
index 0000000000..698d0aaa12
--- /dev/null
+++ b/tests/auto/tools/qmake/testdata/findDeps/needed.cpp
@@ -0,0 +1 @@
+extern int needed(void) { return 1; }
diff --git a/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp b/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp
index 638fad6206..a4a0045265 100644
--- a/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp
+++ b/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp
@@ -57,6 +57,8 @@ private slots:
void asViewport();
void requestUpdate();
void fboRedirect();
+ void showHide();
+ void nativeWindow();
};
void tst_QOpenGLWidget::create()
@@ -81,7 +83,8 @@ public:
: QOpenGLWidget(parent),
m_initCalled(false), m_paintCalled(false), m_resizeCalled(false),
m_resizeOk(false),
- m_w(expectedWidth), m_h(expectedHeight) { }
+ m_w(expectedWidth), m_h(expectedHeight),
+ r(1.0f), g(0.0f), b(0.0f) { }
void initializeGL() Q_DECL_OVERRIDE {
m_initCalled = true;
@@ -89,13 +92,16 @@ public:
}
void paintGL() Q_DECL_OVERRIDE {
m_paintCalled = true;
- glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
+ glClearColor(r, g, b, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
}
void resizeGL(int w, int h) Q_DECL_OVERRIDE {
m_resizeCalled = true;
m_resizeOk = w == m_w && h == m_h;
}
+ void setClearColor(float r, float g, float b) {
+ this->r = r; this->g = g; this->b = b;
+ }
bool m_initCalled;
bool m_paintCalled;
@@ -103,6 +109,7 @@ public:
bool m_resizeOk;
int m_w;
int m_h;
+ float r, g, b;
};
void tst_QOpenGLWidget::clearAndGrab()
@@ -355,6 +362,69 @@ void tst_QOpenGLWidget::fboRedirect()
QVERIFY(reportedDefaultFbo != widgetFbo);
}
+void tst_QOpenGLWidget::showHide()
+{
+ QScopedPointer<ClearWidget> w(new ClearWidget(0, 800, 600));
+ w->resize(800, 600);
+ w->show();
+ QTest::qWaitForWindowExposed(w.data());
+
+ w->hide();
+
+ QImage image = w->grabFramebuffer();
+ QVERIFY(!image.isNull());
+ QCOMPARE(image.width(), w->width());
+ QCOMPARE(image.height(), w->height());
+ QVERIFY(image.pixel(30, 40) == qRgb(255, 0, 0));
+
+ w->setClearColor(0, 0, 1);
+ w->show();
+ QTest::qWaitForWindowExposed(w.data());
+
+ image = w->grabFramebuffer();
+ QVERIFY(!image.isNull());
+ QCOMPARE(image.width(), w->width());
+ QCOMPARE(image.height(), w->height());
+ QVERIFY(image.pixel(30, 40) == qRgb(0, 0, 255));
+}
+
+void tst_QOpenGLWidget::nativeWindow()
+{
+ QScopedPointer<ClearWidget> w(new ClearWidget(0, 800, 600));
+ w->resize(800, 600);
+ w->show();
+ w->winId();
+ QTest::qWaitForWindowExposed(w.data());
+
+ QImage image = w->grabFramebuffer();
+ QVERIFY(!image.isNull());
+ QCOMPARE(image.width(), w->width());
+ QCOMPARE(image.height(), w->height());
+ QVERIFY(image.pixel(30, 40) == qRgb(255, 0, 0));
+ QVERIFY(w->internalWinId());
+
+ // Now as a native child.
+ QWidget nativeParent;
+ nativeParent.resize(800, 600);
+ nativeParent.setAttribute(Qt::WA_NativeWindow);
+ ClearWidget *child = new ClearWidget(0, 800, 600);
+ child->setClearColor(0, 1, 0);
+ child->setParent(&nativeParent);
+ child->resize(400, 400);
+ child->move(23, 34);
+ nativeParent.show();
+ QTest::qWaitForWindowExposed(&nativeParent);
+
+ QVERIFY(nativeParent.internalWinId());
+ QVERIFY(!child->internalWinId());
+
+ image = child->grabFramebuffer();
+ QVERIFY(!image.isNull());
+ QCOMPARE(image.width(), child->width());
+ QCOMPARE(image.height(), child->height());
+ QVERIFY(image.pixel(30, 40) == qRgb(0, 255, 0));
+}
+
QTEST_MAIN(tst_QOpenGLWidget)
#include "tst_qopenglwidget.moc"