testUtils.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #ifndef _TEST_UTILS_H_
  2. #define _TEST_UTILS_H_ 1
  3. #include "irrlicht.h"
  4. #include <assert.h>
  5. #define TestWithAllDrivers(X) \
  6. logTestString("Running test " #X "\n"); \
  7. for (u32 i=1; i<video::EDT_COUNT; ++i) \
  8. result &= X(video::E_DRIVER_TYPE(i))
  9. #define TestWithAllHWDrivers(X) \
  10. logTestString("Running test " #X "\n"); \
  11. for (u32 i=video::EDT_DIRECT3D8; i<video::EDT_COUNT; ++i) \
  12. result &= X(video::E_DRIVER_TYPE(i))
  13. // replacement for assert which does log the lines instead
  14. #define assert_log(X) \
  15. do { \
  16. if ( !(X) ) \
  17. { \
  18. logTestString("ASSERT in %s:%d: %s\n", __FILE__, __LINE__, #X); \
  19. } \
  20. } while (false)
  21. //! Compare two files
  22. /** \param fileName1 The first file for comparison.
  23. \param fileName2 The second file for comparison.
  24. \return true if the files are identical, false on any error or difference. */
  25. extern bool binaryCompareFiles(const char * fileName1, const char * fileName2);
  26. //! Compare two xml-files (which can have different types of text-encoding)
  27. /** \param fs Filesystem which should be used.
  28. \param fileName1 The first file for comparison.
  29. \param fileName2 The second file for comparison.
  30. \return true if the files are identical, false on any error or difference. */
  31. extern bool xmlCompareFiles(irr::io::IFileSystem * fs, const char * fileName1, const char * fileName2);
  32. //! Compare two images, returning the degree to which they match.
  33. /** \param driver The Irrlicht video driver.
  34. \param fileName1 The first image to compare.
  35. \param fileName2 The second image to compare.
  36. \return The match, from 0.f to 100.f */
  37. extern float fuzzyCompareImages(irr::video::IVideoDriver * driver,
  38. const char * fileName1, const char * fileName2);
  39. //! Take a screenshot and compare it against a reference screenshot in the tests/media subdirectory
  40. /** \param driver The Irrlicht video driver.
  41. \param fileName The unique filename suffix that will be appended to the name of the video driver.
  42. \param requiredMatch The degree to which the screenshot needs to match the reference image
  43. in order to be considered a match.
  44. \return true if the screenshot was taken and is identical to the reference image of the same name
  45. in the tests/media directory, false on any error or difference. */
  46. extern bool takeScreenshotAndCompareAgainstReference(irr::video::IVideoDriver * driver,
  47. const char * fileName,
  48. irr::f32 requiredMatch = 99.f);
  49. //! Stabilize the screen background eg. eliminate problems like an aero transparency effects etc.
  50. /** \param driver The Irrlicht video driver.
  51. \return true if required color is the same as a window background color. */
  52. extern void stabilizeScreenBackground(irr::video::IVideoDriver * driver,
  53. irr::video::SColor color = irr::video::SColor(255, 255, 255, 255));
  54. //! Opens a test log file, deleting any existing contents.
  55. /** \param startNewLog true to create a new log file, false to append to an
  56. existing one.
  57. \param filename The filename to open
  58. \return true if the test log file was opened, false on error. */
  59. extern bool openTestLog(bool startNewLog, const char * filename = "tests.log");
  60. //! Close the test log file opened with openTestLog()
  61. extern void closeTestLog();
  62. //! Log a string to the console and the test log file created by openTestLog().
  63. /** \param format The format string
  64. \... optional parameters */
  65. extern void logTestString(const char * format, ...);
  66. //! Return a drivername for the driver which is useable in filenames
  67. extern irr::core::stringc shortDriverName(irr::video::IVideoDriver * driver);
  68. #endif // _TEST_UTILS_H_