diff --git a/CMakeLists.txt b/CMakeLists.txt index f6a3556..2193cb2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # C Floppy Version set(CFL_VERSION_MAJOR 0) set(CFL_VERSION_MINOR 5) -set(CFL_VERSION_PATCH 0) +set(CFL_VERSION_PATCH 1) set(CFL_VERSION_STR "${CFL_VERSION_MAJOR}.${CFL_VERSION_MINOR}.${CFL_VERSION_PATCH}") # Configuration options diff --git a/include/cfl/cfl.h b/include/cfl/cfl.h index 8e4efa7..48e2b0d 100644 --- a/include/cfl/cfl.h +++ b/include/cfl/cfl.h @@ -39,5 +39,6 @@ #include int cfl_init(); +char *cfl_version(); #endif diff --git a/src/cfl.c b/src/cfl.c index 7afb110..426319a 100644 --- a/src/cfl.c +++ b/src/cfl.c @@ -17,7 +17,15 @@ * limitations under the License. */ +#include + int cfl_init() { return 0; } + +char *cfl_version() +{ + return CFL_VERSION_STR; +} + diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 13d113c..1fc231a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -9,6 +9,7 @@ set(UNIT_TESTS_FILES list.c variant.c object.c + version.c ) configure_file( diff --git a/tests/list.c b/tests/list.c index 0c12f88..9717be4 100644 --- a/tests/list.c +++ b/tests/list.c @@ -2,7 +2,7 @@ /* CFL * === - * Copyright (C) 2022 The CFL Authors + * Copyright (C) 2022-2024 The CFL Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ */ #include - #include "cfl_tests_internal.h" struct test { @@ -27,24 +26,74 @@ struct test { static void checks() { - struct test *t; - struct cfl_list list; + struct test *t; + struct cfl_list list; + + cfl_list_init(&list); + TEST_CHECK(cfl_list_is_empty(&list)); + + t = malloc(sizeof(struct test)); + cfl_list_add(&t->_head, &list); + TEST_CHECK(!cfl_list_is_empty(&list)); + + cfl_list_del(&t->_head); + TEST_CHECK(cfl_list_is_empty(&list)); + + free(t); +} + +static void add() +{ + int i; + int count = 0; + struct cfl_list list; + struct cfl_list *head; + struct cfl_list *tmp; + + struct node { + int value; + struct cfl_list _head; + }; + + struct node **nodes; + struct node *node; + + nodes = malloc(sizeof(struct node *) * 3); + for (i = 0; i < 3; i++) { + nodes[i] = malloc(sizeof(struct node)); + nodes[i]->value = i; + } + + cfl_list_init(&list); + cfl_list_add(&nodes[0]->_head, &list); + cfl_list_add(&nodes[2]->_head, &list); + - cfl_list_init(&list); - TEST_CHECK(cfl_list_is_empty(&list)); + node = nodes[2]; + cfl_list_add_before(&nodes[1]->_head, &node->_head, &list); - t = malloc(sizeof(struct test)); - cfl_list_add(&t->_head, &list); - TEST_CHECK(!cfl_list_is_empty(&list)); + /* print all nodes */ + printf("\n"); + cfl_list_foreach(head, &list) { + node = cfl_list_entry(head, struct node, _head); + printf("node value: %d\n", node->value); + count++; + } + TEST_CHECK(count == 3); - cfl_list_del(&t->_head); - TEST_CHECK(cfl_list_is_empty(&list)); + cfl_list_foreach_safe(head, tmp, &list) { + node = cfl_list_entry(head, struct node, _head); + cfl_list_del(&node->_head); + free(node); + count++; + } - free(t); + free(nodes); } TEST_LIST = { {"checks", checks}, + {"add", add}, { 0 } }; diff --git a/tests/version.c b/tests/version.c new file mode 100644 index 0000000..4d1510b --- /dev/null +++ b/tests/version.c @@ -0,0 +1,37 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* CFL + * === + * Copyright (C) 2022 The CFL Authors + * + * 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. + */ + +#include +#include "cfl_tests_internal.h" + +static void test_version() +{ + char *v; + + v = cfl_version(); + TEST_CHECK(v != NULL); + TEST_CHECK(strlen(v) >= 5); + + printf("CFL VERSION => '%s'\n", v); +} + +TEST_LIST = { + { "version" , test_version }, + { 0 } +};