[CRT_APITEST]
authorThomas Faber <thomas.faber@reactos.org>
Sat, 21 Nov 2015 12:04:36 +0000 (12:04 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Sat, 21 Nov 2015 12:04:36 +0000 (12:04 +0000)
- Add tests for static initialization and static constructors
CORE-10562

svn path=/trunk/; revision=69991

rostests/apitests/crt/msvcrt_crt_apitest.cmake
rostests/apitests/crt/static_construct.cpp [new file with mode: 0644]
rostests/apitests/crt/static_init.c [new file with mode: 0644]
rostests/apitests/crt/testlist.c

index 1f38759..6412387 100644 (file)
@@ -1261,6 +1261,8 @@ list(APPEND SOURCE_MSVCRT
 #    wprintf_s.c
 #    wscanf.c
 #    wscanf_s.c
 #    wprintf_s.c
 #    wscanf.c
 #    wscanf_s.c
+    static_construct.cpp
+    static_init.c
 )
 
 if(ARCH STREQUAL "i386")
 )
 
 if(ARCH STREQUAL "i386")
diff --git a/rostests/apitests/crt/static_construct.cpp b/rostests/apitests/crt/static_construct.cpp
new file mode 100644 (file)
index 0000000..6bf9b1d
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * PROJECT:         ReactOS api tests
+ * LICENSE:         LGPLv2.1+ - See COPYING.LIB in the top level directory
+ * PURPOSE:         Test for static C++ object construction
+ * PROGRAMMER:      Thomas Faber <thomas.faber@reactos.org>
+ */
+
+#include <apitest.h>
+
+extern "C"
+{
+extern int static_init_counter;
+
+static int static_init_counter_at_startup;
+static int static_construct_counter_at_startup;
+
+int static_construct_counter = 789;
+}
+
+struct init_static
+{
+    int m_counter;
+
+    init_static() :
+        m_counter(2)
+    {
+        static_init_counter_at_startup = static_init_counter;
+        static_construct_counter_at_startup = static_construct_counter;
+        static_construct_counter++;
+    }
+} init_static;
+
+START_TEST(static_construct)
+{
+    ok(static_init_counter_at_startup == 123, "static_init_counter at startup: %d\n", static_init_counter_at_startup);
+    ok(static_construct_counter_at_startup == 789, "static_construct_counter at startup: %d\n", static_construct_counter_at_startup);
+
+    ok(static_init_counter == 123, "static_init_counter: %d\n", static_init_counter);
+
+    ok(static_construct_counter == 790, "static_construct_counter: %d\n", static_construct_counter);
+    ok(init_static.m_counter == 2, "init_static.m_counter: %d\n", init_static.m_counter);
+}
diff --git a/rostests/apitests/crt/static_init.c b/rostests/apitests/crt/static_init.c
new file mode 100644 (file)
index 0000000..7d18b5a
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * PROJECT:         ReactOS api tests
+ * LICENSE:         LGPLv2.1+ - See COPYING.LIB in the top level directory
+ * PURPOSE:         Test for static variable initialization
+ * PROGRAMMER:      Thomas Faber <thomas.faber@reactos.org>
+ */
+
+#include <apitest.h>
+
+extern int static_construct_counter;
+
+int static_init_counter = 123;
+
+START_TEST(static_init)
+{    
+    ok(static_init_counter == 123, "static_init_counter: %d\n", static_init_counter);
+    ok(static_construct_counter == 790, "static_construct_counter: %d\n", static_construct_counter);
+}
index 49eabd6..92c6111 100644 (file)
@@ -17,6 +17,9 @@ extern void func_sprintf(void);
 extern void func_strcpy(void);
 extern void func_wcstombs(void);
 
 extern void func_strcpy(void);
 extern void func_wcstombs(void);
 
+extern void func_static_construct(void);
+extern void func_static_init(void);
+
 const struct test winetest_testlist[] =
 {
     { "_vsnprintf", func__vsnprintf },
 const struct test winetest_testlist[] =
 {
     { "_vsnprintf", func__vsnprintf },
@@ -35,6 +38,9 @@ const struct test winetest_testlist[] =
 #elif defined(TEST_MSVCRT)
     { "_vscprintf", func__vscprintf },
     { "_vscwprintf", func__vscwprintf },
 #elif defined(TEST_MSVCRT)
     { "_vscprintf", func__vscprintf },
     { "_vscwprintf", func__vscwprintf },
+
+    { "static_construct", func_static_construct },
+    { "static_init", func_static_init },
 #elif defined(TEST_NTDLL)
     { "_vscwprintf", func__vscwprintf },
 #elif defined(TEST_CRTDLL)
 #elif defined(TEST_NTDLL)
     { "_vscwprintf", func__vscwprintf },
 #elif defined(TEST_CRTDLL)