2011-05-23 17:49:06 +03:00
|
|
|
/*
|
|
|
|
Copyright (C) 2011 Markus Kauppila <markus.kauppila@gmail.com>
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
|
2011-05-26 18:38:56 +03:00
|
|
|
#ifndef _SDL_TEST_C
|
|
|
|
#define _SDL_TEST_C
|
2011-05-23 17:49:06 +03:00
|
|
|
|
2011-06-01 18:03:09 -07:00
|
|
|
#include <stdio.h> /* printf/fprintf */
|
|
|
|
#include <stdarg.h> /* va_list */
|
2011-06-27 21:41:34 +03:00
|
|
|
#include <time.h>
|
2011-06-01 18:03:09 -07:00
|
|
|
|
2011-06-26 23:04:37 +03:00
|
|
|
#include "logger.h"
|
|
|
|
|
2011-05-26 18:38:56 +03:00
|
|
|
#include "SDL_test.h"
|
2011-05-23 17:49:06 +03:00
|
|
|
|
2011-05-30 11:53:59 +03:00
|
|
|
/*! \brief return value of test case. Non-zero value means that the test failed */
|
2011-06-04 17:50:23 +03:00
|
|
|
int _testReturnValue;
|
2011-05-26 18:38:56 +03:00
|
|
|
|
2011-06-04 17:50:23 +03:00
|
|
|
/*! \brief counts the failed asserts */
|
|
|
|
int _testAssertsFailed;
|
|
|
|
|
|
|
|
/*! \brief counts the passed asserts */
|
|
|
|
int _testAssertsPassed;
|
2011-06-01 18:03:09 -07:00
|
|
|
|
2011-05-26 18:38:56 +03:00
|
|
|
void
|
2011-07-06 16:06:39 +03:00
|
|
|
_TestCaseInit()
|
2011-05-26 18:38:56 +03:00
|
|
|
{
|
|
|
|
_testReturnValue = 0;
|
2011-06-01 18:03:09 -07:00
|
|
|
_testAssertsFailed = 0;
|
|
|
|
_testAssertsPassed = 0;
|
2011-05-26 18:38:56 +03:00
|
|
|
}
|
|
|
|
|
2011-05-30 12:55:40 +03:00
|
|
|
int
|
2011-06-04 17:50:23 +03:00
|
|
|
_TestCaseQuit()
|
2011-05-26 18:38:56 +03:00
|
|
|
{
|
2011-06-26 23:04:37 +03:00
|
|
|
AssertSummary(_testAssertsFailed + _testAssertsPassed,
|
2011-06-27 21:41:34 +03:00
|
|
|
_testAssertsFailed, _testAssertsPassed, time(0));
|
2011-06-04 18:08:54 +03:00
|
|
|
|
2011-06-04 17:58:46 +03:00
|
|
|
if(_testAssertsFailed == 0 && _testAssertsPassed == 0) {
|
|
|
|
_testReturnValue = 2;
|
|
|
|
}
|
|
|
|
|
2011-05-30 12:55:40 +03:00
|
|
|
return _testReturnValue;
|
2011-05-26 18:38:56 +03:00
|
|
|
}
|
|
|
|
|
2011-06-04 17:50:23 +03:00
|
|
|
void
|
2011-06-01 18:03:09 -07:00
|
|
|
AssertEquals(Uint32 expected, Uint32 actual, char* message, ...)
|
2011-05-23 17:49:06 +03:00
|
|
|
{
|
2011-06-01 18:03:09 -07:00
|
|
|
va_list args;
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
if(expected != actual) {
|
|
|
|
va_start( args, message );
|
|
|
|
SDL_vsnprintf( buf, sizeof(buf), message, args );
|
|
|
|
va_end( args );
|
2011-06-27 22:14:48 +03:00
|
|
|
AssertWithValues("AssertEquals", 0, buf, actual, expected, time(0));
|
2011-06-26 23:04:37 +03:00
|
|
|
|
2011-06-01 18:03:09 -07:00
|
|
|
_testReturnValue = 1;
|
|
|
|
_testAssertsFailed++;
|
|
|
|
} else {
|
2011-07-09 17:55:35 +03:00
|
|
|
AssertWithValues("AssertEquals", 1, buf,
|
2011-06-27 22:14:48 +03:00
|
|
|
actual, expected, time(0));
|
2011-06-26 23:04:37 +03:00
|
|
|
|
2011-06-01 18:03:09 -07:00
|
|
|
_testAssertsPassed++;
|
|
|
|
}
|
2011-05-23 17:49:06 +03:00
|
|
|
}
|
|
|
|
|
2011-06-04 17:50:23 +03:00
|
|
|
void
|
2011-06-01 18:03:09 -07:00
|
|
|
AssertTrue(int condition, char *message, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
if (!condition) {
|
|
|
|
va_start( args, message );
|
|
|
|
SDL_vsnprintf( buf, sizeof(buf), message, args );
|
|
|
|
va_end( args );
|
|
|
|
|
2011-06-27 21:41:34 +03:00
|
|
|
Assert("AssertTrue", 0, buf, time(0));
|
2011-06-26 23:04:37 +03:00
|
|
|
|
2011-06-01 18:03:09 -07:00
|
|
|
_testReturnValue = 1;
|
|
|
|
_testAssertsFailed++;
|
|
|
|
} else {
|
2011-07-09 17:55:35 +03:00
|
|
|
va_start( args, message );
|
|
|
|
SDL_vsnprintf( buf, sizeof(buf), message, args );
|
|
|
|
va_end( args );
|
|
|
|
|
|
|
|
Assert("AssertTrue", 1, buf, time(0));
|
|
|
|
_testAssertsPassed++;
|
2011-06-01 18:03:09 -07:00
|
|
|
}
|
|
|
|
}
|
2011-05-26 19:19:46 +03:00
|
|
|
|
2011-06-18 10:36:27 -07:00
|
|
|
void
|
|
|
|
AssertPass(char *message, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
va_start( args, message );
|
|
|
|
SDL_vsnprintf( buf, sizeof(buf), message, args );
|
|
|
|
va_end( args );
|
|
|
|
|
2011-06-27 21:41:34 +03:00
|
|
|
Assert("AssertPass", 1, buf, time(0));
|
2011-06-18 10:36:27 -07:00
|
|
|
|
|
|
|
_testAssertsPassed++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AssertFail(char *message, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
va_start( args, message );
|
|
|
|
SDL_vsnprintf( buf, sizeof(buf), message, args );
|
|
|
|
va_end( args );
|
|
|
|
|
2011-06-27 21:41:34 +03:00
|
|
|
Assert("AssertFail", 0, buf, time(0));
|
2011-06-18 10:36:27 -07:00
|
|
|
|
|
|
|
_testAssertsFailed++;
|
|
|
|
}
|
|
|
|
|
2011-05-23 17:49:06 +03:00
|
|
|
#endif
|