migrate utils tests - relates to #342

Wed, 20 Dec 2023 17:57:18 +0100

author
Mike Becker <universe@uap-core.de>
date
Wed, 20 Dec 2023 17:57:18 +0100
changeset 767
d31f4d4075dc
parent 766
e59b76889f00
child 768
0e1cf2cd500e

migrate utils tests - relates to #342

src/cx/test.h file | annotate | diff | comparison | revisions
tests/.clang-tidy file | annotate | diff | comparison | revisions
tests/CMakeLists.txt file | annotate | diff | comparison | revisions
tests/Makefile file | annotate | diff | comparison | revisions
tests/test_utils.c file | annotate | diff | comparison | revisions
tests/test_utils.cpp file | annotate | diff | comparison | revisions
tests/test_utils.h file | annotate | diff | comparison | revisions
tests/ucxtest.c file | annotate | diff | comparison | revisions
--- a/src/cx/test.h	Wed Dec 20 16:46:14 2023 +0100
+++ b/src/cx/test.h	Wed Dec 20 17:57:18 2023 +0100
@@ -48,16 +48,13 @@
  * 
  * CX_TEST(function_name) {
  *   // memory allocation and other stuff here
- *   #CX_TEST_BEGIN
- *   // tests with CX_TEST_ASSERT() and/or
- *   // calls with CX_TEST_CALL_SUBROUTINE() here
- *   #CX_TEST_END
+ *   #CX_TEST_DO {
+ *     // tests with CX_TEST_ASSERT() and/or
+ *     // calls with CX_TEST_CALL_SUBROUTINE() here
+ *   }
  *   // cleanup of memory here
  * }
  * </pre>
- *
- * @remark if a test fails, execution continues at the
- * #CX_TEST_END macro! So make sure every necessary cleanup happens afterwards.
  * 
  * @attention Do not call own functions within a test, that use
  * CX_TEST_ASSERT() macros and are not defined by using CX_TEST_SUBROUTINE().
@@ -252,17 +249,18 @@
 #define CX_TEST(name) void name(CxTestSuite* _suite_,void *_output_, cx_write_func _writefnc_)
 
 /**
- * Marks the begin of a test.
- * <b>Note:</b> Any CX_TEST_ASSERT() calls must be performed <b>after</b>
- * #CX_TEST_BEGIN.
- * 
- * @see #CX_TEST_END
+ * Defines the scope of a test.
+ * @attention Any CX_TEST_ASSERT() calls must be performed in scope of
+ * #CX_TEST_DO.
  */
-#define CX_TEST_BEGIN _writefnc_("Running ", 1, 8, _output_);\
+#define CX_TEST_DO _writefnc_("Running ", 1, 8, _output_);\
         _writefnc_(__FUNCTION__, 1, strlen(__FUNCTION__), _output_);\
         _writefnc_("... ", 1, 4, _output_);\
-        jmp_buf _env_; \
-        if (!setjmp(_env_)) {
+        jmp_buf _env_;\
+        for (unsigned int _cx_test_loop_ = 0 ;\
+             _cx_test_loop_ == 0 && !setjmp(_env_);\
+             _writefnc_("success.\n", 1, 9, _output_),\
+             _suite_->success++, _cx_test_loop_++)
 
 /**
  * Checks a test assertion.
@@ -272,11 +270,22 @@
  * @param condition the condition to check
  * @param message the message that shall be printed out on failure
  */
-#define CX_TEST_ASSERT(condition,message) if (!(condition)) { \
-        _writefnc_(message".\n", 1, 2+strlen(message), _output_); \
+#define CX_TEST_ASSERTM(condition,message) if (!(condition)) { \
+        char const* _assert_msg_ = message; \
+        _writefnc_(_assert_msg_, 1, strlen(_assert_msg_), _output_); \
+        _writefnc_(".\n", 1, 2, _output_); \
         _suite_->failure++; \
         longjmp(_env_, 1);\
-    }
+    } (void) 0
+
+/**
+ * Checks a test assertion.
+ * If the assertion is correct, the test carries on. If the assertion is not
+ * correct, the specified message (terminated by a dot and a line break) is
+ * written to the test suites output stream.
+ * @param condition the condition to check
+ */
+#define CX_TEST_ASSERT(condition) CX_TEST_ASSERTM(condition, #condition " failed")
 
 /**
  * Macro for a test subroutine function header.
@@ -298,8 +307,7 @@
  * Subroutines declared with CX_TEST_SUBROUTINE() can be called by using this
  * macro.
  * 
- * <b>Note:</b> You may <b>only</b> call subroutines within a #CX_TEST_BEGIN-
- * #CX_TEST_END-block.
+ * @remark You may <b>only</b> call subroutines within a #CX_TEST_DO block.
  * 
  * @param name the name of the subroutine
  * @param ... the argument list
@@ -309,15 +317,6 @@
 #define CX_TEST_CALL_SUBROUTINE(name,...) \
         name(_suite_,_output_,_writefnc_,_env_,__VA_ARGS__);
 
-/**
- * Marks the end of a test.
- * <b>Note:</b> Any CX_TEST_ASSERT() calls must be performed <b>before</b>
- * #CX_TEST_END.
- * 
- * @see #CX_TEST_BEGIN
- */
-#define CX_TEST_END _writefnc_("success.\n", 1, 9, _output_); _suite_->success++;}
-
 #ifdef	__cplusplus
 }
 #endif
