From patchwork Sat Feb 29 16:42:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2920 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D06BE62689 for ; Sat, 29 Feb 2020 17:43:22 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7652933E for ; Sat, 29 Feb 2020 17:43:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1582994602; bh=rTG5uiSgCf8ZncXT5gLvo4lI/pqVJpXttlHniz78ehs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=eSvLIPQzpuC9M6S6uSDoXhnoBIJZYq4GTNZs0XELKRloZLx2l7L10MILEIwH7WuY0 Wk/kZDYfidDNd/oTEUwm47xqou/lCDKwBoWXV2GV9ZnHVao7pRbhtdPLPLowiRg5iG e1GsAcqHaZmdouD2Nezm/MmnDMGiK9MV/GAX8394= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 29 Feb 2020 18:42:25 +0200 Message-Id: <20200229164254.23604-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200229164254.23604-1-laurent.pinchart@ideasonboard.com> References: <20200229164254.23604-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 02/31] test: Add Span test X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Feb 2020 16:43:23 -0000 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/meson.build | 1 + test/span.cpp | 177 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 178 insertions(+) create mode 100644 test/span.cpp diff --git a/test/meson.build b/test/meson.build index daaa1aac926d..92be382bfe41 100644 --- a/test/meson.build +++ b/test/meson.build @@ -30,6 +30,7 @@ internal_tests = [ ['object', 'object.cpp'], ['object-invoke', 'object-invoke.cpp'], ['signal-threads', 'signal-threads.cpp'], + ['span', 'span.cpp'], ['threads', 'threads.cpp'], ['timer', 'timer.cpp'], ['timer-thread', 'timer-thread.cpp'], diff --git a/test/span.cpp b/test/span.cpp new file mode 100644 index 000000000000..609749f51b86 --- /dev/null +++ b/test/span.cpp @@ -0,0 +1,177 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2020, Google Inc. + * + * span.cpp - Span tests + */ + +#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)