gint delta)
{
gint new_pos;
+ gint len;
g_return_val_if_fail (iter != NULL, NULL);
+ len = g_sequence_get_length (get_sequence (iter));
+
new_pos = node_get_pos (iter) + delta;
- new_pos = clamp_position (get_sequence (iter), new_pos);
+ if (new_pos < 0)
+ new_pos = 0;
+ else if (new_pos > len)
+ new_pos = len;
return node_get_by_pos (iter, new_pos);
}
g_assert (g_sequence_iter_is_begin (iter));
g_assert (g_sequence_iter_is_end (iter));
+
+ g_sequence_free (seq);
+}
+
+static void
+test_iter_move (void)
+{
+ GSequence *seq = g_sequence_new (NULL);
+ GSequenceIter *iter;
+ gint i;
+
+ for (i = 0; i < 10; ++i)
+ g_sequence_append (seq, GINT_TO_POINTER (i));
+
+ iter = g_sequence_get_begin_iter (seq);
+ iter = g_sequence_iter_move (iter, 5);
+ g_assert_cmpint (GPOINTER_TO_INT (g_sequence_get (iter)), ==, 5);
+
+ iter = g_sequence_iter_move (iter, -10);
+ g_assert (g_sequence_iter_is_begin (iter));
+
+ iter = g_sequence_get_end_iter (seq);
+ iter = g_sequence_iter_move (iter, -5);
+ g_assert_cmpint (GPOINTER_TO_INT (g_sequence_get (iter)), ==, 5);
+
+ iter = g_sequence_iter_move (iter, 10);
+ g_assert (g_sequence_iter_is_end (iter));
+
+ g_sequence_free (seq);
}
static int
iter = g_sequence_iter_next (iter);
g_sequence_check (seq);
}
+
+ g_sequence_free (seq);
}
int
/* Standalone tests */
g_test_add_func ("/sequence/out-of-range-jump", test_out_of_range_jump);
+ g_test_add_func ("/sequence/iter-move", test_iter_move);
g_test_add_func ("/sequence/insert-sorted-non-pointer", test_insert_sorted_non_pointer);
g_test_add_func ("/sequence/stable-sort", test_stable_sort);