From patchwork Fri Jun 21 16:13:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 1495 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 DE7C2615BC for ; Fri, 21 Jun 2019 18:14:06 +0200 (CEST) Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8CAD952A; Fri, 21 Jun 2019 18:14:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1561133646; bh=1I58ueIgZpJe4vC52rlGsh3C91qg8EGfNd9XndywWPw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gshrnjJQf50GTBzTwPsgAG21CHHqEbCzxuOo/Yxe/iuYjhDtX4s2icsEfa/IOrvfN 5hb7D/jLCegY5dDDfSp9RMQeXUze2qIh2NaXhzaO+URRg8bqzn1Qg7x0OdeCoyQrdt VeNltAh8vqpQ2sOJ8QXhXDnClSn0PK5EbQ58iTcM= From: Kieran Bingham To: LibCamera Devel Date: Fri, 21 Jun 2019 17:13:54 +0100 Message-Id: <20190621161401.28337-3-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190621161401.28337-1-kieran.bingham@ideasonboard.com> References: <20190621161401.28337-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v2 2/9] libcamera: test: Add Value tests X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Jun 2019 16:14:07 -0000 Add initial basic testing for the new Value APIs. Signed-off-by: Kieran Bingham --- test/meson.build | 1 + test/value.cpp | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 test/value.cpp diff --git a/test/meson.build b/test/meson.build index c36ac2479636..eff541ddc0a6 100644 --- a/test/meson.build +++ b/test/meson.build @@ -15,6 +15,7 @@ public_tests = [ ['list-cameras', 'list-cameras.cpp'], ['signal', 'signal.cpp'], ['timer', 'timer.cpp'], + ['value', 'value.cpp'], ] internal_tests = [ diff --git a/test/value.cpp b/test/value.cpp new file mode 100644 index 000000000000..fea8cd2396cd --- /dev/null +++ b/test/value.cpp @@ -0,0 +1,82 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * value.cpp - Value tests + */ + +#include + +#include + +#include "test.h" + +using namespace std; +using namespace libcamera; + +class Values : public Test +{ +protected: + int run() + { + Value integer(1234); + Value boolean(true); + Value string("test-string"); + + /* Just a string conversion output test... no validation */ + cout << "Int: " << integer.toString() + << " Bool: " << boolean.toString() + << " String: " << string.toString() + << endl; + + /* Just a string conversion output test. Using overloaded << */ + cout << "Int: " << integer + << " Bool: " << boolean + << " String: " << string + << endl; + + if (integer.getInt() != 1234) { + cerr << "Failed to get Integer" << endl; + return TestFail; + } + + if (boolean.getBool() != true) { + cerr << "Failed to get Boolean" << endl; + return TestFail; + } + + if (string.getString() != "test-string") { + cerr << "Failed to get string" << endl; + return TestFail; + } + + /* Test an uninitialised value, and updating it. */ + + Value value; + if (!value.isNull()) { + cerr << "Empty value is non-null" << endl; + return TestFail; + } + + value.set(true); + if (value.isNull()) { + cerr << "Failed to set an empty object" << endl; + return TestFail; + } + + if (value.getBool() != true) { + cerr << "Failed to get Booleans" << endl; + return TestFail; + } + + value.set(10); + if (value.getInt() != 10) { + cerr << "Failed to get Integer" << endl; + return TestFail; + } + + return TestPass; + } +}; + +TEST_REGISTER(Values)