msvcrt-A03: *printf test case

Jaco Greeff jaco at puxedo.org
Sun Nov 3 09:37:18 CST 2002


This msvcrt-A?? series patch implements test cases for the
*printf family of functions

License:
LGPL

Changelog:
* dlls/msvcrt/tests/Makefile.in, dlls/msvcrt/tests/printf.c:
Jaco Greeff <jaco at puxedo.org>
- Test case for the *printf family of functions

--[ inline patch ]--

diff -aurN msvcrt-A02/dlls/msvcrt/tests/Makefile.in
msvcrt-A03/dlls/msvcrt/tests/Makefile.in
--- msvcrt-A02/dlls/msvcrt/tests/Makefile.in	2002-10-30 23:49:03.000000000 +0000
+++ msvcrt-A03/dlls/msvcrt/tests/Makefile.in	2002-11-02 22:51:10.000000000 +0000
@@ -7,6 +7,7 @@
 EXTRAINCL = -I$(TOPSRCDIR)/include/msvcrt
 
 CTESTS = \
+	printf.c \
 	scanf.c 
 
 @MAKE_TEST_RULES@
diff -aurN msvcrt-A02/dlls/msvcrt/tests/printf.c
msvcrt-A03/dlls/msvcrt/tests/printf.c
--- msvcrt-A02/dlls/msvcrt/tests/printf.c	1970-01-01 00:00:00.000000000 +0000
+++ msvcrt-A03/dlls/msvcrt/tests/printf.c	2002-11-02 22:54:21.000000000 +0000
@@ -0,0 +1,69 @@
+/*
+ * Unit test suite for *printf functions.
+ *
+ * Copyright 2002 Jaco Greeff
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "stdio.h"
+#include "wine/test.h"
+#include "wine/unicode.h"
+
+static void test_string(FILE *f, void *pExpected, INT nLen, INT nSize)
+{
+    CHAR szResult[1024];
+
+    ok(fread(szResult, nSize, nLen, f) == nLen, "Unexpected number of bytes
read\n");
+    ok(memcmp(szResult, pExpected, nLen*nSize) == 0, "String comparison
failed\n");
+}
+
+static void test_printf(void)
+{
+    /* test strings */
+    static const CHAR szTestA[] = "ASCII";
+    static const CHAR szTestU[] = "Unicode";
+    static const WCHAR wszTestA[] = { 'A', 'S', 'C', 'I', 'I', 0 };
+    static const WCHAR wszTestU[] = { 'U', 'n', 'i', 'c', 'o', 'd', 'e', 0 };
+
+    /* test formatting operations */
+    static const CHAR szFmtA[] = "%s";
+    static const CHAR szFmtW[] = "%S";
+    static const WCHAR wszFmtW[] = { '%', 's', 0 };
+    static const WCHAR wszFmtA[] = { '%', 'S', 0 };
+
+    FILE *f;
+
+    /* write the strings to disk */
+    ok((f = fopen("printf.txt", "w")) != NULL, "Unable to create
printf.txt\n");
+    ok(fprintf(f, szFmtA, szTestA) == strlen(szTestA), "Failed writing
string\n");
+    ok(fprintf(f, szFmtW, wszTestA) == strlenW(wszTestA), "Failed writing
string\n");
+    ok(fwprintf(f, wszFmtA, szTestU) == strlen(szTestU), "Failed writing
string\n");
+    ok(fwprintf(f, wszFmtW, wszTestU) == strlenW(wszTestU), "Failed writing
string\n");
+    fclose(f);
+
+    /* read/test the strings on disk */
+    ok((f = fopen("printf.txt", "r")) != NULL, "Unable to open printf.txt\n");
+    test_string(f, (void *)szTestA, strlen(szTestA), sizeof(CHAR));
+    test_string(f, (void *)szTestA, strlen(szTestA), sizeof(CHAR));
+    test_string(f, (void *)wszTestU, strlenW(wszTestU), sizeof(WCHAR));
+    test_string(f, (void *)wszTestU, strlenW(wszTestU), sizeof(WCHAR));
+    fclose(f);
+}
+
+START_TEST(printf)
+{
+    test_printf();
+}




More information about the wine-patches mailing list