Added the beginning of automated tests for the standard C library routines.
Implemented more SDL_snprintf format specifiers.
This commit is contained in:
parent
00abdbbc2a
commit
03210bff7e
4 changed files with 359 additions and 135 deletions
|
@ -69,22 +69,23 @@ testaudioinfo$(EXE): $(srcdir)/testaudioinfo.c
|
|||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testautomation$(EXE): $(srcdir)/testautomation.c \
|
||||
$(srcdir)/testautomation_audio.c \
|
||||
$(srcdir)/testautomation_clipboard.c \
|
||||
$(srcdir)/testautomation_events.c \
|
||||
$(srcdir)/testautomation_keyboard.c \
|
||||
$(srcdir)/testautomation_main.c \
|
||||
$(srcdir)/testautomation_mouse.c \
|
||||
$(srcdir)/testautomation_pixels.c \
|
||||
$(srcdir)/testautomation_platform.c \
|
||||
$(srcdir)/testautomation_rect.c \
|
||||
$(srcdir)/testautomation_render.c \
|
||||
$(srcdir)/testautomation_rwops.c \
|
||||
$(srcdir)/testautomation_audio.c \
|
||||
$(srcdir)/testautomation_surface.c \
|
||||
$(srcdir)/testautomation_events.c \
|
||||
$(srcdir)/testautomation_keyboard.c \
|
||||
$(srcdir)/testautomation_video.c \
|
||||
$(srcdir)/testautomation_syswm.c \
|
||||
$(srcdir)/testautomation_sdltest.c \
|
||||
$(srcdir)/testautomation_mouse.c \
|
||||
$(srcdir)/testautomation_stdlib.c \
|
||||
$(srcdir)/testautomation_surface.c \
|
||||
$(srcdir)/testautomation_syswm.c \
|
||||
$(srcdir)/testautomation_timer.c \
|
||||
$(srcdir)/testautomation_pixels.c
|
||||
$(srcdir)/testautomation_video.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) -lSDL2_test $(LIBS)
|
||||
|
||||
testmultiaudio$(EXE): $(srcdir)/testmultiaudio.c
|
||||
|
|
142
test/testautomation_stdlib.c
Normal file
142
test/testautomation_stdlib.c
Normal file
|
@ -0,0 +1,142 @@
|
|||
/**
|
||||
* Standard C library routine test suite
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_test.h"
|
||||
|
||||
|
||||
/* Test case functions */
|
||||
|
||||
/**
|
||||
* @brief Call to SDL_strlcpy
|
||||
*/
|
||||
#undef SDL_strlcpy
|
||||
int
|
||||
stdlib_strlcpy(void *arg)
|
||||
{
|
||||
size_t result;
|
||||
char text[1024];
|
||||
const char *expected;
|
||||
|
||||
result = SDL_strlcpy(text, "foo", sizeof(text));
|
||||
expected = "foo";
|
||||
SDLTest_AssertPass("Call to SDL_strlcpy(\"foo\")");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||
|
||||
result = SDL_strlcpy(text, "foo", 2);
|
||||
expected = "f";
|
||||
SDLTest_AssertPass("Call to SDL_strlcpy(\"foo\") with buffer size 2");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", result);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Call to SDL_snprintf
|
||||
*/
|
||||
#undef SDL_snprintf
|
||||
int
|
||||
stdlib_snprintf(void *arg)
|
||||
{
|
||||
int result;
|
||||
char text[1024];
|
||||
const char *expected;
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%s", "foo");
|
||||
expected = "foo";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\", \"foo\")");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(text, 2, "%s", "foo");
|
||||
expected = "f";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\", \"foo\") with buffer size 2");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", result);
|
||||
|
||||
result = SDL_snprintf(NULL, 0, "%s", "foo");
|
||||
SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", result);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%f", 1.0);
|
||||
expected = "1.000000";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 1.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%.f", 1.0);
|
||||
expected = "1";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%.f\", 1.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%#.f", 1.0);
|
||||
expected = "1.";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%#.f\", 1.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%f", 1.0 + 1.0 / 3.0);
|
||||
expected = "1.333333";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 1.0 + 1.0 / 3.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%+f", 1.0 + 1.0 / 3.0);
|
||||
expected = "+1.333333";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%+f\", 1.0 + 1.0 / 3.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%.2f", 1.0 + 1.0 / 3.0);
|
||||
expected = "1.33";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%.2f\", 1.0 + 1.0 / 3.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%6.2f", 1.0 + 1.0 / 3.0);
|
||||
expected = " 1.33";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%6.2f\", 1.0 + 1.0 / 3.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%06.2f", 1.0 + 1.0 / 3.0);
|
||||
expected = "001.33";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%06.2f\", 1.0 + 1.0 / 3.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", SDL_strlen(text), result);
|
||||
|
||||
result = SDL_snprintf(text, 5, "%06.2f", 1.0 + 1.0 / 3.0);
|
||||
expected = "001.";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%06.2f\", 1.0 + 1.0 / 3.0) with buffer size 5");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
|
||||
SDLTest_AssertCheck(result == 6, "Check result value, expected: 6, got: %d", result);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* ================= Test References ================== */
|
||||
|
||||
/* Standard C routine test cases */
|
||||
static const SDLTest_TestCaseReference stdlibTest1 =
|
||||
{ (SDLTest_TestCaseFp)stdlib_strlcpy, "stdlib_strlcpy", "Call to SDL_strlcpy", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference stdlibTest2 =
|
||||
{ (SDLTest_TestCaseFp)stdlib_snprintf, "stdlib_snprintf", "Call to SDL_sprintf", TEST_ENABLED };
|
||||
|
||||
/* Sequence of Standard C routine test cases */
|
||||
static const SDLTest_TestCaseReference *stdlibTests[] = {
|
||||
&stdlibTest1, &stdlibTest2, NULL
|
||||
};
|
||||
|
||||
/* Timer test suite (global) */
|
||||
SDLTest_TestSuiteReference stdlibTestSuite = {
|
||||
"Standard C routines",
|
||||
NULL,
|
||||
stdlibTests,
|
||||
NULL
|
||||
};
|
|
@ -14,17 +14,18 @@ extern SDLTest_TestSuiteReference clipboardTestSuite;
|
|||
extern SDLTest_TestSuiteReference eventsTestSuite;
|
||||
extern SDLTest_TestSuiteReference keyboardTestSuite;
|
||||
extern SDLTest_TestSuiteReference mainTestSuite;
|
||||
extern SDLTest_TestSuiteReference mouseTestSuite;
|
||||
extern SDLTest_TestSuiteReference pixelsTestSuite;
|
||||
extern SDLTest_TestSuiteReference platformTestSuite;
|
||||
extern SDLTest_TestSuiteReference rectTestSuite;
|
||||
extern SDLTest_TestSuiteReference renderTestSuite;
|
||||
extern SDLTest_TestSuiteReference rwopsTestSuite;
|
||||
extern SDLTest_TestSuiteReference sdltestTestSuite;
|
||||
extern SDLTest_TestSuiteReference stdlibTestSuite;
|
||||
extern SDLTest_TestSuiteReference surfaceTestSuite;
|
||||
extern SDLTest_TestSuiteReference syswmTestSuite;
|
||||
extern SDLTest_TestSuiteReference sdltestTestSuite;
|
||||
extern SDLTest_TestSuiteReference videoTestSuite;
|
||||
extern SDLTest_TestSuiteReference mouseTestSuite;
|
||||
extern SDLTest_TestSuiteReference timerTestSuite;
|
||||
extern SDLTest_TestSuiteReference pixelsTestSuite;
|
||||
extern SDLTest_TestSuiteReference videoTestSuite;
|
||||
|
||||
// All test suites
|
||||
SDLTest_TestSuiteReference *testSuites[] = {
|
||||
|
@ -33,17 +34,18 @@ SDLTest_TestSuiteReference *testSuites[] = {
|
|||
&eventsTestSuite,
|
||||
&keyboardTestSuite,
|
||||
&mainTestSuite,
|
||||
&mouseTestSuite,
|
||||
&pixelsTestSuite,
|
||||
&platformTestSuite,
|
||||
&rectTestSuite,
|
||||
&renderTestSuite,
|
||||
&rwopsTestSuite,
|
||||
&sdltestTestSuite,
|
||||
&stdlibTestSuite,
|
||||
&surfaceTestSuite,
|
||||
&syswmTestSuite,
|
||||
&sdltestTestSuite,
|
||||
&videoTestSuite,
|
||||
&mouseTestSuite,
|
||||
&timerTestSuite,
|
||||
&pixelsTestSuite,
|
||||
&videoTestSuite,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue