Merge testguid into testautomation (#5873)

This commit is contained in:
Cameron Cawley 2022-07-02 00:27:51 +01:00 committed by GitHub
parent cd79e9c4e2
commit 0a600b1df4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 47 additions and 70 deletions

View File

@ -206,6 +206,7 @@
<ClCompile Include="..\..\..\test\testautomation_audio.c" /> <ClCompile Include="..\..\..\test\testautomation_audio.c" />
<ClCompile Include="..\..\..\test\testautomation_clipboard.c" /> <ClCompile Include="..\..\..\test\testautomation_clipboard.c" />
<ClCompile Include="..\..\..\test\testautomation_events.c" /> <ClCompile Include="..\..\..\test\testautomation_events.c" />
<ClCompile Include="..\..\..\test\testautomation_guid.c" />
<ClCompile Include="..\..\..\test\testautomation_hints.c" /> <ClCompile Include="..\..\..\test\testautomation_hints.c" />
<ClCompile Include="..\..\..\test\testautomation_keyboard.c" /> <ClCompile Include="..\..\..\test\testautomation_keyboard.c" />
<ClCompile Include="..\..\..\test\testautomation_main.c" /> <ClCompile Include="..\..\..\test\testautomation_main.c" />

View File

@ -96,7 +96,6 @@ add_executable(testgesture testgesture.c)
add_executable(testgl2 testgl2.c) add_executable(testgl2 testgl2.c)
add_executable(testgles testgles.c) add_executable(testgles testgles.c)
add_executable(testgles2 testgles2.c) add_executable(testgles2 testgles2.c)
add_executable(testguid testguid.c)
add_executable(testhaptic testhaptic.c) add_executable(testhaptic testhaptic.c)
add_executable(testhotplug testhotplug.c) add_executable(testhotplug testhotplug.c)
add_executable(testrumble testrumble.c) add_executable(testrumble testrumble.c)
@ -178,7 +177,6 @@ SET(ALL_TESTS
testgl2 testgl2
testgles testgles
testgles2 testgles2
testguid
testhaptic testhaptic
testhittesting testhittesting
testhotplug testhotplug
@ -227,7 +225,6 @@ set(NONINTERACTIVE
testatomic testatomic
testerror testerror
testfilesystem testfilesystem
testguid
testlocale testlocale
testplatform testplatform
testpower testpower
@ -337,7 +334,6 @@ if(PSP)
testfilesystem testfilesystem
testgeometry testgeometry
testgl2 testgl2
testguid
testhittesting testhittesting
testiconv testiconv
testintersections testintersections

View File

@ -40,7 +40,6 @@ TARGETS = \
testgamecontroller$(EXE) \ testgamecontroller$(EXE) \
testgeometry$(EXE) \ testgeometry$(EXE) \
testgesture$(EXE) \ testgesture$(EXE) \
testguid$(EXE) \
testhaptic$(EXE) \ testhaptic$(EXE) \
testhittesting$(EXE) \ testhittesting$(EXE) \
testhotplug$(EXE) \ testhotplug$(EXE) \
@ -138,6 +137,7 @@ testautomation$(EXE): $(srcdir)/testautomation.c \
$(srcdir)/testautomation_audio.c \ $(srcdir)/testautomation_audio.c \
$(srcdir)/testautomation_clipboard.c \ $(srcdir)/testautomation_clipboard.c \
$(srcdir)/testautomation_events.c \ $(srcdir)/testautomation_events.c \
$(srcdir)/testautomation_guid.c \
$(srcdir)/testautomation_keyboard.c \ $(srcdir)/testautomation_keyboard.c \
$(srcdir)/testautomation_main.c \ $(srcdir)/testautomation_main.c \
$(srcdir)/testautomation_mouse.c \ $(srcdir)/testautomation_mouse.c \
@ -216,9 +216,6 @@ testgles2$(EXE): $(srcdir)/testgles2.c
testgles2_sdf$(EXE): $(srcdir)/testgles2_sdf.c $(srcdir)/testutils.c testgles2_sdf$(EXE): $(srcdir)/testgles2_sdf.c $(srcdir)/testutils.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@ $(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
testguid$(EXE): $(srcdir)/testguid.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
testhaptic$(EXE): $(srcdir)/testhaptic.c testhaptic$(EXE): $(srcdir)/testhaptic.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) $(CC) -o $@ $^ $(CFLAGS) $(LIBS)

View File

@ -1,42 +1,13 @@
/*
Copyright (C) 1997-2022 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.
*/
/** /**
* Automated tests for GUID processing * GUID test suite
*/ */
#include <stdio.h>
#include "SDL.h" #include "SDL.h"
#include "SDL_test.h"
/* Helpers */ /* ================= Test Case Implementation ================== */
static int _error_count = 0; /* Helper functions */
static int
_require_eq(Uint64 expected, Uint64 actual, int line, char *msg)
{
if (expected != actual) {
_error_count += 1;
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "[%s, L%d] %s: Actual %ld (0x%lx) != expected %ld (0x%lx)",
__FILE__, line, msg, actual, actual, expected, expected);
return 0;
}
return 1;
}
#define ASSERT_EQ(MSG, EXPECTED, ACTUAL) _require_eq((EXPECTED), (ACTUAL), __LINE__, (MSG))
/* Helpers */
#define NUM_TEST_GUIDS 5 #define NUM_TEST_GUIDS 5
@ -75,18 +46,20 @@ upper_lower_to_bytestring(Uint8* out, Uint64 upper, Uint64 lower)
} }
} }
/* ================= Test Case Implementation ================== */
/* Test case functions */
/** /**
* @brief Check String-to-GUID conversion * @brief Check String-to-GUID conversion
* *
* @sa SDL_GUIDFromString * @sa SDL_GUIDFromString
*/ */
static void static int
TestGuidFromString(void) TestGuidFromString(void *arg)
{ {
int i; int i;
SDLTest_AssertPass("Call to SDL_GUIDFromString");
for (i = 0; i < NUM_TEST_GUIDS; ++i) { for (i = 0; i < NUM_TEST_GUIDS; ++i) {
Uint8 expected[16]; Uint8 expected[16];
SDL_GUID guid; SDL_GUID guid;
@ -95,10 +68,10 @@ TestGuidFromString(void)
test_guids[i].upper, test_guids[i].lower); test_guids[i].upper, test_guids[i].lower);
guid = SDL_GUIDFromString(test_guids[i].str); guid = SDL_GUIDFromString(test_guids[i].str);
if (!ASSERT_EQ("GUID from string", 0, SDL_memcmp(expected, guid.data, 16))) { SDLTest_AssertCheck(SDL_memcmp(expected, guid.data, 16) == 0, "GUID from string, GUID was: '%s'", test_guids[i].str);
SDL_Log(" GUID was: '%s'", test_guids[i].str);
}
} }
return TEST_COMPLETED;
} }
/** /**
@ -106,11 +79,12 @@ TestGuidFromString(void)
* *
* @sa SDL_GUIDToString * @sa SDL_GUIDToString
*/ */
static void static int
TestGuidToString(void) TestGuidToString(void *arg)
{ {
int i; int i;
SDLTest_AssertPass("Call to SDL_GUIDToString");
for (i = 0; i < NUM_TEST_GUIDS; ++i) { for (i = 0; i < NUM_TEST_GUIDS; ++i) {
const int guid_str_offset = 4; const int guid_str_offset = 4;
char guid_str_buf[64]; char guid_str_buf[64];
@ -134,36 +108,43 @@ TestGuidToString(void)
/* Check bytes before guid_str_buf */ /* Check bytes before guid_str_buf */
expected_prefix = fill_char | (fill_char << 8) | (fill_char << 16) | (fill_char << 24); expected_prefix = fill_char | (fill_char << 8) | (fill_char << 16) | (fill_char << 24);
SDL_memcpy(&actual_prefix, guid_str_buf, 4); SDL_memcpy(&actual_prefix, guid_str_buf, 4);
if (!ASSERT_EQ("String buffer memory before output untouched: ", expected_prefix, actual_prefix)) { SDLTest_AssertCheck(expected_prefix == actual_prefix, "String buffer memory before output untouched, expected: %i, got: %i, at size=%d", expected_prefix, actual_prefix, size);
SDL_Log(" at size=%d", size);
}
/* Check that we did not overwrite too much */ /* Check that we did not overwrite too much */
written_size = 0; written_size = 0;
while ((guid_str[written_size] & 0xff) != fill_char && written_size < 256) { while ((guid_str[written_size] & 0xff) != fill_char && written_size < 256) {
++written_size; ++written_size;
} }
if (!ASSERT_EQ("Output length is within expected bounds", 1, written_size <= size)) { SDLTest_AssertCheck(written_size <= size, "Output length is within expected bounds, with length %d: wrote %d of %d permitted bytes", size, written_size, size);
SDL_Log(" with length %d: wrote %d of %d permitted bytes",
size, written_size, size);
}
if (size >= 33) { if (size >= 33) {
if (!ASSERT_EQ("GUID string equality", 0, SDL_strcmp(guid_str, test_guids[i].str))) { SDLTest_AssertCheck(SDL_strcmp(guid_str, test_guids[i].str) == 0, "GUID string equality, from string: %s", test_guids[i].str);
SDL_Log(" from string: %s", test_guids[i].str);
}
}
} }
} }
} }
int return TEST_COMPLETED;
main(int argc, char *argv[])
{
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
TestGuidFromString();
TestGuidToString();
return _error_count > 0;
} }
/* ================= Test References ================== */
/* GUID routine test cases */
static const SDLTest_TestCaseReference guidTest1 =
{ (SDLTest_TestCaseFp)TestGuidFromString, "TestGuidFromString", "Call to SDL_GUIDFromString", TEST_ENABLED };
static const SDLTest_TestCaseReference guidTest2 =
{ (SDLTest_TestCaseFp)TestGuidToString, "TestGuidToString", "Call to SDL_GUIDToString", TEST_ENABLED };
/* Sequence of GUID routine test cases */
static const SDLTest_TestCaseReference *guidTests[] = {
&guidTest1,
&guidTest2,
NULL
};
/* GUID routine test suite (global) */
SDLTest_TestSuiteReference guidTestSuite = {
"GUID",
NULL,
guidTests,
NULL
};

