1/****************************************************************************
2 * Copyright (C) 2016-2018 Woboq GmbH
3 * Olivier Goffart <ogoffart at woboq.com>
4 * https://woboq.com/
5 *
6 * This file is part of Verdigris: a way to use Qt without moc.
7 * https://github.com/woboq/verdigris
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation, either version 3 of the
12 * License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this program.
21 * If not, see <http://www.gnu.org/licenses/>.
22 */
23
24// Just some unit test for internal functions
25
26#include <wobjectimpl.h>
27#include <QtTest/QtTest>
28
29namespace w_internal {
30
31//static_assert(std::is_same<decltype(viewValidLiterals()), StringViewArray<>>::value, "");
32constexpr auto vl1 = viewValidLiterals("H", "el");
33static_assert(std::is_same<std::decay_t<decltype(vl1)>, StringViewArray<2>>::value, "");
34static_assert (vl1[0].size() == 2, "");
35static_assert (vl1[1].size() == 3, "");
36static_assert(vl1[0].b[0] == 'H', "");
37static_assert(vl1[0].b[1] == '\0', "");
38static_assert(std::is_same<decltype(viewValidLiterals("H", "", "el")), StringViewArray<1>>::value, "");
39static_assert(viewValidLiterals("H", "", "el")[0].b[0] == 'H', "");
40static_assert(viewValidLiterals("H", "", "el")[0].b[1] == '\0', "");
41
42static_assert(std::is_same<decltype(viewValidTails()), StringViewArray<>>::value, "");
43static_assert(viewValidTails<2,1,3>("H", "", "el")[0].b[1] == '\0', "");
44
45}
46
47namespace testEnum {
48 enum ME1 {};
49 enum class ME2 {};
50 static_assert(w_internal::EnumIsScoped<ME1>::Value == 0, "");
51 static_assert(w_internal::EnumIsScoped<ME2>::Value == 2, "");
52}
53
54class tst_Internal : public QObject
55{
56 W_OBJECT(tst_Internal)
57
58private slots:
59 void removedScope() {
60 QCOMPARE(w_internal::removedScopeSize("foo"), int(sizeof("foo")));
61 QCOMPARE(w_internal::removedScopeSize("::foo"), int(sizeof("foo")));
62 QCOMPARE(w_internal::removedScopeSize("hallo::fo"), int(sizeof("fo")));
63 QCOMPARE(w_internal::removedScopeSize("x::hallo::fo"), int(sizeof("fo")));
64
65 using namespace w_internal;
66 QCOMPARE(QByteArray(w_internal::viewValidTails<w_internal::removedScopeSize("foo")>("foo")[0].b), QByteArray("foo"));
67 QCOMPARE(QByteArray(W_PARAM_TOSTRING_REMOVE_SCOPE(::foo)[0].b), QByteArray("foo"));
68 QCOMPARE(QByteArray(W_PARAM_TOSTRING_REMOVE_SCOPE(::foo, hallo::fo)[1].b), QByteArray("fo"));
69 QCOMPARE(QByteArray(W_PARAM_TOSTRING_REMOVE_SCOPE(::foo, hallo::fo, x::hallo::fo)[2].b), QByteArray("fo"));
70 }
71 W_SLOT(removedScope)
72
73};
74
75W_OBJECT_IMPL(tst_Internal)
76
77QTEST_MAIN(tst_Internal)
78