aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJ-P Nurmi <j-p.nurmi@nokia.com>2012-09-10 16:36:55 +0200
committerQt by Nokia <qt-info@nokia.com>2012-09-17 14:35:34 +0200
commita83a557cf2532ee22ccc3cd82c266ddbfbfea8c9 (patch)
treee9e9c84b7e7a363c60f394673d3ad6eed6829344 /tests
parent08444bab1bf25e20837ea47b647a5b1216caa05c (diff)
Auto tests: PlatformQuirks::isClipboardAvailable()
Change-Id: I24c4417b7475ab07a47fbf5bf23d859e38b5c9ae Reviewed-by: Caroline Chao <caroline.chao@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp74
-rw-r--r--tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp84
-rw-r--r--tests/auto/shared/platformquirks.h69
3 files changed, 116 insertions, 111 deletions
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 <QMimeData>
#include <private/qquicktextcontrol_p.h>
#include "../../shared/util.h"
+#include "../../shared/platformquirks.h"
#include "../../shared/platforminputcontext.h"
#include <private/qinputmethod_p.h>
#include <QtGui/qstylehints.h>
@@ -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()
diff --git a/tests/auto/shared/platformquirks.h b/tests/auto/shared/platformquirks.h
new file mode 100644
index 0000000000..9e7b020051
--- /dev/null
+++ b/tests/auto/shared/platformquirks.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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.1, 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef PLATFORMQUIRKS_H
+#define PLATFORMQUIRKS_H
+
+#include <qglobal.h>
+
+#ifdef Q_OS_MAC
+#include <Carbon/Carbon.h>
+#endif
+
+struct PlatformQuirks
+{
+ static inline bool isClipboardAvailable()
+ {
+#if defined(QT_NO_CLIPBOARD)
+ return false;
+#elif defined(Q_OS_MAC)
+ PasteboardRef pasteboard;
+ OSStatus status = PasteboardCreate(0, &pasteboard);
+ if (status == noErr)
+ CFRelease(pasteboard);
+ return status == noErr;
+#else
+ return true;
+#endif
+ }
+};
+
+#endif