@@ -1974,6 +1974,32 @@ DEFINE_TEST(test_stats) {
19741974 roaring64_bitmap_free (r1);
19751975}
19761976
1977+ DEFINE_TEST (test_iterator_read_past_end_can_go_previous) {
1978+ roaring64_bitmap_t * bitmap = roaring64_bitmap_create ();
1979+ assert_non_null (bitmap);
1980+
1981+ roaring64_bitmap_add (bitmap, 10 );
1982+ assert_r64_valid (bitmap);
1983+
1984+ roaring64_iterator_t * iter = roaring64_iterator_create (bitmap);
1985+ assert_non_null (iter);
1986+
1987+ uint64_t buffer[100 ];
1988+ uint64_t actual_read1 = roaring64_iterator_read (
1989+ iter, buffer, sizeof (buffer) / sizeof (buffer[0 ]));
1990+ assert_int_equal (actual_read1, 1 ); // Only one value should be present
1991+
1992+ // Should now be one past the end, but should be able to move backwards
1993+ assert_false (roaring64_iterator_has_value (iter));
1994+ bool prev_result = roaring64_iterator_previous (iter);
1995+ assert_true (prev_result);
1996+ assert_true (roaring64_iterator_has_value (iter));
1997+ assert_int_equal (roaring64_iterator_value (iter), 10 );
1998+
1999+ roaring64_iterator_free (iter);
2000+ roaring64_bitmap_free (bitmap);
2001+ }
2002+
19772003} // namespace
19782004
19792005int main () {
@@ -2038,6 +2064,7 @@ int main() {
20382064 cmocka_unit_test (test_iterator_move_equalorlarger),
20392065 cmocka_unit_test (test_iterator_read),
20402066 cmocka_unit_test (test_stats),
2067+ cmocka_unit_test (test_iterator_read_past_end_can_go_previous),
20412068 };
20422069 return cmocka_run_group_tests (tests, NULL , NULL );
20432070}
0 commit comments