test/testautomation_main.c
author Andreas Schiffler <aschiffler@ferzkopp.net>
Tue, 12 Feb 2013 22:23:42 -0800
changeset 6872 2f4c95464651
parent 6869 baac6ec78a95
child 7144 c700de9c8ed4
permissions -rw-r--r--
Fix fuzzer random boundary functions; add tests for fuzzer
jorgen@6866
     1
/**
jorgen@6866
     2
 * Automated SDL subsystems management test.
jorgen@6866
     3
 *
jorgen@6866
     4
 * Written by Jørgen Tjernø "jorgenpt"
jorgen@6866
     5
 *
jorgen@6866
     6
 * Released under Public Domain.
jorgen@6866
     7
 */
jorgen@6866
     8
jorgen@6866
     9
#include "SDL.h"
jorgen@6866
    10
#include "SDL_test.h"
jorgen@6866
    11
jorgen@6866
    12
jorgen@6866
    13
/*!
jorgen@6866
    14
 * \brief Tests SDL_Init() and SDL_Quit()
jorgen@6866
    15
 * \sa
jorgen@6866
    16
 * http://wiki.libsdl.org/moin.cgi/SDL_Init
jorgen@6866
    17
 * http://wiki.libsdl.org/moin.cgi/SDL_Quit
jorgen@6866
    18
 */
jorgen@6866
    19
static int main_testInitQuit (void *arg)
jorgen@6866
    20
{
jorgen@6869
    21
    int enabled_subsystems;
jorgen@6866
    22
    int initialized_subsystems = SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC;
jorgen@6866
    23
jorgen@6866
    24
    SDLTest_AssertCheck( SDL_Init(initialized_subsystems) == 0, "SDL_Init multiple systems." );
jorgen@6866
    25
jorgen@6869
    26
    enabled_subsystems = SDL_WasInit(initialized_subsystems);
jorgen@6866
    27
    SDLTest_AssertCheck( enabled_subsystems == initialized_subsystems, "SDL_WasInit(SDL_INIT_EVERYTHING) contains all systems (%i)", enabled_subsystems );
jorgen@6866
    28
jorgen@6866
    29
    SDL_Quit();
jorgen@6866
    30
jorgen@6866
    31
    enabled_subsystems = SDL_WasInit(initialized_subsystems);
jorgen@6866
    32
    SDLTest_AssertCheck( enabled_subsystems == 0, "SDL_Quit should shut down everything (%i)", enabled_subsystems );
jorgen@6866
    33
jorgen@6866
    34
    return TEST_COMPLETED;
jorgen@6866
    35
}
jorgen@6866
    36
jorgen@6866
    37
/*!
jorgen@6866
    38
 * \brief Tests SDL_InitSubSystem() and SDL_QuitSubSystem()
jorgen@6866
    39
 * \sa
jorgen@6866
    40
 * http://wiki.libsdl.org/moin.cgi/SDL_Init
jorgen@6866
    41
 * http://wiki.libsdl.org/moin.cgi/SDL_Quit
jorgen@6866
    42
 */
jorgen@6866
    43
static int main_testInitQuitSubSystem (void *arg)
jorgen@6866
    44
{
jorgen@6866
    45
    int i;
jorgen@6866
    46
    int subsystems[] = { SDL_INIT_JOYSTICK, SDL_INIT_HAPTIC, SDL_INIT_GAMECONTROLLER };
jorgen@6866
    47
jorgen@6866
    48
    for (i = 0; i < SDL_arraysize(subsystems); ++i) {
jorgen@6869
    49
        int initialized_system;
jorgen@6866
    50
        int subsystem = subsystems[i];
jorgen@6866
    51
jorgen@6866
    52
        SDLTest_AssertCheck( (SDL_WasInit(subsystem) & subsystem) == 0, "SDL_WasInit(%x) before init should be false", subsystem );
jorgen@6866
    53
        SDLTest_AssertCheck( SDL_InitSubSystem(subsystem) == 0, "SDL_InitSubSystem(%x)", subsystem );
jorgen@6866
    54
jorgen@6869
    55
        initialized_system = SDL_WasInit(subsystem);
jorgen@6866
    56
        SDLTest_AssertCheck( (initialized_system & subsystem) != 0, "SDL_WasInit(%x) should be true (%x)", subsystem, initialized_system );
jorgen@6866
    57
jorgen@6866
    58
        SDL_QuitSubSystem(subsystem);
jorgen@6866
    59
jorgen@6866
    60
        SDLTest_AssertCheck( (SDL_WasInit(subsystem) & subsystem) == 0, "SDL_WasInit(%x) after shutdown should be false", subsystem );
jorgen@6866
    61
    }
jorgen@6866
    62
jorgen@6866
    63
    return TEST_COMPLETED;
jorgen@6866
    64
}
jorgen@6866
    65
jorgen@6866
    66
const int joy_and_controller = SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER;
jorgen@6866
    67
