#include <cameraModeRequest.h>
#include <gtest/gtest.h>
#include <support/exceptionAssertions.h>

namespace lcamera_dev {
namespace {

TEST(CameraModeRequestTest, DefaultFullPlanarIsOptionalIsFalse)
{
	LcameraDevCameraModeRequest request;
	EXPECT_FALSE(request.fullPlanarIsOptional);
}

TEST(CameraModeRequestTest, ZeroWidthThrows)
{
	LcameraDevCameraModeRequest request;
	request.width = 0;
	request.height = 480;

	EXPECT_THROW(
		validateCameraModeRequest(request),
		std::runtime_error);
}

TEST(CameraModeRequestTest, ZeroHeightThrows)
{
	LcameraDevCameraModeRequest request;
	request.width = 640;
	request.height = 0;

	EXPECT_THROW(
		validateCameraModeRequest(request),
		std::runtime_error);
}

TEST(CameraModeRequestTest, UnsupportedColourSpaceThrows)
{
	LcameraDevCameraModeRequest request;
	request.width = 640;
	request.height = 480;

	static_assert(
		static_cast<int>(LcameraDevColourSpace::Yuv) == 0,
		"test assumes Yuv is first enumerator");

	const LcameraDevColourSpace unsupportedColourSpace =
		static_cast<LcameraDevColourSpace>(1);
	request.colourSpace = unsupportedColourSpace;

	EXPECT_THROW(
		validateCameraModeRequest(request),
		std::runtime_error);
}

TEST(CameraModeRequestTest, CameraModeRequestsEqualComparesOptionalPlanarFlag)
{
	LcameraDevCameraModeRequest left;
	left.width = 640;
	left.height = 480;
	left.colourSpace = LcameraDevColourSpace::Yuv;
	left.fullPlanarIsOptional = false;

	LcameraDevCameraModeRequest right = left;
	EXPECT_TRUE(cameraModeRequestsEqual(left, right));

	right.fullPlanarIsOptional = true;
	EXPECT_FALSE(cameraModeRequestsEqual(left, right));
}

TEST(CameraModeRequestTest, CameraModeRequestsEqualComparesAllFields)
{
	LcameraDevCameraModeRequest left;
	left.width = 640;
	left.height = 480;
	left.colourSpace = LcameraDevColourSpace::Yuv;
	left.fullPlanarIsOptional = false;

	LcameraDevCameraModeRequest right = left;
	EXPECT_TRUE(cameraModeRequestsEqual(left, right));

	right.height = 720;
	EXPECT_FALSE(cameraModeRequestsEqual(left, right));
}

} // namespace
} // namespace lcamera_dev
