| 26 | namespace tensorflow { |
| 27 | |
| 28 | TEST(Hash, SignedUnsignedIssue) { |
| 29 | const unsigned char d1[1] = {0x62}; |
| 30 | const unsigned char d2[2] = {0xc3, 0x97}; |
| 31 | const unsigned char d3[3] = {0xe2, 0x99, 0xa5}; |
| 32 | const unsigned char d4[4] = {0xe1, 0x80, 0xb9, 0x32}; |
| 33 | const unsigned char d5[48] = { |
| 34 | 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 35 | 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, |
| 36 | 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x18, 0x28, 0x00, 0x00, 0x00, |
| 37 | 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 38 | }; |
| 39 | |
| 40 | struct Case { |
| 41 | uint32 hash32; |
| 42 | uint64 hash64; |
| 43 | const unsigned char* data; |
| 44 | size_t size; |
| 45 | uint32 seed; |
| 46 | }; |
| 47 | |
| 48 | for (Case c : std::vector<Case>{ |
| 49 | {0x471a8188u, 0x4c61ea3eeda4cb87ull, nullptr, 0, 0xbc9f1d34}, |
| 50 | {0xd615eba5u, 0x091309f7ef916c8aull, d1, sizeof(d1), 0xbc9f1d34}, |
| 51 | {0x0c3cccdau, 0xa815bcdf1d1af01cull, d2, sizeof(d2), 0xbc9f1d34}, |
| 52 | {0x3ba37e0eu, 0x02167564e4d06430ull, d3, sizeof(d3), 0xbc9f1d34}, |
| 53 | {0x16174eb3u, 0x8f7ed82ffc21071full, d4, sizeof(d4), 0xbc9f1d34}, |
| 54 | {0x98b1926cu, 0xce196580c97aff1eull, d5, sizeof(d5), 0x12345678}, |
| 55 | }) { |
| 56 | EXPECT_EQ(c.hash32, |
| 57 | Hash32(reinterpret_cast<const char*>(c.data), c.size, c.seed)); |
| 58 | EXPECT_EQ(c.hash64, |
| 59 | Hash64(reinterpret_cast<const char*>(c.data), c.size, c.seed)); |
| 60 | |
| 61 | // Check hashes with inputs aligned differently. |
| 62 | for (int align = 1; align <= 7; align++) { |
| 63 | std::string input(align, 'x'); |
| 64 | input.append(reinterpret_cast<const char*>(c.data), c.size); |
| 65 | EXPECT_EQ(c.hash32, Hash32(&input[align], c.size, c.seed)); |
| 66 | EXPECT_EQ(c.hash64, Hash64(&input[align], c.size, c.seed)); |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | TEST(Hash, SignedUnsignedIssueHash64V3) { |
| 72 | const unsigned char d1[1] = {0x62}; |
nothing calls this directly
no test coverage detected