Translated gcrypt wrapper tests to catch2
This commit is contained in:
parent
7fe9dcc6dc
commit
13a7abd82d
@ -29,6 +29,13 @@ target_include_directories(test PRIVATE
|
|||||||
include
|
include
|
||||||
)
|
)
|
||||||
|
|
||||||
|
## Move test images to build dir
|
||||||
|
ADD_CUSTOM_COMMAND(
|
||||||
|
TARGET ${PROJECT_NAME} POST_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||||
|
${CMAKE_SOURCE_DIR}/test/testAssets/ $<TARGET_FILE_DIR:${PROJECT_NAME}>/testAssets/
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
##############
|
##############
|
||||||
# Executable #
|
# Executable #
|
||||||
|
@ -26,51 +26,12 @@ TEST_CASE(__FILE__"/Encrypting and decrypting strings works", "[Wrapper]") {
|
|||||||
REQUIRE(plaintext == decrypted);
|
REQUIRE(plaintext == decrypted);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
namespace SimpleTests
|
|
||||||
{
|
|
||||||
TEST_CLASS(GCWrapper)
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
// Tests that encrypting and decrypting strings using the wrapper works.
|
|
||||||
// This test will start from scratch after encryption, to ensure EVERYTHING has to be re-calculated.
|
|
||||||
TEST_METHOD(String)
|
|
||||||
{
|
|
||||||
// Setup
|
|
||||||
const std::string plaintext = "Hello, World!";
|
|
||||||
const std::string password = "Der Affe will Zucker";
|
|
||||||
|
|
||||||
std::string ciphertext;
|
|
||||||
std::string decrypted;
|
|
||||||
|
|
||||||
// Encryption
|
|
||||||
{
|
|
||||||
ciphertext = GhettoCryptWrapper::EncryptString(plaintext, password);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decryption
|
|
||||||
{
|
|
||||||
decrypted = GhettoCryptWrapper::DecryptString(ciphertext, password);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assertion
|
|
||||||
Assert::AreEqual(
|
|
||||||
plaintext,
|
|
||||||
decrypted
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Tests that encrypting and decrypting files using the wrapper works.
|
// Tests that encrypting and decrypting files using the wrapper works.
|
||||||
// This test will start from scratch after encryption, to ensure EVERYTHING has to be re-calculated.
|
// This test will start from scratch after encryption, to ensure EVERYTHING has to be re-calculated.
|
||||||
TEST_METHOD(File)
|
TEST_CASE(__FILE__"/Encrypting and decrypting files works", "[Wrapper]") {
|
||||||
{
|
|
||||||
// Setup
|
// Setup
|
||||||
#if defined _WIN64
|
const std::string testfile_dir = "testAssets/";
|
||||||
const std::string testfile_dir = "../../SimpleTests/";
|
|
||||||
#elif defined _WIN32
|
|
||||||
const std::string testfile_dir = "../SimpleTests/";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const std::string filename_plain = testfile_dir + "testfile.png";
|
const std::string filename_plain = testfile_dir + "testfile.png";
|
||||||
const std::string filename_encrypted = testfile_dir + "testfile.png.crypt";
|
const std::string filename_encrypted = testfile_dir + "testfile.png.crypt";
|
||||||
@ -79,25 +40,19 @@ namespace SimpleTests
|
|||||||
|
|
||||||
|
|
||||||
// Encryption
|
// Encryption
|
||||||
{
|
|
||||||
GhettoCryptWrapper::EncryptFile(filename_plain, filename_encrypted, password);
|
GhettoCryptWrapper::EncryptFile(filename_plain, filename_encrypted, password);
|
||||||
}
|
|
||||||
|
|
||||||
// Decryption
|
// Decryption
|
||||||
{
|
|
||||||
GhettoCryptWrapper::DecryptFile(filename_encrypted, filename_decrypted, password);
|
GhettoCryptWrapper::DecryptFile(filename_encrypted, filename_decrypted, password);
|
||||||
}
|
|
||||||
|
|
||||||
// Read in both the base, and the decrypted file
|
// Read in both the base, and the decrypted file
|
||||||
const Flexblock plainfile = ReadFileToBits(filename_plain);
|
const Flexblock plainfile = ReadFileToBits(filename_plain);
|
||||||
const Flexblock decryptfile = ReadFileToBits(filename_decrypted);
|
const Flexblock decryptfile = ReadFileToBits(filename_decrypted);
|
||||||
|
|
||||||
// Assertion (If this fails, maybe check if the image is even readable by an image viewer)
|
// Assertion (If this fails, maybe check if the image is even readable by an image viewer)
|
||||||
Assert::AreEqual(
|
REQUIRE(
|
||||||
PadStringToLength(plainfile, decryptfile.length(), '0', false),
|
PadStringToLength(plainfile, decryptfile.length(), '0', false) ==
|
||||||
decryptfile
|
decryptfile
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
Before Width: | Height: | Size: 9.5 KiB After Width: | Height: | Size: 9.5 KiB |
Loading…
x
Reference in New Issue
Block a user