mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-23 21:19:11 +00:00
testprograms: parse arguments using SDLTest_CommonState
This commit is contained in:
parent
8bea41f737
commit
4a6528e3f0
71 changed files with 1516 additions and 389 deletions
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_main.h>
|
||||
#include <SDL3/SDL_test.h>
|
||||
|
||||
#define DEFAULT_RESOLUTION 1
|
||||
|
||||
|
@ -36,14 +37,46 @@ callback(Uint32 interval, void *param)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, desired;
|
||||
int i;
|
||||
int desired = -1;
|
||||
SDL_TimerID t1, t2, t3;
|
||||
Uint64 start, now;
|
||||
Uint64 start_perf, now_perf;
|
||||
SDLTest_CommonState *state;
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, 0);
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Parse commandline */
|
||||
for (i = 1; i < argc;) {
|
||||
int consumed;
|
||||
|
||||
consumed = SDLTest_CommonArg(state, i);
|
||||
if (!consumed) {
|
||||
if (desired < 0) {
|
||||
char *endptr;
|
||||
|
||||
desired = SDL_strtoul(argv[i], &endptr, 0);
|
||||
if (desired != 0 && endptr != argv[i] && *endptr == '\0') {
|
||||
consumed = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (consumed <= 0) {
|
||||
static const char *options[] = { "[interval]", NULL };
|
||||
SDLTest_CommonLogUsage(state, argv[0], options);
|
||||
return 1;
|
||||
}
|
||||
|
||||
i += consumed;
|
||||
}
|
||||
|
||||
if (SDL_Init(SDL_INIT_TIMER) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
|
@ -69,11 +102,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
/* Start the timer */
|
||||
desired = 0;
|
||||
if (argv[1]) {
|
||||
desired = SDL_atoi(argv[1]);
|
||||
}
|
||||
if (desired == 0) {
|
||||
if (desired < 0) {
|
||||
desired = DEFAULT_RESOLUTION;
|
||||
}
|
||||
t1 = SDL_AddTimer(desired, ticktock, NULL);
|
||||
|
@ -133,6 +162,7 @@ int main(int argc, char *argv[])
|
|||
now = SDL_GetTicks();
|
||||
SDL_Log("Delay 1 second = %d ms in ticks, %f ms according to performance counter\n", (int)(now - start), (double)((now_perf - start_perf) * 1000) / SDL_GetPerformanceFrequency());
|
||||
|
||||
SDLTest_CommonDestroyState(state);
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue