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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
|
/*--------------------------------------------------------------------*//*:Ignore this sentence.
Copyright (C) 2007 SIL International. All rights reserved.
Distributable under the terms of either the Common Public License or the
GNU Lesser General Public License, as specified in the LICENSING.txt file.
File: GrcRegressionTest.cpp
Responsibility: Sharon Correll
Description:
Main file for the Graphite regression test program.
-------------------------------------------------------------------------------*//*:End Ignore*/
#include "main.h"
//:>********************************************************************************************
//:> Global variables
//:>********************************************************************************************
std::ofstream g_strmLog; // log file output stream
int g_errorCount;
bool g_debugMode = false;
bool g_silentMode = false;
char * g_benchmarkName = NULL;
char * g_testName = NULL;
char g_logFileName[128];
int g_itcaseStart = 0; // adjust to skip to a certain test
// Forward defintions.
int WriteLog(int);
void CopyWstringToUtf16(std::wstring textStr, gr::utf16 * utf16Buf, int bufSize);
//:>********************************************************************************************
//:> Functions
//:>********************************************************************************************
/*----------------------------------------------------------------------------------------------
Main function.
----------------------------------------------------------------------------------------------*/
int main(int argc, char* argv[])
{
#ifdef _WIN32
_CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
#endif // WIN32
if (argc < 3)
{
std::cout << "\nUsage: GrcRegressionTest [options] benchmark-file test-file\n";
std::cout << "\nOptions:\n";
std::cout << " -d - debug mode\n";
std::cout << " -s - silent mode\n";
std::cout << " -l file - specify log file name\n";
return -1;
}
int iargc = 1;
while (iargc < argc)
{
if (strcmp(argv[iargc], "/d") == 0 || strcmp(argv[iargc], "-d") == 0)
{
g_debugMode = true;
}
else if (strcmp(argv[iargc], "/s") == 0 || strcmp(argv[iargc], "-s") == 0)
{
g_silentMode = true;
}
else if (strcmp(argv[iargc], "/l") == 0 || strcmp(argv[iargc], "-l") == 0)
{
iargc++;
if (iargc < argc)
{
strcpy(g_logFileName, argv[iargc]);
//g_logFileName = argv[iargc];
}
}
else if (g_benchmarkName)
{
if (g_testName) {
std::cout << "Incorrect number of arguments";
return -1;
}
g_testName = argv[iargc];
}
else
{
g_benchmarkName = argv[iargc];
}
iargc++;
}
if (!g_silentMode)
std::cout << "Graphite Compiler Regression Test\n\n";
// Start a new log.
if (strlen(g_logFileName) == 0)
{
memset(g_logFileName, 0, 128);
strcpy(g_logFileName, "grcregtest.log");
}
g_strmLog.open(g_logFileName, std::ios_base::out | std::ios_base::app );
if (g_strmLog.fail())
{
std::cout << "Unable to open log file.";
return -1;
}
if (g_testName == NULL || g_benchmarkName == NULL)
{
std::cout << "Font files not adequately specified\n\n";
return -1;
}
g_errorCount = 0;
//WriteToLog("Graphite Compiler Regression Test\n\n");
// *** TEST CASES ***
/***
const int numberOfTests = 5;
TestCase rgtcaseList[5];
rgtcaseList[0].m_testName.assign("Scheherazade");
rgtcaseList[0].m_fontFileBmark.assign("SchBenchmark.ttf");
rgtcaseList[0].m_fontFileTest.assign("SchTest.ttf");
rgtcaseList[0].m_debug = false;
rgtcaseList[0].m_skip = false;
rgtcaseList[1].m_testName.assign("Charis");
rgtcaseList[1].m_fontFileBmark.assign("CharisBenchmark.ttf");
rgtcaseList[1].m_fontFileTest.assign("CharisTest.ttf");
rgtcaseList[1].m_debug = false;
rgtcaseList[1].m_skip = false;
rgtcaseList[2].m_testName.assign("PigLatin - Silf version 2");
rgtcaseList[2].m_fontFileBmark.assign("PigLatinBenchmark_v2.ttf");
rgtcaseList[2].m_fontFileTest.assign("PigLatinTest_v2.ttf");
rgtcaseList[2].m_debug = false;
rgtcaseList[2].m_skip = false;
rgtcaseList[3].m_testName.assign("PigLatin - Silf version 3");
rgtcaseList[3].m_fontFileBmark.assign("PigLatinBenchmark_v3.ttf");
rgtcaseList[3].m_fontFileTest.assign("PigLatinTest_v3.ttf");
rgtcaseList[3].m_debug = false;
rgtcaseList[3].m_skip = false;
rgtcaseList[4].m_testName.assign("Padauk");
rgtcaseList[4].m_fontFileBmark.assign("PadaukBenchmark.ttf");
rgtcaseList[4].m_fontFileTest.assign("PadaukTest.ttf");
rgtcaseList[4].m_debug = false;
rgtcaseList[4].m_skip = false;
// *** Add tests here, and increment numberOfTests. ***
//RunTests(numberOfTests, rgtcaseList);
****/
// Run the test.
WriteToLog("\nTesting ");
WriteToLog(g_testName);
WriteToLog(" against ");
WriteToLog(g_benchmarkName);
WriteToLog("...\n");
if (!g_silentMode)
std::cout << "Testing " << g_testName << " against " << g_benchmarkName << "...\n";
GrcRtFileFont fontBmark(g_benchmarkName, 12.0, 96, 96);
GrcRtFileFont fontTest(g_testName, 12.0, 96, 96);
int g_errorCount = CompareFontTables(NULL, &fontBmark, &fontTest);
WriteLog(g_errorCount);
WriteToLog("\n==============================================\n");
//g_strmLog << "\n\nTOTAL NUMBER OF ERRORS: " << g_errorCount << "\n";
//if (!g_silentMode)
// std::cout << "\n\nTOTAL NUMBER OF ERRORS: " << g_errorCount << "\n";
g_strmLog.close();
return g_errorCount;
}
/*----------------------------------------------------------------------------------------------
Run the tests.
----------------------------------------------------------------------------------------------*/
void RunTests(int numberOfTests, TestCase * ptcaseList)
{
for (int itcase = g_itcaseStart; itcase < numberOfTests; itcase++)
{
TestCase * ptcase = ptcaseList + itcase;
WriteToLog("\n----------------------------------------------\n");
WriteToLog("Test: ");
if (!g_silentMode)
std::cout << "Test " << ptcase->m_testName << "...";
WriteToLog(ptcase->m_testName);
if (ptcase->m_skip)
{
if (!g_silentMode) std::cout << "skipping\n";
WriteToLog("...skipping\n");
continue;
}
WriteToLog("\n");
RunOneTestCase(ptcase);
}
}
/*----------------------------------------------------------------------------------------------
Run a single test case.
----------------------------------------------------------------------------------------------*/
int RunOneTestCase(TestCase * ptcase)
{
#ifdef _MSC_VER
#if (_WIN32_WINNT > 0x0400)
// Break into the debugger if requested.
if (ptcase->m_debug ) ///&& ::IsDebuggerPresent())
{
::DebugBreak();
}
#endif
#endif
GrcRtFileFont fontBmark(ptcase->m_fontFileBmark, 12.0, 96, 96);
GrcRtFileFont fontTest( ptcase->m_fontFileTest, 12.0, 96, 96);
int errorCount = CompareFontTables(ptcase, &fontBmark, &fontTest);
return WriteLog(errorCount);
}
/*----------------------------------------------------------------------------------------------
Write the error count to the log.
----------------------------------------------------------------------------------------------*/
int WriteLog(int errorCount)
{
WriteToLog("\nError count = ");
WriteToLog(errorCount);
WriteToLog("\n");
if (!g_silentMode)
{
if (errorCount == 0)
std::cout << "ok\n";
else
std::cout << "FAILED\n";
}
g_errorCount += errorCount;
return errorCount;
}
/*----------------------------------------------------------------------------------------------
Copy a std::wstring (whose bytes can be of various sizes on different platforms)
to a buffer of UTF16.
----------------------------------------------------------------------------------------------*/
void CopyWstringToUtf16(std::wstring textStr, gr::utf16 * utf16Buf, int bufSize)
{
std::fill_n(utf16Buf, bufSize, 0);
int cc = textStr.length();
for (int i = 0; i < cc; i++)
utf16Buf[i] = textStr[i];
}
/*----------------------------------------------------------------------------------------------
Output information about an error.
----------------------------------------------------------------------------------------------*/
void OutputError(int & errCnt, TestCase * ptcase, std::string strErr, int i)
{
OutputErrorAux(ptcase, strErr, i, "", -1, false, 0, 0);
errCnt++;
}
void OutputErrorWithValues(int & errCnt, TestCase * ptcase, std::string strErr, int i,
int valueFound, int valueExpected)
{
OutputErrorAux(ptcase, strErr, i, "", -1, true, valueFound, valueExpected);
errCnt++;
}
void OutputError(int & errCnt, TestCase * ptcase, std::string strErr1, int i1,
std::string strErr2, int i2)
{
OutputErrorAux(ptcase, strErr1, i1, strErr2, i2, false, 0, 0);
errCnt++;
}
void OutputErrorAux(TestCase * ptcase,
std::string strErr1, int i1, std::string strErr2, int i2,
bool showValues, int valueFound, int valueExpected)
{
// if (g_debugMode)
// ::DebugBreak();
if (!g_silentMode)
{
//std::cout << ptcase->TestName() << ": ";
std::cout << strErr1;
if (i1 > -1)
{
std::cout << "[" << i1 << "]";
}
std::cout << strErr2;
if (i2 > -1)
{
std::cout << "[" << i2 << "]";
}
std::cout << "\n";
}
WriteToLog(strErr1, i1, strErr2, i2, showValues, valueFound, valueExpected);
WriteToLog("\n");
}
/*----------------------------------------------------------------------------------------------
Write some text to the log file.
----------------------------------------------------------------------------------------------*/
bool WriteToLog(std::string str, int i)
{
return WriteToLog(str, i, "", -1);
}
bool WriteToLog(std::string str1, int i1, std::string str2, int i2)
{
if (g_strmLog.fail())
{
std::cout << "Error opening log file.";
return false;
}
g_strmLog << str1;
if (i1 > -1)
g_strmLog << "[" << i1 << "]";
g_strmLog << str2;
if (i2 > -1)
g_strmLog << "[" << i2 << "]";
g_strmLog.flush();
return true;
}
bool WriteToLog(std::string str1, int i1, std::string str2, int i2,
bool showValues, int valueFound, int valueExpected)
{
if (g_strmLog.fail())
{
std::cout << "Error opening log file.";
return false;
}
g_strmLog << str1;
if (i1 > -1)
g_strmLog << "[" << i1 << "]";
g_strmLog << str2;
if (i2 > -1)
g_strmLog << "[" << i2 << "]";
if (showValues)
{
g_strmLog << "; found " << valueFound << " not " << valueExpected;
}
g_strmLog.flush();
return true;
}
bool WriteToLog(int n)
{
if (g_strmLog.fail())
{
std::cout << "Error opening log file.";
return false;
}
g_strmLog << n;
g_strmLog.flush();
return true;
}
std::wstring StringFromNameTable(const gr::byte * pNameTbl, int nLangID, int nNameID)
{
std::wstring stuName;
stuName.erase();
size_t lOffset = -1;
size_t lSize = -1;
// The Graphite compiler stores our names in either
// the MS (platform id = 3) Unicode (writing system id = 1) table
// or the MS Symbol (writing system id = 0) table. Try MS Unicode first.
// lOffset & lSize are in bytes.
// new interface:
if (!TtfUtil::GetNameInfo(pNameTbl, 3, 1, nLangID, nNameID, lOffset, lSize))
{
if (!TtfUtil::GetNameInfo(pNameTbl, 3, 0, nLangID, nNameID, lOffset, lSize))
{
return stuName;
}
}
size_t cchw = (unsigned(lSize) / sizeof(utf16));
utf16 * pchwName = new utf16[cchw+1]; // lSize - byte count for Uni str
const utf16 *pchwSrcName = reinterpret_cast<const utf16*>(pNameTbl + lOffset);
std::transform(pchwSrcName, pchwSrcName + cchw, pchwName, std::ptr_fun<utf16,utf16>(lsbf));
pchwName[cchw] = 0; // zero terminate
#ifdef _WIN32
stuName.assign((const wchar_t*)pchwName, cchw);
#else
wchar_t * pchwName32 = new wchar_t[cchw+1]; // lSize - byte count for Uni str
for (int i = 0; i <= signed(cchw); i++) {
pchwName32[i] = pchwName[i];
}
stuName.assign(pchwName32, cchw);
delete [] pchwName32;
#endif
delete [] pchwName;
return stuName;
}
|