summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Shaw <jshaw@netsurf-browser.org>2007-09-22 23:10:33 +0000
committerJames Shaw <jshaw@netsurf-browser.org>2007-09-22 23:10:33 +0000
commit060cc88e1727f3e56b03651b4471858fd9d49f41 (patch)
tree09349492b29ee28f0402d81b888677822b0cb51b
parentbac4a13febf82bea5c188c45d32fcedc7e868597 (diff)
downloadlibdom-060cc88e1727f3e56b03651b4471858fd9d49f41.tar.gz
libdom-060cc88e1727f3e56b03651b4471858fd9d49f41.tar.bz2
Extend list implementation, add test-list.c to test some of it.
svn path=/trunk/dom/; revision=3574
-rwxr-xr-xtest/test-listbin0 -> 12634 bytes
-rw-r--r--test/test-list.c56
2 files changed, 56 insertions, 0 deletions
diff --git a/test/test-list b/test/test-list
new file mode 100755
index 0000000..7253a85
--- /dev/null
+++ b/test/test-list
Binary files differ
diff --git a/test/test-list.c b/test/test-list.c
new file mode 100644
index 0000000..7871286
--- /dev/null
+++ b/test/test-list.c
@@ -0,0 +1,56 @@
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "testutils.h"
+
+void test_add_remove(void);
+void test_contains_all_true(void);
+
+void test_add_remove(void)
+{
+ struct list* list = list_new();
+
+ char s[] = "hello";
+
+ /* add element */
+ list_add(list, s);
+ assert(strcmp(list->head->data, "hello") == 0);
+ assert(list->size == 1);
+
+ /* remove element */
+ bool found = list_remove(list, s);
+ assert(found == true);
+ assert(list->size == 0);
+ assert(list->head == NULL);
+
+ list_destroy(list);
+}
+
+void test_contains_all_true(void)
+{
+ struct list* superList = list_new();
+ struct list* subList = list_new();
+
+ list_add(superList, (void*) "hello");
+ list_add(superList, (void*) "world");
+
+ list_add(subList, (void*) "hello");
+
+ bool b = list_contains_all(superList, subList, (comparator) strcmp);
+ assert(b == true);
+ assert(superList->size == 2);
+ assert(superList->head->next->next == NULL);
+
+ list_destroy(superList);
+ list_destroy(subList);
+}
+
+int main(void)
+{
+ test_add_remove();
+ test_contains_all_true();
+ //test_different_size_lists();
+
+ printf("PASS\n");
+}