2008-11-29 14:35:56 -08:00
# ifndef _TEST_UTILS_H_
# define _TEST_UTILS_H_ 1
2009-01-16 06:19:38 -08:00
# include "irrlicht.h"
2009-08-24 02:12:27 -07:00
# include <assert.h>
2009-01-16 06:19:38 -08:00
2016-07-08 13:41:42 -07:00
// Small hack. Some newer X11 systems can't handle switching drivers too fast (causing BadWindow errors in X_ChangeWindowAttributes).
// Could be they don't like when Windows with different Visuals are created very quickly (it always happened after creating a new Window with different Visual to previous one).
// timeMs value set by try&error
# ifdef _IRR_POSIX_API_
# include <time.h>
# define SLOW_SWITCH \
do { \
struct timespec ts ; \
const int timeMs = 250 ; \
ts . tv_sec = ( time_t ) ( timeMs / 1000 ) ; \
ts . tv_nsec = ( long ) ( timeMs % 1000 ) * 1000000 ; \
nanosleep ( & ts , NULL ) ; \
} while ( false )
# else
# define SLOW_SWITCH
# endif
2011-06-16 05:06:27 -07:00
# define TestWithAllDrivers(X) \
2011-06-08 10:05:49 -07:00
logTestString ( " Running test " # X " \n " ) ; \
2016-07-08 13:41:42 -07:00
for ( u32 i = 1 ; i < video : : EDT_COUNT ; + + i ) \
if ( video : : E_DRIVER_TYPE ( i ) ! = video : : DEPRECATED_EDT_DIRECT3D8_NO_LONGER_EXISTS & & irr : : IrrlichtDevice : : isDriverSupported ( ( irr : : video : : E_DRIVER_TYPE ) i ) ) \
{ \
SLOW_SWITCH ; \
result & = X ( video : : E_DRIVER_TYPE ( i ) ) ; \
}
2011-06-16 05:06:27 -07:00
# define TestWithAllHWDrivers(X) \
2016-07-08 13:41:42 -07:00
SLOW_SWITCH ; \
2011-06-08 10:05:49 -07:00
logTestString ( " Running test " # X " \n " ) ; \
2015-03-23 13:44:22 -07:00
for ( u32 i = video : : EDT_DIRECT3D9 ; i < video : : EDT_COUNT ; + + i ) \
2016-07-08 13:41:42 -07:00
if ( irr : : IrrlichtDevice : : isDriverSupported ( ( irr : : video : : E_DRIVER_TYPE ) i ) ) \
{ \
SLOW_SWITCH ; \
result & = X ( video : : E_DRIVER_TYPE ( i ) ) ; \
}
2011-06-07 14:09:32 -07:00
2012-04-03 14:27:22 -07:00
// replacement for assert which does log the lines instead
# define assert_log(X) \
do { \
if ( ! ( X ) ) \
{ \
logTestString ( " ASSERT in %s:%d: %s \n " , __FILE__ , __LINE__ , # X ) ; \
} \
} while ( false )
2008-11-29 14:35:56 -08:00
//! Compare two files
/** \param fileName1 The first file for comparison.
2011-06-08 10:05:49 -07:00
\ param fileName2 The second file for comparison .
2008-11-29 14:35:56 -08:00
\ return true if the files are identical , false on any error or difference . */
extern bool binaryCompareFiles ( const char * fileName1 , const char * fileName2 ) ;
2012-02-20 11:43:51 -08:00
//! Compare two xml-files (which can have different types of text-encoding)
/** \param fs Filesystem which should be used.
\ param fileName1 The first file for comparison .
\ param fileName2 The second file for comparison .
\ return true if the files are identical , false on any error or difference . */
extern bool xmlCompareFiles ( irr : : io : : IFileSystem * fs , const char * fileName1 , const char * fileName2 ) ;
2012-04-24 09:53:46 -07:00
//! Compare two images, returning the degree to which they match.
/** \param driver The Irrlicht video driver.
\ param fileName1 The first image to compare .
\ param fileName2 The second image to compare .
\ return The match , from 0.f to 100.f */
extern float fuzzyCompareImages ( irr : : video : : IVideoDriver * driver ,
const char * fileName1 , const char * fileName2 ) ;
2008-11-29 14:35:56 -08:00
//! Take a screenshot and compare it against a reference screenshot in the tests/media subdirectory
/** \param driver The Irrlicht video driver.
2008-12-15 06:18:11 -08:00
\ param fileName The unique filename suffix that will be appended to the name of the video driver .
\ param requiredMatch The degree to which the screenshot needs to match the reference image
in order to be considered a match .
2008-11-29 14:35:56 -08:00
\ return true if the screenshot was taken and is identical to the reference image of the same name
in the tests / media directory , false on any error or difference . */
2008-12-15 06:18:11 -08:00
extern bool takeScreenshotAndCompareAgainstReference ( irr : : video : : IVideoDriver * driver ,
const char * fileName ,
irr : : f32 requiredMatch = 99.f ) ;
2008-11-29 14:35:56 -08:00
2012-04-28 11:23:23 -07:00
//! Stabilize the screen background eg. eliminate problems like an aero transparency effects etc.
/** \param driver The Irrlicht video driver.
\ return true if required color is the same as a window background color . */
extern void stabilizeScreenBackground ( irr : : video : : IVideoDriver * driver ,
irr : : video : : SColor color = irr : : video : : SColor ( 255 , 255 , 255 , 255 ) ) ;
2008-11-29 14:35:56 -08:00
2008-12-03 14:26:53 -08:00
//! Opens a test log file, deleting any existing contents.
2008-12-15 06:18:11 -08:00
/** \param startNewLog true to create a new log file, false to append to an
existing one .
\ param filename The filename to open
2008-12-03 14:26:53 -08:00
\ return true if the test log file was opened , false on error . */
2008-12-15 06:18:11 -08:00
extern bool openTestLog ( bool startNewLog , const char * filename = " tests.log " ) ;
2008-12-03 14:26:53 -08:00
//! Close the test log file opened with openTestLog()
extern void closeTestLog ( ) ;
//! Log a string to the console and the test log file created by openTestLog().
/** \param format The format string
\ . . . optional parameters */
extern void logTestString ( const char * format , . . . ) ;
2012-06-12 13:59:47 -07:00
//! Return a drivername for the driver which is useable in filenames
extern irr : : core : : stringc shortDriverName ( irr : : video : : IVideoDriver * driver ) ;
2008-11-29 14:35:56 -08:00
# endif // _TEST_UTILS_H_