SDL/test/testautomation.c

176 lines
5.0 KiB
C
Raw Normal View History

/*
2024-01-01 14:15:26 -07:00
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely.
*/
#include <stdlib.h>
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include <SDL3/SDL_test.h>
#include "testautomation_suites.h"
static SDLTest_CommonState *state;
2023-03-08 08:41:36 -07:00
/* All test suites */
static SDLTest_TestSuiteReference *testSuites[] = {
&audioTestSuite,
&clipboardTestSuite,
&eventsTestSuite,
&guidTestSuite,
&hintsTestSuite,
2023-03-19 00:13:46 -06:00
&intrinsicsTestSuite,
2023-03-08 08:41:36 -07:00
&joystickTestSuite,
&keyboardTestSuite,
&logTestSuite,
2023-03-08 08:41:36 -07:00
&mainTestSuite,
&mathTestSuite,
&mouseTestSuite,
&penTestSuite,
2023-03-08 08:41:36 -07:00
&pixelsTestSuite,
&platformTestSuite,
&propertiesTestSuite,
2023-03-08 08:41:36 -07:00
&rectTestSuite,
&renderTestSuite,
&iostrmTestSuite,
2023-03-08 08:41:36 -07:00
&sdltestTestSuite,
&stdlibTestSuite,
&surfaceTestSuite,
Add time and realtime clock functions Adds functions to query the system's realtime clock, convert time intervals to/from a calendar date and time in either UTC or the local time, and perform time related calculations. An SDL_Time type (a time interval represented in nanoseconds), and SDL_DateTime struct (broken down calendar date and time) were added to facilitate this functionality. Querying the system time results in a value expressed in nanoseconds since the Unix epoch (Jan 1, 1970) in UTC +0000. Conversions to and from the various platform epochs and units are performed when required. Any direct handling of timezones and DST were intentionally avoided. The offset from UTC is provided when converting from UTC to a local time by calculating the difference between the original UTC and the resulting local time, but no other timezone or DST information is used. The preferred date formatting and 12/24 hour time for the system locale can be retrieved via global preferences. Helper functions for obtaining the day of week or day or year for calendar date, and getting the number of days in a month in a given year are provided for convenience. These are simple, but useful for performing various time related calculations. An automated test for time conversion is included, as is a simple standalone test to display the current system date and time onscreen along with a calendar, the rendering of which demonstrates the use of the utility functions (press up/down to increment or decrement the current month, and keys 1-5 to change the date and time formats).
2024-02-29 11:06:26 -07:00
&timeTestSuite,
2023-03-08 08:41:36 -07:00
&timerTestSuite,
&videoTestSuite,
&subsystemsTestSuite, /* run last, not interfere with other test enviroment */
2023-03-08 08:41:36 -07:00
NULL
};
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
quit(int rc)
{
SDLTest_CommonQuit(state);
/* Let 'main()' return normally */
if (rc != 0) {
exit(rc);
}
}
int main(int argc, char *argv[])
{
int result;
int testIterations = 1;
Uint64 userExecKey = 0;
char *userRunSeed = NULL;
char *filter = NULL;
int i, done;
SDL_Event event;
int list = 0;
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO | SDL_INIT_AUDIO);
2023-11-09 14:29:15 -07:00
if (!state) {
return 1;
}
/* No need of windows (or update testautomation_mouse.c:mouse_getMouseFocus() */
state->num_windows = 0;
/* Parse commandline */
for (i = 1; i < argc;) {
int consumed;
consumed = SDLTest_CommonArg(state, i);
if (consumed == 0) {
consumed = -1;
if (SDL_strcasecmp(argv[i], "--iterations") == 0) {
if (argv[i + 1]) {
testIterations = SDL_atoi(argv[i + 1]);
if (testIterations < 1) {
testIterations = 1;
}
consumed = 2;
}
} else if (SDL_strcasecmp(argv[i], "--execKey") == 0) {
if (argv[i + 1]) {
2022-12-01 14:07:03 -07:00
(void)SDL_sscanf(argv[i + 1], "%" SDL_PRIu64, &userExecKey);
consumed = 2;
}
} else if (SDL_strcasecmp(argv[i], "--seed") == 0) {
if (argv[i + 1]) {
userRunSeed = SDL_strdup(argv[i + 1]);
consumed = 2;
}
} else if (SDL_strcasecmp(argv[i], "--filter") == 0) {
if (argv[i + 1]) {
filter = SDL_strdup(argv[i + 1]);
consumed = 2;
}
} else if (SDL_strcasecmp(argv[i], "--list") == 0) {
consumed = 1;
list = 1;
}
}
if (consumed < 0) {
static const char *options[] = { "[--iterations #]", "[--execKey #]", "[--seed string]", "[--filter suite_name|test_name]", "[--list]", NULL };
SDLTest_CommonLogUsage(state, argv[0], options);
quit(1);
}
i += consumed;
}
/* List all suites. */
if (list) {
int suiteCounter;
for (suiteCounter = 0; testSuites[suiteCounter]; ++suiteCounter) {
int testCounter;
SDLTest_TestSuiteReference *testSuite = testSuites[suiteCounter];
SDL_Log("Test suite: %s", testSuite->name);
for (testCounter = 0; testSuite->testCases[testCounter]; ++testCounter) {
const SDLTest_TestCaseReference *testCase = testSuite->testCases[testCounter];
SDL_Log(" test: %s%s", testCase->name, testCase->enabled ? "" : " (disabled)");
}
}
return 0;
}
/* Initialize common state */
if (!SDLTest_CommonInit(state)) {
quit(2);
}
/* Create the windows, initialize the renderers */
for (i = 0; i < state->num_windows; ++i) {
SDL_Renderer *renderer = state->renderers[i];
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
SDL_RenderClear(renderer);
}
/* Call Harness */
result = SDLTest_RunSuites(testSuites, userRunSeed, userExecKey, filter, testIterations);
/* Empty event queue */
done = 0;
for (i = 0; i < 100; i++) {
while (SDL_PollEvent(&event)) {
SDLTest_CommonEvent(state, &event, &done);
}
SDL_Delay(10);
}
/* Clean up */
SDL_free(userRunSeed);
SDL_free(filter);
/* Shutdown everything */
quit(0);
return result;
}