Commit 66677c0a authored by Markus Kauppila's avatar Markus Kauppila

Fixed AssertEquals.

parent 7de8abe0
...@@ -3,7 +3,7 @@ ACLOCAL_AMFLAGS = -I acinclude -I build-scripts ...@@ -3,7 +3,7 @@ ACLOCAL_AMFLAGS = -I acinclude -I build-scripts
SUBDIRS = testdummy testrect testplatform testaudio testsurface SUBDIRS = testdummy testrect testplatform testaudio testsurface
bin_PROGRAMS = runner bin_PROGRAMS = runner
runner_SOURCES = runner.c SDL_test.c logger.c xml_logger.c plain_logger.c xml.c logger_helpers.c runner_SOURCES = runner.c SDL_test.c xml_logger.c plain_logger.c xml.c logger_helpers.c
runner_CLAGS = -W -Wall -Wextra -g `sdl-config --cflags` -DSDL_NO_COMPAT runner_CLAGS = -W -Wall -Wextra -g `sdl-config --cflags` -DSDL_NO_COMPAT
runner_LDFLAGS = `sdl-config --libs` runner_LDFLAGS = `sdl-config --libs`
......
...@@ -72,7 +72,7 @@ AssertEquals(int expected, int actual, char *message, ...) ...@@ -72,7 +72,7 @@ AssertEquals(int expected, int actual, char *message, ...)
SDL_vsnprintf( buf, sizeof(buf), message, args ); SDL_vsnprintf( buf, sizeof(buf), message, args );
va_end( args ); va_end( args );
if(expected != expected) { if(expected != actual) {
AssertWithValues("AssertEquals", 0, buf, actual, expected, time(0)); AssertWithValues("AssertEquals", 0, buf, actual, expected, time(0));
_testReturnValue = TEST_RESULT_FAILURE; _testReturnValue = TEST_RESULT_FAILURE;
......
...@@ -90,7 +90,7 @@ int _CountFailedAsserts(); ...@@ -90,7 +90,7 @@ int _CountFailedAsserts();
* \param actual The actual value of tested variable * \param actual The actual value of tested variable
* \param message Message that will be printed * \param message Message that will be printed
*/ */
void AssertEquals(const int expected, const int actual, char *message, ...); void AssertEquals(int expected, int actual, char *message, ...);
/*! /*!
* Assert function. Tests if the given condition is true. True in * Assert function. Tests if the given condition is true. True in
......
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <SDL/SDL.h>
#include "logger.h"
#include "xml_logger.h"
#include "plain_logger.h"
...@@ -45,7 +45,7 @@ typedef void (*AssertFp)(const char *assertName, int assertResult, ...@@ -45,7 +45,7 @@ typedef void (*AssertFp)(const char *assertName, int assertResult,
const char *assertMessage, time_t eventTime); const char *assertMessage, time_t eventTime);
typedef void (*AssertWithValuesFp)(const char *assertName, int assertResult, typedef void (*AssertWithValuesFp)(const char *assertName, int assertResult,
const char *assertMessage, int actualValue, int excpected, const char *assertMessage, int actualValue, int expected,
time_t eventTime); time_t eventTime);
typedef void (*AssertSummaryFp)(int numAsserts, int numAssertsFailed, typedef void (*AssertSummaryFp)(int numAsserts, int numAssertsFailed,
......
...@@ -15,22 +15,29 @@ static int indentLevel; ...@@ -15,22 +15,29 @@ static int indentLevel;
/*! /*!
* Prints out the output of the logger * Prints out the output of the logger
* *
* \param currentIdentLevel The currently used indentation level * \param currentIndentLevel The currently used indentation level
* \param message The message to be printed out * \param message The message to be printed out
*/ */
int int
Output(const int currentIdentLevel, const char *message, ...) Output(const int currentIndentLevel, const char *message, ...)
{ {
va_list list;
va_start(list, message);
int ident = 0; int ident = 0;
for( ; ident < currentIdentLevel; ++ident) { for( ; ident < currentIndentLevel; ++ident) {
fprintf(stdout, " "); // \todo make configurable? fprintf(stdout, " "); // \todo make configurable?
} }
char buffer[1024];
SDL_vsnprintf(buffer, sizeof(buffer), message, list); char buffer[1024];
memset(buffer, 0, 1024);
va_list list;
va_start(list, message);
SDL_vsnprintf(buffer, 1024, message, list);
va_end(list);
fprintf(stdout, "%s\n", buffer); fprintf(stdout, "%s\n", buffer);
fflush(stdout); fflush(stdout);
...@@ -121,11 +128,11 @@ PlainAssert(const char *assertName, int assertResult, const char *assertMessage, ...@@ -121,11 +128,11 @@ PlainAssert(const char *assertName, int assertResult, const char *assertMessage,
void void
PlainAssertWithValues(const char *assertName, int assertResult, const char *assertMessage, PlainAssertWithValues(const char *assertName, int assertResult, const char *assertMessage,
int actualValue, int expected, time_t eventTime) int actualValue, int expectedValue, time_t eventTime)
{ {
const char *result = (assertResult) ? "passed" : "failed"; const char *result = (assertResult) ? "passed" : "failed";
Output(indentLevel, "%s: %s (expected %d, actualValue &d) - %s", Output(indentLevel, "%s: %s (expected %d, actualValue %d) - %s",
assertName, result, expected, actualValue, assertMessage); assertName, result, expectedValue, actualValue, assertMessage);
} }
void void
......
...@@ -586,9 +586,11 @@ LoadCountFailedAssertsFunction(void *suite) { ...@@ -586,9 +586,11 @@ LoadCountFailedAssertsFunction(void *suite) {
/* /*
* Execute the test * Execute a test. Loads the test, executes it and
* returns the tests return value to the caller.
* *
* \param testItem Test to be executed * \param testItem Test to be executed
* \param test result
*/ */
int int
RunTest(TestCase *testItem) { RunTest(TestCase *testItem) {
...@@ -629,8 +631,8 @@ void KillHungTest(int signum) { ...@@ -629,8 +631,8 @@ void KillHungTest(int signum) {
} }
/*! /*!
* Executes a test case. Loads the test, executes it and * Sets up a test case. Decideds wheter the test will
* returns the tests return value to the caller. * be executed in-proc or out-of-proc.
* *
* \param testItem The test case that will be executed * \param testItem The test case that will be executed
* \return The return value of the test. Zero means success, non-zero failure. * \return The return value of the test. Zero means success, non-zero failure.
......
...@@ -88,8 +88,7 @@ TearDown(void *arg) ...@@ -88,8 +88,7 @@ TearDown(void *arg)
void void
dummycase1(void *arg) dummycase1(void *arg)
{ {
//AssertEquals(5, 5, "Assert message"); AssertEquals(5, 5, "Assert message");
while(1);
} }
void void
......
...@@ -76,18 +76,18 @@ static int prevEOL = YES; ...@@ -76,18 +76,18 @@ static int prevEOL = YES;
* *
* \todo Make the destination of the output changeable (defaults to stdout) * \todo Make the destination of the output changeable (defaults to stdout)
* *
* \param identLevel the indent level of the message * \param currentIndentLevel the indent level of the message
* \param EOL will it print end of line character or not * \param EOL will it print end of line character or not
* \param the XML element itself * \param the XML element itself
* *
*/ */
void void
XMLOutputter(const int currentIdentLevel, XMLOutputter(const int currentIndentLevel,
int EOL, const char *message) int EOL, const char *message)
{ {
if(ValidateString(message)) { if(ValidateString(message)) {
int ident = 0; int ident = 0;
for( ; ident < currentIdentLevel && prevEOL; ++ident) { for( ; ident < currentIndentLevel && prevEOL; ++ident) {
fprintf(stdout, " "); // \todo make configurable? fprintf(stdout, " "); // \todo make configurable?
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment