Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cetlvast/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ endif()
add_subdirectory(${CMAKE_SOURCE_DIR}/suites/unittest)
add_subdirectory(${CMAKE_SOURCE_DIR}/suites/docs)
add_subdirectory(${CMAKE_SOURCE_DIR}/suites/compile)
add_subdirectory(${CMAKE_SOURCE_DIR}/suites/headers)
if(benchmark_FOUND)
add_subdirectory(${CMAKE_SOURCE_DIR}/suites/benchmark)
endif()
Expand Down Expand Up @@ -240,6 +241,7 @@ add_custom_target(
build_unittests
build_examples
build_compile_tests
build_header_tests
)

add_custom_target(
Expand All @@ -250,6 +252,7 @@ add_custom_target(
run_examples
$<$<CONFIG:Coverage>:gcovr_html_report_for_examples>
run_compile_precheck_tests
build_header_tests
)

# "release" is a legacy target supported for older build systems that use this
Expand Down
1 change: 1 addition & 0 deletions cetlvast/cmake/compiler_flag_sets/default.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ list(APPEND C_FLAG_SET
"-pedantic"
"-Wall"
"-Wextra"
"-Wshadow"
"-Werror"
"-Wfloat-equal"
"-Wconversion"
Expand Down
54 changes: 54 additions & 0 deletions cetlvast/suites/headers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#
# Copyright (C) OpenCyphal Development Team <opencyphal.org>
# SPDX-License-Identifier: MIT
#

cmake_minimum_required(VERSION 3.22.0)

project(cetlvast_header_tests CXX)

# Discover new public headers automatically. Compile each header in isolation and on either side of each
# polyfill facade: namespace aliases can expose diagnostics that isolated headers do not trigger (#263).
file(GLOB_RECURSE PUBLIC_HEADERS CONFIGURE_DEPENDS RELATIVE "${CETL_INCLUDE}" "${CETL_INCLUDE}/cetl/*.hpp")
set(HEADER_TEST_SOURCES)
foreach(HEADER IN LISTS PUBLIC_HEADERS)
string(MAKE_C_IDENTIFIER "${HEADER}" HEADER_ID)
foreach(LAYOUT standalone pf17_first pf17_last pf20_first pf20_last)
set(INCLUDES "#include <${HEADER}>\n")
if(LAYOUT MATCHES "^pf(17|20)_(first|last)$")
set(FACADE "#include <cetl/pf${CMAKE_MATCH_1}/cetlpf.hpp>\n")
if(CMAKE_MATCH_2 STREQUAL "first")
string(PREPEND INCLUDES "${FACADE}")
else()
string(APPEND INCLUDES "${FACADE}")
endif()
endif()
set(SOURCE "${CMAKE_CURRENT_BINARY_DIR}/${HEADER_ID}_${LAYOUT}.cpp")
file(CONFIGURE OUTPUT "${SOURCE}" CONTENT "${INCLUDES}" @ONLY)
list(APPEND HEADER_TEST_SOURCES "${SOURCE}")
endforeach()
endforeach()

foreach(ORDER forward reverse)
set(ORDERED_HEADERS ${PUBLIC_HEADERS})
if(ORDER STREQUAL "reverse")
list(REVERSE ORDERED_HEADERS)
endif()
set(INCLUDES "")
foreach(HEADER IN LISTS ORDERED_HEADERS)
string(APPEND INCLUDES "#include <${HEADER}>\n")
endforeach()
set(SOURCE "${CMAKE_CURRENT_BINARY_DIR}/all_headers_${ORDER}.cpp")
file(CONFIGURE OUTPUT "${SOURCE}" CONTENT "${INCLUDES}" @ONLY)
list(APPEND HEADER_TEST_SOURCES "${SOURCE}")
endforeach()

add_library(header_tests OBJECT ${HEADER_TEST_SOURCES})
target_link_libraries(header_tests PRIVATE cetl o1heap)
# Keep each include order in its own translation unit, including in unity builds.
set_target_properties(header_tests PROPERTIES UNITY_BUILD OFF DISABLE_PRECOMPILE_HEADERS ON)

add_custom_target(build_header_tests DEPENDS header_tests)
# CI presets build and run unit tests directly as well as through the aggregate build target.
add_dependencies(build_unittests build_header_tests)
add_dependencies(run_unittests build_header_tests)
4 changes: 2 additions & 2 deletions cetlvast/suites/unittest/optional/test_pf17_optional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ TEST(test_optional, throwing_move_only_propagates)
template <typename T>
struct comparable final
{
explicit constexpr comparable(const T& value)
: value(value)
explicit constexpr comparable(const T& initial_value)
: value(initial_value)
{
}
comparable(const comparable&) = delete;
Expand Down
16 changes: 8 additions & 8 deletions cetlvast/suites/unittest/test_pf17_polymorphic_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ struct OnlyMovable
OnlyMovable(const OnlyMovable&) = delete;
OnlyMovable& operator=(const OnlyMovable&) = delete;

OnlyMovable(int* value)
: value(value)
OnlyMovable(int* initial_value)
: value(initial_value)
{
}

Expand All @@ -343,9 +343,9 @@ TYPED_TEST(TestPolymorphicAllocatorMoveOnlyProtocols, TestDefaultConstruction)
{
typename cetlvast::MRH::template MemoryResourceType<TypeParam>* resource =
cetlvast::MRH::template new_delete_resource_by_tag<TypeParam>();
using AllocatorType = typename TestFixture::template AllocatorType<OnlyMovable>;
AllocatorType subject{resource};
OnlyMovable* p = subject.allocate(1);
using SubjectAllocator = typename TestFixture::template AllocatorType<OnlyMovable>;
SubjectAllocator subject{resource};
OnlyMovable* p = subject.allocate(1);
ASSERT_FALSE(nullptr == p);
subject.deallocate(p, 1);
}
Expand All @@ -358,9 +358,9 @@ TYPED_TEST(TestPolymorphicAllocatorMoveOnlyProtocols, TestEmplace)
int other_test_data = 0;
typename cetlvast::MRH::template MemoryResourceType<TypeParam>* resource =
cetlvast::MRH::template new_delete_resource_by_tag<TypeParam>();
using AllocatorType = typename TestFixture::template AllocatorType<OnlyMovable>;
AllocatorType subject{resource};
OnlyMovable* p = subject.allocate(1);
using SubjectAllocator = typename TestFixture::template AllocatorType<OnlyMovable>;
SubjectAllocator subject{resource};
OnlyMovable* p = subject.allocate(1);
ASSERT_FALSE(nullptr == p);
subject.construct(p, &test_data);
ASSERT_EQ(&test_data, p->value);
Expand Down
4 changes: 2 additions & 2 deletions cetlvast/suites/unittest/test_pf17_variant_assignment_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ static constexpr auto test_assignment_1_constexpr()
using cetl::pf17::in_place_index;
struct U
{
constexpr explicit U(const std::int64_t value)
: value(value)
constexpr explicit U(const std::int64_t initial_value)
: value(initial_value)
{
}
constexpr U(const U&) noexcept = default;
Expand Down
4 changes: 2 additions & 2 deletions cetlvast/suites/unittest/test_pf17_variant_assignment_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ static constexpr auto test_assignment_2_constexpr()
using cetl::pf17::get;
struct U
{
constexpr explicit U(const std::int64_t value)
: value(value)
constexpr explicit U(const std::int64_t initial_value)
: value(initial_value)
{
}
constexpr U(const U&) noexcept = delete;
Expand Down
4 changes: 2 additions & 2 deletions cetlvast/suites/unittest/test_pf17_variant_ctor_2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ static constexpr auto test_ctor_2_constexpr()
using cetl::pf17::in_place_index;
struct U
{
constexpr explicit U(const std::int64_t value)
: value(value)
constexpr explicit U(const std::int64_t initial_value)
: value(initial_value)
{
}
constexpr U(const U&) noexcept = default;
Expand Down
4 changes: 2 additions & 2 deletions cetlvast/suites/unittest/test_pf17_variant_ctor_3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ static constexpr auto test_ctor_3_constexpr()
using cetl::pf17::get;
struct U
{
constexpr explicit U(const std::int64_t value)
: value(value)
constexpr explicit U(const std::int64_t initial_value)
: value(initial_value)
{
}
constexpr U(const U&) noexcept = delete;
Expand Down
10 changes: 5 additions & 5 deletions cetlvast/suites/unittest/test_pf17_variant_other.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,9 +888,9 @@ TEST(test_variant, visit)
variant<std::int64_t, anchored> b(in_place_index<0>, 1234);
std::int64_t div = 0;
visit(make_overloaded(
[&div](anchored& a, std::int64_t& b) {
div = a.value / b;
std::swap(a.value, b);
[&div](anchored& lhs, std::int64_t& rhs) {
div = lhs.value / rhs;
std::swap(lhs.value, rhs);
},
[](const auto&, const auto&) { std::terminate(); }),
a,
Expand Down Expand Up @@ -934,8 +934,8 @@ TEST(test_variant, visit)
#if __cplusplus >= 201703L
using cetl::make_overloaded;
using cetl::pf17::in_place_type;
static_assert(1110 == visit(make_overloaded([](const std::int8_t a,
const float b) { return a + static_cast<std::int64_t>(b); },
static_assert(1110 == visit(make_overloaded([](const std::int8_t lhs,
const float rhs) { return lhs + static_cast<std::int64_t>(rhs); },
[](const auto&, const auto&) { return 0; }),
variant<float, std::int8_t>(in_place_index<1>, static_cast<std::int8_t>(123)),
variant<float, bool>(in_place_type<float>, 987.0F)));
Expand Down
13 changes: 13 additions & 0 deletions cetlvast/suites/unittest/test_variable_length_array_assign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
/// Copyright (C) OpenCyphal Development Team <opencyphal.org>
/// SPDX-License-Identifier: MIT

// Include the facade first so namespace aliases participate in VLA diagnostics (#263).
#include "cetl/pf17/cetlpf.hpp"
#include "cetl/variable_length_array.hpp"
#include "cetlvast/helpers_gtest.hpp"

Expand All @@ -22,6 +24,17 @@ namespace
template <typename T>
using Array = cetl::variable_length_array<T, std::allocator<T>>;

TEST(VLAAssignPolyfill, BoolPointerRange)
{
const bool source[] = {true, false, true};
Array<bool> actual{std::allocator<bool>{}};
actual.assign(std::begin(source), std::end(source));
ASSERT_EQ(actual.size(), 3U);
EXPECT_TRUE(actual[0]);
EXPECT_FALSE(actual[1]);
EXPECT_TRUE(actual[2]);
}

template <typename T>
class VLAAssign : public ::testing::Test
{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ template <typename Params>
class VLAMoveConstructorExceptionTests : public ::testing::Test
{
protected:
using T = typename Params::value_type;
using Subject = cetl::variable_length_array<T, MoveConstructorAllocator<T, typename Params::pocma>>;
using Allocator = typename Subject::allocator_type;
using T = typename Params::value_type;
using ArrayType = cetl::variable_length_array<T, MoveConstructorAllocator<T, typename Params::pocma>>;
using AllocatorType = typename ArrayType::allocator_type;
};

using MoveConstructorValueTypes = ::testing::Types<MoveConstructorParams<int, std::false_type>,
Expand All @@ -112,8 +112,8 @@ TYPED_TEST_SUITE(VLAMoveConstructorExceptionTests, MoveConstructorValueTypes, );

TYPED_TEST(VLAMoveConstructorExceptionTests, UnequalAllocatorAllocationFailure)
{
using Subject = typename TestFixture::Subject;
using Allocator = typename TestFixture::Allocator;
using Subject = typename TestFixture::ArrayType;
using Allocator = typename TestFixture::AllocatorType;

MoveConstructorAllocatorState source_state;
MoveConstructorAllocatorState destination_state;
Expand Down Expand Up @@ -158,8 +158,8 @@ TYPED_TEST(VLAMoveConstructorExceptionTests, UnequalAllocatorAllocationFailure)

TYPED_TEST(VLAMoveConstructorExceptionTests, EqualAllocatorDoesNotAllocate)
{
using Subject = typename TestFixture::Subject;
using Allocator = typename TestFixture::Allocator;
using Subject = typename TestFixture::ArrayType;
using Allocator = typename TestFixture::AllocatorType;

MoveConstructorAllocatorState state;
{
Expand Down
Loading
Loading