From patchwork Fri Mar 6 16:00:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3003 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 311F9628E0 for ; Fri, 6 Mar 2020 17:00:28 +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 C10A824B for ; Fri, 6 Mar 2020 17:00:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1583510427; bh=n8DnTCdboN0zG0KmvXupotD2rPXq5x5/jyNh0KMTpwQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=t+/crHY3gEbhNWfx5SJU0mKyvlD7QvgoXL2AQJDXSdsOH/ROzZ0up+wvp7DvFqao8 4wSn1+E+7wLGp52/Q/LxVs6Aw2iFQQqDuTLc/g5IzGJ31LQz6KC6wOMvsn0MHtQRA1 cd4s39hZkp5rUqqbWMC4KFgGvcGJOqjht5XQ8JAg= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 6 Mar 2020 18:00:01 +0200 Message-Id: <20200306160002.30549-32-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200306160002.30549-1-laurent.pinchart@ideasonboard.com> References: <20200306160002.30549-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 31/32] test: controls: control_value: Expand test to cover array controls 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: Fri, 06 Mar 2020 16:00:28 -0000 Add tests to ControlValueTest to cover array controls of all supported types. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Kieran Bingham --- Changes since v1: - Renamed int8s to bytes --- test/controls/control_value.cpp | 101 ++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/test/controls/control_value.cpp b/test/controls/control_value.cpp index 37f415302ff6..fd28bfe4604a 100644 --- a/test/controls/control_value.cpp +++ b/test/controls/control_value.cpp @@ -5,6 +5,7 @@ * control_value.cpp - ControlValue tests */ +#include #include #include @@ -48,6 +49,26 @@ protected: return TestFail; } + std::array bools{ true, false }; + value.set(Span(bools)); + if (value.isNone() || !value.isArray() || + value.type() != ControlTypeBool) { + cerr << "Control type mismatch after setting to bool array" << endl; + return TestFail; + } + + Span boolsResult = value.get>(); + if (bools.size() != boolsResult.size() || + !std::equal(bools.begin(), bools.end(), boolsResult.begin())) { + cerr << "Control value mismatch after setting to bool" << endl; + return TestFail; + } + + if (value.toString() != "[ true, false ]") { + cerr << "Control string mismatch after setting to bool array" << endl; + return TestFail; + } + /* * Integer8 type. */ @@ -68,6 +89,26 @@ protected: return TestFail; } + std::array bytes{ 3, 14, 15, 9 }; + value.set(Span(bytes)); + if (value.isNone() || !value.isArray() || + value.type() != ControlTypeByte) { + cerr << "Control type mismatch after setting to uint8_t array" << endl; + return TestFail; + } + + Span int8sResult = value.get>(); + if (bytes.size() != int8sResult.size() || + !std::equal(bytes.begin(), bytes.end(), int8sResult.begin())) { + cerr << "Control value mismatch after setting to uint8_t array" << endl; + return TestFail; + } + + if (value.toString() != "[ 3, 14, 15, 9 ]") { + cerr << "Control string mismatch after setting to uint8_t array" << endl; + return TestFail; + } + /* * Integer32 type. */ @@ -88,6 +129,26 @@ protected: return TestFail; } + std::array int32s{ 3, 14, 15, 9 }; + value.set(Span(int32s)); + if (value.isNone() || !value.isArray() || + value.type() != ControlTypeInteger32) { + cerr << "Control type mismatch after setting to int32_t array" << endl; + return TestFail; + } + + Span int32sResult = value.get>(); + if (int32s.size() != int32sResult.size() || + !std::equal(int32s.begin(), int32s.end(), int32sResult.begin())) { + cerr << "Control value mismatch after setting to int32_t array" << endl; + return TestFail; + } + + if (value.toString() != "[ 3, 14, 15, 9 ]") { + cerr << "Control string mismatch after setting to int32_t array" << endl; + return TestFail; + } + /* * Integer64 type. */ @@ -108,6 +169,26 @@ protected: return TestFail; } + std::array int64s{ 3, 14, 15, 9 }; + value.set(Span(int64s)); + if (value.isNone() || !value.isArray() || + value.type() != ControlTypeInteger64) { + cerr << "Control type mismatch after setting to int64_t array" << endl; + return TestFail; + } + + Span int64sResult = value.get>(); + if (int64s.size() != int64sResult.size() || + !std::equal(int64s.begin(), int64s.end(), int64sResult.begin())) { + cerr << "Control value mismatch after setting to int64_t array" << endl; + return TestFail; + } + + if (value.toString() != "[ 3, 14, 15, 9 ]") { + cerr << "Control string mismatch after setting to int64_t array" << endl; + return TestFail; + } + /* * Float type. */ @@ -128,6 +209,26 @@ protected: return TestFail; } + std::array floats{ 3.141593, 2.718282, 299792458.0 }; + value.set(Span(floats)); + if (value.isNone() || !value.isArray() || + value.type() != ControlTypeFloat) { + cerr << "Control type mismatch after setting to float array" << endl; + return TestFail; + } + + Span floatsResult = value.get>(); + if (floats.size() != floatsResult.size() || + !std::equal(floats.begin(), floats.end(), floatsResult.begin())) { + cerr << "Control value mismatch after setting to float array" << endl; + return TestFail; + } + + if (value.toString() != "[ 3.141593, 2.718282, 299792448.000000 ]") { + cerr << "Control string mismatch after setting to float array" << endl; + return TestFail; + } + return TestPass; } };