summaryrefslogtreecommitdiff
path: root/dviware/dvisvgm/tests/HashFunctionTest.cpp
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-10-29 03:00:39 +0000
committerNorbert Preining <norbert@preining.info>2019-10-29 03:00:39 +0000
commit97f5151099967e6c823d640a90d87bca92c44035 (patch)
tree685caa49488599f87d0caa4e972833b2263d8567 /dviware/dvisvgm/tests/HashFunctionTest.cpp
parent25a647b97ef526aefcc75269dd19c46dbe3ae4c1 (diff)
CTAN sync 201910290300
Diffstat (limited to 'dviware/dvisvgm/tests/HashFunctionTest.cpp')
-rw-r--r--dviware/dvisvgm/tests/HashFunctionTest.cpp51
1 files changed, 38 insertions, 13 deletions
diff --git a/dviware/dvisvgm/tests/HashFunctionTest.cpp b/dviware/dvisvgm/tests/HashFunctionTest.cpp
index dad7a6276c..64559c5aab 100644
--- a/dviware/dvisvgm/tests/HashFunctionTest.cpp
+++ b/dviware/dvisvgm/tests/HashFunctionTest.cpp
@@ -35,10 +35,8 @@ TEST(HashFunctionTest, md5) {
md5.reset();
md5.update("0123456789");
EXPECT_EQ(md5.digestString(), "781e5e245d69b566979b86e28d23f2c7");
- uint8_t bytes[] = {0x78, 0x1e, 0x5e, 0x24, 0x5d, 0x69, 0xb5, 0x66, 0x97, 0x9b, 0x86, 0xe2, 0x8d, 0x23, 0xf2, 0xc7};
- int i=0;
- for (uint8_t byte : md5.digestValue())
- EXPECT_EQ(byte, bytes[i++]);
+ vector<uint8_t> bytes = {0x78, 0x1e, 0x5e, 0x24, 0x5d, 0x69, 0xb5, 0x66, 0x97, 0x9b, 0x86, 0xe2, 0x8d, 0x23, 0xf2, 0xc7};
+ EXPECT_EQ(md5.digestValue(), bytes);
}
@@ -52,10 +50,8 @@ TEST(HashFunctionTest, xxh32) {
xxh32.reset();
xxh32.update("0123456789");
EXPECT_EQ(xxh32.digestString(), "950c9c0a");
- uint8_t bytes[] = {0x95, 0x0c, 0x9c, 0x0a};
- int i=0;
- for (uint8_t byte : xxh32.digestValue())
- EXPECT_EQ(byte, bytes[i++]);
+ vector<uint8_t> bytes = {0x95, 0x0c, 0x9c, 0x0a};
+ EXPECT_EQ(xxh32.digestValue(), bytes);
}
@@ -69,13 +65,28 @@ TEST(HashFunctionTest, xxh64) {
xxh64.reset();
xxh64.update("0123456789");
EXPECT_EQ(xxh64.digestString(), "3f5fc178a81867e7");
- uint8_t bytes[] = {0x3f, 0x5f, 0xc1, 0x78, 0xa8, 0x18, 0x67, 0xe7};
- int i=0;
- for (uint8_t byte : xxh64.digestValue())
- EXPECT_EQ(byte, bytes[i++]);
+ vector<uint8_t> bytes = {0x3f, 0x5f, 0xc1, 0x78, 0xa8, 0x18, 0x67, 0xe7};
+ EXPECT_EQ(xxh64.digestValue(), bytes);
}
+#ifdef ENABLE_XXH128
+TEST(HashFunctionTest, xxh128) {
+ XXH128HashFunction xxh128;
+ ASSERT_EQ(xxh128.digestSize(), 16);
+ xxh128.update("0123456789");
+ EXPECT_EQ(xxh128.digestString(), "942eb242912d99ecb1844fcc57198e3a");
+ xxh128.update("abcdefghij");
+ EXPECT_EQ(xxh128.digestString(), "f37bc26b7087c656f0345fdf02a75bc4");
+ xxh128.reset();
+ xxh128.update("0123456789");
+ EXPECT_EQ(xxh128.digestString(), "942eb242912d99ecb1844fcc57198e3a");
+ vector<uint8_t> bytes = {0x94, 0x2e, 0xb2, 0x42, 0x91, 0x2d, 0x99, 0xec, 0xb1, 0x84, 0x4f, 0xcc, 0x57, 0x19, 0x8e, 0x3a};
+ EXPECT_EQ(xxh128.digestValue(), bytes);
+}
+#endif
+
+
TEST(HashFunctionTest, createMD5) {
auto hashfunc = HashFunction::create("md5");
ASSERT_TRUE(dynamic_cast<MD5HashFunction*>(hashfunc.get()) != nullptr);
@@ -112,6 +123,20 @@ TEST(HashFunctionTest, createXXH64) {
}
+#ifdef ENABLE_XXH128
+TEST(HashFunctionTest, createXXH128) {
+ auto hashfunc = HashFunction::create("xxh128");
+ ASSERT_TRUE(dynamic_cast<XXH128HashFunction*>(hashfunc.get()) != nullptr);
+ hashfunc->update("0123456789");
+ EXPECT_EQ(hashfunc->digestString(), "942eb242912d99ecb1844fcc57198e3a");
+
+ hashfunc = HashFunction::create("xxh128", "0123456789");
+ ASSERT_TRUE(dynamic_cast<XXH128HashFunction*>(hashfunc.get()) != nullptr);
+ EXPECT_EQ(hashfunc->digestString(), "942eb242912d99ecb1844fcc57198e3a");
+}
+#endif
+
+
TEST(HashFunctionTest, createFail) {
ASSERT_TRUE(HashFunction::create("not-available") == nullptr);
-} \ No newline at end of file
+}