diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/Readme.txt | 88 | ||||
-rw-r--r-- | test/TLogHelper.cpp | 278 |
2 files changed, 366 insertions, 0 deletions
diff --git a/test/Readme.txt b/test/Readme.txt new file mode 100644 index 0000000..8ef0c67 --- /dev/null +++ b/test/Readme.txt @@ -0,0 +1,88 @@ +Testing MPQ set for StormLib test suite +======================================= + +The path to the directory could be anywhere. Path to this directory +is set on a command line. If there is no command line argument passed, +one of the hard-coded paths is used. + +The testing directory must contain the following files: + +Path File Size +------------------------------------------------- ----------- +patches\wow-update-13164.MPQ 480 028 668 // Original patch files from WoW +patches\wow-update-13205.MPQ 8 814 +patches\wow-update-13287.MPQ 333 363 917 +patches\wow-update-13329.MPQ 159 285 434 +patches\wow-update-13596.MPQ 148 022 182 +patches\wow-update-13623.MPQ 11 561 +patches\wow-update-base-13914.MPQ 293 580 556 +patches\wow-update-base-14007.MPQ 262 906 +patches\wow-update-base-14333.MPQ 368 972 365 +patches\wow-update-base-14480.MPQ 75 897 +patches\wow-update-base-14545.MPQ 1 224 415 +patches\wow-update-base-14946.MPQ 749 246 163 +patches\wow-update-base-15005.MPQ 7 121 223 +patches\wow-update-base-15050.MPQ 4 497 +patches\wow-update-enGB-16016.MPQ 17 117 318 +patches\wow-update-enGB-16048.MPQ 78 180 +patches\wow-update-enGB-16057.MPQ 4 072 +patches\wow-update-enGB-16309.MPQ 28 187 877 +patches\wow-update-enGB-16357.MPQ 3 621 +patches\wow-update-enGB-16516.MPQ 42 934 402 +patches\wow-update-enGB-16650.MPQ 426 683 +patches\wow-update-enGB-16844.MPQ 18 366 460 +patches\wow-update-enGB-16965.MPQ 305 202 +patches\wow-update-oldworld-13154.MPQ 54 068 663 +patches\wow-update-oldworld-13286.MPQ 2 328 773 + +AddFile.bin 0 // Just an empty file +AddFile.exe 432 640 // An arbitraty binary file +AddFile.wav 311 340 // An arbitrary WAVE file +ListFile_Blizzard.txt 3 904 784 // Listfile for Blizzard games (pre-WoW) +ListFile_WarOfTheImmortals.txt 3 904 858 // Listfile for War of the Immortals game +MPQ_1997_v1_Diablo1_DIABDAT.MPQ 517 501 282 // Originally DIABDAT.MPQ from Diablo I +MPQ_1997_v1_Diablo1_DIABDAT.sha 206 +MPQ_1997_v1_Diablo1_single_0.sha 201 // Single player savegame from Diablo I +MPQ_1997_v1_Diablo1_single_0.sv 98 980 +MPQ_1999_v1_WeakSignature.exe 1 031 826 // War2Patch_202.exe from Warcraft II Bnet Edition +MPQ_1999_v1_WeakSignature.sha 260 +MPQ_2002_v1_BlockTableCut.MPQ 27 765 301 // Cut file War3Patch.mpq from Warcraft III +MPQ_2002_v1_BlockTableCut.sha 250 +MPQ_2002_v1_ProtectedMap_HashTable_FakeValid.sha 1 067 +MPQ_2002_v1_ProtectedMap_HashTable_FakeValid.w3x 1 089 638 // Protected Warcraft III map +MPQ_2002_v1_ProtectedMap_InvalidMpqFormat.sha 507 +MPQ_2002_v1_ProtectedMap_InvalidMpqFormat.w3x 2 429 195 // Protected Warcraft III map +MPQ_2002_v1_ProtectedMap_InvalidUserData.sha 293 +MPQ_2002_v1_ProtectedMap_InvalidUserData.w3x 596 486 // Protected Warcraft III map +MPQ_2002_v1_StrongSignature.sha 250 +MPQ_2002_v1_StrongSignature.w3m 306 818 // (10)DustwallowKeys.w3m from Warcraft III +MPQ_2009_v2_WoW_patch.MPQ.part 31 396 380 // patch.MPQ.part from trial WoW build 10958 +MPQ_2009_v2_WoW_patch.MPQ.sha 226 +MPQ_2010_v2_HasUserData.s2ma 1 972 177 // (4) - AI - Kulas Ravine (1x).s2ma from Starcraft II Beta +MPQ_2010_v2_HasUserData.sha 261 +MPQ_2010_v3_expansion-locale-frFR.MPQ 2 980 489 // expansion-locale-frFR.MPQ from WoW 12911 +MPQ_2010_v3_expansion-locale-frFR.sha 274 +MPQ_2011_v2_EncryptedMpq.MPQE 41 631 764 // Installer UI 2 esES.MPQE from Starcraft II Installer (build 15404) +MPQ_2011_v2_EncryptedMpq.sha 255 +MPQ_2011_v4_InvalidHetEntryCount.MPQ 206 164 // An invalid MPQ created by a previous Stormlib version +MPQ_2011_v4_InvalidHetEntryCount.sha 312 +MPQ_2012_v2_EmptyMpq.MPQ 44 // Empty MPQ (Cache from WoW 11723) +MPQ_2012_v2_EmptyMpq.sha 212 +MPQ_2012_v4_OldWorld.MPQ 1 854 547 587 // OldWorld.MPQ from WoW 12911 +MPQ_2012_v4_OldWorld.sha 270 +MPQ_2013_v4_EmptyMpq.MPQ 208 // Empty MPQ created by StormLib +MPQ_2013_v4_EmptyMpq.sha 183 +MPQ_2013_v4_expansion1.MPQ 1 426 926 736 // expansion1.MPQ from WoW build 17538 +MPQ_2013_v4_expansion1.sha 221 +MPQ_2013_v4_locale-enGB.MPQ 446 491 866 // locale-enGB.MPQ from WoW build 16965 +MPQ_2013_v4_locale-enGB.sha 273 +MPQ_2013_v4_patch-base-16357.MPQ 249 // patch-base-16357.MPQ from WoW build 17538 +MPQ_2013_v4_patch-base-16357.sha 229 +MPQ_2013_v4_SC2_EmptyMap.SC2Map 25 058 // Custom Starcraft II Map +MPQ_2013_v4_SC2_EmptyMap.sha 243 +MPQ_2013_v4_world.MPQ 2 617 175 835 // world.MPQ from WoW build 12911 +MPQ_2013_v4_world.sha 252 +MPx_2013_v1_LongwuOnline.mpk 2 146 549 // Scp.mpk from Longwu Online +MPx_2013_v1_LongwuOnline.sha 277 +MPx_2013_v1_WarOfTheImmortals.sha 248 +MPx_2013_v1_WarOfTheImmortals.sqp 56 775 675 // Modified Other.sqp from War of the Immortals diff --git a/test/TLogHelper.cpp b/test/TLogHelper.cpp new file mode 100644 index 0000000..47a4909 --- /dev/null +++ b/test/TLogHelper.cpp @@ -0,0 +1,278 @@ +/*****************************************************************************/ +/* TLogHelper.cpp Copyright (c) Ladislav Zezula 2013 */ +/*---------------------------------------------------------------------------*/ +/* Helper class for reporting StormLib tests */ +/* This file should be included directly from Test.cpp using #include */ +/*---------------------------------------------------------------------------*/ +/* Date Ver Who Comment */ +/* -------- ---- --- ------- */ +/* 26.11.13 1.00 Lad The first version of TLogHelper.cpp */ +/*****************************************************************************/ + +//----------------------------------------------------------------------------- +// Definition of the TLogHelper class + +class TLogHelper +{ + public: + + TLogHelper(const char * szTestName); + ~TLogHelper(); + +#if defined(UNICODE) || defined(UNICODE) + // TCHAR-based functions. They are only needed on UNICODE builds. + // On ANSI builds is TCHAR = char, so we don't need them at all + int PrintWithClreol(const TCHAR * szFormat, va_list argList, bool bPrintPrefix, bool bPrintLastError, bool bPrintEndOfLine); + int PrintErrorVa(const TCHAR * szFormat, ...); + int PrintError(const TCHAR * szFormat, const TCHAR * szFileName = NULL); +#endif // defined(UNICODE) || defined(UNICODE) + + // ANSI functions + int PrintWithClreol(const char * szFormat, va_list argList, bool bPrintPrefix, bool bPrintLastError, bool bPrintEndOfLine); + void PrintProgress(const char * szFormat, ...); + void PrintMessage(const char * szFormat, ...); + int PrintErrorVa(const char * szFormat, ...); + int PrintError(const char * szFormat, const char * szFileName = NULL); + + protected: + + int GetConsoleWidth(); + + const char * szTestName; // Title of the text + size_t nTextLength; // Length of the previous progress message + bool bMessagePrinted; +}; + +//----------------------------------------------------------------------------- +// Constructor and destructor + +TLogHelper::TLogHelper(const char * szName) +{ + // Fill the test line structure + szTestName = szName; + nTextLength = 0; + bMessagePrinted = false; + + // Show the user that a test is running + PrintProgress("Running test \"%s\" ...", szTestName); +} + +TLogHelper::~TLogHelper() +{ + // If no message has been printed, show "OK" + if(bMessagePrinted == false) + PrintMessage("Running test \"%s\" ... OK", szTestName); +} + +//----------------------------------------------------------------------------- +// TCHAR-based functions. They are only needed on UNICODE builds. +// On ANSI builds is TCHAR = char, so we don't need them at all + +#if defined(UNICODE) || defined(UNICODE) +int TLogHelper::PrintWithClreol(const TCHAR * szFormat, va_list argList, bool bPrintPrefix, bool bPrintLastError, bool bPrintEndOfLine) +{ + TCHAR szOneLineBuff[0x200]; + TCHAR * szSaveBuffer; + TCHAR * szBuffer = szOneLineBuff; + int nRemainingWidth; + int nConsoleWidth = GetConsoleWidth(); + int nLength = 0; + int nError = GetLastError(); + + // Always start the buffer with '\r' + *szBuffer++ = '\r'; + szSaveBuffer = szBuffer; + + // Print the prefix, if needed + if(szTestName != NULL && bPrintPrefix) + { + while(szTestName[nLength] != 0) + *szBuffer++ = szTestName[nLength++]; + + *szBuffer++ = ':'; + *szBuffer++ = ' '; + } + + // Format the message itself + if(szFormat != NULL) + { + nLength = _vstprintf(szBuffer, szFormat, argList); + szBuffer += nLength; + } + + // Print the last error, if needed + if(bPrintLastError) + { + nLength = _stprintf(szBuffer, _T(" (error code: %u)"), nError); + szBuffer += nLength; + } + + // Shall we pad the string? + if((szBuffer - szSaveBuffer) < nConsoleWidth) + { + // Calculate the remaining width + nRemainingWidth = GetConsoleWidth() - (int)(szBuffer - szSaveBuffer) - 1; + + // Pad the string with spaces to fill it up to the end of the line + for(int i = 0; i < nRemainingWidth; i++) + *szBuffer++ = 0x20; + + // Pad the buffer with backslashes to fill it up to the end of the line + for(int i = 0; i < nRemainingWidth; i++) + *szBuffer++ = 0x08; + } + + // Put the newline, if requested + *szBuffer++ = bPrintEndOfLine ? '\n' : 0; + *szBuffer = 0; + + // Remember if we printed a message + if(bPrintEndOfLine) + bMessagePrinted = true; + + // Spit out the text in one single printf + _tprintf(szOneLineBuff); + return nError; +} + +int TLogHelper::PrintErrorVa(const TCHAR * szFormat, ...) +{ + va_list argList; + int nResult; + + va_start(argList, szFormat); + nResult = PrintWithClreol(szFormat, argList, true, true, true); + va_end(argList); + + return nResult; +} + +int TLogHelper::PrintError(const TCHAR * szFormat, const TCHAR * szFileName) +{ + return PrintErrorVa(szFormat, szFileName); +} +#endif // defined(UNICODE) || defined(UNICODE) + +//----------------------------------------------------------------------------- +// ANSI functions + +int TLogHelper::PrintWithClreol(const char * szFormat, va_list argList, bool bPrintPrefix, bool bPrintLastError, bool bPrintEndOfLine) +{ + char szOneLineBuff[0x200]; + char * szSaveBuffer; + char * szBuffer = szOneLineBuff; + int nRemainingWidth; + int nConsoleWidth = GetConsoleWidth(); + int nLength = 0; + int nError = GetLastError(); + + // Always start the buffer with '\r' + *szBuffer++ = '\r'; + szSaveBuffer = szBuffer; + + // Print the prefix, if needed + if(szTestName != NULL && bPrintPrefix) + { + while(szTestName[nLength] != 0) + *szBuffer++ = szTestName[nLength++]; + + *szBuffer++ = ':'; + *szBuffer++ = ' '; + } + + // Format the message itself + if(szFormat != NULL) + { + nLength = vsprintf(szBuffer, szFormat, argList); + szBuffer += nLength; + } + + // Print the last error, if needed + if(bPrintLastError) + { + nLength = sprintf(szBuffer, " (error code: %u)", nError); + szBuffer += nLength; + } + + // Shall we pad the string? + if((szBuffer - szSaveBuffer) < nConsoleWidth) + { + // Calculate the remaining width + nRemainingWidth = GetConsoleWidth() - (int)(szBuffer - szSaveBuffer) - 1; + + // Pad the string with spaces to fill it up to the end of the line + for(int i = 0; i < nRemainingWidth; i++) + *szBuffer++ = 0x20; + + // Pad the buffer with backslashes to fill it up to the end of the line + for(int i = 0; i < nRemainingWidth; i++) + *szBuffer++ = 0x08; + } + + // Put the newline, if requested + *szBuffer++ = bPrintEndOfLine ? '\n' : 0; + *szBuffer = 0; + + // Remember if we printed a message + if(bPrintEndOfLine) + bMessagePrinted = true; + + // Spit out the text in one single printf + printf(szOneLineBuff); + return nError; +} + +void TLogHelper::PrintProgress(const char * szFormat, ...) +{ + va_list argList; + + va_start(argList, szFormat); + PrintWithClreol(szFormat, argList, true, false, false); + va_end(argList); +} + +void TLogHelper::PrintMessage(const char * szFormat, ...) +{ + va_list argList; + + va_start(argList, szFormat); + PrintWithClreol(szFormat, argList, true, false, true); + va_end(argList); +} + +int TLogHelper::PrintErrorVa(const char * szFormat, ...) +{ + va_list argList; + int nResult; + + va_start(argList, szFormat); + nResult = PrintWithClreol(szFormat, argList, true, true, true); + va_end(argList); + + return nResult; +} + +int TLogHelper::PrintError(const char * szFormat, const char * szFileName) +{ + return PrintErrorVa(szFormat, szFileName); +} + +//----------------------------------------------------------------------------- +// Protected functions + +int TLogHelper::GetConsoleWidth() +{ +#ifdef PLATFORM_WINDOWS + + CONSOLE_SCREEN_BUFFER_INFO ScreenInfo; + GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &ScreenInfo); + return (int)(ScreenInfo.srWindow.Right - ScreenInfo.srWindow.Left); + +#else + + // On non-Windows platforms, we assume that width of the console line + // is 80 characters + return 80; + +#endif +} |