test/testpower.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 07 Dec 2017 16:08:09 -0800
changeset 11730 ac6c607e065c
parent 10737 3406a0f8b041
child 11811 5d94cb6b24d3
permissions -rw-r--r--
Enable building the Metal renderer by default, and weak link the Metal framework so the SDL library is safe to use on older Macs
Also generate iOS versions of the Metal shaders
slouken@5535
     1
/*
slouken@10737
     2
  Copyright (C) 1997-2017 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
aschiffler@7639
    24
    SDL_Log("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
aschiffler@7639
    46
    SDL_Log("State: %s\n", statestr);
icculus@3170
    47
icculus@3170
    48
    if (percent == -1) {
aschiffler@7639
    49
        SDL_Log("Percent left: unknown\n");
icculus@3170
    50
    } else {
aschiffler@7639
    51
        SDL_Log("Percent left: %d%%\n", percent);
icculus@3170
    52
    }
icculus@3170
    53
icculus@3170
    54
    if (seconds == -1) {
aschiffler@7639
    55
        SDL_Log("Time left: unknown\n");
icculus@3170
    56
    } else {
aschiffler@7639
    57
        SDL_Log("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
{
aschiffler@7639
    66
    /* Enable standard application logging */
aschiffler@7639
    67
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
aschiffler@7639
    68
slouken@7307
    69
    if (SDL_Init(0) == -1) {
aschiffler@7639
    70
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError());
icculus@3170
    71
        return 1;
icculus@3170
    72
    }
icculus@3170
    73
icculus@3170
    74
    report_power();
icculus@3170
    75
icculus@3170
    76
    SDL_Quit();
icculus@3170
    77
    return 0;
icculus@3170
    78
}
icculus@3170
    79
icculus@3170
    80
/* end of testpower.c ... */