diff options
author | Bradley T. Hughes <bradley.hughes@nokia.com> | 2009-04-16 08:24:47 (GMT) |
---|---|---|
committer | Bradley T. Hughes <bradley.hughes@nokia.com> | 2009-04-16 08:24:47 (GMT) |
commit | ee1e6222114028c2ff181f972e32f15011723b5f (patch) | |
tree | cac3620d648f1a7c6668c7bb3795cb0f4295baf9 /tests | |
parent | cbec6d9481bf8f55834eafac4eca53f85206b240 (diff) | |
parent | d43d33eb3121519d0025ad433d5c186365c47ef6 (diff) | |
download | Qt-ee1e6222114028c2ff181f972e32f15011723b5f.zip Qt-ee1e6222114028c2ff181f972e32f15011723b5f.tar.gz Qt-ee1e6222114028c2ff181f972e32f15011723b5f.tar.bz2 |
Merge branch 'master' of git@scm.dev.nokia.troll.no:qt/qt into windows-7-multitouch
Diffstat (limited to 'tests')
44 files changed, 1587 insertions, 976 deletions
diff --git a/tests/auto/math3d/math3d.pro b/tests/auto/math3d/math3d.pro index 3977e92..d6189ef 100644 --- a/tests/auto/math3d/math3d.pro +++ b/tests/auto/math3d/math3d.pro @@ -1,3 +1,2 @@ TEMPLATE = subdirs -SUBDIRS = qfixedpt qmatrixnxn qquaternion qvectornd -SUBDIRS += qmatrixnxn_fixed qquaternion_fixed qvectornd_fixed +SUBDIRS = qmatrixnxn qquaternion qvectornd diff --git a/tests/auto/math3d/qfixedpt/qfixedpt.pro b/tests/auto/math3d/qfixedpt/qfixedpt.pro deleted file mode 100644 index 94598b5..0000000 --- a/tests/auto/math3d/qfixedpt/qfixedpt.pro +++ /dev/null @@ -1,2 +0,0 @@ -load(qttest_p4) -SOURCES += tst_qfixedpt.cpp diff --git a/tests/auto/math3d/qfixedpt/tst_qfixedpt.cpp b/tests/auto/math3d/qfixedpt/tst_qfixedpt.cpp deleted file mode 100644 index ef333a6..0000000 --- a/tests/auto/math3d/qfixedpt/tst_qfixedpt.cpp +++ /dev/null @@ -1,643 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the $MODULE$ of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include <QtCore/qmath.h> -#include <QtGui/qfixedpt.h> - -class tst_QFixedPt : public QObject -{ - Q_OBJECT -public: - tst_QFixedPt() {} - ~tst_QFixedPt() {} - -private slots: - void create_data(); - void create(); - void add_data(); - void add(); - void sub_data(); - void sub(); - void mul_data(); - void mul(); - void div_data(); - void div(); - void neg_data(); - void neg(); - void shift_data(); - void shift(); - void sqrt_data(); - void sqrt(); - void round_data(); - void round(); - void compare_data(); - void compare(); -}; - -// qFuzzyCompare isn't quite "fuzzy" enough to handle conversion -// to fixed-point and back again. So create a "fuzzier" compare. -static bool fuzzyCompare(double x, double y) -{ - double diff = x - y; - if (diff < 0.0f) - diff = -diff; - return (diff < 0.0001); -} - -// Test the creation of QFixedPt values in various ways. -void tst_QFixedPt::create_data() -{ - QTest::addColumn<int>("value"); - QTest::addColumn<int>("intValue"); - QTest::addColumn<float>("realValue"); - - QTest::newRow("zero") << 0x00000000 << 0 << 0.0f; - QTest::newRow("one") << 0x00010000 << 1 << 1.0f; - QTest::newRow("1.5") << 0x00018000 << 2 << 1.5f; // int rounds up - QTest::newRow("-1.5") << (int)0xFFFE8000 << -1 << -1.5f; // int rounds up - QTest::newRow("-7") << (int)0xFFF90000 << -7 << -7.0f; -} -void tst_QFixedPt::create() -{ - QFETCH(int, value); - QFETCH(int, intValue); - QFETCH(float, realValue); - - if (qFloor(realValue) == realValue) { - QFixedPt<16> ivalue(intValue); - QCOMPARE(ivalue.bits(), value); - QCOMPARE(ivalue.toInt(), intValue); - QCOMPARE(ivalue.toReal(), (qreal)realValue); - } - - QFixedPt<16> fvalue(realValue); - QCOMPARE(fvalue.bits(), value); - QCOMPARE(fvalue.toInt(), intValue); - QCOMPARE(fvalue.toReal(), (qreal)realValue); - - QFixedPt<16> fpvalue; - fpvalue.setBits(value); - QCOMPARE(fpvalue.bits(), value); - QCOMPARE(fpvalue.toInt(), intValue); - QCOMPARE(fpvalue.toReal(), (qreal)realValue); - - QFixedPt<16> fpvalue2(fpvalue); - QCOMPARE(fpvalue2.bits(), value); - QCOMPARE(fpvalue2.toInt(), intValue); - QCOMPARE(fpvalue2.toReal(), (qreal)realValue); - - if (qFloor(realValue) == realValue) { - QFixedPt<16> ivalue2(63); // Initialize the something else. - ivalue2 = intValue; // Then change the value. - QCOMPARE(ivalue2.bits(), value); - QCOMPARE(ivalue2.toInt(), intValue); - QCOMPARE(ivalue2.toReal(), (qreal)realValue); - } - - QFixedPt<16> fvalue2(36); - fvalue2 = realValue; - QCOMPARE(fvalue2.bits(), value); - QCOMPARE(fvalue2.toInt(), intValue); - QCOMPARE(fvalue2.toReal(), (qreal)realValue); - - QFixedPt<16> fpvalue3; - fpvalue3 = fpvalue; - QCOMPARE(fpvalue3.bits(), value); - QCOMPARE(fpvalue3.toInt(), intValue); - QCOMPARE(fpvalue3.toReal(), (qreal)realValue); - - // Now do some of the tests again with a different precision value. - - if (qFloor(realValue) == realValue) { - QFixedPt<4> ivalue3(intValue); - QCOMPARE(ivalue3.bits(), value >> 12); - QCOMPARE(ivalue3.toInt(), intValue); - QCOMPARE(ivalue3.toReal(), (qreal)realValue); - } - - QFixedPt<4> fvalue3(realValue); - QCOMPARE(fvalue3.bits(), value >> 12); - QCOMPARE(fvalue3.toInt(), intValue); - QCOMPARE(fvalue3.toReal(), (qreal)realValue); - - QFixedPt<4> fpvalue4; - fpvalue4.setBits(value >> 12); - QCOMPARE(fpvalue4.bits(), value >> 12); - QCOMPARE(fpvalue4.toInt(), intValue); - QCOMPARE(fpvalue4.toReal(), (qreal)realValue); - - // Test conversion between the precision values. - -#if !defined(QT_NO_MEMBER_TEMPLATES) - if (qFloor(realValue) == realValue) { - QFixedPt<16> ivalue(intValue); - QFixedPt<4> ivalue3(intValue); - QVERIFY(ivalue.toPrecision<4>() == ivalue3); - QVERIFY(ivalue3.toPrecision<16>() == ivalue); - } - QVERIFY(fvalue.toPrecision<4>() == fvalue3); - QVERIFY(fvalue3.toPrecision<16>() == fvalue); -#endif - - if (qFloor(realValue) == realValue) { - QFixedPt<16> ivalue(intValue); - QFixedPt<4> ivalue3(intValue); - QVERIFY(qFixedPtToPrecision<4>(ivalue) == ivalue3); - QVERIFY(qFixedPtToPrecision<16>(ivalue3) == ivalue); - } - QVERIFY(qFixedPtToPrecision<4>(fvalue) == fvalue3); - QVERIFY(qFixedPtToPrecision<16>(fvalue3) == fvalue); -} - -// Test fixed point addition. -void tst_QFixedPt::add_data() -{ - QTest::addColumn<float>("a"); - QTest::addColumn<float>("b"); - - QTest::newRow("zero") << 0.0f << 0.0f; - QTest::newRow("test1") << 1.0f << 0.0f; - QTest::newRow("test2") << 0.0f << 1.0f; - QTest::newRow("test3") << 10.0f << -3.0f; - QTest::newRow("test4") << 10.5f << 3.25f; -} -void tst_QFixedPt::add() -{ - QFETCH(float, a); - QFETCH(float, b); - - QFixedPt<16> avalue(a); - QFixedPt<16> bvalue(b); - - QFixedPt<16> cvalue = avalue + bvalue; - QFixedPt<16> dvalue = a + bvalue; - QFixedPt<16> evalue = avalue + b; - - QCOMPARE(cvalue.toReal(), (qreal)(a + b)); - QCOMPARE(dvalue.toReal(), (qreal)(a + b)); - QCOMPARE(evalue.toReal(), (qreal)(a + b)); - - QFixedPt<16> fvalue(avalue); - fvalue += bvalue; - QCOMPARE(fvalue.toReal(), (qreal)(a + b)); - - QFixedPt<16> gvalue(avalue); - gvalue += b; - QCOMPARE(gvalue.toReal(), (qreal)(a + b)); - - if (qFloor(a) == a && qFloor(b) == b) { - QFixedPt<16> hvalue = int(a) + bvalue; - QFixedPt<16> ivalue = avalue + int(b); - - QCOMPARE(hvalue.toInt(), int(a) + int(b)); - QCOMPARE(ivalue.toInt(), int(a) + int(b)); - QCOMPARE(hvalue.toReal(), (qreal)(a + b)); - QCOMPARE(ivalue.toReal(), (qreal)(a + b)); - - QFixedPt<16> jvalue(avalue); - jvalue += int(b); - QCOMPARE(jvalue.toReal(), (qreal)(a + b)); - } -} - -// Test fixed point subtraction. -void tst_QFixedPt::sub_data() -{ - // Use the same test data as the add() test. - add_data(); -} -void tst_QFixedPt::sub() -{ - QFETCH(float, a); - QFETCH(float, b); - - QFixedPt<16> avalue(a); - QFixedPt<16> bvalue(b); - - QFixedPt<16> cvalue = avalue - bvalue; - QFixedPt<16> dvalue = a - bvalue; - QFixedPt<16> evalue = avalue - b; - - QCOMPARE(cvalue.toReal(), (qreal)(a - b)); - QCOMPARE(dvalue.toReal(), (qreal)(a - b)); - QCOMPARE(evalue.toReal(), (qreal)(a - b)); - - QFixedPt<16> fvalue(avalue); - fvalue -= bvalue; - QCOMPARE(fvalue.toReal(), (qreal)(a - b)); - - QFixedPt<16> gvalue(avalue); - gvalue -= b; - QCOMPARE(gvalue.toReal(), (qreal)(a - b)); - - if (qFloor(a) == a && qFloor(b) == b) { - QFixedPt<16> hvalue = int(a) - bvalue; - QFixedPt<16> ivalue = avalue - int(b); - - QCOMPARE(hvalue.toInt(), int(a) - int(b)); - QCOMPARE(ivalue.toInt(), int(a) - int(b)); - QCOMPARE(hvalue.toReal(), (qreal)(a - b)); - QCOMPARE(ivalue.toReal(), (qreal)(a - b)); - - QFixedPt<16> jvalue(avalue); - jvalue -= int(b); - QCOMPARE(jvalue.toReal(), (qreal)(a - b)); - } -} - -// Test fixed point multiplication. -void tst_QFixedPt::mul_data() -{ - // Use the same test data as the add() test. - add_data(); -} -void tst_QFixedPt::mul() -{ - QFETCH(float, a); - QFETCH(float, b); - - QFixedPt<16> avalue(a); - QFixedPt<16> bvalue(b); - - QFixedPt<16> cvalue = avalue * bvalue; - QFixedPt<16> dvalue = a * bvalue; - QFixedPt<16> evalue = avalue * b; - - QCOMPARE(cvalue.toReal(), (qreal)(a * b)); - QCOMPARE(dvalue.toReal(), (qreal)(a * b)); - QCOMPARE(evalue.toReal(), (qreal)(a * b)); - - QFixedPt<16> fvalue(avalue); - fvalue *= bvalue; - QCOMPARE(fvalue.toReal(), (qreal)(a * b)); - - QFixedPt<16> gvalue(avalue); - gvalue *= b; - QCOMPARE(gvalue.toReal(), (qreal)(a * b)); - - if (qFloor(a) == a && qFloor(b) == b) { - QFixedPt<16> hvalue = int(a) * bvalue; - QFixedPt<16> ivalue = avalue * int(b); - - QCOMPARE(hvalue.toInt(), int(a) * int(b)); - QCOMPARE(ivalue.toInt(), int(a) * int(b)); - QCOMPARE(hvalue.toReal(), (qreal)(a * b)); - QCOMPARE(ivalue.toReal(), (qreal)(a * b)); - - QFixedPt<16> jvalue(avalue); - jvalue *= int(b); - QCOMPARE(jvalue.toReal(), (qreal)(a * b)); - } -} - -// Test fixed point division. -void tst_QFixedPt::div_data() -{ - // Use the same test data as the add() test. - add_data(); -} -void tst_QFixedPt::div() -{ - QFETCH(float, a); - QFETCH(float, b); - - QFixedPt<16> avalue(a); - QFixedPt<16> bvalue(b); - - qreal result; - if (b == 0.0f) - result = 0.0f; // Divide by zero results in zero. - else - result = a / b; - - QFixedPt<16> cvalue = avalue / bvalue; - QFixedPt<16> dvalue = a / bvalue; - QFixedPt<16> evalue = avalue / b; - - QVERIFY(fuzzyCompare(cvalue.toReal(), result)); - QVERIFY(fuzzyCompare(dvalue.toReal(), result)); - QVERIFY(fuzzyCompare(evalue.toReal(), result)); - - QFixedPt<16> fvalue(avalue); - fvalue /= bvalue; - QVERIFY(fuzzyCompare(fvalue.toReal(), result)); - - QFixedPt<16> gvalue(avalue); - gvalue /= b; - QVERIFY(fuzzyCompare(gvalue.toReal(), result)); - - if (qFloor(a) == a && qFloor(b) == b) { - QFixedPt<16> hvalue = int(a) / bvalue; - QFixedPt<16> ivalue = avalue / int(b); - - QCOMPARE(hvalue.toInt(), int(result)); - QCOMPARE(ivalue.toInt(), int(result)); - QVERIFY(fuzzyCompare(hvalue.toReal(), result)); - QVERIFY(fuzzyCompare(ivalue.toReal(), result)); - - QFixedPt<16> jvalue(avalue); - jvalue /= int(b); - QVERIFY(fuzzyCompare(jvalue.toReal(), result)); - } -} - -// Test fixed point negation. -void tst_QFixedPt::neg_data() -{ - // Use the same test data as the add() test. - add_data(); -} -void tst_QFixedPt::neg() -{ - QFETCH(float, a); - QFETCH(float, b); - - QFixedPt<16> avalue(a); - QFixedPt<16> bvalue(b); - - QFixedPt<16> cvalue = -avalue; - QCOMPARE(cvalue.bits(), -avalue.bits()); - QCOMPARE(cvalue.toInt(), int(-a)); - QCOMPARE(cvalue.toReal(), (qreal)-a); - - QFixedPt<16> dvalue = -bvalue; - QCOMPARE(dvalue.bits(), -bvalue.bits()); - QCOMPARE(dvalue.toInt(), int(-b)); - QCOMPARE(dvalue.toReal(), (qreal)-b); -} - -// Test left and right shift operators on fixed point values. -void tst_QFixedPt::shift_data() -{ - QTest::addColumn<float>("a"); - QTest::addColumn<int>("amount"); - - QTest::newRow("zero") << 0.0f << 5; - QTest::newRow("one") << 1.0f << 4; - QTest::newRow("-1.75") << -1.75f << 4; -} -void tst_QFixedPt::shift() -{ - QFETCH(float, a); - QFETCH(int, amount); - - int lresult = int((a * 65536.0) * (1 << amount)); - int rresult = int((a * 65536.0) / (1 << amount)); - - QFixedPt<16> avalue(a); - avalue <<= amount; - QCOMPARE(avalue.bits(), lresult); - - QFixedPt<16> bvalue(a); - bvalue >>= amount; - QCOMPARE(bvalue.bits(), rresult); - - QFixedPt<16> cvalue(a); - - QFixedPt<16> dvalue; - dvalue = cvalue << amount; - QCOMPARE(dvalue.bits(), lresult); - - QFixedPt<16> evalue; - evalue = cvalue >> amount; - QCOMPARE(evalue.bits(), rresult); -} - -// Test fixed point square root. -void tst_QFixedPt::sqrt_data() -{ - QTest::addColumn<float>("a"); - - QTest::newRow("zero") << 0.0f; - QTest::newRow("one") << 1.0f; - QTest::newRow("two") << 2.0f; - QTest::newRow("sixteen") << 16.0f; - QTest::newRow("1.5") << 1.5f; -} -void tst_QFixedPt::sqrt() -{ - QFETCH(float, a); - - QFixedPt<16> avalue(a); - QVERIFY(fuzzyCompare(avalue.sqrt().toReal(), qSqrt(a))); - QVERIFY(fuzzyCompare(avalue.sqrtF(), qSqrt(a))); -} - -// Test fixed point rounding. -void tst_QFixedPt::round_data() -{ - QTest::addColumn<float>("a"); - QTest::addColumn<int>("rounded"); - QTest::addColumn<int>("ceiling"); - QTest::addColumn<int>("flooring"); - QTest::addColumn<int>("truncated"); - - QTest::newRow("zero") << 0.0f << 0 << 0 << 0 << 0; - QTest::newRow("test1") << 1.0f << 1 << 1 << 1 << 1; - QTest::newRow("test2") << 2.5f << 3 << 3 << 2 << 2; - QTest::newRow("test3") << 2.3f << 2 << 3 << 2 << 2; - QTest::newRow("test4") << -2.5f << -2 << -2 << -3 << -3; - QTest::newRow("test5") << -2.3f << -2 << -2 << -3 << -3; - QTest::newRow("test6") << -2.7f << -3 << -2 << -3 << -3; -} -void tst_QFixedPt::round() -{ - QFETCH(float, a); - QFETCH(int, rounded); - QFETCH(int, ceiling); - QFETCH(int, flooring); - QFETCH(int, truncated); - - QFixedPt<16> avalue(a); - QVERIFY(avalue.round() == rounded); - QVERIFY(avalue.ceil() == ceiling); - QVERIFY(avalue.floor() == flooring); - QVERIFY(avalue.truncate() == truncated); - - QCOMPARE(qRound(avalue), rounded); - QCOMPARE(qCeil(avalue), ceiling); - QCOMPARE(qFloor(avalue), flooring); -} - -// Test comparison operators. -void tst_QFixedPt::compare_data() -{ - QTest::addColumn<float>("a"); - QTest::addColumn<float>("b"); - - QTest::newRow("test1") << 0.0f << 0.0f; - QTest::newRow("test2") << 1.0f << 0.0f; - QTest::newRow("test3") << 2.5f << 2.5f; - QTest::newRow("test4") << 2.5f << -2.5f; - QTest::newRow("test5") << -2.5f << 2.5f; -} -void tst_QFixedPt::compare() -{ - QFETCH(float, a); - QFETCH(float, b); - - QFixedPt<16> avalue(a); - QFixedPt<16> bvalue(b); - - if (a == b) { - QVERIFY(avalue == bvalue); - QVERIFY(avalue == b); - QVERIFY(a == bvalue); - QVERIFY(!(avalue != bvalue)); - QVERIFY(!(avalue != b)); - QVERIFY(!(a != bvalue)); - QVERIFY(!(avalue < bvalue)); - QVERIFY(!(avalue < b)); - QVERIFY(!(a < bvalue)); - QVERIFY(!(avalue > bvalue)); - QVERIFY(!(avalue > b)); - QVERIFY(!(a > bvalue)); - QVERIFY(avalue <= bvalue); - QVERIFY(avalue <= b); - QVERIFY(a <= bvalue); - QVERIFY(avalue >= bvalue); - QVERIFY(avalue >= b); - QVERIFY(a >= bvalue); - if (qFloor(a) == a) { - QVERIFY(int(a) == bvalue); - QVERIFY(!(int(a) != bvalue)); - QVERIFY(!(int(a) < bvalue)); - QVERIFY(!(int(a) > bvalue)); - QVERIFY(int(a) <= bvalue); - QVERIFY(int(a) >= bvalue); - } - if (qFloor(b) == b) { - QVERIFY(avalue == int(b)); - QVERIFY(!(avalue != int(b))); - QVERIFY(!(avalue < int(b))); - QVERIFY(!(avalue > int(b))); - QVERIFY(avalue <= int(b)); - QVERIFY(avalue >= int(b)); - } - } - - if (a != b) { - QVERIFY(avalue != bvalue); - QVERIFY(avalue != b); - QVERIFY(a != bvalue); - QVERIFY(!(avalue == bvalue)); - QVERIFY(!(avalue == b)); - QVERIFY(!(a == bvalue)); - if (qFloor(a) == a) { - QVERIFY(int(a) != bvalue); - QVERIFY(!(int(a) == bvalue)); - } - if (qFloor(b) == b) { - QVERIFY(avalue != int(b)); - QVERIFY(!(avalue == int(b))); - } - } - - if (a < b) { - QVERIFY(avalue < bvalue); - QVERIFY(avalue < b); - QVERIFY(a < bvalue); - QVERIFY(!(avalue >= bvalue)); - QVERIFY(!(avalue >= b)); - QVERIFY(!(a >= bvalue)); - QVERIFY(!(avalue > bvalue)); - QVERIFY(!(avalue > b)); - QVERIFY(!(a > bvalue)); - QVERIFY(avalue <= bvalue); - QVERIFY(avalue <= b); - QVERIFY(a <= bvalue); - QVERIFY(!(avalue >= bvalue)); - QVERIFY(!(avalue >= b)); - QVERIFY(!(a >= bvalue)); - if (qFloor(a) == a) { - QVERIFY(int(a) < bvalue); - QVERIFY(!(int(a) >= bvalue)); - QVERIFY(!(int(a) > bvalue)); - QVERIFY(int(a) <= bvalue); - } - if (qFloor(b) == b) { - QVERIFY(avalue < int(b)); - QVERIFY(!(avalue >= int(b))); - QVERIFY(!(avalue > int(b))); - QVERIFY(avalue <= int(b)); - } - } - - if (a > b) { - QVERIFY(avalue > bvalue); - QVERIFY(avalue > b); - QVERIFY(a > bvalue); - QVERIFY(!(avalue <= bvalue)); - QVERIFY(!(avalue <= b)); - QVERIFY(!(a <= bvalue)); - QVERIFY(!(avalue < bvalue)); - QVERIFY(!(avalue < b)); - QVERIFY(!(a < bvalue)); - QVERIFY(avalue >= bvalue); - QVERIFY(avalue >= b); - QVERIFY(a >= bvalue); - QVERIFY(!(avalue <= bvalue)); - QVERIFY(!(avalue <= b)); - QVERIFY(!(a <= bvalue)); - if (qFloor(a) == a) { - QVERIFY(int(a) > bvalue); - QVERIFY(!(int(a) <= bvalue)); - QVERIFY(!(int(a) < bvalue)); - QVERIFY(int(a) >= bvalue); - } - if (qFloor(b) == b) { - QVERIFY(avalue > int(b)); - QVERIFY(!(avalue <= int(b))); - QVERIFY(!(avalue < int(b))); - QVERIFY(avalue >= int(b)); - } - } - - if (qFuzzyCompare(a, b)) - QVERIFY(qFuzzyCompare(avalue, bvalue)); - else - QVERIFY(!qFuzzyCompare(avalue, bvalue)); -} - -QTEST_APPLESS_MAIN(tst_QFixedPt) - -#include "tst_qfixedpt.moc" diff --git a/tests/auto/math3d/qmatrixnxn/tst_qmatrixnxn.cpp b/tests/auto/math3d/qmatrixnxn/tst_qmatrixnxn.cpp index 8a7dd49..bb510fc 100644 --- a/tests/auto/math3d/qmatrixnxn/tst_qmatrixnxn.cpp +++ b/tests/auto/math3d/qmatrixnxn/tst_qmatrixnxn.cpp @@ -321,7 +321,7 @@ void tst_QMatrix::setMatrix(QMatrix4x3& m, const qreal *values) // to be in row-major order. This sets the values using fixed-point. void tst_QMatrix::setMatrixFixed(QMatrix2x2& m, const qreal *values) { - qrealinner *data = m.data(); + float *data = m.data(); for (int row = 0; row < 2; ++row) { for (int col = 0; col < 2; ++col) { data[row + col * 2] = values[row * 2 + col]; @@ -330,7 +330,7 @@ void tst_QMatrix::setMatrixFixed(QMatrix2x2& m, const qreal *values) } void tst_QMatrix::setMatrixFixed(QMatrix3x3& m, const qreal *values) { - qrealinner *data = m.data(); + float *data = m.data(); for (int row = 0; row < 3; ++row) { for (int col = 0; col < 3; ++col) { data[row + col * 3] = values[row * 3 + col]; @@ -339,7 +339,7 @@ void tst_QMatrix::setMatrixFixed(QMatrix3x3& m, const qreal *values) } void tst_QMatrix::setMatrixFixed(QMatrix4x4& m, const qreal *values) { - qrealinner *data = m.data(); + float *data = m.data(); for (int row = 0; row < 4; ++row) { for (int col = 0; col < 4; ++col) { data[row + col * 4] = values[row * 4 + col]; @@ -348,7 +348,7 @@ void tst_QMatrix::setMatrixFixed(QMatrix4x4& m, const qreal *values) } void tst_QMatrix::setMatrixFixed(QMatrix4x3& m, const qreal *values) { - qrealinner *data = m.data(); + float *data = m.data(); for (int row = 0; row < 3; ++row) { for (int col = 0; col < 4; ++col) { data[row + col * 3] = values[row * 4 + col]; @@ -365,15 +365,6 @@ static bool fuzzyCompare(float x, float y, qreal epsilon = 0.001) diff = -diff; return (diff < epsilon); } -#ifdef QT_GL_FIXED_PREFERRED -static bool fuzzyCompareFixed(qrealinner x, int y) -{ - int diff = x.bits() - y; - if (diff < 0) - diff = -diff; - return (diff < 50); -} -#endif static bool fuzzyCompare(const QVector3D &v1, const QVector3D &v2, qreal epsilon = 0.001) { @@ -402,7 +393,7 @@ static bool matrixFuzzyCompare(const QMatrix4x4 &m1, const QMatrix4x4 &m2) // The values are assumed to be specified in row-major order. bool tst_QMatrix::isSame(const QMatrix2x2& m, const qreal *values) { - const qrealinner *mv = m.constData(); + const float *mv = m.constData(); for (int row = 0; row < 2; ++row) { for (int col = 0; col < 2; ++col) { // Check the values using the operator() function. @@ -413,24 +404,17 @@ bool tst_QMatrix::isSame(const QMatrix2x2& m, const qreal *values) // Check the values using direct access, which verifies that the values // are stored internally in column-major order. -#ifdef QT_GL_FIXED_PREFERRED - if (!fuzzyCompareFixed(mv[col * 2 + row], (int)(values[row * 2 + col] * 65536.0))) { - qDebug() << "column fixed-point failure at" << row << col << "actual =" << mv[col * 2 + row] << "expected =" << (int)(values[row * 2 + col] * 65536.0); - return false; - } -#else if (!fuzzyCompare((float)(mv[col * 2 + row]), (float)(values[row * 2 + col]))) { qDebug() << "column floating-point failure at" << row << col << "actual =" << mv[col * 2 + row] << "expected =" << values[row * 2 + col]; return false; } -#endif } } return true; } bool tst_QMatrix::isSame(const QMatrix3x3& m, const qreal *values) { - const qrealinner *mv = m.constData(); + const float *mv = m.constData(); for (int row = 0; row < 3; ++row) { for (int col = 0; col < 3; ++col) { // Check the values using the operator() access function. @@ -441,24 +425,17 @@ bool tst_QMatrix::isSame(const QMatrix3x3& m, const qreal *values) // Check the values using direct access, which verifies that the values // are stored internally in column-major order. -#ifdef QT_GL_FIXED_PREFERRED - if (!fuzzyCompareFixed(mv[col * 3 + row], (int)(values[row * 3 + col] * 65536.0))) { - qDebug() << "column fixed-point failure at" << row << col << "actual =" << mv[col * 3 + row] << "expected =" << (int)(values[row * 3 + col] * 65536.0); - return false; - } -#else if (!fuzzyCompare((float)(mv[col * 3 + row]), (float)(values[row * 3 + col]))) { qDebug() << "column floating-point failure at" << row << col << "actual =" << mv[col * 3 + row] << "expected =" << values[row * 3 + col]; return false; } -#endif } } return true; } bool tst_QMatrix::isSame(const QMatrix4x4& m, const qreal *values) { - const qrealinner *mv = m.constData(); + const float *mv = m.constData(); for (int row = 0; row < 4; ++row) { for (int col = 0; col < 4; ++col) { // Check the values using the operator() access function. @@ -469,24 +446,17 @@ bool tst_QMatrix::isSame(const QMatrix4x4& m, const qreal *values) // Check the values using direct access, which verifies that the values // are stored internally in column-major order. -#ifdef QT_GL_FIXED_PREFERRED - if (!fuzzyCompareFixed(mv[col * 4 + row], (int)(values[row * 4 + col] * 65536.0))) { - qDebug() << "column fixed-point failure at" << row << col << "actual =" << mv[col * 4 + row] << "expected =" << (int)(values[row * 4 + col] * 65536.0); - return false; - } -#else if (!fuzzyCompare((float)(mv[col * 4 + row]), (float)(values[row * 4 + col]))) { qDebug() << "column floating-point failure at" << row << col << "actual =" << mv[col * 4 + row] << "expected =" << values[row * 4 + col]; return false; } -#endif } } return true; } bool tst_QMatrix::isSame(const QMatrix4x3& m, const qreal *values) { - const qrealinner *mv = m.constData(); + const float *mv = m.constData(); for (int row = 0; row < 3; ++row) { for (int col = 0; col < 4; ++col) { // Check the values using the operator() access function. @@ -497,17 +467,10 @@ bool tst_QMatrix::isSame(const QMatrix4x3& m, const qreal *values) // Check the values using direct access, which verifies that the values // are stored internally in column-major order. -#ifdef QT_GL_FIXED_PREFERRED - if (!fuzzyCompareFixed(mv[col * 3 + row], (int)(values[row * 4 + col] * 65536.0))) { - qDebug() << "column fixed-point failure at" << row << col << "actual =" << mv[col * 3 + row] << "expected =" << (int)(values[row * 4 + col] * 65536.0); - return false; - } -#else if (!fuzzyCompare((float)(mv[col * 3 + row]), (float)(values[row * 4 + col]))) { qDebug() << "column floating-point failure at" << row << col << "actual =" << mv[col * 3 + row] << "expected =" << values[row * 4 + col]; return false; } -#endif } } return true; @@ -1333,7 +1296,7 @@ void tst_QMatrix::multiply4x3() QMatrix4x3 m1((const qreal *)m1Values); QMatrix3x4 m2((const qreal *)m2Values); - QGenericMatrix<3, 3, qreal, qrealinner> m4; + QGenericMatrix<3, 3, qreal, float> m4; m4 = m1 * m2; qreal values[9]; m4.toValueArray(values); @@ -2901,11 +2864,7 @@ void tst_QMatrix::extractAxisRotation() m.extractAxisRotation(extractedAngle, extractedAxis); -#ifdef QT_GL_FIXED_PREFERRED - qreal epsilon = 0.003; -#else qreal epsilon = 0.001; -#endif if (angle > 180) { QVERIFY(fuzzyCompare(360.0f - angle, extractedAngle, epsilon)); @@ -2953,11 +2912,7 @@ void tst_QMatrix::extractTranslation() QVector3D vec = rotation.extractTranslation(); -#ifdef QT_GL_FIXED_PREFERRED - qreal epsilon = 0.01; -#else qreal epsilon = 0.001; -#endif QVERIFY(fuzzyCompare(vec.x(), x, epsilon)); QVERIFY(fuzzyCompare(vec.y(), y, epsilon)); @@ -2992,7 +2947,7 @@ enum { // Structure that allows direct access to "flagBits" for testing. struct Matrix4x4 { - qrealinner m[4][4]; + float m[4][4]; int flagBits; }; @@ -3225,24 +3180,6 @@ void tst_QMatrix::fill() QVERIFY(isSame(m2, fillValues4x3)); } -// Force the fixed-point version of the test case to put a -// different test name on the front of failure reports. -class tst_QMatrixFixed : public tst_QMatrix -{ - Q_OBJECT -public: - tst_QMatrixFixed() {} - ~tst_QMatrixFixed() {} -}; - -#ifdef QT_GL_FIXED_PREFERRED - -QTEST_APPLESS_MAIN(tst_QMatrixFixed) - -#else - QTEST_APPLESS_MAIN(tst_QMatrix) -#endif - #include "tst_qmatrixnxn.moc" diff --git a/tests/auto/math3d/qmatrixnxn_fixed/qmatrixnxn_fixed.pro b/tests/auto/math3d/qmatrixnxn_fixed/qmatrixnxn_fixed.pro deleted file mode 100644 index cd1c8fa..0000000 --- a/tests/auto/math3d/qmatrixnxn_fixed/qmatrixnxn_fixed.pro +++ /dev/null @@ -1,8 +0,0 @@ -load(qttest_p4) -VPATH += ../shared -VPATH += ../qmatrixnxn -INCLUDEPATH += ../shared -INCLUDEPATH += ../../../../src/gui/math3d -DEFINES += FIXED_POINT_TESTS -HEADERS += math3dincludes.h -SOURCES += tst_qmatrixnxn.cpp math3dincludes.cpp diff --git a/tests/auto/math3d/qquaternion/tst_qquaternion.cpp b/tests/auto/math3d/qquaternion/tst_qquaternion.cpp index 325cb40..f25f858 100644 --- a/tests/auto/math3d/qquaternion/tst_qquaternion.cpp +++ b/tests/auto/math3d/qquaternion/tst_qquaternion.cpp @@ -88,8 +88,11 @@ private slots: void fromAxisAndAngle_data(); void fromAxisAndAngle(); - void interpolate_data(); - void interpolate(); + void slerp_data(); + void slerp(); + + void nlerp_data(); + void nlerp(); }; // qFuzzyCompare isn't quite "fuzzy" enough to handle conversion @@ -693,7 +696,7 @@ void tst_QQuaternion::fromAxisAndAngle() } // Test spherical interpolation of quaternions. -void tst_QQuaternion::interpolate_data() +void tst_QQuaternion::slerp_data() { QTest::addColumn<qreal>("x1"); QTest::addColumn<qreal>("y1"); @@ -740,7 +743,7 @@ void tst_QQuaternion::interpolate_data() << (qreal)0.5f << (qreal)1.0f << (qreal)2.0f << (qreal)-3.0f << (qreal)-45.0f; } -void tst_QQuaternion::interpolate() +void tst_QQuaternion::slerp() { QFETCH(qreal, x1); QFETCH(qreal, y1); @@ -760,7 +763,7 @@ void tst_QQuaternion::interpolate() QQuaternion q2 = QQuaternion::fromAxisAndAngle(x2, y2, z2, angle2); QQuaternion q3 = QQuaternion::fromAxisAndAngle(x3, y3, z3, angle3); - QQuaternion result = QQuaternion::interpolate(q1, q2, t); + QQuaternion result = QQuaternion::slerp(q1, q2, t); QVERIFY(fuzzyCompare(result.x(), q3.x())); QVERIFY(fuzzyCompare(result.y(), q3.y())); @@ -768,24 +771,60 @@ void tst_QQuaternion::interpolate() QVERIFY(fuzzyCompare(result.scalar(), q3.scalar())); } -// Force the fixed-point version of the test case to put a -// different test name on the front of failure reports. -class tst_QQuaternionFixed : public tst_QQuaternion +// Test normalized linear interpolation of quaternions. +void tst_QQuaternion::nlerp_data() { - Q_OBJECT -public: - tst_QQuaternionFixed() {} - ~tst_QQuaternionFixed() {} -}; + slerp_data(); +} +void tst_QQuaternion::nlerp() +{ + QFETCH(qreal, x1); + QFETCH(qreal, y1); + QFETCH(qreal, z1); + QFETCH(qreal, angle1); + QFETCH(qreal, x2); + QFETCH(qreal, y2); + QFETCH(qreal, z2); + QFETCH(qreal, angle2); + QFETCH(qreal, t); -#ifdef QT_GL_FIXED_PREFERRED + QQuaternion q1 = QQuaternion::fromAxisAndAngle(x1, y1, z1, angle1); + QQuaternion q2 = QQuaternion::fromAxisAndAngle(x2, y2, z2, angle2); -QTEST_APPLESS_MAIN(tst_QQuaternionFixed) + QQuaternion result = QQuaternion::nlerp(q1, q2, t); + + qreal resultx, resulty, resultz, resultscalar; + if (t <= 0.0f) { + resultx = q1.x(); + resulty = q1.y(); + resultz = q1.z(); + resultscalar = q1.scalar(); + } else if (t >= 1.0f) { + resultx = q2.x(); + resulty = q2.y(); + resultz = q2.z(); + resultscalar = q2.scalar(); + } else if (qAbs(angle1 - angle2) <= 180.f) { + resultx = q1.x() * (1 - t) + q2.x() * t; + resulty = q1.y() * (1 - t) + q2.y() * t; + resultz = q1.z() * (1 - t) + q2.z() * t; + resultscalar = q1.scalar() * (1 - t) + q2.scalar() * t; + } else { + // Angle greater than 180 degrees: negate q2. + resultx = q1.x() * (1 - t) - q2.x() * t; + resulty = q1.y() * (1 - t) - q2.y() * t; + resultz = q1.z() * (1 - t) - q2.z() * t; + resultscalar = q1.scalar() * (1 - t) - q2.scalar() * t; + } + + QQuaternion q3 = QQuaternion(resultscalar, resultx, resulty, resultz).normalized(); -#else + QVERIFY(fuzzyCompare(result.x(), q3.x())); + QVERIFY(fuzzyCompare(result.y(), q3.y())); + QVERIFY(fuzzyCompare(result.z(), q3.z())); + QVERIFY(fuzzyCompare(result.scalar(), q3.scalar())); +} QTEST_APPLESS_MAIN(tst_QQuaternion) -#endif - #include "tst_qquaternion.moc" diff --git a/tests/auto/math3d/qquaternion_fixed/qquaternion_fixed.pro b/tests/auto/math3d/qquaternion_fixed/qquaternion_fixed.pro deleted file mode 100644 index a0d5401..0000000 --- a/tests/auto/math3d/qquaternion_fixed/qquaternion_fixed.pro +++ /dev/null @@ -1,8 +0,0 @@ -load(qttest_p4) -VPATH += ../shared -VPATH += ../qquaternion -INCLUDEPATH += ../shared -INCLUDEPATH += ../../../../src/gui/math3d -DEFINES += FIXED_POINT_TESTS -HEADERS += math3dincludes.h -SOURCES += tst_qquaternion.cpp math3dincludes.cpp diff --git a/tests/auto/math3d/qvectornd/tst_qvectornd.cpp b/tests/auto/math3d/qvectornd/tst_qvectornd.cpp index 83bacdf..a092fb0 100644 --- a/tests/auto/math3d/qvectornd/tst_qvectornd.cpp +++ b/tests/auto/math3d/qvectornd/tst_qvectornd.cpp @@ -2040,24 +2040,6 @@ void tst_QVector::dotProduct4() QCOMPARE(QVector4D::dotProduct(v1, v2), d); } -// Force the fixed-point version of the test case to put a -// different test name on the front of failure reports. -class tst_QVectorFixed : public tst_QVector -{ - Q_OBJECT -public: - tst_QVectorFixed() {} - ~tst_QVectorFixed() {} -}; - -#ifdef QT_GL_FIXED_PREFERRED - -QTEST_APPLESS_MAIN(tst_QVectorFixed) - -#else - QTEST_APPLESS_MAIN(tst_QVector) -#endif - #include "tst_qvectornd.moc" diff --git a/tests/auto/math3d/qvectornd_fixed/qvectornd_fixed.pro b/tests/auto/math3d/qvectornd_fixed/qvectornd_fixed.pro deleted file mode 100644 index a667fcc..0000000 --- a/tests/auto/math3d/qvectornd_fixed/qvectornd_fixed.pro +++ /dev/null @@ -1,8 +0,0 @@ -load(qttest_p4) -VPATH += ../shared -VPATH += ../qvectornd -INCLUDEPATH += ../shared -INCLUDEPATH += ../../../../src/gui/math3d -DEFINES += FIXED_POINT_TESTS -HEADERS += math3dincludes.h -SOURCES += tst_qvectornd.cpp math3dincludes.cpp diff --git a/tests/auto/math3d/shared/math3dincludes.cpp b/tests/auto/math3d/shared/math3dincludes.cpp deleted file mode 100644 index 725079d..0000000 --- a/tests/auto/math3d/shared/math3dincludes.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the $MODULE$ of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain -** additional rights. These rights are described in the Nokia Qt LGPL -** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "math3dincludes.h" - -#if defined(FIXED_POINT_TESTS) - -#include "qmatrix4x4.cpp" -#include "qgenericmatrix.cpp" -#include "qvector2d.cpp" -#include "qvector3d.cpp" -#include "qvector4d.cpp" -#include "qquaternion.cpp" -#include "qmath3dutil.cpp" - -#endif diff --git a/tests/auto/math3d/shared/math3dincludes.h b/tests/auto/math3d/shared/math3dincludes.h index 23b0f16..1ac0c08 100644 --- a/tests/auto/math3d/shared/math3dincludes.h +++ b/tests/auto/math3d/shared/math3dincludes.h @@ -42,41 +42,6 @@ #ifndef MATH3DINCLUDES_H #define MATH3DINCLUDES_H -#if defined(FIXED_POINT_TESTS) - -// Rename the classes we want to test in fixed-point mode so that -// they don't conflict with the ones that are built into Qt. -#define QT_NO_GL_FLOAT 1 -#define QVector2D tst_QVector2D -#define QVector3D tst_QVector3D -#define QVector4D tst_QVector4D -#define QQuaternion tst_QQuaternionX -#define QMatrix2x2 tst_QMatrix2x2 -#define QMatrix3x3 tst_QMatrix3x3 -#define QMatrix4x4 tst_QMatrix4x4 -#define QMatrix2x3 tst_QMatrix2x3 -#define QMatrix2x4 tst_QMatrix2x4 -#define QMatrix3x2 tst_QMatrix3x2 -#define QMatrix3x4 tst_QMatrix3x4 -#define QMatrix4x2 tst_QMatrix4x2 -#define QMatrix4x3 tst_QMatrix4x3 -#define QGenericMatrix tst_QGenericMatrix -#define qt_math3d_sincos tst_qt_math3d_sincos -#define qt_math3d_convert tst_qt_math3d_convert -#define qrealinner tst_qrealinner - -// We need to re-include the headers with the changed class names. -#undef QGENERICMATRIX_H -#undef QMATH3DGLOBAL_H -#undef QMATH3DUTIL_P_H -#undef QMATRIX4X4_H -#undef QQUATERNION_H -#undef QVECTOR2D_H -#undef QVECTOR3D_H -#undef QVECTOR4D_H - -#endif - #include <QtGui/qmatrix4x4.h> #include <QtGui/qgenericmatrix.h> #include <QtGui/qvector2d.h> diff --git a/tests/auto/mediaobject/tst_mediaobject.cpp b/tests/auto/mediaobject/tst_mediaobject.cpp index 96589b7..e0275de 100644 --- a/tests/auto/mediaobject/tst_mediaobject.cpp +++ b/tests/auto/mediaobject/tst_mediaobject.cpp @@ -787,7 +787,7 @@ void tst_MediaObject::setMediaAndPlay() QSignalSpy totalTimeChangedSignalSpy(m_media, SIGNAL(totalTimeChanged(qint64))); QVERIFY(m_media->currentSource().type() != MediaSource::Invalid); Phonon::State state = m_media->state(); - QVERIFY(state == Phonon::StoppedState || state == Phonon::PlayingState); + QVERIFY(state == Phonon::StoppedState || state == Phonon::PlayingState || Phonon::PausedState); m_media->setCurrentSource(m_url); // before calling play() we better make sure that if play() finishes very fast that we don't get // called again diff --git a/tests/auto/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/qabstractitemview/tst_qabstractitemview.cpp index 3337a49..086c551 100644 --- a/tests/auto/qabstractitemview/tst_qabstractitemview.cpp +++ b/tests/auto/qabstractitemview/tst_qabstractitemview.cpp @@ -53,6 +53,8 @@ #include <qspinbox.h> #include <qitemdelegate.h> #include <qpushbutton.h> +#include <qscrollbar.h> +#include <qboxlayout.h> #include "../../shared/util.h" //TESTED_CLASS= @@ -209,6 +211,7 @@ private slots: void setCurrentIndex(); void task221955_selectedEditor(); + void task250754_fontChange(); }; class MyAbstractItemDelegate : public QAbstractItemDelegate @@ -1179,8 +1182,46 @@ void tst_QAbstractItemView::task221955_selectedEditor() button->setFocus(); QTest::qWait(50); QVERIFY(tree.selectionModel()->selectedIndexes().isEmpty()); +} + +void tst_QAbstractItemView::task250754_fontChange() +{ + QString app_css = qApp->styleSheet(); + qApp->setStyleSheet("/* */"); + + QWidget w; + QTreeView tree(&w); + QVBoxLayout *vLayout = new QVBoxLayout(&w); + vLayout->addWidget(&tree); + + QStandardItemModel *m = new QStandardItemModel(this); + for (int i=0; i<5; ++i) { + QStandardItem *item = new QStandardItem(QString("Item number %1").arg(i)); + for (int j=0; j<5; ++j) { + QStandardItem *child = new QStandardItem(QString("Child Item number %1").arg(j)); + item->setChild(j, 0, child); + } + m->setItem(i, 0, item); + } + tree.setModel(m); + + w.show(); + w.resize(150,150); + QTest::qWait(30); + QFont font = tree.font(); + font.setPointSize(5); + tree.setFont(font); + QTest::qWait(30); + + QVERIFY(!tree.verticalScrollBar()->isVisible()); + + font.setPointSize(45); + tree.setFont(font); + QTest::qWait(30); + //now with the huge items, the scrollbar must be visible + QVERIFY(tree.verticalScrollBar()->isVisible()); - + qApp->setStyleSheet(app_css); } QTEST_MAIN(tst_QAbstractItemView) diff --git a/tests/auto/qaccessibility/tst_qaccessibility.cpp b/tests/auto/qaccessibility/tst_qaccessibility.cpp index d023557..1aca624 100644 --- a/tests/auto/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/qaccessibility/tst_qaccessibility.cpp @@ -275,6 +275,7 @@ private slots: void accessibleName(); void treeWidgetTest(); void labelTest(); + void accelerators(); private: QWidget *createGUI(); @@ -2592,8 +2593,8 @@ void tst_QAccessibility::menuTest() QTestAccessibility::clearEvents(); mw.hide(); - - + + // Do not crash if the menu don't have a parent QMenu *menu = new QMenu; menu->addAction(QLatin1String("one")); @@ -2607,7 +2608,7 @@ void tst_QAccessibility::menuTest() delete iface2; delete iface; delete menu; - + } QTestAccessibility::clearEvents(); #else @@ -3988,13 +3989,13 @@ void tst_QAccessibility::treeWidgetTest() QCOMPARE(entry, 0); QCOMPARE(accTreeItem2->text(QAccessible::Name, 0), QLatin1String("row: 1")); - - // test selected/focused state + + // test selected/focused state QItemSelectionModel *selModel = tree->selectionModel(); QVERIFY(selModel); selModel->select(QItemSelection(tree->model()->index(0, 0), tree->model()->index(3, 0)), QItemSelectionModel::Select); selModel->setCurrentIndex(tree->model()->index(1, 0), QItemSelectionModel::Current); - + for (int i = 1; i < 10 ; ++i) { QAccessible::State expected; if (i <= 5 && i >= 2) @@ -4046,6 +4047,45 @@ void tst_QAccessibility::labelTest() #endif } +void tst_QAccessibility::accelerators() +{ +#ifdef QTEST_ACCESSIBILITY + QWidget *window = new QWidget; + QHBoxLayout *lay = new QHBoxLayout(window); + QLabel *label = new QLabel(tr("&Line edit"), window); + QLineEdit *le = new QLineEdit(window); + lay->addWidget(label); + lay->addWidget(le); + label->setBuddy(le); + + window->show(); + + QAccessibleInterface *accLineEdit = QAccessible::queryAccessibleInterface(le); + QCOMPARE(accLineEdit->text(QAccessible::Accelerator, 0), QString(QKeySequence(Qt::ALT) + QLatin1String("L"))); + label->setText(tr("Q &")); + QCOMPARE(accLineEdit->text(QAccessible::Accelerator, 0), QString()); + label->setText(tr("Q &&")); + QCOMPARE(accLineEdit->text(QAccessible::Accelerator, 0), QString()); + label->setText(tr("Q && A")); + QCOMPARE(accLineEdit->text(QAccessible::Accelerator, 0), QString()); + label->setText(tr("Q &&&A")); + QCOMPARE(accLineEdit->text(QAccessible::Accelerator, 0), QString(QKeySequence(Qt::ALT) + QLatin1String("A"))); + label->setText(tr("Q &&A")); + QCOMPARE(accLineEdit->text(QAccessible::Accelerator, 0), QString()); + label->setText(tr("Q &A&B")); + QCOMPARE(accLineEdit->text(QAccessible::Accelerator, 0), QString(QKeySequence(Qt::ALT) + QLatin1String("A"))); + +#if defined(Q_WS_X11) + qt_x11_wait_for_window_manager(window); +#endif + QTest::qWait(100); + delete window; + QTestAccessibility::clearEvents(); +#else + QSKIP("Test needs Qt >= 0x040000 and accessibility support.", SkipAll); +#endif +} + QTEST_MAIN(tst_QAccessibility) diff --git a/tests/auto/qcolordialog/tst_qcolordialog.cpp b/tests/auto/qcolordialog/tst_qcolordialog.cpp index e51dfcc..1b5babb 100644 --- a/tests/auto/qcolordialog/tst_qcolordialog.cpp +++ b/tests/auto/qcolordialog/tst_qcolordialog.cpp @@ -108,7 +108,7 @@ void tst_QColorDialog::native_activeModalWidget() // color dialog when it is executing, even when using a native // dialog: TestNativeDialog d; - QTimer::singleShot(100, &d, SLOT(hide())); + QTimer::singleShot(1000, &d, SLOT(hide())); d.exec(); QVERIFY(&d == d.m_activeModalWidget); } diff --git a/tests/auto/qcssparser/tst_cssparser.cpp b/tests/auto/qcssparser/tst_cssparser.cpp index 6e277d3..9a984c8 100644 --- a/tests/auto/qcssparser/tst_cssparser.cpp +++ b/tests/auto/qcssparser/tst_cssparser.cpp @@ -272,7 +272,7 @@ void tst_CssParser::term_data() val.variant = QVariant(QColor("#ffbb00")); QTest::newRow("hexcolor2") << true << "#fb0" << val; - QTest::ignoreMessage(QtWarningMsg, "QColor::setNamedColor: Could not parse color '#cafebabe'"); + QTest::ignoreMessage(QtWarningMsg, "QCssParser::parseHexColor: Unknown color name '#cafebabe'"); QTest::newRow("hexcolor_failure") << false << "#cafebabe" << val; val.type = QCss::Value::Uri; diff --git a/tests/auto/qfiledialog/tst_qfiledialog.cpp b/tests/auto/qfiledialog/tst_qfiledialog.cpp index bade586..695bfe7 100644 --- a/tests/auto/qfiledialog/tst_qfiledialog.cpp +++ b/tests/auto/qfiledialog/tst_qfiledialog.cpp @@ -681,6 +681,22 @@ void tst_QFiledialog::filters() for (int i = views.at(0)->currentIndex(); i < views.at(0)->count(); ++i) views.at(0)->setCurrentIndex(i); QCOMPARE(spyFilterSelected.count(), 0); + + //Let check if filters with whitespaces + QNonNativeFileDialog fd2; + QStringList expected; + expected << "C++ Source Files(*.cpp)"; + expected << "Any(*.*)"; + fd2.setFilter("C++ Source Files(*.cpp);;Any(*.*)"); + QCOMPARE(expected, fd2.filters()); + fd2.setFilter("C++ Source Files(*.cpp) ;;Any(*.*)"); + QCOMPARE(expected, fd2.filters()); + fd2.setFilter("C++ Source Files(*.cpp);; Any(*.*)"); + QCOMPARE(expected, fd2.filters()); + fd2.setFilter(" C++ Source Files(*.cpp);; Any(*.*)"); + QCOMPARE(expected, fd2.filters()); + fd2.setFilter("C++ Source Files(*.cpp) ;; Any(*.*)"); + QCOMPARE(expected, fd2.filters()); } void tst_QFiledialog::selectFilter() diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index af40e67..09b209d 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -163,6 +163,8 @@ private slots: void mapFromToParent(); void mapFromToScene(); void mapFromToItem(); + void mapRectFromToParent_data(); + void mapRectFromToParent(); void isAncestorOf(); void commonAncestorItem(); void data(); @@ -221,6 +223,7 @@ private slots: // task specific tests below me void task141694_textItemEnsureVisible(); void task128696_textItemEnsureMovable(); + void ensureUpdateOnTextItem(); void task177918_lineItemUndetected(); void task240400_clickOnTextItem_data(); void task240400_clickOnTextItem(); @@ -2539,6 +2542,87 @@ void tst_QGraphicsItem::mapFromToItem() delete item4; } +void tst_QGraphicsItem::mapRectFromToParent_data() +{ + QTest::addColumn<bool>("parent"); + QTest::addColumn<QPointF>("parentPos"); + QTest::addColumn<QTransform>("parentTransform"); + QTest::addColumn<QPointF>("pos"); + QTest::addColumn<QTransform>("transform"); + QTest::addColumn<QRectF>("inputRect"); + QTest::addColumn<QRectF>("outputRect"); + + QTest::newRow("nil") << false << QPointF() << QTransform() << QPointF() << QTransform() << QRectF() << QRectF(); + QTest::newRow("simple") << false << QPointF() << QTransform() << QPointF() << QTransform() + << QRectF(0, 0, 10, 10) << QRectF(0, 0, 10, 10); + QTest::newRow("simple w/parent") << true + << QPointF() << QTransform() + << QPointF() << QTransform() + << QRectF(0, 0, 10, 10) << QRectF(0, 0, 10, 10); + QTest::newRow("simple w/parent parentPos") << true + << QPointF(50, 50) << QTransform() + << QPointF() << QTransform() + << QRectF(0, 0, 10, 10) << QRectF(0, 0, 10, 10); + QTest::newRow("simple w/parent parentPos parentRotation") << true + << QPointF(50, 50) << QTransform().rotate(45) + << QPointF() << QTransform() + << QRectF(0, 0, 10, 10) << QRectF(0, 0, 10, 10); + QTest::newRow("pos w/parent") << true + << QPointF() << QTransform() + << QPointF(50, 50) << QTransform() + << QRectF(0, 0, 10, 10) << QRectF(50, 50, 10, 10); + QTest::newRow("rotation w/parent") << true + << QPointF() << QTransform() + << QPointF() << QTransform().rotate(90) + << QRectF(0, 0, 10, 10) << QRectF(-10, 0, 10, 10); + QTest::newRow("pos rotation w/parent") << true + << QPointF() << QTransform() + << QPointF(50, 50) << QTransform().rotate(90) + << QRectF(0, 0, 10, 10) << QRectF(40, 50, 10, 10); + QTest::newRow("pos rotation w/parent parentPos parentRotation") << true + << QPointF(-170, -190) << QTransform().rotate(90) + << QPointF(50, 50) << QTransform().rotate(90) + << QRectF(0, 0, 10, 10) << QRectF(40, 50, 10, 10); +} + +void tst_QGraphicsItem::mapRectFromToParent() +{ + QFETCH(bool, parent); + QFETCH(QPointF, parentPos); + QFETCH(QTransform, parentTransform); + QFETCH(QPointF, pos); + QFETCH(QTransform, transform); + QFETCH(QRectF, inputRect); + QFETCH(QRectF, outputRect); + + QGraphicsRectItem *rect = new QGraphicsRectItem; + rect->setPos(pos); + rect->setTransform(transform); + + if (parent) { + QGraphicsRectItem *rectParent = new QGraphicsRectItem; + rect->setParentItem(rectParent); + rectParent->setPos(parentPos); + rectParent->setTransform(parentTransform); + } + + // Make sure we use non-destructive transform operations (e.g., 90 degree + // rotations). + QCOMPARE(rect->mapRectToParent(inputRect), outputRect); + QCOMPARE(rect->mapRectFromParent(outputRect), inputRect); + QCOMPARE(rect->itemTransform(rect->parentItem()).mapRect(inputRect), outputRect); + QCOMPARE(rect->mapToParent(inputRect).boundingRect(), outputRect); + QCOMPARE(rect->mapToParent(QPolygonF(inputRect)).boundingRect(), outputRect); + QCOMPARE(rect->mapFromParent(outputRect).boundingRect(), inputRect); + QCOMPARE(rect->mapFromParent(QPolygonF(outputRect)).boundingRect(), inputRect); + QPainterPath inputPath; + inputPath.addRect(inputRect); + QPainterPath outputPath; + outputPath.addRect(outputRect); + QCOMPARE(rect->mapToParent(inputPath).boundingRect(), outputPath.boundingRect()); + QCOMPARE(rect->mapFromParent(outputPath).boundingRect(), inputPath.boundingRect()); +} + void tst_QGraphicsItem::isAncestorOf() { QGraphicsItem *grandPa = new QGraphicsRectItem; @@ -3956,8 +4040,26 @@ void tst_QGraphicsItem::itemChange() tester.itemSceneChangeTargetScene = 0; tester.itemChangeReturnValue = QVariant(); scene.removeItem(&tester); + ++changeCount; // ItemSceneChange + ++changeCount; // ItemSceneHasChanged QCOMPARE(tester.scene(), (QGraphicsScene *)0); } + { + // ItemToolTipChange/ItemToolTipHasChanged + const QString toolTip(QLatin1String("I'm soo cool")); + const QString overridenToolTip(QLatin1String("No, you are not soo cool")); + tester.itemChangeReturnValue = overridenToolTip; + tester.setToolTip(toolTip); + ++changeCount; // ItemToolTipChange + ++changeCount; // ItemToolTipHasChanged + QCOMPARE(tester.changes.size(), changeCount); + QCOMPARE(tester.changes.at(changeCount - 2), QGraphicsItem::ItemToolTipChange); + QCOMPARE(tester.values.at(changeCount - 2).toString(), toolTip); + QCOMPARE(tester.changes.at(changeCount - 1), QGraphicsItem::ItemToolTipHasChanged); + QCOMPARE(tester.values.at(changeCount - 1).toString(), overridenToolTip); + QCOMPARE(tester.toolTip(), overridenToolTip); + tester.itemChangeReturnValue = QVariant(); + } } class EventFilterTesterItem : public QGraphicsLineItem @@ -4041,6 +4143,25 @@ void tst_QGraphicsItem::sceneEventFilter() QCOMPARE(tester->filteredEventReceivers.at(6), static_cast<QGraphicsItem *>(text2)); QVERIFY(text2->hasFocus()); + + //Let check if the items are correctly removed from the sceneEventFilters array + //to avoid stale pointers. + QGraphicsView gv; + QGraphicsScene *anotherScene = new QGraphicsScene; + QGraphicsTextItem *ti = anotherScene->addText("This is a test #1"); + ti->moveBy(50, 50); + QGraphicsTextItem *ti2 = anotherScene->addText("This is a test #2"); + QGraphicsTextItem *ti3 = anotherScene->addText("This is a test #3"); + gv.setScene(anotherScene); + gv.show(); + QTest::qWait(250); + ti->installSceneEventFilter(ti2); + ti3->installSceneEventFilter(ti); + delete ti2; + //we souldn't crash + QTest::mouseMove(gv.viewport(), gv.mapFromScene(ti->scenePos())); + QTest::qWait(250); + delete ti; } class GeometryChanger : public QGraphicsItem @@ -5174,6 +5295,39 @@ void tst_QGraphicsItem::task240400_clickOnTextItem() QCOMPARE(item->textCursor().columnNumber(), 0); } +class TextItem : public QGraphicsSimpleTextItem +{ +public: + TextItem(const QString& text) : QGraphicsSimpleTextItem(text) + { + updates = 0; + } + + void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) + { + updates++; + QGraphicsSimpleTextItem::paint(painter, option, widget); + } + + int updates; +}; + +void tst_QGraphicsItem::ensureUpdateOnTextItem() +{ + QGraphicsScene scene; + TextItem *text1 = new TextItem(QLatin1String("123")); + scene.addItem(text1); + QGraphicsView view(&scene); + view.show(); + QTest::qWait(250); + QCOMPARE(text1->updates,1); + + //same bouding rect but we have to update + text1->setText(QLatin1String("321")); + QTest::qWait(250); + QCOMPARE(text1->updates,2); +} + void tst_QGraphicsItem::task243707_addChildBeforeParent() { // Task reports that adding the child before the parent leads to an diff --git a/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp index d1d1857..b99f111 100644 --- a/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp +++ b/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp @@ -1475,7 +1475,7 @@ void tst_QGraphicsProxyWidget::scrollUpdate() view.paintEventRegion = QRegion(); view.npaints = 0; QTimer::singleShot(0, widget, SLOT(updateScroll())); - QTest::qWait(500); + QTest::qWait(500); QCOMPARE(view.npaints, 2); // QRect(0, 0, 200, 12) is the first update, expanded (-2, -2, 2, 2) // QRect(0, 12, 102, 10) is the scroll update, expanded (-2, -2, 2, 2), @@ -2582,7 +2582,7 @@ void tst_QGraphicsProxyWidget::childPos() { #ifdef Q_OS_IRIX QSKIP("This test is not reliable on IRIX.", SkipAll); -#endif +#endif QFETCH(bool, moveCombo); QFETCH(QPoint, comboPos); QFETCH(QPointF, proxyPos); @@ -2797,6 +2797,7 @@ void tst_QGraphicsProxyWidget::palettePropagation() void tst_QGraphicsProxyWidget::fontPropagation() { // Construct a font with an unlikely setup + QGraphicsScene scene; QFont lineEditFont = QApplication::font("QLineEdit"); QFont font = lineEditFont; font.setPointSize(43); @@ -2805,6 +2806,7 @@ void tst_QGraphicsProxyWidget::fontPropagation() QGraphicsProxyWidget proxy; proxy.setWidget(edit); + scene.addItem(&proxy); EventSpy editSpy(edit); EventSpy proxySpy(&proxy); @@ -2825,6 +2827,7 @@ void tst_QGraphicsProxyWidget::fontPropagation() // Proxy to widget proxy.setFont(font); + QApplication::processEvents(); // wait for QEvent::Polish QVERIFY(proxy.testAttribute(Qt::WA_SetFont)); QCOMPARE(editSpy.counts[QEvent::FontChange], 3); QCOMPARE(proxySpy.counts[QEvent::FontChange], 1); @@ -2893,7 +2896,7 @@ void tst_QGraphicsProxyWidget::createProxyForChildWidget() edit2->setText("QLineEdit 2"); QCheckBox *checkbox = new QCheckBox("QCheckBox"); QVBoxLayout *vlayout = new QVBoxLayout; - + vlayout->addWidget(edit1); vlayout->addWidget(edit2); vlayout->addWidget(checkbox); @@ -2916,7 +2919,7 @@ void tst_QGraphicsProxyWidget::createProxyForChildWidget() QVERIFY(window.graphicsProxyWidget() == 0); QVERIFY(checkbox->graphicsProxyWidget() == 0); - + QGraphicsProxyWidget *windowProxy = scene.addWidget(&window); QGraphicsView view(&scene); view.show(); @@ -2946,10 +2949,10 @@ void tst_QGraphicsProxyWidget::createProxyForChildWidget() QVERIFY(boxProxy->size() == box->size()); QTest::qWait(10); - + QSignalSpy spy(checkbox, SIGNAL(clicked())); - + QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(checkboxProxy->mapToScene(QPointF(8,8)))); QTRY_COMPARE(spy.count(), 0); @@ -2958,7 +2961,7 @@ void tst_QGraphicsProxyWidget::createProxyForChildWidget() QTRY_COMPARE(spy.count(), 1); - + boxProxy->setWidget(0); QVERIFY(checkbox->graphicsProxyWidget() == 0); @@ -3006,10 +3009,10 @@ void tst_QGraphicsProxyWidget::actionsContextMenu() widget->addAction(new QAction("item 2", widget)); widget->addAction(new QAction("item 3", widget)); widget->setContextMenuPolicy(Qt::ActionsContextMenu); - + QGraphicsScene scene; scene.addWidget(widget); - + QGraphicsView view(&scene); view.show(); #ifdef Q_WS_X11 diff --git a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp index 91ed851..354d81a 100644 --- a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp @@ -245,6 +245,7 @@ private slots: void task139782_containsItemBoundingRect(); void task176178_itemIndexMethodBreaksSceneRect(); void task160653_selectionChanged(); + void task250680_childClip(); }; void tst_QGraphicsScene::initTestCase() @@ -3384,6 +3385,31 @@ void tst_QGraphicsScene::task160653_selectionChanged() QCOMPARE(spy.count(), 1); } +void tst_QGraphicsScene::task250680_childClip() +{ + QGraphicsRectItem *clipper = new QGraphicsRectItem; + clipper->setFlag(QGraphicsItem::ItemClipsChildrenToShape); + clipper->setPen(QPen(Qt::green)); + clipper->setRect(200, 200, 640, 480); + + QGraphicsRectItem *rect = new QGraphicsRectItem(clipper); + rect->setPen(QPen(Qt::red)); + rect->setBrush(QBrush(QColor(255, 0, 0, 75))); + rect->setPos(320, 240); + rect->setRect(-25, -25, 50, 50); + + QGraphicsScene scene; + scene.addItem(clipper); + + QPainterPath path; + path.addRect(-25, -25, 50, 50); + QCOMPARE(rect->clipPath(), path); + + QCOMPARE(scene.items(QRectF(320, 240, 5, 5)).size(), 2); + rect->rotate(45); + QCOMPARE(scene.items(QRectF(320, 240, 5, 5)).size(), 2); +} + void tst_QGraphicsScene::sorting_data() { QTest::addColumn<bool>("cache"); diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp index 4368e76..6b3a9d4 100644 --- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp @@ -155,6 +155,8 @@ private slots: void fitInView(); void itemsAtPoint(); void itemsInRect(); + void itemsInRect_cosmeticAdjust_data(); + void itemsInRect_cosmeticAdjust(); void itemsInPoly(); void itemsInPath(); void itemAt(); @@ -189,6 +191,7 @@ private slots: void scrollAfterResize_data(); void scrollAfterResize(); void centerOnDirtyItem(); + void mouseTracking(); // task specific tests below me void task172231_untransformableItems(); @@ -1310,6 +1313,65 @@ void tst_QGraphicsView::itemsInRect() QCOMPARE(items.takeFirst()->zValue(), qreal(3)); } +class CountPaintItem : public QGraphicsRectItem +{ +public: + int numPaints; + + CountPaintItem(const QRectF &rect) + : QGraphicsRectItem(rect), numPaints(0) + { } + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) + { + ++numPaints; + QGraphicsRectItem::paint(painter, option, widget); + } +}; + +void tst_QGraphicsView::itemsInRect_cosmeticAdjust_data() +{ + QTest::addColumn<QRect>("updateRect"); + QTest::addColumn<int>("numPaints"); + + QTest::newRow("nil") << QRect() << 1; + QTest::newRow("0, 0, 300, 100") << QRect(0, 0, 300, 100) << 1; + QTest::newRow("0, 0, 100, 300") << QRect(0, 0, 100, 300) << 1; + QTest::newRow("200, 0, 100, 300") << QRect(200, 0, 100, 300) << 1; + QTest::newRow("0, 200, 300, 100") << QRect(0, 200, 300, 100) << 1; + QTest::newRow("0, 0, 300, 99") << QRect(0, 0, 300, 99) << 0; + QTest::newRow("0, 0, 99, 300") << QRect(0, 0, 99, 300) << 0; + QTest::newRow("201, 0, 99, 300") << QRect(201, 0, 99, 300) << 0; + QTest::newRow("0, 201, 300, 99") << QRect(0, 201, 300, 99) << 0; +} + +void tst_QGraphicsView::itemsInRect_cosmeticAdjust() +{ + QFETCH(QRect, updateRect); + QFETCH(int, numPaints); + + QGraphicsScene scene(-100, -100, 200, 200); + CountPaintItem *rect = new CountPaintItem(QRectF(-50, -50, 100, 100)); + scene.addItem(rect); + + QGraphicsView view(&scene); + view.setFrameStyle(0); + view.resize(300, 300); + view.show(); +#ifdef Q_WS_X11 + qt_x11_wait_for_window_manager(&view); +#endif + QTest::qWait(125); + + rect->numPaints = 0; + if (updateRect.isNull()) + view.viewport()->update(); + else + view.viewport()->update(updateRect); + qApp->processEvents(); + QCOMPARE(rect->numPaints, numPaints); +} + void tst_QGraphicsView::itemsInPoly() { QGraphicsScene scene; @@ -2454,7 +2516,8 @@ void tst_QGraphicsView::replayMouseMove() // One mouse event should be translated into one scene event. for (int i = 0; i < 3; ++i) { - sendMouseMove(view.viewport(), view.viewport()->rect().center()); + sendMouseMove(view.viewport(), view.viewport()->rect().center(), + Qt::LeftButton, Qt::MouseButtons(Qt::LeftButton)); QCOMPARE(viewSpy.count(), i + 1); QCOMPARE(sceneSpy.count(), i + 1); } @@ -2644,6 +2707,7 @@ void tst_QGraphicsView::task186827_deleteReplayedItem() MouseMoveCounter view; view.setScene(&scene); view.show(); + view.viewport()->setMouseTracking(true); #ifdef Q_WS_X11 qt_x11_wait_for_window_manager(&view); #endif @@ -2987,6 +3051,102 @@ void tst_QGraphicsView::centerOnDirtyItem() QCOMPARE(before, after); } +void tst_QGraphicsView::mouseTracking() +{ + // Mouse tracking should only be automatically enabled if items either accept hover events + // or have a cursor set. We never disable mouse tracking if it is already enabled. + + { // Make sure mouse tracking is disabled by default. + QGraphicsScene scene(-10000, -10000, 20000, 20000); + QGraphicsView view(&scene); + QVERIFY(!view.viewport()->hasMouseTracking()); + } + + { // Make sure we don't disable mouse tracking in setupViewport/setScene. + QGraphicsView view; + QWidget *viewport = new QWidget; + viewport->setMouseTracking(true); + view.setViewport(viewport); + QVERIFY(viewport->hasMouseTracking()); + + QGraphicsScene scene(-10000, -10000, 20000, 20000); + view.setScene(&scene); + QVERIFY(viewport->hasMouseTracking()); + } + + // Make sure we enable mouse tracking when having items that accept hover events. + { + // Adding an item to the scene after the scene is set on the view. + QGraphicsScene scene(-10000, -10000, 20000, 20000); + QGraphicsView view(&scene); + + QGraphicsRectItem *item = new QGraphicsRectItem(10, 10, 10, 10); + item->setAcceptHoverEvents(true); + scene.addItem(item); + QVERIFY(view.viewport()->hasMouseTracking()); + } + { + // Adding an item to the scene before the scene is set on the view. + QGraphicsScene scene(-10000, -10000, 20000, 20000); + QGraphicsRectItem *item = new QGraphicsRectItem(10, 10, 10, 10); + item->setAcceptHoverEvents(true); + scene.addItem(item); + + QGraphicsView view(&scene); + QVERIFY(view.viewport()->hasMouseTracking()); + } + { + // QGraphicsWidget implicitly accepts hover if it has window decoration. + QGraphicsScene scene(-10000, -10000, 20000, 20000); + QGraphicsView view(&scene); + + QGraphicsWidget *widget = new QGraphicsWidget; + scene.addItem(widget); + QVERIFY(!view.viewport()->hasMouseTracking()); + // Enable window decoraton. + widget->setWindowFlags(Qt::Window | Qt::WindowTitleHint); + QVERIFY(view.viewport()->hasMouseTracking()); + } + + // Make sure we enable mouse tracking when having items with a cursor set. + { + // Adding an item to the scene after the scene is set on the view. + QGraphicsScene scene(-10000, -10000, 20000, 20000); + QGraphicsView view(&scene); + + QGraphicsRectItem *item = new QGraphicsRectItem(10, 10, 10, 10); + item->setCursor(Qt::CrossCursor); + scene.addItem(item); + QVERIFY(view.viewport()->hasMouseTracking()); + } + { + // Adding an item to the scene before the scene is set on the view. + QGraphicsScene scene(-10000, -10000, 20000, 20000); + QGraphicsRectItem *item = new QGraphicsRectItem(10, 10, 10, 10); + item->setCursor(Qt::CrossCursor); + scene.addItem(item); + + QGraphicsView view(&scene); + QVERIFY(view.viewport()->hasMouseTracking()); + } + + // Make sure we propagate mouse tracking to all views. + { + QGraphicsScene scene(-10000, -10000, 20000, 20000); + QGraphicsView view1(&scene); + QGraphicsView view2(&scene); + QGraphicsView view3(&scene); + + QGraphicsRectItem *item = new QGraphicsRectItem(10, 10, 10, 10); + item->setCursor(Qt::CrossCursor); + scene.addItem(item); + + QVERIFY(view1.viewport()->hasMouseTracking()); + QVERIFY(view2.viewport()->hasMouseTracking()); + QVERIFY(view3.viewport()->hasMouseTracking()); + } +} + QTEST_MAIN(tst_QGraphicsView) #include "tst_qgraphicsview.moc" #endif diff --git a/tests/auto/qhostinfo/tst_qhostinfo.cpp b/tests/auto/qhostinfo/tst_qhostinfo.cpp index 3a7698b..0c5bc59 100644 --- a/tests/auto/qhostinfo/tst_qhostinfo.cpp +++ b/tests/auto/qhostinfo/tst_qhostinfo.cpp @@ -305,7 +305,7 @@ void tst_QHostInfo::reverseLookup_data() // ### Use internal DNS instead. Discussed with Andreas. //QTest::newRow("classical.hexago.com") << QString("2001:5c0:0:2::24") << QStringList(QString("classical.hexago.com")) << 0; - QTest::newRow("www.cisco.com") << QString("198.133.219.25") << QStringList(QString("www.cisco.com")) << 0; + QTest::newRow("www.cisco.com") << QString("198.133.219.25") << QStringList(QString("origin-www.cisco.com")) << 0; QTest::newRow("bogusexample.doenstexist.org") << QString("1::2::3::4") << QStringList() << 1; } diff --git a/tests/auto/qitemdelegate/tst_qitemdelegate.cpp b/tests/auto/qitemdelegate/tst_qitemdelegate.cpp index befe0eb..27741e0 100644 --- a/tests/auto/qitemdelegate/tst_qitemdelegate.cpp +++ b/tests/auto/qitemdelegate/tst_qitemdelegate.cpp @@ -777,6 +777,7 @@ void tst_QItemDelegate::dateTimeEditor() QCOMPARE(timeEditor->time(), time); widget.clearFocus(); + qApp->setActiveWindow(&widget); widget.setFocus(); widget.editItem(item2); diff --git a/tests/auto/qline/tst_qline.cpp b/tests/auto/qline/tst_qline.cpp index 932ec8e..ab0bd9b 100644 --- a/tests/auto/qline/tst_qline.cpp +++ b/tests/auto/qline/tst_qline.cpp @@ -201,8 +201,8 @@ void tst_QLine::testIntersection_data() b = b.translated(1, 1); QTest::newRow(qPrintable(QString::fromLatin1("rotation-%0").arg(i))) - << a.x1() << a.y1() << a.x2() << a.y2() - << b.x1() << b.y1() << b.x2() << b.y2() + << (double)a.x1() << (double)a.y1() << (double)a.x2() << (double)a.y2() + << (double)b.x1() << (double)b.y1() << (double)b.x2() << (double)b.y2() << int(QLineF::BoundedIntersection) << 1.0 << 1.0; @@ -232,8 +232,8 @@ void tst_QLine::testIntersection() QCOMPARE(int(itype), type); if (type != QLineF::NoIntersection) { - QCOMPARE(ip.x(), qreal(ix)); - QCOMPARE(ip.y(), qreal(iy)); + QVERIFY(qAbs(ip.x() - ix) < epsilon); + QVERIFY(qAbs(ip.y() - iy) < epsilon); } } diff --git a/tests/auto/qmenu/tst_qmenu.cpp b/tests/auto/qmenu/tst_qmenu.cpp index 7607838..a86b754 100644 --- a/tests/auto/qmenu/tst_qmenu.cpp +++ b/tests/auto/qmenu/tst_qmenu.cpp @@ -92,6 +92,7 @@ private slots: void activeSubMenuPosition(); void task242454_sizeHint(); void task176201_clear(); + void task250673_activeMutliColumnSubMenuPosition(); protected slots: void onActivated(QAction*); void onHighlighted(QAction*); @@ -678,6 +679,39 @@ void tst_QMenu::task176201_clear() QTest::mouseClick(&menu, Qt::LeftButton, 0, menu.rect().center()); } +void tst_QMenu::task250673_activeMutliColumnSubMenuPosition() +{ + class MyMenu : public QMenu + { + public: + friend class tst_QMenu; + }; + + QMenu sub; + sub.addAction("Sub-Item1"); + QAction *subAction = sub.addAction("Sub-Item2"); + + MyMenu main; + main.addAction("Item 1"); + QAction *menuAction = main.addMenu(&sub); + main.popup(QPoint(200,200)); + + uint i = 2; + while (main.columnCount() < 2) { + main.addAction(QString("Item %1").arg(i)); + ++i; + Q_ASSERT(i<1000); + } + main.setActiveAction(menuAction); + sub.setActiveAction(subAction); + QVERIFY(main.isVisible()); + QCOMPARE(main.activeAction(), menuAction); + QVERIFY(sub.isVisible()); + QVERIFY(sub.pos().x() > main.pos().x()); + + const int subMenuOffset = main.style()->pixelMetric(QStyle::PM_SubMenuOverlap, 0, &main); + QVERIFY((sub.geometry().left() - subMenuOffset + 5) < main.geometry().right()); +} QTEST_MAIN(tst_QMenu) #include "tst_qmenu.moc" diff --git a/tests/auto/qmenubar/tst_qmenubar.cpp b/tests/auto/qmenubar/tst_qmenubar.cpp index 277e15c..538e443 100644 --- a/tests/auto/qmenubar/tst_qmenubar.cpp +++ b/tests/auto/qmenubar/tst_qmenubar.cpp @@ -457,8 +457,8 @@ void tst_QMenuBar::accel() void tst_QMenuBar::accel_noQt3() { -#ifdef Q_WS_MAC - QSKIP("On Mac, native key events are needed to test menu action activation", SkipAll); +#if defined(Q_WS_MAC) || defined(Q_OS_WINCE_WM) + QSKIP("On Mac/WinCE, native key events are needed to test menu action activation", SkipAll); #endif // create a popup menu with menu items set the accelerators later... initSimpleMenubar_noQt3(); @@ -486,8 +486,8 @@ void tst_QMenuBar::activatedCount() void tst_QMenuBar::activatedCount_noQt3() { -#ifdef Q_WS_MAC - QSKIP("On Mac, native key events are needed to test menu action activation", SkipAll); +#if defined(Q_WS_MAC) || defined(Q_OS_WINCE_WM) + QSKIP("On Mac/WinCE, native key events are needed to test menu action activation", SkipAll); #endif // create a popup menu with menu items set the accelerators later... initSimpleMenubar_noQt3(); @@ -888,8 +888,8 @@ void tst_QMenuBar::insertItem_QString_QObject_noQt3() void tst_QMenuBar::check_accelKeys() { -#ifdef Q_WS_MAC - QSKIP("On Mac, native key events are needed to test menu action activation", SkipAll); +#if defined(Q_WS_MAC) || defined(Q_OS_WINCE_WM) + QSKIP("On Mac/WinCE, native key events are needed to test menu action activation", SkipAll); #endif #ifdef QT3_SUPPORT initComplexMenubar(); @@ -961,8 +961,8 @@ void tst_QMenuBar::check_accelKeys() void tst_QMenuBar::check_cursorKeys1() { -#ifdef Q_WS_MAC - QSKIP("Qt/Mac does not use the native popups/menubar", SkipAll); +#if defined(Q_WS_MAC) || defined(Q_OS_WINCE_WM) + QSKIP("Qt/Mac,WinCE does not use the native popups/menubar", SkipAll); #endif #ifdef QT3_SUPPORT @@ -996,8 +996,8 @@ void tst_QMenuBar::check_cursorKeys1() void tst_QMenuBar::check_cursorKeys2() { -#ifdef Q_WS_MAC - QSKIP("Qt/Mac does not use the native popups/menubar", SkipAll); +#if defined(Q_WS_MAC) || defined(Q_OS_WINCE_WM) + QSKIP("Qt/Mac,WinCE does not use the native popups/menubar", SkipAll); #endif #ifdef QT3_SUPPORT @@ -1030,8 +1030,8 @@ void tst_QMenuBar::check_cursorKeys2() */ void tst_QMenuBar::check_cursorKeys3() { -#ifdef Q_WS_MAC - QSKIP("Qt/Mac does not use the native popups/menubar", SkipAll); +#if defined(Q_WS_MAC) || defined(Q_OS_WINCE_WM) + QSKIP("Qt/Mac,WinCE does not use the native popups/menubar", SkipAll); #endif #ifdef QT3_SUPPORT @@ -1186,8 +1186,8 @@ void tst_QMenuBar::check_escKey() void tst_QMenuBar::check_escKey_noQt3() { -#ifdef Q_WS_MAC - QSKIP("Qt/Mac does not use the native popups/menubar", SkipAll); +#if defined(Q_WS_MAC) || defined(Q_OS_WINCE_WM) + QSKIP("Qt/Mac,WinCE does not use the native popups/menubar", SkipAll); #endif initComplexMenubar_noQt3(); @@ -1329,7 +1329,7 @@ void tst_QMenuBar::check_escKey_noQt3() void tst_QMenuBar::allowActiveAndDisabled() { -#ifndef Q_WS_MAC +#if !defined(Q_WS_MAC) && !defined(Q_OS_WINCE_WM) mb->hide(); mb->clear(); @@ -1337,7 +1337,6 @@ tst_QMenuBar::allowActiveAndDisabled() // disabled menu items are added QMenu fileMenu("&File"); - QAction disabledAction() ; // Task 241043 : check that second menu is activated // if all items are disabled QAction *act = fileMenu.addAction("Disabled"); @@ -1394,8 +1393,8 @@ void tst_QMenuBar::check_altPress() void tst_QMenuBar::check_shortcutPress() { -#ifdef Q_WS_MAC - QSKIP("Qt/Mac does not use the native popups/menubar", SkipAll); +#if defined(Q_WS_MAC) || defined(Q_OS_WINCE_WM) + QSKIP("Qt/Mac,WinCE does not use the native popups/menubar", SkipAll); #endif #ifdef QT3_SUPPORT @@ -1430,7 +1429,7 @@ void tst_QMenuBar::check_menuPosition() #ifdef Q_WS_MAC QSKIP("Qt/Mac does not use the native popups/menubar", SkipAll); #endif -#ifdef Q_OS_WINCE +#ifdef Q_OS_WINCE_WM QSKIP("Qt/CE uses native menubar", SkipAll); #endif QMenu menu; diff --git a/tests/auto/qpainter/tst_qpainter.cpp b/tests/auto/qpainter/tst_qpainter.cpp index a4c768d..fb8df2e 100644 --- a/tests/auto/qpainter/tst_qpainter.cpp +++ b/tests/auto/qpainter/tst_qpainter.cpp @@ -3629,7 +3629,7 @@ void tst_QPainter::drawImage_data() QString("srcFormat %1, dstFormat %2, odd x: %3, odd width: %4") .arg(srcFormat).arg(dstFormat).arg(odd_x).arg(odd_width); - QTest::newRow(description) << (10 + odd_x) << 10 << (20 + odd_width) << 20 + QTest::newRow(qPrintable(description)) << (10 + odd_x) << 10 << (20 + odd_width) << 20 << QImage::Format(srcFormat) << QImage::Format(dstFormat); } diff --git a/tests/auto/qpoint/tst_qpoint.cpp b/tests/auto/qpoint/tst_qpoint.cpp index 67fefa8..16d55fc 100644 --- a/tests/auto/qpoint/tst_qpoint.cpp +++ b/tests/auto/qpoint/tst_qpoint.cpp @@ -60,6 +60,8 @@ public: private slots: void getSetCheck(); void division(); + + void manhattanLength(); }; tst_QPoint::tst_QPoint() @@ -70,6 +72,24 @@ tst_QPoint::~tst_QPoint() { } + + +void tst_QPoint::manhattanLength() +{ + { + QPoint p(10, 20); + QCOMPARE(p.manhattanLength(), 30); + } + { + QPointF p(10., 20.); + QCOMPARE(p.manhattanLength(), 30.); + } + { + QPointF p(10.1, 20.2); + QCOMPARE(p.manhattanLength(), 30.3); + } +} + // Testing get/set functions void tst_QPoint::getSetCheck() { diff --git a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp index 0a48066..ee9daef 100644 --- a/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp @@ -131,6 +131,7 @@ private slots: void task247867_insertRowsSort(); void task248868_staticSorting(); void task248868_dynamicSorting(); + void task250023_fetchMore(); protected: void buildHierarchy(const QStringList &data, QAbstractItemModel *model); @@ -2590,6 +2591,92 @@ void tst_QSortFilterProxyModel::task248868_dynamicSorting() } } +class QtTestModel: public QAbstractItemModel +{ + public: + QtTestModel(int _rows, int _cols, QObject *parent = 0): QAbstractItemModel(parent), + rows(_rows), cols(_cols), wrongIndex(false) { } + + bool canFetchMore(const QModelIndex &idx) const { + return !fetched.contains(idx); + } + + void fetchMore(const QModelIndex &idx) { + fetched.insert(idx); + } + + bool hasChildren(const QModelIndex & = QModelIndex()) const { + return true; + } + + int rowCount(const QModelIndex& parent = QModelIndex()) const { + return fetched.contains(parent) ? rows : 0; + } + int columnCount(const QModelIndex& parent = QModelIndex()) const { + return fetched.contains(parent) ? cols : 0; + } + + QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const + { + if (row < 0 || column < 0 || column >= cols || row >= rows) { + return QModelIndex(); + } + QModelIndex i = createIndex(row, column, int(parent.internalId() + 1)); + parentHash[i] = parent; + return i; + } + + QModelIndex parent(const QModelIndex &index) const + { + if (!parentHash.contains(index)) + return QModelIndex(); + return parentHash[index]; + } + + QVariant data(const QModelIndex &idx, int role) const + { + if (!idx.isValid()) + return QVariant(); + + if (role == Qt::DisplayRole) { + if (idx.row() < 0 || idx.column() < 0 || idx.column() >= cols || idx.row() >= rows) { + wrongIndex = true; + qWarning("Invalid modelIndex [%d,%d,%p]", idx.row(), idx.column(), + idx.internalPointer()); + } + return QString("[%1,%2]").arg(idx.row()).arg(idx.column()); + } + return QVariant(); + } + + QSet<QModelIndex> fetched; + int rows, cols; + mutable bool wrongIndex; + mutable QMap<QModelIndex,QModelIndex> parentHash; +}; + +void tst_QSortFilterProxyModel::task250023_fetchMore() +{ + QtTestModel model(10,10); + QSortFilterProxyModel proxy; + proxy.setSourceModel(&model); + QVERIFY(proxy.canFetchMore(QModelIndex())); + QVERIFY(proxy.hasChildren()); + while (proxy.canFetchMore(QModelIndex())) + proxy.fetchMore(QModelIndex()); + QCOMPARE(proxy.rowCount(), 10); + QCOMPARE(proxy.columnCount(), 10); + + QModelIndex idx = proxy.index(1,1); + QVERIFY(idx.isValid()); + QVERIFY(proxy.canFetchMore(idx)); + QVERIFY(proxy.hasChildren(idx)); + while (proxy.canFetchMore(idx)) + proxy.fetchMore(idx); + QCOMPARE(proxy.rowCount(idx), 10); + QCOMPARE(proxy.columnCount(idx), 10); +} + QTEST_MAIN(tst_QSortFilterProxyModel) #include "tst_qsortfilterproxymodel.moc" diff --git a/tests/auto/qsqldatabase/tst_databases.h b/tests/auto/qsqldatabase/tst_databases.h index 9c19048..611077f 100644 --- a/tests/auto/qsqldatabase/tst_databases.h +++ b/tests/auto/qsqldatabase/tst_databases.h @@ -105,11 +105,7 @@ inline static QString qTableName( const QString& prefix, QSqlDriver* driver = 0 inline static bool testWhiteSpaceNames( const QString &name ) { -/* return name.startsWith( "QPSQL" ) - || name.startsWith( "QODBC" ) - || name.startsWith( "QSQLITE" ) - || name.startsWith( "QMYSQL" );*/ - return name != QLatin1String("QSQLITE2"); + return name != QLatin1String("QTDS7"); } inline static QString toHex( const QString& binary ) @@ -211,7 +207,7 @@ public: // This requires a local ODBC data source to be configured( pointing to a MySql database ) // addDb( "QODBC", "mysqlodbc", "troll", "trond" ); // addDb( "QODBC", "SqlServer", "troll", "trond" ); -// addDb( "QTDS7", "testdb", "troll", "trondk", "horsehead.nokia.troll.no" ); +// addDb( "QTDS7", "testdb", "troll", "trondk", "horsehead" ); // addDb( "QODBC", "silencetestdb", "troll", "trond", "silence" ); // addDb( "QODBC", "horseheadtestdb", "troll", "trondk", "horsehead" ); @@ -221,7 +217,7 @@ public: // addDb( "QMYSQL3", "testdb", "troll", "trond", "horsehead.nokia.troll.no", 3309, "CLIENT_COMPRESS=1;CLIENT_SSL=1" ); // MySQL 5.0.18 Linux // addDb( "QMYSQL3", "testdb", "troll", "trond", "iceblink.nokia.troll.no" ); // MySQL 5.0.13 Windows // addDb( "QMYSQL3", "testdb", "testuser", "Ee4Gabf6_", "mysql4-nokia.trolltech.com.au" ); // MySQL 4.1.22-2.el4 linux -// addDb( "QMYSQL3", "testdb", "testuser", "Ee4Gabf6_", "mysql5-nokia.trolltech.com.au" ); // MySQL 5.0.45-7.el5 linux +// addDb( "QMYSQL3", "testdb", "testuser", "Ee4Gabf6_", "mysql5-nokia.trolltech.com.au" ); // MySQL 5.0.45-7.el5 linux // addDb( "QPSQL7", "testdb", "troll", "trond", "horsehead.nokia.troll.no" ); // V7.2 NOT SUPPORTED! // addDb( "QPSQL7", "testdb", "troll", "trond", "horsehead.nokia.troll.no", 5434 ); // V7.2 NOT SUPPORTED! Multi-byte @@ -242,12 +238,15 @@ public: // addDb( "QIBASE", "/opt/firebird/databases/testdb.fdb", "testuser", "Ee4Gabf6_", "firebird2-nokia.trolltech.com.au" ); // Firebird 2.1.1 // use in-memory database to prevent local files -// addDb("QSQLITE", ":memory:"); - addDb( "QSQLITE", QDir::toNativeSeparators(QDir::tempPath()+"/foo.db") ); + addDb("QSQLITE", ":memory:"); +// addDb( "QSQLITE", QDir::toNativeSeparators(QDir::tempPath()+"/foo.db") ); // addDb( "QSQLITE2", QDir::toNativeSeparators(QDir::tempPath()+"/foo2.db") ); // addDb( "QODBC3", "DRIVER={SQL SERVER};SERVER=iceblink.nokia.troll.no\\ICEBLINK", "troll", "trond", "" ); // addDb( "QODBC3", "DRIVER={SQL Native Client};SERVER=silence.nokia.troll.no\\SQLEXPRESS", "troll", "trond", "" ); +// addDb( "QODBC", "DRIVER={MySQL ODBC 3.51 Driver};SERVER=mysql5-nokia.trolltech.com.au;DATABASE=testdb", "testuser", "Ee4Gabf6_", "" ); +// addDb( "QODBC", "DRIVER={FreeTDS};SERVER=horsehead.nokia.troll.no;DATABASE=testdb;PORT=4101;UID=troll;PWD=trondk", "troll", "trondk", "" ); + } void open() @@ -313,16 +312,18 @@ public: QSqlQuery q( db ); QStringList dbtables=db.tables(); - foreach(const QString &tableName, tableNames) { + foreach(QString tableName, tableNames) + { wasDropped = true; - foreach(const QString dbtablesName, dbtables) { - if(dbtablesName.toUpper() == tableName.toUpper()) { - dbtables.removeAll(dbtablesName); - wasDropped = q.exec("drop table " + db.driver()->escapeIdentifier( dbtablesName, QSqlDriver::TableName )); - if(!wasDropped) - wasDropped = q.exec("drop table " + dbtablesName); - } - } + QString table=tableName; + if ( db.driver()->isIdentifierEscaped(table, QSqlDriver::TableName)) + table = db.driver()->stripDelimiters(table, QSqlDriver::TableName); + + if ( dbtables.contains( table, Qt::CaseSensitive ) ) + wasDropped = q.exec( "drop table " + tableName); + else if ( dbtables.contains( table, Qt::CaseInsensitive ) ) + wasDropped = q.exec( "drop table " + tableName); + if ( !wasDropped ) qWarning() << dbToString(db) << "unable to drop table" << tableName << ':' << q.lastError().text() << "tables:" << dbtables; } diff --git a/tests/auto/qsqldatabase/tst_qsqldatabase.cpp b/tests/auto/qsqldatabase/tst_qsqldatabase.cpp index e10a0ca..8dede12 100644 --- a/tests/auto/qsqldatabase/tst_qsqldatabase.cpp +++ b/tests/auto/qsqldatabase/tst_qsqldatabase.cpp @@ -191,6 +191,10 @@ private slots: void sqlite_bindAndFetchUInt_data() { generic_data("QSQLITE3"); } void sqlite_bindAndFetchUInt(); + void sqlStatementUseIsNull_189093_data() { generic_data(); } + void sqlStatementUseIsNull_189093(); + + private: void createTestTables(QSqlDatabase db); void dropTestTables(QSqlDatabase db); @@ -363,6 +367,7 @@ void tst_QSqlDatabase::populateTestTables(QSqlDatabase db) QVERIFY_SQL(q, exec("insert into " + qTableName("qtest") + " (id, t_varchar, t_char, t_numeric) values (1, 'VarChar1', 'Char1', 2.2)")); QVERIFY_SQL(q, exec("insert into " + qTableName("qtest") + " (id, t_varchar, t_char, t_numeric) values (2, 'VarChar2', 'Char2', 3.3)")); QVERIFY_SQL(q, exec("insert into " + qTableName("qtest") + " (id, t_varchar, t_char, t_numeric) values (3, 'VarChar3', 'Char3', 4.4)")); + QVERIFY_SQL(q, exec("insert into " + qTableName("qtest") + " (id, t_varchar, t_char, t_numeric) values (4, 'VarChar4', NULL, NULL)")); } void tst_QSqlDatabase::initTestCase() @@ -1045,6 +1050,7 @@ void tst_QSqlDatabase::recordMySQL() int minor = tst_Databases::getMySqlVersion( db ).section( QChar('.'), 1, 1 ).toInt(); int revision = tst_Databases::getMySqlVersion( db ).section( QChar('.'), 2, 2 ).toInt(); +#ifdef QT3_SUPPORT /* The below is broken in mysql below 5.0.15 see http://dev.mysql.com/doc/refman/5.0/en/binary-varbinary.html specifically: Before MySQL 5.0.15, the pad value is space. Values are right-padded @@ -1054,6 +1060,7 @@ void tst_QSqlDatabase::recordMySQL() bin10 = FieldDef("binary(10)", QVariant::ByteArray, QByteArray(Q3CString("123abc "))); varbin10 = FieldDef("varbinary(10)", QVariant::ByteArray, QByteArray(Q3CString("123abcv "))); } +#endif static QDateTime dt(QDate::currentDate(), QTime(1, 2, 3, 0)); static const FieldDef fieldDefs[] = { @@ -2267,5 +2274,28 @@ void tst_QSqlDatabase::db2_valueCacheUpdate() QCOMPARE(c1.toString(), q.value(0).toString()); } +void tst_QSqlDatabase::sqlStatementUseIsNull_189093() +{ + // NULL = NULL is unknow, the sqlStatment must use IS NULL + QFETCH(QString, dbName); + QSqlDatabase db = QSqlDatabase::database(dbName); + CHECK_DATABASE(db); + + // select a record with NULL value + QSqlQuery q(QString::null, db); + QVERIFY_SQL(q, exec("select * from " + qTableName("qtest") + " where id = 4")); + QVERIFY_SQL(q, next()); + + QSqlDriver *driver = db.driver(); + QVERIFY(driver); + + QString preparedStatment = driver->sqlStatement(QSqlDriver::WhereStatement, QString("qtest"), q.record(), true); + QCOMPARE(preparedStatment.count("IS NULL", Qt::CaseInsensitive), 2); + + QString statment = driver->sqlStatement(QSqlDriver::WhereStatement, QString("qtest"), q.record(), false); + QCOMPARE(statment.count("IS NULL", Qt::CaseInsensitive), 2); +} + + QTEST_MAIN(tst_QSqlDatabase) #include "tst_qsqldatabase.moc" diff --git a/tests/auto/qsqldriver/qsqldriver.pro b/tests/auto/qsqldriver/qsqldriver.pro new file mode 100644 index 0000000..0024841 --- /dev/null +++ b/tests/auto/qsqldriver/qsqldriver.pro @@ -0,0 +1,16 @@ +load(qttest_p4) +SOURCES += tst_qsqldriver.cpp + +QT += sql + +wince*: { + plugFiles.sources = ../../../plugins/sqldrivers + plugFiles.path = . + DEPLOYMENT += plugFiles +} else { + win32-g++ { + LIBS += -lws2_32 + } else:win32 { + LIBS += ws2_32.lib + } +} diff --git a/tests/auto/qsqldriver/tst_qsqldriver.cpp b/tests/auto/qsqldriver/tst_qsqldriver.cpp new file mode 100644 index 0000000..bbd7483 --- /dev/null +++ b/tests/auto/qsqldriver/tst_qsqldriver.cpp @@ -0,0 +1,218 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include <QtTest/QtTest> +#include <QtSql/QtSql> + +#include "../qsqldatabase/tst_databases.h" + + + +//TESTED_CLASS= +//TESTED_FILES= + +class tst_QSqlDriver : public QObject +{ + Q_OBJECT + +public: + void recreateTestTables(QSqlDatabase); + + tst_Databases dbs; + +public slots: + void initTestCase_data(); + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + void record(); + void primaryIndex(); +}; + + +void tst_QSqlDriver::initTestCase_data() +{ + dbs.open(); + if (dbs.fillTestTable() == 0) { + qWarning("NO DATABASES"); + QSKIP("No database drivers are available in this Qt configuration", SkipAll); + } +} + +void tst_QSqlDriver::recreateTestTables(QSqlDatabase db) +{ + QSqlQuery q(db); + + QStringList tableNames; + tableNames << qTableName( "relTEST1" ); + tst_Databases::safeDropTables( db, tableNames ); + + QVERIFY_SQL( q, exec("create table " + qTableName("relTEST1") + + " (id int not null primary key, name varchar(20), title_key int, another_title_key int)")); + QVERIFY_SQL( q, exec("insert into " + qTableName("relTEST1") + " values(1, 'harry', 1, 2)")); + QVERIFY_SQL( q, exec("insert into " + qTableName("relTEST1") + " values(2, 'trond', 2, 1)")); + QVERIFY_SQL( q, exec("insert into " + qTableName("relTEST1") + " values(3, 'vohi', 1, 2)")); + QVERIFY_SQL( q, exec("insert into " + qTableName("relTEST1") + " values(4, 'boris', 2, 2)")); +} + +void tst_QSqlDriver::initTestCase() +{ + foreach (const QString &dbname, dbs.dbNames) + recreateTestTables(QSqlDatabase::database(dbname)); +} + +void tst_QSqlDriver::cleanupTestCase() +{ + QStringList tableNames; + tableNames << qTableName( "relTEST1" ); + foreach (const QString &dbName, dbs.dbNames) { + QSqlDatabase db = QSqlDatabase::database(dbName); + tst_Databases::safeDropTables( db, tableNames ); + } + dbs.close(); +} + +void tst_QSqlDriver::init() +{ +} + +void tst_QSqlDriver::cleanup() +{ +} + +void tst_QSqlDriver::record() +{ + QFETCH_GLOBAL(QString, dbName); + QSqlDatabase db = QSqlDatabase::database(dbName); + CHECK_DATABASE(db); + + QString tablename = qTableName("relTEST1"); + QStringList fields; + fields << "id" << "name" << "title_key" << "another_title_key"; + + //check we can get records using an unquoted mixed case table name + QSqlRecord rec = db.driver()->record(tablename); + QCOMPARE(rec.count(), 4); + + if (db.driverName().startsWith("QIBASE")|| db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) + for(int i = 0; i < fields.count(); ++i) + fields[i] = fields[i].toUpper(); + + for (int i = 0; i < fields.count(); ++i) + QCOMPARE(rec.fieldName(i), fields[i]); + + if (db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) + tablename = tablename.toUpper(); + else if (db.driverName().startsWith("QPSQL")) + tablename = tablename.toLower(); + + //check we can get records using a properly quoted table name + rec = db.driver()->record(db.driver()->escapeIdentifier(tablename,QSqlDriver::TableName)); + QCOMPARE(rec.count(), 4); + + for (int i = 0; i < fields.count(); ++i) + QCOMPARE(rec.fieldName(i), fields[i]); + + if( db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) + tablename = tablename.toLower(); + else if (db.driverName().startsWith("QPSQL")) + tablename = tablename.toUpper(); + + //check that we can't get records using incorrect tablename casing that's been quoted + rec = db.driver()->record(db.driver()->escapeIdentifier(tablename,QSqlDriver::TableName)); + if (db.driverName().startsWith("QMYSQL") || db.driverName().startsWith("QSQLITE") || db.driverName().startsWith("QTDS")) + QCOMPARE(rec.count(), 4); //mysql, sqlite and tds will match + else + QCOMPARE(rec.count(), 0); + +} + +void tst_QSqlDriver::primaryIndex() +{ + QFETCH_GLOBAL(QString, dbName); + QSqlDatabase db = QSqlDatabase::database(dbName); + CHECK_DATABASE(db); + + QString tablename = qTableName("relTEST1"); + //check that we can get primary index using unquoted mixed case table name + QSqlIndex index = db.driver()->primaryIndex(tablename); + QCOMPARE(index.count(), 1); + + if( db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) + QCOMPARE(index.fieldName(0), QString::fromLatin1("ID")); + else + QCOMPARE(index.fieldName(0), QString::fromLatin1("id")); + + + //check that we can get the primary index using a quoted tablename + if( db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) + tablename = tablename.toUpper(); + else if (db.driverName().startsWith("QPSQL")) + tablename = tablename.toLower(); + + index = db.driver()->primaryIndex(db.driver()->escapeIdentifier(tablename, QSqlDriver::TableName)); + QCOMPARE(index.count(), 1); + if( db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) + QCOMPARE(index.fieldName(0), QString::fromLatin1("ID")); + else + QCOMPARE(index.fieldName(0), QString::fromLatin1("id")); + + + + //check that we can not get the primary index using a quoted but incorrect table name casing + if( db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) + tablename = tablename.toLower(); + else if (db.driverName().startsWith("QPSQL")) + tablename = tablename.toUpper(); + + index = db.driver()->primaryIndex(db.driver()->escapeIdentifier(tablename, QSqlDriver::TableName)); + if (db.driverName().startsWith("QMYSQL") || db.driverName().startsWith("QSQLITE") || db.driverName().startsWith("QTDS")) + QCOMPARE(index.count(), 1); //mysql will always find the table name regardless of casing + else + QCOMPARE(index.count(), 0); +} + +QTEST_MAIN(tst_QSqlDriver) +#include "tst_qsqldriver.moc" diff --git a/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp b/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp index 76785c3..bb2cddd 100644 --- a/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp +++ b/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp @@ -82,6 +82,10 @@ private slots: void insertRecordDuplicateFieldNames(); void invalidData(); void relationModel(); + void casing(); + void escapedRelations(); + void escapedTableName(); + void whiteSpaceInIdentifiers(); }; @@ -103,7 +107,9 @@ void tst_QSqlRelationalTableModel::recreateTestTables(QSqlDatabase db) << qTableName( "reltest2" ) << qTableName( "reltest3" ) << qTableName( "reltest4" ) - << qTableName( "reltest5" ); + << qTableName( "reltest5" ) + << db.driver()->escapeIdentifier(qTableName( "rel test6" ), QSqlDriver::TableName) + << db.driver()->escapeIdentifier(qTableName( "rel test7" ), QSqlDriver::TableName); tst_Databases::safeDropTables( db, tableNames ); QVERIFY_SQL( q, exec("create table " + qTableName("reltest1") + @@ -128,6 +134,19 @@ void tst_QSqlRelationalTableModel::recreateTestTables(QSqlDatabase db) QVERIFY_SQL( q, exec("create table " + qTableName("reltest5") + " (title varchar(20) not null primary key, abbrev varchar(20))")); QVERIFY_SQL( q, exec("insert into " + qTableName("reltest5") + " values('herr', 'Hr')")); QVERIFY_SQL( q, exec("insert into " + qTableName("reltest5") + " values('mister', 'Mr')")); + + if (testWhiteSpaceNames(db.driverName())) { + QString reltest6 = db.driver()->escapeIdentifier(qTableName("rel test6"), QSqlDriver::TableName); + QVERIFY_SQL( q, exec("create table " + reltest6 + " (id int not null primary key, " + db.driver()->escapeIdentifier("city key", QSqlDriver::FieldName) + + " int, " + db.driver()->escapeIdentifier("extra field", QSqlDriver::FieldName) + " int)")); + QVERIFY_SQL( q, exec("insert into " + reltest6 + " values(1, 1,9)")); + QVERIFY_SQL( q, exec("insert into " + reltest6 + " values(2, 2,8)")); + + QString reltest7 = db.driver()->escapeIdentifier(qTableName("rel test7"), QSqlDriver::TableName); + QVERIFY_SQL( q, exec("create table " + reltest7 + " (" + db.driver()->escapeIdentifier("city id", QSqlDriver::TableName) + " int not null primary key, " + db.driver()->escapeIdentifier("city name", QSqlDriver::FieldName) + " varchar(20))")); + QVERIFY_SQL( q, exec("insert into " + reltest7 + " values(1, 'New York')")); + QVERIFY_SQL( q, exec("insert into " + reltest7 + " values(2, 'Washington')")); + } } void tst_QSqlRelationalTableModel::initTestCase() @@ -142,10 +161,14 @@ void tst_QSqlRelationalTableModel::cleanupTestCase() tableNames << qTableName( "reltest1" ) << qTableName( "reltest2" ) << qTableName( "reltest3" ) - << qTableName( "reltest4" ); + << qTableName( "reltest4" ) + << qTableName( "reltest5" ); foreach (const QString &dbName, dbs.dbNames) { QSqlDatabase db = QSqlDatabase::database(dbName); - tst_Databases::safeDropTables( db, tableNames ); + QStringList tables = tableNames; + tables << db.driver()->escapeIdentifier(qTableName( "rel test6" ), QSqlDriver::TableName) + << db.driver()->escapeIdentifier(qTableName( "rel test7" ), QSqlDriver::TableName); + tst_Databases::safeDropTables( db, tables ); } dbs.close(); } @@ -273,7 +296,12 @@ void tst_QSqlRelationalTableModel::setData() model.setTable(qTableName("reltest1")); model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); - model.setRelation(3, QSqlRelation(qTableName("reltest2"), "tid", "title")); + + //sybase doesn't allow tables with the same alias used twice as col names + //so don't set up an identical relation when using the tds driver + if (!db.driverName().startsWith("QTDS")) + model.setRelation(3, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setEditStrategy(QSqlTableModel::OnManualSubmit); model.setSort(0, Qt::AscendingOrder); QVERIFY_SQL(model, select()); @@ -284,7 +312,10 @@ void tst_QSqlRelationalTableModel::setData() QCOMPARE(model.data(model.index(2, 1)).toString(), QString("vohi2")); QCOMPARE(model.data(model.index(3, 2)).toString(), QString("herr")); - QCOMPARE(model.data(model.index(0, 3)).toString(), QString("herr")); + if (!db.driverName().startsWith("QTDS")) + QCOMPARE(model.data(model.index(0, 3)).toString(), QString("herr")); + else + QCOMPARE(model.data(model.index(0, 3)).toInt(), 1); QVERIFY_SQL(model, submitAll()); } @@ -299,10 +330,15 @@ void tst_QSqlRelationalTableModel::setData() QCOMPARE(model.data(model.index(0, 3)).toInt(), 1); model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); - model.setRelation(3, QSqlRelation(qTableName("reltest2"), "tid", "title")); + if (!db.driverName().startsWith("QTDS")) + model.setRelation(3, QSqlRelation(qTableName("reltest2"), "tid", "title")); QVERIFY_SQL(model, select()); QCOMPARE(model.data(model.index(3, 2)).toString(), QString("herr")); - QCOMPARE(model.data(model.index(0, 3)).toString(), QString("herr")); + + if (!db.driverName().startsWith("QTDS")) + QCOMPARE(model.data(model.index(0, 3)).toString(), QString("herr")); + else + QCOMPARE(model.data(model.index(0, 3)).toInt(), 1); } //check setting of data when the relational key is a non-integer type @@ -336,7 +372,8 @@ void tst_QSqlRelationalTableModel::multipleRelation() model.setTable(qTableName("reltest1")); model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); - model.setRelation(3, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setRelation(3, QSqlRelation(qTableName("reltest4"), "id", "name")); + model.setSort(0, Qt::AscendingOrder); QVERIFY_SQL(model, select()); QCOMPARE(model.data(model.index(2, 0)).toInt(), 3); @@ -344,7 +381,7 @@ void tst_QSqlRelationalTableModel::multipleRelation() QCOMPARE(model.data(model.index(0, 0)).toInt(), 1); QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); QCOMPARE(model.data(model.index(0, 2)).toString(), QString("herr")); - QCOMPARE(model.data(model.index(0, 3)).toString(), QString("mister")); + QCOMPARE(model.data(model.index(0, 3)).toString(), QString("Trondheim")); } void tst_QSqlRelationalTableModel::insertRecord() @@ -357,6 +394,7 @@ void tst_QSqlRelationalTableModel::insertRecord() model.setTable(qTableName("reltest1")); model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setSort(0, Qt::AscendingOrder); QVERIFY_SQL(model, select()); QSqlRecord rec; @@ -398,6 +436,7 @@ void tst_QSqlRelationalTableModel::setRecord() model.setTable(qTableName("reltest1")); model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setSort(0, Qt::AscendingOrder); QVERIFY_SQL(model, select()); QSqlRecord rec; @@ -450,13 +489,18 @@ void tst_QSqlRelationalTableModel::insertWithStrategies() model.setTable(qTableName("reltest1")); model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); - model.setRelation(3, QSqlRelation(qTableName("reltest2"), "tid", "title")); + + if (!db.driverName().startsWith("QTDS")) + model.setRelation(3, QSqlRelation(qTableName("reltest2"), "tid", "title")); QVERIFY_SQL(model, select()); QCOMPARE(model.data(model.index(0,0)).toInt(), 1); QCOMPARE(model.data(model.index(0,1)).toString(), QString("harry")); QCOMPARE(model.data(model.index(0,2)).toString(), QString("herr")); - QCOMPARE(model.data(model.index(0,3)).toString(), QString("mister")); + if (!db.driverName().startsWith("QTDS")) + QCOMPARE(model.data(model.index(0,3)).toString(), QString("mister")); + else + QCOMPARE(model.data(model.index(0,3)).toInt(), 2); model.insertRows(0, 1); model.setData(model.index(0, 0), 1011); @@ -467,12 +511,20 @@ void tst_QSqlRelationalTableModel::insertWithStrategies() QCOMPARE(model.data(model.index(0,0)).toInt(), 1011); QCOMPARE(model.data(model.index(0,1)).toString(), QString("test")); QCOMPARE(model.data(model.index(0,2)).toString(), QString("mister")); - QCOMPARE(model.data(model.index(0,3)).toString(), QString("herr")); + if (!db.driverName().startsWith("QTDS")) + QCOMPARE(model.data(model.index(0,3)).toString(), QString("herr")); + else + QCOMPARE(model.data(model.index(0,3)).toInt(), 1); QCOMPARE(model.data(model.index(1,0)).toInt(), 1); QCOMPARE(model.data(model.index(1,1)).toString(), QString("harry")); QCOMPARE(model.data(model.index(1,2)).toString(), QString("herr")); - QCOMPARE(model.data(model.index(1,3)).toString(), QString("mister")); + if (!db.driverName().startsWith("QTDS")) + QCOMPARE(model.data(model.index(1,3)).toString(), QString("mister")); + else + QCOMPARE(model.data(model.index(1,3)).toInt(), 2); + + QVERIFY_SQL(model, submitAll()); @@ -481,9 +533,16 @@ void tst_QSqlRelationalTableModel::insertWithStrategies() QCOMPARE(model.data(model.index(0,0)).toInt(), 1); QCOMPARE(model.data(model.index(0,1)).toString(), QString("harry")); QCOMPARE(model.data(model.index(0,2)).toString(), QString("herr")); - QCOMPARE(model.data(model.index(0,3)).toString(), QString("mister")); - model.setData(model.index(0,3),1); - QCOMPARE(model.data(model.index(0,3)).toString(), QString("herr")); + + if (!db.driverName().startsWith("QTDS")) { + QCOMPARE(model.data(model.index(0,3)).toString(), QString("mister")); + model.setData(model.index(0,3),1); + QCOMPARE(model.data(model.index(0,3)).toString(), QString("herr")); + } else { + QCOMPARE(model.data(model.index(0,3)).toInt(), 2); + model.setData(model.index(0,3),1); + QCOMPARE(model.data(model.index(0,3)).toInt(), 1); + } model.insertRows(0, 2); model.setData(model.index(0, 0), 1012); @@ -499,17 +558,27 @@ void tst_QSqlRelationalTableModel::insertWithStrategies() QCOMPARE(model.data(model.index(0,0)).toInt(),1012); QCOMPARE(model.data(model.index(0,1)).toString(), QString("george")); QCOMPARE(model.data(model.index(0,2)).toString(), QString("mister")); - QCOMPARE(model.data(model.index(0,3)).toString(), QString("mister")); + if (!db.driverName().startsWith("QTDS")) + QCOMPARE(model.data(model.index(0,3)).toString(), QString("mister")); + else + QCOMPARE(model.data(model.index(0,3)).toInt(), 2); + QCOMPARE(model.data(model.index(1,0)).toInt(),1013); QCOMPARE(model.data(model.index(1,1)).toString(), QString("kramer")); QCOMPARE(model.data(model.index(1,2)).toString(), QString("mister")); - QCOMPARE(model.data(model.index(1,3)).toString(), QString("herr")); + if (!db.driverName().startsWith("QTDS")) + QCOMPARE(model.data(model.index(1,3)).toString(), QString("herr")); + else + QCOMPARE(model.data(model.index(1,3)).toInt(), 1); QCOMPARE(model.data(model.index(2,0)).toInt(), 1); QCOMPARE(model.data(model.index(2,1)).toString(), QString("harry")); QCOMPARE(model.data(model.index(2,2)).toString(), QString("herr")); - QCOMPARE(model.data(model.index(2,3)).toString(), QString("herr")); + if (!db.driverName().startsWith("QTDS")) + QCOMPARE(model.data(model.index(2,3)).toString(), QString("herr")); + else + QCOMPARE(model.data(model.index(2,3)).toInt(), 1); QVERIFY_SQL(model, submitAll()); } @@ -574,7 +643,8 @@ void tst_QSqlRelationalTableModel::sort() model.setTable(qTableName("reltest1")); model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); - model.setRelation(3, QSqlRelation(qTableName("reltest2"), "tid", "title")); + if (!db.driverName().startsWith("QTDS")) + model.setRelation(3, QSqlRelation(qTableName("reltest2"), "tid", "title")); model.setSort(2, Qt::DescendingOrder); QVERIFY_SQL(model, select()); @@ -589,11 +659,19 @@ void tst_QSqlRelationalTableModel::sort() model.setSort(3, Qt::AscendingOrder); QVERIFY_SQL(model, select()); - QCOMPARE(model.rowCount(), 4); - QCOMPARE(model.data(model.index(0, 3)).toString(), QString("herr")); - QCOMPARE(model.data(model.index(1, 3)).toString(), QString("mister")); - QCOMPARE(model.data(model.index(2, 3)).toString(), QString("mister")); - QCOMPARE(model.data(model.index(3, 3)).toString(), QString("mister")); + if (!db.driverName().startsWith("QTDS")) { + QCOMPARE(model.rowCount(), 4); + QCOMPARE(model.data(model.index(0, 3)).toString(), QString("herr")); + QCOMPARE(model.data(model.index(1, 3)).toString(), QString("mister")); + QCOMPARE(model.data(model.index(2, 3)).toString(), QString("mister")); + QCOMPARE(model.data(model.index(3, 3)).toString(), QString("mister")); + } else { + QCOMPARE(model.data(model.index(0, 3)).toInt(), 1); + QCOMPARE(model.data(model.index(1, 3)).toInt(), 2); + QCOMPARE(model.data(model.index(2, 3)).toInt(), 2); + QCOMPARE(model.data(model.index(3, 3)).toInt(), 2); + } + } static void testRevert(QSqlRelationalTableModel &model) @@ -663,7 +741,7 @@ void tst_QSqlRelationalTableModel::revert() model.setTable(qTableName("reltest1")); model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); - model.setRelation(3, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setRelation(3, QSqlRelation(qTableName("reltest4"), "id", "name")); model.setSort(0, Qt::AscendingOrder); @@ -689,7 +767,9 @@ void tst_QSqlRelationalTableModel::clearDisplayValuesCache() model.setTable(qTableName("reltest1")); model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); - model.setRelation(3, QSqlRelation(qTableName("reltest2"), "tid", "title")); + + if (!db.driverName().startsWith("QTDS")) + model.setRelation(3, QSqlRelation(qTableName("reltest2"), "tid", "title")); model.setSort(1, Qt::AscendingOrder); model.setEditStrategy(QSqlTableModel::OnManualSubmit); @@ -698,7 +778,10 @@ void tst_QSqlRelationalTableModel::clearDisplayValuesCache() QCOMPARE(model.data(model.index(3, 0)).toInt(), 3); QCOMPARE(model.data(model.index(3, 1)).toString(), QString("vohi")); QCOMPARE(model.data(model.index(3, 2)).toString(), QString("herr")); - QCOMPARE(model.data(model.index(3, 3)).toString(), QString("mister")); + if (!db.driverName().startsWith("QTDS")) + QCOMPARE(model.data(model.index(3, 3)).toString(), QString("mister")); + else + QCOMPARE(model.data(model.index(3, 3)).toInt(), 2 ); model.insertRow(model.rowCount()); QVERIFY(model.setData(model.index(4, 0), 5, Qt::EditRole)); @@ -710,11 +793,18 @@ void tst_QSqlRelationalTableModel::clearDisplayValuesCache() QCOMPARE(model.data(model.index(0, 0)).toInt(), 5); QCOMPARE(model.data(model.index(0, 1)).toString(), QString("anders")); QCOMPARE(model.data(model.index(0, 2)).toString(), QString("herr")); - QCOMPARE(model.data(model.index(0, 3)).toString(), QString("herr")); + if (!db.driverName().startsWith("QTDS")) + QCOMPARE(model.data(model.index(0, 3)).toString(), QString("herr")); + else + QCOMPARE(model.data(model.index(0, 3)).toInt(), 1); + QCOMPARE(model.data(model.index(4, 0)).toInt(), 3); QCOMPARE(model.data(model.index(4, 1)).toString(), QString("vohi")); QCOMPARE(model.data(model.index(4, 2)).toString(), QString("herr")); - QCOMPARE(model.data(model.index(4, 3)).toString(), QString("mister")); + if (!db.driverName().startsWith("QTDS")) + QCOMPARE(model.data(model.index(4, 3)).toString(), QString("mister")); + else + QCOMPARE(model.data(model.index(4, 3)).toInt(), 2); } // For task 140782 and 176374: If the main table and the the related tables uses the same @@ -729,27 +819,38 @@ void tst_QSqlRelationalTableModel::insertRecordDuplicateFieldNames() QSqlRelationalTableModel model(0, db); model.setTable(qTableName("reltest3")); model.setEditStrategy(QSqlTableModel::OnManualSubmit); + model.setSort(0, Qt::AscendingOrder); // Duplication of "name", used in both reltest3 and reltest4. model.setRelation(2, QSqlRelation(qTableName("reltest4"), "id", "name")); QVERIFY_SQL(model, select()); - QCOMPARE(model.record(1).value(qTableName("reltest4").append(QLatin1String("_name"))).toString(), + if (db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) { + QCOMPARE(model.record(1).value(qTableName("reltest4").append(QLatin1String("_name")).toUpper()).toString(), + QString("Trondheim")); + } else { + QCOMPARE(model.record(1).value(qTableName("reltest4").append(QLatin1String("_name"))).toString(), QString("Trondheim")); + } QSqlRecord rec = model.record(); rec.setValue(0, 3); rec.setValue(1, "Berge"); rec.setValue(2, 1); // Must insert the key value - QCOMPARE(rec.fieldName(0), QLatin1String("id")); - QCOMPARE(rec.fieldName(1), QLatin1String("name")); // This comes from main table + if (db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) { + QCOMPARE(rec.fieldName(0), QLatin1String("ID")); + QCOMPARE(rec.fieldName(1), QLatin1String("NAME")); // This comes from main table + } else { + QCOMPARE(rec.fieldName(0), QLatin1String("id")); + QCOMPARE(rec.fieldName(1), QLatin1String("name")); + } // The duplicate field names is aliased because it's comes from the relation's display column. - if(!db.driverName().startsWith("QIBASE")) - QCOMPARE(rec.fieldName(2), qTableName("reltest4").append(QLatin1String("_name"))); - else + if(db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) QCOMPARE(rec.fieldName(2), (qTableName("reltest4").append(QLatin1String("_name"))).toUpper()); + else + QCOMPARE(rec.fieldName(2), qTableName("reltest4").append(QLatin1String("_name"))); QVERIFY(model.insertRecord(-1, rec)); QCOMPARE(model.data(model.index(2, 2)).toString(), QString("Oslo")); @@ -793,7 +894,7 @@ void tst_QSqlRelationalTableModel::relationModel() QVERIFY(model.relationModel(3) == NULL); QVERIFY(model.relationModel(4) == NULL); - model.setRelation(3, QSqlRelation(qTableName("reltest2"), "tid", "title")); + model.setRelation(3, QSqlRelation(qTableName("reltest4"), "id", "name")); QVERIFY_SQL(model, select()); QVERIFY(model.relationModel(0) == NULL); @@ -806,5 +907,285 @@ void tst_QSqlRelationalTableModel::relationModel() QCOMPARE(rel_model->data(rel_model->index(0,1)).toString(), QString("herr")); } +void tst_QSqlRelationalTableModel::casing() +{ + QFETCH_GLOBAL(QString, dbName); + QSqlDatabase db = QSqlDatabase::database(dbName); + CHECK_DATABASE(db); + + if (db.driverName().startsWith("QSQLITE")) + QSKIP("The casing test for SQLITE is irrelevant since SQLITE is case insensitive", SkipAll); + + QStringList tableNames; + tableNames << qTableName("CASETEST1", db.driver()).toUpper(); + tableNames << qTableName("casetest1", db.driver()); + tst_Databases::safeDropTables(db, tableNames); + + QSqlQuery q(db); + QVERIFY_SQL( q, exec("create table " + qTableName("CASETEST1", db.driver()).toUpper() + + " (id int not null primary key, name varchar(20), title_key int, another_title_key int)")); + QVERIFY_SQL( q, exec("insert into " + qTableName("CASETEST1", db.driver()).toUpper() + " values(1, 'harry', 1, 2)")); + QVERIFY_SQL( q, exec("insert into " + qTableName("CASETEST1", db.driver()).toUpper() + " values(2, 'trond', 2, 1)")); + QVERIFY_SQL( q, exec("insert into " + qTableName("CASETEST1", db.driver()).toUpper() + " values(3, 'vohi', 1, 2)")); + QVERIFY_SQL( q, exec("insert into " + qTableName("CASETEST1", db.driver()).toUpper() + " values(4, 'boris', 2, 2)")); + + QVERIFY_SQL( q, exec("create table " + qTableName("casetest1", db.driver()) + + " (ident int not null primary key, name varchar(20), title_key int)")); + QVERIFY_SQL( q, exec("insert into " + qTableName("casetest1", db.driver()) + " values(1, 'jerry', 1)")); + QVERIFY_SQL( q, exec("insert into " + qTableName("casetest1", db.driver()) + " values(2, 'george', 2)")); + QVERIFY_SQL( q, exec("insert into " + qTableName("casetest1", db.driver()) + " values(4, 'kramer', 2)")); + + if (db.driverName().startsWith("QOCI")) { + //try an owner that doesn't exist + QSqlRecord rec = db.driver()->record("doug." + qTableName("CASETEST1", db.driver()).toUpper()); + QCOMPARE( rec.count(), 0); + + //try an owner that does exist + rec = db.driver()->record(db.userName() + "." + qTableName("CASETEST1", db.driver()).toUpper()); + QCOMPARE( rec.count(), 4); + } + QSqlRecord rec = db.driver()->record(qTableName("CASETEST1", db.driver()).toUpper()); + QCOMPARE( rec.count(), 4); + + rec = db.driver()->record(qTableName("casetest1", db.driver())); + QCOMPARE( rec.count(), 3); + + QSqlTableModel upperCaseModel(0, db); + upperCaseModel.setTable(qTableName("CASETEST1", db.driver()).toUpper()); + + QCOMPARE(upperCaseModel.tableName(),qTableName("CASETEST1",db.driver()).toUpper()); + + QVERIFY_SQL(upperCaseModel, select()); + + QCOMPARE(upperCaseModel.rowCount(), 4); + + QSqlTableModel lowerCaseModel(0, db); + lowerCaseModel.setTable(qTableName("casetest1", db.driver())); + QCOMPARE(lowerCaseModel.tableName(), qTableName("casetest1",db.driver())); + QVERIFY_SQL(lowerCaseModel, select()); + + QCOMPARE(lowerCaseModel.rowCount(), 3); + + QSqlRelationalTableModel model(0, db); + model.setTable(qTableName("CASETEST1", db.driver()).toUpper()); + model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); + QVERIFY_SQL(model, select()); + + QCOMPARE(model.data(model.index(0, 0)).toInt(), 1); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); + QCOMPARE(model.data(model.index(0, 2)).toString(), QString("herr")); + + tst_Databases::safeDropTables(db, tableNames); +} + +void tst_QSqlRelationalTableModel::escapedRelations() +{ + QFETCH_GLOBAL(QString, dbName); + QSqlDatabase db = QSqlDatabase::database(dbName); + CHECK_DATABASE(db); + recreateTestTables(db); + + QSqlRelationalTableModel model(0, db); + model.setTable(qTableName("reltest1")); + + //try with relation table name quoted + if (db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) { + model.setRelation(2, QSqlRelation(db.driver()->escapeIdentifier(qTableName("reltest2").toUpper(),QSqlDriver::TableName), + "tid", + "title")); + } else { + model.setRelation(2, QSqlRelation(db.driver()->escapeIdentifier(qTableName("reltest2"),QSqlDriver::TableName), + "tid", + "title")); + + } + QVERIFY_SQL(model, select()); + + QCOMPARE(model.data(model.index(0, 0)).toInt(), 1); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); + QCOMPARE(model.data(model.index(0, 2)).toString(), QString("herr")); + + //try with index column quoted + if (db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) { + model.setRelation(2, QSqlRelation(qTableName("reltest2"), + db.driver()->escapeIdentifier("tid", QSqlDriver::FieldName).toUpper(), + "title")); + } else { + model.setRelation(2, QSqlRelation(qTableName("reltest2"), + db.driver()->escapeIdentifier("tid", QSqlDriver::FieldName), + "title")); + } + QVERIFY_SQL(model, select()); + + QCOMPARE(model.data(model.index(0, 0)).toInt(), 1); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); + QCOMPARE(model.data(model.index(0, 2)).toString(), QString("herr")); + + //try with display column quoted + + if (db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) { + + model.setRelation(2, QSqlRelation(qTableName("reltest2"), + "tid", + db.driver()->escapeIdentifier("title", QSqlDriver::FieldName).toUpper())); + } else { + model.setRelation(2, QSqlRelation(qTableName("reltest2"), + "tid", + db.driver()->escapeIdentifier("title", QSqlDriver::FieldName))); + } + + QVERIFY_SQL(model, select()); + + QCOMPARE(model.data(model.index(0, 0)).toInt(), 1); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); + QCOMPARE(model.data(model.index(0, 2)).toString(), QString("herr")); + + //try with tablename and index and display columns quoted in the relation + + if (db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) { + model.setRelation(2, QSqlRelation(qTableName("reltest2"), + "tid", + db.driver()->escapeIdentifier("title", QSqlDriver::FieldName).toUpper())); + } else { + model.setRelation(2, QSqlRelation(qTableName("reltest2"), + "tid", + db.driver()->escapeIdentifier("title", QSqlDriver::FieldName))); + } + QVERIFY_SQL(model, select()); + + QCOMPARE(model.data(model.index(0, 0)).toInt(), 1); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry")); + QCOMPARE(model.data(model.index(0, 2)).toString(), QString("herr")); +} + +void tst_QSqlRelationalTableModel::escapedTableName() +{ + QFETCH_GLOBAL(QString, dbName); + QSqlDatabase db = QSqlDatabase::database(dbName); + CHECK_DATABASE(db); + + // set the values using OnRowChange Strategy with an escaped tablename + { + QSqlRelationalTableModel model(0, db); + + if (db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) { + model.setTable(db.driver()->escapeIdentifier(qTableName("reltest1").toUpper(), QSqlDriver::TableName)); + } else { + model.setTable(db.driver()->escapeIdentifier(qTableName("reltest1"), QSqlDriver::TableName)); + } + model.setSort(0, Qt::AscendingOrder); + model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); + QVERIFY_SQL(model, select()); + + QVERIFY(model.setData(model.index(0, 1), QString("harry2"))); + QVERIFY(model.setData(model.index(0, 2), 2)); + + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry2")); + QCOMPARE(model.data(model.index(0, 2)).toString(), QString("mister")); + + model.submit(); + + QVERIFY(model.setData(model.index(3,1), QString("boris2"))); + QVERIFY(model.setData(model.index(3, 2), 1)); + + QCOMPARE(model.data(model.index(3,1)).toString(), QString("boris2")); + QCOMPARE(model.data(model.index(3, 2)).toString(), QString("herr")); + + model.submit(); + } + { //verify values + QSqlRelationalTableModel model(0, db); + model.setTable(qTableName("reltest1")); + model.setSort(0, Qt::AscendingOrder); + QVERIFY_SQL(model, select()); + + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("harry2")); + QCOMPARE(model.data(model.index(0, 2)).toInt(), 2); + QCOMPARE(model.data(model.index(3, 1)).toString(), QString("boris2")); + QCOMPARE(model.data(model.index(3, 2)).toInt(), 1); + + model.setRelation(2, QSqlRelation(qTableName("reltest2"), "tid", "title")); + QVERIFY_SQL(model, select()); + QCOMPARE(model.data(model.index(0, 2)).toString(), QString("mister")); + QCOMPARE(model.data(model.index(3,2)).toString(), QString("herr")); + + } +} + +void tst_QSqlRelationalTableModel::whiteSpaceInIdentifiers() { + + QFETCH_GLOBAL(QString, dbName); + QSqlDatabase db = QSqlDatabase::database(dbName); + CHECK_DATABASE(db); + + if (!testWhiteSpaceNames(db.driverName())) + QSKIP("White space test irrelevant for driver", SkipAll); + QSqlRelationalTableModel model(0, db); + model.setTable(db.driver()->escapeIdentifier(qTableName("rel test6"), QSqlDriver::TableName)); + model.setSort(0, Qt::DescendingOrder); + model.setRelation(1, QSqlRelation(db.driver()->escapeIdentifier(qTableName("rel test7"), QSqlDriver::TableName), + db.driver()->escapeIdentifier("city id", QSqlDriver::FieldName), + db.driver()->escapeIdentifier("city name", QSqlDriver::FieldName))); + QVERIFY_SQL(model, select()); + + QCOMPARE(model.data(model.index(0,1)).toString(), QString("Washington")); + QCOMPARE(model.data(model.index(1,1)).toString(), QString("New York")); + + QSqlRecord rec; + QSqlField f1("id", QVariant::Int); + QSqlField f2(db.driver()->escapeIdentifier("city key", QSqlDriver::FieldName), QVariant::Int); + QSqlField f3(db.driver()->escapeIdentifier("extra field", QSqlDriver::FieldName), QVariant::Int); + + f1.setValue(3); + f2.setValue(2); + f3.setValue(7); + + f1.setGenerated(true); + f2.setGenerated(true); + f3.setGenerated(true); + + rec.append(f1); + rec.append(f2); + rec.append(f3); + + QVERIFY_SQL(model, insertRecord(-1, rec)); + model.submitAll(); + + QCOMPARE(model.data(model.index(0, 0)).toInt(), 3); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("Washington")); + QCOMPARE(model.data(model.index(0, 2)).toInt(), 7); + + //TODO: For some reson setting a record using manual submit fails + //model.setEditStrategy(QSqlTableModel::OnManualSubmit); + + QSqlRecord recNew; + QSqlField f1New("id", QVariant::Int); + QSqlField f2New(db.driver()->escapeIdentifier("city key", QSqlDriver::FieldName), QVariant::Int); + QSqlField f3New(db.driver()->escapeIdentifier("extra field", QSqlDriver::FieldName), QVariant::Int); + + f1New.setValue(4); + f2New.setValue(1); + f3New.setValue(6); + + f1New.setGenerated(true); + f2New.setGenerated(true); + f3New.setGenerated(true); + + recNew.append(f1New); + recNew.append(f2New); + recNew.append(f3New); + + QVERIFY_SQL(model, setRecord(0, recNew)); + + QCOMPARE(model.data(model.index(0, 0)).toInt(), 4); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("New York")); + QCOMPARE(model.data(model.index(0, 2)).toInt(), 6); + + QVERIFY_SQL(model, submitAll()); + QCOMPARE(model.data(model.index(0, 0)).toInt(), 4); + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("New York")); + QCOMPARE(model.data(model.index(0, 2)).toInt(), 6); +} + QTEST_MAIN(tst_QSqlRelationalTableModel) #include "tst_qsqlrelationaltablemodel.moc" diff --git a/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp b/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp index d4affe4..0e7355e 100644 --- a/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp +++ b/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp @@ -145,7 +145,7 @@ void tst_QSqlTableModel::dropTestTables() << qTableName("bigtable") << qTableName("foo"); if (testWhiteSpaceNames(db.driverName())) - tableNames << qTableName("qtestw hitespace"); + tableNames << qTableName("qtestw hitespace", db.driver()); tst_Databases::safeDropTables(db, tableNames); @@ -277,6 +277,7 @@ void tst_QSqlTableModel::setRecord() QList<QSqlTableModel::EditStrategy> policies = QList<QSqlTableModel::EditStrategy>() << QSqlTableModel::OnFieldChange << QSqlTableModel::OnRowChange << QSqlTableModel::OnManualSubmit; + QString Xsuffix; foreach( QSqlTableModel::EditStrategy submitpolicy, policies) { QSqlTableModel model(0, db); @@ -295,6 +296,8 @@ void tst_QSqlTableModel::setRecord() if ((QSqlTableModel::EditStrategy)submitpolicy == QSqlTableModel::OnManualSubmit) QVERIFY(model.submitAll()); + else if ((QSqlTableModel::EditStrategy)submitpolicy == QSqlTableModel::OnRowChange && i == model.rowCount() -1) + model.submit(); else { // dataChanged() is not emitted when submitAll() is called QCOMPARE(spy.count(), 2); @@ -304,10 +307,12 @@ void tst_QSqlTableModel::setRecord() } } - QCOMPARE(model.data(model.index(0, 1)).toString(), QString("fooX")); - QCOMPARE(model.data(model.index(0, 2)).toString(), QString("barX")); - QCOMPARE(model.data(model.index(1, 1)).toString(), QString("bazX")); - QCOMPARE(model.data(model.index(1, 2)).toString(), QString("joeX")); + Xsuffix.append('X'); + + QCOMPARE(model.data(model.index(0, 1)).toString(), QString("foo").append(Xsuffix)); + QCOMPARE(model.data(model.index(0, 2)).toString(), QString("bar").append(Xsuffix)); + QCOMPARE(model.data(model.index(1, 1)).toString(), QString("baz").append(Xsuffix)); + QCOMPARE(model.data(model.index(1, 2)).toString(), QString("joe").append(Xsuffix)); } } diff --git a/tests/auto/qsqlthread/tst_qsqlthread.cpp b/tests/auto/qsqlthread/tst_qsqlthread.cpp index d871be4..8b8fc65 100644 --- a/tests/auto/qsqlthread/tst_qsqlthread.cpp +++ b/tests/auto/qsqlthread/tst_qsqlthread.cpp @@ -70,7 +70,7 @@ public: void recreateTestTables(); void repopulateTestTables(); - void generic_data(); + void generic_data(const QString &engine=QString()); tst_Databases dbs; public slots: diff --git a/tests/auto/qstring/tst_qstring.cpp b/tests/auto/qstring/tst_qstring.cpp index f786965..1263a41 100644 --- a/tests/auto/qstring/tst_qstring.cpp +++ b/tests/auto/qstring/tst_qstring.cpp @@ -432,6 +432,10 @@ void tst_QString::replace_uint_uint_data() QTest::newRow( "rep09" ) << QString("ACABCAB") << 4 << 2 << QString("XX") << QString("ACABXXB"); QTest::newRow( "rep10" ) << QString("ACABCAB") << 5 << 2 << QString("XX") << QString("ACABCXX"); QTest::newRow( "rep10" ) << QString("ACABCAB") << 6 << 2 << QString("XX") << QString("ACABCAXX"); + QTest::newRow( "rep12" ) << QString() << 0 << 10 << QString("X") << QString("X"); + QTest::newRow( "rep13" ) << QString("short") << 0 << 10 << QString("X") << QString("X"); + QTest::newRow( "rep14" ) << QString() << 0 << 10 << QString("XX") << QString("XX"); + QTest::newRow( "rep15" ) << QString("short") << 0 << 10 << QString("XX") << QString("XX"); } void tst_QString::replace_string_data() diff --git a/tests/auto/qtextcodec/test/test.pro b/tests/auto/qtextcodec/test/test.pro index ed2ade3..e52bb7a 100644 --- a/tests/auto/qtextcodec/test/test.pro +++ b/tests/auto/qtextcodec/test/test.pro @@ -5,6 +5,7 @@ wince*: { addFiles.sources = ../*.txt addFiles.path = . DEPLOYMENT += addFiles + DEPLOYMENT_PLUGIN += qcncodecs qjpcodecs qkrcodecs qtwcodecs } diff --git a/tests/auto/qtimer/tst_qtimer.cpp b/tests/auto/qtimer/tst_qtimer.cpp index 527628c..bffb4f2 100644 --- a/tests/auto/qtimer/tst_qtimer.cpp +++ b/tests/auto/qtimer/tst_qtimer.cpp @@ -83,6 +83,7 @@ private slots: void recurringTimer(); void deleteLaterOnQTimer(); // long name, don't want to shadow QObject::deleteLater() void moveToThread(); + void restartedTimerFiresTooSoon(); }; class TimerHelper : public QObject @@ -416,5 +417,69 @@ void tst_QTimer::moveToThread() QVERIFY((ti3.timerId() & 0xffffff) != (ti1.timerId() & 0xffffff)); } +class RestartedTimerFiresTooSoonObject : public QObject +{ + Q_OBJECT + +public: + QBasicTimer m_timer; + + int m_interval; + QTime m_startedTime; + QEventLoop eventLoop; + + inline RestartedTimerFiresTooSoonObject() + : QObject(), m_interval(0) + { } + + void timerFired() + { + static int interval = 1000; + + m_interval = interval; + m_startedTime.start(); + m_timer.start(interval, this); + + // alternate between single-shot and 1 sec + interval = interval ? 0 : 1000; + } + + void timerEvent(QTimerEvent* ev) + { + if (ev->timerId() != m_timer.timerId()) + return; + + m_timer.stop(); + + QTime now = QTime::currentTime(); + int elapsed = m_startedTime.elapsed(); + + if (elapsed < m_interval / 2) { + // severely too early! + m_timer.stop(); + eventLoop.exit(-1); + return; + } + + timerFired(); + + // don't do this forever + static int count = 0; + if (count++ > 20) { + m_timer.stop(); + eventLoop.quit(); + return; + } + } +}; + +void tst_QTimer::restartedTimerFiresTooSoon() +{ + RestartedTimerFiresTooSoonObject object; + object.timerFired(); + QVERIFY(object.eventLoop.exec() == 0); +} + QTEST_MAIN(tst_QTimer) #include "tst_qtimer.moc" +\ diff --git a/tests/auto/qtranslator/qtranslator.pro b/tests/auto/qtranslator/qtranslator.pro index e4ad22a..0d67f70 100644 --- a/tests/auto/qtranslator/qtranslator.pro +++ b/tests/auto/qtranslator/qtranslator.pro @@ -3,7 +3,7 @@ SOURCES += tst_qtranslator.cpp wince*: { - addFiles.sources = hellotr_la.qm + addFiles.sources = hellotr_la.qm msgfmt_from_po.qm addFiles.path = . DEPLOYMENT += addFiles } diff --git a/tests/auto/qtreeview/tst_qtreeview.cpp b/tests/auto/qtreeview/tst_qtreeview.cpp index e1d405d..a96dbac 100644 --- a/tests/auto/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/qtreeview/tst_qtreeview.cpp @@ -209,6 +209,8 @@ private slots: void indexRowSizeHint(); void addRowsWhileSectionsAreHidden(); + void filterProxyModelCrash(); + // task-specific tests: void task174627_moveLeftToRoot(); void task171902_expandWith1stColHidden(); @@ -223,6 +225,7 @@ private slots: void task238873_avoidAutoReopening(); void task244304_clickOnDecoration(); void task246536_scrollbarsNotWorking(); + void task250683_wrongSectionSize(); }; class QtTestModel: public QAbstractItemModel @@ -2829,6 +2832,29 @@ void tst_QTreeView::indexRowSizeHint() QCOMPARE(view.indexRowSizeHint(index), w->sizeHint().height()); } +void tst_QTreeView::filterProxyModelCrash() +{ + QStandardItemModel model; + QList<QStandardItem *> items; + for (int i = 0; i < 100; i++) + items << new QStandardItem(QString::fromLatin1("item %1").arg(i)); + model.appendColumn(items); + + QSortFilterProxyModel proxy; + proxy.setSourceModel(&model); + + QTreeView view; + view.setModel(&proxy); + view.show(); + QTest::qWait(30); + proxy.invalidate(); + view.verticalScrollBar()->setValue(15); + QTest::qWait(20); + + proxy.invalidate(); + view.repaint(); //used to crash +} + class task174627_TreeView : public QTreeView { Q_OBJECT @@ -3255,5 +3281,21 @@ void tst_QTreeView::task246536_scrollbarsNotWorking() } +void tst_QTreeView::task250683_wrongSectionSize() +{ + QDirModel model; + QTreeView treeView; + treeView.header()->setResizeMode(QHeaderView::ResizeToContents); + treeView.setModel(&model); + treeView.setColumnHidden(2, true); + treeView.setColumnHidden(3, true); + + treeView.show(); + QTest::qWait(100); + + QCOMPARE(treeView.header()->sectionSize(0) + treeView.header()->sectionSize(1), treeView.viewport()->width()); +} + + QTEST_MAIN(tst_QTreeView) #include "tst_qtreeview.moc" diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp index 9197144..cdffcc0 100644 --- a/tests/auto/qwidget/tst_qwidget.cpp +++ b/tests/auto/qwidget/tst_qwidget.cpp @@ -8746,7 +8746,9 @@ void tst_QWidget::toplevelLineEditFocus() QLineEdit w; w.show(); +#ifdef Q_WS_X11 qt_x11_wait_for_window_manager(&w); +#endif QTest::qWait(200); QCOMPARE(QApplication::activeWindow(), &w); diff --git a/tests/benchmarks/qgraphicswidget/qgraphicswidget.pro b/tests/benchmarks/qgraphicswidget/qgraphicswidget.pro new file mode 100644 index 0000000..f1ec54e --- /dev/null +++ b/tests/benchmarks/qgraphicswidget/qgraphicswidget.pro @@ -0,0 +1,6 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_qgraphicswidget +TEMPLATE = app +# Input +SOURCES += tst_qgraphicswidget.cpp diff --git a/tests/benchmarks/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/benchmarks/qgraphicswidget/tst_qgraphicswidget.cpp new file mode 100644 index 0000000..97837e2 --- /dev/null +++ b/tests/benchmarks/qgraphicswidget/tst_qgraphicswidget.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +****************************************************************************/ + +#include <qtest.h> +#include <QGraphicsItem> +#include <QGraphicsScene> +#include <QGraphicsView> +#include <QGraphicsWidget> +//TESTED_FILES= + +class tst_QGraphicsWidget : public QObject +{ + Q_OBJECT + +public: + tst_QGraphicsWidget(); + virtual ~tst_QGraphicsWidget(); + +public slots: + void init(); + void cleanup(); + +private slots: + void move(); +}; + +tst_QGraphicsWidget::tst_QGraphicsWidget() +{ +} + +tst_QGraphicsWidget::~tst_QGraphicsWidget() +{ +} + +void tst_QGraphicsWidget::init() +{ +} + +void tst_QGraphicsWidget::cleanup() +{ +} + +void tst_QGraphicsWidget::move() +{ + QGraphicsScene scene; + QGraphicsWidget *widget = new QGraphicsWidget(); + scene.addItem(widget); + QGraphicsView view(&scene); + view.show(); + QBENCHMARK { + widget->setPos(qrand(),qrand()); + } +} + +QTEST_MAIN(tst_QGraphicsWidget) +#include "tst_qgraphicswidget.moc" |