1
/* This file is part of the KDE project
2
Copyright (C) 2011 Harald Sitter <sitter@kde.org>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Lesser General Public
6
License as published by the Free Software Foundation; either
7
version 2.1 of the License, or (at your option) version 3, or any
8
later version accepted by the membership of KDE e.V. (or its
9
successor approved by the membership of KDE e.V.), Nokia Corporation
10
(or its successors, if any) and the KDE Free Qt Foundation, which shall
11
act as a proxy defined in Section 6 of version 3 of the license.
13
This library is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
Lesser General Public License for more details.
18
You should have received a copy of the GNU Lesser General Public
19
License along with this library. If not, see <http://www.gnu.org/licenses/>.
24
#include <QtCore/QDebug>
25
#include <QtTest/QTest>
27
class MrlTest : public QObject
36
void testQStringCtor();
37
void testAssignment();
38
#ifndef QT_NO_URL_CAST_FROM_STRING
39
void testQStringAssingment();
42
void testLocalEncodingWithoutScheme();
43
void testLocalEncodingWithScheme();
44
void testUrlEncoding();
46
void testImplicitSharing();
48
void cleanupTestCase();
51
using namespace Phonon;
53
void MrlTest::initTestCase()
57
void MrlTest::testDCtor()
60
QCOMPARE(mrl.isValid(), false);
61
QCOMPARE(mrl.toString(), QString());
64
void MrlTest::testCCtor()
66
Mrl mrl(QString("/usr/share/sounds/KDE_Beep.ogg"));
70
QCOMPARE(newMrl.isValid(), mrl.isValid());
71
QCOMPARE(newMrl.toString(), mrl.toString());
74
void MrlTest::testQUrlCtor()
76
QUrl qurl(QString("/usr/share/sounds/KDE_Beep.ogg"));
80
QCOMPARE(mrl.isValid(), qurl.isValid());
81
QCOMPARE(mrl.toString(), qurl.toString());
84
void MrlTest::testQStringCtor()
86
QString url("/usr/share/sounds/KDE_Beep.ogg");
91
QCOMPARE(mrl.isValid(), qurl.isValid());
92
QCOMPARE(mrl.toString(), qurl.toString());
93
QCOMPARE(mrl.toString(), url);
96
void MrlTest::testAssignment()
98
Mrl mrl(QString("/usr/share/sounds/KDE_Beep.ogg"));
102
QCOMPARE(newMrl.isValid(), mrl.isValid());
103
QCOMPARE(newMrl.toString(), mrl.toString());
106
#ifndef QT_NO_URL_CAST_FROM_STRING
107
void MrlTest::testQStringAssingment()
109
QString filename("/usr/share/sounds/KDE_Beep.ogg");
114
QCOMPARE(mrl.toString(), filename);
118
void MrlTest::testLocalEncodingWithoutScheme()
120
QString url("/home/test/Geräteüberhöhung.mp3");
123
qurl.setScheme(QString("file://"));
125
qDebug() << "MRL: " << mrl.toEncoded();
126
qDebug() << "QURL: " << qurl.toEncoded();
128
QEXPECT_FAIL("", "QUrl produces expected bogus encoded", Continue);
129
QCOMPARE(mrl.toEncoded(), qurl.toEncoded());
130
QCOMPARE(mrl.toEncoded(), QByteArray("file:///home/test/Ger%C3%A4te%C3%BCberh%C3%B6hung.mp3"));
133
void MrlTest::testLocalEncodingWithScheme()
135
QString url("file:///home/test/Geräteüberhöhung.mp3");
139
QEXPECT_FAIL("", "QUrl produces expected bogus encoded", Continue);
140
QCOMPARE(mrl.toEncoded(), qurl.toEncoded());
141
QCOMPARE(mrl.toEncoded(), QByteArray("file:///home/test/Ger%C3%A4te%C3%BCberh%C3%B6hung.mp3"));
144
void MrlTest::testUrlEncoding()
146
QString url("http://user@häst.eu/a/b/c/d/Geräteüberhöhung.mp3");
150
QCOMPARE(mrl.toEncoded(), qurl.toEncoded());
153
void MrlTest::testImplicitSharing()
155
QString url("/usr/share/sounds/KDE_Beep.ogg");
156
QUrl qurl(QString("/usr/share/sounds/KDE_Beep.ogg"));
159
mrl.setHost(QString("randomhost.com"));
160
mrl.setScheme(QString("http"));
162
QCOMPARE(mrl.toString(), QString("http://randomhost.com/usr/share/sounds/KDE_Beep.ogg"));
163
QCOMPARE(qurl.toString(), url);
166
void MrlTest::cleanupTestCase()
170
QTEST_APPLESS_MAIN(MrlTest)
172
#include "mrltest.moc"