New snprintf test

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

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


[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux