[libcamera-devel] [RFC PATCH v2 2/9] libcamera: test: Add Value tests
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Sun Jun 23 00:43:44 CEST 2019
Hi Kieran,
Thank you for the patch.
On Fri, Jun 21, 2019 at 05:13:54PM +0100, Kieran Bingham wrote:
> Add initial basic testing for the new Value APIs.
>
> Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
> ---
> 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 <iostream>
> +
> +#include <libcamera/value.h>
> +
> +#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;
I think you should validate them both instead of printing them. You can
output to a stringstream and compare the result with an expected value.
> +
> + 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)
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list