Andrew Ziem : msvcrt: Fix _initterm, with tests.

Alexandre Julliard julliard at wine.codeweavers.com
Wed Jun 21 08:02:19 CDT 2006


Module: wine
Branch: refs/heads/master
Commit: 2132eb549074b35768a8023c7e5a9dde234b8131
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=2132eb549074b35768a8023c7e5a9dde234b8131

Author: Andrew Ziem <ahziem1 at mailbolt.com>
Date:   Tue Jun 13 22:51:13 2006 -0600

msvcrt: Fix _initterm, with tests.

---

 dlls/msvcrt/data.c            |    4 ++
 dlls/msvcrt/tests/.gitignore  |    1 +
 dlls/msvcrt/tests/Makefile.in |    1 +
 dlls/msvcrt/tests/data.c      |   73 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 78 insertions(+), 1 deletions(-)
 create mode 100644 dlls/msvcrt/tests/data.c

diff --git a/dlls/msvcrt/data.c b/dlls/msvcrt/data.c
index 1c4b8a7..2511970 100644
--- a/dlls/msvcrt/data.c
+++ b/dlls/msvcrt/data.c
@@ -342,6 +342,7 @@ void CDECL __wgetmainargs(int *argc, MSV
 unsigned int CDECL _initterm(_INITTERMFUN *start,_INITTERMFUN *end)
 {
   _INITTERMFUN* current = start;
+  unsigned int count=0;
 
   TRACE("(%p,%p)\n",start,end);
   while (current<end)
@@ -351,10 +352,11 @@ unsigned int CDECL _initterm(_INITTERMFU
       TRACE("Call init function %p\n",*current);
       (**current)();
       TRACE("returned\n");
+      count++;
     }
     current++;
   }
-  return 0;
+  return count;
 }
 
 /*********************************************************************
diff --git a/dlls/msvcrt/tests/.gitignore b/dlls/msvcrt/tests/.gitignore
index 2980711..f07f5c9 100644
--- a/dlls/msvcrt/tests/.gitignore
+++ b/dlls/msvcrt/tests/.gitignore
@@ -1,5 +1,6 @@
 Makefile
 cpp.ok
+data.ok
 dir.ok
 environ.ok
 file.ok
diff --git a/dlls/msvcrt/tests/Makefile.in b/dlls/msvcrt/tests/Makefile.in
index 9569f1e..38ddf05 100644
--- a/dlls/msvcrt/tests/Makefile.in
+++ b/dlls/msvcrt/tests/Makefile.in
@@ -9,6 +9,7 @@ EXTRAINCL = -I$(TOPSRCDIR)/include/msvcr
 
 CTESTS = \
 	cpp.c \
+	data.c \
 	dir.c \
 	environ.c \
 	file.c \
diff --git a/dlls/msvcrt/tests/data.c b/dlls/msvcrt/tests/data.c
new file mode 100644
index 0000000..c8eee75
--- /dev/null
+++ b/dlls/msvcrt/tests/data.c
@@ -0,0 +1,73 @@
+/*
+ * Tests msvcrt/data.c
+ *
+ * Copyright 2006 Andrew Ziem
+ *
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "msvcrt.h"
+#include "wine/test.h"
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <io.h>
+#include <windef.h>
+#include <winbase.h>
+#include <winnls.h>
+#include <process.h>
+#include <errno.h>
+
+typedef void (*_INITTERMFUN)(void);
+extern unsigned int CDECL _initterm(_INITTERMFUN *start,_INITTERMFUN *end);
+
+static int callbacked;
+
+void initcallback(void)
+{
+   callbacked++;
+}
+
+#define initterm_test(start, end, expected) \
+    callbacked = 0; \
+    rc = _initterm(start, end); \
+    ok(expected == rc, "_initterm: return result mismatch: got %i, expected %i\n", rc, expected); \
+    ok(expected == callbacked,"_initterm: callbacks count mismatch: got %i, expected %i\n", callbacked, expected);
+
+void test_initterm(void)
+{
+    int i;
+    int rc;
+    static _INITTERMFUN callbacks[4];
+
+    for (i = 0; i < 4; i++)
+    {
+        callbacks[i] = initcallback;
+    }
+
+    initterm_test(&callbacks[0], &callbacks[1], 1);
+    initterm_test(&callbacks[0], &callbacks[2], 2);
+    initterm_test(&callbacks[0], &callbacks[3], 3);
+
+    callbacks[1] = NULL;
+    initterm_test(&callbacks[0], &callbacks[3], 2);
+}
+
+START_TEST(data)
+{
+    test_initterm();
+}




More information about the wine-cvs mailing list