| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "gate/tests.hpp" | ||
| 2 | #include "gate/encode/crchash.hpp" | ||
| 3 | #include "gate/encode/md5hash.hpp" | ||
| 4 | #include "gate/encode/sha1hash.hpp" | ||
| 5 | #include "gate/encode/sha256hash.hpp" | ||
| 6 | #include "gate/streams.hpp" | ||
| 7 | |||
| 8 | using namespace gate; | ||
| 9 | using namespace gate::enc; | ||
| 10 | |||
| 11 | static StaticString const content = "There are two types of people in the world: those with a gun, and those who dig."; | ||
| 12 | |||
| 13 | 18 | template<class T> void test_hash(T& h, String const& text) | |
| 14 | { | ||
| 15 | // create hash from string | ||
| 16 |
1/2✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
|
18 | h.reset(); |
| 17 |
1/2✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
|
18 | h.update(text); |
| 18 |
1/2✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
|
36 | String hash1 = h.computeResult(); |
| 19 | |||
| 20 | // create hash from stream | ||
| 21 |
1/2✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
|
18 | h.reset(); |
| 22 |
1/2✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
|
36 | StringStream ss(text); |
| 23 |
1/2✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
|
18 | h.update(ss); |
| 24 |
1/2✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
|
36 | String hash2 = h.computeResult(); |
| 25 | |||
| 26 | // create hash from byte buffer | ||
| 27 |
1/2✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
|
18 | h.reset(); |
| 28 | 18 | gate::size_t mid_pos = text.length() / 2; | |
| 29 |
1/2✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
|
18 | h.update(text.c_str(), mid_pos); |
| 30 |
1/2✓ Branch 3 taken 9 times.
✗ Branch 4 not taken.
|
18 | h.update(text.c_str() + mid_pos, text.length() - mid_pos); |
| 31 |
1/2✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
|
36 | String hash3 = h.computeResult(); |
| 32 | |||
| 33 | // all hashes must be equal: | ||
| 34 |
4/12✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 9 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 9 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
|
18 | GATEXX_TEST_CHECK_EQUAL(hash1, hash2); |
| 35 |
4/12✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 9 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 9 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
|
18 | GATEXX_TEST_CHECK_EQUAL(hash1, hash3); |
| 36 | 18 | } | |
| 37 | |||
| 38 | 8 | template<class T> void test_hash_static(String const& text) | |
| 39 | { | ||
| 40 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
16 | String hash1 = T::compute(text); |
| 41 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
16 | StringStream ss(text); |
| 42 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
16 | String hash2 = T::compute(ss); |
| 43 |
1/2✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
|
16 | String hash3 = T::compute(text.c_str(), text.length()); |
| 44 | |||
| 45 | // all hashes must be equal: | ||
| 46 |
4/12✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
|
8 | GATEXX_TEST_CHECK_EQUAL(hash1, hash2); |
| 47 |
4/12✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
|
8 | GATEXX_TEST_CHECK_EQUAL(hash1, hash3); |
| 48 | 8 | } | |
| 49 | |||
| 50 |
2/7✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
6 | GATEXX_TEST_UNIT(Crc) |
| 51 | { | ||
| 52 | { | ||
| 53 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
4 | Crc16Hash h(Crc16Hash::Crc16_MODBUS); |
| 54 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | test_hash(h, content); |
| 55 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | test_hash_static<Crc16Hash>(content); |
| 56 | } | ||
| 57 | { | ||
| 58 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
4 | Crc16Hash h(Crc16Hash::Crc16_ARC); |
| 59 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | test_hash(h, content); |
| 60 | } | ||
| 61 | { | ||
| 62 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
4 | Crc16Hash h(Crc16Hash::Crc16_CCITT_FALSE); |
| 63 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | test_hash(h, content); |
| 64 | } | ||
| 65 | { | ||
| 66 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
4 | Crc16Hash h(Crc16Hash::Crc16_KERMIT); |
| 67 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | test_hash(h, content); |
| 68 | } | ||
| 69 | { | ||
| 70 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
4 | Crc16Hash h(Crc16Hash::Crc16_XMODEM); |
| 71 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | test_hash(h, content); |
| 72 | } | ||
| 73 | |||
| 74 | { | ||
| 75 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
4 | Crc32Hash h; |
| 76 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | test_hash(h, content); |
| 77 | } | ||
| 78 | 2 | } | |
| 79 | |||
| 80 |
2/7✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
6 | GATEXX_TEST_UNIT(MD5) |
| 81 | { | ||
| 82 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
4 | Md5Hash h; |
| 83 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | test_hash(h, content); |
| 84 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | test_hash_static<Md5Hash>(content); |
| 85 | 2 | } | |
| 86 | |||
| 87 |
2/7✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
6 | GATEXX_TEST_UNIT(SHA1) |
| 88 | { | ||
| 89 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
4 | Sha1Hash h; |
| 90 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | test_hash(h, content); |
| 91 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | test_hash_static<Sha1Hash>(content); |
| 92 | 2 | } | |
| 93 | |||
| 94 |
2/7✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
6 | GATEXX_TEST_UNIT(SHA256) |
| 95 | { | ||
| 96 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
4 | Sha256Hash h; |
| 97 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | test_hash(h, content); |
| 98 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | test_hash_static<Sha256Hash>(content); |
| 99 | 2 | } | |
| 100 |