| 1 |
/**************************************************************************** |
| 2 |
** |
| 3 |
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). |
| 4 |
** All rights reserved. |
| 5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
| 6 |
** |
| 7 |
** This file is part of the test suite of the Qt Toolkit. |
| 8 |
** |
| 9 |
** $QT_BEGIN_LICENSE:LGPL$ |
| 10 |
** GNU Lesser General Public License Usage |
| 11 |
** This file may be used under the terms of the GNU Lesser General Public |
| 12 |
** License version 2.1 as published by the Free Software Foundation and |
| 13 |
** appearing in the file LICENSE.LGPL included in the packaging of this |
| 14 |
** file. Please review the following information to ensure the GNU Lesser |
| 15 |
** General Public License version 2.1 requirements will be met: |
| 16 |
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 17 |
** |
| 18 |
** In addition, as a special exception, Nokia gives you certain additional |
| 19 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
| 20 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 21 |
** |
| 22 |
** GNU General Public License Usage |
| 23 |
** Alternatively, this file may be used under the terms of the GNU General |
| 24 |
** Public License version 3.0 as published by the Free Software Foundation |
| 25 |
** and appearing in the file LICENSE.GPL included in the packaging of this |
| 26 |
** file. Please review the following information to ensure the GNU General |
| 27 |
** Public License version 3.0 requirements will be met: |
| 28 |
** http://www.gnu.org/copyleft/gpl.html. |
| 29 |
** |
| 30 |
** Other Usage |
| 31 |
** Alternatively, this file may be used in accordance with the terms and |
| 32 |
** conditions contained in a signed written agreement between you and Nokia. |
| 33 |
** |
| 34 |
** |
| 35 |
** |
| 36 |
** |
| 37 |
** |
| 38 |
** $QT_END_LICENSE$ |
| 39 |
** |
| 40 |
****************************************************************************/ |
| 41 |
|
| 42 |
|
| 43 |
#include <QtTest/QtTest> |
| 44 |
#include <qapplication.h> |
| 45 |
#include <q3dragobject.h> |
| 46 |
|
| 47 |
//TESTED_FILES= |
| 48 |
QT_FORWARD_DECLARE_CLASS(Q3UriDrag) |
| 49 |
|
| 50 |
class tst_Q3UriDrag : public QObject |
| 51 |
{ |
| 52 |
Q_OBJECT |
| 53 |
public: |
| 54 |
tst_Q3UriDrag(); |
| 55 |
virtual ~tst_Q3UriDrag(); |
| 56 |
|
| 57 |
public slots: |
| 58 |
void initTestCase(); |
| 59 |
void cleanupTestCase(); |
| 60 |
private slots: |
| 61 |
void decodeLocalFiles_data(); |
| 62 |
void decodeLocalFiles(); |
| 63 |
void decodeToUnicodeUris_data(); |
| 64 |
void decodeToUnicodeUris(); |
| 65 |
void uriToLocalFile_data(); |
| 66 |
void uriToLocalFile(); |
| 67 |
void localFileToUri_data(); |
| 68 |
void localFileToUri(); |
| 69 |
|
| 70 |
private: |
| 71 |
Q3UriDrag *uriDrag; |
| 72 |
}; |
| 73 |
|
| 74 |
tst_Q3UriDrag::tst_Q3UriDrag() |
| 75 |
{ |
| 76 |
} |
| 77 |
|
| 78 |
tst_Q3UriDrag::~tst_Q3UriDrag() |
| 79 |
{ |
| 80 |
} |
| 81 |
|
| 82 |
void tst_Q3UriDrag::initTestCase() |
| 83 |
{ |
| 84 |
uriDrag = new Q3UriDrag(); |
| 85 |
} |
| 86 |
|
| 87 |
void tst_Q3UriDrag::cleanupTestCase() |
| 88 |
{ |
| 89 |
delete uriDrag; |
| 90 |
uriDrag = 0; |
| 91 |
} |
| 92 |
|
| 93 |
void tst_Q3UriDrag::decodeLocalFiles_data() |
| 94 |
{ |
| 95 |
QTest::addColumn<QStringList>("localFiles"); |
| 96 |
QTest::addColumn<QStringList>("decodedFiles"); |
| 97 |
|
| 98 |
#ifdef Q_WS_WIN |
| 99 |
QTest::newRow("singleFileWithAbsPath") << QStringList("c:/main.cpp") << QStringList("c:/main.cpp"); |
| 100 |
#else |
| 101 |
QTest::newRow("singleFileWithAbsPath") << QStringList("/main.cpp") << QStringList("/main.cpp"); |
| 102 |
#endif |
| 103 |
|
| 104 |
QStringList multipleFilesWithAbsPaths; |
| 105 |
#ifdef Q_WS_WIN |
| 106 |
multipleFilesWithAbsPaths << "c:/main.cpp" << "c:/home/test.cpp" << "e:/andy/quridrag.cpp" << "//somehost/somfile"; |
| 107 |
#else |
| 108 |
multipleFilesWithAbsPaths << "/main.cpp" << "/home/test.cpp" << "/andy/quridrag.cpp"; |
| 109 |
#endif |
| 110 |
QTest::newRow("multipleFilesWithAbsPaths") << multipleFilesWithAbsPaths << multipleFilesWithAbsPaths; |
| 111 |
|
| 112 |
QTest::newRow("nonLocalFile") << QStringList("http://qt.nokia.com") << QStringList(); |
| 113 |
|
| 114 |
QStringList mixOfLocalAndNonLocalFiles; |
| 115 |
#ifdef Q_WS_WIN |
| 116 |
mixOfLocalAndNonLocalFiles << "http://qt.nokia.com" << "c:/main.cpp" << "ftp://qt.nokia.com/doc"; |
| 117 |
QTest::newRow("mixOfLocalAndNonLocalFiles") << mixOfLocalAndNonLocalFiles << QStringList("c:/main.cpp"); |
| 118 |
#else |
| 119 |
mixOfLocalAndNonLocalFiles << "http://qt.nokia.com" << "/main.cpp" << "ftp://qt.nokia.com/doc"; |
| 120 |
QTest::newRow("mixOfLocalAndNonLocalFiles") << mixOfLocalAndNonLocalFiles << QStringList("/main.cpp"); |
| 121 |
#endif |
| 122 |
} |
| 123 |
|
| 124 |
void tst_Q3UriDrag::decodeLocalFiles() |
| 125 |
{ |
| 126 |
QFETCH(QStringList, localFiles); |
| 127 |
QFETCH(QStringList, decodedFiles); |
| 128 |
|
| 129 |
uriDrag->setFileNames(localFiles); |
| 130 |
|
| 131 |
QStringList decodeList; |
| 132 |
QVERIFY(Q3UriDrag::decodeLocalFiles(uriDrag, decodeList)); |
| 133 |
|
| 134 |
QCOMPARE(decodeList.join(";;"), decodedFiles.join(";;")); |
| 135 |
// Need to add the unicodeUris test separately |
| 136 |
} |
| 137 |
|
| 138 |
void tst_Q3UriDrag::decodeToUnicodeUris_data() |
| 139 |
{ |
| 140 |
QTest::addColumn<QStringList>("unicodeUris"); |
| 141 |
QTest::addColumn<QStringList>("decodedFiles"); |
| 142 |
|
| 143 |
#ifdef Q_WS_WIN |
| 144 |
QTest::newRow("singleFileWithAbsPath") << QStringList("c:/main.cpp") << QStringList("c:/main.cpp"); |
| 145 |
#else |
| 146 |
QTest::newRow("singleFileWithAbsPath") << QStringList("/main.cpp") << QStringList("/main.cpp"); |
| 147 |
#endif |
| 148 |
|
| 149 |
QStringList multipleFiles; |
| 150 |
QStringList multipleFilesUU; |
| 151 |
#ifdef Q_WS_WIN |
| 152 |
multipleFiles << "c:/main.cpp" << "c:/home/with space test.cpp" << "e:/andy/~quridrag.cpp"; |
| 153 |
multipleFilesUU << "c:/main.cpp" << "c:/home/with space test.cpp" << "e:/andy/~quridrag.cpp"; |
| 154 |
#else |
| 155 |
multipleFiles << "/main.cpp" << "/home/with space test.cpp" << "/andy/~quridrag.cpp"; |
| 156 |
multipleFilesUU << "/main.cpp" << "/home/with space test.cpp" << "/andy/~quridrag.cpp"; |
| 157 |
#endif |
| 158 |
QTest::newRow("multipleFiles") << multipleFiles << multipleFilesUU; |
| 159 |
|
| 160 |
QTest::newRow("nonLocalUris") << QStringList("http://qt.nokia.com") << QStringList("http://qt.nokia.com"); |
| 161 |
|
| 162 |
QStringList mixOfLocalAndNonLocalUris; |
| 163 |
QStringList mixOfLocalAndNonLocalUrisUU; |
| 164 |
#ifdef Q_WS_WIN |
| 165 |
mixOfLocalAndNonLocalUris << "http://qt.nokia.com" << "c:/with space main.cpp" << "ftp://qt.nokia.com/doc"; |
| 166 |
mixOfLocalAndNonLocalUrisUU << "http://qt.nokia.com" << "c:/with space main.cpp" << "ftp://qt.nokia.com/doc"; |
| 167 |
#else |
| 168 |
mixOfLocalAndNonLocalUris << "http://qt.nokia.com" << "/main.cpp" << "ftp://qt.nokia.com/doc"; |
| 169 |
mixOfLocalAndNonLocalUrisUU << "http://qt.nokia.com" << "/main.cpp" << "ftp://qt.nokia.com/doc"; |
| 170 |
#endif |
| 171 |
QTest::newRow("mixOfLocalAndNonLocalUris") << mixOfLocalAndNonLocalUris << mixOfLocalAndNonLocalUrisUU; |
| 172 |
} |
| 173 |
|
| 174 |
void tst_Q3UriDrag::decodeToUnicodeUris() |
| 175 |
{ |
| 176 |
// RFC 2396 used for reference |
| 177 |
// |
| 178 |
// Possible AbsoluteURIs are: |
| 179 |
// |
| 180 |
// http://qt.nokia.com |
| 181 |
// c:/main.cpp |
| 182 |
// |
| 183 |
|
| 184 |
QFETCH(QStringList, unicodeUris); |
| 185 |
QFETCH(QStringList, decodedFiles); |
| 186 |
|
| 187 |
uriDrag->setUnicodeUris(unicodeUris); |
| 188 |
|
| 189 |
QStringList decodeList; |
| 190 |
QVERIFY(Q3UriDrag::decodeToUnicodeUris(uriDrag, decodeList)); |
| 191 |
QCOMPARE(decodeList.join(";;"), decodedFiles.join(";;")); |
| 192 |
|
| 193 |
// Need to test setFileNames separately |
| 194 |
} |
| 195 |
|
| 196 |
void tst_Q3UriDrag::uriToLocalFile_data() |
| 197 |
{ |
| 198 |
QTest::addColumn<QString>("uri"); |
| 199 |
QTest::addColumn<QString>("localFile"); |
| 200 |
|
| 201 |
//QTest::newRow("localFileNoEncoding") << QString("main.cpp") << QString("main.cpp"); |
| 202 |
//QTest::newRow("localFileAbsPathNoEnc") << QString("c:/main.cpp") << QString("c:/main.cpp"); |
| 203 |
//QTest::newRow("localFileAbsPathNoEnc-2") << QString("/main.cpp") << QString("/main.cpp"); |
| 204 |
//QTest::newRow("localFileEncoding") << QString("Fran%c3%a7ois") << QString::fromUtf8("François"); |
| 205 |
//QTest::newRow("localFileAbsPathEnc") << QString("c:/main.cpp") << QString("c:/main.cpp"); |
| 206 |
//QTest::newRow("localFileAbsPathEnc-2") << QString("/main.cpp") << QString("/main.cpp"); |
| 207 |
QTest::newRow("fileSchemelocalFileNoEncoding") << QString("file:///main.cpp") << QString("/main.cpp"); |
| 208 |
#ifdef Q_WS_WIN |
| 209 |
QTest::newRow("fileSchemelocalFileAbsPathNoEnc") << QString("file:///c:/main.cpp") << QString("c:/main.cpp"); |
| 210 |
QTest::newRow("fileSchemelocalFileWindowsNetworkPath") << QString("file://somehost/somefile") << QString("//somehost/somefile"); |
| 211 |
#endif |
| 212 |
QTest::newRow("fileSchemelocalFileEncoding") << QString("file:///Fran%e7ois") << QString::fromUtf8("/François"); |
| 213 |
QTest::newRow("nonLocalFile") << QString("http://qt.nokia.com") << QString(); |
| 214 |
} |
| 215 |
|
| 216 |
void tst_Q3UriDrag::uriToLocalFile() |
| 217 |
{ |
| 218 |
QFETCH(QString, uri); |
| 219 |
QFETCH(QString, localFile); |
| 220 |
QCOMPARE(Q3UriDrag::uriToLocalFile(uri.utf8()), localFile); |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
void tst_Q3UriDrag::localFileToUri_data() |
| 225 |
{ |
| 226 |
QTest::addColumn<QString>("localFile"); |
| 227 |
QTest::addColumn<QString>("uri"); |
| 228 |
#ifdef Q_WS_WIN |
| 229 |
QTest::newRow("fileSchemelocalFileWindowsNetworkPath") << QString("//somehost/somefile") << QString("file://somehost/somefile"); |
| 230 |
QTest::newRow("hash in path") << QString("c:/tmp/p#d") << QString("file:///c:/tmp/p%23d"); |
| 231 |
#else |
| 232 |
QTest::newRow("fileSchemelocalFile") << QString("/somehost/somefile") << QString("file:///somehost/somefile"); |
| 233 |
QTest::newRow("hash in path") << QString("/tmp/p#d") << QString("file:///tmp/p%23d"); |
| 234 |
#endif |
| 235 |
|
| 236 |
} |
| 237 |
|
| 238 |
void tst_Q3UriDrag::localFileToUri() |
| 239 |
{ |
| 240 |
QFETCH(QString, localFile); |
| 241 |
QFETCH(QString, uri); |
| 242 |
|
| 243 |
QCOMPARE(Q3UriDrag::localFileToUri(localFile), uri.toUtf8()); |
| 244 |
} |
| 245 |
|
| 246 |
|
| 247 |
QTEST_MAIN(tst_Q3UriDrag) |
| 248 |
#include "tst_q3uridrag.moc" |