summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/TLogHelper.cpp107
-rw-r--r--test/Test.cpp51
2 files changed, 120 insertions, 38 deletions
diff --git a/test/TLogHelper.cpp b/test/TLogHelper.cpp
index bd1bd56..127ce77 100644
--- a/test/TLogHelper.cpp
+++ b/test/TLogHelper.cpp
@@ -41,6 +41,10 @@ class TLogHelper
protected:
+#if defined(UNICODE) || defined(UNICODE)
+ TCHAR * CopyFormatCharacter(TCHAR * szBuffer, const TCHAR *& szFormat);
+#endif
+ char * CopyFormatCharacter(char * szBuffer, const char *& szFormat);
int GetConsoleWidth();
const char * szMainTitle; // Title of the text (usually name)
@@ -50,6 +54,17 @@ class TLogHelper
};
//-----------------------------------------------------------------------------
+// String replacements for format strings
+
+#ifdef _MSC_VER
+#define I64u_t _T("%I64u");
+#define I64u_a "%I64u";
+#else
+#define I64u_t "%llu";
+#define I64u_a "%llu";
+#endif
+
+//-----------------------------------------------------------------------------
// Constructor and destructor
TLogHelper::TLogHelper(const char * szNewTestTitle, const char * szNewSubTitle)
@@ -124,21 +139,8 @@ int TLogHelper::PrintWithClreol(const TCHAR * szFormat, va_list argList, bool bP
// Copy the message format itself. Replace %s with "%s", unless it's (%s)
if(szFormat != NULL)
{
- while(szFormat[0] != 0)
- {
- if(szFormat[0] == '%' && szFormat[1] == 's' && szFormat[2] != ')')
- {
- *szBuffer++ = '\"';
- *szBuffer++ = '%';
- *szBuffer++ = 's';
- *szBuffer++ = '\"';
- szFormat += 2;
- }
- else
- {
- *szBuffer++ = *szFormat++;
- }
- }
+ szBuffer = CopyFormatCharacter(szBuffer, szFormat);
+ szFormat += nLength;
}
// Append the last error
@@ -235,18 +237,7 @@ int TLogHelper::PrintWithClreol(const char * szFormat, va_list argList, bool bPr
{
while(szFormat[0] != 0)
{
- if(szFormat[0] == '%' && szFormat[1] == 's' && szFormat[2] != ')')
- {
- *szBuffer++ = '\"';
- *szBuffer++ = '%';
- *szBuffer++ = 's';
- *szBuffer++ = '\"';
- szFormat += 2;
- }
- else
- {
- *szBuffer++ = *szFormat++;
- }
+ szBuffer = CopyFormatCharacter(szBuffer, szFormat);
}
}
@@ -324,6 +315,66 @@ int TLogHelper::PrintError(const char * szFormat, const char * szFileName)
//-----------------------------------------------------------------------------
// Protected functions
+#ifdef _UNICODE
+TCHAR * TLogHelper::CopyFormatCharacter(TCHAR * szBuffer, const TCHAR *& szFormat)
+{
+ static const TCHAR * szStringFormat = _T("\"%s\"");
+ static const TCHAR * szUint64Format = I64u_t;
+
+ // String format
+ if(szFormat[0] == '%')
+ {
+ if(szFormat[1] == 's' && szFormat[2] != ')')
+ {
+ _tcscpy(szBuffer, szStringFormat);
+ szFormat += 2;
+ return szBuffer + _tcslen(szStringFormat);
+ }
+
+ // Replace %I64u with the proper platform-dependent suffix
+ if(szFormat[1] == 'I' && szFormat[2] == '6' && szFormat[3] == '4' && szFormat[4] == 'u')
+ {
+ _tcscpy(szBuffer, szUint64Format);
+ szFormat += 5;
+ return szBuffer + _tcslen(szUint64Format);
+ }
+ }
+
+ // Copy the character as-is
+ *szBuffer++ = *szFormat++;
+ return szBuffer;
+}
+#endif
+
+char * TLogHelper::CopyFormatCharacter(char * szBuffer, const char *& szFormat)
+{
+ static const char * szStringFormat = "\"%s\"";
+ static const char * szUint64Format = I64u_a;
+
+ // String format
+ if(szFormat[0] == '%')
+ {
+ if(szFormat[1] == 's' && szFormat[2] != ')')
+ {
+ strcpy(szBuffer, szStringFormat);
+ szFormat += 2;
+ return szBuffer + strlen(szStringFormat);
+ }
+
+ // Replace %I64u with the proper platform-dependent suffix
+ if(szFormat[1] == 'I' && szFormat[2] == '6' && szFormat[3] == '4' && szFormat[4] == 'u')
+ {
+ strcpy(szBuffer, szUint64Format);
+ szFormat += 5;
+ return szBuffer + strlen(szUint64Format);
+ }
+ }
+
+ // Copy the character as-is
+ *szBuffer++ = *szFormat++;
+ return szBuffer;
+}
+
int TLogHelper::GetConsoleWidth()
{
#ifdef PLATFORM_WINDOWS
@@ -336,7 +387,7 @@ int TLogHelper::GetConsoleWidth()
// On non-Windows platforms, we assume that width of the console line
// is 80 characters
- return 80;
+ return 120;
#endif
}
diff --git a/test/Test.cpp b/test/Test.cpp
index 41a310b..bb5fc38 100644
--- a/test/Test.cpp
+++ b/test/Test.cpp
@@ -219,7 +219,7 @@ static void CreateFullPathName(TCHAR * szBuffer, const char * szSubDir, const ch
// Append the subdirectory, if any
if(szSubDir != NULL && (nLength = strlen(szSubDir)) != 0)
{
- // No leading or trailing separator must be there
+ // No leading or trailing separators allowed
assert(szSubDir[0] != '/' && szSubDir[0] != '\\');
assert(szSubDir[nLength - 1] != '/' && szSubDir[nLength - 1] != '\\');
@@ -228,6 +228,12 @@ static void CreateFullPathName(TCHAR * szBuffer, const char * szSubDir, const ch
// Copy the subdirectory
mbstowcs(szBuffer, szSubDir, nLength);
+
+ // Fix the path separators
+ for(size_t i = 0; i < nLength; i++)
+ szBuffer[i] = (szBuffer[i] != '\\' && szBuffer[i] != '/') ? szBuffer[i] : PATH_SEPARATOR;
+
+ // Move the buffer pointer
szBuffer += nLength;
}
@@ -241,7 +247,7 @@ static void CreateFullPathName(TCHAR * szBuffer, const char * szSubDir, const ch
// Append file path separator
*szBuffer++ = PATH_SEPARATOR;
- // Copy the subdirectory
+ // Copy the file name
mbstowcs(szBuffer, szFileName, nLength);
szBuffer += nLength;
}
@@ -309,6 +315,12 @@ static void CreateFullPathName(char * szBuffer, const char * szSubDir, const cha
// Copy the subdirectory
memcpy(szBuffer, szSubDir, nLength);
+
+ // Fix the path separators
+ for(size_t i = 0; i < nLength; i++)
+ szBuffer[i] = (szBuffer[i] != '\\' && szBuffer[i] != '/') ? szBuffer[i] : PATH_SEPARATOR;
+
+ // Move the buffer pointer
szBuffer += nLength;
}
@@ -322,7 +334,7 @@ static void CreateFullPathName(char * szBuffer, const char * szSubDir, const cha
// Append file path separator
*szBuffer++ = PATH_SEPARATOR;
- // Copy the subdirectory
+ // Copy file name
memcpy(szBuffer, szFileName, nLength);
szBuffer += nLength;
}
@@ -1045,7 +1057,7 @@ static int OpenExistingArchive(TLogHelper * pLogger, const char * szFileName, co
TCHAR szMpqName[MAX_PATH];
HANDLE hMpq = NULL;
DWORD dwFlags = 0;
- int nError;
+ int nError = ERROR_SUCCESS;
// We expect MPQ directory to be already prepared by InitializeMpqDirectory
assert(szMpqDirectory[0] != 0);
@@ -1088,7 +1100,7 @@ static int OpenExistingArchive(TLogHelper * pLogger, const char * szFileName, co
SFileCloseArchive(hMpq);
else
*phMpq = hMpq;
- return ERROR_SUCCESS;
+ return nError;
}
static int OpenPatchedArchive(TLogHelper * pLogger, HANDLE * phMpq, const char * PatchList[])
@@ -1126,7 +1138,7 @@ static int OpenPatchedArchive(TLogHelper * pLogger, HANDLE * phMpq, const char *
SFileCloseArchive(hMpq);
else
*phMpq = hMpq;
- return ERROR_SUCCESS;
+ return nError;
}
static int AddFileToMpq(
@@ -1648,6 +1660,7 @@ static int TestOpenArchive_ReadOnly(const char * szPlainName, bool bReadOnly)
static int TestOpenArchive_GetFileInfo(const char * szPlainName1, const char * szPlainName4)
{
TLogHelper Logger("GetFileInfoTest");
+ HANDLE hFile;
HANDLE hMpq4;
HANDLE hMpq1;
DWORD cbLength;
@@ -1660,12 +1673,18 @@ static int TestOpenArchive_GetFileInfo(const char * szPlainName1, const char * s
nError4 = OpenExistingArchive(&Logger, szPlainName4, NULL, &hMpq4);
if(nError1 == ERROR_SUCCESS && nError4 == ERROR_SUCCESS)
{
- // Invalid handle - expected (false, ERROR_INVALID_PARAMETER)
- TestGetFileInfo(&Logger, NULL, SFileMpqBetHeader, NULL, 0, NULL, false, ERROR_INVALID_PARAMETER);
+ // Invalid handle - expected (false, ERROR_INVALID_HANDLE)
+ TestGetFileInfo(&Logger, NULL, SFileMpqBetHeader, NULL, 0, NULL, false, ERROR_INVALID_HANDLE);
+
+ // Valid handle but invalid value of file info class (false, ERROR_INVALID_PARAMETER)
+ TestGetFileInfo(&Logger, NULL, (SFileInfoClass)0xFFF, NULL, 0, NULL, false, ERROR_INVALID_PARAMETER);
+
+ // Valid archive handle but file info class is for file (false, ERROR_INVALID_HANDLE)
+ TestGetFileInfo(&Logger, NULL, SFileInfoNameHash1, NULL, 0, NULL, false, ERROR_INVALID_HANDLE);
// Valid handle and all parameters NULL
// Returns (true, ERROR_SUCCESS), if BET table is present, otherwise (false, ERROR_CAN_NOT_COMPLETE)
- TestGetFileInfo(&Logger, hMpq1, SFileMpqBetHeader, NULL, 0, NULL, false, ERROR_INVALID_PARAMETER);
+ TestGetFileInfo(&Logger, hMpq1, SFileMpqBetHeader, NULL, 0, NULL, false, ERROR_FILE_NOT_FOUND);
TestGetFileInfo(&Logger, hMpq4, SFileMpqBetHeader, NULL, 0, NULL, true, ERROR_SUCCESS);
// Now try to retrieve the required size of the BET table header
@@ -1685,7 +1704,7 @@ static int TestOpenArchive_GetFileInfo(const char * szPlainName1, const char * s
// Try to retrieve strong signature from the MPQ
TestGetFileInfo(&Logger, hMpq1, SFileMpqStrongSignature, NULL, 0, NULL, true, ERROR_SUCCESS);
- TestGetFileInfo(&Logger, hMpq4, SFileMpqStrongSignature, NULL, 0, NULL, false, ERROR_INVALID_PARAMETER);
+ TestGetFileInfo(&Logger, hMpq4, SFileMpqStrongSignature, NULL, 0, NULL, false, ERROR_FILE_NOT_FOUND);
// Strong signature is returned including the signature ID
TestGetFileInfo(&Logger, hMpq1, SFileMpqStrongSignature, NULL, 0, &cbLength, true, ERROR_SUCCESS);
@@ -1694,6 +1713,18 @@ static int TestOpenArchive_GetFileInfo(const char * szPlainName1, const char * s
// Retrieve the signature
TestGetFileInfo(&Logger, hMpq1, SFileMpqStrongSignature, DataBuff, sizeof(DataBuff), &cbLength, true, ERROR_SUCCESS);
assert(memcmp(DataBuff, "NGIS", 4) == 0);
+
+ // Check SFileGetFileInfo on
+ if(SFileOpenFileEx(hMpq4, LISTFILE_NAME, 0, &hFile))
+ {
+ // Valid parameters but the handle should be file handle
+ TestGetFileInfo(&Logger, hMpq4, SFileInfoFileTime, DataBuff, sizeof(DataBuff), &cbLength, false, ERROR_INVALID_HANDLE);
+
+ // Valid parameters
+ TestGetFileInfo(&Logger, hFile, SFileInfoFileTime, DataBuff, sizeof(DataBuff), &cbLength, true, ERROR_SUCCESS);
+
+ SFileCloseFile(hFile);
+ }
}
if(hMpq4 != NULL)