| 31 | #include "Engine/Hash64.h" |
| 32 | |
| 33 | NATRON_NAMESPACE_USING |
| 34 | |
| 35 | TEST(Hash64, |
| 36 | GeneralTest) |
| 37 | { |
| 38 | Hash64 hash1; |
| 39 | |
| 40 | ASSERT_FALSE( hash1.valid() ) << "A fresh hash is not valid."; |
| 41 | |
| 42 | hash1.computeHash(); |
| 43 | ASSERT_FALSE( hash1.valid() ) << "Compute on an empty hash doesn't make it valid"; |
| 44 | |
| 45 | hash1.append<int>(3); |
| 46 | ASSERT_FALSE( hash1.valid() ) << "You need to call compute to make the hash valid"; |
| 47 | |
| 48 | hash1.computeHash(); |
| 49 | ASSERT_TRUE( hash1.valid() ); |
| 50 | |
| 51 | hash1.reset(); |
| 52 | ASSERT_FALSE( hash1.valid() ); |
| 53 | |
| 54 | srand(2000); |
| 55 | // coverity[dont_call] |
| 56 | int hash1ElementCount = rand() % 100 + 80; |
| 57 | std::vector<int> hash1Elements; |
| 58 | for (int i = 0; i < hash1ElementCount; ++i) { |
| 59 | // coverity[dont_call] |
| 60 | int v = rand(); |
| 61 | hash1Elements.push_back(v); |
| 62 | hash1.append<int>(v); |
| 63 | } |
| 64 | |
| 65 | hash1.computeHash(); |
| 66 | ASSERT_TRUE( hash1.valid() ); |
| 67 | |
| 68 | Hash64 hash2; |
| 69 | for (int i = 0; i < hash1ElementCount; ++i) { |
| 70 | hash2.append<int>(hash1Elements[i]); |
| 71 | } |
| 72 | hash2.computeHash(); |
| 73 | ASSERT_TRUE( hash2.valid() ); |
| 74 | |
| 75 | EXPECT_EQ( hash1.value(), hash2.value() ) << "Hashs with same elements should be equal."; |
| 76 | EXPECT_EQ(hash1, hash2); |
| 77 | |
| 78 | hash2.reset(); |
| 79 | ASSERT_FALSE( hash2.valid() ); |
| 80 | |
| 81 | // coverity[dont_call] |
| 82 | int hash2ElementCount = hash1ElementCount + (rand() % 10 + 1); |
| 83 | for (int i = 0; i < hash2ElementCount; ++i) { |
| 84 | // coverity[dont_call] |
| 85 | hash2.append<int>( rand() ); |
| 86 | } |
| 87 | hash2.computeHash(); |
| 88 | ASSERT_TRUE( hash2.valid() ); |
| 89 | |
| 90 | EXPECT_NE( hash1.value(), hash2.value() ); |
nothing calls this directly
no test coverage detected