New snprintf test (take 2)

Ferenc Wagner wferi at afavant.elte.hu
Sun Dec 14 18:51:51 CST 2003


Under Wine I see libc 2.1+ behaviour, on XP pre-2.1
behaviour with respect to the return value of snprintf.

This test may not belong to scanf.c, but it has already
contained an sprintf test, so I decided to go on.  Drop me a
mail if those should be moved into some other file instead.

I hope that todo("none") { ... } is an acceptable way of not
marking a test as TODO.

Feri.

Index: dlls/msvcrt/tests/scanf.c
===================================================================
RCS file: /home/wine/wine/dlls/msvcrt/tests/scanf.c,v
retrieving revision 1.9
diff -u -r1.9 scanf.c
--- dlls/msvcrt/tests/scanf.c	28 Oct 2003 00:04:42 -0000	1.9
+++ dlls/msvcrt/tests/scanf.c	15 Dec 2003 00:47:08 -0000
@@ -92,8 +92,43 @@
       }
 }
 
+static void test_snprintf (void)
+{
+    struct snprintf_test {
+        const char *format;
+        int expected;
+        struct {
+            int retval;
+            int render;
+        } todo;
+    };
+    /* Pre-2.1 libc behaviour, not C99 compliant. */
+    const struct snprintf_test tests[] = {{"short", 5, {0, 0}},
+                                          {"justfit", 7, {0, 0}},
+                                          {"justfits", 8, {0, 1}},
+                                          {"muchlonger", -1, {1, 1}}};
+    char buffer[8];
+    const int bufsiz = sizeof buffer;
+    unsigned int i;
+
+    for (i = 0; i < sizeof tests / sizeof tests[0]; i++) {
+        const char *fmt  = tests[i].format;
+        const int expect = tests[i].expected;
+        const int n      = _snprintf (buffer, bufsiz, fmt);
+        const int valid  = n < 0 ? bufsiz : (n == bufsiz ? n : n+1);
+
+        todo (tests[i].todo.retval ? "wine" : "none")
+            ok (n == expect, "\"%s\": expected %d, returned %d",
+                fmt, expect, n);
+        todo (tests[i].todo.render ? "wine" : "none")
+            ok (!memcmp (fmt, buffer, valid),
+                "\"%s\": rendered \"%.*s\"", fmt, valid, buffer);
+    };
+}
+
 START_TEST(scanf)
 {
     test_sscanf();
     test_sprintf();
+    test_snprintf();
 }



More information about the wine-patches mailing list