visualtest/unittest/testquit.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 29 May 2020 21:26:32 -0700
changeset 13884 ba1ed72249c0
parent 12758 3c6a6dad3487
permissions -rw-r--r--
Fixed bug 5113 - SDL_UpdateWindowSurfaceRects BitBlt the entire surface on Win32

Ryan C. Gordon

As discussed here:
https://discourse.libsdl.org/t/question-about-implementation-of-sdl-updatewindowsurfacerects/27561

"As you can see this function [WIN_UpdateWindowFramebuffer, in src/video/windows/SDL_windowsframebuffer.c] calls BitBlt on entire screen, even though it accepts the rects. Rects variable is not even used in this function at all. Now my question is why is that the case?"
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@12758
    67
            static const char *options = { "[--exit-code N]", "[--crash]", "[--hang]", NULL };
icculus@12758
    68
            SDLTest_CommonLogUsage(state, argv[0], options);
icculus@7924
    69
            SDLTest_CommonQuit(state);
icculus@7924
    70
            return 1;
icculus@7924
    71
        }
icculus@7924
    72
        i += consumed;
icculus@7924
    73
    }
icculus@7924
    74
icculus@7924
    75
    if(!SDLTest_CommonInit(state))
icculus@7924
    76
    {
icculus@7924
    77
        SDLTest_CommonQuit(state);
icculus@7924
    78
        return 1;
icculus@7924
    79
    }
icculus@7924
    80
icculus@7924
    81
    /* infinite loop to hang the process */
icculus@7924
    82
    while(hang)
icculus@7924
    83
        SDL_Delay(10);
icculus@7924
    84
icculus@7924
    85
    /* dereference NULL pointer to crash process */
icculus@7924
    86
    if(crash)
icculus@7924
    87
    {
icculus@7924
    88
        int* p = NULL;
icculus@7924
    89
        *p = 5;
icculus@7924
    90
    }
icculus@7924
    91
icculus@7924
    92
    /* event loop */
icculus@7924
    93
    done = 0;
icculus@7924
    94
    while(!done)
icculus@7924
    95
    {
icculus@7924
    96
        while(SDL_PollEvent(&event))
icculus@7924
    97
            SDLTest_CommonEvent(state, &event, &done);
icculus@7924
    98
        SDL_Delay(10);
icculus@7924
    99
    }
icculus@7924
   100
icculus@7924
   101
    return exit_code;
slouken@9619
   102
}