From 7286156e8ccde06d86ceb5a9ee2876f68b87b07f Mon Sep 17 00:00:00 2001 From: Ladislas de Toldi Date: Wed, 26 Oct 2022 19:32:34 +0200 Subject: [PATCH] :alembic: (stl): Test std::ranges support for arm-gcc + clang --- spikes/stl_cxxsupport/main.cpp | 16 +++++++++ tests/functional/CMakeLists.txt | 2 ++ .../tests/stl_features/CMakeLists.txt | 15 ++++++++ .../tests/stl_features/suite_std_ranges.cpp | 35 +++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 tests/functional/tests/stl_features/CMakeLists.txt create mode 100644 tests/functional/tests/stl_features/suite_std_ranges.cpp diff --git a/spikes/stl_cxxsupport/main.cpp b/spikes/stl_cxxsupport/main.cpp index eff0ebd85a..7ae5c431a9 100644 --- a/spikes/stl_cxxsupport/main.cpp +++ b/spikes/stl_cxxsupport/main.cpp @@ -3,6 +3,7 @@ // SPDX-License-Identifier: Apache-2.0 #include +#include #include #include "drivers/BufferedSerial.h" @@ -94,5 +95,20 @@ auto main() -> int auto back = span0.back(); log_info("span0.back() = %i", back); + log_info("Test std::range features"); + + constexpr auto range = [](const auto a, const auto b) { + auto x = std::ranges::views::iota(a) | std::ranges::views::take(b - a + 1); + return std::ranges::views::all(x); + }; + + for (auto x: range(1, 10)) { + log_info("x: %i", x); + } + + for (auto y: range(20, 25)) { + log_info("y: %i", y); + } + return 1; } diff --git a/tests/functional/CMakeLists.txt b/tests/functional/CMakeLists.txt index 6b9430de14..b5610723ed 100644 --- a/tests/functional/CMakeLists.txt +++ b/tests/functional/CMakeLists.txt @@ -42,3 +42,5 @@ add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/boost_ut) add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/io_expander) add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/file_manager) add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/qdac) + +add_subdirectory(${TESTS_FUNCTIONAL_TESTS_DIR}/stl_features) diff --git a/tests/functional/tests/stl_features/CMakeLists.txt b/tests/functional/tests/stl_features/CMakeLists.txt new file mode 100644 index 0000000000..78108634ba --- /dev/null +++ b/tests/functional/tests/stl_features/CMakeLists.txt @@ -0,0 +1,15 @@ +# Leka - LekaOS +# Copyright 2022 APF France handicap +# SPDX-License-Identifier: Apache-2.0 + +register_functional_test( + TARGET + functional_ut_std_features + + INCLUDE_DIRECTORIES + + SOURCES + suite_std_ranges.cpp + + LINK_LIBRARIES +) diff --git a/tests/functional/tests/stl_features/suite_std_ranges.cpp b/tests/functional/tests/stl_features/suite_std_ranges.cpp new file mode 100644 index 0000000000..ce6f1dedef --- /dev/null +++ b/tests/functional/tests/stl_features/suite_std_ranges.cpp @@ -0,0 +1,35 @@ +// Leka - LekaOS +// Copyright 2022 APF France handicap +// SPDX-License-Identifier: Apache-2.0 + +#include + +#include "tests/config.h" + +using namespace boost::ut; + +constexpr auto range = [](auto a, auto b) { + auto x = std::ranges::views::iota(a) | std::ranges::views::take(b - a + 1); + return std::ranges::views::all(x); +}; + +suite suite_std_ranges = [] { + "generate range of 5 values from 1 to 5"_test = [] { + auto data = std::to_array({1, 2, 3, 4, 5}); + auto i = 0; + for (auto v: range(1, 5)) { + expect(data[i] == v); + ++i; + } + }; + + "store range in variable and compare"_test = [&] { + auto data = range(10, 20); + auto i = 0; + + for (auto v: range(10, 20)) { + expect(data[i] == v); + ++i; + } + }; +};