diff options
author | Mark Haines <mjark@negativecurvature.net> | 2016-05-25 15:00:05 +0100 |
---|---|---|
committer | Mark Haines <mjark@negativecurvature.net> | 2016-05-25 15:00:05 +0100 |
commit | 19a7fb5df5ec3445201ce5fbe475a08faf6319fc (patch) | |
tree | e9f9ac72d035106a42260e792cdc0bad6c72fc4e /tests | |
parent | 01ea3d4b9a3c6f3e0303c2d421a248715a96af99 (diff) |
Fix an integer wrap around bug and add a couple more tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_megolm.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/test_megolm.cpp b/tests/test_megolm.cpp index bf53346..3048fa3 100644 --- a/tests/test_megolm.cpp +++ b/tests/test_megolm.cpp @@ -98,4 +98,37 @@ std::uint8_t random_bytes[] = assert_equals(megolm_get_data(&mr2), megolm_get_data(&mr1), MEGOLM_RATCHET_LENGTH); } +{ + TestCase test_case("Megolm::advance overflow by one"); + + Megolm mr1, mr2; + + megolm_init(&mr1, random_bytes, 0xffffffffUL); + megolm_advance_to(&mr1, 0x0); + assert_equals(0x0U, mr1.counter); + + megolm_init(&mr2, random_bytes, 0xffffffffUL); + megolm_advance(&mr2); + assert_equals(0x0U, mr2.counter); + + assert_equals(megolm_get_data(&mr2), megolm_get_data(&mr1), MEGOLM_RATCHET_LENGTH); +} + +{ + TestCase test_case("Megolm::advance overflow"); + + Megolm mr1, mr2; + + megolm_init(&mr1, random_bytes, 0x1UL); + megolm_advance_to(&mr1, 0x80000000UL); + megolm_advance_to(&mr1, 0x0); + assert_equals(0x0U, mr1.counter); + + megolm_init(&mr2, random_bytes, 0x1UL); + megolm_advance_to(&mr2, 0x0UL); + assert_equals(0x0U, mr2.counter); + + assert_equals(megolm_get_data(&mr2), megolm_get_data(&mr1), MEGOLM_RATCHET_LENGTH); +} + } |