summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2008-12-16 19:26:32 (EST)
committer ticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2008-12-16 19:26:32 (EST)
commit4a5627af1ecf0061c99409f4a3b4e84de5e58f30 (patch)
tree6d45577650af682ccd329fc228e2076fe4b6d6dc /tests
parentda40af11f7cdf54b484c8aae73d6201694e6c234 (diff)
introduce the active_list for searching.
introduce the active_list_sort git-svn-id: http://opkg.googlecode.com/svn/trunk@181 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358
Diffstat (limited to 'tests')
-rw-r--r--tests/opkg_active_list_test.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/tests/opkg_active_list_test.c b/tests/opkg_active_list_test.c
index 77819b0..4792eae 100644
--- a/tests/opkg_active_list_test.c
+++ b/tests/opkg_active_list_test.c
@@ -94,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;
@@ -102,16 +119,21 @@ int main (void) {
make_list(&head);
printf("pos order: ");
- for(ptr = active_list_next(&head, &head); ptr ;ptr = active_list_next(&head, ptr)) {
+ 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("\nneg order: ");
+ }*/
+ 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("\nafter clear: ");
+ 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);