QtBase  v6.3.1
tst_qmakearray.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2018 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 <QTest>
30 
31 #include <private/qmakearray_p.h>
32 
33 
34 class tst_QMakeArray : public QObject
35 {
36  Q_OBJECT
37 
38 private slots:
39  void quicksort();
40 };
41 
42 struct Pair {
43  unsigned int key;
44  unsigned int val;
45 
46  constexpr bool operator <=(const Pair &that) const noexcept
47  {
48  return key <= that.key;
49  }
50 
51  constexpr bool operator<(const Pair &that) const noexcept
52  {
53  return key < that.key;
54  }
55 
56  constexpr bool operator==(const Pair &that) const noexcept
57  {
58  return key == that.key;
59  }
60 };
61 
62 template<std::size_t Key, std::size_t Val>
64 {
65  using Type = Pair;
66  static constexpr Type data() noexcept { return Type{Key, Val}; }
67 };
68 
69 void tst_QMakeArray::quicksort()
70 {
71  constexpr const auto sorted_array = qMakeArray(
85  >::Data{});
86  static_assert(sorted_array.size() == 12, "sorted_array.size() != 12");
87  QCOMPARE(sorted_array[0].key, 1u);
88  QCOMPARE(sorted_array[1].key, 1u);
89  QCOMPARE(sorted_array[2].key, 2u);
90  QCOMPARE(sorted_array[3].key, 3u);
91  QCOMPARE(sorted_array[4].key, 4u);
92  QCOMPARE(sorted_array[5].key, 5u);
93  QCOMPARE(sorted_array[6].key, 5u);
94  QCOMPARE(sorted_array[7].key, 6u);
95  QCOMPARE(sorted_array[8].key, 7u);
96  QCOMPARE(sorted_array[9].key, 8u);
97  QCOMPARE(sorted_array[10].key, 10u);
98  QCOMPARE(sorted_array[11].key, 10u);
99 }
100 
101 
103 #include "tst_qmakearray.moc"
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
QCOMPARE(spy.count(), 1)
constexpr QtPrivate::ArrayType< ManualType, Types... > qMakeArray(Types &&... t) noexcept
Definition: qmakearray_p.h:160
GLuint64 key
#define QTEST_APPLESS_MAIN(TestObject)
Definition: qtest.h:632
#define Q_OBJECT
Definition: qtmetamacros.h:158
#define slots
Definition: qtmetamacros.h:76
constexpr bool operator<(const Pair &that) const noexcept
unsigned int val
constexpr bool operator<=(const Pair &that) const noexcept
constexpr bool operator==(const Pair &that) const noexcept
unsigned int key
static constexpr Type data() noexcept