From 996db4c23df9696a3d4773bc675563eac1bf4aa8 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Tue, 14 Jan 2020 06:20:36 +0200 Subject: test: Add Span test Add a compile-only test that exercises the whole Span API, as template functions are not fully compile-tested when the file is parsed. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- test/span.cpp | 181 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 test/span.cpp (limited to 'test/span.cpp') diff --git a/test/span.cpp b/test/span.cpp new file mode 100644 index 00000000..69f0732e --- /dev/null +++ b/test/span.cpp @@ -0,0 +1,181 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2020, Google Inc. + * + * span.cpp - Span tests + */ + +/* + * Include first to ensure the header is self-contained, as there's no span.cpp + * in libcamera. + */ +#include + +#include +#include +#include + +#include "test.h" + +using namespace std; +using namespace libcamera; + +class SpanTest : public Test +{ +protected: + int run() + { + int i[4]{ 1, 2, 3, 4 }; + std::array a{ 1, 2, 3, 4 }; + const std::array ca{ 1, 2, 3, 4 }; + std::vector v{ 1, 2, 3, 4 }; + const std::vector cv{ 1, 2, 3, 4 }; + + /* + * Compile-test construction and usage of spans with static + * extent. Commented-out tests are expected not to compile, or + * to generate undefined behaviour. + */ + + Span{}; + /* Span{}; */ + + Span{ &i[0], 4 }; + Span{ &i[0], &i[3] }; + + Span{ i }; + /* Span{ i }; */ + /* Span{ i }; */ + + Span{ a }; + Span{ a }; + /* Span{ a }; */ + /* Span{ a }; */ + + Span{ ca }; + /* Span{ ca }; */ + /* Span{ ca }; */ + /* Span{ ca }; */ + + Span{ v }; + Span{ v }; + /* Span{ v }; */ + + Span{ v }; + /* Span{ v }; */ + /* Span{ v }; */ + + Span staticSpan{ i }; + Span{ staticSpan }; + Span{ staticSpan }; + /* Span{ staticSpan }; */ + + staticSpan = Span{ v }; + + staticSpan.begin(); + staticSpan.cbegin(); + staticSpan.end(); + staticSpan.cend(); + staticSpan.rbegin(); + staticSpan.crbegin(); + staticSpan.rend(); + staticSpan.crend(); + + staticSpan.front(); + staticSpan.back(); + staticSpan[0]; + staticSpan.data(); + + staticSpan.size(); + staticSpan.size_bytes(); + + staticSpan.empty(); + + staticSpan.first<2>(); + staticSpan.first(2); + /* staticSpan.first<6>(); */ + /* staticSpan.first(6); */ + staticSpan.last<2>(); + staticSpan.last(2); + /* staticSpan.last<6>(); */ + /* staticSpan.last(6); */ + staticSpan.subspan<1>(); + staticSpan.subspan<1, 2>(); + staticSpan.subspan(1); + staticSpan.subspan(1, 2); + /* staticSpan.subspan(2, 4); */ + + /* + * Compile-test construction and usage of spans with static + * extent. Commented-out tests are expected not to compile, or + * to generate undefined behaviour. + */ + + Span{}; + + Span{ &i[0], 4 }; + Span{ &i[0], &i[3] }; + + Span{ i }; + /* Span{ i }; */ + + Span{ a }; + Span{ a }; + /* Span{ a }; */ + + Span{ ca }; + /* Span{ca}; */ + /* Span{ca}; */ + + Span{ v }; + Span{ v }; + /* Span{ v }; */ + + Span{ v }; + /* Span{ v }; */ + /* Span{ v }; */ + + Span dynamicSpan{ i }; + Span{ dynamicSpan }; + Span{ dynamicSpan }; + + dynamicSpan = Span{ a }; + + dynamicSpan.begin(); + dynamicSpan.cbegin(); + dynamicSpan.end(); + dynamicSpan.cend(); + dynamicSpan.rbegin(); + dynamicSpan.crbegin(); + dynamicSpan.rend(); + dynamicSpan.crend(); + + dynamicSpan.front(); + dynamicSpan.back(); + dynamicSpan[0]; + dynamicSpan.data(); + + dynamicSpan.size(); + dynamicSpan.size_bytes(); + + dynamicSpan.empty(); + + dynamicSpan.first<2>(); + dynamicSpan.first(2); + /* dynamicSpan.first<6>(); */ + /* dynamicSpan.first(6); */ + dynamicSpan.last<2>(); + dynamicSpan.last(2); + /* dynamicSpan.last<6>(); */ + /* dynamicSpan.last(6); */ + dynamicSpan.subspan<1>(); + dynamicSpan.subspan<1, 2>(); + dynamicSpan.subspan(1); + dynamicSpan.subspan(1, 2); + /* dynamicSpan.subspan(2, 4); */ + + return TestPass; + } +}; + +TEST_REGISTER(SpanTest) -- cgit v1.2.1