-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathtestViews.cpp
More file actions
190 lines (169 loc) · 4.82 KB
/
Copy pathtestViews.cpp
File metadata and controls
190 lines (169 loc) · 4.82 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*--------------------------------------------------------------------*//*: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: testViews.cpp
Responsibility:
Last reviewed:
Global initialization/cleanup for unit testing the Views DLL classes.
-------------------------------------------------------------------------------*//*:End Ignore*/
#if !defined(WIN32) && !defined(_M_X64)
#define INITGUID
#endif
#include "testViews.h"
#include "RedirectHKCU.h"
#include "DebugProcs.h"
#include <cstdlib>
#include <cstring>
#include <csignal>
#include <stdexcept>
#if !defined(WIN32) && !defined(_M_X64)
// These define GUIDs that we need to define globally somewhere
#include "TestVwTxtSrc.h"
#include "TestLayoutPage.h"
#endif
namespace
{
Pfn_Assert g_previousAssertProc = NULL;
void RestorePreviousAssertProc()
{
if (g_previousAssertProc != NULL)
{
SetAssertProc(g_previousAssertProc);
g_previousAssertProc = NULL;
}
}
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;
}
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);
}
}
namespace unitpp
{
void GlobalSetup(bool verbose)
{
printf("DEBUG: Entering GlobalSetup\n");
fflush(stdout);
if (IsEnvironmentSwitchEnabled("FW_TEST_ALLOW_ASSERT_DIALOGS"))
{
ShowAssertMessageBox(1);
}
else
{
g_previousAssertProc = SetAssertProc(ThrowingAssertProc);
ShowAssertMessageBox(0); // Disable assertion dialogs
}
printf("DEBUG: After ShowAssertMessageBox\n");
fflush(stdout);
#if defined(WIN32) || defined(_M_X64)
ModuleEntry::DllMain(0, DLL_PROCESS_ATTACH);
printf("DEBUG: After DllMain\n");
fflush(stdout);
#endif
auto hr = ::OleInitialize(NULL);
printf("DEBUG: After OleInitialize (hr=0x%08X)\n", hr);
fflush(stdout);
RedirectRegistry();
printf("DEBUG: After RedirectRegistry\n");
fflush(stdout);
StrUtil::InitIcuDataDir();
printf("DEBUG: After InitIcuDataDir\n");
fflush(stdout);
}
void GlobalTeardown()
{
signal(SIGABRT, TerminateOnSigAbrt);
const bool fInjectTeardownAssert = IsEnvironmentSwitchEnabled("FW_TEST_INDUCE_TEARDOWN_ASSERT");
const bool fInjectTeardownAbort = IsEnvironmentSwitchEnabled("FW_TEST_INDUCE_TEARDOWN_ABORT");
if (fInjectTeardownAssert || fInjectTeardownAbort)
RestorePreviousAssertProc();
#ifdef DEBUG
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();
}
::OleUninitialize();
#if defined(WIN32) || defined(_M_X64)
ModuleEntry::DllMain(0, DLL_PROCESS_DETACH);
#endif
RestorePreviousAssertProc();
}
}
namespace TestViews
{
ILgWritingSystemFactoryPtr g_qwsf;
int g_wsEng = 0;
int g_wsFrn = 0;
int g_wsGer = 0;
int g_wsTest = 0;
int g_wsTest2 = 0;
// Create a dummy writing system factory with English and French.
void CreateTestWritingSystemFactory()
{
StrUni stuWs;
ILgWritingSystemPtr qws;
g_qwsf.Attach(NewObj MockLgWritingSystemFactory);
// Add a writing system for English.
stuWs.Assign(L"en");
CheckHr(g_qwsf->get_Engine(stuWs.Bstr(), &qws));
MockLgWritingSystem* mws = dynamic_cast<MockLgWritingSystem*>(qws.Ptr());
StrUni stuTimesNewRoman(L"Times New Roman");
mws->put_DefaultFontName(stuTimesNewRoman.Bstr());
CheckHr(qws->get_Handle(&g_wsEng));
CheckHr(g_qwsf->put_UserWs(g_wsEng));
// Add a writing system for French.
stuWs.Assign(L"fr");
CheckHr(g_qwsf->get_Engine(stuWs.Bstr(), &qws));
mws = dynamic_cast<MockLgWritingSystem*>(qws.Ptr());
mws->put_DefaultFontName(stuTimesNewRoman.Bstr());
CheckHr(qws->get_Handle(&g_wsFrn));
// Add a writing system for German.
stuWs.Assign(L"de");
CheckHr(g_qwsf->get_Engine(stuWs.Bstr(), &qws));
mws = dynamic_cast<MockLgWritingSystem*>(qws.Ptr());
mws->put_DefaultFontName(stuTimesNewRoman.Bstr());
CheckHr(qws->get_Handle(&g_wsGer));
}
// Free the dummy writing system factory.
void CloseTestWritingSystemFactory()
{
if (g_qwsf)
{
g_qwsf.Clear();
}
}
}
// Local Variables:
// mode:C++
// compile-command:"cmd.exe /e:4096 /c c:\\FW\\Bin\\mkvw-tst.bat DONTRUN"
// End: (These 4 lines are useful to Steve McConnel.)