diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-20 14:33:09 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-20 14:33:09 +1000 |
commit | 6352e8e3196f78388b6c771073f9e03eaa612673 (patch) | |
tree | e23772f79a7fbc41bc9108951e9e136857484bf4 /source/test/encode_test.cpp | |
parent | 6741a057e5639280d85d0f88ba26f000baa58f61 (diff) |
everything everywhere
all at once
Diffstat (limited to 'source/test/encode_test.cpp')
-rw-r--r-- | source/test/encode_test.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/source/test/encode_test.cpp b/source/test/encode_test.cpp new file mode 100644 index 0000000..6a53c10 --- /dev/null +++ b/source/test/encode_test.cpp @@ -0,0 +1,36 @@ +#include "StarEncode.hpp" +#include "StarSha256.hpp" + +#include "gtest/gtest.h" + +using namespace Star; + +TEST(EncodeTest, Base64) { + char const* data = + "Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust " + "of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, " + "exceeds the short vehemence of any carnal pleasure."; + ByteArray testSource = ByteArray(data, strlen(data)); + String testEncoded = + "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhl" + "ciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29u" + "dGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55" + "IGNhcm5hbCBwbGVhc3VyZS4="; + + String encoded = base64Encode(testSource); + ByteArray decoded = base64Decode(encoded); + + EXPECT_EQ(encoded, testEncoded); + EXPECT_EQ(decoded, testSource); +} + +TEST(EncodeTest, SHA256) { + char const* data = + "Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust " + "of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, " + "exceeds the short vehemence of any carnal pleasure."; + ByteArray testSource = ByteArray(data, strlen(data)); + ByteArray testHash = hexDecode("78fe75026c4390ceccc4e9e6a9428ba8ae5968b458e60b5eebecd682cf24bbf2"); + + EXPECT_EQ(sha256(testSource), testHash); +} |