mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-14 00:14:18 +00:00
Improved the SHA256 unit test, and added test for MD5.
This commit is contained in:
parent
43fb1f11d9
commit
e31ebbfbc9
2 changed files with 61 additions and 18 deletions
|
|
@ -297,3 +297,40 @@ String MD5::toHexString() const
|
|||
//==============================================================================
|
||||
bool MD5::operator== (const MD5& other) const noexcept { return memcmp (result, other.result, sizeof (result)) == 0; }
|
||||
bool MD5::operator!= (const MD5& other) const noexcept { return ! operator== (other); }
|
||||
|
||||
|
||||
//==============================================================================
|
||||
#if JUCE_UNIT_TESTS
|
||||
|
||||
class MD5Tests : public UnitTest
|
||||
{
|
||||
public:
|
||||
MD5Tests() : UnitTest ("MD5") {}
|
||||
|
||||
void test (const char* input, const char* expected)
|
||||
{
|
||||
{
|
||||
MD5 hash (input, strlen (input));
|
||||
expectEquals (hash.toHexString(), String (expected));
|
||||
}
|
||||
|
||||
{
|
||||
MemoryInputStream m (input, strlen (input), false);
|
||||
MD5 hash (m);
|
||||
expectEquals (hash.toHexString(), String (expected));
|
||||
}
|
||||
}
|
||||
|
||||
void runTest()
|
||||
{
|
||||
beginTest ("MD5");
|
||||
|
||||
test ("", "d41d8cd98f00b204e9800998ecf8427e");
|
||||
test ("The quick brown fox jumps over the lazy dog", "9e107d9d372bb6826bd81d3542a419d6");
|
||||
test ("The quick brown fox jumps over the lazy dog.", "e4d909c290d0fb1ca068ffaddf22cbd0");
|
||||
}
|
||||
};
|
||||
|
||||
static MD5Tests MD5UnitTests;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -240,27 +240,33 @@ class SHA256Tests : public UnitTest
|
|||
public:
|
||||
SHA256Tests() : UnitTest ("SHA-256") {}
|
||||
|
||||
void test (const char* input, const char* expected)
|
||||
{
|
||||
{
|
||||
SHA256 hash (input, strlen (input));
|
||||
expectEquals (hash.toHexString(), String (expected));
|
||||
}
|
||||
|
||||
{
|
||||
CharPointer_UTF8 utf8 (input);
|
||||
SHA256 hash (utf8);
|
||||
expectEquals (hash.toHexString(), String (expected));
|
||||
}
|
||||
|
||||
{
|
||||
MemoryInputStream m (input, strlen (input), false);
|
||||
SHA256 hash (m);
|
||||
expectEquals (hash.toHexString(), String (expected));
|
||||
}
|
||||
}
|
||||
|
||||
void runTest()
|
||||
{
|
||||
beginTest ("SHA-256");
|
||||
beginTest ("SHA256");
|
||||
|
||||
{
|
||||
char n[] = "";
|
||||
SHA256 sha (n, 0);
|
||||
expectEquals (sha.toHexString(), String ("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"));
|
||||
}
|
||||
|
||||
{
|
||||
const char n[] = "The quick brown fox jumps over the lazy dog";
|
||||
SHA256 sha (n, sizeof (n) - 1);
|
||||
expectEquals (sha.toHexString(), String ("d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592"));
|
||||
}
|
||||
|
||||
{
|
||||
const char n[] = "The quick brown fox jumps over the lazy dog.";
|
||||
SHA256 sha (n, sizeof (n) - 1);
|
||||
expectEquals (sha.toHexString(), String ("ef537f25c895bfa782526529a9b63d97aa631564d5d789c2b765448c8635fb6c"));
|
||||
}
|
||||
test ("", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
|
||||
test ("The quick brown fox jumps over the lazy dog", "d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592");
|
||||
test ("The quick brown fox jumps over the lazy dog.", "ef537f25c895bfa782526529a9b63d97aa631564d5d789c2b765448c8635fb6c");
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue