Skip to content
This repository was archived by the owner on Jun 8, 2025. It is now read-only.

Commit ba01e1a

Browse files
illiashkirkochfast
authored andcommitted
Parametrized bytes test
1 parent 3f74b37 commit ba01e1a

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

test/unittests/test_keccak.cpp

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -205,19 +205,6 @@ TEST(keccak, nullptr_512)
205205
EXPECT_EQ(to_hex(h), test_cases[0].expected_hash512);
206206
}
207207

208-
TEST(keccak, bytes)
209-
{
210-
const uint8_t* const data = reinterpret_cast<const uint8_t*>(test_text);
211-
212-
for (auto& t : test_cases)
213-
{
214-
const auto h256 = keccak256(data, t.input_size);
215-
ASSERT_EQ(to_hex(h256), t.expected_hash256) << t.input_size;
216-
const auto h512 = keccak512(data, t.input_size);
217-
ASSERT_EQ(to_hex(h512), t.expected_hash512) << t.input_size;
218-
}
219-
}
220-
221208
TEST(keccak, unaligned)
222209
{
223210
const auto text_length = std::strlen(test_text);
@@ -247,6 +234,34 @@ TEST(keccak, hpp_aliases)
247234
EXPECT_EQ(keccak512_64(data).word64s[1], ethash_keccak512_64(data).word64s[1]);
248235
}
249236

237+
// parametrized keccak tests
238+
239+
class bytes : public testing::TestWithParam<size_t>
240+
{
241+
};
242+
243+
TEST_P(bytes, 256)
244+
{
245+
const uint8_t* const data = reinterpret_cast<const uint8_t*>(test_text);
246+
247+
const size_t index = GetParam();
248+
const auto h256 = keccak256(data, test_cases[index].input_size);
249+
ASSERT_EQ(to_hex(h256), test_cases[index].expected_hash256) << test_cases[index].input_size;
250+
}
251+
252+
TEST_P(bytes, 512)
253+
{
254+
const uint8_t* const data = reinterpret_cast<const uint8_t*>(test_text);
255+
256+
const size_t index = GetParam();
257+
const auto h512 = keccak512(data, test_cases[index].input_size);
258+
ASSERT_EQ(to_hex(h512), test_cases[index].expected_hash512) << test_cases[index].input_size;
259+
}
260+
261+
INSTANTIATE_TEST_SUITE_P(keccak, bytes, ::testing::Range(size_t(0), size_t(167)));
262+
263+
// end of parametrized keccak tests
264+
250265
TEST(helpers, to_hex)
251266
{
252267
hash256 h = {};

0 commit comments

Comments
 (0)