--- a/tests/.clang-tidy	Wed Dec 20 16:46:14 2023 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
-# Disable static initialization warning for test code
-Checks: '-cert-err58-cpp'
--- a/tests/CMakeLists.txt	Wed Dec 20 16:46:14 2023 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-cmake_minimum_required(VERSION 3.14)
-project(ucxtest VERSION 3.0 DESCRIPTION "UAP Common Extensions - Tests")
-
-# Configuration
-cmake_policy(SET CMP0077 NEW)
-set(CMAKE_CXX_STANDARD 17)
-enable_testing()
-
-# Load Google Test Framework
-option(INSTALL_GTEST "By default googletest shall not be installed." OFF)
-option(BUILD_GMOCK "In this project we do not need gmock." OFF)
-include(FetchContent)
-FetchContent_Declare(
-        googletest
-        GIT_REPOSITORY https://github.com/google/googletest.git
-        GIT_TAG e2239ee6043f73722e7aa812a459f54a28552929 # release 1.11.0
-)
-# For Windows: Prevent overriding the parent project's compiler/linker settings
-set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
-FetchContent_MakeAvailable(googletest)
-include(GoogleTest)
-message(STATUS "Google Test made available")
-
-add_executable(ucxtest
-        test_utils.cpp
-        test_allocator.cpp
-        test_compare.cpp
-        test_string.cpp
-        test_buffer.cpp
-        test_list.cpp
-        test_hash_key.cpp
-        test_map.cpp
-        test_map_generics.c
-        test_mempool.cpp
-        test_printf.cpp
-        selftest.cpp
-        util_allocator.cpp
-        )
-target_include_directories(ucxtest PRIVATE ${CMAKE_SOURCE_DIR}/../src)
-target_link_libraries(ucxtest ${CMAKE_BINARY_DIR}/../libucx_static${STLIB_EXT} gtest_main)
-gtest_discover_tests(ucxtest)
--- a/tests/Makefile	Wed Dec 20 16:46:14 2023 +0100
+++ b/tests/Makefile	Wed Dec 20 17:57:18 2023 +0100
@@ -27,14 +27,14 @@
 
 TEST_DIR=$(build_dir)/tests
 
-SRC = test_utils.c ucxtest.o
+SRC = test_utils.c ucxtest.c
 
 OBJ_EXT=.o
 OBJ=$(SRC:%.c=$(TEST_DIR)/%$(OBJ_EXT))
 
 all: $(TEST_DIR) $(TEST_DIR)/ucxtest
 
-$(TEST_DIR)/ucxtest: $(build_dir)/libucx_static.a $(OBJ)
+$(TEST_DIR)/ucxtest: $(OBJ) $(build_dir)/libucx_static.a
 	$(CC) -o $@ $+
 
 $(build_dir)/libucx_static.a:
@@ -53,12 +53,13 @@
 	@echo "Compiling $<"
 	$(CC) -o $@ $(CFLAGS) -c $<
 
-$(TEST_DIR)/test_utils$(OBJ_EXT): test_utils.c test_utils.h \
- ../src/cx/test.h
+$(TEST_DIR)/test_utils$(OBJ_EXT): test_utils.c ../src/cx/test.h \
+ ../src/cx/utils.h ../src/cx/common.h ../src/cx/buffer.h \
+ ../src/cx/allocator.h ../src/szmul.c
 	@echo "Compiling $<"
 	$(CC) -o $@ $(CFLAGS) -c $<
 
