enumerateImageManipulators.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // Copyright (C) 2008-2012 Colin MacDonald
  2. // No rights reserved: this software is in the public domain.
  3. #include "testUtils.h"
  4. using namespace irr;
  5. using namespace scene;
  6. using namespace video;
  7. bool enumerateImageManipulators(void)
  8. {
  9. IrrlichtDevice *device = createDevice(video::EDT_NULL);
  10. if (!device)
  11. return false;
  12. IVideoDriver* driver = device->getVideoDriver();
  13. const char* filenames[] =
  14. {
  15. "foo.bmp",
  16. "foo.jpg",
  17. "foo.pcx",
  18. "foo.png",
  19. "foo.ppm",
  20. "foo.psd",
  21. "foo.tga",
  22. // the following have no writers
  23. "foo.wal",
  24. "foo.pgm",
  25. "foo.pbm",
  26. "foo.rgb",
  27. "foo.rgba",
  28. "foo.sgi",
  29. "foo.int",
  30. "foo.inta",
  31. "foo.bw"
  32. };
  33. // how many formats have loaders?
  34. const u32 writersUntil = 7;
  35. const u32 numberOfFilenames = sizeof(filenames) / sizeof(filenames[0]);
  36. bool loaderForFilename[numberOfFilenames] = { false }; // and the rest get 0 == false
  37. bool writerForFilename[numberOfFilenames] = { false }; // and the rest get 0 == false
  38. bool result = true;
  39. u32 i;
  40. const u32 loaders = driver->getImageLoaderCount();
  41. for (i = 0; i < loaders; ++i)
  42. {
  43. IImageLoader * loader = driver->getImageLoader(i);
  44. if(!loader)
  45. {
  46. logTestString("Failed to get image loader %d\n", i);
  47. assert_log(false);
  48. result = false;
  49. }
  50. for(u32 filename = 0; filename < numberOfFilenames; ++filename)
  51. {
  52. if(loader->isALoadableFileExtension(filenames[filename]))
  53. {
  54. loaderForFilename[filename] = true;
  55. }
  56. }
  57. }
  58. IImageLoader * loader = driver->getImageLoader(i);
  59. assert_log(loader == 0);
  60. if(loader)
  61. {
  62. logTestString("Got a loader when none was expected (%d)\n", i);
  63. result = false;
  64. }
  65. for(u32 filename = 0; filename < numberOfFilenames; ++filename)
  66. {
  67. if(!loaderForFilename[filename])
  68. {
  69. logTestString("File type '%s' doesn't have a loader\n", filenames[filename]);
  70. assert_log(false);
  71. result = false;
  72. }
  73. }
  74. const u32 writers = driver->getImageWriterCount();
  75. for (i = 0; i < writers; ++i)
  76. {
  77. IImageWriter * writer = driver->getImageWriter(i);
  78. if(!writer)
  79. {
  80. logTestString("Failed to get image writer %d\n", i);
  81. assert_log(false);
  82. result = false;
  83. }
  84. for(u32 filename = 0; filename < numberOfFilenames; ++filename)
  85. {
  86. if(writer->isAWriteableFileExtension(filenames[filename]))
  87. {
  88. writerForFilename[filename] = true;
  89. break;
  90. }
  91. }
  92. }
  93. IImageWriter * writer = driver->getImageWriter(i);
  94. assert_log(writer == 0);
  95. if(writer)
  96. {
  97. logTestString("Got a writer when none was expected (%d)\n", i);
  98. result = false;
  99. }
  100. for(u32 filename = 0; filename < numberOfFilenames; ++filename)
  101. {
  102. // There's no writer for the .WAL file type.
  103. if(!writerForFilename[filename] && (filename<writersUntil))
  104. {
  105. logTestString("File type '%s' doesn't have a writer\n", filenames[filename]);
  106. assert_log(false);
  107. result = false;
  108. }
  109. }
  110. device->closeDevice();
  111. device->run();
  112. device->drop();
  113. return result;
  114. }