Skip to content

Commit

Permalink
[CRT_APITEST]
Browse files Browse the repository at this point in the history
- Add tests for static initialization and static constructors
CORE-10562

svn path=/trunk/; revision=69991
  • Loading branch information
ThFabba committed Nov 21, 2015
1 parent cd1f296 commit bfa1295
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rostests/apitests/crt/msvcrt_crt_apitest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,8 @@ list(APPEND SOURCE_MSVCRT
# wprintf_s.c
# wscanf.c
# wscanf_s.c
static_construct.cpp
static_init.c
)

if(ARCH STREQUAL "i386")
Expand Down
42 changes: 42 additions & 0 deletions rostests/apitests/crt/static_construct.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
18 changes: 18 additions & 0 deletions rostests/apitests/crt/static_init.c
Original file line number Diff line number Diff line change
@@ -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);
}
6 changes: 6 additions & 0 deletions rostests/apitests/crt/testlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ extern void func_sprintf(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 },
Expand All @@ -35,6 +38,9 @@ const struct test winetest_testlist[] =
#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)
Expand Down

0 comments on commit bfa1295

Please sign in to comment.