test/testpower.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 19 Jan 2011 22:20:44 -0800
changeset 5046 4cb778067834
parent 3186 51750b7a966f
child 5535 96594ac5fd1a
permissions -rw-r--r--
Clearing the API changes for the 1.3.0 release
icculus@3170
     1
/* Simple test of power subsystem. */
icculus@3170
     2
icculus@3170
     3
#include <stdio.h>
icculus@3170
     4
#include "SDL.h"
icculus@3170
     5
slouken@3186
     6
static void
slouken@3186
     7
report_power(void)
icculus@3170
     8
{
icculus@3170
     9
    int seconds, percent;
icculus@3170
    10
    const SDL_PowerState state = SDL_GetPowerInfo(&seconds, &percent);
icculus@3170
    11
    char *statestr = NULL;
icculus@3170
    12
icculus@3170
    13
    printf("SDL-reported power info...\n");
slouken@3186
    14
    switch (state) {
slouken@3186
    15
    case SDL_POWERSTATE_UNKNOWN:
slouken@3186
    16
        statestr = "Unknown";
slouken@3186
    17
        break;
slouken@3186
    18
    case SDL_POWERSTATE_ON_BATTERY:
slouken@3186
    19
        statestr = "On battery";
slouken@3186
    20
        break;
slouken@3186
    21
    case SDL_POWERSTATE_NO_BATTERY:
slouken@3186
    22
        statestr = "No battery";
slouken@3186
    23
        break;
slouken@3186
    24
    case SDL_POWERSTATE_CHARGING:
slouken@3186
    25
        statestr = "Charging";
slouken@3186
    26
        break;
slouken@3186
    27
    case SDL_POWERSTATE_CHARGED:
slouken@3186
    28
        statestr = "Charged";
slouken@3186
    29
        break;
slouken@3186
    30
    default:
slouken@3186
    31
        statestr = "!!API ERROR!!";
slouken@3186
    32
        break;
icculus@3170
    33
    }
icculus@3170
    34
icculus@3170
    35
    printf("State: %s\n", statestr);
icculus@3170
    36
icculus@3170
    37
    if (percent == -1) {
icculus@3170
    38
        printf("Percent left: unknown\n");
icculus@3170
    39
    } else {
icculus@3170
    40
        printf("Percent left: %d%%\n", percent);
icculus@3170
    41
    }
icculus@3170
    42
icculus@3170
    43
    if (seconds == -1) {
icculus@3170
    44
        printf("Time left: unknown\n");
icculus@3170
    45
    } else {
slouken@3186
    46
        printf("Time left: %d minutes, %d seconds\n", (int) (seconds / 60),
slouken@3186
    47
               (int) (seconds % 60));
icculus@3170
    48
    }
icculus@3170
    49
}
icculus@3170
    50
icculus@3170
    51
slouken@3186
    52
int
slouken@3186
    53
main(int argc, char *argv[])
icculus@3170
    54
{
icculus@3170
    55
    if (SDL_Init(SDL_INIT_VIDEO) == -1) {
icculus@3170
    56
        fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError());
icculus@3170
    57
        return 1;
icculus@3170
    58
    }
icculus@3170
    59
icculus@3170
    60
    report_power();
icculus@3170
    61
icculus@3170
    62
    SDL_Quit();
icculus@3170
    63
    return 0;
icculus@3170
    64
}
icculus@3170
    65
icculus@3170
    66
/* end of testpower.c ... */