moc: Add a test for QtMocHelpers
Change-Id: I8a96935cf6c742259c9dfffd17e9a702717a18bf Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
This commit is contained in:
parent
a2a315eaa2
commit
d31f6496c9
@ -1,6 +1,8 @@
|
|||||||
# Copyright (C) 2022 The Qt Company Ltd.
|
# Copyright (C) 2022 The Qt Company Ltd.
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
add_subdirectory(mochelpers)
|
||||||
|
|
||||||
# QTBUG-88538
|
# QTBUG-88538
|
||||||
if(NOT ANDROID AND NOT IOS)
|
if(NOT ANDROID AND NOT IOS)
|
||||||
add_subdirectory(qmakelib)
|
add_subdirectory(qmakelib)
|
||||||
|
17
tests/auto/tools/mochelpers/CMakeLists.txt
Normal file
17
tests/auto/tools/mochelpers/CMakeLists.txt
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# Copyright (C) 2024 Intel Corporation.
|
||||||
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
#####################################################################
|
||||||
|
## tst_qmetaenum Test:
|
||||||
|
#####################################################################
|
||||||
|
|
||||||
|
if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
|
||||||
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
project(tst_mochelpers LANGUAGES CXX)
|
||||||
|
find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
qt_internal_add_test(tst_mochelpers
|
||||||
|
SOURCES
|
||||||
|
tst_mochelpers.cpp
|
||||||
|
)
|
50
tests/auto/tools/mochelpers/tst_mochelpers.cpp
Normal file
50
tests/auto/tools/mochelpers/tst_mochelpers.cpp
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
// Copyright (C) 2024 Intel Corporation.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
||||||
|
|
||||||
|
// Testing qtmochelpers.h is probably pointless... if there's a problem with it
|
||||||
|
// then you most likely can't compile this test in the first place.
|
||||||
|
#include <QtCore/qtmochelpers.h>
|
||||||
|
|
||||||
|
#include <QTest>
|
||||||
|
|
||||||
|
#include <QtCore/qobject.h>
|
||||||
|
|
||||||
|
#include <initializer_list>
|
||||||
|
|
||||||
|
class tst_MocHelpers : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
private slots:
|
||||||
|
void stringData();
|
||||||
|
};
|
||||||
|
|
||||||
|
template <int Count, size_t StringSize>
|
||||||
|
void verifyStringData(const QtMocHelpers::StringData<Count, StringSize> &data,
|
||||||
|
std::initializer_list<const char *> strings)
|
||||||
|
{
|
||||||
|
QCOMPARE(std::size(strings), size_t(Count) / 2);
|
||||||
|
ptrdiff_t i = 0;
|
||||||
|
for (const char *str : strings) {
|
||||||
|
uint offset = data.offsetsAndSizes[i++] - sizeof(data.offsetsAndSizes);
|
||||||
|
uint len = data.offsetsAndSizes[i++];
|
||||||
|
QByteArrayView result(data.stringdata0 + offset, len);
|
||||||
|
|
||||||
|
QCOMPARE(len, strlen(str));
|
||||||
|
QCOMPARE(result, str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_MocHelpers::stringData()
|
||||||
|
{
|
||||||
|
#define CHECK(...) \
|
||||||
|
verifyStringData(QtMocHelpers::stringData(__VA_ARGS__), { __VA_ARGS__ })
|
||||||
|
|
||||||
|
QTest::setThrowOnFail(true);
|
||||||
|
CHECK("Hello");
|
||||||
|
CHECK("Hello", "World");
|
||||||
|
CHECK("Hello", "", "World");
|
||||||
|
#undef CHECK
|
||||||
|
}
|
||||||
|
|
||||||
|
QTEST_MAIN(tst_MocHelpers)
|
||||||
|
#include "tst_mochelpers.moc"
|
Loading…
x
Reference in New Issue
Block a user