From a83a557cf2532ee22ccc3cd82c266ddbfbfea8c9 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 10 Sep 2012 16:36:55 +0200 Subject: Auto tests: PlatformQuirks::isClipboardAvailable() Change-Id: I24c4417b7475ab07a47fbf5bf23d859e38b5c9ae Reviewed-by: Caroline Chao --- .../quick/qquicktextedit/tst_qquicktextedit.cpp | 74 ++++++------------- .../quick/qquicktextinput/tst_qquicktextinput.cpp | 84 +++++++--------------- 2 files changed, 47 insertions(+), 111 deletions(-) (limited to 'tests/auto/quick') diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp index f9f585b07a..37a929136b 100644 --- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp @@ -60,6 +60,7 @@ #include #include #include "../../shared/util.h" +#include "../../shared/platformquirks.h" #include "../../shared/platforminputcontext.h" #include #include @@ -148,15 +149,19 @@ private slots: void delegateLoading(); void navigation(); void readOnly(); +#ifndef QT_NO_CLIPBOARD void copyAndPaste(); void canPaste(); void canPasteEmpty(); void middleClickPaste(); +#endif void textInput(); void inputMethodUpdate(); void openInputPanel(); void geometrySignals(); +#ifndef QT_NO_CLIPBOARD void pastingRichText_QTBUG_14003(); +#endif void implicitSize_data(); void implicitSize(); void contentSize(); @@ -2533,19 +2538,11 @@ void tst_qquicktextedit::navigation() QCOMPARE(input->hasActiveFocus(), false); } -void tst_qquicktextedit::copyAndPaste() { #ifndef QT_NO_CLIPBOARD - -#ifdef Q_OS_MAC - { - PasteboardRef pasteboard; - OSStatus status = PasteboardCreate(0, &pasteboard); - if (status == noErr) - CFRelease(pasteboard); - else - QSKIP("This machine doesn't support the clipboard"); - } -#endif +void tst_qquicktextedit::copyAndPaste() +{ + if (!PlatformQuirks::isClipboardAvailable()) + QSKIP("This machine doesn't support the clipboard"); QString componentStr = "import QtQuick 2.0\nTextEdit { text: \"Hello world!\" }"; QQmlComponent textEditComponent(&engine); @@ -2615,12 +2612,12 @@ void tst_qquicktextedit::copyAndPaste() { textEdit->setText(QString()); textEdit->paste(); QCOMPARE(textEdit->text(), QString("Hello")); -#endif } +#endif -void tst_qquicktextedit::canPaste() { #ifndef QT_NO_CLIPBOARD - +void tst_qquicktextedit::canPaste() +{ QGuiApplication::clipboard()->setText("Some text"); QString componentStr = "import QtQuick 2.0\nTextEdit { text: \"Hello world!\" }"; @@ -2633,13 +2630,12 @@ void tst_qquicktextedit::canPaste() { QTextDocument document; QQuickTextControl tc(&document); QCOMPARE(textEdit->canPaste(), tc.canPaste()); - -#endif } +#endif -void tst_qquicktextedit::canPasteEmpty() { #ifndef QT_NO_CLIPBOARD - +void tst_qquicktextedit::canPasteEmpty() +{ QGuiApplication::clipboard()->clear(); QString componentStr = "import QtQuick 2.0\nTextEdit { text: \"Hello world!\" }"; @@ -2652,25 +2648,14 @@ void tst_qquicktextedit::canPasteEmpty() { QTextDocument document; QQuickTextControl tc(&document); QCOMPARE(textEdit->canPaste(), tc.canPaste()); - -#endif } +#endif - +#ifndef QT_NO_CLIPBOARD void tst_qquicktextedit::middleClickPaste() { -#ifndef QT_NO_CLIPBOARD - -#ifdef Q_OS_MAC - { - PasteboardRef pasteboard; - OSStatus status = PasteboardCreate(0, &pasteboard); - if (status == noErr) - CFRelease(pasteboard); - else - QSKIP("This machine doesn't support the clipboard"); - } -#endif + if (!PlatformQuirks::isClipboardAvailable()) + QSKIP("This machine doesn't support the clipboard"); QQuickView window(testFileUrl("mouseselection_true.qml")); @@ -2706,8 +2691,8 @@ void tst_qquicktextedit::middleClickPaste() QCOMPARE(textEditObject->text().mid(1, selectedText.length()), selectedText); else QCOMPARE(textEditObject->text(), originalText); -#endif } +#endif void tst_qquicktextedit::readOnly() { @@ -2954,9 +2939,9 @@ void tst_qquicktextedit::geometrySignals() delete o; } +#ifndef QT_NO_CLIPBOARD void tst_qquicktextedit::pastingRichText_QTBUG_14003() { -#ifndef QT_NO_CLIPBOARD QString componentStr = "import QtQuick 2.0\nTextEdit { textFormat: TextEdit.PlainText }"; QQmlComponent component(&engine); component.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); @@ -2972,8 +2957,8 @@ void tst_qquicktextedit::pastingRichText_QTBUG_14003() obj->paste(); QTRY_VERIFY(obj->text() == ""); QTRY_VERIFY(obj->textFormat() == QQuickTextEdit::PlainText); -#endif } +#endif void tst_qquicktextedit::implicitSize_data() { @@ -4697,18 +4682,7 @@ void tst_qquicktextedit::undo_keypressevents_data() QTest::newRow("Inserts,moving,selection and overwriting") << keys << expectedString; } - -#ifndef QT_NO_CLIPBOARD - - bool canCopyPaste = true; -#ifdef Q_OS_MAC - - { - PasteboardRef pasteboard; - OSStatus status = PasteboardCreate(0, &pasteboard); - canCopyPaste = status == noErr; - } -#endif + bool canCopyPaste = PlatformQuirks::isClipboardAvailable(); if (canCopyPaste) { KeyList keys; @@ -4738,8 +4712,6 @@ void tst_qquicktextedit::undo_keypressevents_data() << "123"; QTest::newRow("Copy,paste") << keys << expectedString; } - -#endif } void tst_qquicktextedit::undo_keypressevents() diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index 0879b4bdb6..a877551d73 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -61,6 +61,7 @@ #endif #include "qplatformdefs.h" +#include "../../shared/platformquirks.h" #include "../../shared/platforminputcontext.h" #define SERVER_PORT 14460 @@ -153,11 +154,13 @@ private slots: void cursorRectangle(); void navigation(); void navigation_RTL(); +#ifndef QT_NO_CLIPBOARD void copyAndPaste(); void copyAndPasteKeySequence(); void canPasteEmpty(); void canPaste(); void middleClickPaste(); +#endif void readOnly(); void focusOnPress(); @@ -2388,19 +2391,11 @@ void tst_qquicktextinput::navigation_RTL() QVERIFY(input->hasActiveFocus() == true); } -void tst_qquicktextinput::copyAndPaste() { #ifndef QT_NO_CLIPBOARD - -#ifdef Q_OS_MAC - { - PasteboardRef pasteboard; - OSStatus status = PasteboardCreate(0, &pasteboard); - if (status == noErr) - CFRelease(pasteboard); - else - QSKIP("This machine doesn't support the clipboard"); - } -#endif +void tst_qquicktextinput::copyAndPaste() +{ + if (!PlatformQuirks::isClipboardAvailable()) + QSKIP("This machine doesn't support the clipboard"); QString componentStr = "import QtQuick 2.0\nTextInput { text: \"Hello world!\" }"; QQmlComponent textInputComponent(&engine); @@ -2491,22 +2486,14 @@ void tst_qquicktextinput::copyAndPaste() { } delete textInput; -#endif } +#endif -void tst_qquicktextinput::copyAndPasteKeySequence() { #ifndef QT_NO_CLIPBOARD - -#ifdef Q_OS_MAC - { - PasteboardRef pasteboard; - OSStatus status = PasteboardCreate(0, &pasteboard); - if (status == noErr) - CFRelease(pasteboard); - else - QSKIP("This machine doesn't support the clipboard"); - } -#endif +void tst_qquicktextinput::copyAndPasteKeySequence() +{ + if (!PlatformQuirks::isClipboardAvailable()) + QSKIP("This machine doesn't support the clipboard"); QString componentStr = "import QtQuick 2.0\nTextInput { text: \"Hello world!\"; focus: true }"; QQmlComponent textInputComponent(&engine); @@ -2567,12 +2554,12 @@ void tst_qquicktextinput::copyAndPasteKeySequence() { } delete textInput; -#endif } +#endif -void tst_qquicktextinput::canPasteEmpty() { #ifndef QT_NO_CLIPBOARD - +void tst_qquicktextinput::canPasteEmpty() +{ QGuiApplication::clipboard()->clear(); QString componentStr = "import QtQuick 2.0\nTextInput { text: \"Hello world!\" }"; @@ -2583,13 +2570,12 @@ void tst_qquicktextinput::canPasteEmpty() { bool cp = !textInput->isReadOnly() && QGuiApplication::clipboard()->text().length() != 0; QCOMPARE(textInput->canPaste(), cp); - -#endif } +#endif -void tst_qquicktextinput::canPaste() { #ifndef QT_NO_CLIPBOARD - +void tst_qquicktextinput::canPaste() +{ QGuiApplication::clipboard()->setText("Some text"); QString componentStr = "import QtQuick 2.0\nTextInput { text: \"Hello world!\" }"; @@ -2600,24 +2586,14 @@ void tst_qquicktextinput::canPaste() { bool cp = !textInput->isReadOnly() && QGuiApplication::clipboard()->text().length() != 0; QCOMPARE(textInput->canPaste(), cp); - -#endif } +#endif +#ifndef QT_NO_CLIPBOARD void tst_qquicktextinput::middleClickPaste() { -#ifndef QT_NO_CLIPBOARD - -#ifdef Q_OS_MAC - { - PasteboardRef pasteboard; - OSStatus status = PasteboardCreate(0, &pasteboard); - if (status == noErr) - CFRelease(pasteboard); - else - QSKIP("This machine doesn't support the clipboard"); - } -#endif + if (!PlatformQuirks::isClipboardAvailable()) + QSKIP("This machine doesn't support the clipboard"); QQuickView window(testFileUrl("mouseselection_true.qml")); @@ -2653,8 +2629,8 @@ void tst_qquicktextinput::middleClickPaste() QCOMPARE(textInputObject->text().mid(1, selectedText.length()), selectedText); else QCOMPARE(textInputObject->text(), originalText); -#endif } +#endif void tst_qquicktextinput::passwordCharacter() { @@ -5526,17 +5502,7 @@ void tst_qquicktextinput::undo_keypressevents_data() QTest::newRow("Insert,move,select,delete next word,undo,insert") << keys << expectedString; } -#ifndef QT_NO_CLIPBOARD - - bool canCopyPaste = true; -#ifdef Q_OS_MAC - - { - PasteboardRef pasteboard; - OSStatus status = PasteboardCreate(0, &pasteboard); - canCopyPaste = status == noErr; - } -#endif + bool canCopyPaste = PlatformQuirks::isClipboardAvailable(); if (canCopyPaste) { KeyList keys; @@ -5566,8 +5532,6 @@ void tst_qquicktextinput::undo_keypressevents_data() << "123"; QTest::newRow("Copy,paste") << keys << expectedString; } - -#endif } void tst_qquicktextinput::undo_keypressevents() -- cgit v1.2.3