|
@@ -0,0 +1,134 @@
|
|
|
+#include "tests/PNGReaderTests.h"
|
|
|
+#include "tests/Test.h"
|
|
|
+#include "images/PNGReader.h"
|
|
|
+#include "utils/StringBuffer.h"
|
|
|
+
|
|
|
+template<int N>
|
|
|
+static void testRead(int correct, Test& test, PNGReader& png, const char* text) {
|
|
|
+ Color<N>* buffer = new Color<N>[png.getBufferSize()];
|
|
|
+ test.checkEqual(N != correct, png.readData(buffer), text);
|
|
|
+ delete[] buffer;
|
|
|
+}
|
|
|
+
|
|
|
+static void testFullRead(int correct, Test& test, PNGReader& png, const char* text) {
|
|
|
+ testRead<1>(correct, test, png, text);
|
|
|
+ testRead<2>(correct, test, png, text);
|
|
|
+ testRead<3>(correct, test, png, text);
|
|
|
+ testRead<4>(correct, test, png, text);
|
|
|
+}
|
|
|
+
|
|
|
+static void testReadRGB8(Test& test, const char* path) {
|
|
|
+ PNGReader png(StringBuffer<200>(path).append("rgb8.png"));
|
|
|
+ if(png.hasError()) {
|
|
|
+ test.checkEqual(false, true, "read rgb8 error");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ test.checkEqual(32, png.getWidth(), "rgb8 width");
|
|
|
+ test.checkEqual(64, png.getHeight(), "rgb8 height");
|
|
|
+ test.checkEqual(3, png.getChannels(), "rgb8 channels");
|
|
|
+ testFullRead(3, test, png, "rgb8 read");
|
|
|
+}
|
|
|
+
|
|
|
+static void testReadRGB16(Test& test, const char* path) {
|
|
|
+ PNGReader png(StringBuffer<200>(path).append("rgb16.png"));
|
|
|
+ if(png.hasError()) {
|
|
|
+ test.checkEqual(false, true, "read rgb16 error");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ test.checkEqual(32, png.getWidth(), "rgb16 width");
|
|
|
+ test.checkEqual(64, png.getHeight(), "rgb16 height");
|
|
|
+ test.checkEqual(3, png.getChannels(), "rgb16 channels");
|
|
|
+ test.checkEqual(32 * 64, png.getBufferSize(), "rgb16 channels");
|
|
|
+ testFullRead(3, test, png, "rgb16 read");
|
|
|
+}
|
|
|
+
|
|
|
+static void testReadRGBA8(Test& test, const char* path) {
|
|
|
+ PNGReader png(StringBuffer<200>(path).append("rgba8.png"));
|
|
|
+ if(png.hasError()) {
|
|
|
+ test.checkEqual(false, true, "read rgba8 error");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ test.checkEqual(32, png.getWidth(), "rgba8 width");
|
|
|
+ test.checkEqual(64, png.getHeight(), "rgba8 height");
|
|
|
+ test.checkEqual(4, png.getChannels(), "rgba8 channels");
|
|
|
+ test.checkEqual(32 * 64, png.getBufferSize(), "rgba8 channels");
|
|
|
+ testFullRead(4, test, png, "rgba8 read");
|
|
|
+}
|
|
|
+
|
|
|
+static void testReadRGBA16(Test& test, const char* path) {
|
|
|
+ PNGReader png(StringBuffer<200>(path).append("rgba16.png"));
|
|
|
+ if(png.hasError()) {
|
|
|
+ test.checkEqual(false, true, "read rgba16 error");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ test.checkEqual(32, png.getWidth(), "rgba16 width");
|
|
|
+ test.checkEqual(64, png.getHeight(), "rgba16 height");
|
|
|
+ test.checkEqual(4, png.getChannels(), "rgba16 channels");
|
|
|
+ test.checkEqual(32 * 64, png.getBufferSize(), "rgba16 channels");
|
|
|
+ testFullRead(4, test, png, "rgba16 read");
|
|
|
+}
|
|
|
+
|
|
|
+static void testReadGray8(Test& test, const char* path) {
|
|
|
+ PNGReader png(StringBuffer<200>(path).append("gray8.png"));
|
|
|
+ if(png.hasError()) {
|
|
|
+ test.checkEqual(false, true, "read gray8 error");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ test.checkEqual(32, png.getWidth(), "gray8 width");
|
|
|
+ test.checkEqual(64, png.getHeight(), "gray8 height");
|
|
|
+ test.checkEqual(1, png.getChannels(), "gray8 channels");
|
|
|
+ test.checkEqual(32 * 64, png.getBufferSize(), "gray8 channels");
|
|
|
+ testFullRead(1, test, png, "gray8 read");
|
|
|
+}
|
|
|
+
|
|
|
+static void testReadGray16(Test& test, const char* path) {
|
|
|
+ PNGReader png(StringBuffer<200>(path).append("gray16.png"));
|
|
|
+ if(png.hasError()) {
|
|
|
+ test.checkEqual(false, true, "read gray16 error");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ test.checkEqual(32, png.getWidth(), "gray16 width");
|
|
|
+ test.checkEqual(64, png.getHeight(), "gray16 height");
|
|
|
+ test.checkEqual(1, png.getChannels(), "gray16 channels");
|
|
|
+ test.checkEqual(32 * 64, png.getBufferSize(), "gray16 channels");
|
|
|
+ testFullRead(1, test, png, "gray16 read");
|
|
|
+}
|
|
|
+
|
|
|
+static void testReadGrayA8(Test& test, const char* path) {
|
|
|
+ PNGReader png(StringBuffer<200>(path).append("graya8.png"));
|
|
|
+ if(png.hasError()) {
|
|
|
+ test.checkEqual(false, true, "read graya8 error");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ test.checkEqual(32, png.getWidth(), "graya8 width");
|
|
|
+ test.checkEqual(64, png.getHeight(), "graya8 height");
|
|
|
+ test.checkEqual(2, png.getChannels(), "graya8 channels");
|
|
|
+ test.checkEqual(32 * 64, png.getBufferSize(), "graya8 channels");
|
|
|
+ testFullRead(2, test, png, "graya8 read");
|
|
|
+}
|
|
|
+
|
|
|
+static void testReadGrayA16(Test& test, const char* path) {
|
|
|
+ PNGReader png(StringBuffer<200>(path).append("graya16.png"));
|
|
|
+ if(png.hasError()) {
|
|
|
+ test.checkEqual(false, true, "read graya16 error");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ test.checkEqual(32, png.getWidth(), "graya16 width");
|
|
|
+ test.checkEqual(64, png.getHeight(), "graya16 height");
|
|
|
+ test.checkEqual(2, png.getChannels(), "graya16 channels");
|
|
|
+ test.checkEqual(32 * 64, png.getBufferSize(), "graya16 channels");
|
|
|
+ testFullRead(2, test, png, "graya16 read");
|
|
|
+}
|
|
|
+
|
|
|
+void PNGReaderTests::test(const char* path) {
|
|
|
+ Test test("PNGReader");
|
|
|
+ testReadRGB8(test, path);
|
|
|
+ testReadRGB16(test, path);
|
|
|
+ testReadRGBA8(test, path);
|
|
|
+ testReadRGBA16(test, path);
|
|
|
+ testReadGray8(test, path);
|
|
|
+ testReadGray16(test, path);
|
|
|
+ testReadGrayA8(test, path);
|
|
|
+ testReadGrayA16(test, path);
|
|
|
+ test.finalize();
|
|
|
+}
|