diff options
Diffstat (limited to 'tests/auto/corelib/tools/qoffsetstringarray')
-rw-r--r-- | tests/auto/corelib/tools/qoffsetstringarray/CMakeLists.txt | 18 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qoffsetstringarray/tst_qoffsetstringarray.cpp | 68 |
2 files changed, 42 insertions, 44 deletions
diff --git a/tests/auto/corelib/tools/qoffsetstringarray/CMakeLists.txt b/tests/auto/corelib/tools/qoffsetstringarray/CMakeLists.txt index 7584d580ec..d0205cfa15 100644 --- a/tests/auto/corelib/tools/qoffsetstringarray/CMakeLists.txt +++ b/tests/auto/corelib/tools/qoffsetstringarray/CMakeLists.txt @@ -1,12 +1,26 @@ -# Generated from qoffsetstringarray.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qoffsetstringarray Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qoffsetstringarray LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qoffsetstringarray SOURCES tst_qoffsetstringarray.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate ) + +if (CLANG) + target_compile_options(tst_qoffsetstringarray + PUBLIC -fbracket-depth=512) +elseif (GCC) + # fconstexpr-depth= defaults to 512 +endif() diff --git a/tests/auto/corelib/tools/qoffsetstringarray/tst_qoffsetstringarray.cpp b/tests/auto/corelib/tools/qoffsetstringarray/tst_qoffsetstringarray.cpp index 9445366efc..dbb24e7af4 100644 --- a/tests/auto/corelib/tools/qoffsetstringarray/tst_qoffsetstringarray.cpp +++ b/tests/auto/corelib/tools/qoffsetstringarray/tst_qoffsetstringarray.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -38,6 +13,7 @@ class tst_QOffsetStringArray : public QObject private slots: void init(); void access(); + void contains(); }; @@ -46,8 +22,7 @@ constexpr const auto messages = qOffsetStringArray( "level - 1", "level - 2", "level - 3", - "level - 4", - "" + "level - 4" ); constexpr const auto messages257 = qOffsetStringArray( @@ -90,19 +65,17 @@ constexpr const auto messagesBigOffsets = qOffsetStringArray( void tst_QOffsetStringArray::init() { - static_assert(messages.sizeString == 51, "message.sizeString"); - static_assert(messages.sizeOffsets == 6, "message.sizeOffsets"); - static_assert(std::is_same<decltype(messages)::Type, quint8>::value, "messages::Type != quint8"); - - static_assert(messages257.sizeOffsets == 257, "messages257.sizeOffsets"); - static_assert(messages257.sizeString == 260, "messages257.sizeString"); - static_assert(std::is_same<decltype(messages257)::Type, quint16>::value, - "messages257::Type != quint16"); - - static_assert(messagesBigOffsets.sizeOffsets == 4, "messagesBigOffsets.sizeOffsets"); - static_assert(messagesBigOffsets.sizeString == 364, "messagesBigOffsets.sizeString"); - static_assert(std::is_same<decltype(messagesBigOffsets)::Type, quint16>::value, - "messagesBigOffsets::Type != quint16"); + static_assert(messages.m_string.size() == 50); + static_assert(messages.m_offsets.size() == 6); + static_assert(std::is_same_v<decltype(messages.m_offsets)::value_type, quint8>); + + static_assert(messages257.m_offsets.size() == 258); + static_assert(messages257.m_string.size() == 260); + static_assert(std::is_same_v<decltype(messages257.m_offsets)::value_type, quint16>); + + static_assert(messagesBigOffsets.m_offsets.size() == 5); + static_assert(messagesBigOffsets.m_string.size() == 364); + static_assert(std::is_same_v<decltype(messagesBigOffsets.m_offsets)::value_type, quint16>); } void tst_QOffsetStringArray::access() @@ -112,10 +85,21 @@ void tst_QOffsetStringArray::access() QCOMPARE(messages[2], "level - 2"); QCOMPARE(messages[3], "level - 3"); QCOMPARE(messages[4], "level - 4"); + // out of bounds returns empty strings: QCOMPARE(messages[5], ""); QCOMPARE(messages[6], ""); } +void tst_QOffsetStringArray::contains() +{ + QVERIFY(!messages.contains("")); + QVERIFY( messages.contains("level - 0")); + std::string l2 = "level - 2"; // make sure we don't compare pointer values + QVERIFY( messages.contains(l2)); + QByteArray L4 = "Level - 4"; + QVERIFY( messages.contains(L4, Qt::CaseInsensitive)); + QVERIFY(!messages.contains(L4, Qt::CaseSensitive)); +} QTEST_APPLESS_MAIN(tst_QOffsetStringArray) #include "tst_qoffsetstringarray.moc" |