test/testpower.c
author Bob Pendleton <bob@pendleton.com>
Wed, 23 Sep 2009 02:52:11 +0000
changeset 3299 975fd903466b
parent 3186 51750b7a966f
child 5535 96594ac5fd1a
permissions -rw-r--r--
int testmmousetable.c the arguments to main() are not compatible with what is required in SDL_main.h
Cleaned up testatomic.c to use the same syntax as every other test program.
     1 /* Simple test of power subsystem. */
     2 
     3 #include <stdio.h>
     4 #include "SDL.h"
     5 
     6 static void
     7 report_power(void)
     8 {
     9     int seconds, percent;
    10     const SDL_PowerState state = SDL_GetPowerInfo(&seconds, &percent);
    11     char *statestr = NULL;
    12 
    13     printf("SDL-reported power info...\n");
    14     switch (state) {
    15     case SDL_POWERSTATE_UNKNOWN:
    16         statestr = "Unknown";
    17         break;
    18     case SDL_POWERSTATE_ON_BATTERY:
    19         statestr = "On battery";
    20         break;
    21     case SDL_POWERSTATE_NO_BATTERY:
    22         statestr = "No battery";
    23         break;
    24     case SDL_POWERSTATE_CHARGING:
    25         statestr = "Charging";
    26         break;
    27     case SDL_POWERSTATE_CHARGED:
    28         statestr = "Charged";
    29         break;
    30     default:
    31         statestr = "!!API ERROR!!";
    32         break;
    33     }
    34 
    35     printf("State: %s\n", statestr);
    36 
    37     if (percent == -1) {
    38         printf("Percent left: unknown\n");
    39     } else {
    40         printf("Percent left: %d%%\n", percent);
    41     }
    42 
    43     if (seconds == -1) {
    44         printf("Time left: unknown\n");
    45     } else {
    46         printf("Time left: %d minutes, %d seconds\n", (int) (seconds / 60),
    47                (int) (seconds % 60));
    48     }
    49 }
    50 
    51 
    52 int
    53 main(int argc, char *argv[])
    54 {
    55     if (SDL_Init(SDL_INIT_VIDEO) == -1) {
    56         fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError());
    57         return 1;
    58     }
    59 
    60     report_power();
    61 
    62     SDL_Quit();
    63     return 0;
    64 }
    65 
    66 /* end of testpower.c ... */