diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-07-10 11:41:33 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-07-21 22:01:20 +0200 |
commit | d25589e0529732996e405aaff8d6c46b012e1601 (patch) | |
tree | 29b596d0c2ca0e36aa9aea65f426ed393c660e78 /src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp | |
parent | b50daef9771d8829fc7f808898cbe051a5464b79 (diff) |
QTestlib: Enable comparing QList against initializer lists/arrays
It is unnecessary to create a QList container just for comparison.
Split out helpers for comparing sequence sizes and sequences from
qCompare(QList) and add a template for an array with a non-type template
parameter for the size.
One can then write something like:
const int expected[] = {10, 12,...};
QCOMPARE(QFontDatabase.pointSizes(...), expected)
Unfortunately, any commas in such an array will be misread by macro expansion
as macro argument separators, so any expected array with more than one entry
needs an extra macro expanding __VA_ARGS__.
Change-Id: Ie7c8dc20bf669bbb25f6d7f8562455f8d03968c8
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp')
-rw-r--r-- | src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp b/src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp index cfa999a6f4..01f4e11eb4 100644 --- a/src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp +++ b/src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp @@ -49,6 +49,9 @@ ****************************************************************************/ #include <QTest> #include <QSqlDatabase> +#include <QtGui/qfontdatabase.h> + +#include <initializer_list> // dummy class TestBenchmark : public QObject @@ -246,3 +249,20 @@ QVERIFY2(file.open(QIODevice::WriteOnly), .arg(file.fileName()).arg(file.errorString()))); //! [33] } + +void compareListToArray() +{ +//! [34] + const int expected[] = {8, 10, 12, 16, 20, 24}; + QCOMPARE(QFontDatabase::standardSizes(), expected); +//! [34] +} + +void compareListToInitializerList() +{ +//! [35] + #define ARG(...) __VA_ARGS__ + QCOMPARE(QFontDatabase::standardSizes(), ARG({8, 10, 12, 16, 20, 24})); + #undef ARG +//! [35] +} |