test/testpower.c
changeset 3170 b7a48f533966
child 3186 51750b7a966f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/testpower.c	Sun Jun 07 06:06:35 2009 +0000
     1.3 @@ -0,0 +1,65 @@
     1.4 +/* Simple test of power subsystem. */
     1.5 +
     1.6 +#include <stdio.h>
     1.7 +#include "SDL.h"
     1.8 +
     1.9 +static void report_power(void)
    1.10 +{
    1.11 +    int seconds, percent;
    1.12 +    const SDL_PowerState state = SDL_GetPowerInfo(&seconds, &percent);
    1.13 +    char *statestr = NULL;
    1.14 +
    1.15 +    printf("SDL-reported power info...\n");
    1.16 +    switch(state)
    1.17 +    {
    1.18 +        case SDL_POWERSTATE_UNKNOWN:
    1.19 +            statestr = "Unknown";
    1.20 +            break;
    1.21 +        case SDL_POWERSTATE_ON_BATTERY:
    1.22 +            statestr = "On battery";
    1.23 +            break;
    1.24 +        case SDL_POWERSTATE_NO_BATTERY:
    1.25 +            statestr = "No battery";
    1.26 +            break;
    1.27 +        case SDL_POWERSTATE_CHARGING:
    1.28 +            statestr = "Charging";
    1.29 +            break;
    1.30 +        case SDL_POWERSTATE_CHARGED:
    1.31 +            statestr = "Charged";
    1.32 +            break;
    1.33 +        default:
    1.34 +            statestr = "!!API ERROR!!";
    1.35 +            break;
    1.36 +    }
    1.37 +
    1.38 +    printf("State: %s\n", statestr);
    1.39 +
    1.40 +    if (percent == -1) {
    1.41 +        printf("Percent left: unknown\n");
    1.42 +    } else {
    1.43 +        printf("Percent left: %d%%\n", percent);
    1.44 +    }
    1.45 +
    1.46 +    if (seconds == -1) {
    1.47 +        printf("Time left: unknown\n");
    1.48 +    } else {
    1.49 +        printf("Time left: %d minutes, %d seconds\n", (int) (seconds / 60), (int) (seconds % 60));
    1.50 +    }
    1.51 +}
    1.52 +
    1.53 +
    1.54 +int main(int argc, char *argv[])
    1.55 +{
    1.56 +    if (SDL_Init(SDL_INIT_VIDEO) == -1) {
    1.57 +        fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError());
    1.58 +        return 1;
    1.59 +    }
    1.60 +
    1.61 +    report_power();
    1.62 +
    1.63 +    SDL_Quit();
    1.64 +    return 0;
    1.65 +}
    1.66 +
    1.67 +/* end of testpower.c ... */
    1.68 +