| 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 Qt Charts module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL$ |
| 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 or (at your option) any later version |
| 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
| 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
| 22 | ** included in the packaging of this file. Please review the following |
| 23 | ** information to ensure the GNU General Public License requirements will |
| 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 25 | ** |
| 26 | ** $QT_END_LICENSE$ |
| 27 | ** |
| 28 | ****************************************************************************/ |
| 29 | #include <QtTest/QtTest> |
| 30 | #include <QtQml/QQmlEngine> |
| 31 | #include <QtQml/QQmlComponent> |
| 32 | #include "tst_definitions.h" |
| 33 | |
| 34 | class tst_qml : public QObject |
| 35 | { |
| 36 | Q_OBJECT |
| 37 | |
| 38 | public slots: |
| 39 | void initTestCase(); |
| 40 | void cleanupTestCase(); |
| 41 | void init(); |
| 42 | void cleanup(); |
| 43 | private slots: |
| 44 | void checkPlugin_data(); |
| 45 | void checkPlugin(); |
| 46 | private: |
| 47 | QString componentErrors(const QQmlComponent* component) const; |
| 48 | QString imports_1_1(); |
| 49 | QString imports_1_3(); |
| 50 | QString imports_1_4(); |
| 51 | QString imports_2_0(); |
| 52 | QString imports_2_1(); |
| 53 | |
| 54 | }; |
| 55 | |
| 56 | QString tst_qml::componentErrors(const QQmlComponent* component) const |
| 57 | { |
| 58 | Q_ASSERT(component); |
| 59 | |
| 60 | QStringList errors; |
| 61 | |
| 62 | foreach (QQmlError const& error, component->errors()) { |
| 63 | errors << error.toString(); |
| 64 | } |
| 65 | |
| 66 | return errors.join(sep: "\n"); |
| 67 | } |
| 68 | |
| 69 | QString tst_qml::imports_1_1() |
| 70 | { |
| 71 | return "import QtQuick 2.0 \n" |
| 72 | "import QtCharts 1.1 \n"; |
| 73 | } |
| 74 | |
| 75 | QString tst_qml::imports_1_3() |
| 76 | { |
| 77 | return "import QtQuick 2.0 \n" |
| 78 | "import QtCharts 1.3 \n"; |
| 79 | } |
| 80 | |
| 81 | QString tst_qml::imports_1_4() |
| 82 | { |
| 83 | return "import QtQuick 2.0 \n" |
| 84 | "import QtCharts 1.4 \n"; |
| 85 | } |
| 86 | |
| 87 | QString tst_qml::imports_2_0() |
| 88 | { |
| 89 | return "import QtQuick 2.0 \n" |
| 90 | "import QtCharts 2.0 \n"; |
| 91 | } |
| 92 | |
| 93 | QString tst_qml::imports_2_1() |
| 94 | { |
| 95 | return "import QtQuick 2.1 \n" |
| 96 | "import QtCharts 2.1 \n"; |
| 97 | } |
| 98 | |
| 99 | void tst_qml::initTestCase() |
| 100 | { |
| 101 | } |
| 102 | |
| 103 | void tst_qml::cleanupTestCase() |
| 104 | { |
| 105 | } |
| 106 | |
| 107 | void tst_qml::init() |
| 108 | { |
| 109 | |
| 110 | } |
| 111 | |
| 112 | void tst_qml::cleanup() |
| 113 | { |
| 114 | |
| 115 | } |
| 116 | |
| 117 | void tst_qml::checkPlugin_data() |
| 118 | { |
| 119 | QTest::addColumn<QString>(name: "source"); |
| 120 | |
| 121 | QTest::newRow(dataTag: "createChartView") << imports_1_1() + "ChartView{}"; |
| 122 | QTest::newRow(dataTag: "XYPoint") << imports_1_1() + "XYPoint{}"; |
| 123 | QTest::newRow(dataTag: "scatterSeries") << imports_1_1() + "ScatterSeries{}"; |
| 124 | QTest::newRow(dataTag: "lineSeries") << imports_1_1() + "LineSeries{}"; |
| 125 | QTest::newRow(dataTag: "splineSeries") << imports_1_1() + "SplineSeries{}"; |
| 126 | QTest::newRow(dataTag: "areaSeries") << imports_1_1() + "AreaSeries{}"; |
| 127 | QTest::newRow(dataTag: "barSeries") << imports_1_1() + "BarSeries{}"; |
| 128 | QTest::newRow(dataTag: "stackedBarSeries") << imports_1_1() + "StackedBarSeries{}"; |
| 129 | QTest::newRow(dataTag: "precentBarSeries") << imports_1_1() + "PercentBarSeries{}"; |
| 130 | QTest::newRow(dataTag: "horizonatlBarSeries") << imports_1_1() + "HorizontalBarSeries{}"; |
| 131 | QTest::newRow(dataTag: "horizonatlStackedBarSeries") << imports_1_1() + "HorizontalStackedBarSeries{}"; |
| 132 | QTest::newRow(dataTag: "horizonatlstackedBarSeries") << imports_1_1() + "HorizontalPercentBarSeries{}"; |
| 133 | QTest::newRow(dataTag: "pieSeries") << imports_1_1() + "PieSeries{}"; |
| 134 | QTest::newRow(dataTag: "PieSlice") << imports_1_1() + "PieSlice{}"; |
| 135 | QTest::newRow(dataTag: "BarSet") << imports_1_1() + "BarSet{}"; |
| 136 | QTest::newRow(dataTag: "HXYModelMapper") << imports_1_1() + "HXYModelMapper{}"; |
| 137 | QTest::newRow(dataTag: "VXYModelMapper") << imports_1_1() + "VXYModelMapper{}"; |
| 138 | QTest::newRow(dataTag: "HPieModelMapper") << imports_1_1() + "HPieModelMapper{}"; |
| 139 | QTest::newRow(dataTag: "HPieModelMapper") << imports_1_1() + "HPieModelMapper{}"; |
| 140 | QTest::newRow(dataTag: "HBarModelMapper") << imports_1_1() + "HBarModelMapper{}"; |
| 141 | QTest::newRow(dataTag: "VBarModelMapper") << imports_1_1() + "VBarModelMapper{}"; |
| 142 | QTest::newRow(dataTag: "ValueAxis") << imports_1_1() + "ValueAxis{}"; |
| 143 | #ifndef QT_QREAL_IS_FLOAT |
| 144 | QTest::newRow(dataTag: "DateTimeAxis") << imports_1_1() + "DateTimeAxis{}"; |
| 145 | #endif |
| 146 | QTest::newRow(dataTag: "CategoryAxis") << imports_1_1() + "CategoryAxis{}"; |
| 147 | QTest::newRow(dataTag: "CategoryRange") << imports_1_1() + "CategoryRange{}"; |
| 148 | QTest::newRow(dataTag: "BarCategoryAxis") << imports_1_1() + "BarCategoryAxis{}"; |
| 149 | |
| 150 | QTest::newRow(dataTag: "createPolarChartView") << imports_1_3() + "PolarChartView{}"; |
| 151 | QTest::newRow(dataTag: "LogValueAxis") << imports_1_3() + "LogValueAxis{}"; |
| 152 | QTest::newRow(dataTag: "BoxPlotSeries") << imports_1_3() + "BoxPlotSeries{}"; |
| 153 | QTest::newRow(dataTag: "BoxSet") << imports_1_3() + "BoxSet{}"; |
| 154 | |
| 155 | QTest::newRow(dataTag: "createChartView_2_0") << imports_2_0() + "ChartView{}"; |
| 156 | QTest::newRow(dataTag: "XYPoint_2_0") << imports_2_0() + "XYPoint{}"; |
| 157 | QTest::newRow(dataTag: "scatterSeries_2_0") << imports_2_0() + "ScatterSeries{}"; |
| 158 | QTest::newRow(dataTag: "lineSeries_2_0") << imports_2_0() + "LineSeries{}"; |
| 159 | QTest::newRow(dataTag: "splineSeries_2_0") << imports_2_0() + "SplineSeries{}"; |
| 160 | QTest::newRow(dataTag: "areaSeries_2_0") << imports_2_0() + "AreaSeries{}"; |
| 161 | QTest::newRow(dataTag: "barSeries_2_0") << imports_2_0() + "BarSeries{}"; |
| 162 | QTest::newRow(dataTag: "stackedBarSeries_2_0") << imports_2_0() + "StackedBarSeries{}"; |
| 163 | QTest::newRow(dataTag: "precentBarSeries_2_0") << imports_2_0() + "PercentBarSeries{}"; |
| 164 | QTest::newRow(dataTag: "horizonatlBarSeries_2_0") << imports_2_0() + "HorizontalBarSeries{}"; |
| 165 | QTest::newRow(dataTag: "horizonatlStackedBarSeries_2_0") |
| 166 | << imports_2_0() + "HorizontalStackedBarSeries{}"; |
| 167 | QTest::newRow(dataTag: "horizonatlstackedBarSeries_2_0") |
| 168 | << imports_2_0() + "HorizontalPercentBarSeries{}"; |
| 169 | QTest::newRow(dataTag: "pieSeries_2_0") << imports_2_0() + "PieSeries{}"; |
| 170 | QTest::newRow(dataTag: "PieSlice_2_0") << imports_2_0() + "PieSlice{}"; |
| 171 | QTest::newRow(dataTag: "BarSet_2_0") << imports_2_0() + "BarSet{}"; |
| 172 | QTest::newRow(dataTag: "HXYModelMapper_2_0") << imports_2_0() + "HXYModelMapper{}"; |
| 173 | QTest::newRow(dataTag: "VXYModelMapper_2_0") << imports_2_0() + "VXYModelMapper{}"; |
| 174 | QTest::newRow(dataTag: "HPieModelMapper_2_0") << imports_2_0() + "HPieModelMapper{}"; |
| 175 | QTest::newRow(dataTag: "HPieModelMapper_2_0") << imports_2_0() + "HPieModelMapper{}"; |
| 176 | QTest::newRow(dataTag: "HBarModelMapper_2_0") << imports_2_0() + "HBarModelMapper{}"; |
| 177 | QTest::newRow(dataTag: "VBarModelMapper_2_0") << imports_2_0() + "VBarModelMapper{}"; |
| 178 | QTest::newRow(dataTag: "ValueAxis_2_0") << imports_2_0() + "ValueAxis{}"; |
| 179 | #ifndef QT_QREAL_IS_FLOAT |
| 180 | QTest::newRow(dataTag: "DateTimeAxis_2_0") << imports_2_0() + "DateTimeAxis{}"; |
| 181 | #endif |
| 182 | QTest::newRow(dataTag: "CategoryAxis_2_0") << imports_2_0() + "CategoryAxis{}"; |
| 183 | QTest::newRow(dataTag: "CategoryRange_2_0") << imports_2_0() + "CategoryRange{}"; |
| 184 | QTest::newRow(dataTag: "BarCategoryAxis_2_0") << imports_2_0() + "BarCategoryAxis{}"; |
| 185 | QTest::newRow(dataTag: "createPolarChartView_2_0") << imports_2_0() + "PolarChartView{}"; |
| 186 | QTest::newRow(dataTag: "LogValueAxis_2_0") << imports_2_0() + "LogValueAxis{}"; |
| 187 | QTest::newRow(dataTag: "BoxPlotSeries_2_0") << imports_2_0() + "BoxPlotSeries{}"; |
| 188 | QTest::newRow(dataTag: "BoxSet_2_0") << imports_2_0() + "BoxSet{}"; |
| 189 | |
| 190 | QTest::newRow(dataTag: "CategoryAxis_2_1") << imports_2_1() + "CategoryAxis{}"; |
| 191 | QTest::newRow(dataTag: "ScatterSeries_2_1") << imports_2_1() + "ScatterSeries{}"; |
| 192 | QTest::newRow(dataTag: "LineSeries_2_1") << imports_2_1() + "LineSeries{}"; |
| 193 | QTest::newRow(dataTag: "SplineSeries_2_1") << imports_2_1() + "SplineSeries{}"; |
| 194 | } |
| 195 | |
| 196 | void tst_qml::checkPlugin() |
| 197 | { |
| 198 | QFETCH(QString, source); |
| 199 | QQmlEngine engine; |
| 200 | engine.addImportPath(dir: QString::fromLatin1(str: "%1/%2").arg(args: QCoreApplication::applicationDirPath(), args: QLatin1String( "qml"))); |
| 201 | QQmlComponent component(&engine); |
| 202 | component.setData(source.toLatin1(), baseUrl: QUrl()); |
| 203 | QVERIFY2(!component.isError(), qPrintable(componentErrors(&component))); |
| 204 | TRY_COMPARE(component.status(), QQmlComponent::Ready); |
| 205 | QObject *obj = component.create(); |
| 206 | QVERIFY(obj != 0); |
| 207 | delete obj; |
| 208 | } |
| 209 | |
| 210 | QTEST_MAIN(tst_qml) |
| 211 | |
| 212 | #include "tst_qml.moc" |
| 213 | |
| 214 |
