Commit 0a600b1df45558c16812995aa2c03f0b5f636afb

Cameron Cawley 2022-07-02T00:27:51

Merge testguid into testautomation (#5873)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
diff --git a/VisualC/tests/testautomation/testautomation.vcxproj b/VisualC/tests/testautomation/testautomation.vcxproj
index 1673aee..0acc54a 100644
--- a/VisualC/tests/testautomation/testautomation.vcxproj
+++ b/VisualC/tests/testautomation/testautomation.vcxproj
@@ -206,6 +206,7 @@
     <ClCompile Include="..\..\..\test\testautomation_audio.c" />
     <ClCompile Include="..\..\..\test\testautomation_clipboard.c" />
     <ClCompile Include="..\..\..\test\testautomation_events.c" />
+    <ClCompile Include="..\..\..\test\testautomation_guid.c" />
     <ClCompile Include="..\..\..\test\testautomation_hints.c" />
     <ClCompile Include="..\..\..\test\testautomation_keyboard.c" />
     <ClCompile Include="..\..\..\test\testautomation_main.c" />
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index c2fcc76..0781aad 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -96,7 +96,6 @@ add_executable(testgesture testgesture.c)
 add_executable(testgl2 testgl2.c)
 add_executable(testgles testgles.c)
 add_executable(testgles2 testgles2.c)
-add_executable(testguid testguid.c)
 add_executable(testhaptic testhaptic.c)
 add_executable(testhotplug testhotplug.c)
 add_executable(testrumble testrumble.c)
@@ -178,7 +177,6 @@ SET(ALL_TESTS
     testgl2
     testgles
     testgles2
-    testguid
     testhaptic
     testhittesting
     testhotplug
@@ -227,7 +225,6 @@ set(NONINTERACTIVE
     testatomic
     testerror
     testfilesystem
-    testguid
     testlocale
     testplatform
     testpower
@@ -337,7 +334,6 @@ if(PSP)
         testfilesystem
         testgeometry
         testgl2
-        testguid
         testhittesting
         testiconv
         testintersections
diff --git a/test/Makefile.in b/test/Makefile.in
index 2bcfa92..435e50f 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -40,7 +40,6 @@ TARGETS = \
 	testgamecontroller$(EXE) \
 	testgeometry$(EXE) \
 	testgesture$(EXE) \
-	testguid$(EXE) \
 	testhaptic$(EXE) \
 	testhittesting$(EXE) \
 	testhotplug$(EXE) \
@@ -138,6 +137,7 @@ testautomation$(EXE): $(srcdir)/testautomation.c \
 		      $(srcdir)/testautomation_audio.c \
 		      $(srcdir)/testautomation_clipboard.c \
 		      $(srcdir)/testautomation_events.c \
+		      $(srcdir)/testautomation_guid.c \
 		      $(srcdir)/testautomation_keyboard.c \
 		      $(srcdir)/testautomation_main.c \
 		      $(srcdir)/testautomation_mouse.c \
@@ -216,9 +216,6 @@ testgles2$(EXE): $(srcdir)/testgles2.c
 testgles2_sdf$(EXE): $(srcdir)/testgles2_sdf.c $(srcdir)/testutils.c
 	$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
 
-testguid$(EXE): $(srcdir)/testguid.c
-	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
-
 testhaptic$(EXE): $(srcdir)/testhaptic.c
 	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
 
diff --git a/test/testautomation_guid.c b/test/testautomation_guid.c
new file mode 100644
index 0000000..0bfedeb
--- /dev/null
+++ b/test/testautomation_guid.c
@@ -0,0 +1,150 @@
+/**
+ * GUID test suite
+ */
+
+#include "SDL.h"
+#include "SDL_test.h"
+
+/* ================= Test Case Implementation ================== */
+
+/* Helper functions */
+
+#define NUM_TEST_GUIDS 5
+
+static struct {
+    char *str;
+    Uint64 upper, lower;
+} test_guids[NUM_TEST_GUIDS] = {
+    { "0000000000000000"    "ffffffffffffffff",
+     0x0000000000000000,   0xfffffffffffffffflu },
+    { "0011223344556677"    "8091a2b3c4d5e6f0",
+     0x0011223344556677lu, 0x8091a2b3c4d5e6f0lu },
+    { "a011223344556677"    "8091a2b3c4d5e6f0",
+     0xa011223344556677lu, 0x8091a2b3c4d5e6f0lu },
+    { "a011223344556677"    "8091a2b3c4d5e6f1",
+     0xa011223344556677lu, 0x8091a2b3c4d5e6f1lu },
+    { "a011223344556677"    "8191a2b3c4d5e6f0",
+     0xa011223344556677lu, 0x8191a2b3c4d5e6f0lu },
+};
+
+static void
+upper_lower_to_bytestring(Uint8* out, Uint64 upper, Uint64 lower)
+{
+    Uint64 values[2];
+    int i, k;
+
+    values[0] = upper;
+    values [1] = lower;
+
+    for (i = 0; i < 2; ++i) {
+        Uint64 v = values[i];
+
+        for (k = 0; k < 8; ++k) {
+            *out++ = v >> 56;
+            v <<= 8;
+        }
+    }
+}
+
+
+/* Test case functions */
+
+/**
+ * @brief Check String-to-GUID conversion
+ *
+ * @sa SDL_GUIDFromString
+ */
+static int
+TestGuidFromString(void *arg)
+{
+    int i;
+
+    SDLTest_AssertPass("Call to SDL_GUIDFromString");
+    for (i = 0; i < NUM_TEST_GUIDS; ++i) {
+        Uint8 expected[16];
+        SDL_GUID guid;
+
+        upper_lower_to_bytestring(expected,
+                                  test_guids[i].upper, test_guids[i].lower);
+
+        guid = SDL_GUIDFromString(test_guids[i].str);
+        SDLTest_AssertCheck(SDL_memcmp(expected, guid.data, 16) == 0, "GUID from string, GUID was: '%s'", test_guids[i].str);
+    }
+
+    return TEST_COMPLETED;
+}
+
+/**
+ * @brief Check GUID-to-String conversion
+ *
+ * @sa SDL_GUIDToString
+ */
+static int
+TestGuidToString(void *arg)
+{
+    int i;
+
+    SDLTest_AssertPass("Call to SDL_GUIDToString");
+    for (i = 0; i < NUM_TEST_GUIDS; ++i) {
+        const int guid_str_offset = 4;
+        char guid_str_buf[64];
+        char *guid_str = guid_str_buf + guid_str_offset;
+        SDL_GUID guid;
+        int size;
+
+        upper_lower_to_bytestring(guid.data,
+                                  test_guids[i].upper, test_guids[i].lower);
+
+        /* Serialise to limited-length buffers */
+        for (size = 0; size <= 36; ++size) {
+            const Uint8 fill_char = size + 0xa0;
+            Uint32 expected_prefix;
+            Uint32 actual_prefix;
+            int written_size;
+
+            SDL_memset(guid_str_buf, fill_char, sizeof(guid_str_buf));
+            SDL_GUIDToString(guid, guid_str, size);
+
+            /* Check bytes before guid_str_buf */
+            expected_prefix = fill_char | (fill_char << 8) | (fill_char << 16) | (fill_char << 24);
+            SDL_memcpy(&actual_prefix, guid_str_buf, 4);
+            SDLTest_AssertCheck(expected_prefix == actual_prefix, "String buffer memory before output untouched, expected: %i, got: %i, at size=%d", expected_prefix, actual_prefix, size);
+
+            /* Check that we did not overwrite too much */
+            written_size = 0;
+            while ((guid_str[written_size] & 0xff) != fill_char && written_size < 256) {
+                ++written_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);
+            if (size >= 33) {
+                SDLTest_AssertCheck(SDL_strcmp(guid_str, test_guids[i].str) == 0, "GUID string equality, from string: %s", test_guids[i].str);
+            }
+        }
+    }
+
+    return TEST_COMPLETED;
+}
+
+/* ================= 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
+};
diff --git a/test/testautomation_suites.h b/test/testautomation_suites.h
index a8c8863..a03cdbc 100644
--- a/test/testautomation_suites.h
+++ b/test/testautomation_suites.h
@@ -12,6 +12,7 @@
 extern SDLTest_TestSuiteReference audioTestSuite;
 extern SDLTest_TestSuiteReference clipboardTestSuite;
 extern SDLTest_TestSuiteReference eventsTestSuite;
+extern SDLTest_TestSuiteReference guidTestSuite;
 extern SDLTest_TestSuiteReference keyboardTestSuite;
 extern SDLTest_TestSuiteReference mainTestSuite;
 extern SDLTest_TestSuiteReference mouseTestSuite;
@@ -34,6 +35,7 @@ SDLTest_TestSuiteReference *testSuites[] =  {
     &audioTestSuite,
     &clipboardTestSuite,
     &eventsTestSuite,
+    &guidTestSuite,
     &keyboardTestSuite,
     &mainTestSuite,
     &mouseTestSuite,
diff --git a/test/testguid.c b/test/testguid.c
deleted file mode 100644
index 29ccb6a..0000000
--- a/test/testguid.c
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
-  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
- */
-
-#include <stdio.h>
-
-#include "SDL.h"
-
-/* Helpers */
-
-static int _error_count = 0;
-
-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
-
-static struct {
-    char *str;
-    Uint64 upper, lower;
-} test_guids[NUM_TEST_GUIDS] = {
-    { "0000000000000000"    "ffffffffffffffff",
-     0x0000000000000000,   0xfffffffffffffffflu },
-    { "0011223344556677"    "8091a2b3c4d5e6f0",
-     0x0011223344556677lu, 0x8091a2b3c4d5e6f0lu },
-    { "a011223344556677"    "8091a2b3c4d5e6f0",
-     0xa011223344556677lu, 0x8091a2b3c4d5e6f0lu },
-    { "a011223344556677"    "8091a2b3c4d5e6f1",
-     0xa011223344556677lu, 0x8091a2b3c4d5e6f1lu },
-    { "a011223344556677"    "8191a2b3c4d5e6f0",
-     0xa011223344556677lu, 0x8191a2b3c4d5e6f0lu },
-};
-
-static void
-upper_lower_to_bytestring(Uint8* out, Uint64 upper, Uint64 lower)
-{
-    Uint64 values[2];
-    int i, k;
-
-    values[0] = upper;
-    values [1] = lower;
-
-    for (i = 0; i < 2; ++i) {
-        Uint64 v = values[i];
-
-        for (k = 0; k < 8; ++k) {
-            *out++ = v >> 56;
-            v <<= 8;
-        }
-    }
-}
-
-/* ================= Test Case Implementation ================== */
-
-/**
- * @brief Check String-to-GUID conversion
- *
- * @sa SDL_GUIDFromString
- */
-static void
-TestGuidFromString(void)
-{
-    int i;
-
-    for (i = 0; i < NUM_TEST_GUIDS; ++i) {
-        Uint8 expected[16];
-        SDL_GUID guid;
-
-        upper_lower_to_bytestring(expected,
-                                  test_guids[i].upper, test_guids[i].lower);
-
-        guid = SDL_GUIDFromString(test_guids[i].str);
-        if (!ASSERT_EQ("GUID from string", 0, SDL_memcmp(expected, guid.data, 16))) {
-            SDL_Log("  GUID was: '%s'", test_guids[i].str);
-        }
-    }
-}
-
-/**
- * @brief Check GUID-to-String conversion
- *
- * @sa SDL_GUIDToString
- */
-static void
-TestGuidToString(void)
-{
-    int i;
-
-    for (i = 0; i < NUM_TEST_GUIDS; ++i) {
-        const int guid_str_offset = 4;
-        char guid_str_buf[64];
-        char *guid_str = guid_str_buf + guid_str_offset;
-        SDL_GUID guid;
-        int size;
-
-        upper_lower_to_bytestring(guid.data,
-                                  test_guids[i].upper, test_guids[i].lower);
-
-        /* Serialise to limited-length buffers */
-        for (size = 0; size <= 36; ++size) {
-            const Uint8 fill_char = size + 0xa0;
-            Uint32 expected_prefix;
-            Uint32 actual_prefix;
-            int written_size;
-
-            SDL_memset(guid_str_buf, fill_char, sizeof(guid_str_buf));
-            SDL_GUIDToString(guid, guid_str, size);
-
-            /* Check bytes before guid_str_buf */
-            expected_prefix = fill_char | (fill_char << 8) | (fill_char << 16) | (fill_char << 24);
-            SDL_memcpy(&actual_prefix, guid_str_buf, 4);
-            if (!ASSERT_EQ("String buffer memory before output untouched: ", expected_prefix, actual_prefix)) {
-                SDL_Log("  at size=%d", size);
-            }
-
-            /* Check that we did not overwrite too much */
-            written_size = 0;
-            while ((guid_str[written_size] & 0xff) != fill_char && written_size < 256) {
-                ++written_size;
-            }
-            if (!ASSERT_EQ("Output length is within expected bounds", 1, written_size <= size)) {
-                SDL_Log("  with length %d: wrote %d of %d permitted bytes",
-                        size, written_size, size);
-            }
-            if (size >= 33) {
-                if (!ASSERT_EQ("GUID string equality", 0, SDL_strcmp(guid_str, test_guids[i].str))) {
-                    SDL_Log("  from string: %s", test_guids[i].str);
-                }
-            }
-        }
-    }
-}
-
-int
-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;
-}
diff --git a/test/watcom.mif b/test/watcom.mif
index fd9bff7..91036f9 100644
--- a/test/watcom.mif
+++ b/test/watcom.mif
@@ -11,7 +11,7 @@ TARGETS = testatomic.exe testdisplayinfo.exe testbounds.exe testdraw2.exe &
           testdrawchessboard.exe testdropfile.exe testerror.exe testfile.exe &
           testfilesystem.exe testgamecontroller.exe testgeometry.exe testgesture.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 &
           testpower.exe testsensor.exe testrelative.exe testrendercopyex.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_surface.c testautomation_syswm.c &
          testautomation_timer.c testautomation_video.c &
-         testautomation_math.c
+         testautomation_math.c testautomation_guid.c
 
 OBJS = $(TARGETS:.exe=.obj)
 COBJS = $(CSRCS:.c=.obj)