sdl

FORK: Simple Directmedia Layer
git clone https://git.neptards.moe/neptards/sdl.git
Log | Files | Refs

testquit.c (2433B)


      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             static const char *options = { "[--exit-code N]", "[--crash]", "[--hang]", NULL };
     68             SDLTest_CommonLogUsage(state, argv[0], options);
     69             SDLTest_CommonQuit(state);
     70             return 1;
     71         }
     72         i += consumed;
     73     }
     74 
     75     if(!SDLTest_CommonInit(state))
     76     {
     77         SDLTest_CommonQuit(state);
     78         return 1;
     79     }
     80 
     81     /* infinite loop to hang the process */
     82     while(hang)
     83         SDL_Delay(10);
     84 
     85     /* dereference NULL pointer to crash process */
     86     if(crash)
     87     {
     88         int* p = NULL;
     89         *p = 5;
     90     }
     91 
     92     /* event loop */
     93     done = 0;
     94     while(!done)
     95     {
     96         while(SDL_PollEvent(&event))
     97             SDLTest_CommonEvent(state, &event, &done);
     98         SDL_Delay(10);
     99     }
    100 
    101     return exit_code;
    102 }