diff options
author | Ladislav Zezula <ladislav.zezula@avg.com> | 2014-12-02 09:38:34 +0100 |
---|---|---|
committer | Ladislav Zezula <ladislav.zezula@avg.com> | 2014-12-02 09:38:34 +0100 |
commit | 3e594190e4a89252755907a313914a96b6abb1c8 (patch) | |
tree | dcfd8cb1b143d8728a627b92f0fa71472f3b88ef /test | |
parent | 495b2ab3d42db3f0d484e76eba15c7da9148d53a (diff) |
+ Files with zero size are now processed properly during archive compacting
+ Fixed few memory leaks
Diffstat (limited to 'test')
-rw-r--r-- | test/StormTest.cpp | 56 | ||||
-rw-r--r-- | test/TLogHelper.cpp | 38 |
2 files changed, 63 insertions, 31 deletions
diff --git a/test/StormTest.cpp b/test/StormTest.cpp index a489ecc..c6ae959 100644 --- a/test/StormTest.cpp +++ b/test/StormTest.cpp @@ -2466,7 +2466,7 @@ static int TestOpenArchive_ReadOnly(const char * szPlainName, bool bReadOnly) static int TestOpenArchive_GetFileInfo(const char * szPlainName1, const char * szPlainName4) { - TLogHelper Logger("GetFileInfoTest"); + TLogHelper Logger("GetFileInfoTest", szPlainName1, szPlainName4); HANDLE hFile; HANDLE hMpq4; HANDLE hMpq1; @@ -3342,7 +3342,7 @@ static int TestCreateArchive_IncMaxFileCount(const char * szPlainName) nError = AddFileToMpq(&Logger, hMpq, szFileName, szFileData); if(nError != ERROR_SUCCESS) { - // Increment the ma file count by one + // Increment the max file count by one dwMaxFileCount = SFileGetMaxFileCount(hMpq) + 1; Logger.PrintProgress("Increasing max file count to %u ...", dwMaxFileCount); SFileSetMaxFileCount(hMpq, dwMaxFileCount); @@ -3755,18 +3755,17 @@ static int TestCreateArchive_BigArchive(const char * szPlainName) } // "MPQ_2014_v4_Heroes_Replay.MPQ", "AddFile-replay.message.events" -static int TestModifyArchive_ReplaceFile(const char * szPlainName, const char * szFileName) +static int TestModifyArchive_ReplaceFile(const char * szMpqPlainName, const char * szFileName) { TLogHelper Logger("ModifyTest"); HANDLE hMpq = NULL; - HANDLE hFile = NULL; const char * szArchivedName; char szLocalFileName[MAX_PATH]; size_t nOffset = 0; int nError; // Open an existing archive - nError = OpenExistingArchiveWithCopy(&Logger, szPlainName, szPlainName, &hMpq); + nError = OpenExistingArchiveWithCopy(&Logger, szMpqPlainName, szMpqPlainName, &hMpq); // Add the given file if(nError == ERROR_SUCCESS) @@ -3776,10 +3775,6 @@ static int TestModifyArchive_ReplaceFile(const char * szPlainName, const char * nOffset = 8; szArchivedName = szFileName + nOffset; - // Just for test - try to open the file in the archive - if(SFileOpenFileEx(hMpq, szArchivedName, 0, &hFile)) - SFileCloseFile(hFile); - // Create the local file name CreateFullPathName(szLocalFileName, szMpqSubDir, szFileName); @@ -3792,9 +3787,29 @@ static int TestModifyArchive_ReplaceFile(const char * szPlainName, const char * true); } - // Close the MPQ - if(hMpq != NULL) + // Reopen the MPQ and compact it + if(nError == ERROR_SUCCESS) + { + // Compact the archive + Logger.PrintProgress("Compacting archive %s ...", szMpqPlainName); + if(!SFileSetCompactCallback(hMpq, CompactCallback, &Logger)) + nError = Logger.PrintError("Failed to compact archive %s", szMpqPlainName); + + if(!SFileCompactArchive(hMpq, NULL, 0)) + nError = GetLastError(); + SFileCloseArchive(hMpq); + } + + // Try to open the archive again + if(nError == ERROR_SUCCESS) + { + CreateFullPathName(szLocalFileName, NULL, szMpqPlainName); + nError = OpenExistingArchive(&Logger, szLocalFileName, 0, &hMpq); + if(nError == ERROR_SUCCESS) + SFileCloseArchive(hMpq); + } + return nError; } @@ -3881,9 +3896,9 @@ int main(int argc, char * argv[]) // nError = FindFilePairs(ForEachFile_CreateArchiveLink, "2004 - WoW\\06080", "2004 - WoW\\06299"); // Search all testing archives and verify their SHA1 hash -// if(nError == ERROR_SUCCESS) -// nError = FindFiles(ForEachFile_VerifyFileChecksum, szMpqSubDir); -/* + if(nError == ERROR_SUCCESS) + nError = FindFiles(ForEachFile_VerifyFileChecksum, szMpqSubDir); + // Test reading linear file without bitmap if(nError == ERROR_SUCCESS) nError = TestFileStreamOperations("MPQ_2013_v4_alternate-original.MPQ", 0); @@ -4109,11 +4124,10 @@ int main(int argc, char * argv[]) if(nError == ERROR_SUCCESS) nError = TestAddFile_ListFileTest("MPQ_2013_v4_SC2_EmptyMap.SC2Map", true, true); - // Test archive compacting // Create an empty archive v2 if(nError == ERROR_SUCCESS) nError = TestCreateArchive_EmptyMpq("StormLibTest_EmptyMpq_v2.mpq", MPQ_CREATE_ARCHIVE_V2 | MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES); - + // Create an empty archive v4 if(nError == ERROR_SUCCESS) nError = TestCreateArchive_EmptyMpq("StormLibTest_EmptyMpq_v4.mpq", MPQ_CREATE_ARCHIVE_V4 | MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES); @@ -4188,10 +4202,14 @@ int main(int argc, char * argv[]) // Open a MPQ (add custom user data to it) if(nError == ERROR_SUCCESS) nError = TestCreateArchive_BigArchive("StormLibTest_BigArchive_v4.mpq"); -*/ - // Test modifying a replay file from Heroes of the Storm + + // Test replacing a file with zero size file if(nError == ERROR_SUCCESS) - nError = TestModifyArchive_ReplaceFile("MPQ_2014_v4_Heroes_Replay.MPQ", "AddFile-replay.message.events"); + nError = TestModifyArchive_ReplaceFile("MPQ_2014_v4_Base.StormReplay", "AddFile-replay.message.events"); + +#ifdef _MSC_VER + _CrtDumpMemoryLeaks(); +#endif // _MSC_VER return nError; } diff --git a/test/TLogHelper.cpp b/test/TLogHelper.cpp index fb8505d..511bcc9 100644 --- a/test/TLogHelper.cpp +++ b/test/TLogHelper.cpp @@ -16,7 +16,7 @@ class TLogHelper { public: - TLogHelper(const char * szNewMainTitle = NULL, const char * szNewSubTitle = NULL); + TLogHelper(const char * szNewMainTitle = NULL, const char * szNewSubTitle1 = NULL, const char * szNewSubTitle2 = NULL); ~TLogHelper(); #if defined(UNICODE) || defined(UNICODE) @@ -49,7 +49,8 @@ class TLogHelper int GetConsoleWidth(); const char * szMainTitle; // Title of the text (usually name) - const char * szSubTitle; // Title of the text (can be name of the tested file) + const char * szSubTitle1; // Title of the text (can be name of the tested file) + const char * szSubTitle2; // Title of the text (can be name of the tested file) size_t nTextLength; // Length of the previous progress message bool bMessagePrinted; }; @@ -71,16 +72,18 @@ class TLogHelper //----------------------------------------------------------------------------- // Constructor and destructor + -TLogHelper::TLogHelper(const char * szNewTestTitle, const char * szNewSubTitle) +TLogHelper::TLogHelper(const char * szNewMainTitle, const char * szNewSubTitle1, const char * szNewSubTitle2) { UserString = ""; UserCount = 1; UserTotal = 1; // Fill the test line structure - szMainTitle = szNewTestTitle; - szSubTitle = szNewSubTitle; + szMainTitle = szNewMainTitle; + szSubTitle1 = szNewSubTitle1; + szSubTitle2 = szNewSubTitle2; nTextLength = 0; bMessagePrinted = false; bDontPrintResult = false; @@ -88,8 +91,10 @@ TLogHelper::TLogHelper(const char * szNewTestTitle, const char * szNewSubTitle) // Print the initial information if(szMainTitle != NULL) { - if(szSubTitle != NULL) - printf("Running %s (%s) ...", szMainTitle, szSubTitle); + if(szSubTitle1 != NULL && szSubTitle2 != NULL) + printf("Running %s (%s+%s) ...", szMainTitle, szSubTitle1, szSubTitle2); + else if(szSubTitle1 != NULL) + printf("Running %s (%s) ...", szMainTitle, szSubTitle1); else printf("Running %s ...", szMainTitle); } @@ -98,19 +103,21 @@ TLogHelper::TLogHelper(const char * szNewTestTitle, const char * szNewSubTitle) TLogHelper::~TLogHelper() { const char * szSaveMainTitle = szMainTitle; - const char * szSaveSubTitle = szSubTitle; + const char * szSaveSubTitle1 = szSubTitle1; + const char * szSaveSubTitle2 = szSubTitle2; // Set both to NULL so the won't be printed - szMainTitle = NULL; - szSubTitle = NULL; + szMainTitle = szSubTitle1 = szSubTitle2 = NULL; // Print the final information if(szSaveMainTitle != NULL && bMessagePrinted == false) { if(bDontPrintResult == false) { - if(szSaveSubTitle != NULL) - PrintMessage("%s (%s) succeeded.", szSaveMainTitle, szSaveSubTitle); + if(szSaveSubTitle1 != NULL && szSaveSubTitle2 != NULL) + PrintMessage("%s (%s+%s) succeeded.", szSaveMainTitle, szSaveSubTitle1, szSaveSubTitle2); + else if(szSaveSubTitle1 != NULL) + PrintMessage("%s (%s) succeeded.", szSaveMainTitle, szSaveSubTitle1); else PrintMessage("%s succeeded.", szSaveMainTitle); } @@ -120,6 +127,13 @@ TLogHelper::~TLogHelper() printf("\r"); } } + +#ifdef _MSC_VER + if(_CrtDumpMemoryLeaks()) + { + PrintMessage("Memory leak detected after %s\n.", szSaveMainTitle); + } +#endif // _MSC_VER } //----------------------------------------------------------------------------- |