Commit cdb4d8f22fc31b09e3f186f96c9e9f517662a558

Sam Lantinga 2021-11-07T09:39:57

Added a test case for snprintf of 0.0 This verifies regressions in https://github.com/libsdl-org/SDL/issues/4795

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
diff --git a/test/testautomation_stdlib.c b/test/testautomation_stdlib.c
index 9ea1964..608d92f 100644
--- a/test/testautomation_stdlib.c
+++ b/test/testautomation_stdlib.c
@@ -64,6 +64,14 @@ stdlib_snprintf(void *arg)
   SDLTest_AssertPass("Call to 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", 0.0);
+  predicted = SDL_snprintf(NULL, 0, "%f", 0.0);
+  expected = "0.000000";
+  SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 0.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", (int) SDL_strlen(text), result);
+  SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
+
   result = SDL_snprintf(text, sizeof(text), "%f", 1.0);
   predicted = SDL_snprintf(NULL, 0, "%f", 1.0);
   expected = "1.000000";