visualtest/unittest/testquit.c
author Ozkan Sezer <sezeroz@gmail.com>
Tue, 12 Jun 2018 14:00:15 +0300
changeset 12016 f3d8b8456e7b
parent 9619 b94b6d0bff0f
child 12758 3c6a6dad3487
permissions -rw-r--r--
ran 'chmod -x' on many files
icculus@7924
     1
/*
icculus@7924
     2
  Copyright (C) 2013 Apoorv Upreti <apoorvupreti@gmail.com>
icculus@7924
     3
icculus@7924
     4
  This software is provided 'as-is', without any express or implied
icculus@7924
     5
  warranty.  In no event will the authors be held liable for any damages
icculus@7924
     6
  arising from the use of this software.
icculus@7924
     7
icculus@7924
     8
  Permission is granted to anyone to use this software for any purpose,
icculus@7924
     9
  including commercial applications, and to alter it and redistribute it
icculus@7924
    10
  freely.
icculus@7924
    11
*/
icculus@7924
    12
/* Quits, hangs or crashes based on the command line options passed. */
icculus@7924
    13
icculus@7924
    14
#include <SDL.h>
icculus@7924
    15
#include <SDL_test.h>
icculus@7924
    16
icculus@7924
    17
static SDLTest_CommonState *state;
icculus@7924
    18
static int exit_code;
icculus@7924
    19
static SDL_bool hang;
icculus@7924
    20
static SDL_bool crash;
icculus@7924
    21
icculus@7924
    22
int
icculus@7924
    23
main(int argc, char** argv)
icculus@7924
    24
{
icculus@7924
    25
    int i, done;
icculus@7924
    26
    SDL_Event event;
icculus@7924
    27
icculus@7924
    28
    state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
icculus@7924
    29
    if(!state)
icculus@7924
    30
        return 1;
icculus@7924
    31
icculus@7924
    32
    state->window_flags |= SDL_WINDOW_RESIZABLE;
icculus@7924
    33
    
icculus@7924
    34
    exit_code = 0;
icculus@7924
    35
    hang = SDL_FALSE;
icculus@7924
    36
    crash = SDL_FALSE;
icculus@7924
    37
icculus@7924
    38
    for(i = 1; i < argc; )
icculus@7924
    39
    {
icculus@7924
    40
        int consumed;
icculus@7924
    41
        consumed = SDLTest_CommonArg(state, i);
icculus@7924
    42
        if(consumed == 0)
icculus@7924
    43
        {
icculus@7924
    44
            consumed = -1;
icculus@7924
    45
            if(SDL_strcasecmp(argv[i], "--exit-code") == 0)
icculus@7924
    46
            {
icculus@7924
    47
                if(argv[i + 1])
icculus@7924
    48
                {
icculus@7924
    49
                    exit_code = SDL_atoi(argv[i + 1]);
icculus@7924
    50
                    consumed = 2;
icculus@7924
    51
                }
icculus@7924
    52
            }
icculus@7924
    53
            else if(SDL_strcasecmp(argv[i], "--hang") == 0)
icculus@7924
    54
            {
icculus@7924
    55
                hang = SDL_TRUE;
icculus@7924
    56
                consumed = 1;
icculus@7924
    57
            }
icculus@7924
    58
            else if(SDL_strcasecmp(argv[i], "--crash") == 0)
icculus@7924
    59
            {
icculus@7924
    60
                crash = SDL_TRUE;
icculus@7924
    61
                consumed = 1;
icculus@7924
    62
            }
icculus@7924
    63
        }
icculus@7924
    64
icculus@7924
    65
        if(consumed < 0)
icculus@7924
    66
        {
icculus@7924
    67
            SDLTest_Log("Usage: %s %s [--exit-code N] [--crash] [--hang]", argv[0], SDLTest_CommonUsage(state));
icculus@7924
    68
            SDLTest_CommonQuit(state);
icculus@7924
    69
            return 1;
icculus@7924
    70
        }
icculus@7924
    71
        i += consumed;
icculus@7924
    72
    }
icculus@7924
    73
icculus@7924
    74
    if(!SDLTest_CommonInit(state))
icculus@7924
    75
    {
icculus@7924
    76
        SDLTest_CommonQuit(state);
icculus@7924
    77
        return 1;
icculus@7924
    78
    }
icculus@7924
    79
icculus@7924
    80
    /* infinite loop to hang the process */
icculus@7924
    81
    while(hang)
icculus@7924
    82
        SDL_Delay(10);
icculus@7924
    83
icculus@7924
    84
    /* dereference NULL pointer to crash process */
icculus@7924
    85
    if(crash)
icculus@7924
    86
    {
icculus@7924
    87
        int* p = NULL;
icculus@7924
    88
        *p = 5;
icculus@7924
    89
    }
icculus@7924
    90
icculus@7924
    91
    /* event loop */
icculus@7924
    92
    done = 0;
icculus@7924
    93
    while(!done)
icculus@7924
    94
    {
icculus@7924
    95
        while(SDL_PollEvent(&event))
icculus@7924
    96
            SDLTest_CommonEvent(state, &event, &done);
icculus@7924
    97
        SDL_Delay(10);
icculus@7924
    98
    }
icculus@7924
    99
icculus@7924
   100
    return exit_code;
slouken@9619
   101
}