| 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 | |
| 30 | #include <QFile> |
| 31 | #include <QtTest/QtTest> |
| 32 | |
| 33 | /* We expect these headers to be available. */ |
| 34 | #include <QtXmlPatterns/QAbstractUriResolver> |
| 35 | #include <QtXmlPatterns/qabstracturiresolver.h> |
| 36 | #include <QAbstractUriResolver> |
| 37 | #include <qabstracturiresolver.h> |
| 38 | |
| 39 | #include "TestURIResolver.h" |
| 40 | |
| 41 | /*! |
| 42 | \class tst_QAbstractUriResolver |
| 43 | \internal |
| 44 | \since 4.4 |
| 45 | \brief Tests the QAbstractUriResolver class. |
| 46 | */ |
| 47 | class tst_QAbstractUriResolver : public QObject |
| 48 | { |
| 49 | Q_OBJECT |
| 50 | |
| 51 | private Q_SLOTS: |
| 52 | void constructor() const; |
| 53 | void resolve() const; |
| 54 | void constCorrectness() const; |
| 55 | void objectSize() const; |
| 56 | void hasQ_OBJECTMacro() const; |
| 57 | }; |
| 58 | |
| 59 | void tst_QAbstractUriResolver::constructor() const |
| 60 | { |
| 61 | /* Allocate instances. */ |
| 62 | { |
| 63 | TestURIResolver instance; |
| 64 | } |
| 65 | |
| 66 | { |
| 67 | TestURIResolver instance1; |
| 68 | TestURIResolver instance2; |
| 69 | } |
| 70 | |
| 71 | { |
| 72 | TestURIResolver instance1; |
| 73 | TestURIResolver instance2; |
| 74 | TestURIResolver instance3; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | void tst_QAbstractUriResolver::constCorrectness() const |
| 79 | { |
| 80 | const TestURIResolver instance; |
| 81 | |
| 82 | /* This function is supposed to be const. */ |
| 83 | instance.resolve(relative: QUrl(), baseURI: QUrl()); |
| 84 | } |
| 85 | |
| 86 | void tst_QAbstractUriResolver::resolve() const |
| 87 | { |
| 88 | const TestURIResolver instance; |
| 89 | QCOMPARE(instance.resolve(QUrl(QLatin1String("foo/relative.file")), |
| 90 | QUrl(QLatin1String("http://example.com/NotThisOne"))), |
| 91 | QUrl(QLatin1String("http://example.com/"))); |
| 92 | } |
| 93 | |
| 94 | void tst_QAbstractUriResolver::objectSize() const |
| 95 | { |
| 96 | /* We shouldn't have a different size. */ |
| 97 | QCOMPARE(sizeof(QAbstractUriResolver), sizeof(QObject)); |
| 98 | } |
| 99 | |
| 100 | void tst_QAbstractUriResolver::hasQ_OBJECTMacro() const |
| 101 | { |
| 102 | TestURIResolver uriResolver; |
| 103 | /* If this code fails to compile, the Q_OBJECT macro is missing in |
| 104 | * the class declaration. */ |
| 105 | QAbstractUriResolver *const secondPointer = qobject_cast<QAbstractUriResolver *>(object: &uriResolver); |
| 106 | /* The static_cast is for compiling on broken compilers. */ |
| 107 | QCOMPARE(static_cast<QAbstractUriResolver *>(&uriResolver), secondPointer); |
| 108 | } |
| 109 | |
| 110 | QTEST_MAIN(tst_QAbstractUriResolver) |
| 111 | |
| 112 | #include "tst_qabstracturiresolver.moc" |
| 113 | |
| 114 | // vim: et:ts=4:sw=4:sts=4 |
| 115 |
