test/testpower.c
author David Ludwig <dludwig@pobox.com>
Tue, 12 Feb 2013 12:57:06 -0500
changeset 8424 3cf9501008f1
parent 5535 96594ac5fd1a
child 7307 5d6b7b9432d3
permissions -rw-r--r--
WinRT: fixed bug: SDL_CreateWindow wouldn't work after an initial window was created + destroyed
     1 /*
     2   Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
     3 
     4   This software is provided 'as-is', without any express or implied
     5   warranty.  In no event will the authors be held liable for any damages
     6   arising from the use of this software.
     7 
     8   Permission is granted to anyone to use this software for any purpose,
     9   including commercial applications, and to alter it and redistribute it
    10   freely.
    11 */
    12 /* Simple test of power subsystem. */
    13 
    14 #include <stdio.h>
    15 #include "SDL.h"
    16 
    17 static void
    18 report_power(void)
    19 {
    20     int seconds, percent;
    21     const SDL_PowerState state = SDL_GetPowerInfo(&seconds, &percent);
    22     char *statestr = NULL;
    23 
    24     printf("SDL-reported power info...\n");
    25     switch (state) {
    26     case SDL_POWERSTATE_UNKNOWN:
    27         statestr = "Unknown";
    28         break;
    29     case SDL_POWERSTATE_ON_BATTERY:
    30         statestr = "On battery";
    31         break;
    32     case SDL_POWERSTATE_NO_BATTERY:
    33         statestr = "No battery";
    34         break;
    35     case SDL_POWERSTATE_CHARGING:
    36         statestr = "Charging";
    37         break;
    38     case SDL_POWERSTATE_CHARGED:
    39         statestr = "Charged";
    40         break;
    41     default:
    42         statestr = "!!API ERROR!!";
    43         break;
    44     }
    45 
    46     printf("State: %s\n", statestr);
    47 
    48     if (percent == -1) {
    49         printf("Percent left: unknown\n");
    50     } else {
    51         printf("Percent left: %d%%\n", percent);
    52     }
    53 
    54     if (seconds == -1) {
    55         printf("Time left: unknown\n");
    56     } else {
    57         printf("Time left: %d minutes, %d seconds\n", (int) (seconds / 60),
    58                (int) (seconds % 60));
    59     }
    60 }
    61 
    62 
    63 int
    64 main(int argc, char *argv[])
    65 {
    66     if (SDL_Init(SDL_INIT_VIDEO) == -1) {
    67         fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError());
    68         return 1;
    69     }
    70 
    71     report_power();
    72 
    73     SDL_Quit();
    74     return 0;
    75 }
    76 
    77 /* end of testpower.c ... */