test/testautomation_main.c
author Andreas Schiffler <aschiffler@ferzkopp.net>
Sat, 18 May 2013 09:35:09 -0700
changeset 7189 414be1d64060
parent 7144 c700de9c8ed4
child 7191 75360622e65f
permissions -rw-r--r--
Update test harness to handle test return codes; fix comment format in harness; update Main test suite to handle globally disabled features
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
/*!
aschiffler@7189
    14
 * \brief Tests SDL_Init() and SDL_Quit() of Joystick and Haptic subsystems
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
 */
aschiffler@7189
    19
static int main_testInitQuitJoystickHaptic (void *arg)
jorgen@6866
    20
{
aschiffler@7189
    21
#if defined SDL_JOYSTICK_DISABLED || defined SDL_HAPTIC_DISABLED
aschiffler@7189
    22
    return TEST_SKIPPED;
aschiffler@7189
    23
#else
jorgen@6869
    24
    int enabled_subsystems;
jorgen@6866
    25
    int initialized_subsystems = SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC;
jorgen@6866
    26
jorgen@6866
    27
    SDLTest_AssertCheck( SDL_Init(initialized_subsystems) == 0, "SDL_Init multiple systems." );
jorgen@6866
    28
jorgen@6869
    29
    enabled_subsystems = SDL_WasInit(initialized_subsystems);
jorgen@6866
    30
    SDLTest_AssertCheck( enabled_subsystems == initialized_subsystems, "SDL_WasInit(SDL_INIT_EVERYTHING) contains all systems (%i)", enabled_subsystems );
jorgen@6866
    31
jorgen@6866
    32
    SDL_Quit();
jorgen@6866
    33
jorgen@6866
    34
    enabled_subsystems = SDL_WasInit(initialized_subsystems);
jorgen@6866
    35
    SDLTest_AssertCheck( enabled_subsystems == 0, "SDL_Quit should shut down everything (%i)", enabled_subsystems );
jorgen@6866
    36
jorgen@6866
    37
    return TEST_COMPLETED;
aschiffler@7189
    38
#endif
jorgen@6866
    39
}
jorgen@6866
    40
jorgen@6866
    41
/*!
jorgen@6866
    42
 * \brief Tests SDL_InitSubSystem() and SDL_QuitSubSystem()
jorgen@6866
    43
 * \sa
jorgen@6866
    44
 * http://wiki.libsdl.org/moin.cgi/SDL_Init
jorgen@6866
    45
 * http://wiki.libsdl.org/moin.cgi/SDL_Quit
jorgen@6866
    46
 */
jorgen@6866
    47
static int main_testInitQuitSubSystem (void *arg)
jorgen@6866
    48
{
aschiffler@7189
    49
#if defined SDL_JOYSTICK_DISABLED || defined SDL_HAPTIC_DISABLED || defined SDL_GAMECONTROLLER_DISABLED
aschiffler@7189
    50
    return TEST_SKIPPED;
aschiffler@7189
    51
#else
jorgen@6866
    52
    int i;
jorgen@6866
    53
    int subsystems[] = { SDL_INIT_JOYSTICK, SDL_INIT_HAPTIC, SDL_INIT_GAMECONTROLLER };
jorgen@6866
    54
jorgen@6866
    55
    for (i = 0; i < SDL_arraysize(subsystems); ++i) {
jorgen@6869
    56
        int initialized_system;
jorgen@6866
    57
        int subsystem = subsystems[i];
jorgen@6866
    58
jorgen@6866
    59
        SDLTest_AssertCheck( (SDL_WasInit(subsystem) & subsystem) == 0, "SDL_WasInit(%x) before init should be false", subsystem );
jorgen@6866
    60
        SDLTest_AssertCheck( SDL_InitSubSystem(subsystem) == 0, "SDL_InitSubSystem(%x)", subsystem );
jorgen@6866
    61
jorgen@6869
    62
        initialized_system = SDL_WasInit(subsystem);
jorgen@6866
    63
        SDLTest_AssertCheck( (initialized_system & subsystem) != 0, "SDL_WasInit(%x) should be true (%x)", subsystem, initialized_system );
jorgen@6866
    64
jorgen@6866
    65
        SDL_QuitSubSystem(subsystem);
jorgen@6866
    66
jorgen@6866
    67
        SDLTest_AssertCheck( (SDL_WasInit(subsystem) & subsystem) == 0, "SDL_WasInit(%x) after shutdown should be false", subsystem );
jorgen@6866
    68
    }
jorgen@6866
    69
jorgen@6866
    70
    return TEST_COMPLETED;
aschiffler@7189
    71
#endif
jorgen@6866
    72
}
jorgen@6866
    73
jorgen@6866
    74
const int joy_and_controller = SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER;
jorgen@6866
    75
