#include <pixelAndColorFormatDecisions.h>
#include <gtest/gtest.h>

namespace smo {
namespace stim_buff {
namespace lcamera_buff {
namespace {

lcamera_dev::LcameraDevConfiguredCameraMode makeConfiguredMode(
	const char *pixelFormatName)
{
	lcamera_dev::LcameraDevConfiguredCameraMode mode;
	mode.width = 640;
	mode.height = 480;
	mode.pixelFormatName = pixelFormatName;
	return mode;
}

TEST(PixelAndColorFormatDecisionsTest, YuyvClassifiesAsYuv422)
{
	const lcamera_dev::LcameraDevConfiguredCameraMode mode =
		makeConfiguredMode("YUYV");

	EXPECT_EQ(
		classifyYuvChromaSubsampling(mode),
		YuvChromaSubsampling::Yuv422);
}

TEST(PixelAndColorFormatDecisionsTest, Yuv420ChannelSizes)
{
	EXPECT_EQ(
		computeDeinterleavedChannelByteSize(
			YuvChannelKind::Y,
			640,
			480,
			YuvChromaSubsampling::Yuv420),
		640u * 480u);
	EXPECT_EQ(
		computeDeinterleavedChannelByteSize(
			YuvChannelKind::U,
			640,
			480,
			YuvChromaSubsampling::Yuv420),
		320u * 240u);
	EXPECT_EQ(
		computeDeinterleavedChannelByteSize(
			YuvChannelKind::V,
			640,
			480,
			YuvChromaSubsampling::Yuv420),
		320u * 240u);
}

TEST(PixelAndColorFormatDecisionsTest, Yuv422ChannelSizesForDellLaptopYuyv)
{
	EXPECT_EQ(
		computeDeinterleavedChannelByteSize(
			YuvChannelKind::Y,
			640,
			480,
			YuvChromaSubsampling::Yuv422),
		640u * 480u);
	EXPECT_EQ(
		computeDeinterleavedChannelByteSize(
			YuvChannelKind::U,
			640,
			480,
			YuvChromaSubsampling::Yuv422),
		320u * 480u);
	EXPECT_EQ(
		computeDeinterleavedChannelByteSize(
			YuvChannelKind::V,
			640,
			480,
			YuvChromaSubsampling::Yuv422),
		320u * 480u);
}

} // namespace
} // namespace lcamera_buff
} // namespace stim_buff
} // namespace smo
