1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include "private/qdataurl_p.h"
30#include <QtTest/QtTest>
31#include <QtCore/QDebug>
32
33class tst_QDataUrl : public QObject
34{
35 Q_OBJECT
36
37private slots:
38 void decode_data();
39 void decode();
40};
41
42void tst_QDataUrl::decode_data()
43{
44 QTest::addColumn<QString>(name: "input");
45 QTest::addColumn<bool>(name: "result");
46 QTest::addColumn<QString>(name: "mimeType");
47 QTest::addColumn<QByteArray>(name: "payload");
48
49 auto row = [](const char *tag, const char *url, bool success, QString mimeType = {}, QByteArray payload = {}) {
50 QTest::newRow(dataTag: tag) << url << success <<mimeType << payload;
51 };
52
53 row("nonData", "http://test.com", false);
54 row("emptyData", "data:text/plain", true,
55 QLatin1String("text/plain;charset=US-ASCII"));
56 row("alreadyPercentageEncoded", "data:text/plain,%E2%88%9A", true,
57 QLatin1String("text/plain"), QByteArray::fromPercentEncoding(pctEncoded: "%E2%88%9A"));
58}
59
60void tst_QDataUrl::decode()
61{
62 QFETCH(const QString, input);
63 QFETCH(const bool, result);
64 QFETCH(const QString, mimeType);
65 QFETCH(const QByteArray, payload);
66
67 QString actualMimeType;
68 QByteArray actualPayload;
69
70 QUrl url(input);
71 const bool actualResult = qDecodeDataUrl(url, mimeType&: actualMimeType, payload&: actualPayload);
72
73 QCOMPARE(actualResult, result);
74 QCOMPARE(actualMimeType, mimeType);
75 QCOMPARE(actualPayload, payload);
76 QCOMPARE(actualPayload.isNull(), payload.isNull()); // assume nullness is significant
77}
78
79QTEST_MAIN(tst_QDataUrl)
80#include "tst_qdataurl.moc"
81

source code of qtbase/tests/auto/corelib/io/qdataurl/tst_qdataurl.cpp