1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Copyright (C) 2014 Keith Gardner <kreios4004@gmail.com>
5** Contact: https://www.qt.io/licensing/
6**
7** This file is part of the test suite of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:GPL-EXCEPT$
10** Commercial License Usage
11** Licensees holding valid commercial Qt licenses may use this file in
12** accordance with the commercial license agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and The Qt Company. For licensing terms
15** and conditions see https://www.qt.io/terms-conditions. For further
16** information use the contact form at https://www.qt.io/contact-us.
17**
18** GNU General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU
20** General Public License version 3 as published by the Free Software
21** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
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
30#include <QtTest/QtTest>
31#include <QtCore/qversionnumber.h>
32#include <QtCore/qlibraryinfo.h>
33
34class tst_QVersionNumber : public QObject
35{
36 Q_OBJECT
37
38private:
39 void singleInstanceData();
40 void comparisonData();
41
42private slots:
43 void initTestCase();
44 void constructorDefault();
45 void constructorVersioned_data();
46 void constructorVersioned();
47 void constructorExplicit();
48 void constructorCopy_data();
49 void constructorCopy();
50 void compareGreater_data();
51 void compareGreater();
52 void compareGreaterEqual_data();
53 void compareGreaterEqual();
54 void compareLess_data();
55 void compareLess();
56 void compareLessEqual_data();
57 void compareLessEqual();
58 void compareEqual_data();
59 void compareEqual();
60 void compareNotEqual_data();
61 void compareNotEqual();
62 void compare_data();
63 void compare();
64 void isPrefixOf_data();
65 void isPrefixOf();
66 void commonPrefix_data();
67 void commonPrefix();
68 void normalized_data();
69 void normalized();
70 void isNormalized_data();
71 void isNormalized();
72 void assignment_data();
73 void assignment();
74 void fromString_data();
75 void fromString();
76 void toString_data();
77 void toString();
78 void isNull_data();
79 void isNull();
80 void serialize_data();
81 void serialize();
82 void moveSemantics();
83 void qtVersion();
84};
85
86void tst_QVersionNumber::singleInstanceData()
87{
88 QTest::addColumn<QVector<int> >(name: "segments");
89 QTest::addColumn<QVersionNumber>(name: "expectedVersion");
90 QTest::addColumn<QString>(name: "expectedString");
91 QTest::addColumn<QString>(name: "constructionString");
92 QTest::addColumn<int>(name: "suffixIndex");
93 QTest::addColumn<bool>(name: "isNull");
94
95 // segments expectedVersion expectedString constructionString suffixIndex null
96 QTest::newRow(dataTag: "null") << QVector<int>() << QVersionNumber(QVector<int>()) << QString() << QString() << 0 << true;
97 QTest::newRow(dataTag: "text") << QVector<int>() << QVersionNumber(QVector<int>()) << QString() << QStringLiteral("text") << 0 << true;
98 QTest::newRow(dataTag: " text") << QVector<int>() << QVersionNumber(QVector<int>()) << QString() << QStringLiteral(" text") << 0 << true;
99 QTest::newRow(dataTag: "Empty String") << QVector<int>() << QVersionNumber(QVector<int>()) << QString() << QStringLiteral("Empty String") << 0 << true;
100 QTest::newRow(dataTag: "-1.-2") << (QVector<int>()) << QVersionNumber() << QStringLiteral("") << QStringLiteral("-1.-2") << 0 << true;
101 QTest::newRow(dataTag: "1.-2-3") << (QVector<int>() << 1) << QVersionNumber(QVector<int>() << 1) << QStringLiteral("1") << QStringLiteral("1.-2-3") << 1 << false;
102 QTest::newRow(dataTag: "1.2-3") << (QVector<int>() << 1 << 2) << QVersionNumber(QVector<int>() << 1 << 2) << QStringLiteral("1.2") << QStringLiteral("1.2-3") << 3 << false;
103 QTest::newRow(dataTag: "0") << (QVector<int>() << 0) << QVersionNumber(QVector<int>() << 0) << QStringLiteral("0") << QStringLiteral("0") << 1 << false;
104 QTest::newRow(dataTag: "0.1") << (QVector<int>() << 0 << 1) << QVersionNumber(QVector<int>() << 0 << 1) << QStringLiteral("0.1") << QStringLiteral("0.1") << 3 << false;
105 QTest::newRow(dataTag: "0.1.2") << (QVector<int>() << 0 << 1 << 2) << QVersionNumber(0, 1, 2) << QStringLiteral("0.1.2") << QStringLiteral("0.1.2") << 5 << false;
106 QTest::newRow(dataTag: "0.1.2alpha") << (QVector<int>() << 0 << 1 << 2) << QVersionNumber(0, 1, 2) << QStringLiteral("0.1.2") << QStringLiteral("0.1.2alpha") << 5 << false;
107 QTest::newRow(dataTag: "0.1.2-alpha") << (QVector<int>() << 0 << 1 << 2) << QVersionNumber(0, 1, 2) << QStringLiteral("0.1.2") << QStringLiteral("0.1.2-alpha") << 5 << false;
108 QTest::newRow(dataTag: "0.1.2.alpha") << (QVector<int>() << 0 << 1 << 2) << QVersionNumber(0, 1, 2) << QStringLiteral("0.1.2") << QStringLiteral("0.1.2.alpha") << 5 << false;
109 QTest::newRow(dataTag: "0.1.2.3alpha") << (QVector<int>() << 0 << 1 << 2 << 3) << QVersionNumber(QVector<int>() << 0 << 1 << 2 << 3) << QStringLiteral("0.1.2.3") << QStringLiteral("0.1.2.3alpha") << 7 << false;
110 QTest::newRow(dataTag: "0.1.2.3.alpha") << (QVector<int>() << 0 << 1 << 2 << 3) << QVersionNumber(QVector<int>() << 0 << 1 << 2 << 3) << QStringLiteral("0.1.2.3") << QStringLiteral("0.1.2.3.alpha") << 7 << false;
111 QTest::newRow(dataTag: "0.1.2.3.4.alpha") << (QVector<int>() << 0 << 1 << 2 << 3 << 4) << QVersionNumber(QVector<int>() << 0 << 1 << 2 << 3 << 4) << QStringLiteral("0.1.2.3.4") << QStringLiteral("0.1.2.3.4.alpha") << 9 << false;
112 QTest::newRow(dataTag: "0.1.2.3.4 alpha") << (QVector<int>() << 0 << 1 << 2 << 3 << 4) << QVersionNumber(QVector<int>() << 0 << 1 << 2 << 3 << 4) << QStringLiteral("0.1.2.3.4") << QStringLiteral("0.1.2.3.4 alpha") << 9 << false;
113 QTest::newRow(dataTag: "0.1.2.3.4 alp ha") << (QVector<int>() << 0 << 1 << 2 << 3 << 4) << QVersionNumber(QVector<int>() << 0 << 1 << 2 << 3 << 4) << QStringLiteral("0.1.2.3.4") << QStringLiteral("0.1.2.3.4 alp ha") << 9 << false;
114 QTest::newRow(dataTag: "0.1.2.3.4alp ha") << (QVector<int>() << 0 << 1 << 2 << 3 << 4) << QVersionNumber(QVector<int>() << 0 << 1 << 2 << 3 << 4) << QStringLiteral("0.1.2.3.4") << QStringLiteral("0.1.2.3.4alp ha") << 9 << false;
115 QTest::newRow(dataTag: "0.1.2.3.4alpha ") << (QVector<int>() << 0 << 1 << 2 << 3 << 4) << QVersionNumber(QVector<int>() << 0 << 1 << 2 << 3 << 4) << QStringLiteral("0.1.2.3.4") << QStringLiteral("0.1.2.3.4alpha ") << 9 << false;
116 QTest::newRow(dataTag: "0.1.2.3.4.5alpha ") << (QVector<int>() << 0 << 1 << 2 << 3 << 4 << 5) << QVersionNumber(QVector<int>() << 0 << 1 << 2 << 3 << 4 << 5) << QStringLiteral("0.1.2.3.4.5") << QStringLiteral("0.1.2.3.4.5alpha ") << 11 << false;
117 QTest::newRow(dataTag: "0.1.2.3.4.5.6alpha ") << (QVector<int>() << 0 << 1 << 2 << 3 << 4 << 5 << 6) << QVersionNumber(QVector<int>() << 0 << 1 << 2 << 3 << 4 << 5 << 6) << QStringLiteral("0.1.2.3.4.5.6") << QStringLiteral("0.1.2.3.4.5.6alpha ") << 13 << false;
118 QTest::newRow(dataTag: "0.1.2.3.4.5.6.7alpha ") << (QVector<int>() << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7) << QVersionNumber(QVector<int>() << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7) << QStringLiteral("0.1.2.3.4.5.6.7") << QStringLiteral("0.1.2.3.4.5.6.7alpha ") << 15 << false;
119 QTest::newRow(dataTag: "0.1.2.3.4.5.6.7.8alpha ") << (QVector<int>() << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8) << QVersionNumber(QVector<int>() << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8) << QStringLiteral("0.1.2.3.4.5.6.7.8") << QStringLiteral("0.1.2.3.4.5.6.7.8alpha ") << 17 << false;
120 QTest::newRow(dataTag: "0.1.2.3.4.5.6.7.8.alpha") << (QVector<int>() << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8) << QVersionNumber(QVector<int>() << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8) << QStringLiteral("0.1.2.3.4.5.6.7.8") << QStringLiteral("0.1.2.3.4.5.6.7.8.alpha") << 17 << false;
121 QTest::newRow(dataTag: "0.1.2.3.4.5.6.7.8 alpha") << (QVector<int>() << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8) << QVersionNumber(QVector<int>() << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8) << QStringLiteral("0.1.2.3.4.5.6.7.8") << QStringLiteral("0.1.2.3.4.5.6.7.8 alpha") << 17 << false;
122 QTest::newRow(dataTag: "0.1.2.3.4.5.6.7.8 alp ha") << (QVector<int>() << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8) << QVersionNumber(QVector<int>() << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8) << QStringLiteral("0.1.2.3.4.5.6.7.8") << QStringLiteral("0.1.2.3.4.5.6.7.8 alp ha") << 17 << false;
123 QTest::newRow(dataTag: "0.1.2.3.4.5.6.7.8alp ha") << (QVector<int>() << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8) << QVersionNumber(QVector<int>() << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8) << QStringLiteral("0.1.2.3.4.5.6.7.8") << QStringLiteral("0.1.2.3.4.5.6.7.8alp ha") << 17 << false;
124 QTest::newRow(dataTag: "10.09") << (QVector<int>() << 10 << 9) << QVersionNumber(QVector<int>() << 10 << 9) << QStringLiteral("10.9") << QStringLiteral("10.09") << 5 << false;
125 QTest::newRow(dataTag: "10.0x") << (QVector<int>() << 10 << 0) << QVersionNumber(QVector<int>() << 10 << 0) << QStringLiteral("10.0") << QStringLiteral("10.0x") << 4 << false;
126 QTest::newRow(dataTag: "10.0xTest") << (QVector<int>() << 10 << 0) << QVersionNumber(QVector<int>() << 10 << 0) << QStringLiteral("10.0") << QStringLiteral("10.0xTest") << 4 << false;
127 QTest::newRow(dataTag: "127.09") << (QVector<int>() << 127 << 9) << QVersionNumber(QVector<int>() << 127 << 9) << QStringLiteral("127.9") << QStringLiteral("127.09") << 6 << false;
128 QTest::newRow(dataTag: "127.0x") << (QVector<int>() << 127 << 0) << QVersionNumber(QVector<int>() << 127 << 0) << QStringLiteral("127.0") << QStringLiteral("127.0x") << 5 << false;
129 QTest::newRow(dataTag: "127.0xTest") << (QVector<int>() << 127 << 0) << QVersionNumber(QVector<int>() << 127 << 0) << QStringLiteral("127.0") << QStringLiteral("127.0xTest") << 5 << false;
130 QTest::newRow(dataTag: "128.09") << (QVector<int>() << 128 << 9) << QVersionNumber(QVector<int>() << 128 << 9) << QStringLiteral("128.9") << QStringLiteral("128.09") << 6 << false;
131 QTest::newRow(dataTag: "128.0x") << (QVector<int>() << 128 << 0) << QVersionNumber(QVector<int>() << 128 << 0) << QStringLiteral("128.0") << QStringLiteral("128.0x") << 5 << false;
132 QTest::newRow(dataTag: "128.0xTest") << (QVector<int>() << 128 << 0) << QVersionNumber(QVector<int>() << 128 << 0) << QStringLiteral("128.0") << QStringLiteral("128.0xTest") << 5 << false;
133}
134
135namespace UglyOperator {
136// ugh, but the alternative (operator <<) is even worse...
137static inline QVector<int> operator+(QVector<int> v, int i) { v.push_back(t: i); return v; }
138}
139
140void tst_QVersionNumber::comparisonData()
141{
142 QTest::addColumn<QVersionNumber>(name: "lhs");
143 QTest::addColumn<QVersionNumber>(name: "rhs");
144 QTest::addColumn<bool>(name: "equal");
145 QTest::addColumn<bool>(name: "notEqual");
146 QTest::addColumn<bool>(name: "lessThan");
147 QTest::addColumn<bool>(name: "lessThanOrEqual");
148 QTest::addColumn<bool>(name: "greaterThan");
149 QTest::addColumn<bool>(name: "greaterThanOrEqual");
150 QTest::addColumn<int>(name: "compareResult");
151 QTest::addColumn<bool>(name: "isPrefix");
152 QTest::addColumn<QVersionNumber>(name: "common");
153
154 // LHS RHS == != < <= > >= compareResult isPrefixOf commonPrefix
155 QTest::newRow(dataTag: "null, null") << QVersionNumber() << QVersionNumber() << true << false << false << true << false << true << 0 << true << QVersionNumber();
156 QTest::newRow(dataTag: "null, 0") << QVersionNumber() << QVersionNumber(0) << false << true << true << true << false << false << -1 << true << QVersionNumber();
157 QTest::newRow(dataTag: "0, null") << QVersionNumber(0) << QVersionNumber() << false << true << false << false << true << true << 1 << false << QVersionNumber();
158 QTest::newRow(dataTag: "0, 0") << QVersionNumber(0) << QVersionNumber(0) << true << false << false << true << false << true << 0 << true << QVersionNumber(0);
159 QTest::newRow(dataTag: "1.0, 1.0") << QVersionNumber(1, 0) << QVersionNumber(1, 0) << true << false << false << true << false << true << 0 << true << QVersionNumber(1, 0);
160 QTest::newRow(dataTag: "1, 1.0") << QVersionNumber(1) << QVersionNumber(1, 0) << false << true << true << true << false << false << -1 << true << QVersionNumber(1);
161 QTest::newRow(dataTag: "1.0, 1") << QVersionNumber(1, 0) << QVersionNumber(1) << false << true << false << false << true << true << 1 << false << QVersionNumber(1);
162
163 QTest::newRow(dataTag: "0.1.2, 0.1") << QVersionNumber(0, 1, 2) << QVersionNumber(0, 1) << false << true << false << false << true << true << 2 << false << QVersionNumber(0, 1);
164 QTest::newRow(dataTag: "0.1, 0.1.2") << QVersionNumber(0, 1) << QVersionNumber(0, 1, 2) << false << true << true << true << false << false << -2 << true << QVersionNumber(0, 1);
165 QTest::newRow(dataTag: "0.1.2, 0.1.2") << QVersionNumber(0, 1, 2) << QVersionNumber(0, 1, 2) << true << false << false << true << false << true << 0 << true << QVersionNumber(0, 1, 2);
166 QTest::newRow(dataTag: "0.1.2, 1.1.2") << QVersionNumber(0, 1, 2) << QVersionNumber(1, 1, 2) << false << true << true << true << false << false << -1 << false << QVersionNumber();
167 QTest::newRow(dataTag: "1.1.2, 0.1.2") << QVersionNumber(1, 1, 2) << QVersionNumber(0, 1, 2) << false << true << false << false << true << true << 1 << false << QVersionNumber();
168 QTest::newRow(dataTag: "1, -1") << QVersionNumber(1) << QVersionNumber(-1) << false << true << false << false << true << true << 2 << false << QVersionNumber();
169 QTest::newRow(dataTag: "-1, 1") << QVersionNumber(-1) << QVersionNumber(1) << false << true << true << true << false << false << -2 << false << QVersionNumber();
170 QTest::newRow(dataTag: "0.1, 0.-1") << QVersionNumber(0, 1) << QVersionNumber(0, -1) << false << true << false << false << true << true << 2 << false << QVersionNumber(0);
171 QTest::newRow(dataTag: "0.-1, 0.1") << QVersionNumber(0, -1) << QVersionNumber(0, 1) << false << true << true << true << false << false << -2 << false << QVersionNumber(0);
172 QTest::newRow(dataTag: "0.-1, 0") << QVersionNumber(0, -1) << QVersionNumber(0) << false << true << true << true << false << false << -1 << false << QVersionNumber(0);
173 QTest::newRow(dataTag: "0, 0.-1") << QVersionNumber(0) << QVersionNumber(0, -1) << false << true << false << false << true << true << 1 << true << QVersionNumber(0);
174
175 QTest::newRow(dataTag: "0.127.2, 0.127") << QVersionNumber(0, 127, 2) << QVersionNumber(0, 127) << false << true << false << false << true << true << 2 << false << QVersionNumber(0, 127);
176 QTest::newRow(dataTag: "0.127, 0.127.2") << QVersionNumber(0, 127) << QVersionNumber(0, 127, 2) << false << true << true << true << false << false << -2 << true << QVersionNumber(0, 127);
177 QTest::newRow(dataTag: "0.127.2, 0.127.2") << QVersionNumber(0, 127, 2) << QVersionNumber(0, 127, 2) << true << false << false << true << false << true << 0 << true << QVersionNumber(0, 127, 2);
178 QTest::newRow(dataTag: "0.127.2, 127.127.2") << QVersionNumber(0, 127, 2) << QVersionNumber(127, 127, 2) << false << true << true << true << false << false << -127 << false << QVersionNumber();
179 QTest::newRow(dataTag: "127.127.2, 0.127.2") << QVersionNumber(127, 127, 2) << QVersionNumber(0, 127, 2) << false << true << false << false << true << true << 127 << false << QVersionNumber();
180 QTest::newRow(dataTag: "127, -128") << QVersionNumber(127) << QVersionNumber(-128) << false << true << false << false << true << true << 255 << false << QVersionNumber();
181 QTest::newRow(dataTag: "-128, 127") << QVersionNumber(-128) << QVersionNumber(127) << false << true << true << true << false << false << -255 << false << QVersionNumber();
182 QTest::newRow(dataTag: "0.127, 0.-128") << QVersionNumber(0, 127) << QVersionNumber(0, -128) << false << true << false << false << true << true << 255 << false << QVersionNumber(0);
183 QTest::newRow(dataTag: "0.-128, 0.127") << QVersionNumber(0, -128) << QVersionNumber(0, 127) << false << true << true << true << false << false << -255 << false << QVersionNumber(0);
184 QTest::newRow(dataTag: "0.-128, 0") << QVersionNumber(0, -128) << QVersionNumber(0) << false << true << true << true << false << false << -128 << false << QVersionNumber(0);
185 QTest::newRow(dataTag: "0, 0.-128") << QVersionNumber(0) << QVersionNumber(0, -128) << false << true << false << false << true << true << 128 << true << QVersionNumber(0);
186
187 QTest::newRow(dataTag: "0.128.2, 0.128") << QVersionNumber(0, 128, 2) << QVersionNumber(0, 128) << false << true << false << false << true << true << 2 << false << QVersionNumber(0, 128);
188 QTest::newRow(dataTag: "0.128, 0.128.2") << QVersionNumber(0, 128) << QVersionNumber(0, 128, 2) << false << true << true << true << false << false << -2 << true << QVersionNumber(0, 128);
189 QTest::newRow(dataTag: "0.128.2, 0.128.2") << QVersionNumber(0, 128, 2) << QVersionNumber(0, 128, 2) << true << false << false << true << false << true << 0 << true << QVersionNumber(0, 128, 2);
190 QTest::newRow(dataTag: "0.128.2, 128.128.2") << QVersionNumber(0, 128, 2) << QVersionNumber(128, 128, 2) << false << true << true << true << false << false << -128 << false << QVersionNumber();
191 QTest::newRow(dataTag: "128.128.2, 0.128.2") << QVersionNumber(128, 128, 2) << QVersionNumber(0, 128, 2) << false << true << false << false << true << true << 128 << false << QVersionNumber();
192 QTest::newRow(dataTag: "128, -129") << QVersionNumber(128) << QVersionNumber(-129) << false << true << false << false << true << true << 257 << false << QVersionNumber();
193 QTest::newRow(dataTag: "-129, 128") << QVersionNumber(-129) << QVersionNumber(128) << false << true << true << true << false << false << -257 << false << QVersionNumber();
194 QTest::newRow(dataTag: "0.128, 0.-129") << QVersionNumber(0, 128) << QVersionNumber(0, -129) << false << true << false << false << true << true << 257 << false << QVersionNumber(0);
195 QTest::newRow(dataTag: "0.-129, 0.128") << QVersionNumber(0, -129) << QVersionNumber(0, 128) << false << true << true << true << false << false << -257 << false << QVersionNumber(0);
196 QTest::newRow(dataTag: "0.-129, 0") << QVersionNumber(0, -129) << QVersionNumber(0) << false << true << true << true << false << false << -129 << false << QVersionNumber(0);
197 QTest::newRow(dataTag: "0, 0.-129") << QVersionNumber(0) << QVersionNumber(0, -129) << false << true << false << false << true << true << 129 << true << QVersionNumber(0);
198
199 const QVector<int> common = QVector<int>() << 0 << 1 << 2 << 3 << 4 << 5 << 6;
200 using namespace UglyOperator;
201 QTest::newRow(dataTag: "0.1.2.3.4.5.6.0.1.2, 0.1.2.3.4.5.6.0.1") << QVersionNumber(common + 0 + 1 + 2) << QVersionNumber(common + 0 + 1) << false << true << false << false << true << true << 2 << false << QVersionNumber(common + 0 + 1);
202 QTest::newRow(dataTag: "0.1.2.3.4.5.6.0.1, 0.1.2.3.4.5.6.0.1.2") << QVersionNumber(common + 0 + 1) << QVersionNumber(common + 0 + 1 + 2) << false << true << true << true << false << false << -2 << true << QVersionNumber(common + 0 + 1);
203 QTest::newRow(dataTag: "0.1.2.3.4.5.6.0.1.2, 0.1.2.3.4.5.6.0.1.2") << QVersionNumber(common + 0 + 1 + 2) << QVersionNumber(common + 0 + 1 + 2) << true << false << false << true << false << true << 0 << true << QVersionNumber(common + 0 + 1 + 2);
204 QTest::newRow(dataTag: "0.1.2.3.4.5.6.0.1.2, 0.1.2.3.4.5.6.1.1.2") << QVersionNumber(common + 0 + 1 + 2) << QVersionNumber(common + 1 + 1 + 2) << false << true << true << true << false << false << -1 << false << QVersionNumber(common);
205 QTest::newRow(dataTag: "0.1.2.3.4.5.6.1.1.2, 0.1.2.3.4.5.6.0.1.2") << QVersionNumber(common + 1 + 1 + 2) << QVersionNumber(common + 0 + 1 + 2) << false << true << false << false << true << true << 1 << false << QVersionNumber(common);
206 QTest::newRow(dataTag: "0.1.2.3.4.5.6.1, 0.1.2.3.4.5.6.-1") << QVersionNumber(common + 1) << QVersionNumber(common + -1) << false << true << false << false << true << true << 2 << false << QVersionNumber(common);
207 QTest::newRow(dataTag: "0.1.2.3.4.5.6.-1, 0.1.2.3.4.5.6.1") << QVersionNumber(common + -1) << QVersionNumber(common + 1) << false << true << true << true << false << false << -2 << false << QVersionNumber(common);
208 QTest::newRow(dataTag: "0.1.2.3.4.5.6.0.1, 0.1.2.3.4.5.6.0.-1") << QVersionNumber(common + 0 + 1) << QVersionNumber(common + 0 + -1) << false << true << false << false << true << true << 2 << false << QVersionNumber(common + 0);
209 QTest::newRow(dataTag: "0.1.2.3.4.5.6.0.-1, 0.1.2.3.4.5.6.0.1") << QVersionNumber(common + 0 + -1) << QVersionNumber(common + 0 + 1) << false << true << true << true << false << false << -2 << false << QVersionNumber(common + 0);
210 QTest::newRow(dataTag: "0.1.2.3.4.5.6.0.-1, 0.1.2.3.4.5.6.0") << QVersionNumber(common + 0 + -1) << QVersionNumber(common + 0) << false << true << true << true << false << false << -1 << false << QVersionNumber(common + 0);
211 QTest::newRow(dataTag: "0.1.2.3.4.5.6.0, 0.1.2.3.4.5.6.0.-1") << QVersionNumber(common + 0) << QVersionNumber(common + 0 + -1) << false << true << false << false << true << true << 1 << true << QVersionNumber(common + 0);
212}
213
214void tst_QVersionNumber::initTestCase()
215{
216 qRegisterMetaType<QVector<int> >();
217}
218
219void tst_QVersionNumber::constructorDefault()
220{
221 QVersionNumber version;
222
223 QCOMPARE(version.majorVersion(), 0);
224 QCOMPARE(version.minorVersion(), 0);
225 QCOMPARE(version.microVersion(), 0);
226 QVERIFY(version.segments().isEmpty());
227}
228
229void tst_QVersionNumber::constructorVersioned_data()
230{
231 singleInstanceData();
232}
233
234void tst_QVersionNumber::constructorVersioned()
235{
236 QFETCH(QVector<int>, segments);
237 QFETCH(QVersionNumber, expectedVersion);
238
239 QVersionNumber version(segments);
240 QCOMPARE(version.majorVersion(), expectedVersion.majorVersion());
241 QCOMPARE(version.minorVersion(), expectedVersion.minorVersion());
242 QCOMPARE(version.microVersion(), expectedVersion.microVersion());
243 QCOMPARE(version.segments(), expectedVersion.segments());
244}
245
246void tst_QVersionNumber::constructorExplicit()
247{
248 QVersionNumber v1(1);
249 QVersionNumber v2(QVector<int>() << 1);
250
251 QCOMPARE(v1.segments(), v2.segments());
252
253 QVersionNumber v3(1, 2);
254 QVersionNumber v4(QVector<int>() << 1 << 2);
255
256 QCOMPARE(v3.segments(), v4.segments());
257
258 QVersionNumber v5(1, 2, 3);
259 QVersionNumber v6(QVector<int>() << 1 << 2 << 3);
260
261 QCOMPARE(v5.segments(), v6.segments());
262
263 QVersionNumber v7(4, 5, 6);
264 QVersionNumber v8 = {4, 5, 6};
265
266 QCOMPARE(v7.segments(), v8.segments());
267}
268
269void tst_QVersionNumber::constructorCopy_data()
270{
271 singleInstanceData();
272}
273
274void tst_QVersionNumber::constructorCopy()
275{
276 QFETCH(QVector<int>, segments);
277 QFETCH(QVersionNumber, expectedVersion);
278
279 QVersionNumber original(segments);
280 QVersionNumber version(original);
281
282 QCOMPARE(version.majorVersion(), expectedVersion.majorVersion());
283 QCOMPARE(version.minorVersion(), expectedVersion.minorVersion());
284 QCOMPARE(version.microVersion(), expectedVersion.microVersion());
285 QCOMPARE(version.segments(), expectedVersion.segments());
286}
287
288void tst_QVersionNumber::compareGreater_data()
289{
290 comparisonData();
291}
292
293void tst_QVersionNumber::compareGreater()
294{
295 QFETCH(QVersionNumber, lhs);
296 QFETCH(QVersionNumber, rhs);
297 QFETCH(bool, greaterThan);
298
299 QCOMPARE(lhs > rhs, greaterThan);
300}
301
302void tst_QVersionNumber::compareGreaterEqual_data()
303{
304 comparisonData();
305}
306
307void tst_QVersionNumber::compareGreaterEqual()
308{
309 QFETCH(QVersionNumber, lhs);
310 QFETCH(QVersionNumber, rhs);
311 QFETCH(bool, greaterThanOrEqual);
312
313 QCOMPARE(lhs >= rhs, greaterThanOrEqual);
314}
315
316void tst_QVersionNumber::compareLess_data()
317{
318 comparisonData();
319}
320
321void tst_QVersionNumber::compareLess()
322{
323 QFETCH(QVersionNumber, lhs);
324 QFETCH(QVersionNumber, rhs);
325 QFETCH(bool, lessThan);
326
327 QCOMPARE(lhs < rhs, lessThan);
328}
329
330void tst_QVersionNumber::compareLessEqual_data()
331{
332 comparisonData();
333}
334
335void tst_QVersionNumber::compareLessEqual()
336{
337 QFETCH(QVersionNumber, lhs);
338 QFETCH(QVersionNumber, rhs);
339 QFETCH(bool, lessThanOrEqual);
340
341 QCOMPARE(lhs <= rhs, lessThanOrEqual);
342}
343
344void tst_QVersionNumber::compareEqual_data()
345{
346 comparisonData();
347}
348
349void tst_QVersionNumber::compareEqual()
350{
351 QFETCH(QVersionNumber, lhs);
352 QFETCH(QVersionNumber, rhs);
353 QFETCH(bool, equal);
354
355 QCOMPARE(lhs == rhs, equal);
356}
357
358void tst_QVersionNumber::compareNotEqual_data()
359{
360 comparisonData();
361}
362
363void tst_QVersionNumber::compareNotEqual()
364{
365 QFETCH(QVersionNumber, lhs);
366 QFETCH(QVersionNumber, rhs);
367 QFETCH(bool, notEqual);
368
369 QCOMPARE(lhs != rhs, notEqual);
370}
371
372void tst_QVersionNumber::compare_data()
373{
374 comparisonData();
375}
376
377void tst_QVersionNumber::compare()
378{
379 QFETCH(QVersionNumber, lhs);
380 QFETCH(QVersionNumber, rhs);
381 QFETCH(int, compareResult);
382
383 QCOMPARE(QVersionNumber::compare(lhs, rhs), compareResult);
384}
385
386void tst_QVersionNumber::isPrefixOf_data()
387{
388 comparisonData();
389}
390
391void tst_QVersionNumber::isPrefixOf()
392{
393 QFETCH(QVersionNumber, lhs);
394 QFETCH(QVersionNumber, rhs);
395 QFETCH(bool, isPrefix);
396
397 QCOMPARE(lhs.isPrefixOf(rhs), isPrefix);
398}
399
400void tst_QVersionNumber::commonPrefix_data()
401{
402 comparisonData();
403}
404
405void tst_QVersionNumber::commonPrefix()
406{
407 QFETCH(QVersionNumber, lhs);
408 QFETCH(QVersionNumber, rhs);
409 QFETCH(QVersionNumber, common);
410
411 QVersionNumber calculatedPrefix = QVersionNumber::commonPrefix(v1: lhs, v2: rhs);
412 QCOMPARE(calculatedPrefix, common);
413 QCOMPARE(calculatedPrefix.segments(), common.segments());
414}
415
416void tst_QVersionNumber::normalized_data()
417{
418 QTest::addColumn<QVersionNumber>(name: "version");
419 QTest::addColumn<QVersionNumber>(name: "expected");
420
421 QTest::newRow(dataTag: "0") << QVersionNumber(0) << QVersionNumber();
422 QTest::newRow(dataTag: "1") << QVersionNumber(1) << QVersionNumber(1);
423 QTest::newRow(dataTag: "1.2") << QVersionNumber(1, 2) << QVersionNumber(1, 2);
424 QTest::newRow(dataTag: "1.0") << QVersionNumber(1, 0) << QVersionNumber(1);
425 QTest::newRow(dataTag: "1.0.0") << QVersionNumber(1, 0, 0) << QVersionNumber(1);
426 QTest::newRow(dataTag: "1.0.1") << QVersionNumber(1, 0, 1) << QVersionNumber(1, 0, 1);
427 QTest::newRow(dataTag: "1.0.1.0") << QVersionNumber(QVector<int>() << 1 << 0 << 1 << 0) << QVersionNumber(1, 0, 1);
428 QTest::newRow(dataTag: "0.0.1.0") << QVersionNumber(QVector<int>() << 0 << 0 << 1 << 0) << QVersionNumber(0, 0, 1);
429}
430
431void tst_QVersionNumber::normalized()
432{
433 QFETCH(QVersionNumber, version);
434 QFETCH(QVersionNumber, expected);
435
436 QCOMPARE(version.normalized(), expected);
437 QCOMPARE(std::move(version).normalized(), expected);
438}
439
440void tst_QVersionNumber::isNormalized_data()
441{
442 QTest::addColumn<QVersionNumber>(name: "version");
443 QTest::addColumn<bool>(name: "expected");
444
445 QTest::newRow(dataTag: "null") << QVersionNumber() << true;
446 QTest::newRow(dataTag: "0") << QVersionNumber(0) << false;
447 QTest::newRow(dataTag: "1") << QVersionNumber(1) << true;
448 QTest::newRow(dataTag: "1.2") << QVersionNumber(1, 2) << true;
449 QTest::newRow(dataTag: "1.0") << QVersionNumber(1, 0) << false;
450 QTest::newRow(dataTag: "1.0.0") << QVersionNumber(1, 0, 0) << false;
451 QTest::newRow(dataTag: "1.0.1") << QVersionNumber(1, 0, 1) << true;
452}
453
454void tst_QVersionNumber::isNormalized()
455{
456 QFETCH(QVersionNumber, version);
457 QFETCH(bool, expected);
458
459 QCOMPARE(version.isNormalized(), expected);
460}
461
462void tst_QVersionNumber::assignment_data()
463{
464 singleInstanceData();
465}
466
467void tst_QVersionNumber::assignment()
468{
469 QFETCH(QVector<int>, segments);
470 QFETCH(QVersionNumber, expectedVersion);
471
472 QVersionNumber original(segments);
473 QVersionNumber version;
474 version = original;
475
476 QCOMPARE(version.majorVersion(), expectedVersion.majorVersion());
477 QCOMPARE(version.minorVersion(), expectedVersion.minorVersion());
478 QCOMPARE(version.microVersion(), expectedVersion.microVersion());
479 QCOMPARE(version.segments(), expectedVersion.segments());
480}
481
482void tst_QVersionNumber::fromString_data()
483{
484 singleInstanceData();
485
486 const quint64 largerThanIntCanHold = quint64(std::numeric_limits<int>::max()) + 1;
487 const QString largerThanIntCanHoldString0 = QString::number(largerThanIntCanHold) + ".0";
488 const QString largerThanIntCanHoldString1 = "0." + QString::number(largerThanIntCanHold);
489
490 QTest::newRow(qPrintable(largerThanIntCanHoldString0))
491 << QVector<int>() << QVersionNumber() << QString() << largerThanIntCanHoldString0 << 0 << true;
492 QTest::newRow(qPrintable(largerThanIntCanHoldString1))
493 << QVector<int>(0) << QVersionNumber(0) << QStringLiteral("0") << largerThanIntCanHoldString1 << 1 << true;
494
495 const QString largerThanULongLongCanHoldString0 = QString::number(std::numeric_limits<qulonglong>::max()) + "0.0"; // 10x ULLONG_MAX
496 const QString largerThanULongLongCanHoldString1 = "0." + QString::number(std::numeric_limits<qulonglong>::max()) + '0'; // 10x ULLONG_MAX
497
498 QTest::newRow(qPrintable(largerThanULongLongCanHoldString0))
499 << QVector<int>() << QVersionNumber() << QString() << largerThanULongLongCanHoldString0 << 0 << true;
500 QTest::newRow(qPrintable(largerThanULongLongCanHoldString1))
501 << QVector<int>(0) << QVersionNumber(0) << QStringLiteral("0") << largerThanULongLongCanHoldString1 << 1 << true;
502}
503
504void tst_QVersionNumber::fromString()
505{
506 QFETCH(QString, constructionString);
507 QFETCH(QVersionNumber, expectedVersion);
508 QFETCH(int, suffixIndex);
509
510 int index;
511 QCOMPARE(QVersionNumber::fromString(constructionString), expectedVersion);
512 QCOMPARE(QVersionNumber::fromString(constructionString, &index), expectedVersion);
513 QCOMPARE(index, suffixIndex);
514
515 QCOMPARE(QVersionNumber::fromString(QStringView(constructionString)), expectedVersion);
516 QCOMPARE(QVersionNumber::fromString(QStringView(constructionString), &index), expectedVersion);
517 QCOMPARE(index, suffixIndex);
518
519 QCOMPARE(QVersionNumber::fromString(QLatin1String(constructionString.toLatin1())), expectedVersion);
520 QCOMPARE(QVersionNumber::fromString(QLatin1String(constructionString.toLatin1()), &index), expectedVersion);
521 QCOMPARE(index, suffixIndex);
522}
523
524void tst_QVersionNumber::toString_data()
525{
526 singleInstanceData();
527
528 // segments expectedVersion expectedString constructionString suffixIndex null
529 QTest::newRow(dataTag: "-1") << (QVector<int>() << -1) << QVersionNumber(-1) << QString("-1") << QString() << 0 << true;
530 QTest::newRow(dataTag: "-1.0") << (QVector<int>() << -1 << 0) << QVersionNumber(-1, 0) << QString("-1.0") << QString() << 0 << true;
531 QTest::newRow(dataTag: "1.-2") << (QVector<int>() << 1 << -2) << QVersionNumber(1, -2) << QString("1.-2") << QString() << 0 << true;
532}
533
534void tst_QVersionNumber::toString()
535{
536 QFETCH(QVersionNumber, expectedVersion);
537 QFETCH(QString, expectedString);
538
539 QCOMPARE(expectedVersion.toString(), expectedString);
540}
541
542void tst_QVersionNumber::isNull_data()
543{
544 singleInstanceData();
545}
546
547void tst_QVersionNumber::isNull()
548{
549 QFETCH(QVector<int>, segments);
550 QFETCH(bool, isNull);
551
552 QVersionNumber version(segments);
553
554 QCOMPARE(version.isNull(), isNull);
555}
556
557void tst_QVersionNumber::serialize_data()
558{
559 singleInstanceData();
560}
561
562void tst_QVersionNumber::serialize()
563{
564 QFETCH(QVector<int>, segments);
565
566 QVersionNumber original(segments);
567 QVersionNumber version;
568
569 QByteArray buffer;
570 {
571 QDataStream ostream(&buffer, QIODevice::WriteOnly);
572 ostream << original;
573 }
574 {
575 QDataStream istream(buffer);
576 istream >> version;
577 }
578
579 QCOMPARE(version.majorVersion(), original.majorVersion());
580 QCOMPARE(version.minorVersion(), original.minorVersion());
581 QCOMPARE(version.microVersion(), original.microVersion());
582 QCOMPARE(version.segments(), original.segments());
583}
584
585void tst_QVersionNumber::moveSemantics()
586{
587 // QVersionNumber(QVersionNumber &&)
588 {
589 QVersionNumber v1(1, 2, 3);
590 QVersionNumber v2 = std::move(v1);
591 QCOMPARE(v2, QVersionNumber(1, 2, 3));
592 }
593 // QVersionNumber &operator=(QVersionNumber &&)
594 {
595 QVersionNumber v1(1, 2, 3);
596 QVersionNumber v2;
597 v2 = std::move(v1);
598 QCOMPARE(v2, QVersionNumber(1, 2, 3));
599 }
600 // QVersionNumber(QVector<int> &&)
601 {
602 QVector<int> segments = QVector<int>() << 1 << 2 << 3;
603 QVersionNumber v1(segments);
604 QVersionNumber v2(std::move(segments));
605 QVERIFY(!v1.isNull());
606 QVERIFY(!v2.isNull());
607 QCOMPARE(v1, v2);
608 }
609#ifdef Q_COMPILER_REF_QUALIFIERS
610 // normalized()
611 {
612 QVersionNumber v(1, 0, 0);
613 QVERIFY(!v.isNull());
614 QVersionNumber nv;
615 nv = v.normalized();
616 QVERIFY(!v.isNull());
617 QVERIFY(!nv.isNull());
618 QVERIFY(nv.isNormalized());
619 nv = std::move(v).normalized();
620 QVERIFY(!nv.isNull());
621 QVERIFY(nv.isNormalized());
622 }
623 // segments()
624 {
625 QVersionNumber v(1, 2, 3);
626 QVERIFY(!v.isNull());
627 QVector<int> segments;
628 segments = v.segments();
629 QVERIFY(!v.isNull());
630 QVERIFY(!segments.empty());
631 segments = std::move(v).segments();
632 QVERIFY(!segments.empty());
633 }
634#endif
635}
636
637void tst_QVersionNumber::qtVersion()
638{
639 QVersionNumber v = QLibraryInfo::version();
640 QVERIFY(!v.isNull());
641 QCOMPARE(v.majorVersion(), QT_VERSION_MAJOR);
642 // we can't compare the minor and micro version:
643 // the library may change without the test being recompiled
644
645 QCOMPARE(v.toString(), QString(qVersion()));
646}
647
648QTEST_APPLESS_MAIN(tst_QVersionNumber)
649
650#include "tst_qversionnumber.moc"
651

source code of qtbase/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp