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 <QtTest/QtTest>
30
31#include <private/qoffsetstringarray_p.h>
32
33
34class tst_QOffsetStringArray : public QObject
35{
36 Q_OBJECT
37
38private slots:
39 void init();
40 void access();
41};
42
43
44constexpr const auto messages = qOffsetStringArray(
45 strings: "level - 0",
46 strings: "level - 1",
47 strings: "level - 2",
48 strings: "level - 3",
49 strings: "level - 4",
50 strings: ""
51);
52
53constexpr const auto messages257 = qOffsetStringArray(
54 strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "",
55 strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "",
56 strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "",
57 strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "",
58 strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "",
59 strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "",
60 strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "",
61 strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "",
62 strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "",
63 strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "",
64
65 strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "",
66 strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "",
67 strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "",
68 strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "",
69 strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "",
70 strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "",
71 strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "",
72 strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "",
73 strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "",
74 strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "",
75
76 strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "",
77 strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "",
78 strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "",
79 strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "",
80 strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "",
81 strings: "", strings: "", strings: "", strings: "", strings: "", strings: "", strings: "end"
82);
83
84constexpr const auto messagesBigOffsets = qOffsetStringArray(
85 strings: " 10 20 30 40 50 60 70 80 90",
86 strings: " 10 20 30 40 50 60 70 80 90",
87 strings: " 10 20 30 40 50 60 70 80 90",
88 strings: " 10 20 30 40 50 60 70 80 90"
89);
90
91void tst_QOffsetStringArray::init()
92{
93 static_assert(messages.sizeString == 51, "message.sizeString");
94 static_assert(messages.sizeOffsets == 6, "message.sizeOffsets");
95 static_assert(std::is_same<decltype(messages)::Type, quint8>::value, "messages::Type != quint8");
96
97 static_assert(messages257.sizeOffsets == 257, "messages257.sizeOffsets");
98 static_assert(messages257.sizeString == 260, "messages257.sizeString");
99 static_assert(std::is_same<decltype(messages257)::Type, quint16>::value,
100 "messages257::Type != quint16");
101
102 static_assert(messagesBigOffsets.sizeOffsets == 4, "messagesBigOffsets.sizeOffsets");
103 static_assert(messagesBigOffsets.sizeString == 364, "messagesBigOffsets.sizeString");
104 static_assert(std::is_same<decltype(messagesBigOffsets)::Type, quint16>::value,
105 "messagesBigOffsets::Type != quint16");
106}
107
108void tst_QOffsetStringArray::access()
109{
110 QCOMPARE(messages[0], "level - 0");
111 QCOMPARE(messages[1], "level - 1");
112 QCOMPARE(messages[2], "level - 2");
113 QCOMPARE(messages[3], "level - 3");
114 QCOMPARE(messages[4], "level - 4");
115 QCOMPARE(messages[5], "");
116 QCOMPARE(messages[6], "");
117}
118
119
120QTEST_APPLESS_MAIN(tst_QOffsetStringArray)
121#include "tst_qoffsetstringarray.moc"
122

source code of qtbase/tests/auto/corelib/tools/qoffsetstringarray/tst_qoffsetstringarray.cpp