ImageReaderTests.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #include "tests/ImageReaderTests.h"
  2. #include "io/ImageReader.h"
  3. #include "tests/Test.h"
  4. #include "utils/StringBuffer.h"
  5. typedef StringBuffer<200> String;
  6. static void testReadPNG(Test& test, const char* path, const char* name,
  7. unsigned int channels, unsigned int bitdepth) {
  8. ImageReader::Image image;
  9. Error error =
  10. ImageReader::load(image, String(path).append(name).append(".png"));
  11. if(error.has()) {
  12. test.checkEqual(false, true,
  13. String("read ").append(name).append(" error"));
  14. return;
  15. }
  16. test.checkEqual(32u, image.width, String(name).append(" width"));
  17. test.checkEqual(64u, image.height, String(name).append(" height"));
  18. test.checkEqual(channels, image.channels, String(name).append(" channels"));
  19. test.checkEqual(bitdepth, image.bitdepth, String(name).append(" bitdepth"));
  20. test.checkEqual(true, image.data != nullptr, String(name).append(" data"));
  21. }
  22. void ImageReaderTests::test(const char* path) {
  23. Test test("ImageReader");
  24. testReadPNG(test, path, "rgb8", 3, 8);
  25. testReadPNG(test, path, "rgb16", 3, 16);
  26. testReadPNG(test, path, "rgba8", 4, 8);
  27. testReadPNG(test, path, "rgba16", 4, 16);
  28. testReadPNG(test, path, "gray8", 1, 8);
  29. testReadPNG(test, path, "gray16", 1, 16);
  30. testReadPNG(test, path, "graya8", 2, 8);
  31. testReadPNG(test, path, "graya16", 2, 16);
  32. test.finalize();
  33. }