View File

@ -12,6 +12,7 @@
extern SDLTest_TestSuiteReference audioTestSuite; extern SDLTest_TestSuiteReference audioTestSuite;
extern SDLTest_TestSuiteReference clipboardTestSuite; extern SDLTest_TestSuiteReference clipboardTestSuite;
extern SDLTest_TestSuiteReference eventsTestSuite; extern SDLTest_TestSuiteReference eventsTestSuite;
extern SDLTest_TestSuiteReference guidTestSuite;
extern SDLTest_TestSuiteReference keyboardTestSuite; extern SDLTest_TestSuiteReference keyboardTestSuite;
extern SDLTest_TestSuiteReference mainTestSuite; extern SDLTest_TestSuiteReference mainTestSuite;
extern SDLTest_TestSuiteReference mouseTestSuite; extern SDLTest_TestSuiteReference mouseTestSuite;
@ -34,6 +35,7 @@ SDLTest_TestSuiteReference *testSuites[] = {
&audioTestSuite, &audioTestSuite,
&clipboardTestSuite, &clipboardTestSuite,
&eventsTestSuite, &eventsTestSuite,
&guidTestSuite,
&keyboardTestSuite, &keyboardTestSuite,
&mainTestSuite, &mainTestSuite,
&mouseTestSuite, &mouseTestSuite,

View File

@ -11,7 +11,7 @@ TARGETS = testatomic.exe testdisplayinfo.exe testbounds.exe testdraw2.exe &
testdrawchessboard.exe testdropfile.exe testerror.exe testfile.exe & testdrawchessboard.exe testdropfile.exe testerror.exe testfile.exe &
testfilesystem.exe testgamecontroller.exe testgeometry.exe testgesture.exe & testfilesystem.exe testgamecontroller.exe testgeometry.exe testgesture.exe &
testhittesting.exe testhotplug.exe testiconv.exe testime.exe testlocale.exe & testhittesting.exe testhotplug.exe testiconv.exe testime.exe testlocale.exe &
testguid.exe testintersections.exe testjoystick.exe testkeys.exe testloadso.exe & testintersections.exe testjoystick.exe testkeys.exe testloadso.exe &
testlock.exe testmessage.exe testoverlay2.exe testplatform.exe & testlock.exe testmessage.exe testoverlay2.exe testplatform.exe &
testpower.exe testsensor.exe testrelative.exe testrendercopyex.exe & testpower.exe testsensor.exe testrelative.exe testrendercopyex.exe &
testrendertarget.exe testrumble.exe testscale.exe testsem.exe & testrendertarget.exe testrumble.exe testscale.exe testsem.exe &
@ -58,7 +58,7 @@ TASRCS = testautomation.c testautomation_audio.c testautomation_clipboard.c &
testautomation_sdltest.c testautomation_stdlib.c & testautomation_sdltest.c testautomation_stdlib.c &
testautomation_surface.c testautomation_syswm.c & testautomation_surface.c testautomation_syswm.c &
testautomation_timer.c testautomation_video.c & testautomation_timer.c testautomation_video.c &
testautomation_math.c testautomation_math.c testautomation_guid.c
OBJS = $(TARGETS:.exe=.obj) OBJS = $(TARGETS:.exe=.obj)
COBJS = $(CSRCS:.c=.obj) COBJS = $(CSRCS:.c=.obj)