-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathtestGeneric.cpp
More file actions
129 lines (115 loc) · 3.01 KB
/
Copy pathtestGeneric.cpp
File metadata and controls
129 lines (115 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*--------------------------------------------------------------------*//*:Ignore this sentence.
Copyright (c) 2003-2013 SIL International
This software is licensed under the LGPL, version 2.1 or later
(http://www.gnu.org/licenses/lgpl-2.1.html)
File: testGeneric.cpp
Responsibility: Dan Hinton (and possibly Alistair Imrie, if Dan has died or something)
Last reviewed:
Global initialization/cleanup for unit testing the Language DLL classes.
-------------------------------------------------------------------------------*//*:End Ignore*/
#include "testGenericLib.h"
#include "RedirectHKCU.h"
#ifdef DEBUG
#include "DebugProcs.h"
#endif
#include <cstdlib>
#include <cstring>
#include <csignal>
#include <stdexcept>
namespace
{
#ifdef DEBUG
Pfn_Assert g_previousAssertProc = NULL;
void RestorePreviousAssertProc()
{
if (g_previousAssertProc != NULL)
{
SetAssertProc(g_previousAssertProc);
g_previousAssertProc = NULL;
}
}
#endif
void TerminateOnSigAbrt(int)
{
TerminateProcess(GetCurrentProcess(), 3);
}
bool IsEnvironmentSwitchEnabled(const char * pszName)
{
size_t cchValue = 0;
char * pszValue = NULL;
const bool fEnabled =
_dupenv_s(&pszValue, &cchValue, pszName) == 0 &&
pszValue != NULL &&
strcmp(pszValue, "1") == 0;
free(pszValue);
return fEnabled;
}
#ifdef DEBUG
void WINAPI ThrowingAssertProc(const char * pszExp, const char * pszFile, int nLine, HMODULE)
{
char szMessage[1024];
sprintf_s(
szMessage,
"Native assert fired during test: %s (%s:%d)",
pszExp,
pszFile,
nLine
);
fprintf(stderr, "%s\n", szMessage);
fflush(stderr);
throw std::runtime_error(szMessage);
}
#endif
}
namespace unitpp
{
void GlobalSetup(bool verbose)
{
#ifdef DEBUG
if (IsEnvironmentSwitchEnabled("FW_TEST_ALLOW_ASSERT_DIALOGS"))
{
ShowAssertMessageBox(1);
}
else
{
g_previousAssertProc = SetAssertProc(ThrowingAssertProc);
ShowAssertMessageBox(0);
}
#endif
#if defined(WIN32) || defined(WIN64)
ModuleEntry::DllMain(0, DLL_PROCESS_ATTACH);
#endif
::OleInitialize(NULL);
RedirectRegistry();
StrUtil::InitIcuDataDir();
}
void GlobalTeardown()
{
signal(SIGABRT, TerminateOnSigAbrt);
const bool fInjectTeardownAbort = IsEnvironmentSwitchEnabled("FW_TEST_INDUCE_TEARDOWN_ABORT");
#ifdef DEBUG
const bool fInjectTeardownAssert = IsEnvironmentSwitchEnabled("FW_TEST_INDUCE_TEARDOWN_ASSERT");
if (fInjectTeardownAssert || fInjectTeardownAbort)
RestorePreviousAssertProc();
if (fInjectTeardownAssert)
AssertMsg(false, "Injected teardown assert for native test infrastructure validation");
#endif
if (fInjectTeardownAbort)
{
_set_error_mode(_OUT_TO_STDERR);
_set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
abort();
}
#if defined(WIN32) || defined(WIN64)
ModuleEntry::DllMain(0, DLL_PROCESS_DETACH);
#endif
::OleUninitialize();
#ifdef DEBUG
RestorePreviousAssertProc();
#endif
}
}
// Local Variables:
// mode:C++
// compile-command:"cmd.exe /e:4096 /c c:\\FW\\Bin\\mkGenLib-tst.bat"
// End: (These 4 lines are useful to Steve McConnel.)