test/testpower.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 25 Apr 2013 00:26:17 -0700
changeset 7110 2a98852fd58d
parent 5535 96594ac5fd1a
child 7307 5d6b7b9432d3
permissions -rw-r--r--
Fixed bug 1582 - Allow disabling SDL_VIDEO_DRIVER_WINDOWS

Marcus von Appen

Trying to build SDL 2.x (HG) on Win32 platforms with either VS.NET or MinGW requires one to have the video subsystem and SDL_VIDEO_DRIVER_WINDOWS flag enabled due to the helper window creation routines.

The attached patch changes the helper window creation behaviour, so that one can build SDL2 without the video subsystem or Windows video drivers on Win32 platforms.
slouken@5535
     1
/*
slouken@5535
     2
  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
slouken@5535
     3
slouken@5535
     4
  This software is provided 'as-is', without any express or implied
slouken@5535
     5
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     6
  arising from the use of this software.
slouken@5535
     7
slouken@5535
     8
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
     9
  including commercial applications, and to alter it and redistribute it
slouken@5535
    10
  freely.
slouken@5535
    11
*/
icculus@3170
    12
/* Simple test of power subsystem. */
icculus@3170
    13
icculus@3170
    14
#include <stdio.h>
icculus@3170
    15
#include "SDL.h"
icculus@3170
    16
slouken@3186
    17
static void
slouken@3186
    18
report_power(void)
icculus@3170
    19
{
icculus@3170
    20
    int seconds, percent;
icculus@3170
    21
    const SDL_PowerState state = SDL_GetPowerInfo(&seconds, &percent);
icculus@3170
    22
    char *statestr = NULL;
icculus@3170
    23
icculus@3170
    24
    printf("SDL-reported power info...\n");
slouken@3186
    25
    switch (state) {
slouken@3186
    26
    case SDL_POWERSTATE_UNKNOWN:
slouken@3186
    27
        statestr = "Unknown";
slouken@3186
    28
        break;
slouken@3186
    29
    case SDL_POWERSTATE_ON_BATTERY:
slouken@3186
    30
        statestr = "On battery";
slouken@3186
    31
        break;
slouken@3186
    32
    case SDL_POWERSTATE_NO_BATTERY:
slouken@3186
    33
        statestr = "No battery";
slouken@3186
    34
        break;
slouken@3186
    35
    case SDL_POWERSTATE_CHARGING:
slouken@3186
    36
        statestr = "Charging";
slouken@3186
    37
        break;
slouken@3186
    38
    case SDL_POWERSTATE_CHARGED:
slouken@3186
    39
        statestr = "Charged";
slouken@3186
    40
        break;
slouken@3186
    41
    default:
slouken@3186
    42
        statestr = "!!API ERROR!!";
slouken@3186
    43
        break;
icculus@3170
    44
    }
icculus@3170
    45
icculus@3170
    46
    printf("State: %s\n", statestr);
icculus@3170
    47
icculus@3170
    48
    if (percent == -1) {
icculus@3170
    49
        printf("Percent left: unknown\n");
icculus@3170
    50
    } else {
icculus@3170
    51
        printf("Percent left: %d%%\n", percent);
icculus@3170
    52
    }
icculus@3170
    53
icculus@3170
    54
    if (seconds == -1) {
icculus@3170
    55
        printf("Time left: unknown\n");
icculus@3170
    56
    } else {
slouken@3186
    57
        printf("Time left: %d minutes, %d seconds\n", (int) (seconds / 60),
slouken@3186
    58
               (int) (seconds % 60));
icculus@3170
    59
    }
icculus@3170
    60
}
icculus@3170
    61
icculus@3170
    62
slouken@3186
    63
int
slouken@3186
    64
main(int argc, char *argv[])
icculus@3170
    65
{
icculus@3170
    66
    if (SDL_Init(SDL_INIT_VIDEO) == -1) {
icculus@3170
    67
        fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError());
icculus@3170
    68
        return 1;
icculus@3170
    69
    }
icculus@3170
    70
icculus@3170
    71
    report_power();
icculus@3170
    72
icculus@3170
    73
    SDL_Quit();
icculus@3170
    74
    return 0;
icculus@3170
    75
}
icculus@3170
    76
icculus@3170
    77
/* end of testpower.c ... */