Update to work with older check 0.10

This commit is contained in:
2022-05-13 15:47:23 -04:00
parent 89fa8b72ec
commit 3626f70cb1
5 changed files with 80 additions and 22 deletions

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project(EmberLib C)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_EXTENSIONS OFF)
@@ -27,45 +27,80 @@ if(NOT DEFINED BUILD_TESTS)
set(BUILD_TESTS FALSE)
endif(NOT DEFINED BUILD_TESTS)
###############################################################################
# Set build features
set(CMAKE_BUILD_TYPE Debug)
###############################################################################
include(CheckCSourceCompiles)
include(CheckCSourceRuns)
include(CheckFunctionExists)
include(CheckIncludeFile)
include(CheckIncludeFiles)
include(CheckLibraryExists)
include(CheckSymbolExists)
include(CheckTypeSize)
# Check Headers
###############################################################################
# Check headers
set(INCLUDES "")
macro(ck_check_include_file header var)
check_include_file("${INCLUDES};${header}" ${var})
if(${var})
set(INCLUDES ${INCLUDES} ${header})
endif(${var})
check_include_files("${INCLUDES};${header}" ${var})
if(${var})
set(INCLUDES ${INCLUDES} ${header})
endif(${var})
endmacro(ck_check_include_file)
ck_check_include_file("stdlib.h" HAVE_STDLIB_H)
###############################################################################
# Check functions
# (Nothing to check for the money example)
###############################################################################
# Check defines
# (Nothing to check for the money example)
###############################################################################
# Check struct members
# (Nothing to check for the money example)
###############################################################################
# Check for integer types
# (The following are used in check.h. Regardless if they are used in
# the project, they will need to be checked in order to use Check).
check_type_size(intmax_t INTMAX_T)
check_type_size(uintmax_t UINTMMAX_T)
check_type_size(uintmax_t UINTMAX_T)
check_type_size(pid_t PID_T)
if(NOT HAVE_PID_T)
if(WIN32)
set(pid_t "int")
else(WIN32)
MESSAGE(FATAL_ERROR "pid_t doesn't exist on this platform?")
endif(WIN32)
if(WIN32)
set(pid_t "int")
else(WIN32)
MESSAGE(FATAL_ERROR "pid_t doesn't exist on this platform?")
endif(WIN32)
endif(NOT HAVE_PID_T)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
###############################################################################
# Check libraries
###############################################################################
# Generate "config.h" from "cmake/config.h.cmake"
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.in
${CMAKE_CURRENT_BINARY_DIR}/config.h)
include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
add_definitions(-DHAVE_CONFIG_H)
set(CONFIG_HEADER ${CMAKE_CURRENT_BINARY_DIR/config.h})
set(CONFIG_HEADER ${CMAKE_CURRENT_BINARY_DIR}/config.h)
add_subdirectory(src)
add_subdirectory(demo)
set(BUILD_TESTS TRUE)
if(${BUILD_TESTS})
add_subdirectory(tests)
# Unit tests
enable_testing()
endif(${BUILD_TESTS})
enable_testing()

View File

@@ -7,6 +7,8 @@
#ifdef WIN32
#include <windows.h>
#else
#define __USE_BSD
#include <stddef.h>
#include <sys/time.h>
#include <sys/resource.h>
#endif
@@ -20,8 +22,7 @@ double get_time()
return (double)t.QuadPart/(double)f.QuadPart;
#else
struct timeval t;
struct timezone tzp;
gettimeofday(&t, &tzp);
gettimeofday(&t, NULL);
return (double)t.tv_sec + t.tv_usec*1e-6;
#endif
}
}

View File

@@ -4,6 +4,7 @@ if(${BUILD_TESTS})
#
# set(CHECK_INSTALL_DIR "C:/Program Files/check")
find_package(Check REQUIRED)
include_directories(${CHECK_INCLUDE_DIRS})
set(TEST_HEADERS check_util.h)
set(TEST_SOURCE check_util.c)
@@ -14,19 +15,31 @@ if(${BUILD_TESTS})
set(EMBER_STRING_TEST_SOURCES ${TEST_HEADERS} ${TEST_SOURCE}
check_ember_string.c)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
find_package(Check REQUIRED)
add_executable(test_arraylist ${ARRAYLIST_TEST_SOURCES})
add_executable(test_ember_string ${EMBER_STRING_TEST_SOURCES})
target_link_directories(test_arraylist PRIVATE ${CHECK_LIBRARY_DIRS})
target_link_libraries(test_arraylist PRIVATE Threads::Threads)
target_link_libraries(test_arraylist PRIVATE ${CHECK_LIBRARIES})
target_link_libraries(test_arraylist PRIVATE m)
target_link_libraries(test_arraylist PRIVATE rt)
target_link_libraries(test_arraylist PRIVATE subunit)
target_link_libraries(test_arraylist PRIVATE EmberLib)
target_link_directories(test_ember_string PRIVATE ${CHECK_LIBRARY_DIRS})
target_link_libraries(test_ember_string PRIVATE Threads::Threads)
target_link_libraries(test_ember_string PRIVATE ${CHECK_LIBRARIES})
target_link_libraries(test_ember_string PRIVATE m)
target_link_libraries(test_ember_string PRIVATE rt)
target_link_libraries(test_ember_string PRIVATE subunit)
target_link_libraries(test_ember_string PRIVATE EmberLib)
enable_testing()
add_test(NAME test_arraylist COMMAND test_arraylist)
add_test(NAME test_ember_string COMMAND test_ember_string)
add_test(NAME test_emberlist COMMAND test_arraylist)
add_test(NAME test_emberstring COMMAND test_ember_string)
endif(${BUILD_TESTS})

View File

@@ -2,9 +2,13 @@
* Created by Aaron Helton on 11/22/19
*/
#include <EmberLib/Util/EmberString.h>
#include <stddef.h>
#include <stdlib.h>
#include <check.h>
#define ck_assert_ptr_null(A) ck_assert_ptr_eq(A, NULL)
#define ck_assert_ptr_nonnull(A) ck_assert_ptr_ne(A, NULL)
START_TEST(test_ember_string_from_cstr)
{
char *TEST_STR_1 = "Test_String_One";
@@ -364,13 +368,14 @@ START_TEST(test_ember_string_compare)
destroy_estring(test3);
destroy_estring(empty);
}
END_TEST
Suite *ember_string_suite(void)
{
Suite *s;
TCase *tc_core;
s = suite_create("Arraylist_New");
s = suite_create("EmberString");
/* Core Test Case */
tc_core = tcase_create("Core");

View File

@@ -4,9 +4,13 @@
#include <EmberLib/Util/EmberList.h>
#include "check_util.h"
#include <stddef.h>
#include <stdlib.h>
#include <check.h>
#define ck_assert_ptr_nonnull(A) ck_assert_ptr_ne(A, NULL)
#define ck_assert_ptr_null(A) ck_assert_ptr_eq(A, NULL)
START_TEST(test_arraylist_int_create_destroy)
{
size_t expected_size = sizeof(size_t) * 3 + sizeof(int);
@@ -596,7 +600,7 @@ Suite *arraylist_suite(void)
Suite *s;
TCase *tc_core;
s = suite_create("Arraylist_New");
s = suite_create("EmberList");
/* Core Test Case */
tc_core = tcase_create("Core");