diff --git a/test/Makefile.am b/test/Makefile.am index 7bb1675d..3df808d5 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -14,12 +14,15 @@ CLEANFILES = $(noinst_PROGRAMS:%$(EXEEXT)=%.self) \ $(noinst_PROGRAMS:%$(EXEEXT)=%.elf) \ $(noinst_PROGRAMS:%$(EXEEXT)=%.exe) +EXTRA_DIST = data/gradient.png + noinst_PROGRAMS = quad sandbox benchsuite testsuite TESTS = testsuite testsuite_SOURCES = testsuite.cpp \ - unit/matrix.cpp unit/half.cpp unit/trig.cpp unit/build.cpp unit/real.cpp + unit/matrix.cpp unit/half.cpp unit/trig.cpp unit/build.cpp \ + unit/real.cpp unit/image.cpp testsuite_CPPFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@ testsuite_LDFLAGS = $(top_builddir)/src/liblol.a @LOL_LIBS@ @PIPI_LIBS@ testsuite_DEPENDENCIES = $(top_builddir)/src/liblol.a diff --git a/test/data/gradient.png b/test/data/gradient.png new file mode 100644 index 00000000..2789c49e Binary files /dev/null and b/test/data/gradient.png differ diff --git a/test/unit/image.cpp b/test/unit/image.cpp new file mode 100644 index 00000000..ae2a5a80 --- /dev/null +++ b/test/unit/image.cpp @@ -0,0 +1,50 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2011 Sam Hocevar +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include "core.h" +#include "lol/unit.h" + +namespace lol +{ + +LOLUNIT_FIXTURE(ImageTest) +{ + LOLUNIT_TEST(OpenImage) + { + Image *image = new Image("data/gradient.png"); + LOLUNIT_ASSERT(image); + + ivec2 size = image->GetSize(); + LOLUNIT_ASSERT_EQUAL(size.x, 256); + LOLUNIT_ASSERT_EQUAL(size.y, 16); + + uint8_t *data = (uint8_t *)image->GetData(); + LOLUNIT_ASSERT(data); + + LOLUNIT_ASSERT_EQUAL((int)data[0], 0x00); + LOLUNIT_ASSERT_EQUAL((int)data[1], 0x00); + LOLUNIT_ASSERT_EQUAL((int)data[2], 0x00); + + LOLUNIT_ASSERT_EQUAL((int)data[255 * 4 + 0], 0xff); + LOLUNIT_ASSERT_EQUAL((int)data[255 * 4 + 1], 0xff); + LOLUNIT_ASSERT_EQUAL((int)data[255 * 4 + 2], 0xff); + + delete image; + } +}; + +} /* namespace lol */ +