static int main_testImpliedJoystickInit (void *arg)
jorgen@6866
    76
{
aschiffler@7189
    77
#if defined SDL_JOYSTICK_DISABLED || defined SDL_GAMECONTROLLER_DISABLED
aschiffler@7189
    78
    return TEST_SKIPPED;
aschiffler@7189
    79
#else
jorgen@6869
    80
    int initialized_system;
jorgen@6869
    81
jorgen@6866
    82
    // First initialize the controller
jorgen@6866
    83
    SDLTest_AssertCheck( (SDL_WasInit(joy_and_controller) & joy_and_controller) == 0, "SDL_WasInit() before init should be false for joystick & controller" );
jorgen@6866
    84
    SDLTest_AssertCheck( SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == 0, "SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)" );
jorgen@6866
    85
jorgen@6866
    86
    // Then make sure this implicitly initialized the joystick subsystem
jorgen@6869
    87
    initialized_system = SDL_WasInit(joy_and_controller);
jorgen@6866
    88
    SDLTest_AssertCheck( (initialized_system & joy_and_controller) == joy_and_controller, "SDL_WasInit() should be true for joystick & controller (%x)", initialized_system );
jorgen@6866
    89
philipp@7144
    90
    // Then quit the controller, and make sure that implicitly also quits the
jorgen@6866
    91
    // joystick subsystem
jorgen@6866
    92
    SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
jorgen@6866
    93
    initialized_system = SDL_WasInit(joy_and_controller);
jorgen@6866
    94
    SDLTest_AssertCheck( (initialized_system & joy_and_controller) == 0, "SDL_WasInit() should be false for joystick & controller (%x)", initialized_system );
aschiffler@6872
    95
aschiffler@7189
    96
    return TEST_COMPLETED;
aschiffler@7189
    97
#endif
jorgen@6866
    98
}
jorgen@6866
    99
jorgen@6866
   100
static int main_testImpliedJoystickQuit (void *arg)
jorgen@6866
   101
{
aschiffler@7189
   102
#if defined SDL_JOYSTICK_DISABLED || defined SDL_GAMECONTROLLER_DISABLED
aschiffler@7189
   103
    return TEST_SKIPPED;
aschiffler@7189
   104
#else
jorgen@6869
   105
    int initialized_system;
jorgen@6869
   106
jorgen@6866
   107
    // First initialize the controller and the joystick (explicitly)
jorgen@6866
   108
    SDLTest_AssertCheck( (SDL_WasInit(joy_and_controller) & joy_and_controller) == 0, "SDL_WasInit() before init should be false for joystick & controller" );
jorgen@6866
   109
    SDLTest_AssertCheck( SDL_InitSubSystem(SDL_INIT_JOYSTICK) == 0, "SDL_InitSubSystem(SDL_INIT_JOYSTICK)" );
jorgen@6866
   110
    SDLTest_AssertCheck( SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == 0, "SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)" );
jorgen@6866
   111
jorgen@6866
   112
    // Then make sure they're both initialized properly
jorgen@6869
   113
    initialized_system = SDL_WasInit(joy_and_controller);
jorgen@6866
   114
    SDLTest_AssertCheck( (initialized_system & joy_and_controller) == joy_and_controller, "SDL_WasInit() should be true for joystick & controller (%x)", initialized_system );
jorgen@6866
   115
jorgen@6866
   116
    // Then quit the controller, and make sure that it does NOT quit the
jorgen@6866
   117
    // explicitly initialized joystick subsystem.
jorgen@6866
   118
    SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
jorgen@6866
   119
    initialized_system = SDL_WasInit(joy_and_controller);
jorgen@6866
   120
    SDLTest_AssertCheck( (initialized_system & joy_and_controller) == SDL_INIT_JOYSTICK, "SDL_WasInit() should be false for joystick & controller (%x)", initialized_system );
jorgen@6866
   121
jorgen@6866
   122
    SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
aschiffler@6872
   123
aschiffler@7189
   124
    return TEST_COMPLETED;
aschiffler@7189
   125
#endif
jorgen@6866
   126
}
jorgen@6866
   127
jorgen@6866
   128
static const SDLTest_TestCaseReference mainTest1 =
aschiffler@7189
   129
		{ (SDLTest_TestCaseFp)main_testInitQuitJoystickHaptic, "main_testInitQuitJoystickHaptic", "Tests SDL_Init/Quit of Joystick and Haptic subsystem", TEST_ENABLED};
jorgen@6866
   130
jorgen@6866
   131
static const SDLTest_TestCaseReference mainTest2 =
jorgen@6866
   132
		{ (SDLTest_TestCaseFp)main_testInitQuitSubSystem, "main_testInitQuitSubSystem", "Tests SDL_InitSubSystem/QuitSubSystem", TEST_ENABLED};
jorgen@6866
   133
jorgen@6866
   134
static const SDLTest_TestCaseReference mainTest3 =
jorgen@6866
   135
		{ (SDLTest_TestCaseFp)main_testImpliedJoystickInit, "main_testImpliedJoystickInit", "Tests that init for gamecontroller properly implies joystick", TEST_ENABLED};
jorgen@6866
   136
jorgen@6866
   137
static const SDLTest_TestCaseReference mainTest4 =
jorgen@6866
   138
		{ (SDLTest_TestCaseFp)main_testImpliedJoystickQuit, "main_testImpliedJoystickQuit", "Tests that quit for gamecontroller doesn't quit joystick if you inited it explicitly", TEST_ENABLED};
jorgen@6866
   139
jorgen@6866
   140
/* Sequence of Platform test cases */
jorgen@6866
   141
static const SDLTest_TestCaseReference *mainTests[] =  {
jorgen@6866
   142
	&mainTest1,
jorgen@6866
   143
	&mainTest2,
jorgen@6866
   144
	&mainTest3,
jorgen@6866
   145
	&mainTest4,
jorgen@6866
   146
	NULL
jorgen@6866
   147
};
jorgen@6866
   148
jorgen@6866
   149
/* Platform test suite (global) */
jorgen@6866
   150
SDLTest_TestSuiteReference mainTestSuite = {
jorgen@6866
   151
	"Main",
jorgen@6866
   152
	NULL,
jorgen@6866
   153
	mainTests,
jorgen@6866
   154
	NULL
jorgen@6866
   155
};
jorgen@6866
   156
jorgen@6866
   157
/* vi: set ts=4 sw=4 expandtab: */