ImageTests.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <core/Logger.hpp>
  2. #include <cstdio>
  3. #include "../Tests.hpp"
  4. #include "core/Image.hpp"
  5. static void testReadPNG8(
  6. const char* path, const char* name, int width, int height, int channels) {
  7. char fullPath[512];
  8. Core::formatBuffer(fullPath, sizeof(fullPath), "#/#.png", path, name);
  9. Core::Image8 i;
  10. TEST(width == 0, i.read(fullPath));
  11. if(width != 0) {
  12. TEST_TRUE(i.data.getLength() > 0);
  13. }
  14. TEST(width, i.width);
  15. TEST(height, i.height);
  16. TEST(channels, i.channels);
  17. }
  18. static void testReadPNG16(
  19. const char* path, const char* name, int width, int height, int channels) {
  20. char fullPath[512];
  21. Core::formatBuffer(fullPath, sizeof(fullPath), "#/#.png", path, name);
  22. Core::Image16 i;
  23. TEST(width == 0, i.read(fullPath));
  24. if(width != 0) {
  25. TEST_TRUE(i.data.getLength() > 0);
  26. }
  27. TEST(width, i.width);
  28. TEST(height, i.height);
  29. TEST(channels, i.channels);
  30. }
  31. void testImageReader(const char* path) {
  32. testReadPNG8(path, "rgb8", 32, 64, 3);
  33. testReadPNG8(path, "rgb16", 32, 64, 3);
  34. testReadPNG8(path, "rgba8", 32, 64, 4);
  35. testReadPNG8(path, "rgba16", 32, 64, 4);
  36. testReadPNG8(path, "gray8", 32, 64, 1);
  37. testReadPNG8(path, "gray16", 32, 64, 1);
  38. testReadPNG8(path, "graya8", 32, 64, 2);
  39. testReadPNG8(path, "graya16", 32, 64, 2);
  40. useReport = false;
  41. testReadPNG8(path, "nope", 0, 0, 0);
  42. useReport = true;
  43. testReadPNG16(path, "rgb8", 32, 64, 3);
  44. testReadPNG16(path, "rgb16", 32, 64, 3);
  45. testReadPNG16(path, "rgba8", 32, 64, 4);
  46. testReadPNG16(path, "rgba16", 32, 64, 4);
  47. testReadPNG16(path, "gray8", 32, 64, 1);
  48. testReadPNG16(path, "gray16", 32, 64, 1);
  49. testReadPNG16(path, "graya8", 32, 64, 2);
  50. testReadPNG16(path, "graya16", 32, 64, 2);
  51. useReport = false;
  52. testReadPNG16(path, "nope", 0, 0, 0);
  53. useReport = true;
  54. }