Update contrib.
1 /* Portions copyright (c) 2009 Nokia Corporation. All rights reserved.*/
6 #include "mrt2_glib2_test.h"
7 #endif /*__SYMBIAN32__*/
8 /* Keep this in sync with gsequence.c !!! */
9 typedef struct _GSequenceNode GSequenceNode;
13 GSequenceNode * end_node;
14 GDestroyNotify data_destroy_notify;
15 gboolean access_prohibited;
16 GSequence * real_sequence;
22 GSequenceNode * parent;
24 GSequenceNode * right;
29 get_priority (GSequenceNode *node)
31 guint key = GPOINTER_TO_UINT (node);
33 key = (key << 15) - key - 1;
34 key = key ^ (key >> 12);
35 key = key + (key << 2);
36 key = key ^ (key >> 4);
37 key = key + (key << 3) + (key << 11);
38 key = key ^ (key >> 16);
44 check_node (GSequenceNode *node)
48 g_assert (node->parent != node);
50 g_assert (node->parent->left == node || node->parent->right == node);
51 g_assert (node->n_nodes == 1 + (node->left ? node->left->n_nodes : 0) + (node->right ? node->right->n_nodes : 0));
53 g_assert (get_priority (node) >= get_priority (node->left));
55 g_assert (get_priority (node) >= get_priority (node->right));
56 check_node (node->left);
57 check_node (node->right);
62 g_sequence_check (GSequence *seq)
64 GSequenceNode *node = seq->end_node;
74 g_assert (seq->end_node == node);
75 g_assert (node->data == seq);
79 //undefs done here as some of these enums are already defined in s60 environ
91 NEW, FREE, GET_LENGTH, FOREACH, FOREACH_RANGE, SORT, SORT_ITER,
94 GET_BEGIN_ITER, GET_END_ITER, GET_ITER_AT_POS, APPEND, PREPEND,
95 INSERT_BEFORE, MOVE, SWAP, INSERT_SORTED, INSERT_SORTED_ITER, SORT_CHANGED,
96 SORT_CHANGED_ITER, REMOVE, REMOVE_RANGE, MOVE_RANGE, SEARCH, SEARCH_ITER,
101 /* operations on GSequenceIter * */
102 ITER_IS_BEGIN, ITER_IS_END, ITER_NEXT, ITER_PREV, ITER_GET_POSITION,
103 ITER_MOVE, ITER_GET_SEQUENCE,
106 ITER_COMPARE, RANGE_GET_MIDPOINT,
110 typedef struct SequenceInfo
113 GSequence * sequence;
123 void g_sequence_check (GSequence *sequence);
126 fix_pointer (gconstpointer data)
128 return (Item *)((char *)data - 1);
132 get_item (GSequenceIter *iter)
134 return fix_pointer (g_sequence_get (iter));
138 check_integrity (SequenceInfo *info)
144 g_sequence_check (info->sequence);
146 if (g_sequence_get_length (info->sequence) != info->n_items)
148 g_sequence_get_length (info->sequence), info->n_items);
149 g_assert (info->n_items == g_queue_get_length (info->queue));
150 g_assert (g_sequence_get_length (info->sequence) == info->n_items);
152 iter = g_sequence_get_begin_iter (info->sequence);
153 list = info->queue->head;
155 while (iter != g_sequence_get_end_iter (info->sequence))
158 g_assert (list->data == iter);
159 item = get_item (list->data);
160 g_assert (item->seq == info);
162 iter = g_sequence_iter_next (iter);
167 g_assert (info->n_items == g_queue_get_length (info->queue));
168 g_assert (g_sequence_get_length (info->sequence) == info->n_items);
172 new_item (SequenceInfo *seq)
174 Item *item = g_new (Item, 1);
177 item->number = g_random_int ();
179 /* There have been bugs in the past where the GSequence would
180 * dereference the user pointers. This will make sure such
181 * behavior causes crashes
183 return ((char *)item + 1);
187 free_item (gpointer data)
189 Item *item = fix_pointer (data);
190 item->seq->n_items--;
195 seq_foreach (gpointer data,
198 Item *item = fix_pointer (data);
199 GList **link = user_data;
202 g_assert (*link != NULL);
204 iter = (*link)->data;
206 g_assert (get_item (iter) == item);
208 item->number = g_random_int();
210 *link = (*link)->next;
214 compare_items (gconstpointer a,
218 const Item *item_a = fix_pointer (a);
219 const Item *item_b = fix_pointer (b);
221 if (item_a->number < item_b->number)
225 else if (item_a->number == item_b->number)
227 /* Force an arbitrary order on the items
228 * We have to do this, since g_queue_insert_sorted() and
229 * g_sequence_insert_sorted() do not agree on the exact
230 * position the item is inserted if the new item is
231 * equal to an existing one.
235 else if (item_a == item_b)
247 check_sorted (SequenceInfo *info)
251 GSequenceIter *last_iter;
253 check_integrity (info);
257 for (list = info->queue->head; list != NULL; list = list->next)
259 GSequenceIter *iter = list->data;
260 Item *item = get_item (iter);
262 g_assert (item->number >= last);
263 /* Check that the ordering is the same as that of the queue,
264 * ie. that the sort is stable
267 g_assert (iter == g_sequence_iter_next (last_iter));
275 compare_iters (gconstpointer a,
279 GSequence *seq = data;
280 GSequenceIter *iter_a = (GSequenceIter *)a;
281 GSequenceIter *iter_b = (GSequenceIter *)b;
282 /* compare_items() will fix up the pointers */
283 Item *item_a = g_sequence_get (iter_a);
284 Item *item_b = g_sequence_get (iter_b);
288 g_assert (g_sequence_iter_get_sequence (iter_a) == seq);
289 g_assert (g_sequence_iter_get_sequence (iter_b) == seq);
292 return compare_items (item_a, item_b, data);
295 /* A version of g_queue_link_index() that treats NULL as just
299 queue_link_index (SequenceInfo *seq, GList *link)
302 return g_queue_link_index (seq->queue, link);
304 return g_queue_get_length (seq->queue);
308 get_random_range (SequenceInfo *seq,
309 GSequenceIter **begin_iter,
310 GSequenceIter **end_iter,
314 int length = g_queue_get_length (seq->queue);
315 int b = g_random_int_range (0, length + 1);
316 int e = g_random_int_range (b, length + 1);
318 g_assert (length == g_sequence_get_length (seq->sequence));
321 *begin_iter = g_sequence_get_iter_at_pos (seq->sequence, b);
323 *end_iter = g_sequence_get_iter_at_pos (seq->sequence, e);
325 *begin_link = g_queue_peek_nth_link (seq->queue, b);
327 *end_link = g_queue_peek_nth_link (seq->queue, e);
328 if (begin_iter && begin_link)
331 queue_link_index (seq, *begin_link) ==
332 g_sequence_iter_get_position (*begin_iter));
334 if (end_iter && end_link)
337 queue_link_index (seq, *end_link) ==
338 g_sequence_iter_get_position (*end_iter));
343 get_random_position (SequenceInfo *seq)
345 int length = g_queue_get_length (seq->queue);
347 g_assert (length == g_sequence_get_length (seq->sequence));
349 return g_random_int_range (-2, length + 5);
352 static GSequenceIter *
353 get_random_iter (SequenceInfo *seq,
357 int pos = get_random_position (seq);
359 *link = g_queue_peek_nth_link (seq->queue, pos);
360 iter = g_sequence_get_iter_at_pos (seq->sequence, pos);
362 g_assert (queue_link_index (seq, *link) == g_sequence_iter_get_position (iter));
367 dump_info (SequenceInfo *seq)
373 iter = g_sequence_get_begin_iter (seq->sequence);
374 list = seq->queue->head;
376 while (iter != g_sequence_get_end_iter (seq->sequence))
378 Item *item = get_item (iter);
379 g_print ("%p %p %d\n", list->data, iter, item->number);
381 iter = g_sequence_iter_next (iter);
387 /* A version of g_queue_insert_before() that appends if link is NULL */
389 queue_insert_before (SequenceInfo *seq, GList *link, gpointer data)
392 g_queue_insert_before (seq->queue, link, data);
394 g_queue_push_tail (seq->queue, data);
398 run_random_tests (guint32 seed)
400 #ifndef __SYMBIAN32__
401 #define N_ITERATIONS 60000
403 #define N_ITERATIONS 600
404 #endif//__SYMBIAN32__
405 #define N_SEQUENCES 8
408 SequenceInfo sequences[N_SEQUENCES];
411 g_print (" seed: %u\n", seed);
413 g_random_set_seed (seed);
415 for (k = 0; k < N_SEQUENCES; ++k)
417 sequences[k].queue = g_queue_new ();
418 sequences[k].sequence = g_sequence_new (free_item);
419 sequences[k].n_items = 0;
422 #define RANDOM_SEQUENCE() &(sequences[g_random_int_range (0, N_SEQUENCES)])
424 for (k = 0; k < N_ITERATIONS; ++k)
427 SequenceInfo *seq = RANDOM_SEQUENCE();
428 int op = g_random_int_range (0, N_OPS);
431 g_print ("%d on %p\n", op, seq);
439 g_queue_free (seq->queue);
440 g_sequence_free (seq->sequence);
442 g_assert (seq->n_items == 0);
444 seq->queue = g_queue_new ();
445 seq->sequence = g_sequence_new (free_item);
447 check_integrity (seq);
452 int slen = g_sequence_get_length (seq->sequence);
453 int qlen = g_queue_get_length (seq->queue);
455 g_assert (slen == qlen);
460 GList *link = seq->queue->head;
461 g_sequence_foreach (seq->sequence, seq_foreach, &link);
462 g_assert (link == NULL);
467 GSequenceIter *begin_iter, *end_iter;
468 GList *begin_link, *end_link;
470 get_random_range (seq, &begin_iter, &end_iter, &begin_link, &end_link);
472 check_integrity (seq);
474 g_sequence_foreach_range (begin_iter, end_iter, seq_foreach, &begin_link);
476 g_assert (begin_link == end_link);
483 g_sequence_sort (seq->sequence, compare_items, NULL);
484 g_queue_sort (seq->queue, compare_iters, NULL);
493 check_integrity (seq);
494 g_sequence_sort_iter (seq->sequence,
495 (GSequenceIterCompareFunc)compare_iters, seq->sequence);
496 g_queue_sort (seq->queue, compare_iters, NULL);
505 GSequenceIter *begin_iter;
506 GSequenceIter *end_iter;
507 GSequenceIter *penultimate_iter;
509 begin_iter = g_sequence_get_begin_iter (seq->sequence);
510 check_integrity (seq);
512 end_iter = g_sequence_get_end_iter (seq->sequence);
513 check_integrity (seq);
515 penultimate_iter = g_sequence_iter_prev (end_iter);
516 check_integrity (seq);
518 if (g_sequence_get_length (seq->sequence) > 0)
520 g_assert (seq->queue->head);
521 g_assert (seq->queue->head->data == begin_iter);
522 g_assert (seq->queue->tail);
523 g_assert (seq->queue->tail->data == penultimate_iter);
527 g_assert (penultimate_iter == end_iter);
528 g_assert (begin_iter == end_iter);
529 g_assert (penultimate_iter == begin_iter);
530 g_assert (seq->queue->head == NULL);
531 g_assert (seq->queue->tail == NULL);
535 case GET_ITER_AT_POS:
539 g_assert (g_queue_get_length (seq->queue) == g_sequence_get_length (seq->sequence));
541 for (i = 0; i < 10; ++i)
543 int pos = get_random_position (seq);
544 GSequenceIter *iter = g_sequence_get_iter_at_pos (seq->sequence, pos);
545 GList *link = g_queue_peek_nth_link (seq->queue, pos);
546 check_integrity (seq);
547 if (pos >= g_sequence_get_length (seq->sequence) || pos < 0)
549 g_assert (iter == g_sequence_get_end_iter (seq->sequence));
550 g_assert (link == NULL);
555 g_assert (link->data == iter);
562 for (i = 0; i < 10; ++i)
564 GSequenceIter *iter = g_sequence_append (seq->sequence, new_item (seq));
565 g_queue_push_tail (seq->queue, iter);
571 for (i = 0; i < 10; ++i)
573 GSequenceIter *iter = g_sequence_prepend (seq->sequence, new_item (seq));
574 g_queue_push_head (seq->queue, iter);
580 for (i = 0; i < 10; ++i)
583 GSequenceIter *iter = get_random_iter (seq, &link);
584 GSequenceIter *new_iter;
585 check_integrity (seq);
587 new_iter = g_sequence_insert_before (iter, new_item (seq));
589 queue_insert_before (seq, link, new_iter);
595 GList *link1, *link2;
596 SequenceInfo *seq1 = RANDOM_SEQUENCE();
597 SequenceInfo *seq2 = RANDOM_SEQUENCE();
598 GSequenceIter *iter1 = get_random_iter (seq1, &link1);
599 GSequenceIter *iter2 = get_random_iter (seq2, &link2);
601 if (!g_sequence_iter_is_end (iter1))
603 g_sequence_move (iter1, iter2);
606 g_assert (g_sequence_iter_is_end (iter2));
608 queue_insert_before (seq2, link2, link1->data);
610 g_queue_delete_link (seq1->queue, link1);
612 get_item (iter1)->seq = seq2;
618 check_integrity (seq);
620 iter1 = get_random_iter (seq, NULL);
622 /* Moving an iter to itself should have no effect */
623 if (!g_sequence_iter_is_end (iter1))
624 g_sequence_move (iter1, iter1);
629 GList *link1, *link2;
630 SequenceInfo *seq1 = RANDOM_SEQUENCE();
631 SequenceInfo *seq2 = RANDOM_SEQUENCE();
632 GSequenceIter *iter1 = get_random_iter (seq1, &link1);
633 GSequenceIter *iter2 = get_random_iter (seq2, &link2);
635 if (!g_sequence_iter_is_end (iter1) &&
636 !g_sequence_iter_is_end (iter2))
640 g_sequence_swap (iter1, iter2);
642 get_item (iter1)->seq = seq2;
643 get_item (iter2)->seq = seq1;
646 link1->data = link2->data;
656 g_sequence_sort (seq->sequence, compare_items, NULL);
657 g_queue_sort (seq->queue, compare_iters, NULL);
661 for (i = 0; i < N_TIMES; ++i)
663 GSequenceIter *iter =
664 g_sequence_insert_sorted (seq->sequence, new_item(seq), compare_items, NULL);
666 g_queue_insert_sorted (seq->queue, iter, compare_iters, NULL);
674 case INSERT_SORTED_ITER:
679 g_sequence_sort (seq->sequence, compare_items, NULL);
680 g_queue_sort (seq->queue, compare_iters, NULL);
684 for (i = 0; i < N_TIMES; ++i)
688 iter = g_sequence_insert_sorted_iter (seq->sequence,
690 (GSequenceIterCompareFunc)compare_iters,
693 g_queue_insert_sorted (seq->queue, iter, compare_iters, NULL);
705 g_sequence_sort (seq->sequence, compare_items, NULL);
706 g_queue_sort (seq->queue, compare_iters, NULL);
710 for (i = 0; i < N_TIMES; ++i)
713 GSequenceIter *iter = get_random_iter (seq, &link);
715 if (!g_sequence_iter_is_end (iter))
717 g_sequence_set (iter, new_item (seq));
718 g_sequence_sort_changed (iter, compare_items, NULL);
720 g_queue_delete_link (seq->queue, link);
721 g_queue_insert_sorted (seq->queue, iter, compare_iters, NULL);
728 case SORT_CHANGED_ITER:
732 g_sequence_sort (seq->sequence, compare_items, NULL);
733 g_queue_sort (seq->queue, compare_iters, NULL);
737 for (i = 0; i < N_TIMES; ++i)
740 GSequenceIter *iter = get_random_iter (seq, &link);
742 if (!g_sequence_iter_is_end (iter))
744 g_sequence_set (iter, new_item (seq));
745 g_sequence_sort_changed_iter (iter,
746 (GSequenceIterCompareFunc)compare_iters, seq->sequence);
748 g_queue_delete_link (seq->queue, link);
749 g_queue_insert_sorted (seq->queue, iter, compare_iters, NULL);
760 for (i = 0; i < N_TIMES; ++i)
763 GSequenceIter *iter = get_random_iter (seq, &link);
765 if (!g_sequence_iter_is_end (iter))
767 g_sequence_remove (iter);
768 g_queue_delete_link (seq->queue, link);
775 GSequenceIter *begin_iter, *end_iter;
776 GList *begin_link, *end_link;
779 get_random_range (seq, &begin_iter, &end_iter, &begin_link, &end_link);
781 g_sequence_remove_range (begin_iter, end_iter);
784 while (list != end_link)
786 GList *next = list->next;
788 g_queue_delete_link (seq->queue, list);
796 SequenceInfo *src = RANDOM_SEQUENCE();
797 SequenceInfo *dst = RANDOM_SEQUENCE();
799 GSequenceIter *begin_iter, *end_iter;
800 GList *begin_link, *end_link;
802 GSequenceIter *dst_iter;
807 g_assert (src->queue);
808 g_assert (dst->queue);
810 get_random_range (src, &begin_iter, &end_iter, &begin_link, &end_link);
811 dst_iter = get_random_iter (dst, &dst_link);
813 g_sequence_move_range (dst_iter, begin_iter, end_iter);
815 if (dst_link == begin_link || (src == dst && dst_link == end_link))
817 check_integrity (src);
818 check_integrity (dst);
822 if (queue_link_index (src, begin_link) >=
823 queue_link_index (src, end_link))
829 queue_link_index (src, dst_link) >= queue_link_index (src, begin_link) &&
830 queue_link_index (src, dst_link) <= queue_link_index (src, end_link))
836 while (list != end_link)
838 GList *next = list->next;
839 Item *item = get_item (list->data);
841 g_assert (dst->queue);
842 queue_insert_before (dst, dst_link, list->data);
843 g_queue_delete_link (src->queue, list);
845 g_assert (item->seq == src);
858 GSequenceIter *search_iter;
859 GSequenceIter *insert_iter;
861 g_sequence_sort (seq->sequence, compare_items, NULL);
862 g_queue_sort (seq->queue, compare_iters, NULL);
866 item = new_item (seq);
867 search_iter = g_sequence_search (seq->sequence, item, compare_items, NULL);
869 insert_iter = g_sequence_insert_sorted (seq->sequence, item, compare_items, NULL);
871 g_assert (search_iter == g_sequence_iter_next (insert_iter));
873 g_queue_insert_sorted (seq->queue, insert_iter, compare_iters, NULL);
879 GSequenceIter *search_iter;
880 GSequenceIter *insert_iter;
882 g_sequence_sort (seq->sequence, compare_items, NULL);
883 g_queue_sort (seq->queue, compare_iters, NULL);
887 item = new_item (seq);
888 search_iter = g_sequence_search_iter (seq->sequence,
890 (GSequenceIterCompareFunc)compare_iters, seq->sequence);
892 insert_iter = g_sequence_insert_sorted (seq->sequence, item, compare_items, NULL);
894 g_assert (search_iter == g_sequence_iter_next (insert_iter));
896 g_queue_insert_sorted (seq->queue, insert_iter, compare_iters, NULL);
907 iter = get_random_iter (seq, &link);
909 if (!g_sequence_iter_is_end (iter))
914 check_integrity (seq);
916 /* Test basic functionality */
917 item = new_item (seq);
918 g_sequence_set (iter, item);
919 g_assert (g_sequence_get (iter) == item);
921 /* Make sure that existing items are freed */
922 for (i = 0; i < N_TIMES; ++i)
923 g_sequence_set (iter, new_item (seq));
925 check_integrity (seq);
927 g_sequence_set (iter, new_item (seq));
932 /* operations on GSequenceIter * */
937 iter = g_sequence_get_iter_at_pos (seq->sequence, 0);
939 g_assert (g_sequence_iter_is_begin (iter));
941 check_integrity (seq);
943 if (g_sequence_get_length (seq->sequence) > 0)
945 g_assert (!g_sequence_iter_is_begin (g_sequence_get_end_iter (seq->sequence)));
949 g_assert (g_sequence_iter_is_begin (g_sequence_get_end_iter (seq->sequence)));
952 g_assert (g_sequence_iter_is_begin (g_sequence_get_begin_iter (seq->sequence)));
958 int len = g_sequence_get_length (seq->sequence);
960 iter = g_sequence_get_iter_at_pos (seq->sequence, len);
962 g_assert (g_sequence_iter_is_end (iter));
966 g_assert (!g_sequence_iter_is_end (g_sequence_get_begin_iter (seq->sequence)));
970 g_assert (g_sequence_iter_is_end (g_sequence_get_begin_iter (seq->sequence)));
973 g_assert (g_sequence_iter_is_end (g_sequence_get_end_iter (seq->sequence)));
978 GSequenceIter *iter1, *iter2, *iter3, *end;
980 iter1 = g_sequence_append (seq->sequence, new_item (seq));
981 iter2 = g_sequence_append (seq->sequence, new_item (seq));
982 iter3 = g_sequence_append (seq->sequence, new_item (seq));
984 end = g_sequence_get_end_iter (seq->sequence);
986 g_assert (g_sequence_iter_next (iter1) == iter2);
987 g_assert (g_sequence_iter_next (iter2) == iter3);
988 g_assert (g_sequence_iter_next (iter3) == end);
989 g_assert (g_sequence_iter_next (end) == end);
991 g_queue_push_tail (seq->queue, iter1);
992 g_queue_push_tail (seq->queue, iter2);
993 g_queue_push_tail (seq->queue, iter3);
998 GSequenceIter *iter1, *iter2, *iter3, *begin;
1000 iter1 = g_sequence_prepend (seq->sequence, new_item (seq));
1001 iter2 = g_sequence_prepend (seq->sequence, new_item (seq));
1002 iter3 = g_sequence_prepend (seq->sequence, new_item (seq));
1004 begin = g_sequence_get_begin_iter (seq->sequence);
1006 g_assert (g_sequence_iter_prev (iter1) == iter2);
1007 g_assert (g_sequence_iter_prev (iter2) == iter3);
1008 g_assert (iter3 == begin);
1009 g_assert (g_sequence_iter_prev (iter3) == begin);
1010 g_assert (g_sequence_iter_prev (begin) == begin);
1012 g_queue_push_head (seq->queue, iter1);
1013 g_queue_push_head (seq->queue, iter2);
1014 g_queue_push_head (seq->queue, iter3);
1017 case ITER_GET_POSITION:
1020 GSequenceIter *iter = get_random_iter (seq, &link);
1022 g_assert (g_sequence_iter_get_position (iter) ==
1023 queue_link_index (seq, link));
1028 int len = g_sequence_get_length (seq->sequence);
1029 GSequenceIter *iter;
1032 iter = get_random_iter (seq, NULL);
1033 pos = g_sequence_iter_get_position (iter);
1034 iter = g_sequence_iter_move (iter, len - pos);
1035 g_assert (g_sequence_iter_is_end (iter));
1038 iter = get_random_iter (seq, NULL);
1039 pos = g_sequence_iter_get_position (iter);
1042 g_assert (!g_sequence_iter_is_end (iter));
1044 iter = g_sequence_iter_move (iter, 1);
1046 g_assert (g_sequence_iter_is_end (iter));
1049 case ITER_GET_SEQUENCE:
1051 GSequenceIter *iter = get_random_iter (seq, NULL);
1053 g_assert (g_sequence_iter_get_sequence (iter) == seq->sequence);
1060 GList *link1, *link2;
1061 GSequenceIter *iter1 = get_random_iter (seq, &link1);
1062 GSequenceIter *iter2 = get_random_iter (seq, &link2);
1064 int cmp = g_sequence_iter_compare (iter1, iter2);
1065 int pos1 = queue_link_index (seq, link1);
1066 int pos2 = queue_link_index (seq, link2);
1070 g_assert (pos1 == pos2);
1074 g_assert (pos1 < pos2);
1078 g_assert (pos1 > pos2);
1082 case RANGE_GET_MIDPOINT:
1084 GSequenceIter *iter1 = get_random_iter (seq, NULL);
1085 GSequenceIter *iter2 = get_random_iter (seq, NULL);
1086 GSequenceIter *iter3;
1089 cmp = g_sequence_iter_compare (iter1, iter2);
1100 iter3 = g_sequence_range_get_midpoint (iter1, iter2);
1104 g_assert (iter3 == iter1);
1105 g_assert (iter3 == iter2);
1108 g_assert (g_sequence_iter_get_position (iter3) >=
1109 g_sequence_iter_get_position (iter1));
1110 g_assert (g_sequence_iter_get_position (iter2) >=
1111 g_sequence_iter_get_position (iter3));
1117 check_integrity (seq);
1121 /* Random seeds known to have failed at one point
1123 static gulong seeds[] =
1137 static void standalone_tests (void);
1140 get_seed (int argc, char **argv)
1146 return strtol (argv[1], &endptr, 0);
1150 return g_random_int();
1158 guint32 seed = get_seed (argc, argv);
1160 #ifdef __SYMBIAN32__
1161 g_log_set_handler (NULL, G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL);
1162 g_set_print_handler(mrtPrintHandler);
1163 #endif /*__SYMBIAN32__*/
1164 /* Run stand alone tests */
1165 g_print ("running standalone tests\n");
1168 g_print ("running regression tests:\n");
1169 /* Run regression tests */
1170 for (i = 0; i < G_N_ELEMENTS (seeds); ++i)
1172 run_random_tests (seeds[i]);
1175 /* Run with a new random seed */
1176 g_print ("random seed:\n");
1177 run_random_tests (seed);
1180 testResultXml("sequence-test");
1181 #endif /* EMULATOR */
1186 /* Single, stand-alone tests */
1189 test_out_of_range_jump (void)
1191 GSequence *seq = g_sequence_new (NULL);
1192 GSequenceIter *iter = g_sequence_get_begin_iter (seq);
1194 g_sequence_iter_move (iter, 5);
1196 g_assert (g_sequence_iter_is_begin (iter));
1197 g_assert (g_sequence_iter_is_end (iter));
1201 compare (gconstpointer a, gconstpointer b, gpointer userdata)
1205 ai = GPOINTER_TO_INT (a);
1206 bi = GPOINTER_TO_INT (b);
1217 compare_iter (GSequenceIter *a,
1221 return compare (g_sequence_get (a),
1227 test_insert_sorted_non_pointer (void)
1231 for (i = 0; i < 10; i++)
1233 GSequence *seq = g_sequence_new (NULL);
1236 for (j = 0; j < 10000; j++)
1238 g_sequence_insert_sorted (seq, GINT_TO_POINTER (g_random_int()),
1241 g_sequence_insert_sorted_iter (seq, GINT_TO_POINTER (g_random_int()),
1242 compare_iter, NULL);
1245 g_sequence_check (seq);
1247 g_sequence_free (seq);
1252 test_stable_sort (void)
1255 GSequence *seq = g_sequence_new (NULL);
1257 #define N_ITEMS 1000
1259 GSequenceIter *iters[N_ITEMS];
1260 GSequenceIter *iter;
1262 for (i = 0; i < N_ITEMS; ++i)
1264 iters[i] = g_sequence_append (seq, GINT_TO_POINTER (3000));
1265 g_sequence_check (seq);
1266 g_assert (g_sequence_iter_get_sequence (iters[i]) == seq);
1270 iter = g_sequence_get_begin_iter (seq);
1271 g_assert (g_sequence_iter_get_sequence (iter) == seq);
1272 g_sequence_check (seq);
1273 while (!g_sequence_iter_is_end (iter))
1275 g_assert (g_sequence_iter_get_sequence (iters[i]) == seq);
1276 g_assert (iters[i++] == iter);
1278 iter = g_sequence_iter_next (iter);
1279 g_sequence_check (seq);
1282 g_sequence_sort (seq, compare, NULL);
1285 iter = g_sequence_get_begin_iter (seq);
1286 while (!g_sequence_iter_is_end (iter))
1288 g_assert (g_sequence_iter_get_sequence (iters[i]) == seq);
1289 g_assert (iters[i] == iter);
1291 iter = g_sequence_iter_next (iter);
1292 g_sequence_check (seq);
1297 for (i = N_ITEMS - 1; i >= 0; --i)
1299 g_sequence_check (seq);
1300 g_assert (g_sequence_iter_get_sequence (iters[i]) == seq);
1301 g_assert (g_sequence_get_end_iter (seq) != iters[i]);
1302 g_sequence_sort_changed (iters[i], compare, NULL);
1306 iter = g_sequence_get_begin_iter (seq);
1307 while (!g_sequence_iter_is_end (iter))
1309 g_assert (iters[i++] == iter);
1311 iter = g_sequence_iter_next (iter);
1312 g_sequence_check (seq);
1317 standalone_tests (void)
1319 test_out_of_range_jump ();
1320 test_insert_sorted_non_pointer ();
1321 test_stable_sort ();