diff options
author | Sergio Ahumada <sergio.ahumada@nokia.com> | 2011-08-29 08:51:04 (GMT) |
---|---|---|
committer | Sergio Ahumada <sergio.ahumada@nokia.com> | 2011-08-29 08:51:04 (GMT) |
commit | fc87ef723d5a030fd701257eeca471e450e08fbb (patch) | |
tree | dcd380c789de4cc2b586c66277b39b8c9fc0d76f /tests | |
parent | 87136163dcd7ffb8759875bca2b4e559a32167cd (diff) | |
parent | e154fb84b075ad3fda4ac02d620b28cc50e46c09 (diff) | |
download | Qt-fc87ef723d5a030fd701257eeca471e450e08fbb.zip Qt-fc87ef723d5a030fd701257eeca471e450e08fbb.tar.gz Qt-fc87ef723d5a030fd701257eeca471e450e08fbb.tar.bz2 |
Merge remote-tracking branch 'upstream/4.8'
Conflicts:
tools/qdoc3/cppcodemarker.cpp
Diffstat (limited to 'tests')
9 files changed, 151 insertions, 145 deletions
diff --git a/tests/auto/declarative/qdeclarativetextedit/data/horizontalAlignment_RightToLeft.qml b/tests/auto/declarative/qdeclarativetextedit/data/horizontalAlignment_RightToLeft.qml index 43ea8d8..6e739bf 100644 --- a/tests/auto/declarative/qdeclarativetextedit/data/horizontalAlignment_RightToLeft.qml +++ b/tests/auto/declarative/qdeclarativetextedit/data/horizontalAlignment_RightToLeft.qml @@ -18,6 +18,7 @@ Rectangle { objectName: "text" anchors.fill: parent text: top.text + focus: true } } } diff --git a/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_false_words.qml b/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_false_words.qml index 22a9871..f8d2e4e 100644 --- a/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_false_words.qml +++ b/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_false_words.qml @@ -1,7 +1,8 @@ -import QtQuick 1.0 +import QtQuick 1.1 TextEdit { focus: true - text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + text: "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" selectByMouse: false + mouseSelectionMode: TextEdit.SelectWords } diff --git a/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_true_words.qml b/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_true_words.qml index d61da46..f58fd45 100644 --- a/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_true_words.qml +++ b/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_true_words.qml @@ -1,7 +1,8 @@ -import QtQuick 1.0 +import QtQuick 1.1 TextEdit { focus: true - text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + text: "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" selectByMouse: true + mouseSelectionMode: TextEdit.SelectWords } diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index 5d6f2a2..fde0588 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -454,6 +454,8 @@ void tst_qdeclarativetextedit::hAlign_RightToLeft() QVERIFY(textEdit != 0); canvas->show(); + const QString rtlText = textEdit->text(); + // implicit alignment should follow the reading direction of text QCOMPARE(textEdit->hAlign(), QDeclarativeTextEdit::AlignRight); QVERIFY(textEdit->positionToRectangle(0).x() > canvas->width()/2); @@ -530,6 +532,16 @@ void tst_qdeclarativetextedit::hAlign_RightToLeft() QCOMPARE(textEdit->hAlign(), QDeclarativeTextEdit::AlignLeft); QVERIFY(textEdit->positionToRectangle(0).x() < canvas->width()/2); + QApplication::setActiveWindow(canvas); + QTest::qWaitForWindowShown(canvas); + QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(canvas)); + + textEdit->setText(QString()); + { QInputMethodEvent ev(rtlText, QList<QInputMethodEvent::Attribute>()); QApplication::sendEvent(canvas, &ev); } + QCOMPARE(textEdit->hAlign(), QDeclarativeTextEdit::AlignRight); + { QInputMethodEvent ev("Hello world!", QList<QInputMethodEvent::Attribute>()); QApplication::sendEvent(canvas, &ev); } + QCOMPARE(textEdit->hAlign(), QDeclarativeTextEdit::AlignLeft); + #ifndef Q_OS_MAC // QTBUG-18040 // empty text with implicit alignment follows the system locale-based // keyboard input direction from QApplication::keyboardInputDirection @@ -1315,20 +1327,32 @@ void tst_qdeclarativetextedit::moveCursorSelectionSequence() void tst_qdeclarativetextedit::mouseSelection_data() { QTest::addColumn<QString>("qmlfile"); - QTest::addColumn<bool>("expectSelection"); + QTest::addColumn<int>("from"); + QTest::addColumn<int>("to"); + QTest::addColumn<QString>("selectedText"); // import installed - QTest::newRow("on") << SRCDIR "/data/mouseselection_true.qml" << true; - QTest::newRow("off") << SRCDIR "/data/mouseselection_false.qml" << false; - QTest::newRow("default") << SRCDIR "/data/mouseselection_default.qml" << false; - QTest::newRow("on word selection") << SRCDIR "/data/mouseselection_true_words.qml" << true; - QTest::newRow("off word selection") << SRCDIR "/data/mouseselection_false_words.qml" << false; + QTest::newRow("on") << SRCDIR "/data/mouseselection_true.qml" << 4 << 9 << "45678"; + QTest::newRow("off") << SRCDIR "/data/mouseselection_false.qml" << 4 << 9 << QString(); + QTest::newRow("default") << SRCDIR "/data/mouseselection_default.qml" << 4 << 9 << QString(); + QTest::newRow("off word selection") << SRCDIR "/data/mouseselection_false_words.qml" << 4 << 9 << QString(); + QTest::newRow("on word selection (4,9)") << SRCDIR "/data/mouseselection_true_words.qml" << 4 << 9 << "0123456789"; + QTest::newRow("on word selection (2,13)") << SRCDIR "/data/mouseselection_true_words.qml" << 2 << 13 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + QTest::newRow("on word selection (2,30)") << SRCDIR "/data/mouseselection_true_words.qml" << 2 << 30 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + QTest::newRow("on word selection (9,13)") << SRCDIR "/data/mouseselection_true_words.qml" << 9 << 13 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + QTest::newRow("on word selection (9,30)") << SRCDIR "/data/mouseselection_true_words.qml" << 9 << 30 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + QTest::newRow("on word selection (13,2)") << SRCDIR "/data/mouseselection_true_words.qml" << 13 << 2 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + QTest::newRow("on word selection (20,2)") << SRCDIR "/data/mouseselection_true_words.qml" << 20 << 2 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + QTest::newRow("on word selection (12,9)") << SRCDIR "/data/mouseselection_true_words.qml" << 12 << 9 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + QTest::newRow("on word selection (30,9)") << SRCDIR "/data/mouseselection_true_words.qml" << 30 << 9 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ"; } void tst_qdeclarativetextedit::mouseSelection() { QFETCH(QString, qmlfile); - QFETCH(bool, expectSelection); + QFETCH(int, from); + QFETCH(int, to); + QFETCH(QString, selectedText); QDeclarativeView *canvas = createView(qmlfile); @@ -1342,25 +1366,20 @@ void tst_qdeclarativetextedit::mouseSelection() QVERIFY(textEditObject != 0); // press-and-drag-and-release from x1 to x2 - int x1 = 10; - int x2 = 70; - int y = textEditObject->height()/2; - QTest::mousePress(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(x1,y))); + QPoint p1 = canvas->mapFromScene(textEditObject->positionToRectangle(from).center()); + QPoint p2 = canvas->mapFromScene(textEditObject->positionToRectangle(to).center()); + QTest::mousePress(canvas->viewport(), Qt::LeftButton, 0, p1); //QTest::mouseMove(canvas->viewport(), canvas->mapFromScene(QPoint(x2,y))); // doesn't work - QMouseEvent mv(QEvent::MouseMove, canvas->mapFromScene(QPoint(x2,y)), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier); + QMouseEvent mv(QEvent::MouseMove, canvas->mapFromScene(p2), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier); QApplication::sendEvent(canvas->viewport(), &mv); - QTest::mouseRelease(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(x2,y))); - QString str = textEditObject->selectedText(); - if (expectSelection) - QVERIFY(str.length() > 3); // don't reallly care *what* was selected (and it's too sensitive to platform) - else - QVERIFY(str.isEmpty()); + QTest::mouseRelease(canvas->viewport(), Qt::LeftButton, 0, p2); + QCOMPARE(textEditObject->selectedText(), selectedText); // Clicking and shift to clicking between the same points should select the same text. textEditObject->setCursorPosition(0); - QTest::mouseClick(canvas->viewport(), Qt::LeftButton, Qt::NoModifier, canvas->mapFromScene(QPoint(x1,y))); - QTest::mouseClick(canvas->viewport(), Qt::LeftButton, Qt::ShiftModifier, canvas->mapFromScene(QPoint(x2,y))); - QCOMPARE(textEditObject->selectedText(), str); + QTest::mouseClick(canvas->viewport(), Qt::LeftButton, Qt::NoModifier, p1); + QTest::mouseClick(canvas->viewport(), Qt::LeftButton, Qt::ShiftModifier, p2); + QCOMPARE(textEditObject->selectedText(), selectedText); delete canvas; } diff --git a/tests/auto/declarative/qdeclarativetextinput/data/horizontalAlignment_RightToLeft.qml b/tests/auto/declarative/qdeclarativetextinput/data/horizontalAlignment_RightToLeft.qml index b11535e..7f27bbe 100644 --- a/tests/auto/declarative/qdeclarativetextinput/data/horizontalAlignment_RightToLeft.qml +++ b/tests/auto/declarative/qdeclarativetextinput/data/horizontalAlignment_RightToLeft.qml @@ -18,6 +18,7 @@ Rectangle { objectName: "text" anchors.fill: parent text: top.text + focus: true } } } diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index 280f952..bb895bf 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -1198,6 +1198,8 @@ void tst_qdeclarativetextinput::horizontalAlignment_RightToLeft() QVERIFY(textInput != 0); canvas->show(); + const QString rtlText = textInput->text(); + QDeclarativeTextInputPrivate *textInputPrivate = QDeclarativeTextInputPrivate::get(textInput); QVERIFY(textInputPrivate != 0); QVERIFY(-textInputPrivate->hscroll > canvas->width()/2); @@ -1262,6 +1264,17 @@ void tst_qdeclarativetextinput::horizontalAlignment_RightToLeft() QCOMPARE(textInput->hAlign(), QDeclarativeTextInput::AlignLeft); QVERIFY(-textInputPrivate->hscroll < canvas->width()/2); + QApplication::setActiveWindow(canvas); + QTest::qWaitForWindowShown(canvas); + QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(canvas)); + + // If there is no committed text, the preedit text should determine the alignment. + textInput->setText(QString()); + { QInputMethodEvent ev(rtlText, QList<QInputMethodEvent::Attribute>()); QApplication::sendEvent(canvas, &ev); } + QCOMPARE(textInput->hAlign(), QDeclarativeTextInput::AlignRight); + { QInputMethodEvent ev("Hello world!", QList<QInputMethodEvent::Attribute>()); QApplication::sendEvent(canvas, &ev); } + QCOMPARE(textInput->hAlign(), QDeclarativeTextInput::AlignLeft); + #ifndef Q_OS_MAC // QTBUG-18040 // empty text with implicit alignment follows the system locale-based // keyboard input direction from QApplication::keyboardInputDirection diff --git a/tests/auto/qdir/tst_qdir.cpp b/tests/auto/qdir/tst_qdir.cpp index 0a42a97..419eaae 100644 --- a/tests/auto/qdir/tst_qdir.cpp +++ b/tests/auto/qdir/tst_qdir.cpp @@ -444,9 +444,15 @@ void tst_QDir::QDir_default() void tst_QDir::compare() { // operator== + + // Not using QCOMPARE to test result of QDir::operator== + QDir dir; dir.makeAbsolute(); QVERIFY(dir == QDir::currentPath()); + + QVERIFY(QDir() == QDir(QDir::currentPath())); + QVERIFY(QDir("../") == QDir(QDir::currentPath() + "/..")); } static QStringList filterLinks(const QStringList &list) diff --git a/tests/auto/qlineedit/tst_qlineedit.cpp b/tests/auto/qlineedit/tst_qlineedit.cpp index 2c88561..6abbdcd 100644 --- a/tests/auto/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/qlineedit/tst_qlineedit.cpp @@ -1770,13 +1770,6 @@ void tst_QLineEdit::passwordEchoDelay() QApplication::sendEvent(testWidget, &ev); QCOMPARE(testWidget->displayText(), QString(7, fillChar) + QLatin1Char('7')); - testWidget->setCursorPosition(3); - QCOMPARE(testWidget->displayText(), QString(7, fillChar) + QLatin1Char('7')); - QTest::keyPress(testWidget, 'a'); - QCOMPARE(testWidget->displayText(), QString(3, fillChar) + QLatin1Char('a') + QString(5, fillChar)); - QTest::keyPress(testWidget, Qt::Key_Backspace); - QCOMPARE(testWidget->displayText(), QString(8, fillChar)); - // restore clean state testWidget->setEchoMode(QLineEdit::Normal); } diff --git a/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp index 2edb93a..c9d4ba4 100644 --- a/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp +++ b/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp @@ -69,13 +69,7 @@ class tst_QTemporaryFile : public QObject { Q_OBJECT -public: - tst_QTemporaryFile(); - virtual ~tst_QTemporaryFile(); public slots: - void init(); - void cleanup(); - void initTestCase(); void cleanupTestCase(); @@ -100,22 +94,17 @@ private slots: void resetTemplateAfterError(); void setTemplateAfterOpen(); void autoRemoveAfterFailedRename(); - - void QTBUG_4796_data(); - void QTBUG_4796(); - -public: }; void tst_QTemporaryFile::initTestCase() { - // For QTBUG_4796 + // For fileTemplate tests QVERIFY(QDir("test-XXXXXX").exists() || QDir().mkdir("test-XXXXXX")); } void tst_QTemporaryFile::cleanupTestCase() { - // From QTBUG_4796 + // From fileTemplate tests QVERIFY(QDir().rmdir("test-XXXXXX")); } @@ -139,76 +128,6 @@ void tst_QTemporaryFile::getSetCheck() QCOMPARE(true, obj1.autoRemove()); } -tst_QTemporaryFile::tst_QTemporaryFile() -{ -} - -tst_QTemporaryFile::~tst_QTemporaryFile() -{ - -} - -void tst_QTemporaryFile::init() -{ -// TODO: Add initialization code here. -// This will be executed immediately before each test is run. -} - -void tst_QTemporaryFile::cleanup() -{ -// TODO: Add cleanup code here. -// This will be executed immediately after each test is run. -} - -void tst_QTemporaryFile::fileTemplate_data() -{ - QTest::addColumn<QString>("constructorTemplate"); - QTest::addColumn<QString>("prefix"); - QTest::addColumn<QString>("suffix"); - QTest::addColumn<QString>("fileTemplate"); - - QTest::newRow("constructor default") << "" << "." << "" << ""; - QTest::newRow("constructor with xxx sufix") << "qt_XXXXXXxxx" << "qt_" << "xxx" << ""; - QTest::newRow("constructor with xXx sufix") << "qt_XXXXXXxXx" << "qt_" << "xXx" << ""; - QTest::newRow("constructor with no sufix") << "qt_XXXXXX" << "qt_" << "" << ""; - QTest::newRow("constructor with >6 X's and xxx suffix") << "qt_XXXXXXXXXXxxx" << "qt_" << "xxx" << ""; - QTest::newRow("constructor with >6 X's, no suffix") << "qt_XXXXXXXXXX" << "qt_" << "" << ""; - - QTest::newRow("constructor with XXXX suffix") << "qt_XXXXXX_XXXX" << "qt_" << "_XXXX" << ""; - QTest::newRow("constructor with XXXXX suffix") << "qt_XXXXXX_XXXXX" << "qt_" << "_XXXXX" << ""; - QTest::newRow("constructor with XXXX prefix") << "qt_XXXX" << "qt_XXXX." << "" << ""; - QTest::newRow("constructor with XXXXX prefix") << "qt_XXXXX" << "qt_XXXXX." << "" << ""; - QTest::newRow("constructor with XXXX prefix and suffix") << "qt_XXXX_XXXXXX_XXXX" << "qt_XXXX_" << "_XXXX" << ""; - QTest::newRow("constructor with XXXXX prefix and suffix") << "qt_XXXXX_XXXXXX_XXXXX" << "qt_XXXXX_" << "_XXXXX" << ""; - - QTest::newRow("set template, no suffix") << "" << "foo" << "" << "foo"; - QTest::newRow("set template, with lowercase XXXXXX") << "" << "qt_" << "xxxxxx" << "qt_XXXXXXxxxxxx"; - QTest::newRow("set template, with xxx") << "" << "qt_" << ".xxx" << "qt_XXXXXX.xxx"; - QTest::newRow("set template, with >6 X's") << "" << "qt_" << ".xxx" << "qt_XXXXXXXXXXXXXX.xxx"; - QTest::newRow("set template, with >6 X's, no suffix") << "" << "qt_" << "" << "qt_XXXXXXXXXXXXXX"; -} - -void tst_QTemporaryFile::fileTemplate() -{ - QFETCH(QString, constructorTemplate); - QFETCH(QString, prefix); - QFETCH(QString, suffix); - QFETCH(QString, fileTemplate); - - QTemporaryFile file(constructorTemplate); - if (!fileTemplate.isEmpty()) - file.setFileTemplate(fileTemplate); - - QCOMPARE(file.open(), true); - - if (prefix.length()) - QCOMPARE(file.fileName().left(prefix.length()), prefix); - - if (suffix.length()) - QCOMPARE(file.fileName().right(suffix.length()), suffix); -} - - /* This tests whether the temporary file really gets placed in QDir::tempPath */ @@ -411,11 +330,11 @@ void tst_QTemporaryFile::rename() { QTemporaryFile file(dir.filePath("temporary-file.XXXXXX")); - QVERIFY(file.open()); + QVERIFY2(file.open(), qPrintable(file.errorString())); tempname = file.fileName(); QVERIFY(dir.exists(tempname)); - QVERIFY(file.rename("temporary-file.txt")); + QVERIFY2(file.rename("temporary-file.txt"), qPrintable(file.errorString())); QVERIFY(!dir.exists(tempname)); QVERIFY(dir.exists("temporary-file.txt")); QCOMPARE(file.fileName(), QString("temporary-file.txt")); @@ -622,7 +541,7 @@ void tst_QTemporaryFile::autoRemoveAfterFailedRename() cleaner.reset(); } -void tst_QTemporaryFile::QTBUG_4796_data() +void tst_QTemporaryFile::fileTemplate_data() { QTest::addColumn<QString>("prefix"); QTest::addColumn<QString>("suffix"); @@ -631,15 +550,33 @@ void tst_QTemporaryFile::QTBUG_4796_data() QString unicode = QString::fromUtf8("\xc3\xa5\xc3\xa6\xc3\xb8"); QTest::newRow("<empty>") << QString() << QString() << true; + + QTest::newRow(".") << QString(".") << QString() << true; + QTest::newRow("..") << QString("..") << QString() << true; + + QTest::newRow("foo") << QString("foo") << QString() << true; + QTest::newRow("qt_ ... xxxxxx") << QString("qt_") << QString("xxxxxx") << true; + QTest::newRow("qt_ ... xxx") << QString("qt_") << QString("xxx") << true; + QTest::newRow("qt_ ... xXx") << QString("qt_") << QString("xXx") << true; + QTest::newRow("qt_ ...") << QString("qt_") << QString() << true; + QTest::newRow("qt_ ... _XXXX") << QString("qt_") << QString("_XXXX") << true; + QTest::newRow("qt_ ... _XXXXX") << QString("qt_") << QString("_XXXXX") << true; + QTest::newRow("qt_XXXX_ ...") << QString("qt_XXXX_") << QString() << true; + QTest::newRow("qt_XXXXX_ ...") << QString("qt_XXXXX_") << QString() << true; + QTest::newRow("qt_XXXX_ ... _XXXX") << QString("qt_XXXX_") << QString("_XXXX") << true; + QTest::newRow("qt_XXXXX_ ... _XXXXX") << QString("qt_XXXXX_") << QString("_XXXXX") << true; + QTest::newRow("blaXXXXXX") << QString("bla") << QString() << true; QTest::newRow("XXXXXXbla") << QString() << QString("bla") << true; + QTest::newRow("does-not-exist/qt_temp.XXXXXX") << QString("does-not-exist/qt_temp") << QString() << false; + QTest::newRow("XXXXXX<unicode>") << QString() << unicode << true; QTest::newRow("<unicode>XXXXXX") << unicode << QString() << true; QTest::newRow("<unicode>XXXXXX<unicode>") << unicode << unicode << true; } -void tst_QTemporaryFile::QTBUG_4796() +void tst_QTemporaryFile::fileTemplate() { QVERIFY(QDir("test-XXXXXX").exists()); @@ -665,25 +602,56 @@ void tst_QTemporaryFile::QTBUG_4796() QFETCH(QString, suffix); QFETCH(bool, openResult); + enum IterationType { + UseConstructor, + UseSetFileTemplate, + Done + }; + + for (IterationType setFileTemplate = UseConstructor; setFileTemplate != Done; + setFileTemplate = IterationType(int(setFileTemplate) + 1)) { + Q_FOREACH(QString const &tempName, cleaner.tempNames) + QVERIFY( !QFile::exists(tempName) ); + + cleaner.reset(); + QString fileTemplate1 = prefix + QString("XX") + suffix; QString fileTemplate2 = prefix + QString("XXXX") + suffix; QString fileTemplate3 = prefix + QString("XXXXXX") + suffix; QString fileTemplate4 = prefix + QString("XXXXXXXX") + suffix; - QTemporaryFile file1(fileTemplate1); - QTemporaryFile file2(fileTemplate2); - QTemporaryFile file3(fileTemplate3); - QTemporaryFile file4(fileTemplate4); - QTemporaryFile file5("test-XXXXXX/" + fileTemplate1); - QTemporaryFile file6("test-XXXXXX/" + fileTemplate3); + QTemporaryFile file1(setFileTemplate ? QString() : fileTemplate1); + QTemporaryFile file2(setFileTemplate ? QString() : fileTemplate2); + QTemporaryFile file3(setFileTemplate ? QString() : fileTemplate3); + QTemporaryFile file4(setFileTemplate ? QString() : fileTemplate4); + QTemporaryFile file5(setFileTemplate ? QString() : "test-XXXXXX/" + fileTemplate1); + QTemporaryFile file6(setFileTemplate ? QString() : "test-XXXXXX/" + fileTemplate3); + + if (setFileTemplate) { + file1.setFileTemplate(fileTemplate1); + file2.setFileTemplate(fileTemplate2); + file3.setFileTemplate(fileTemplate3); + file4.setFileTemplate(fileTemplate4); + file5.setFileTemplate("test-XXXXXX/" + fileTemplate1); + file6.setFileTemplate("test-XXXXXX/" + fileTemplate3); + } - QCOMPARE(file1.open(), openResult); - QCOMPARE(file2.open(), openResult); - QCOMPARE(file3.open(), openResult); - QCOMPARE(file4.open(), openResult); - QCOMPARE(file5.open(), openResult); - QCOMPARE(file6.open(), openResult); + if (openResult) { + QVERIFY2(file1.open(), qPrintable(file1.errorString())); + QVERIFY2(file2.open(), qPrintable(file2.errorString())); + QVERIFY2(file3.open(), qPrintable(file3.errorString())); + QVERIFY2(file4.open(), qPrintable(file4.errorString())); + QVERIFY2(file5.open(), qPrintable(file5.errorString())); + QVERIFY2(file6.open(), qPrintable(file6.errorString())); + } else { + QVERIFY(!file1.open()); + QVERIFY(!file2.open()); + QVERIFY(!file3.open()); + QVERIFY(!file4.open()); + QVERIFY(!file5.open()); + QVERIFY(!file6.open()); + } QCOMPARE(file1.exists(), openResult); QCOMPARE(file2.exists(), openResult); @@ -701,28 +669,31 @@ void tst_QTemporaryFile::QTBUG_4796() << file5.fileName() << file6.fileName(); - QVERIFY(file1.fileName().startsWith(fileTemplate1 + QLatin1Char('.'))); - QVERIFY(file2.fileName().startsWith(fileTemplate2 + QLatin1Char('.'))); - QVERIFY(file5.fileName().startsWith("test-XXXXXX/" + fileTemplate1 + QLatin1Char('.'))); - QVERIFY(file6.fileName().startsWith("test-XXXXXX/" + prefix)); + QDir currentDir; + QString fileName1 = currentDir.relativeFilePath(file1.fileName()); + QString fileName2 = currentDir.relativeFilePath(file2.fileName()); + QString fileName3 = currentDir.relativeFilePath(file3.fileName()); + QString fileName4 = currentDir.relativeFilePath(file4.fileName()); + QString fileName5 = currentDir.relativeFilePath(file5.fileName()); + QString fileName6 = currentDir.relativeFilePath(file6.fileName()); + + QVERIFY2(fileName1.startsWith(fileTemplate1 + QLatin1Char('.')), qPrintable(file1.fileName())); + QVERIFY2(fileName2.startsWith(fileTemplate2 + QLatin1Char('.')), qPrintable(file2.fileName())); + QVERIFY2(fileName5.startsWith("test-XXXXXX/" + fileTemplate1 + QLatin1Char('.')), qPrintable(file5.fileName())); + QVERIFY2(fileName6.startsWith("test-XXXXXX/" + prefix), qPrintable(file6.fileName())); if (!prefix.isEmpty()) { - QVERIFY(file3.fileName().startsWith(prefix)); - QVERIFY(file4.fileName().startsWith(prefix)); + QVERIFY2(fileName3.startsWith(prefix), qPrintable(file3.fileName())); + QVERIFY2(fileName4.startsWith(prefix), qPrintable(file4.fileName())); } if (!suffix.isEmpty()) { - QVERIFY(file3.fileName().endsWith(suffix)); - QVERIFY(file4.fileName().endsWith(suffix)); - QVERIFY(file6.fileName().endsWith(suffix)); + QVERIFY2(fileName3.endsWith(suffix), qPrintable(file3.fileName())); + QVERIFY2(fileName4.endsWith(suffix), qPrintable(file4.fileName())); + QVERIFY2(fileName6.endsWith(suffix), qPrintable(file6.fileName())); } } } - - Q_FOREACH(QString const &tempName, cleaner.tempNames) - QVERIFY( !QFile::exists(tempName) ); - - cleaner.reset(); } QTEST_MAIN(tst_QTemporaryFile) |