123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- #include "tests/PNGReaderTests.h"
- #include "tests/Test.h"
- #include "images/PNGReader.h"
- #include "utils/StringBuffer.h"
- #include "memory/StackAllocator.h"
- 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) {
- 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");
- testRead(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");
- testRead(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");
- testRead(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");
- testRead(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");
- testRead(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");
- testRead(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");
- testRead(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");
- testRead(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();
- }
|