]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Convert hash test suite to Catch2
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 8 May 2020 19:36:44 +0000 (21:36 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 12 May 2020 19:06:47 +0000 (21:06 +0200)
unittest/main.cpp
unittest/test_hash.cpp

index 2fed2da118ea14947ff532b661c8e17777b94c79..2d8b87cbcac788f10c3b03d71c1f1c52a9ecdc47 100644 (file)
 #include "catch2_tests.hpp"
 #include "framework.hpp"
 
-unsigned suite_conf(unsigned);
-unsigned suite_hash(unsigned);
 unsigned suite_hashutil(unsigned);
 unsigned suite_legacy_util(unsigned);
 
 const suite_fn k_legacy_suites[] = {
-  &suite_hash,
   &suite_hashutil,
   &suite_legacy_util,
   nullptr,
index 2c402b20477c3ace48663d84a5aa66174824a302..6ea9fcc249a035152d9819b787ef91cfc3b82a1c 100644 (file)
 // This file contains tests for functions in hash.c.
 
 #include "../src/hash.hpp"
-#include "framework.hpp"
 
-TEST_SUITE(hash)
+#include "third_party/catch.hpp"
 
-TEST(test_known_strings)
+TEST_CASE("test_known_strings")
 {
   char d[DIGEST_STRING_BUFFER_SIZE];
 
@@ -31,7 +30,7 @@ TEST(test_known_strings)
     struct hash* h = hash_init();
     hash_string(h, "");
     hash_result_as_string(h, d);
-    CHECK_STR_EQ("3345524abf6bbe1809449224b5972c41790b6cf2", d);
+    CHECK(strcmp(d, "3345524abf6bbe1809449224b5972c41790b6cf2") == 0);
     hash_free(h);
   }
 
@@ -39,7 +38,7 @@ TEST(test_known_strings)
     struct hash* h = hash_init();
     hash_string(h, "a");
     hash_result_as_string(h, d);
-    CHECK_STR_EQ("948caa2db61bc4cdb4faf7740cd491f195043914", d);
+    CHECK(strcmp(d, "948caa2db61bc4cdb4faf7740cd491f195043914") == 0);
     hash_free(h);
   }
 
@@ -47,7 +46,7 @@ TEST(test_known_strings)
     struct hash* h = hash_init();
     hash_string(h, "message digest");
     hash_result_as_string(h, d);
-    CHECK_STR_EQ("6bfec6f65e52962be863d6ea1005fc5e4cc8478c", d);
+    CHECK(strcmp(d, "6bfec6f65e52962be863d6ea1005fc5e4cc8478c") == 0);
     hash_free(h);
   }
 
@@ -59,12 +58,12 @@ TEST(test_known_strings)
       "1"
       "234567890");
     hash_result_as_string(h, d);
-    CHECK_STR_EQ("c2be0e534a67d25947f0c7e78527b2f82abd260f", d);
+    CHECK(strcmp(d, "c2be0e534a67d25947f0c7e78527b2f82abd260f") == 0);
     hash_free(h);
   }
 }
 
-TEST(hash_result_should_not_alter_state)
+TEST_CASE("hash_result_should_not_alter_state")
 {
   char d[DIGEST_STRING_BUFFER_SIZE];
   struct hash* h = hash_init();
@@ -72,34 +71,33 @@ TEST(hash_result_should_not_alter_state)
   hash_result_as_string(h, d);
   hash_string(h, " digest");
   hash_result_as_string(h, d);
-  CHECK_STR_EQ("6bfec6f65e52962be863d6ea1005fc5e4cc8478c", d);
+  CHECK(strcmp(d, "6bfec6f65e52962be863d6ea1005fc5e4cc8478c") == 0);
   hash_free(h);
 }
 
-TEST(hash_result_should_be_idempotent)
+TEST_CASE("hash_result_should_be_idempotent")
 {
   char d[DIGEST_STRING_BUFFER_SIZE];
   struct hash* h = hash_init();
   hash_string(h, "");
   hash_result_as_string(h, d);
-  CHECK_STR_EQ("3345524abf6bbe1809449224b5972c41790b6cf2", d);
+  CHECK(strcmp(d, "3345524abf6bbe1809449224b5972c41790b6cf2") == 0);
   hash_result_as_string(h, d);
-  CHECK_STR_EQ("3345524abf6bbe1809449224b5972c41790b6cf2", d);
+  CHECK(strcmp(d, "3345524abf6bbe1809449224b5972c41790b6cf2") == 0);
 
   hash_free(h);
 }
 
-TEST(hash_result_as_bytes)
+TEST_CASE("hash_result_as_bytes")
 {
   struct hash* h = hash_init();
   hash_string(h, "message digest");
   struct digest d;
   hash_result_as_bytes(h, &d);
-  uint8_t expected[sizeof(d.bytes)] = {0x6b, 0xfe, 0xc6, 0xf6, 0x5e, 0x52, 0x96,
-                                       0x2b, 0xe8, 0x63, 0xd6, 0xea, 0x10, 0x05,
-                                       0xfc, 0x5e, 0x4c, 0xc8, 0x47, 0x8c};
-  CHECK_DATA_EQ(d.bytes, expected, sizeof(d.bytes));
+  uint8_t expected[sizeof(d.bytes)] = {
+    0x6b, 0xfe, 0xc6, 0xf6, 0x5e, 0x52, 0x96, 0x2b, 0xe8, 0x63,
+    0xd6, 0xea, 0x10, 0x05, 0xfc, 0x5e, 0x4c, 0xc8, 0x47, 0x8c,
+  };
+  CHECK(memcmp(d.bytes, expected, sizeof(d.bytes)) == 0);
   hash_free(h);
 }
-
-TEST_SUITE_END