From patchwork Fri Mar 6 16:00:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3002 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C729A628DC for ; Fri, 6 Mar 2020 17:00:27 +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 6EEB613C2 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=SpuC2fqlNBdLpoKFLny8epULykqnOwoyDMWKj17ltOE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=s4i6qADI3TOyZ3kYRWbfvMj5UE6LWx+E0/EEgl8RQz0XtAwO4tQIgWaFyN2jfTrFX ry09KgOkHBb+XofuQzmHEiFMGWGFWhVHozEZOR0tqEieWOr+l2nnTVR4Sx3153FaGM f5XeIh4t9XtUbBX6AunPYN6KYC+ScZmk3PNUr/50= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 6 Mar 2020 18:00:00 +0200 Message-Id: <20200306160002.30549-31-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 30/32] test: controls: control_value: Expand test to cover all control types 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 The ControlValueTest hasn't been updated for a long time and is outdated. Improve it to support all control types, and test the type(), isArray() and toString() methods. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- Changes since v1: - Move change to ControlValue::toString() to a separate patch --- test/controls/control_value.cpp | 110 +++++++++++++++++++++++++------- 1 file changed, 88 insertions(+), 22 deletions(-) diff --git a/test/controls/control_value.cpp b/test/controls/control_value.cpp index a1ffa842f29e..37f415302ff6 100644 --- a/test/controls/control_value.cpp +++ b/test/controls/control_value.cpp @@ -19,46 +19,112 @@ class ControlValueTest : public Test protected: int run() { - ControlValue integer(1234); - ControlValue boolean(true); + /* + * None type. + */ + ControlValue value; + if (!value.isNone() || value.isArray()) { + cerr << "Empty value is non-null" << endl; + return TestFail; + } - /* Just a string conversion output test... no validation */ - cout << "Int: " << integer.toString() - << " Bool: " << boolean.toString() - << endl; + /* + * Bool type. + */ + value.set(true); + if (value.isNone() || value.isArray() || + value.type() != ControlTypeBool) { + cerr << "Control type mismatch after setting to bool" << endl; + return TestFail; + } - if (integer.get() != 1234) { - cerr << "Failed to get Integer" << endl; + if (value.get() != true) { + cerr << "Control value mismatch after setting to bool" << endl; return TestFail; } - if (boolean.get() != true) { - cerr << "Failed to get Boolean" << endl; + if (value.toString() != "true") { + cerr << "Control string mismatch after setting to bool" << endl; return TestFail; } - /* Test an uninitialised value, and updating it. */ + /* + * Integer8 type. + */ + value.set(static_cast(42)); + if (value.isNone() || value.isArray() || + value.type() != ControlTypeByte) { + cerr << "Control type mismatch after setting to uint8_t" << endl; + return TestFail; + } - ControlValue value; - if (!value.isNone()) { - cerr << "Empty value is non-null" << endl; + if (value.get() != 42) { + cerr << "Control value mismatch after setting to uint8_t" << endl; return TestFail; } - value.set(true); - if (value.isNone()) { - cerr << "Failed to set an empty object" << endl; + if (value.toString() != "42") { + cerr << "Control string mismatch after setting to uint8_t" << endl; return TestFail; } - if (value.get() != true) { - cerr << "Failed to get Booleans" << endl; + /* + * Integer32 type. + */ + value.set(0x42000000); + if (value.isNone() || value.isArray() || + value.type() != ControlTypeInteger32) { + cerr << "Control type mismatch after setting to int32_t" << endl; + return TestFail; + } + + if (value.get() != 0x42000000) { + cerr << "Control value mismatch after setting to int32_t" << endl; + return TestFail; + } + + if (value.toString() != "1107296256") { + cerr << "Control string mismatch after setting to int32_t" << endl; + return TestFail; + } + + /* + * Integer64 type. + */ + value.set(static_cast(-42)); + if (value.isNone() || value.isArray() || + value.type() != ControlTypeInteger64) { + cerr << "Control type mismatch after setting to int64_t" << endl; + return TestFail; + } + + if (value.get() != -42) { + cerr << "Control value mismatch after setting to int64_t" << endl; + return TestFail; + } + + if (value.toString() != "-42") { + cerr << "Control string mismatch after setting to int64_t" << endl; + return TestFail; + } + + /* + * Float type. + */ + value.set(-0.42f); + if (value.isNone() || value.isArray() || + value.type() != ControlTypeFloat) { + cerr << "Control type mismatch after setting to float" << endl; + return TestFail; + } + + if (value.get() != -0.42f) { + cerr << "Control value mismatch after setting to float" << endl; return TestFail; } - value.set(10); - if (value.get() != 10) { - cerr << "Failed to get Integer" << endl; + if (value.toString() != "-0.420000") { + cerr << "Control string mismatch after setting to float" << endl; return TestFail; }