|
@@ -2,19 +2,15 @@
|
|
|
#include "tests/Test.h"
|
|
|
#include "images/PNGReader.h"
|
|
|
#include "utils/StringBuffer.h"
|
|
|
+#include "memory/StackAllocator.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 testRead(Test& test, PNGReader& png, const char* text) {
|
|
|
+ StackAllocator::Array<ColorChannel> buffer(png.getBufferSize());
|
|
|
+ test.checkEqual(true, png.getBufferSize() > 0, text);
|
|
|
+ test.checkEqual(png.getBufferSize(), buffer.getLength(), text);
|
|
|
+ if(png.getBufferSize() == buffer.getLength()) {
|
|
|
+ test.checkEqual(false, png.readData(buffer), text);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
static void testReadRGB8(Test& test, const char* path) {
|
|
@@ -26,7 +22,7 @@ static void testReadRGB8(Test& test, const char* path) {
|
|
|
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");
|
|
|
+ testRead(test, png, "rgb8 read");
|
|
|
}
|
|
|
|
|
|
static void testReadRGB16(Test& test, const char* path) {
|
|
@@ -39,7 +35,7 @@ static void testReadRGB16(Test& test, const char* path) {
|
|
|
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");
|
|
|
+ testRead(test, png, "rgb16 read");
|
|
|
}
|
|
|
|
|
|
static void testReadRGBA8(Test& test, const char* path) {
|
|
@@ -52,7 +48,7 @@ static void testReadRGBA8(Test& test, const char* path) {
|
|
|
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");
|
|
|
+ testRead(test, png, "rgba8 read");
|
|
|
}
|
|
|
|
|
|
static void testReadRGBA16(Test& test, const char* path) {
|
|
@@ -65,7 +61,7 @@ static void testReadRGBA16(Test& test, const char* path) {
|
|
|
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");
|
|
|
+ testRead(test, png, "rgba16 read");
|
|
|
}
|
|
|
|
|
|
static void testReadGray8(Test& test, const char* path) {
|
|
@@ -78,7 +74,7 @@ static void testReadGray8(Test& test, const char* path) {
|
|
|
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");
|
|
|
+ testRead(test, png, "gray8 read");
|
|
|
}
|
|
|
|
|
|
static void testReadGray16(Test& test, const char* path) {
|
|
@@ -91,7 +87,7 @@ static void testReadGray16(Test& test, const char* path) {
|
|
|
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");
|
|
|
+ testRead(test, png, "gray16 read");
|
|
|
}
|
|
|
|
|
|
static void testReadGrayA8(Test& test, const char* path) {
|
|
@@ -104,7 +100,7 @@ static void testReadGrayA8(Test& test, const char* path) {
|
|
|
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");
|
|
|
+ testRead(test, png, "graya8 read");
|
|
|
}
|
|
|
|
|
|
static void testReadGrayA16(Test& test, const char* path) {
|
|
@@ -117,7 +113,7 @@ static void testReadGrayA16(Test& test, const char* path) {
|
|
|
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");
|
|
|
+ testRead(test, png, "graya16 read");
|
|
|
}
|
|
|
|
|
|
void PNGReaderTests::test(const char* path) {
|