list: Rename struct list to struct ovs_list
[cascardo/ovs.git] / tests / test-list.c
index 5e62e0c..5fd7149 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009, 2010 Nicira Networks.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2014 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * list.h. */
 
 #include <config.h>
-#include "list.h"
-#include <string.h>
-
 #undef NDEBUG
+#include "list.h"
 #include <assert.h>
+#include <string.h>
+#include "ovstest.h"
 
 /* Sample list element. */
 struct element {
     int value;
-    struct list node;
+    struct ovs_list node;
 };
 
 /* Puts the 'n' values in 'values' into 'elements', and then puts those
  * elements in order into 'list'. */
 static void
-make_list(struct list *list, struct element elements[],
+make_list(struct ovs_list *list, struct element elements[],
           int values[], size_t n)
 {
     size_t i;
@@ -49,7 +49,7 @@ make_list(struct list *list, struct element elements[],
 /* Verifies that 'list' contains exactly the 'n' values in 'values', in the
  * specified order. */
 static void
-check_list(struct list *list, const int values[], size_t n)
+check_list(struct ovs_list *list, const int values[], size_t n)
 {
     struct element *e;
     size_t i;
@@ -73,13 +73,15 @@ check_list(struct list *list, const int values[], size_t n)
     assert(i == n);
 
     assert(list_is_empty(list) == !n);
+    assert(list_is_singleton(list) == (n == 1));
+    assert(list_is_short(list) == (n < 2));
     assert(list_size(list) == n);
 }
 
 #if 0
 /* Prints the values in 'list', plus 'name' as a title. */
 static void
-print_list(const char *name, struct list *list)
+print_list(const char *name, struct ovs_list *list)
 {
     struct element *e;
 
@@ -101,7 +103,7 @@ test_list_construction(void)
     for (n = 0; n <= MAX_ELEMS; n++) {
         struct element elements[MAX_ELEMS];
         int values[MAX_ELEMS];
-        struct list list;
+        struct ovs_list list;
 
         make_list(&list, elements, values, n);
         check_list(&list, values, n);
@@ -121,7 +123,7 @@ test_list_for_each_safe(void)
         for (pattern = 0; pattern < 1ul << n; pattern++) {
             struct element elements[MAX_ELEMS];
             int values[MAX_ELEMS];
-            struct list list;
+            struct ovs_list list;
             struct element *e, *next;
             size_t values_idx, n_remaining;
             int i;
@@ -164,12 +166,12 @@ run_test(void (*function)(void))
     printf(".");
 }
 
-int
-main(void)
+static void
+test_list_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
 {
     run_test(test_list_construction);
     run_test(test_list_for_each_safe);
     printf("\n");
-    return 0;
 }
 
+OVSTEST_REGISTER("test-list", test_list_main);