1 | #include "catch.hpp" |
---|---|
2 | #include "duckdb/common/checksum.hpp" |
3 | |
4 | #include <vector> |
5 | |
6 | using namespace duckdb; |
7 | using namespace std; |
8 | |
9 | #define NUM_INTS 10 |
10 | |
11 | TEST_CASE("Checksum tests", "[checksum]") { |
12 | // create a buffer |
13 | int vals[NUM_INTS]; |
14 | for (size_t i = 0; i < NUM_INTS; i++) { |
15 | vals[i] = i + 1; |
16 | } |
17 | // verify that checksum is consistent |
18 | uint64_t c1 = Checksum((uint8_t *)vals, sizeof(int) * NUM_INTS); |
19 | uint64_t c2 = Checksum((uint8_t *)vals, sizeof(int) * NUM_INTS); |
20 | REQUIRE(c1 == c2); |
21 | |
22 | // verify that checksum is sort of good |
23 | vals[3] = 1; |
24 | uint64_t c3 = Checksum((uint8_t *)vals, sizeof(int) * NUM_INTS); |
25 | REQUIRE(c1 != c3); |
26 | |
27 | // verify that zeros in the input does not zero the checksum |
28 | vals[3] = 0; |
29 | uint64_t c4 = Checksum((uint8_t *)vals, sizeof(int) * NUM_INTS); |
30 | REQUIRE(c4 != 0); |
31 | |
32 | // zero at a different location should change the checksum |
33 | vals[3] = 4; |
34 | vals[4] = 0; |
35 | uint64_t c5 = Checksum((uint8_t *)vals, sizeof(int) * NUM_INTS); |
36 | REQUIRE(c4 != c5); |
37 | |
38 | REQUIRE(c1 != c4); |
39 | REQUIRE(c1 != c5); |
40 | } |
41 |