src/test/SDL_test_harness.c
changeset 6718 918ba414168b
parent 6717 2acd95060548
child 6721 53b71f45a53a
equal deleted inserted replaced
6717:2acd95060548 6718:918ba414168b
    21 
    21 
    22 #include "SDL_config.h"
    22 #include "SDL_config.h"
    23 
    23 
    24 #include "SDL_test.h"
    24 #include "SDL_test.h"
    25 
    25 
    26 // TODO: port over harness
    26 #include <stdio.h>
       
    27 #include <string.h>
       
    28 
       
    29 // TODO: port over remaining harness
    27 
    30 
    28 /**
    31 /**
    29  * Generates a random run seed string for the harness. The generated seed
    32  * Generates a random run seed string for the harness. The generated seed
    30  * will contain alphanumeric characters (0-9A-Z).
    33  * will contain alphanumeric characters (0-9A-Z).
    31  *
    34  *
   138 	SDL_free(buffer);
   141 	SDL_free(buffer);
   139 	keys = (Uint64 *)md5Context.digest;
   142 	keys = (Uint64 *)md5Context.digest;
   140 
   143 
   141 	return keys[0];
   144 	return keys[0];
   142 }
   145 }
       
   146 
       
   147 /**
       
   148  * \brief Set timeout handler for test.
       
   149  *
       
   150  * Note: SDL_Init(SDL_INIT_TIMER) will be called if it wasn't done so before.
       
   151  *
       
   152  * \param timeout Timeout interval in seconds.
       
   153  * \param callback Function that will be called after timeout has elapsed.
       
   154  * 
       
   155  * \return Timer id or -1 on failure.
       
   156  */
       
   157 SDL_TimerID
       
   158 SetTestTimeout(int timeout, void (*callback)())
       
   159 {
       
   160 	Uint32 timeoutInMilliseconds;
       
   161 	SDL_TimerID timerID;
       
   162 
       
   163 	if (callback == NULL) {
       
   164 		SDLTest_LogError("Timeout callback can't be NULL");
       
   165 		return -1;
       
   166 	}
       
   167 
       
   168 	if (timeout < 0) {
       
   169 		SDLTest_LogError("Timeout value must be bigger than zero.");
       
   170 		return -1;
       
   171 	}
       
   172 
       
   173 	/* Init SDL timer if not initialized before */
       
   174 	if (SDL_WasInit(SDL_INIT_TIMER) == 0) {
       
   175 		if (SDL_InitSubSystem(SDL_INIT_TIMER)) {
       
   176 			SDLTest_LogError("Failed to init timer subsystem: %s", SDL_GetError());
       
   177 			return -1;
       
   178 		}
       
   179 	}
       
   180 
       
   181 	/* Set timer */
       
   182 	timeoutInMilliseconds = timeout * 1000;
       
   183 	timerID = SDL_AddTimer(timeoutInMilliseconds, (SDL_TimerCallback)callback, 0x0);
       
   184 	if (timerID == 0) {
       
   185 		SDLTest_LogError("Creation of SDL timer failed: %s", SDL_GetError());
       
   186 		return -1;
       
   187 	}
       
   188 
       
   189 	return timerID;
       
   190 }