And make the install command work. WTF?
[oweals/opkg-lede.git] / tests / opkg_active_list_test.c
index f7bd390e181b9ffd68d8e644f1a548fbea2ee021..4792eae3c184d485c971d48ec97d0049719b09eb 100644 (file)
@@ -48,7 +48,8 @@ void active_test_add_depend(struct active_test *A, struct active_test *B) {
              |_M      |_O
 
 Then the sequence will be 
-G M H I O J A B K N L C D E F
++: G M H I O J A B K N L C D E F
+-: F E D C L N K B A J O I H M G
 */
 void make_list(struct active_list *head) {
     struct active_test *A = active_test_new("A");
@@ -93,6 +94,23 @@ void make_list(struct active_list *head) {
     active_test_add_depend(L, N);
 }
 
+int active_test_compare(const void *a, const void *b) {
+    struct active_list *first = (struct active_list *)a;
+    struct active_list *second = (struct active_list *)b;
+    return strcmp(list_entry(first, struct active_test, list),
+            list_entry(second, struct active_test, list));
+}
+
+void show_list(struct active_list *head) {
+    struct active_list *ptr;
+    struct active_test *test;
+    for(ptr = active_list_next(head, NULL); ptr ;ptr = active_list_next(head, ptr)) {
+        test = list_entry(ptr, struct active_test, list);
+        printf ("%s ",test->str);
+    }
+    printf("\n");
+}
+
 int main (void) {
     struct active_list head;
     struct active_list *ptr;
@@ -100,16 +118,23 @@ int main (void) {
     active_list_init(&head);
     make_list(&head);
 
-    for(ptr = active_list_next(&head, &head); ptr ;ptr = active_list_next(&head, ptr)) {
+    printf("pos order: ");
+    show_list(&head);
+/*    for(ptr = active_list_next(&head, &head); ptr ;ptr = active_list_next(&head, ptr)) {
         test = list_entry(ptr, struct active_test, list);
         printf ("%s ",test->str);
-    }
-    printf("\n");
-    for(ptr = active_list_next(&head, &head); ptr ;ptr = active_list_next(&head, ptr)) {
+    }*/
+    printf("neg order: ");
+    for(ptr = active_list_prev(&head, &head); ptr ;ptr = active_list_prev(&head, ptr)) {
         test = list_entry(ptr, struct active_test, list);
         printf ("%s ",test->str);
     }
-    printf("\n");
+    printf("\npos order after sort: ");
+    active_list_sort(&head, &active_test_compare);
+    show_list(&head);
+
+    printf("after clear: ");
+    active_list_clear(&head);
     for(ptr = active_list_next(&head, NULL); ptr ;ptr = active_list_next(&head, ptr)) {
         test = list_entry(ptr, struct active_test, list);
         printf ("%s ",test->str);