Adjusted tests

This commit is contained in:
Leonetienne
2022-05-22 14:26:23 +02:00
parent 967eba2f03
commit fe6ec11672
3 changed files with 80 additions and 84 deletions

View File

@@ -1,4 +1,4 @@
#include <GCrypt/GCryptWrapper.h>
#include <GCrypt/GWrapper.h>
#include <GCrypt/Flexblock.h>
#include <GCrypt/Util.h>
#include "Catch2.h"
@@ -9,50 +9,50 @@ using namespace Leonetienne::GCrypt;
// This test will start from scratch after encryption, to ensure EVERYTHING has to be re-calculated.
TEST_CASE(__FILE__"/Encrypting and decrypting strings works", "[Wrapper]") {
// Setup
const std::string plaintext = "Hello, World!";
const std::string password = "Der Affe will Zucker";
// Setup
const std::string plaintext = "Hello, World!";
const Key key = Key::FromPassword("Der Affe will Zucker");
std::string ciphertext;
std::string decrypted;
std::string ciphertext;
std::string decrypted;
// Encryption
ciphertext = GCryptWrapper::EncryptString(plaintext, password);
// Encryption
ciphertext = GWrapper::EncryptString(plaintext, key);
// Decryption
decrypted = GCryptWrapper::DecryptString(ciphertext, password);
// Decryption
decrypted = GWrapper::DecryptString(ciphertext, key);
// Assertion
REQUIRE(plaintext == decrypted);
// Assertion
REQUIRE(plaintext == decrypted);
}
// 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.
TEST_CASE(__FILE__"/Encrypting and decrypting files works", "[Wrapper]") {
// Setup
const std::string testfile_dir = "testAssets/";
// Setup
const std::string testfile_dir = "testAssets/";
const std::string filename_plain = testfile_dir + "testfile.png";
const std::string filename_encrypted = testfile_dir + "testfile.png.crypt";
const std::string filename_decrypted = testfile_dir + "testfile.png.clear.png";
const std::string password = "Der Affe will Zucker";
const std::string filename_plain = testfile_dir + "testfile.png";
const std::string filename_encrypted = testfile_dir + "testfile.png.crypt";
const std::string filename_decrypted = testfile_dir + "testfile.png.clear.png";
const Key key = Key::FromPassword("Der Affe will Zucker");
// Encryption
GCryptWrapper::EncryptFile(filename_plain, filename_encrypted, password);
// Encryption
GWrapper::EncryptFile(filename_plain, filename_encrypted, key);
// Decryption
GCryptWrapper::DecryptFile(filename_encrypted, filename_decrypted, password);
// Decryption
GWrapper::DecryptFile(filename_encrypted, filename_decrypted, key);
// Read in both the base, and the decrypted file
const Flexblock plainfile = ReadFileToBits(filename_plain);
const Flexblock decryptfile = ReadFileToBits(filename_decrypted);
// Read in both the base, and the decrypted file
const Flexblock plainfile = ReadFileToBits(filename_plain);
const Flexblock decryptfile = ReadFileToBits(filename_decrypted);
// Assertion (If this fails, maybe check if the image is even readable by an image viewer)
REQUIRE(
PadStringToLength(plainfile, decryptfile.length(), '0', false) ==
decryptfile
// Assertion (If this fails, maybe check if the image is even readable by an image viewer)
REQUIRE(
PadStringToLength(plainfile, decryptfile.length(), '0', false) ==
decryptfile
);
}