static int main_testImpliedJoystickInit (void *arg)
jorgen@6866
    68
{
jorgen@6869
    69
    int initialized_system;
jorgen@6869
    70
jorgen@6866
    71
    // First initialize the controller
jorgen@6866
    72
    SDLTest_AssertCheck( (SDL_WasInit(joy_and_controller) & joy_and_controller) == 0, "SDL_WasInit() before init should be false for joystick & controller" );
jorgen@6866
    73
    SDLTest_AssertCheck( SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == 0, "SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)" );
jorgen@6866
    74
jorgen@6866
    75
    // Then make sure this implicitly initialized the joystick subsystem
jorgen@6869
    76
    initialized_system = SDL_WasInit(joy_and_controller);
jorgen@6866
    77
    SDLTest_AssertCheck( (initialized_system & joy_and_controller) == joy_and_controller, "SDL_WasInit() should be true for joystick & controller (%x)", initialized_system );
jorgen@6866
    78
jorgen@6866
    79
    // Then quit the controller, and make sure that imlicity also quits the
jorgen@6866
    80
    // joystick subsystem
jorgen@6866
    81
    SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
jorgen@6866
    82
    initialized_system = SDL_WasInit(joy_and_controller);
jorgen@6866
    83
    SDLTest_AssertCheck( (initialized_system & joy_and_controller) == 0, "SDL_WasInit() should be false for joystick & controller (%x)", initialized_system );
aschiffler@6872
    84
aschiffler@6872
    85
	return TEST_COMPLETED;
jorgen@6866
    86
}
jorgen@6866
    87
jorgen@6866
    88
static int main_testImpliedJoystickQuit (void *arg)
jorgen@6866
    89
{
jorgen@6869
    90
    int initialized_system;
jorgen@6869
    91
jorgen@6866
    92
    // First initialize the controller and the joystick (explicitly)
jorgen@6866
    93
    SDLTest_AssertCheck( (SDL_WasInit(joy_and_controller) & joy_and_controller) == 0, "SDL_WasInit() before init should be false for joystick & controller" );
jorgen@6866
    94
    SDLTest_AssertCheck( SDL_InitSubSystem(SDL_INIT_JOYSTICK) == 0, "SDL_InitSubSystem(SDL_INIT_JOYSTICK)" );
jorgen@6866
    95
    SDLTest_AssertCheck( SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == 0, "SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)" );
jorgen@6866
    96
jorgen@6866
    97
    // Then make sure they're both initialized properly
jorgen@6869
    98
    initialized_system = SDL_WasInit(joy_and_controller);
jorgen@6866
    99
    SDLTest_AssertCheck( (initialized_system & joy_and_controller) == joy_and_controller, "SDL_WasInit() should be true for joystick & controller (%x)", initialized_system );
jorgen@6866
   100
jorgen@6866
   101
    // Then quit the controller, and make sure that it does NOT quit the
jorgen@6866
   102
    // explicitly initialized joystick subsystem.
jorgen@6866
   103
    SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
jorgen@6866
   104
    initialized_system = SDL_WasInit(joy_and_controller);
jorgen@6866
   105
    SDLTest_AssertCheck( (initialized_system & joy_and_controller) == SDL_INIT_JOYSTICK, "SDL_WasInit() should be false for joystick & controller (%x)", initialized_system );
jorgen@6866
   106
jorgen@6866
   107
    SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
aschiffler@6872
   108
aschiffler@6872
   109
	return TEST_COMPLETED;
jorgen@6866
   110
}
jorgen@6866
   111
jorgen@6866
   112
static const SDLTest_TestCaseReference mainTest1 =
jorgen@6866
   113
		{ (SDLTest_TestCaseFp)main_testInitQuit, "main_testInitQuit", "Tests SDL_Init/Quit", TEST_ENABLED};
jorgen@6866
   114
jorgen@6866
   115
static const SDLTest_TestCaseReference mainTest2 =
jorgen@6866
   116
		{ (SDLTest_TestCaseFp)main_testInitQuitSubSystem, "main_testInitQuitSubSystem", "Tests SDL_InitSubSystem/QuitSubSystem", TEST_ENABLED};
jorgen@6866
   117
jorgen@6866
   118
static const SDLTest_TestCaseReference mainTest3 =
jorgen@6866
   119
		{ (SDLTest_TestCaseFp)main_testImpliedJoystickInit, "main_testImpliedJoystickInit", "Tests that init for gamecontroller properly implies joystick", TEST_ENABLED};
jorgen@6866
   120
jorgen@6866
   121
static const SDLTest_TestCaseReference mainTest4 =
jorgen@6866
   122
		{ (SDLTest_TestCaseFp)main_testImpliedJoystickQuit, "main_testImpliedJoystickQuit", "Tests that quit for gamecontroller doesn't quit joystick if you inited it explicitly", TEST_ENABLED};
jorgen@6866
   123
jorgen@6866
   124
/* Sequence of Platform test cases */
jorgen@6866
   125
static const SDLTest_TestCaseReference *mainTests[] =  {
jorgen@6866
   126
	&mainTest1,
jorgen@6866
   127
	&mainTest2,
jorgen@6866
   128
	&mainTest3,
jorgen@6866
   129
	&mainTest4,
jorgen@6866
   130
	NULL
jorgen@6866
   131
};
jorgen@6866
   132
jorgen@6866
   133
/* Platform test suite (global) */
jorgen@6866
   134
SDLTest_TestSuiteReference mainTestSuite = {
jorgen@6866
   135
	"Main",
jorgen@6866
   136
	NULL,
jorgen@6866
   137
	mainTests,
jorgen@6866
   138
	NULL
jorgen@6866
   139
};
jorgen@6866
   140
jorgen@6866
   141
/* vi: set ts=4 sw=4 expandtab: */