Refactoring the massive main() to smaller functions.

--HG--
rename : test/test-automation/tests/asserts.c => test/test-automation/tests/SDL_test.c
rename : test/test-automation/tests/asserts.h => test/test-automation/tests/SDL_test.h
This commit is contained in:
Markus Kauppila 2011-05-26 18:38:56 +03:00
parent 4540a8a1b9
commit d6d8dec05e
7 changed files with 137 additions and 83 deletions

View file

@ -1,6 +1,6 @@
lib_LTLIBRARIES = libtest.la
libtest_la_SOURCES = test.c asserts.c
libtest_la_CLAGS = -fPIC
libtest_la_SOURCES = test.c sdl_test.c
libtest_la_CLAGS = -fPIC -g
libtest_la_LDFLAGS = `sdl-config --libs`
distclean-local:

View file

@ -18,21 +18,36 @@
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef _ASSERTS_C
#define _ASSERTS_C
#ifndef _SDL_TEST_C
#define _SDL_TEST_C
#include "asserts.h"
#include "SDL_test.h"
#include <stdlib.h>
static int _testReturnValue;
void
assertEquals(char *message, Uint32 expected, Uint32 actual)
TestInit()
{
_testReturnValue = 0;
}
void
TestQuit()
{
exit(_testReturnValue);
}
void
AssertEquals(char *message, Uint32 expected, Uint32 actual)
{
if(expected != actual) {
printf("===============================\n");
printf("\n===============================\n");
printf("Assert failed: %s\n", message);
printf("Expected %d, got %d\n", expected, actual);
printf("===============================\n");
_testReturnValue = 1;
}
}

View file

@ -18,11 +18,14 @@
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef _ASSERTS_H
#define _ASSERTS_H
#ifndef _SDL_TEST_H
#define _SDL_TEST_H
#include <SDL/SDL.h>
void assertEquals(char *message, Uint32 expected, Uint32 actual);
void TestInit();
void TestQuit();
void AssertEquals(char *message, Uint32 expected, Uint32 actual);
#endif

View file

@ -25,30 +25,42 @@
#include <SDL/SDL.h>
#include "asserts.h"
#include "SDL_test.h"
const char *names[] = {"hello", "hello2", "hello3"};
char *names[] = {"hello", "hello2", "hello3", NULL};
const char **suite() {
char **queryTestNames() {
return names;
}
void hello(void *arg){
TestInit();
const char *revision = SDL_GetRevision();
printf("Revision is %s\n", revision);
assertEquals("will fail", 3, 5);
AssertEquals("will fail", 3, 5);
TestQuit();
}
void hello2(void *arg) {
TestInit();
// why this isn't segfaulting?
char *msg = "eello";
msg[0] = 'H';
TestQuit();
}
void hello3(void *arg) {
printf("hello\n");
TestInit();
printf("hello3\n");
assertEquals("passes", 3, 3);
AssertEquals("passes", 3, 3);
TestQuit();
}
#endif