summaryrefslogtreecommitdiff
path: root/src/contrib/SDL-3.2.20/test/testpower.c
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2025-08-30 16:53:58 -0700
committer3gg <3gg@shellblade.net>2025-08-30 16:53:58 -0700
commit6aaedb813fa11ba0679c3051bc2eb28646b9506c (patch)
tree34acbfc9840e02cb4753e6306ea7ce978bf8b58e /src/contrib/SDL-3.2.20/test/testpower.c
parent8f228ade99dd3d4c8da9b78ade1815c9adf85c8f (diff)
Update to SDL3
Diffstat (limited to 'src/contrib/SDL-3.2.20/test/testpower.c')
-rw-r--r--src/contrib/SDL-3.2.20/test/testpower.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/contrib/SDL-3.2.20/test/testpower.c b/src/contrib/SDL-3.2.20/test/testpower.c
new file mode 100644
index 0000000..912ee67
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/test/testpower.c
@@ -0,0 +1,90 @@
1/*
2 Copyright (C) 1997-2025 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 <SDL3/SDL.h>
15#include <SDL3/SDL_main.h>
16#include <SDL3/SDL_test.h>
17
18static void
19report_power(void)
20{
21 int seconds, percent;
22 const SDL_PowerState state = SDL_GetPowerInfo(&seconds, &percent);
23 const char *statestr = NULL;
24
25 SDL_Log("SDL-reported power info...");
26 switch (state) {
27 case SDL_POWERSTATE_UNKNOWN:
28 statestr = "Unknown";
29 break;
30 case SDL_POWERSTATE_ON_BATTERY:
31 statestr = "On battery";
32 break;
33 case SDL_POWERSTATE_NO_BATTERY:
34 statestr = "No battery";
35 break;
36 case SDL_POWERSTATE_CHARGING:
37 statestr = "Charging";
38 break;
39 case SDL_POWERSTATE_CHARGED:
40 statestr = "Charged";
41 break;
42 default:
43 statestr = "!!API ERROR!!";
44 break;
45 }
46
47 SDL_Log("State: %s", statestr);
48
49 if (percent == -1) {
50 SDL_Log("Percent left: unknown");
51 } else {
52 SDL_Log("Percent left: %d%%", percent);
53 }
54
55 if (seconds == -1) {
56 SDL_Log("Time left: unknown");
57 } else {
58 SDL_Log("Time left: %d minutes, %d seconds", seconds / 60, seconds % 60);
59 }
60}
61
62int main(int argc, char *argv[])
63{
64 SDLTest_CommonState *state;
65
66 /* Initialize test framework */
67 state = SDLTest_CommonCreateState(argv, 0);
68 if (!state) {
69 return 1;
70 }
71
72 /* Parse commandline */
73 if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
74 return 1;
75 }
76
77 if (!SDL_Init(0)) {
78 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s", SDL_GetError());
79 return 1;
80 }
81
82 report_power();
83
84 SDL_Quit();
85 SDLTest_CommonDestroyState(state);
86
87 return 0;
88}
89
90/* end of testpower.c ... */