diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/StormTest.cpp | 129 | ||||
-rw-r--r-- | test/TLogHelper.cpp | 81 |
2 files changed, 113 insertions, 97 deletions
diff --git a/test/StormTest.cpp b/test/StormTest.cpp index 123ec43..1f8a334 100644 --- a/test/StormTest.cpp +++ b/test/StormTest.cpp @@ -36,6 +36,7 @@ // Local structures
#define TFLG_COUNT_HASH 0x01000000 // There is file count in the lower 24-bits, then hash
+#define TFLG_WILL_FAIL 0x02000000 // The process is expected to fail
#define TFLG_COUNT_MASK 0x00FFFFFF // Mask for file count
#define TEST_DATA(hash, num) (num | TFLG_COUNT_HASH), hash
@@ -44,8 +45,8 @@ typedef struct _TEST_INFO LPCTSTR szMpqName1;
LPCTSTR szMpqName2;
DWORD dwFlags;
- LPCSTR szFileName1;
- LPCSTR szFileName2;
+ const void * param1;
+ const void * param2;
} TEST_INFO, *PTEST_INFO;
typedef struct _LINE_INFO
@@ -929,23 +930,23 @@ static DWORD GetFilePatchCount(TLogHelper * pLogger, HANDLE hMpq, LPCSTR szFileN return nPatchCount;
}
-static DWORD VerifyFilePatchCount(TLogHelper * pLogger, HANDLE hMpq, LPCSTR szFileName, int nExpectedPatchCount)
+static DWORD VerifyFilePatchCount(TLogHelper * pLogger, HANDLE hMpq, LPCSTR szFileName, DWORD dwExpectedPatchCount)
{
- int nPatchCount = 0;
+ DWORD dwPatchCount = 0;
// Retrieve the patch count
pLogger->PrintProgress(_T("Verifying patch count for %s ..."), szFileName);
- nPatchCount = GetFilePatchCount(pLogger, hMpq, szFileName);
+ dwPatchCount = GetFilePatchCount(pLogger, hMpq, szFileName);
// Check if there are any patches at all
- if(nExpectedPatchCount != 0 && nPatchCount == 0)
+ if(dwExpectedPatchCount != 0 && dwPatchCount == 0)
{
pLogger->PrintMessage("There are no patches for %s", szFileName);
return ERROR_FILE_CORRUPT;
}
// Check if the number of patches fits
- if(nPatchCount != nExpectedPatchCount)
+ if(dwPatchCount != dwExpectedPatchCount)
{
pLogger->PrintMessage("Unexpected number of patches for %s", szFileName);
return ERROR_FILE_CORRUPT;
@@ -2598,7 +2599,7 @@ static DWORD TestArchive( STORM_FREE(FileDataList[0]);
if(hMpq != NULL)
SFileCloseArchive(hMpq);
- return dwErrCode;
+ return Logger.PrintVerdict(dwErrCode);
}
// Open an empty archive (found in WoW cache - it's just a header)
@@ -2643,15 +2644,17 @@ static DWORD TestOpenArchive_Corrupt(LPCTSTR szPlainName) // Opens a patched MPQ archive
-static DWORD TestOpenArchive_Patched(LPCTSTR PatchList[], LPCSTR szPatchedFile, int nExpectedPatchCount, bool bExpectedToFail = false)
+static DWORD TestArchive_Patched(LPCTSTR PatchList[], LPCSTR szPatchedFile, DWORD dwFlags)
{
TLogHelper Logger("OpenPatchedMpqTest", PatchList[0]);
HANDLE hMpq;
HANDLE hFile;
BYTE Buffer[0x100];
+ DWORD dwExpectedPatchCount = (dwFlags & TFLG_COUNT_MASK);
DWORD dwFileCount = 0;
DWORD BytesRead = 0;
DWORD dwErrCode;
+ bool bExpectedToFail = (dwFlags & TFLG_WILL_FAIL) ? true : false;
// Open a patched MPQ archive
dwErrCode = OpenPatchedArchive(&Logger, &hMpq, PatchList);
@@ -2659,7 +2662,7 @@ static DWORD TestOpenArchive_Patched(LPCTSTR PatchList[], LPCSTR szPatchedFile, {
// Check patch count
if(szPatchedFile != NULL)
- dwErrCode = VerifyFilePatchCount(&Logger, hMpq, szPatchedFile, nExpectedPatchCount);
+ dwErrCode = VerifyFilePatchCount(&Logger, hMpq, szPatchedFile, dwExpectedPatchCount);
// Try to open and read the file
if(dwErrCode == ERROR_SUCCESS)
@@ -4280,6 +4283,21 @@ static const TEST_INFO Test_Mpqs[] = {_T("MPQ_2021_v1_CantExtractCHK.scx"), NULL, TEST_DATA("c9a7ded9f93d883b9419a52bec6087f7", 28)},
};
+static const TEST_INFO Patched_Mpqs[] =
+{
+ {NULL, NULL, 0, PatchList_StarCraft, "music\\terran1.wav"},
+ {NULL, NULL, 2, PatchList_WoW_OldWorld13286, "OldWorld\\World\\Model.blob"},
+ {NULL, NULL, 8, PatchList_WoW_15050, "World\\Model.blob"},
+ {NULL, NULL, 0, PatchList_WoW_16965, "DBFilesClient\\BattlePetNPCTeamMember.db2"},
+ {NULL, NULL, 6, PatchList_SC2_32283, "TriggerLibs\\natives.galaxy"},
+ {NULL, NULL, 2, PatchList_SC2_34644, "TriggerLibs\\GameData\\GameData.galaxy"},
+ {NULL, NULL, 3, PatchList_SC2_34644_Maps, "Maps\\Campaign\\THorner03.SC2Map\\BankList.xml"},
+ {NULL, NULL, TFLG_WILL_FAIL, PatchList_SC2_32283_enGB, "Assets\\Textures\\startupimage.dds"},
+ {NULL, NULL, 6, PatchList_SC2_36281_enGB, "LocalizedData\\GameHotkeys.txt"},
+ {NULL, NULL, 1, PatchList_HS_3604_enGB, "Hearthstone.exe"},
+ {NULL, NULL, 10, PatchList_HS_6898_enGB, "Hearthstone_Data\\Managed\\Assembly-Csharp.dll"}
+};
+
//-----------------------------------------------------------------------------
// Main
@@ -4298,21 +4316,21 @@ int _tmain(int argc, TCHAR * argv[]) //
// Tests on a local listfile
//
- /*
+
if(dwErrCode == ERROR_SUCCESS)
{
TestOnLocalListFile(_T("FLAT-MAP:ListFile_Blizzard.txt"));
dwErrCode = TestOnLocalListFile(_T("ListFile_Blizzard.txt"));
}
- */
+
//
// Open all files from the command line
//
- //for(int i = 1; i < argc; i++)
- //{
- // TestArchive(_T("MPQ_2021_v1_CantExtractCHK.scx"), _T("Listfile_Blizzard.txt"), TEST_FLAG_FILE_COUNT, NULL, NULL);
- //}
+ for(int i = 1; i < argc; i++)
+ {
+ TestArchive(_T("MPQ_2021_v1_CantExtractCHK.scx"), _T("Listfile_Blizzard.txt"), 0, NULL, NULL);
+ }
//
// Search all testing archives and verify their SHA1 hash
@@ -4361,13 +4379,34 @@ int _tmain(int argc, TCHAR * argv[]) {
for(size_t i = 0; i < _countof(Test_Mpqs); i++)
{
- dwErrCode = TestArchive(Test_Mpqs[i].szMpqName1, // Plain archive name
- Test_Mpqs[i].szMpqName2, // List file (NULL if none)
- Test_Mpqs[i].dwFlags, // What exactly to do
- Test_Mpqs[i].szFileName1, // The first name of the open file
- Test_Mpqs[i].szFileName2); // The second name of the open file
- if(dwErrCode != ERROR_SUCCESS)
- break;
+ dwErrCode = TestArchive(Test_Mpqs[i].szMpqName1, // Plain archive name
+ Test_Mpqs[i].szMpqName2, // List file (NULL if none)
+ Test_Mpqs[i].dwFlags, // What exactly to do
+ (LPCSTR)Test_Mpqs[i].param1, // The 1st parameter
+ (LPCSTR)Test_Mpqs[i].param2); // The 2nd parameter
+// if(dwErrCode != ERROR_SUCCESS)
+// break;
+ dwErrCode = ERROR_SUCCESS;
+ }
+ }
+
+ //
+ // Test opening patched archives - correct, damaged, protected
+ //
+
+ if(dwErrCode == ERROR_SUCCESS)
+ {
+ for(size_t i = 0; i < _countof(Patched_Mpqs); i++)
+ {
+ LPCTSTR * PatchList = (LPCTSTR *)Patched_Mpqs[i].param1;
+ LPCSTR szFileName = (LPCSTR)Patched_Mpqs[i].param2;
+
+ dwErrCode = TestArchive_Patched(PatchList, // List of patches
+ szFileName, // Name of a file
+ Patched_Mpqs[i].dwFlags);
+// if(dwErrCode != ERROR_SUCCESS)
+// break;
+ dwErrCode = ERROR_SUCCESS;
}
}
@@ -4383,50 +4422,6 @@ int _tmain(int argc, TCHAR * argv[]) if(dwErrCode == ERROR_SUCCESS)
dwErrCode = TestOpenArchive_Corrupt(_T("MPQ_2013_vX_Battle.net.MPQ"));
- // Open a patched archive
- if(dwErrCode == ERROR_SUCCESS)
- dwErrCode = TestOpenArchive_Patched(PatchList_StarCraft, "music\\terran1.wav", 0);
-
- // Open a patched archive
- if(dwErrCode == ERROR_SUCCESS)
- dwErrCode = TestOpenArchive_Patched(PatchList_WoW_OldWorld13286, "OldWorld\\World\\Model.blob", 2);
-
- // Open a patched archive
- if(dwErrCode == ERROR_SUCCESS)
- dwErrCode = TestOpenArchive_Patched(PatchList_WoW_15050, "World\\Model.blob", 8);
-
- // Open a patched archive
- if(dwErrCode == ERROR_SUCCESS)
- dwErrCode = TestOpenArchive_Patched(PatchList_WoW_16965, "DBFilesClient\\BattlePetNPCTeamMember.db2", 0);
-
- // Open a patched archive
- if(dwErrCode == ERROR_SUCCESS)
- dwErrCode = TestOpenArchive_Patched(PatchList_SC2_32283, "TriggerLibs\\natives.galaxy", 6);
-
- // Open a patched archive
- if(dwErrCode == ERROR_SUCCESS)
- dwErrCode = TestOpenArchive_Patched(PatchList_SC2_34644, "TriggerLibs\\GameData\\GameData.galaxy", 2);
-
- // Open a patched archive with new format of BSDIFF patch
- if(dwErrCode == ERROR_SUCCESS)
- dwErrCode = TestOpenArchive_Patched(PatchList_SC2_34644_Maps, "Maps\\Campaign\\THorner03.SC2Map\\BankList.xml", 3);
-
- // Open a patched archive
- if(dwErrCode == ERROR_SUCCESS)
- dwErrCode = TestOpenArchive_Patched(PatchList_SC2_32283_enGB, "Assets\\Textures\\startupimage.dds", 0, true);
-
- // Open a patched archive where the "StreamingBuckets.txt" in the patch doesn't contain MPQ_FILE_PATCH_FILE
- if(dwErrCode == ERROR_SUCCESS)
- dwErrCode = TestOpenArchive_Patched(PatchList_SC2_36281_enGB, "LocalizedData\\GameHotkeys.txt", 6);
-
- // Open a patched archive
- if(dwErrCode == ERROR_SUCCESS)
- dwErrCode = TestOpenArchive_Patched(PatchList_HS_3604_enGB, "Hearthstone.exe", 1);
-
- // Open a patched archive
- if(dwErrCode == ERROR_SUCCESS)
- dwErrCode = TestOpenArchive_Patched(PatchList_HS_6898_enGB, "Hearthstone_Data\\Managed\\Assembly-Csharp.dll", 10);
-
// Check the opening archive for read-only
if(dwErrCode == ERROR_SUCCESS)
dwErrCode = TestOpenArchive_ReadOnly(_T("MPQ_1997_v1_Diablo1_DIABDAT.MPQ"), true);
diff --git a/test/TLogHelper.cpp b/test/TLogHelper.cpp index 8a4fc41..7129b63 100644 --- a/test/TLogHelper.cpp +++ b/test/TLogHelper.cpp @@ -36,6 +36,9 @@ class TLogHelper DWORD PrintErrorVa(const char * szFormat, ...);
DWORD PrintError(const char * szFormat, const char * szFileName = NULL);
+ // Print final verdict
+ DWORD PrintVerdict(DWORD dwErrCode = ERROR_SUCCESS);
+
const char * UserString;
unsigned int UserCount;
unsigned int UserTotal;
@@ -108,39 +111,16 @@ TLogHelper::TLogHelper(const char * szNewMainTitle, const TCHAR * szNewSubTitle1 TLogHelper::~TLogHelper()
{
- const TCHAR * szSaveSubTitle1 = szSubTitle1;
- const TCHAR * szSaveSubTitle2 = szSubTitle2;
- TCHAR szSaveMainTitle[0x80];
-
- // Set both to NULL so they won't be printed
- StringCopy(szSaveMainTitle, _countof(szSaveMainTitle), szMainTitle);
- szSubTitle1 = NULL;
- szSubTitle2 = NULL;
- szMainTitle = NULL;
-
- // Print the final information
- if(szSaveMainTitle != NULL && bMessagePrinted == false)
+ // Print a verdict, if no verdict was printed yet
+ if(bMessagePrinted == false)
{
- if(bDontPrintResult == false)
- {
- if(szSaveSubTitle1 != NULL && szSaveSubTitle2 != NULL)
- PrintMessage(_T("%s (%s+%s) succeeded."), szSaveMainTitle, szSaveSubTitle1, szSaveSubTitle2);
- else if(szSaveSubTitle1 != NULL)
- PrintMessage(_T("%s (%s) succeeded."), szSaveMainTitle, szSaveSubTitle1);
- else
- PrintMessage(_T("%s succeeded."), szSaveMainTitle);
- }
- else
- {
- PrintProgress(" ");
- printf("\r");
- }
+ PrintVerdict(ERROR_SUCCESS);
}
#if defined(_MSC_VER) && defined(_DEBUG)
if(_CrtDumpMemoryLeaks())
{
- PrintMessage(_T("Memory leak(s) detected after %s.\n"), szSaveMainTitle);
+ PrintMessage(_T("Memory leak(s) detected after.\n"));
}
#endif // _MSC_VER
}
@@ -361,18 +341,59 @@ DWORD TLogHelper::PrintError(const char * szFormat, const char * szFileName) }
//-----------------------------------------------------------------------------
+// Print final verdict
+
+DWORD TLogHelper::PrintVerdict(DWORD dwErrCode)
+{
+ LPCTSTR szSaveSubTitle1 = szSubTitle1;
+ LPCTSTR szSaveSubTitle2 = szSubTitle2;
+ TCHAR szSaveMainTitle[0x80];
+
+ // Set both to NULL so they won't be printed
+ StringCopy(szSaveMainTitle, _countof(szSaveMainTitle), szMainTitle);
+ szSubTitle1 = NULL;
+ szSubTitle2 = NULL;
+ szMainTitle = NULL;
+
+ // Print the final information
+ if(szSaveMainTitle[0] != 0)
+ {
+ if(bDontPrintResult == false)
+ {
+ LPCTSTR szVerdict = (dwErrCode == ERROR_SUCCESS) ? _T("succeeded") : _T("failed");
+
+ if(szSaveSubTitle1 != NULL && szSaveSubTitle2 != NULL)
+ PrintMessage(_T("%s (%s+%s) %s."), szSaveMainTitle, szSaveSubTitle1, szSaveSubTitle2, szVerdict);
+ else if(szSaveSubTitle1 != NULL)
+ PrintMessage(_T("%s (%s) %s."), szSaveMainTitle, szSaveSubTitle1, szVerdict);
+ else
+ PrintMessage(_T("%s %s."), szSaveMainTitle, szVerdict);
+ }
+ else
+ {
+ PrintProgress(" ");
+ printf("\r");
+ }
+ }
+
+ // Return the error code so the caller can pass it fuhrter
+ return dwErrCode;
+}
+
+//-----------------------------------------------------------------------------
// Protected functions
#ifdef _UNICODE
TCHAR * TLogHelper::CopyFormatCharacter(TCHAR * szBuffer, const TCHAR *& szFormat)
{
- static const TCHAR * szStringFormat = _T("\"%s\"");
- static const TCHAR * szUint64Format = I64u_t;
+// static LPCTSTR szStringFormat = _T("\"%s\"");
+ static LPCTSTR szStringFormat = _T("%s");
+ static LPCTSTR szUint64Format = I64u_t;
// String format
if(szFormat[0] == '%')
{
- if(szFormat[1] == 's' && szFormat[2] != ')')
+ if(szFormat[1] == 's')
{
_tcscpy(szBuffer, szStringFormat);
szFormat += 2;
|