From dacbcc7d7779e5faec243b51b1581d401954ddea Mon Sep 17 00:00:00 2001 From: Stefan Klug Date: Thu, 3 Apr 2025 17:49:11 +0200 Subject: test: Add minimal test for Matrix Add a few tests for the Matrix class. This is not full fledged but at least a starter. Signed-off-by: Stefan Klug Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Paul Elder --- test/matrix.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 test/matrix.cpp (limited to 'test/matrix.cpp') diff --git a/test/matrix.cpp b/test/matrix.cpp new file mode 100644 index 00000000..4afae2da --- /dev/null +++ b/test/matrix.cpp @@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2024, Ideas on Board Oy + * + * Matrix tests + */ + +#include "libcamera/internal/matrix.h" + +#include +#include + +#include "test.h" + +using namespace libcamera; + +#define ASSERT_EQ(a, b) \ + if ((a) != (b)) { \ + std::cout << #a " != " #b << " (line " << __LINE__ << ")" \ + << std::endl; \ + return TestFail; \ + } + +class MatrixTest : public Test +{ +protected: + int run() + { + Matrix m1; + + ASSERT_EQ(m1[0][0], 0.0); + ASSERT_EQ(m1[0][1], 0.0); + + constexpr Matrix m2 = Matrix().identity(); + ASSERT_EQ(m2[0][0], 1.0); + ASSERT_EQ(m2[0][1], 0.0); + ASSERT_EQ(m2[1][0], 0.0); + ASSERT_EQ(m2[1][1], 1.0); + + Matrix m3{ { 2.0, 0.0, 0.0, 2.0 } }; + Matrix m4 = m3.inverse(); + + Matrix m5 = m3 * m4; + ASSERT_EQ(m5[0][0], 1.0); + ASSERT_EQ(m5[0][1], 0.0); + ASSERT_EQ(m5[1][0], 0.0); + ASSERT_EQ(m5[1][1], 1.0); + + return TestPass; + } +}; + +TEST_REGISTER(MatrixTest) -- cgit v1.2.1