-$(TEST_DIR)/ucxtest$(OBJ_EXT): ucxtest.c test_utils.h ../src/cx/test.h
+$(TEST_DIR)/ucxtest$(OBJ_EXT): ucxtest.c ../src/cx/test.h
 	@echo "Compiling $<"
 	$(CC) -o $@ $(CFLAGS) -c $<
 
--- a/tests/test_utils.c	Wed Dec 20 16:46:14 2023 +0100
+++ b/tests/test_utils.c	Wed Dec 20 17:57:18 2023 +0100
@@ -26,11 +26,230 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "test_utils.h"
+#include "cx/test.h"
+
+#include "cx/utils.h"
+#include "cx/buffer.h"
+
+CX_TEST(test_stream_bncopy) {
+    CxBuffer source, target;
+    char sbuf[32], tbuf[32];
+    memset(tbuf, 0, 32);
+    cxBufferInit(&source, sbuf, 32, NULL, 0);
+    cxBufferInit(&target, tbuf, 32, NULL, 0);
+    cxBufferPutString(&source, "This is a stream copy test.");
+    cxBufferSeek(&source, 0, SEEK_SET);
+    char tmp[4];
+
+    CX_TEST_DO {
+        size_t result = cx_stream_bncopy(&source, &target,
+                                         (cx_read_func) cxBufferRead,
+                                         (cx_write_func) cxBufferWrite,
+                                         tmp, 4, 20);
+        CX_TEST_ASSERT(result == 20);
+        CX_TEST_ASSERT(target.size == 20);
+        CX_TEST_ASSERT(strcmp("This is a stream cop\0", tbuf) == 0);
+
+        result = cx_stream_bcopy(&source, &target,
+                                 (cx_read_func) cxBufferRead,
+                                 (cx_write_func) cxBufferWrite,
+                                 NULL, 16);
+
+        CX_TEST_ASSERT(result == 7);
+        CX_TEST_ASSERT(target.size == 27);
+        CX_TEST_ASSERT(strcmp("This is a stream copy test.\0", tbuf) == 0);
+    }
+
+    cxBufferDestroy(&source);
+    cxBufferDestroy(&target);
+}
+
+CX_TEST(test_stream_ncopy) {
+    CxBuffer source, target;
+    char sbuf[32], tbuf[32];
+    memset(tbuf, 0, 32);
+    cxBufferInit(&source, sbuf, 32, NULL, 0);
+    cxBufferInit(&target, tbuf, 32, NULL, 0);
+    cxBufferPutString(&source, "This is a stream copy test.");
+    cxBufferSeek(&source, 0, SEEK_SET);
+
+    CX_TEST_DO {
+        size_t result = cx_stream_ncopy(&source, &target,
+                                        (cx_read_func) cxBufferRead,
+                                        (cx_write_func) cxBufferWrite,
+                                        20);
+        CX_TEST_ASSERT(result == 20);
+        CX_TEST_ASSERT(target.size == 20);
+        CX_TEST_ASSERT(strcmp("This is a stream cop\0", tbuf) == 0);
+
+        result = cx_stream_copy(&source, &target,
+                                (cx_read_func) cxBufferRead,
+                                (cx_write_func) cxBufferWrite);
+
+        CX_TEST_ASSERT(result == 7);
+        CX_TEST_ASSERT(target.size == 27);
+        CX_TEST_ASSERT(strcmp("This is a stream copy test.\0", tbuf) == 0);
+    }
+
+    cxBufferDestroy(&source);
+    cxBufferDestroy(&target);
+}
+
+CX_TEST(test_forn) {
+    unsigned j;
+    j = 0;
+    CX_TEST_DO {
+        cx_for_n(i, 50) {
+            CX_TEST_ASSERT(i == j);
+            j++;
+        }
+    }
+}
+
+CX_TEST(test_swap_ptr) {
+    int i = 5;
+    int j = 8;
+    int *ip = &i;
+    int *jp = &j;
+    CX_TEST_DO {
+        cx_swap_ptr(ip, jp);
+        CX_TEST_ASSERT(ip == &j);
+        CX_TEST_ASSERT(jp == &i);
+    }
+}
+
+CX_TEST(test_szmul) {
+    size_t r;
+    int e;
+
+    CX_TEST_DO {
+        e = cx_szmul(5, 7, &r);
+        CX_TEST_ASSERT(e == 0);
+        CX_TEST_ASSERT(r == 35);
+
+        size_t s = SIZE_MAX & ~3;
+
+        e = cx_szmul(s / 4, 2, &r);
+        CX_TEST_ASSERT(e == 0);
+        CX_TEST_ASSERT(r == s / 2);
+
+        e = cx_szmul(2, s / 4, &r);
+        CX_TEST_ASSERT(e == 0);
+        CX_TEST_ASSERT(r == s / 2);
+
+        e = cx_szmul(s / 4, 4, &r);
+        CX_TEST_ASSERT(e == 0);
+        CX_TEST_ASSERT(r == s);
+
+        e = cx_szmul(4, s / 4, &r);
+        CX_TEST_ASSERT(e == 0);
+        CX_TEST_ASSERT(r == s);
+
+        e = cx_szmul(s / 4, 5, &r);
+        CX_TEST_ASSERT(e != 0);
+
+        e = cx_szmul(5, s / 4, &r);
+        CX_TEST_ASSERT(e != 0);
+
+        e = cx_szmul(SIZE_MAX - 4, 0, &r);
+        CX_TEST_ASSERT(e == 0);
+        CX_TEST_ASSERT(r == 0);
+
+        e = cx_szmul(0, SIZE_MAX - 1, &r);
+        CX_TEST_ASSERT(e == 0);
+        CX_TEST_ASSERT(r == 0);
+
+        e = cx_szmul(SIZE_MAX, 0, &r);
+        CX_TEST_ASSERT(e == 0);
+        CX_TEST_ASSERT(r == 0);
+
+        e = cx_szmul(0, SIZE_MAX, &r);
+        CX_TEST_ASSERT(e == 0);
+        CX_TEST_ASSERT(r == 0);
+
+        e = cx_szmul(0, 0, &r);
+        CX_TEST_ASSERT(e == 0);
+        CX_TEST_ASSERT(r == 0);
+    }
+}
+
+#ifdef CX_SZMUL_BUILTIN
+
+// also test the custom implementation
+#undef CX_SZMUL_BUILTIN
+
+#include "../src/szmul.c"
+
+#define CX_SZMUL_BUILTIN
+
+CX_TEST(test_szmul_impl) {
+    size_t r;
+    int e;
+
+    CX_TEST_DO {
+        e = cx_szmul_impl(5, 7, &r);
+        CX_TEST_ASSERT(e == 0);
+        CX_TEST_ASSERT(r == 35);
+
+        size_t s = SIZE_MAX & ~3;
+
+        e = cx_szmul_impl(s / 4, 2, &r);
+        CX_TEST_ASSERT(e == 0);
+        CX_TEST_ASSERT(r == s / 2);
+
+        e = cx_szmul_impl(2, s / 4, &r);
+        CX_TEST_ASSERT(e == 0);
+        CX_TEST_ASSERT(r == s / 2);
+
+        e = cx_szmul_impl(s / 4, 4, &r);
+        CX_TEST_ASSERT(e == 0);
+        CX_TEST_ASSERT(r == s);
+
+        e = cx_szmul_impl(4, s / 4, &r);
+        CX_TEST_ASSERT(e == 0);
+        CX_TEST_ASSERT(r == s);
+
+        e = cx_szmul_impl(s / 4, 5, &r);
+        CX_TEST_ASSERT(e != 0);
+
+        e = cx_szmul_impl(5, s / 4, &r);
+        CX_TEST_ASSERT(e != 0);
+
+        e = cx_szmul_impl(SIZE_MAX - 4, 0, &r);
+        CX_TEST_ASSERT(e == 0);
+        CX_TEST_ASSERT(r == 0);
+
+        e = cx_szmul_impl(0, SIZE_MAX - 1, &r);
+        CX_TEST_ASSERT(e == 0);
+        CX_TEST_ASSERT(r == 0);
+
+        e = cx_szmul_impl(SIZE_MAX, 0, &r);
+        CX_TEST_ASSERT(e == 0);
+        CX_TEST_ASSERT(r == 0);
+
+        e = cx_szmul_impl(0, SIZE_MAX, &r);
+        CX_TEST_ASSERT(e == 0);
+        CX_TEST_ASSERT(r == 0);
+
+        e = cx_szmul_impl(0, 0, &r);
+        CX_TEST_ASSERT(e == 0);
+        CX_TEST_ASSERT(r == 0);
+    }
+}
+
+#endif // CX_SZMUL_BUILTIN
+
 
 CxTestSuite *cx_test_suite_utils(void) {
     CxTestSuite *suite = cx_test_suite_new("utils");
 
+    cx_test_register(suite, test_stream_bncopy);
+    cx_test_register(suite, test_stream_ncopy);
+    cx_test_register(suite, test_forn);
+    cx_test_register(suite, test_swap_ptr);
+    cx_test_register(suite, test_szmul);
+    cx_test_register(suite, test_szmul_impl);
+
     return suite;
 }
 
