/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* geometry.cpp - Geometry classes tests
*/
#include <iostream>
#include <libcamera/geometry.h>
#include "test.h"
using namespace std;
using namespace libcamera;
class GeometryTest : public Test
{
protected:
template<typename T>
bool compare(const T &lhs, const T &rhs,
bool (*op)(const T &lhs, const T &rhs),
const char *opName, bool expect)
{
bool result = op(lhs, rhs);
if (result != expect) {
cout << lhs.toString()
<< opName << " "
<< rhs.toString()
<< "test failed" << std::endl;
return false;
}
return true;
}
int run()
{
/*
* Point tests
*/
/* Equality */
if (!compare(Point(50, 100), Point(50, 100), &operator==, "==", true))
return TestFail;
if (!compare(Point(-50, 100), Point(-50, 100), &operator==, "==", true))
return TestFail;
if (!compare(Point(50, -100), Point(50, -100), &operator==, "==", true))
return TestFail;
if (!compare(Point(-50, -100), Point(-50, -100), &operator==, "==", true))
return TestFail;
/* Inequality */
if (!compare(Point(50, 100), Point(50, 100), &operator!=, "!=", false))
return TestFail;
if (!compare(Point(-50, 100), Point(-50, 100), &operator!=, "!=", false))
return TestFail;
if (!compare(Point(50, -100), Point(50, -100), &operator!=, "!=", false))
return TestFail;
if (!compare(Point(-50, -100), Point(-50, -100), &operator!=, "!=", false))
return TestFail;
|