[libcamera-devel] [PATCH 4/6] test: Add a ColorSpace test
paul.elder at ideasonboard.com
paul.elder at ideasonboard.com
Thu Aug 25 21:52:37 CEST 2022
On Tue, Aug 23, 2022 at 08:43:12PM +0300, Laurent Pinchart via libcamera-devel wrote:
> Add a test for the ColorSpace class that exercises the toString() and
> fromString() functions.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder at ideasonboard.com>
> ---
> test/color-space.cpp | 105 +++++++++++++++++++++++++++++++++++++++++++
> test/meson.build | 1 +
> 2 files changed, 106 insertions(+)
> create mode 100644 test/color-space.cpp
>
> diff --git a/test/color-space.cpp b/test/color-space.cpp
> new file mode 100644
> index 000000000000..7d45b2179bca
> --- /dev/null
> +++ b/test/color-space.cpp
> @@ -0,0 +1,105 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * Copyright (C) 2022, Laurent Pinchart <laurent.pinchart at ideasonboard.com>
> + *
> + * libcamera ColorSpace test
> + */
> +
> +#include <array>
> +#include <iostream>
> +
> +#include <libcamera/color_space.h>
> +
> +#include "test.h"
> +
> +using namespace libcamera;
> +using namespace std;
> +
> +class ColorSpaceTest : public Test
> +{
> +protected:
> + int run()
> + {
> + if (ColorSpace::toString(std::nullopt) != "Unset") {
> + std::cerr << "Conversion from nullopt to string failed" << std::endl;
> + return TestFail;
> + }
> +
> + const std::array<std::pair<ColorSpace, std::string>, 10> colorSpaces = { {
> + { ColorSpace::Raw, "RAW" },
> + { ColorSpace::Srgb, "sRGB" },
> + { ColorSpace::Sycc, "sYCC" },
> + { ColorSpace::Smpte170m, "SMPTE170M" },
> + { ColorSpace::Rec709, "Rec709" },
> + { ColorSpace::Rec2020, "Rec2020" },
> + {
> + ColorSpace{
> + ColorSpace::Primaries::Raw,
> + ColorSpace::TransferFunction::Linear,
> + ColorSpace::YcbcrEncoding::None,
> + ColorSpace::Range::Limited
> + },
> + "RAW/Linear/None/Limited"
> + }, {
> + ColorSpace{
> + ColorSpace::Primaries::Smpte170m,
> + ColorSpace::TransferFunction::Srgb,
> + ColorSpace::YcbcrEncoding::Rec601,
> + ColorSpace::Range::Full
> + },
> + "SMPTE170M/sRGB/Rec601/Full"
> + }, {
> + ColorSpace{
> + ColorSpace::Primaries::Rec709,
> + ColorSpace::TransferFunction::Rec709,
> + ColorSpace::YcbcrEncoding::Rec709,
> + ColorSpace::Range::Full
> + },
> + "Rec709/Rec709/Rec709/Full"
> + }, {
> + ColorSpace{
> + ColorSpace::Primaries::Rec2020,
> + ColorSpace::TransferFunction::Linear,
> + ColorSpace::YcbcrEncoding::Rec2020,
> + ColorSpace::Range::Limited
> + },
> + "Rec2020/Linear/Rec2020/Limited"
> + },
> + } };
> +
> + for (const auto &[colorSpace, name] : colorSpaces) {
> + if (colorSpace.toString() != name) {
> + std::cerr
> + << "Conversion from ColorSpace to string failed: "
> + << "expected " << name
> + << ", got " << colorSpace.toString()
> + << std::endl;
> + return TestFail;
> + }
> +
> + if (ColorSpace::fromString(name) != colorSpace) {
> + std::cerr
> + << "Conversion from string "
> + << name << " to ColorSpace failed"
> + << std::endl;
> + return TestFail;
> + }
> + }
> +
> + if (ColorSpace::fromString("Invalid")) {
> + std::cerr << "Conversion from invalid name string to color space succeeded"
> + << std::endl;
> + return TestFail;
> + }
> +
> + if (ColorSpace::fromString("Rec709/Rec709/Rec710/Limited")) {
> + std::cerr << "Conversion from invalid component string to color space succeeded"
> + << std::endl;
> + return TestFail;
> + }
> +
> + return TestPass;
> + }
> +};
> +
> +TEST_REGISTER(ColorSpaceTest)
> diff --git a/test/meson.build b/test/meson.build
> index d050bfa14cec..6cc778415dc8 100644
> --- a/test/meson.build
> +++ b/test/meson.build
> @@ -26,6 +26,7 @@ subdir('v4l2_subdevice')
> subdir('v4l2_videodevice')
>
> public_tests = [
> + ['color-space', 'color-space.cpp'],
> ['geometry', 'geometry.cpp'],
> ['public-api', 'public-api.cpp'],
> ['signal', 'signal.cpp'],
More information about the libcamera-devel
mailing list