--- a/tests/test_utils.cpp	Wed Dec 20 16:46:14 2023 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,227 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright 2021 Mike Becker, Olaf Wintermann All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright
- *      notice, this list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright
- *      notice, this list of conditions and the following disclaimer in the
- *      documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "cx/utils.h"
-
-#include "cx/buffer.h"
-
-#include <gtest/gtest.h>
-
-TEST(Utils, cx_stream_bncopy) {
-    CxBuffer source, target;
-    char sbuf[32], tbuf[32];
-    memset(tbuf, 0, 32);
-    cxBufferInit(&source, sbuf, 32, nullptr, 0);
-    cxBufferInit(&target, tbuf, 32, nullptr, 0);
-    cxBufferPutString(&source, "This is a stream copy test.");
-    cxBufferSeek(&source, 0, SEEK_SET);
-
-    char tmp[4];
-    size_t result = cx_stream_bncopy(&source, &target,
-                                     (cx_read_func) cxBufferRead,
-                                     (cx_write_func) cxBufferWrite,
-                                     tmp, 4, 20);
-    EXPECT_EQ(20, result);
-    EXPECT_EQ(20, target.size);
-    EXPECT_STREQ("This is a stream cop\0", tbuf);
-
-    result = cx_stream_bcopy(&source, &target,
-                             (cx_read_func) cxBufferRead,
-                             (cx_write_func) cxBufferWrite,
-                             nullptr, 16);
-
-    EXPECT_EQ(7, result);
-    EXPECT_EQ(27, target.size);
-    EXPECT_STREQ("This is a stream copy test.\0", tbuf);
-
-    cxBufferDestroy(&source);
-    cxBufferDestroy(&target);
-}
-
-TEST(Utils, cx_stream_ncopy) {
-    CxBuffer source, target;
-    char sbuf[32], tbuf[32];
-    memset(tbuf, 0, 32);
-    cxBufferInit(&source, sbuf, 32, nullptr, 0);
-    cxBufferInit(&target, tbuf, 32, nullptr, 0);
-    cxBufferPutString(&source, "This is a stream copy test.");
-    cxBufferSeek(&source, 0, SEEK_SET);
-
-    size_t result = cx_stream_ncopy(&source, &target,
-                                    (cx_read_func) cxBufferRead,
-                                    (cx_write_func) cxBufferWrite,
-                                    20);
-    EXPECT_EQ(20, result);
-    EXPECT_EQ(20, target.size);
-    EXPECT_STREQ("This is a stream cop\0", tbuf);
-
-    result = cx_stream_copy(&source, &target,
-                            (cx_read_func) cxBufferRead,
-                            (cx_write_func) cxBufferWrite);
-
-    EXPECT_EQ(7, result);
-    EXPECT_EQ(27, target.size);
-    EXPECT_STREQ("This is a stream copy test.\0", tbuf);
-
-    cxBufferDestroy(&source);
-    cxBufferDestroy(&target);
-}
-
-TEST(Utils, ForN) {
-    unsigned j;
-    j = 0;
-    cx_for_n(i, 50) {
-        EXPECT_EQ(i, j);
-        j++;
-    }
-}
-
-TEST(Utils, swap_ptr) {
-    int i = 5;
-    int j = 8;
-    int *ip = &i;
-    int *jp = &j;
-    cx_swap_ptr(ip, jp);
-    EXPECT_EQ(ip, &j);
-    EXPECT_EQ(jp, &i);
-}
-
-TEST(Utils, szmul) {
-    size_t r;
-    int e;
-    e = cx_szmul(5, 7, &r);
-    EXPECT_EQ(0, e);
-    EXPECT_EQ(35, r);
-
-    size_t s = SIZE_MAX & ~3;
-
-    e = cx_szmul(s / 4, 2, &r);
-    EXPECT_EQ(0, e);
-    EXPECT_EQ(s / 2, r);
-    e = cx_szmul(2, s / 4, &r);
-    EXPECT_EQ(0, e);
-    EXPECT_EQ(s / 2, r);
-
-    e = cx_szmul(s / 4, 4, &r);
-    EXPECT_EQ(0, e);
-    EXPECT_EQ(s, r);
-
-    e = cx_szmul(4, s / 4, &r);
-    EXPECT_EQ(0, e);
-    EXPECT_EQ(s, r);
-
-    e = cx_szmul(s / 4, 5, &r);
-    EXPECT_NE(0, e);
-
-    e = cx_szmul(5, s / 4, &r);
-    EXPECT_NE(0, e);
-
-    e = cx_szmul(SIZE_MAX - 4, 0, &r);
-    EXPECT_EQ(0, e);
-    EXPECT_EQ(0, r);
-
-    e = cx_szmul(0, SIZE_MAX - 1, &r);
-    EXPECT_EQ(0, e);
-    EXPECT_EQ(0, r);
-
-    e = cx_szmul(SIZE_MAX, 0, &r);
-    EXPECT_EQ(0, e);
-    EXPECT_EQ(0, r);
-
-    e = cx_szmul(0, SIZE_MAX, &r);
-    EXPECT_EQ(0, e);
-    EXPECT_EQ(0, r);
-
-    e = cx_szmul(0, 0, &r);
-    EXPECT_EQ(0, e);
-    EXPECT_EQ(0, r);
-}
-
-#ifdef CX_SZMUL_BUILTIN
-
-// also test the custom implementation
-struct Utils_szmul_impl : ::testing::Test {
-#undef CX_SZMUL_BUILTIN
-
-#include "../src/szmul.c"
-
-#define CX_SZMUL_BUILTIN
-};
-
-TEST_F(Utils_szmul_impl, Test) {
-    size_t r;
-    int e;
-    e = cx_szmul_impl(5, 7, &r);
-    EXPECT_EQ(0, e);
-    EXPECT_EQ(35, r);
-
-    size_t s = SIZE_MAX & ~3;
-
-    e = cx_szmul_impl(s / 4, 2, &r);
-    EXPECT_EQ(0, e);
-    EXPECT_EQ(s / 2, r);
-    e = cx_szmul_impl(2, s / 4, &r);
-    EXPECT_EQ(0, e);
-    EXPECT_EQ(s / 2, r);
-
-    e = cx_szmul_impl(s / 4, 4, &r);
-    EXPECT_EQ(0, e);
-    EXPECT_EQ(s, r);
-
-    e = cx_szmul_impl(4, s / 4, &r);
-    EXPECT_EQ(0, e);
-    EXPECT_EQ(s, r);
-
-    e = cx_szmul_impl(s / 4, 5, &r);
-    EXPECT_NE(0, e);
-
-    e = cx_szmul_impl(5, s / 4, &r);
-    EXPECT_NE(0, e);
-
-    e = cx_szmul_impl(SIZE_MAX - 4, 0, &r);
-    EXPECT_EQ(0, e);
-    EXPECT_EQ(0, r);
-
-    e = cx_szmul_impl(0, SIZE_MAX - 1, &r);
-    EXPECT_EQ(0, e);
-    EXPECT_EQ(0, r);
-
-    e = cx_szmul_impl(SIZE_MAX, 0, &r);
-    EXPECT_EQ(0, e);
-    EXPECT_EQ(0, r);
-
-    e = cx_szmul_impl(0, SIZE_MAX, &r);
-    EXPECT_EQ(0, e);
-    EXPECT_EQ(0, r);
-
-    e = cx_szmul_impl(0, 0, &r);
-    EXPECT_EQ(0, e);
-    EXPECT_EQ(0, r);
-}
-
-#endif // CX_SZMUL_BUILTIN
--- a/tests/test_utils.h	Wed Dec 20 16:46:14 2023 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright 2023 Mike Becker, Olaf Wintermann All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- *   1. Redistributions of source code must retain the above copyright
- *      notice, this list of conditions and the following disclaimer.
- *
- *   2. Redistributions in binary form must reproduce the above copyright
- *      notice, this list of conditions and the following disclaimer in the
- *      documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef UCX_TEST_SUITE_UTILS_H
-#define UCX_TEST_SUITE_UTILS_H
-
-#include "cx/test.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-CxTestSuite *cx_test_suite_utils(void);
-
-
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#endif // UCX_TEST_SUITE_UTILS_H
--- a/tests/ucxtest.c	Wed Dec 20 16:46:14 2023 +0100
+++ b/tests/ucxtest.c	Wed Dec 20 17:57:18 2023 +0100
@@ -26,7 +26,9 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "test_utils.h"
+#include "cx/test.h"
+
+CxTestSuite *cx_test_suite_utils(void);
 
 #define run_tests(suite) cx_test_run_stdout(suite); success += (suite)->success; failure += (suite)->failure
 

mercurial