X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tests%2Ftest-list.c;h=5cba959d23ed5943b70aaa71fcf03f917f51d9df;hb=c5cf10598f8c9f4428291e9df3ecd72a05fb1ccf;hp=62857be9489b4859df71c5cc53c7755c5efac4a5;hpb=064af42167bf4fc9aaea2702d80ce08074b889c0;p=sliver-openvswitch.git diff --git a/tests/test-list.c b/tests/test-list.c index 62857be94..5cba959d2 100644 --- a/tests/test-list.c +++ b/tests/test-list.c @@ -1,9 +1,26 @@ +/* + * 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. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* A non-exhaustive test for some of the functions and macros declared in * list.h. */ #include #include "list.h" #include +#include "ovstest.h" #undef NDEBUG #include @@ -18,10 +35,10 @@ struct element { * elements in order into 'list'. */ static void make_list(struct list *list, struct element elements[], - int values[], size_t n) + int values[], size_t n) { size_t i; - + list_init(list); for (i = 0; i < n; i++) { elements[i].value = i; @@ -33,13 +50,13 @@ 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 list *list, const int values[], size_t n) { struct element *e; size_t i; - + i = 0; - LIST_FOR_EACH (e, struct element, node, list) { + LIST_FOR_EACH (e, node, list) { assert(i < n); assert(e->value == values[i]); i++; @@ -48,7 +65,7 @@ check_list(struct list *list, const int values[], size_t n) assert(i == n); i = 0; - LIST_FOR_EACH_REVERSE (e, struct element, node, list) { + LIST_FOR_EACH_REVERSE (e, node, list) { assert(i < n); assert(e->value == values[n - i - 1]); i++; @@ -57,18 +74,20 @@ 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 list *list) { struct element *e; - + printf("%s:", name); - LIST_FOR_EACH (e, struct element, node, list) { + LIST_FOR_EACH (e, node, list) { printf(" %d", e->value); } printf("\n"); @@ -77,7 +96,7 @@ print_list(const char *name, struct list *list) /* Tests basic list construction. */ static void -test_list_construction(void) +test_list_construction(void) { enum { MAX_ELEMS = 100 }; size_t n; @@ -86,7 +105,7 @@ test_list_construction(void) struct element elements[MAX_ELEMS]; int values[MAX_ELEMS]; struct list list; - + make_list(&list, elements, values, n); check_list(&list, values, n); } @@ -95,7 +114,7 @@ test_list_construction(void) /* Tests that LIST_FOR_EACH_SAFE properly allows for deletion of the current * element of a list. */ static void -test_list_for_each_safe(void) +test_list_for_each_safe(void) { enum { MAX_ELEMS = 10 }; size_t n; @@ -109,13 +128,13 @@ test_list_for_each_safe(void) struct element *e, *next; size_t values_idx, n_remaining; int i; - + make_list(&list, elements, values, n); i = 0; values_idx = 0; n_remaining = n; - LIST_FOR_EACH_SAFE (e, next, struct element, node, &list) { + LIST_FOR_EACH_SAFE (e, next, node, &list) { assert(i < n); if (pattern & (1ul << i)) { list_remove(&e->node); @@ -142,18 +161,18 @@ test_list_for_each_safe(void) } static void -run_test(void (*function)(void)) +run_test(void (*function)(void)) { function(); 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);