Functions
crc32_test.cc File Reference
#include "catch2/catch.hpp"
#include "cetlib/crc32.h"
#include <string>
#include "CRC32Calculator.h"

Go to the source code of this file.

Functions

 SCENARIO ("We can produce CRC32 checksums accurately")
 

Function Documentation

SCENARIO ( "We can produce CRC32 checksums accurately"  )

Definition at line 52 of file crc32_test.cc.

53 {
54  crc32 crc;
55 
56  GIVEN("We have a short string")
57  {
58  WHEN("We create CRC32 digests in two different ways")
59  {
60  crc << TESTA;
61  cet::CRC32Calculator const refMaker(TESTA);
62 
63  auto const digest = crc.digest();
64  auto const ref = refMaker.checksum();
65 
66  THEN("The checksums compare equal") { CHECK(digest == ref); }
67  }
68  }
69 
70  GIVEN("We have a longer string")
71  {
72  WHEN("We create CRC32 digests in two different ways")
73  {
74  crc << TESTB;
75  cet::CRC32Calculator const refMaker(TESTB);
76 
77  auto const digest = crc.digest();
78  auto const ref = refMaker.checksum();
79 
80  THEN("The checksums compare equal") { CHECK(digest == ref); }
81  }
82  }
83 
84  GIVEN("We have a *much* longer string")
85  {
86  WHEN("We create CRC32 digests in two different ways")
87  {
88  crc << TESTC;
89  cet::CRC32Calculator const refMaker(TESTC);
90 
91  auto const digest = crc.digest();
92  auto const ref = refMaker.checksum();
93 
94  THEN("The checksums compare equal") { CHECK(digest == ref); }
95  }
96  }
97 
98  GIVEN("We have a string with a known, externally calculated CRC32 checksum")
99  {
100  WHEN("We create CRC32 digests in two different ways")
101  {
102  auto const testString = "type_label_instance"s;
103  auto const process_suffix = "_process"s;
104  auto const knownResult = 1215348599u;
105 
106  crc << (testString + process_suffix);
107  cet::CRC32Calculator const refMaker(testString + process_suffix);
108 
109  auto const digest = crc.digest();
110  auto const ref = refMaker.checksum();
111 
112  THEN("All three checksums compare equal")
113  {
114  CHECK(digest == knownResult);
115  CHECK(digest == ref);
116  }
117  WHEN("We insert more text before calculating a digest")
118  {
119  crc32 crc_insert(testString);
120  crc_insert << process_suffix;
121 
122  THEN("We get the same answer")
123  {
124  CHECK(crc_insert.digest() == knownResult);
125  }
126  }
127  }
128  }
129 
130  GIVEN("We have an empty string")
131  {
132  WHEN("We calculate its CRC32 checksum")
133  {
134  crc << "";
135 
136  THEN("It should be 0") { CHECK(crc.digest() == 0); }
137  }
138  }
139 }
#define TESTC
Definition: sha1_test_2.cc:8
#define TESTB
Definition: sha1_test_2.cc:7
#define TESTA
Definition: sha1_test_2.cc:6
constexpr digest_t digest() const
Definition: crc32.h:138
static QCString * s
Definition: config.cpp:1042