visualtest/unittest/testquit.c
author Ryan C. Gordon <icculus@icculus.org>
Sun, 10 Nov 2013 00:32:23 -0500
changeset 7924 fcb86d323770
child 9619 b94b6d0bff0f
permissions -rwxr-xr-x
Added Apoorv Upreti's GSoC2013 work: visual test suite.

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