🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
2.4 KiB

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