Skip to content

Commit

Permalink
Use MTA temp path for client tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Lpsd committed Oct 14, 2023
1 parent f886a35 commit 370a07f
Showing 1 changed file with 40 additions and 25 deletions.
65 changes: 40 additions & 25 deletions Shared/sdk/SharedUtil.Tests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ void SharedUtil_Collection_Tests();
void SharedUtil_String_Tests();
void SharedUtil_Hash_Tests();

#ifdef MTA_CLIENT
static const SString tempFilepath = SString("%s\\%s", GetMTATempPath().c_str(),
"hash_"
"\xD0"
"\x98"
"_test");
#else
static const char* tempFilepath =
"hash_"
"\xD0"
"\x98"
"_test";
#endif

///////////////////////////////////////////////////////////////
//
// Run tests entry point
Expand All @@ -47,20 +61,21 @@ void SharedUtil_Tests()
//
///////////////////////////////////////////////////////////////
#define TEST_FUNCTION \
struct testStruct { \
void Test(int testIndex) \
{ \
testStruct dataCopy = *this; // Info when debugging
struct testStruct \
{ \
void Test(int testIndex) \
{ \
testStruct dataCopy = *this; // Info when debugging

#define TEST_VARS \
}
#define TEST_VARS }

#define TEST_DATA \
} testData[]
} \
testData[]

#define TEST_END \
for (uint i = 0 ; i < NUMELMS(testData) ; i++) \
testData[i].Test(i);
for (uint i = 0; i < NUMELMS(testData); i++) \
testData[i].Test(i);

///////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -316,7 +331,7 @@ void SharedUtil_File_Tests()
TEST_END
}

#endif // WIN32
#endif // WIN32
}

///////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -946,8 +961,6 @@ void SharedUtil_Hash_Tests()
TEST_END
}

#define szTempFilename "hash_""\xD0""\x98""_test"

// MD5
{
TEST_FUNCTION
Expand All @@ -957,8 +970,10 @@ void SharedUtil_Hash_Tests()
strResult = GenerateHashHexString(EHashFunction::MD5, a);
assert(strResult == result);

FileSave(szTempFilename, a);
strResult = GenerateHashHexStringFromFile(EHashFunction::MD5, szTempFilename);
auto filepath = tempFilepath;
bool save = FileSave(tempFilepath, a);

strResult = GenerateHashHexStringFromFile(EHashFunction::MD5, tempFilepath);
assert(strResult == result);
TEST_VARS
const SString a;
Expand All @@ -977,8 +992,8 @@ void SharedUtil_Hash_Tests()
SString strResult = GenerateSha256HexString(a);
assert(strResult == result);

FileSave(szTempFilename, a);
strResult = GenerateHashHexStringFromFile(EHashFunction::SHA256, szTempFilename);
FileSave(tempFilepath, a);
strResult = GenerateHashHexStringFromFile(EHashFunction::SHA256, tempFilepath);
assert(strResult == result);
TEST_VARS
const SString a;
Expand All @@ -997,8 +1012,8 @@ void SharedUtil_Hash_Tests()
SString strResult = GenerateHashHexString(EHashFunction::SHA1, a);
assert(strResult == result);

FileSave(szTempFilename, a);
strResult = GenerateHashHexStringFromFile(EHashFunction::SHA1, szTempFilename);
FileSave(tempFilepath, a);
strResult = GenerateHashHexStringFromFile(EHashFunction::SHA1, tempFilepath);
assert(strResult == result);
TEST_VARS
const SString a;
Expand All @@ -1017,8 +1032,8 @@ void SharedUtil_Hash_Tests()
SString strResult = GenerateHashHexString(EHashFunction::SHA224, a);
assert(strResult == result);

FileSave(szTempFilename, a);
strResult = GenerateHashHexStringFromFile(EHashFunction::SHA224, szTempFilename);
FileSave(tempFilepath, a);
strResult = GenerateHashHexStringFromFile(EHashFunction::SHA224, tempFilepath);
assert(strResult == result);
TEST_VARS
const SString a;
Expand All @@ -1037,8 +1052,8 @@ void SharedUtil_Hash_Tests()
SString strResult = GenerateHashHexString(EHashFunction::SHA384, a);
assert(strResult == result);

FileSave(szTempFilename, a);
strResult = GenerateHashHexStringFromFile(EHashFunction::SHA384, szTempFilename);
FileSave(tempFilepath, a);
strResult = GenerateHashHexStringFromFile(EHashFunction::SHA384, tempFilepath);
assert(strResult == result);
TEST_VARS
const SString a;
Expand All @@ -1057,8 +1072,8 @@ void SharedUtil_Hash_Tests()
SString strResult = GenerateHashHexString(EHashFunction::SHA512, a);
assert(strResult == result);

FileSave(szTempFilename, a);
strResult = GenerateHashHexStringFromFile(EHashFunction::SHA512, szTempFilename);
FileSave(tempFilepath, a);
strResult = GenerateHashHexStringFromFile(EHashFunction::SHA512, tempFilepath);
assert(strResult == result);
TEST_VARS
const SString a;
Expand All @@ -1071,5 +1086,5 @@ void SharedUtil_Hash_Tests()
TEST_END
}

FileDelete(szTempFilename);
FileDelete(tempFilepath);
}

0 comments on commit 370a07f

Please sign in to comment.