aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-12-21 11:12:05 +0100
committerSven Gothel <[email protected]>2020-12-21 11:12:05 +0100
commita65ef73681248d14a7ec3727f349f758388d07c6 (patch)
tree3634abefe3f35dc6c5d4eb90311d2aa14a8c38e5
parent4f1583d727cfcafa087a9e98aad99ae56e481fa1 (diff)
Replace cppunit.h with Catch2 (v3-devel): Supporting CI integration, more versatile functionality (benchmarking, ..)
-rw-r--r--README.md3
-rw-r--r--include/cppunit/cppunit.h110
-rw-r--r--include/jau/test/catch2_ext.hpp40
-rw-r--r--test/CMakeLists.txt69
-rw-r--r--test/test_basictypes01.cpp66
-rw-r--r--test/test_functiondef01.cpp440
-rw-r--r--test/test_lfringbuffer01.cpp276
-rw-r--r--test/test_lfringbuffer11.cpp101
-rw-r--r--test/test_mm_sc_drf_00.cpp88
-rw-r--r--test/test_mm_sc_drf_01.cpp84
10 files changed, 593 insertions, 684 deletions
diff --git a/README.md b/README.md
index 95bc28a..ab604cc 100644
--- a/README.md
+++ b/README.md
@@ -110,6 +110,9 @@ Changes
**0.3.0**
* TODO
+* Test: Using imported Catch2 (v3-devel) for C++ unit testing
+* Reduced ringbuffer to single implementation, adding move-operations
+* Added basic_types.hpp: 'to_decimal_string(..)' implementing <type>DecString() inlines.
* Use nsize_t and snsize_t where appropriate for smaller footprint
* Have ringbuffer's Size_type parameterized
* Bugfixes and added cow_array
diff --git a/include/cppunit/cppunit.h b/include/cppunit/cppunit.h
deleted file mode 100644
index 09c60fb..0000000
--- a/include/cppunit/cppunit.h
+++ /dev/null
@@ -1,110 +0,0 @@
-#ifndef CPPUNIT_H
-#define CPPUNIT_H
-
-// Required headers, or just use #include <bits/stdc++.h>
-#include <iostream>
-#include <sstream>
-#include <cstring>
-#include <string>
-#include <ctime>
-#include <cmath>
-
-
-// CPlusPlusUnit - C++ Unit testing TDD framework (github.com/cppunit/cppunit)
-class Cppunit {
-
- private:
- static float machineFloatEpsilon() {
- float x = 1.0f, res;
- do {
- res = x;
- } while (1.0f + (x /= 2.0f) > 1.0f);
- return res;
- }
-
- static double machineDoubleEpsilon() {
- double x = 1.0, res;
- do {
- res = x;
- } while (1.0 + (x /= 2.0) > 1.0);
- return res;
- }
-
- public:
-
- #define PRINTM(m) print(m, __FILE__, __LINE__, __FUNCTION__);
- #define CHECK(a,b) check<long long>("", a, b, #a, #b, __FILE__, __LINE__, __FUNCTION__);
- #define CHECKM(m,a,b) check<long long>(m, a, b, #a, #b, __FILE__, __LINE__, __FUNCTION__);
- #define CHECKD(m,a,b) checkDelta<double>(m, a, b, doubleEpsilon, #a, #b, __FILE__, __LINE__, __FUNCTION__);
- #define CHECKDD(m,a,b,c) checkDelta<double>(m, a, b, c, #a, #b, __FILE__, __LINE__, __FUNCTION__);
- #define CHECKT(a) check<bool>("", a, true, #a, "true", __FILE__, __LINE__, __FUNCTION__);
- #define CHECKTM(m,a) check<bool>(m, a, true, #a, "true", __FILE__, __LINE__, __FUNCTION__);
- #define CHECKS(a,b) check<cs>("", a, b, #a, #b, __FILE__, __LINE__, __FUNCTION__);
- #define CHECKSM(m,a,b) check<cs>(m, a, b, #a, #b, __FILE__, __LINE__, __FUNCTION__);
-
- typedef const std::string& cs;
-
- int checks, fails; std::ostringstream serr; std::istringstream *in;
- float floatEpsilon;
- double doubleEpsilon;
-
- Cppunit()
- : checks(0), fails(0), floatEpsilon(machineFloatEpsilon()), doubleEpsilon(machineDoubleEpsilon())
- {}
-
- virtual ~Cppunit() {}
-
- void test_cin(cs s){ in = new std::istringstream(s); std::cin.rdbuf(in->rdbuf()); }
-
- void fail_hdr(cs stra, cs strb, cs file, int line, cs func) {
- serr << "==================================================" << std::endl;
- serr << "FAIL: " << func << std::endl;
- serr << "--------------------------------------------------" << std::endl;
- serr << "File \"" << file << "\", line " << line << " in " << func << std::endl;
- serr << " Checking " << stra << " == " << strb << std::endl;
- }
-
- static void print(cs m, cs file, int line, cs func) {
- std::cerr << std::endl << m << "; file \"" << file << "\", line " << line << " in " << func << std::endl;
- }
-
- template <typename T> void check(cs m, T a, T b, cs stra, cs strb, cs file, int line, cs func) {
- checks++; if (a == b) { std::cout << "."; return; }
- fails++; std::cout << "F"; fail_hdr(stra, strb, file, line, func);
- serr << " Error: " << m << ": \"" << a << "\" ! = \"" << b << "\"" << std::endl << std::endl;
- }
-
- template <typename T> void checkDelta(cs m, T a, T b, T d, cs stra, cs strb, cs file, int line, cs func) {
- checks++; if ( labs ( a - b ) < d ) { std::cout << "."; return; }
- fails++; std::cout << "F"; fail_hdr(stra, strb, file, line, func);
- serr << " Error: " << m << ": \"" << a << "\" ! = \"" << b << "\" (delta " << d << ")" << std::endl << std::endl;
- }
-
- virtual void single_test() {}
- virtual void test_list() { single_test(); }
- double dclock() { return double(clock()) / CLOCKS_PER_SEC; }
- int status() {
- std::cout << std::endl; if (fails) std::cout << serr.str();
- std::cout << "--------------------------------------------------" << std::endl;
- std::cout << "Ran " << checks << " checks in " << dclock() << "s" << std::endl << std::endl;
- if (fails) std::cout << "FAILED (failures=" << fails << ")"; else std::cout << "OK" << std::endl;
- return fails > 0;
- }
- int run() { std::streambuf* ocin = std::cin.rdbuf(); test_list(); std::cin.rdbuf(ocin); return status(); }
-};
-
-template<> void Cppunit::checkDelta<float>(cs m, float a, float b, float epsilon, cs stra, cs strb, cs file, int line, cs func) {
- checks++; if ( fabsf( a - b ) < epsilon ) { std::cout << "."; return; }
- fails++; std::cout << "F"; fail_hdr(stra, strb, file, line, func);
- serr << " Error: " << m << ": \"" << a << "\" ! = \"" << b << "\" (epsilon " << epsilon << ")" << std::endl << std::endl;
-}
-
-template<> void Cppunit::checkDelta<double>(cs m, double a, double b, double epsilon, cs stra, cs strb, cs file, int line, cs func) {
- checks++; if ( fabs( a - b ) < epsilon ) { std::cout << "."; return; }
- fails++; std::cout << "F"; fail_hdr(stra, strb, file, line, func);
- serr << " Error: " << m << ": \"" << a << "\" ! = \"" << b << "\" (epsilon " << epsilon << ")" << std::endl << std::endl;
-}
-
-
-#endif // CPPUNIT_H
-
diff --git a/include/jau/test/catch2_ext.hpp b/include/jau/test/catch2_ext.hpp
new file mode 100644
index 0000000..03a5d15
--- /dev/null
+++ b/include/jau/test/catch2_ext.hpp
@@ -0,0 +1,40 @@
+// Copyright Catch2 Authors
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// https://www.boost.org/LICENSE_1_0.txt)
+
+// SPDX-License-Identifier: BSL-1.0
+
+// Using Catch v3+
+// ----------------------------------------------------------
+
+#ifndef CATCH2_EXT_H
+#define CATCH2_EXT_H
+
+#include <catch2/catch_amalgamated.hpp>
+
+// namespace Catch {
+///////////////////////////////////////////////////////////////////////////////
+#define INTERNAL_CATCH_TEST_M( msg, macroName, resultDisposition, ... ) \
+ do { \
+ /* The expression should not be evaluated, but warnings should hopefully be checked */ \
+ CATCH_INTERNAL_IGNORE_BUT_WARN(__VA_ARGS__); \
+ std::string s1( macroName##_catch_sr ); \
+ s1.append(msg); \
+ s1.append(": "); \
+ Catch::AssertionHandler catchAssertionHandler( s1, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \
+ INTERNAL_CATCH_TRY { \
+ CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
+ CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
+ catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \
+ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
+ } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
+ INTERNAL_CATCH_REACT( catchAssertionHandler ) \
+ } while( (void)0, (false) && static_cast<bool>( !!(__VA_ARGS__) ) )
+
+ #define REQUIRE_MSG(MSG, ... ) INTERNAL_CATCH_TEST_M( MSG, "REQUIRE: ", Catch::ResultDisposition::Normal, __VA_ARGS__ )
+ #define INFO_STR( msg ) INTERNAL_CATCH_INFO( "INFO", static_cast<std::string>(msg) )
+// }
+
+#endif // CATCH2_EXT_H
+
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 9b0a9ba..e573c4a 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -1,35 +1,42 @@
include_directories(
- ${PROJECT_SOURCE_DIR}/include/cppunit
- ${PROJECT_SOURCE_DIR}/include
+ ${CMAKE_CURRENT_SOURCE_DIR}/../include
)
-add_executable (test_functiondef01 test_functiondef01.cpp)
-target_link_libraries (test_functiondef01 jaucpp)
-add_dependencies(test_functiondef01 jaucpp)
-add_test (NAME functiondef01 COMMAND test_functiondef01)
-
-add_executable (test_basictypes01 test_basictypes01.cpp)
-target_link_libraries (test_basictypes01 jaucpp)
-add_dependencies(test_basictypes01 jaucpp)
-add_test (NAME basictypes01 COMMAND test_basictypes01)
-
-add_executable (test_lfringbuffer01 test_lfringbuffer01.cpp)
-target_link_libraries (test_lfringbuffer01 jaucpp)
-add_dependencies(test_lfringbuffer01 jaucpp)
-add_test (NAME lfringbuffer01 COMMAND test_lfringbuffer01)
-
-add_executable (test_lfringbuffer11 test_lfringbuffer11.cpp)
-target_link_libraries (test_lfringbuffer11 jaucpp)
-add_dependencies(test_lfringbuffer11 jaucpp)
-add_test (NAME lfringbuffer11 COMMAND test_lfringbuffer11)
-
-add_executable (test_mm_sc_drf_00 test_mm_sc_drf_00.cpp)
-target_link_libraries (test_mm_sc_drf_00 jaucpp)
-add_dependencies(test_mm_sc_drf_00 jaucpp)
-add_test (NAME mm_sc_drf_00 COMMAND test_mm_sc_drf_00)
-
-add_executable (test_mm_sc_drf_01 test_mm_sc_drf_01.cpp)
-target_link_libraries (test_mm_sc_drf_01 jaucpp)
-add_dependencies(test_mm_sc_drf_01 jaucpp)
-add_test (NAME mm_sc_drf_01 COMMAND test_mm_sc_drf_01)
+set (catch2_LIB_SRCS
+ ${CMAKE_CURRENT_SOURCE_DIR}/../include/catch2/catch_amalgamated.cpp
+)
+
+add_library (catch2 STATIC ${catch2_LIB_SRCS})
+
+target_compile_options(catch2 PUBLIC "-Wno-error=format-overflow")
+
+# install(TARGETS catch2 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
+
+# These examples use the standard separate compilation
+set( SOURCES_IDIOMATIC_EXAMPLES
+ test_functiondef01.cpp
+ test_basictypes01.cpp
+ test_lfringbuffer01.cpp
+ test_lfringbuffer11.cpp
+ test_mm_sc_drf_00.cpp
+ test_mm_sc_drf_01.cpp
+)
+
+string( REPLACE ".cpp" "" BASENAMES_IDIOMATIC_EXAMPLES "${SOURCES_IDIOMATIC_EXAMPLES}" )
+set( TARGETS_IDIOMATIC_EXAMPLES ${BASENAMES_IDIOMATIC_EXAMPLES} )
+
+foreach( name ${TARGETS_IDIOMATIC_EXAMPLES} )
+ add_executable(${name} ${name}.cpp)
+endforeach()
+
+set(ALL_EXAMPLE_TARGETS
+ ${TARGETS_IDIOMATIC_EXAMPLES}
+)
+
+foreach(name ${ALL_EXAMPLE_TARGETS})
+ target_link_libraries(${name} jaulib catch2)
+ add_dependencies(${name} jaulib catch2)
+ add_test (NAME ${name} COMMAND ${name})
+endforeach()
+
diff --git a/test/test_basictypes01.cpp b/test/test_basictypes01.cpp
index da5d071..a0ec3ba 100644
--- a/test/test_basictypes01.cpp
+++ b/test/test_basictypes01.cpp
@@ -3,14 +3,15 @@
#include <cinttypes>
#include <cstring>
-#include <cppunit.h>
+#define CATCH_CONFIG_MAIN
+#include <catch2/catch_amalgamated.hpp>
#include <jau/basic_types.hpp>
using namespace jau;
// Test examples.
-class Cppunit_tests : public Cppunit {
+class TestBasicTypes01 {
private:
#define SHOW_DECIMAL_STRING_STATS 0
@@ -37,58 +38,57 @@ class Cppunit_tests : public Cppunit {
const nsize_t net_chars = digit10_count + comma_count;
const nsize_t total_chars = std::min<nsize_t>(max_chars, std::max<nsize_t>(min_width, net_chars));
- PRINTM(msg+": value "+std::to_string(value)+", use_separator "+std::to_string(use_separator)+", min_width "+std::to_string(min_width));
- PRINTM(msg+": min "+std::to_string(min_value)+", max "+std::to_string(max_value));
- PRINTM(msg+": max_digits10 "+std::to_string(max_digits10)+" [ orig "+std::to_string(max_digits10_0)+", min "+std::to_string(max_digits10_1)+", max "+std::to_string(max_digits10_2)+"]");
- PRINTM(msg+": max_commas "+std::to_string(max_commas));
- PRINTM(msg+": max_chars "+std::to_string(max_chars));
- PRINTM(msg+": value digits10 "+std::to_string(digit10_count));
- PRINTM(msg+": value commas "+std::to_string(comma_count));
- PRINTM(msg+": value net_chars "+std::to_string(net_chars));
- PRINTM(msg+": value total_chars "+std::to_string(total_chars));
+ INFO(msg+": value "+std::to_string(value)+", use_separator "+std::to_string(use_separator)+", min_width "+std::to_string(min_width));
+ INFO(msg+": min "+std::to_string(min_value)+", max "+std::to_string(max_value));
+ INFO(msg+": max_digits10 "+std::to_string(max_digits10)+" [ orig "+std::to_string(max_digits10_0)+", min "+std::to_string(max_digits10_1)+", max "+std::to_string(max_digits10_2)+"]");
+ INFO(msg+": max_commas "+std::to_string(max_commas));
+ INFO(msg+": max_chars "+std::to_string(max_chars));
+ INFO(msg+": value digits10 "+std::to_string(digit10_count));
+ INFO(msg+": value commas "+std::to_string(comma_count));
+ INFO(msg+": value net_chars "+std::to_string(net_chars));
+ INFO(msg+": value total_chars "+std::to_string(total_chars));
std::string s = to_decimal_string<T>(value, use_separator ? ',' : 0, min_width);
- PRINTM(msg+": result '"+s+"', len "+std::to_string(s.length()));
+ INFO(msg+": result '"+s+"', len "+std::to_string(s.length()));
}
#endif
- void test_int32_t(const std::string msg, const int32_t v, const int expStrLen, const std::string expStr) {
+ void test_int32_t(const std::string msg, const int32_t v, const size_t expStrLen, const std::string expStr) {
#if SHOW_DECIMAL_STRING_STATS
show_decimal_string_stats<int32_t>(msg, v, true /* use_separator */, 0 /* min_width */);
#endif
-
const std::string str = int32DecString(v);
- PRINTM(msg+": has '"+str+"', len "+std::to_string(str.length()));
- PRINTM(msg+": exp '"+expStr+"', len "+std::to_string(expStr.length())+", equal: "+std::to_string(str==expStr));
- CHECKM(msg, str.length(), expStrLen);
- CHECKTM(msg, str == expStr);
+ INFO(msg+": has '"+str+"', len "+std::to_string(str.length()));
+ INFO(msg+": exp '"+expStr+"', len "+std::to_string(expStr.length())+", equal: "+std::to_string(str==expStr));
+ REQUIRE(str.length() == expStrLen);
+ REQUIRE_THAT(str, Catch::Matchers::Equals(expStr, Catch::CaseSensitive::Yes));
}
- void test_uint32_t(const std::string msg, const uint32_t v, const int expStrLen, const std::string expStr) {
+ void test_uint32_t(const std::string msg, const uint32_t v, const size_t expStrLen, const std::string expStr) {
#if SHOW_DECIMAL_STRING_STATS
show_decimal_string_stats<uint32_t>(msg, v, true /* use_separator */, 0 /* min_width */);
#endif
const std::string str = uint32DecString(v);
- PRINTM(msg+": has '"+str+"', len "+std::to_string(str.length()));
- PRINTM(msg+": exp '"+expStr+"', len "+std::to_string(expStr.length())+", equal: "+std::to_string(str==expStr));
- CHECKM(msg, str.length(), expStrLen);
- CHECKTM(msg, str == expStr);
+ INFO(msg+": has '"+str+"', len "+std::to_string(str.length()));
+ INFO(msg+": exp '"+expStr+"', len "+std::to_string(expStr.length())+", equal: "+std::to_string(str==expStr));
+ REQUIRE(str.length() == expStrLen);
+ REQUIRE_THAT(str, Catch::Matchers::Equals(expStr, Catch::CaseSensitive::Yes));
}
- void test_uint64_t(const std::string msg, const uint64_t v, const int expStrLen, const std::string expStr) {
+ void test_uint64_t(const std::string msg, const uint64_t v, const size_t expStrLen, const std::string expStr) {
#if SHOW_DECIMAL_STRING_STATS
show_decimal_string_stats<uint64_t>(msg, v, true /* use_separator */, 0 /* min_width */);
#endif
const std::string str = uint64DecString(v);
- PRINTM(msg+": has '"+str+"', len "+std::to_string(str.length()));
- PRINTM(msg+": exp '"+expStr+"', len "+std::to_string(expStr.length())+", equal: "+std::to_string(str==expStr));
- CHECKM(msg, str.length(), expStrLen);
- CHECKTM(msg, str == expStr);
+ INFO(msg+": has '"+str+"', len "+std::to_string(str.length()));
+ INFO(msg+": exp '"+expStr+"', len "+std::to_string(expStr.length())+", equal: "+std::to_string(str==expStr));
+ REQUIRE(str.length() == expStrLen);
+ REQUIRE_THAT(str, Catch::Matchers::Equals(expStr, Catch::CaseSensitive::Yes));
}
public:
- void single_test() override {
+ void single_test() {
{
test_int32_t("INT32_MIN", INT32_MIN, 14, "-2,147,483,648");
test_int32_t("int32_t -thousand", -1000, 6, "-1,000");
@@ -109,11 +109,5 @@ class Cppunit_tests : public Cppunit {
}
};
-int main(int argc, char *argv[]) {
- (void)argc;
- (void)argv;
-
- Cppunit_tests test1;
- return test1.run();
-}
+METHOD_AS_TEST_CASE( TestBasicTypes01::single_test, "Test Basic Types 01");
diff --git a/test/test_functiondef01.cpp b/test/test_functiondef01.cpp
index 3cd1fea..f22efe3 100644
--- a/test/test_functiondef01.cpp
+++ b/test/test_functiondef01.cpp
@@ -3,14 +3,15 @@
#include <cinttypes>
#include <cstring>
-#include <cppunit.h>
+#define CATCH_CONFIG_MAIN
+#include <catch2/catch_amalgamated.hpp>
#include <jau/function_def.hpp>
using namespace jau;
// Test examples.
-class Cppunit_tests : public Cppunit {
+class TestFunctionDef01 {
private:
int func2a_member(int i) {
@@ -40,15 +41,15 @@ class Cppunit_tests : public Cppunit {
IntOffset(const IntOffset &o)
: value(o.value)
{
- PRINTM("IntOffset::copy_ctor");
+ INFO("IntOffset::copy_ctor");
}
IntOffset(IntOffset &&o)
: value(std::move(o.value))
{
- PRINTM("IntOffset::move_ctor");
+ INFO("IntOffset::move_ctor");
}
IntOffset& operator=(const IntOffset &o) {
- PRINTM("IntOffset::copy_assign");
+ INFO("IntOffset::copy_assign");
if( &o == this ) {
return *this;
}
@@ -56,7 +57,7 @@ class Cppunit_tests : public Cppunit {
return *this;
}
IntOffset& operator=(IntOffset &&o) {
- PRINTM("IntOffset::move_assign");
+ INFO("IntOffset::move_assign");
value = std::move(o.value);
(void)value;
return *this;
@@ -76,244 +77,245 @@ class Cppunit_tests : public Cppunit {
void test_FunctionPointer00(std::string msg, bool expEqual, int value, int expRes, MyClassFunction & f1, MyClassFunction &f2) {
// test std::function identity
- PRINTM(msg+": FunctionPointer00 Fun f1p == f2p : " + std::to_string( f1 == f2 ) + ", f1p: " + f1.toString() + ", f2 "+f2.toString() );
+ INFO(msg+": FunctionPointer00 Fun f1p == f2p : " + std::to_string( f1 == f2 ) + ", f1p: " + f1.toString() + ", f2 "+f2.toString() );
int f1r = f1.invoke(value);
int f2r = f2.invoke(value);
- PRINTM(msg+": FunctionPointer00 Res f1r == f2r : " + std::to_string( f1r == f2r ) + ", f1r: " + std::to_string( f1r ) + ", f2r "+std::to_string( f2r ) );
+ INFO(msg+": FunctionPointer00 Res f1r == f2r : " + std::to_string( f1r == f2r ) + ", f1r: " + std::to_string( f1r ) + ", f2r "+std::to_string( f2r ) );
if( expEqual ) {
- CHECKM(msg, f1r, expRes);
- CHECKM(msg, f2r, expRes);
- CHECKTM(msg, f1 == f2);
+ REQUIRE(f1r == expRes);
+ REQUIRE(f2r == expRes);
+ REQUIRE(f1 == f2);
} else {
- CHECKTM(msg, f1 != f2);
+ REQUIRE(f1 != f2);
}
}
void test_FunctionPointer01(std::string msg, bool expEqual, MyClassFunction & f1, MyClassFunction &f2) {
// test std::function identity
- PRINTM(msg+": FunctionPointer00 Fun f1p == f2p : " + std::to_string( f1 == f2 ) + ", f1p: " + f1.toString() + ", f2 "+f2.toString() );
+ INFO(msg+": FunctionPointer00 Fun f1p == f2p : " + std::to_string( f1 == f2 ) + ", f1p: " + f1.toString() + ", f2 "+f2.toString() );
if( expEqual ) {
- CHECKTM(msg, f1 == f2);
+ REQUIRE(f1 == f2);
} else {
- CHECKTM(msg, f1 != f2);
+ REQUIRE(f1 != f2);
}
}
public:
- void single_test() override {
+ void test01_memberfunc_this() {
+ INFO("FuncPtr2_member: bindMemberFunc<int, TestFunctionDef01, int>: START");
+ // FunctionDef(TestFunctionDef01 &base, Func1Type func)
+ MyClassFunction f2a_1 = bindMemberFunc<int, TestFunctionDef01, int>(this, &TestFunctionDef01::func2a_member);
+ MyClassFunction f2a_2 = bindMemberFunc(this, &TestFunctionDef01::func2a_member);
+ test_FunctionPointer00("FuncPtr2a_member_11", true, 1, 101, f2a_1, f2a_1);
+ test_FunctionPointer00("FuncPtr2a_member_12", true, 1, 101, f2a_1, f2a_2);
+
+ MyClassFunction f2b_1 = bindMemberFunc(this, &TestFunctionDef01::func2b_member);
+ MyClassFunction f2b_2 = bindMemberFunc(this, &TestFunctionDef01::func2b_member);
+ test_FunctionPointer00("FuncPtr2b_member_11", true, 1, 1001, f2b_1, f2b_1);
+ test_FunctionPointer00("FuncPtr2b_member_12", true, 1, 1001, f2b_1, f2b_2);
+
+ test_FunctionPointer00("FuncPtr2ab_member_11", false, 1, 0, f2a_1, f2b_1);
+ test_FunctionPointer00("FuncPtr2ab_member_22", false, 1, 0, f2a_2, f2b_2);
+ INFO("FuncPtr2_member: bindMemberFunc<int, TestFunctionDef01, int>: END");
+ }
- {
- PRINTM("FuncPtr2_member: bindMemberFunc<int, Cppunit_tests, int>: START");
- // FunctionDef(Cppunit_tests &base, Func1Type func)
- MyClassFunction f2a_1 = bindMemberFunc<int, Cppunit_tests, int>(this, &Cppunit_tests::func2a_member);
- MyClassFunction f2a_2 = bindMemberFunc(this, &Cppunit_tests::func2a_member);
- test_FunctionPointer00("FuncPtr2a_member_11", true, 1, 101, f2a_1, f2a_1);
- test_FunctionPointer00("FuncPtr2a_member_12", true, 1, 101, f2a_1, f2a_2);
-
- MyClassFunction f2b_1 = bindMemberFunc(this, &Cppunit_tests::func2b_member);
- MyClassFunction f2b_2 = bindMemberFunc(this, &Cppunit_tests::func2b_member);
- test_FunctionPointer00("FuncPtr2b_member_11", true, 1, 1001, f2b_1, f2b_1);
- test_FunctionPointer00("FuncPtr2b_member_12", true, 1, 1001, f2b_1, f2b_2);
-
- test_FunctionPointer00("FuncPtr2ab_member_11", false, 1, 0, f2a_1, f2b_1);
- test_FunctionPointer00("FuncPtr2ab_member_22", false, 1, 0, f2a_2, f2b_2);
- PRINTM("FuncPtr2_member: bindMemberFunc<int, Cppunit_tests, int>: END");
- }
- {
- PRINTM("FuncPtr3_plain: bindPlainFunc<int, int>: START");
- // FunctionDef(Func1Type func)
- MyClassFunction f3a_1 = bindPlainFunc<int, int>(&Cppunit_tests::Func3a_static);
- MyClassFunction f3a_2 = bindPlainFunc(&Cppunit_tests::Func3a_static);
- test_FunctionPointer00("FuncPtr3a_plain_11", true, 1, 101, f3a_1, f3a_1);
- test_FunctionPointer00("FuncPtr3a_plain_12", true, 1, 101, f3a_1, f3a_2);
-
- MyClassFunction f3b_1 = bindPlainFunc(&Cppunit_tests::Func3b_static);
- MyClassFunction f3b_2 = bindPlainFunc(&Func3b_static);
- test_FunctionPointer00("FuncPtr3b_plain_11", true, 1, 1001, f3b_1, f3b_1);
- test_FunctionPointer00("FuncPtr3b_plain_12", true, 1, 1001, f3b_1, f3b_2);
-
- test_FunctionPointer00("FuncPtr3ab_plain_11", false, 1, 0, f3a_1, f3b_1);
- test_FunctionPointer00("FuncPtr3ab_plain_22", false, 1, 0, f3a_2, f3b_2);
- PRINTM("FuncPtr3_plain: bindPlainFunc<int, int>: END");
- }
- {
- PRINTM("FuncPtr4_stdlambda: bindStdFunc<int, int>: START");
- // FunctionDef(Func1Type func) <int, int>
- std::function<int(int i)> func4a_stdlambda = [](int i)->int {
- int res = i+100;
- return res;;
- };
- std::function<int(int i)> func4b_stdlambda = [](int i)->int {
- int res = i+1000;
- return res;;
- };
- MyClassFunction f4a_1 = bindStdFunc<int, int>(100, func4a_stdlambda);
- MyClassFunction f4a_2 = bindStdFunc(100, func4a_stdlambda);
- test_FunctionPointer00("FuncPtr4a_stdlambda_11", true, 1, 101, f4a_1, f4a_1);
- test_FunctionPointer00("FuncPtr4a_stdlambda_12", true, 1, 101, f4a_1, f4a_2);
-
- MyClassFunction f4b_1 = bindStdFunc(200, func4b_stdlambda);
- MyClassFunction f4b_2 = bindStdFunc(200, func4b_stdlambda);
- test_FunctionPointer00("FuncPtr4b_stdlambda_11", true, 1, 1001, f4b_1, f4b_1);
- test_FunctionPointer00("FuncPtr4b_stdlambda_12", true, 1, 1001, f4b_1, f4b_2);
-
- test_FunctionPointer00("FuncPtr4ab_stdlambda_11", false, 1, 0, f4a_1, f4b_1);
- test_FunctionPointer00("FuncPtr4ab_stdlambda_22", false, 1, 0, f4a_2, f4b_2);
-
- MyClassFunction f4a_0 = bindStdFunc<int, int>(100);
- MyClassFunction f4b_0 = bindStdFunc<int, int>(200);
- test_FunctionPointer01("FuncPtr4a_stdlambda_01", true, f4a_0, f4a_1);
- test_FunctionPointer01("FuncPtr4a_stdlambda_02", true, f4a_0, f4a_2);
- test_FunctionPointer01("FuncPtr4b_stdlambda_01", true, f4b_0, f4b_1);
- test_FunctionPointer01("FuncPtr4b_stdlambda_02", true, f4b_0, f4b_2);
- test_FunctionPointer01("FuncPtr4ab_stdlambda_00", false, f4a_0, f4b_0);
- test_FunctionPointer01("FuncPtr4ab_stdlambda_01", false, f4a_0, f4b_1);
- test_FunctionPointer01("FuncPtr4ab_stdlambda_10", false, f4a_1, f4b_0);
- PRINTM("FuncPtr4_stdlambda: bindStdFunc<int, int>: END");
- }
- {
- PRINTM("FuncPtr5_capture: bindCaptureFunc<int, int, int>: START");
- // bindCaptureFunc(I& data, R(*func)(I&, A...))
- // FunctionDef(Func1Type func) <int, int>
- int offset100 = 100;
- int offset1000 = 1000;
-
- int(*func5a_capture)(int&, int) = [](int& offset, int i)->int {
- int res = i+10000+offset;
- return res;
- };
- int(*func5b_capture)(int&, int) = [](int& offset, int i)->int {
- int res = i+100000+offset;
- return res;
- };
+ void test02_plainfunc_static() {
+ INFO("FuncPtr3_plain: bindPlainFunc<int, int>: START");
+ // FunctionDef(Func1Type func)
+ MyClassFunction f3a_1 = bindPlainFunc<int, int>(&TestFunctionDef01::Func3a_static);
+ MyClassFunction f3a_2 = bindPlainFunc(&TestFunctionDef01::Func3a_static);
+ test_FunctionPointer00("FuncPtr3a_plain_11", true, 1, 101, f3a_1, f3a_1);
+ test_FunctionPointer00("FuncPtr3a_plain_12", true, 1, 101, f3a_1, f3a_2);
+
+ MyClassFunction f3b_1 = bindPlainFunc(&TestFunctionDef01::Func3b_static);
+ MyClassFunction f3b_2 = bindPlainFunc(&Func3b_static);
+ test_FunctionPointer00("FuncPtr3b_plain_11", true, 1, 1001, f3b_1, f3b_1);
+ test_FunctionPointer00("FuncPtr3b_plain_12", true, 1, 1001, f3b_1, f3b_2);
+
+ test_FunctionPointer00("FuncPtr3ab_plain_11", false, 1, 0, f3a_1, f3b_1);
+ test_FunctionPointer00("FuncPtr3ab_plain_22", false, 1, 0, f3a_2, f3b_2);
+ INFO("FuncPtr3_plain: bindPlainFunc<int, int>: END");
+ }
+
+ void test03_stdfunc_lambda() {
+ INFO("FuncPtr4_stdlambda: bindStdFunc<int, int>: START");
+ // FunctionDef(Func1Type func) <int, int>
+ std::function<int(int i)> func4a_stdlambda = [](int i)->int {
+ int res = i+100;
+ return res;;
+ };
+ std::function<int(int i)> func4b_stdlambda = [](int i)->int {
+ int res = i+1000;
+ return res;;
+ };
+ MyClassFunction f4a_1 = bindStdFunc<int, int>(100, func4a_stdlambda);
+ MyClassFunction f4a_2 = bindStdFunc(100, func4a_stdlambda);
+ test_FunctionPointer00("FuncPtr4a_stdlambda_11", true, 1, 101, f4a_1, f4a_1);
+ test_FunctionPointer00("FuncPtr4a_stdlambda_12", true, 1, 101, f4a_1, f4a_2);
+
+ MyClassFunction f4b_1 = bindStdFunc(200, func4b_stdlambda);
+ MyClassFunction f4b_2 = bindStdFunc(200, func4b_stdlambda);
+ test_FunctionPointer00("FuncPtr4b_stdlambda_11", true, 1, 1001, f4b_1, f4b_1);
+ test_FunctionPointer00("FuncPtr4b_stdlambda_12", true, 1, 1001, f4b_1, f4b_2);
+
+ test_FunctionPointer00("FuncPtr4ab_stdlambda_11", false, 1, 0, f4a_1, f4b_1);
+ test_FunctionPointer00("FuncPtr4ab_stdlambda_22", false, 1, 0, f4a_2, f4b_2);
+
+ MyClassFunction f4a_0 = bindStdFunc<int, int>(100);
+ MyClassFunction f4b_0 = bindStdFunc<int, int>(200);
+ test_FunctionPointer01("FuncPtr4a_stdlambda_01", true, f4a_0, f4a_1);
+ test_FunctionPointer01("FuncPtr4a_stdlambda_02", true, f4a_0, f4a_2);
+ test_FunctionPointer01("FuncPtr4b_stdlambda_01", true, f4b_0, f4b_1);
+ test_FunctionPointer01("FuncPtr4b_stdlambda_02", true, f4b_0, f4b_2);
+ test_FunctionPointer01("FuncPtr4ab_stdlambda_00", false, f4a_0, f4b_0);
+ test_FunctionPointer01("FuncPtr4ab_stdlambda_01", false, f4a_0, f4b_1);
+ test_FunctionPointer01("FuncPtr4ab_stdlambda_10", false, f4a_1, f4b_0);
+ INFO("FuncPtr4_stdlambda: bindStdFunc<int, int>: END");
+ }
+
+ void test04_captfunc_lambda() {
+ INFO("FuncPtr5_capture: bindCaptureFunc<int, int, int>: START");
+ // bindCaptureFunc(I& data, R(*func)(I&, A...))
+ // FunctionDef(Func1Type func) <int, int>
+ int offset100 = 100;
+ int offset1000 = 1000;
+
+ int(*func5a_capture)(int&, int) = [](int& offset, int i)->int {
+ int res = i+10000+offset;
+ return res;
+ };
+ int(*func5b_capture)(int&, int) = [](int& offset, int i)->int {
+ int res = i+100000+offset;
+ return res;
+ };
#if 0
- MyClassFunction f5a_o100_0 = bindCaptureFunc<int, int, int>(offset100,
- [](int& offset, int i)->int {
- int res = i+10000+offset;
- return res;;
- } );
- test_FunctionPointer01("FuncPtr5a_o100_capture_00", true, f5a_o100_0, f5a_o100_0);
+ MyClassFunction f5a_o100_0 = bindCaptureFunc<int, int, int>(offset100,
+ [](int& offset, int i)->int {
+ int res = i+10000+offset;
+ return res;;
+ } );
+ test_FunctionPointer01("FuncPtr5a_o100_capture_00", true, f5a_o100_0, f5a_o100_0);
#endif
- MyClassFunction f5a_o100_1 = bindCaptureFunc<int, int, int>(offset100, func5a_capture);
- MyClassFunction f5a_o100_2 = bindCaptureFunc(offset100, func5a_capture);
- test_FunctionPointer01("FuncPtr5a_o100_capture_12", true, f5a_o100_1, f5a_o100_2);
- test_FunctionPointer00("FuncPtr5a_o100_capture_11", true, 1, 10101, f5a_o100_1, f5a_o100_1);
- test_FunctionPointer00("FuncPtr5a_o100_capture_12", true, 1, 10101, f5a_o100_1, f5a_o100_2);
- // test_FunctionPointer01("FuncPtr5a_o100_capture_01", false, f5a_o100_0, f5a_o100_1);
- MyClassFunction f5a_o1000_1 = bindCaptureFunc(offset1000, func5a_capture);
- MyClassFunction f5a_o1000_2 = bindCaptureFunc(offset1000, func5a_capture);
- test_FunctionPointer01("FuncPtr5a_o1000_capture_12", true, f5a_o1000_1, f5a_o1000_2);
- test_FunctionPointer01("FuncPtr5a_o100_o1000_capture_11", false, f5a_o100_1, f5a_o1000_1);
-
- MyClassFunction f5b_o100_1 = bindCaptureFunc(offset100, func5b_capture);
- MyClassFunction f5b_o100_2 = bindCaptureFunc(offset100, func5b_capture);
- test_FunctionPointer00("FuncPtr5b_o100_capture_11", true, 1, 100101, f5b_o100_1, f5b_o100_1);
- test_FunctionPointer00("FuncPtr5b_o100_capture_12", true, 1, 100101, f5b_o100_1, f5b_o100_2);
-
- test_FunctionPointer00("FuncPtr5ab_o100_capture_11", false, 1, 0, f5a_o100_1, f5b_o100_1);
- test_FunctionPointer00("FuncPtr5ab_o100_capture_22", false, 1, 0, f5a_o100_2, f5b_o100_2);
- PRINTM("FuncPtr5_capture: bindCaptureFunc<int, int, int>: END");
- }
- {
- PRINTM("FuncPtr6_capture: bindCaptureFunc<int, std::shared_ptr<IntOffset>, int>: START");
- // bindCaptureFunc(I& data, R(*func)(I&, A...))
- // FunctionDef(Func1Type func) <int, int>
- std::shared_ptr<IntOffset> offset100(new IntOffset(100));
- std::shared_ptr<IntOffset> offset1000(new IntOffset(1000));
-
- int(*func6a_capture)(std::shared_ptr<IntOffset>&, int) = [](std::shared_ptr<IntOffset>& sharedOffset, int i)->int {
- int res = i+10000+sharedOffset->value;
- return res;
- };
- int(*func6b_capture)(std::shared_ptr<IntOffset>&, int) = [](std::shared_ptr<IntOffset>& sharedOffset, int i)->int {
- int res = i+100000+sharedOffset->value;
- return res;
- };
+ MyClassFunction f5a_o100_1 = bindCaptureFunc<int, int, int>(offset100, func5a_capture);
+ MyClassFunction f5a_o100_2 = bindCaptureFunc(offset100, func5a_capture);
+ test_FunctionPointer01("FuncPtr5a_o100_capture_12", true, f5a_o100_1, f5a_o100_2);
+ test_FunctionPointer00("FuncPtr5a_o100_capture_11", true, 1, 10101, f5a_o100_1, f5a_o100_1);
+ test_FunctionPointer00("FuncPtr5a_o100_capture_12", true, 1, 10101, f5a_o100_1, f5a_o100_2);
+ // test_FunctionPointer01("FuncPtr5a_o100_capture_01", false, f5a_o100_0, f5a_o100_1);
+ MyClassFunction f5a_o1000_1 = bindCaptureFunc(offset1000, func5a_capture);
+ MyClassFunction f5a_o1000_2 = bindCaptureFunc(offset1000, func5a_capture);
+ test_FunctionPointer01("FuncPtr5a_o1000_capture_12", true, f5a_o1000_1, f5a_o1000_2);
+ test_FunctionPointer01("FuncPtr5a_o100_o1000_capture_11", false, f5a_o100_1, f5a_o1000_1);
+
+ MyClassFunction f5b_o100_1 = bindCaptureFunc(offset100, func5b_capture);
+ MyClassFunction f5b_o100_2 = bindCaptureFunc(offset100, func5b_capture);
+ test_FunctionPointer00("FuncPtr5b_o100_capture_11", true, 1, 100101, f5b_o100_1, f5b_o100_1);
+ test_FunctionPointer00("FuncPtr5b_o100_capture_12", true, 1, 100101, f5b_o100_1, f5b_o100_2);
+
+ test_FunctionPointer00("FuncPtr5ab_o100_capture_11", false, 1, 0, f5a_o100_1, f5b_o100_1);
+ test_FunctionPointer00("FuncPtr5ab_o100_capture_22", false, 1, 0, f5a_o100_2, f5b_o100_2);
+ INFO("FuncPtr5_capture: bindCaptureFunc<int, int, int>: END");
+ }
+
+ void test05_captfunc_lambda() {
+ INFO("FuncPtr6_capture: bindCaptureFunc<int, std::shared_ptr<IntOffset>, int>: START");
+ // bindCaptureFunc(I& data, R(*func)(I&, A...))
+ // FunctionDef(Func1Type func) <int, int>
+ std::shared_ptr<IntOffset> offset100(new IntOffset(100));
+ std::shared_ptr<IntOffset> offset1000(new IntOffset(1000));
+
+ int(*func6a_capture)(std::shared_ptr<IntOffset>&, int) = [](std::shared_ptr<IntOffset>& sharedOffset, int i)->int {
+ int res = i+10000+sharedOffset->value;
+ return res;
+ };
+ int(*func6b_capture)(std::shared_ptr<IntOffset>&, int) = [](std::shared_ptr<IntOffset>& sharedOffset, int i)->int {
+ int res = i+100000+sharedOffset->value;
+ return res;
+ };
#if 0
- MyClassFunction f6a_o100_0 = bindCaptureFunc<int, std::shared_ptr<IntOffset>, int>(offset100,
- [](std::shared_ptr<IntOffset>& sharedOffset, int i)->int {
- int res = i+10000+sharedOffset->value;
- return res;;
- } );
- test_FunctionPointer01("FuncPtr6a_o100_capture_00", true, f6a_o100_0, f6a_o100_0);
+ MyClassFunction f6a_o100_0 = bindCaptureFunc<int, std::shared_ptr<IntOffset>, int>(offset100,
+ [](std::shared_ptr<IntOffset>& sharedOffset, int i)->int {
+ int res = i+10000+sharedOffset->value;
+ return res;;
+ } );
+ test_FunctionPointer01("FuncPtr6a_o100_capture_00", true, f6a_o100_0, f6a_o100_0);
#endif
- MyClassFunction f6a_o100_1 = bindCaptureFunc<int, std::shared_ptr<IntOffset>, int>(offset100, func6a_capture);
- MyClassFunction f6a_o100_2 = bindCaptureFunc(offset100, func6a_capture);
- test_FunctionPointer01("FuncPtr6a_o100_capture_12", true, f6a_o100_1, f6a_o100_2);
- test_FunctionPointer00("FuncPtr6a_o100_capture_11", true, 1, 10101, f6a_o100_1, f6a_o100_1);
- test_FunctionPointer00("FuncPtr6a_o100_capture_12", true, 1, 10101, f6a_o100_1, f6a_o100_2);
- // test_FunctionPointer01("FuncPtr6a_o100_capture_01", false, f6a_o100_0, f6a_o100_1);
- MyClassFunction f6a_o1000_1 = bindCaptureFunc(offset1000, func6a_capture);
- MyClassFunction f6a_o1000_2 = bindCaptureFunc(offset1000, func6a_capture);
- test_FunctionPointer01("FuncPtr6a_o1000_capture_12", true, f6a_o1000_1, f6a_o1000_2);
- test_FunctionPointer01("FuncPtr6a_o100_o1000_capture_11", false, f6a_o100_1, f6a_o1000_1);
-
- MyClassFunction f6b_o100_1 = bindCaptureFunc(offset100, func6b_capture);
- MyClassFunction f6b_o100_2 = bindCaptureFunc(offset100, func6b_capture);
- test_FunctionPointer00("FuncPtr6b_o100_capture_11", true, 1, 100101, f6b_o100_1, f6b_o100_1);
- test_FunctionPointer00("FuncPtr6b_o100_capture_12", true, 1, 100101, f6b_o100_1, f6b_o100_2);
-
- test_FunctionPointer00("FuncPtr6ab_o100_capture_11", false, 1, 0, f6a_o100_1, f6b_o100_1);
- test_FunctionPointer00("FuncPtr6ab_o100_capture_22", false, 1, 0, f6a_o100_2, f6b_o100_2);
- PRINTM("FuncPtr6_capture: bindCaptureFunc<int, std::shared_ptr<IntOffset>, int>: END");
- }
- {
- PRINTM("FuncPtr7_capture: bindCaptureFunc<int, IntOffset, int>: START");
- // bindCaptureFunc(I& data, R(*func)(I&, A...))
- // FunctionDef(Func1Type func) <int, int>
- IntOffset offset100(100);
- IntOffset offset1000(1000);
-
- int(*func7a_capture)(IntOffset&, int) = [](IntOffset& sharedOffset, int i)->int {
- int res = i+10000+sharedOffset.value;
- return res;
- };
- int(*func7b_capture)(IntOffset&, int) = [](IntOffset& sharedOffset, int i)->int {
- int res = i+100000+sharedOffset.value;
- return res;
- };
+ MyClassFunction f6a_o100_1 = bindCaptureFunc<int, std::shared_ptr<IntOffset>, int>(offset100, func6a_capture);
+ MyClassFunction f6a_o100_2 = bindCaptureFunc(offset100, func6a_capture);
+ test_FunctionPointer01("FuncPtr6a_o100_capture_12", true, f6a_o100_1, f6a_o100_2);
+ test_FunctionPointer00("FuncPtr6a_o100_capture_11", true, 1, 10101, f6a_o100_1, f6a_o100_1);
+ test_FunctionPointer00("FuncPtr6a_o100_capture_12", true, 1, 10101, f6a_o100_1, f6a_o100_2);
+ // test_FunctionPointer01("FuncPtr6a_o100_capture_01", false, f6a_o100_0, f6a_o100_1);
+ MyClassFunction f6a_o1000_1 = bindCaptureFunc(offset1000, func6a_capture);
+ MyClassFunction f6a_o1000_2 = bindCaptureFunc(offset1000, func6a_capture);
+ test_FunctionPointer01("FuncPtr6a_o1000_capture_12", true, f6a_o1000_1, f6a_o1000_2);
+ test_FunctionPointer01("FuncPtr6a_o100_o1000_capture_11", false, f6a_o100_1, f6a_o1000_1);
+
+ MyClassFunction f6b_o100_1 = bindCaptureFunc(offset100, func6b_capture);
+ MyClassFunction f6b_o100_2 = bindCaptureFunc(offset100, func6b_capture);
+ test_FunctionPointer00("FuncPtr6b_o100_capture_11", true, 1, 100101, f6b_o100_1, f6b_o100_1);
+ test_FunctionPointer00("FuncPtr6b_o100_capture_12", true, 1, 100101, f6b_o100_1, f6b_o100_2);
+
+ test_FunctionPointer00("FuncPtr6ab_o100_capture_11", false, 1, 0, f6a_o100_1, f6b_o100_1);
+ test_FunctionPointer00("FuncPtr6ab_o100_capture_22", false, 1, 0, f6a_o100_2, f6b_o100_2);
+ INFO("FuncPtr6_capture: bindCaptureFunc<int, std::shared_ptr<IntOffset>, int>: END");
+ }
+
+ void test06_captfunc_lambda() {
+ INFO("FuncPtr7_capture: bindCaptureFunc<int, IntOffset, int>: START");
+ // bindCaptureFunc(I& data, R(*func)(I&, A...))
+ // FunctionDef(Func1Type func) <int, int>
+ IntOffset offset100(100);
+ IntOffset offset1000(1000);
+
+ int(*func7a_capture)(IntOffset&, int) = [](IntOffset& sharedOffset, int i)->int {
+ int res = i+10000+sharedOffset.value;
+ return res;
+ };
+ int(*func7b_capture)(IntOffset&, int) = [](IntOffset& sharedOffset, int i)->int {
+ int res = i+100000+sharedOffset.value;
+ return res;
+ };
#if 0
- MyClassFunction f7a_o100_0 = bindCaptureFunc<int, IntOffset, int>(offset100,
- [](IntOffset& sharedOffset, int i)->int {
- int res = i+10000+sharedOffset.value;
- return res;;
- } );
- test_FunctionPointer01("FuncPtr7a_o100_capture_00", true, f7a_o100_0, f7a_o100_0);
+ MyClassFunction f7a_o100_0 = bindCaptureFunc<int, IntOffset, int>(offset100,
+ [](IntOffset& sharedOffset, int i)->int {
+ int res = i+10000+sharedOffset.value;
+ return res;;
+ } );
+ test_FunctionPointer01("FuncPtr7a_o100_capture_00", true, f7a_o100_0, f7a_o100_0);
#endif
- PRINTM("f7a_o100_1 copy_ctor");
- MyClassFunction f7a_o100_1 = bindCaptureFunc<int, IntOffset, int>(offset100, func7a_capture);
- PRINTM("f7a_o100_1 copy_ctor done");
- PRINTM("f7a_o100_2 move_ctor");
- MyClassFunction f7a_o100_2 = bindCaptureFunc(IntOffset(100), func7a_capture);
- PRINTM("f7a_o100_2 move_ctor done");
- test_FunctionPointer01("FuncPtr7a_o100_capture_12", true, f7a_o100_1, f7a_o100_2);
- test_FunctionPointer00("FuncPtr7a_o100_capture_11", true, 1, 10101, f7a_o100_1, f7a_o100_1);
- test_FunctionPointer00("FuncPtr7a_o100_capture_12", true, 1, 10101, f7a_o100_1, f7a_o100_2);
- // test_FunctionPointer01("FuncPtr7a_o100_capture_01", false, f7a_o100_0, f7a_o100_1);
- MyClassFunction f7a_o1000_1 = bindCaptureFunc(offset1000, func7a_capture);
- MyClassFunction f7a_o1000_2 = bindCaptureFunc(offset1000, func7a_capture);
- test_FunctionPointer01("FuncPtr7a_o1000_capture_12", true, f7a_o1000_1, f7a_o1000_2);
- test_FunctionPointer01("FuncPtr7a_o100_o1000_capture_11", false, f7a_o100_1, f7a_o1000_1);
-
- MyClassFunction f7b_o100_1 = bindCaptureFunc(offset100, func7b_capture);
- MyClassFunction f7b_o100_2 = bindCaptureFunc(offset100, func7b_capture);
- test_FunctionPointer00("FuncPtr7b_o100_capture_11", true, 1, 100101, f7b_o100_1, f7b_o100_1);
- test_FunctionPointer00("FuncPtr7b_o100_capture_12", true, 1, 100101, f7b_o100_1, f7b_o100_2);
-
- test_FunctionPointer00("FuncPtr7ab_o100_capture_11", false, 1, 0, f7a_o100_1, f7b_o100_1);
- test_FunctionPointer00("FuncPtr7ab_o100_capture_22", false, 1, 0, f7a_o100_2, f7b_o100_2);
- PRINTM("FuncPtr7_capture: bindCaptureFunc<int, IntOffset, int>: END");
- }
+ INFO("f7a_o100_1 copy_ctor");
+ MyClassFunction f7a_o100_1 = bindCaptureFunc<int, IntOffset, int>(offset100, func7a_capture);
+ INFO("f7a_o100_1 copy_ctor done");
+ INFO("f7a_o100_2 move_ctor");
+ MyClassFunction f7a_o100_2 = bindCaptureFunc(IntOffset(100), func7a_capture);
+ INFO("f7a_o100_2 move_ctor done");
+ test_FunctionPointer01("FuncPtr7a_o100_capture_12", true, f7a_o100_1, f7a_o100_2);
+ test_FunctionPointer00("FuncPtr7a_o100_capture_11", true, 1, 10101, f7a_o100_1, f7a_o100_1);
+ test_FunctionPointer00("FuncPtr7a_o100_capture_12", true, 1, 10101, f7a_o100_1, f7a_o100_2);
+ // test_FunctionPointer01("FuncPtr7a_o100_capture_01", false, f7a_o100_0, f7a_o100_1);
+ MyClassFunction f7a_o1000_1 = bindCaptureFunc(offset1000, func7a_capture);
+ MyClassFunction f7a_o1000_2 = bindCaptureFunc(offset1000, func7a_capture);
+ test_FunctionPointer01("FuncPtr7a_o1000_capture_12", true, f7a_o1000_1, f7a_o1000_2);
+ test_FunctionPointer01("FuncPtr7a_o100_o1000_capture_11", false, f7a_o100_1, f7a_o1000_1);
+
+ MyClassFunction f7b_o100_1 = bindCaptureFunc(offset100, func7b_capture);
+ MyClassFunction f7b_o100_2 = bindCaptureFunc(offset100, func7b_capture);
+ test_FunctionPointer00("FuncPtr7b_o100_capture_11", true, 1, 100101, f7b_o100_1, f7b_o100_1);
+ test_FunctionPointer00("FuncPtr7b_o100_capture_12", true, 1, 100101, f7b_o100_1, f7b_o100_2);
+
+ test_FunctionPointer00("FuncPtr7ab_o100_capture_11", false, 1, 0, f7a_o100_1, f7b_o100_1);
+ test_FunctionPointer00("FuncPtr7ab_o100_capture_22", false, 1, 0, f7a_o100_2, f7b_o100_2);
+ INFO("FuncPtr7_capture: bindCaptureFunc<int, IntOffset, int>: END");
}
};
-int main(int argc, char *argv[]) {
- (void)argc;
- (void)argv;
-
- Cppunit_tests test1;
- return test1.run();
-}
+METHOD_AS_TEST_CASE( TestFunctionDef01::test01_memberfunc_this, "Test FunctionDef 01 - 01 memberfunc");
+METHOD_AS_TEST_CASE( TestFunctionDef01::test02_plainfunc_static, "Test FunctionDef 01 - 02 plainfunc");
+METHOD_AS_TEST_CASE( TestFunctionDef01::test03_stdfunc_lambda, "Test FunctionDef 01 - 03 stdfunc");
+METHOD_AS_TEST_CASE( TestFunctionDef01::test04_captfunc_lambda, "Test FunctionDef 01 - 04 captfunc");
+METHOD_AS_TEST_CASE( TestFunctionDef01::test05_captfunc_lambda, "Test FunctionDef 01 - 05 captfunc");
+METHOD_AS_TEST_CASE( TestFunctionDef01::test06_captfunc_lambda, "Test FunctionDef 01 - 06 captfunc");
diff --git a/test/test_lfringbuffer01.cpp b/test/test_lfringbuffer01.cpp
index 065b94e..e1b4f25 100644
--- a/test/test_lfringbuffer01.cpp
+++ b/test/test_lfringbuffer01.cpp
@@ -4,7 +4,9 @@
#include <cstring>
#include <memory>
-#include <cppunit.h>
+#define CATCH_CONFIG_MAIN
+#include <catch2/catch_amalgamated.hpp>
+#include <jau/test/catch2_ext.hpp>
#include <jau/ringbuffer.hpp>
@@ -34,19 +36,19 @@ typedef std::shared_ptr<Integer> SharedType;
typedef ringbuffer<SharedType, nullptr, jau::nsize_t> SharedTypeRingbuffer;
// Test examples.
-class Cppunit_tests : public Cppunit {
+class TestRingbuffer01 {
private:
std::shared_ptr<SharedTypeRingbuffer> createEmpty(jau::nsize_t initialCapacity) {
std::shared_ptr<SharedTypeRingbuffer> rb = std::shared_ptr<SharedTypeRingbuffer>(new SharedTypeRingbuffer(initialCapacity));
- CHECKTM("Is !empty-1 "+rb->toString(), rb->isEmpty());
- CHECKTM("Is !empty-2 "+rb->toString(), rb->isEmpty2());
+ REQUIRE_MSG("empty-1 "+rb->toString(), rb->isEmpty());
+ REQUIRE_MSG("empty-2 "+rb->toString(), rb->isEmpty2());
return rb;
}
std::shared_ptr<SharedTypeRingbuffer> createFull(const std::vector<std::shared_ptr<Integer>> & source) {
std::shared_ptr<SharedTypeRingbuffer> rb = std::shared_ptr<SharedTypeRingbuffer>(new SharedTypeRingbuffer(source));
- CHECKTM("Is !full-1 "+rb->toString(), rb->isFull());
- CHECKTM("Is !full-2 "+rb->toString(), rb->isFull2());
+ REQUIRE_MSG("full-1 "+rb->toString(), rb->isFull());
+ REQUIRE_MSG("full-2 "+rb->toString(), rb->isFull2());
return rb;
}
@@ -62,199 +64,203 @@ class Cppunit_tests : public Cppunit {
(void) clearRef;
jau::nsize_t preSize = rb.getSize();
- CHECKM("Wrong capacity "+rb.toString(), capacity, rb.capacity());
- CHECKTM("Too low capacity to read "+std::to_string(len)+" elems: "+rb.toString(), capacity >= len);
- CHECKTM("Too low size to read "+std::to_string(len)+" elems: "+rb.toString(), preSize >= len);
- CHECKTM("Is empty "+rb.toString(), !rb.isEmpty());
+ REQUIRE_MSG("capacity "+rb.toString(), capacity == rb.capacity());
+ REQUIRE_MSG("capacity at read "+std::to_string(len)+" elems: "+rb.toString(), capacity >= len);
+ REQUIRE_MSG("size at read "+std::to_string(len)+" elems: "+rb.toString(), preSize >= len);
+ REQUIRE_MSG("not empty "+rb.toString(), !rb.isEmpty());
for(jau::nsize_t i=0; i<len; i++) {
SharedType svI = rb.get();
- CHECKTM("Empty at read #"+std::to_string(i+1)+": "+rb.toString(), svI!=nullptr);
- CHECKM("Wrong value at read #"+std::to_string(i+1)+": "+rb.toString(), startValue+i, svI->intValue());
+ REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb.toString(), svI!=nullptr);
+ REQUIRE_MSG("value at read #"+std::to_string(i+1)+": "+rb.toString(), startValue+i == svI->intValue());
}
- CHECKM("Invalid size "+rb.toString(), preSize-len, rb.getSize());
- CHECKTM("Invalid free slots after reading "+std::to_string(len)+": "+rb.toString(), rb.getFreeSlots()>= len);
- CHECKTM("Is full "+rb.toString(), !rb.isFull());
+ REQUIRE_MSG("size "+rb.toString(), preSize-len == rb.getSize());
+ REQUIRE_MSG("free slots after reading "+std::to_string(len)+": "+rb.toString(), rb.getFreeSlots()>= len);
+ REQUIRE_MSG("not full "+rb.toString(), !rb.isFull());
}
void writeTestImpl(SharedTypeRingbuffer &rb, jau::nsize_t capacity, jau::nsize_t len, jau::nsize_t startValue) {
jau::nsize_t preSize = rb.getSize();
- CHECKM("Wrong capacity "+rb.toString(), capacity, rb.capacity());
- CHECKTM("Too low capacity to write "+std::to_string(len)+" elems: "+rb.toString(), capacity >= len);
- CHECKTM("Too low size to write "+std::to_string(len)+" elems: "+rb.toString(), preSize+len <= capacity);
- CHECKTM("Is full "+rb.toString(), !rb.isFull());
+ REQUIRE_MSG("capacity "+rb.toString(), capacity == rb.capacity());
+ REQUIRE_MSG("capacity at write "+std::to_string(len)+" elems: "+rb.toString(), capacity >= len);
+ REQUIRE_MSG("size at write "+std::to_string(len)+" elems: "+rb.toString(), preSize+len <= capacity);
+ REQUIRE_MSG("not full "+rb.toString(), !rb.isFull());
for(jau::nsize_t i=0; i<len; i++) {
- std::string m = "Buffer is full at put #"+std::to_string(i)+": "+rb.toString();
- CHECKTM(m, rb.put( SharedType( new Integer(startValue+i) ) ) );
+ std::string m = "buffer put #"+std::to_string(i)+": "+rb.toString();
+ REQUIRE_MSG(m, rb.put( SharedType( new Integer(startValue+i) ) ) );
}
- CHECKM("Invalid size "+rb.toString(), preSize+len, rb.getSize());
- CHECKTM("Is empty "+rb.toString(), !rb.isEmpty());
+ REQUIRE_MSG("size "+rb.toString(), preSize+len == rb.getSize());
+ REQUIRE_MSG("not empty "+rb.toString(), !rb.isEmpty());
}
void moveGetPutImpl(SharedTypeRingbuffer &rb, jau::nsize_t pos) {
- CHECKTM("RB is empty "+rb.toString(), !rb.isEmpty());
+ REQUIRE_MSG("not empty "+rb.toString(), !rb.isEmpty());
for(jau::nsize_t i=0; i<pos; i++) {
- CHECKM("MoveFull.get failed "+rb.toString(), i, rb.get()->intValue());
- CHECKTM("MoveFull.put failed "+rb.toString(), rb.put( SharedType( new Integer(i) ) ) );
+ REQUIRE_MSG("moveFull.get "+rb.toString(), i == rb.get()->intValue());
+ REQUIRE_MSG("moveFull.put "+rb.toString(), rb.put( SharedType( new Integer(i) ) ) );
}
}
void movePutGetImpl(SharedTypeRingbuffer &rb, jau::nsize_t pos) {
- CHECKTM("RB is full "+rb.toString(), !rb.isFull());
+ REQUIRE_MSG("RB is full "+rb.toString(), !rb.isFull());
for(jau::nsize_t i=0; i<pos; i++) {
- CHECKTM("MoveEmpty.put failed "+rb.toString(), rb.put( SharedType( new Integer(600+i) ) ) );
- CHECKM("MoveEmpty.get failed "+rb.toString(), 600+i, rb.get()->intValue());
+ REQUIRE_MSG("moveEmpty.put "+rb.toString(), rb.put( SharedType( new Integer(600+i) ) ) );
+ REQUIRE_MSG("moveEmpty.get "+rb.toString(), 600+i == rb.get()->intValue());
}
}
+ public:
+
void test01_FullRead() {
jau::nsize_t capacity = 11;
std::vector<SharedType> source = createIntArray(capacity, 0);
std::shared_ptr<SharedTypeRingbuffer> rb = createFull(source);
- fprintf(stderr, "test01_FullRead: Created / %s\n", rb->toString().c_str());
- CHECKM("Not full size "+rb->toString(), capacity, rb->getSize());
- CHECKTM("Not full-1 "+rb->toString(), rb->isFull());
- CHECKTM("Not full-2 "+rb->toString(), rb->isFull2());
+ INFO_STR("test01_FullRead: Created / "+ rb->toString());
+ REQUIRE_MSG("full size "+rb->toString(), capacity == rb->getSize());
+ REQUIRE_MSG("full-1 "+rb->toString(), rb->isFull());
+ REQUIRE_MSG("full-2 "+rb->toString(), rb->isFull2());
readTestImpl(*rb, true, capacity, capacity, 0);
- fprintf(stderr, "test01_FullRead: PostRead / %s\n", rb->toString().c_str());
- CHECKTM("Not empty-1 "+rb->toString(), rb->isEmpty());
- CHECKTM("Not empty-2 "+rb->toString(), rb->isEmpty2());
+ INFO_STR("test01_FullRead: PostRead / " + rb->toString());
+ REQUIRE_MSG("empty-1 "+rb->toString(), rb->isEmpty());
+ REQUIRE_MSG("empty-2 "+rb->toString(), rb->isEmpty2());
}
void test02_EmptyWrite() {
jau::nsize_t capacity = 11;
std::shared_ptr<SharedTypeRingbuffer> rb = createEmpty(capacity);
- fprintf(stderr, "test01_EmptyWrite: Created / %s\n", rb->toString().c_str());
- CHECKM("Not zero size "+rb->toString(), 0, rb->getSize());
- CHECKTM("Not empty-1 "+rb->toString(), rb->isEmpty());
- CHECKTM("Not empty-2 "+rb->toString(), rb->isEmpty2());
+ INFO( std::string("test01_EmptyWrite: Created / ") + rb->toString().c_str());
+ REQUIRE_MSG("zero size "+rb->toString(), 0 == rb->getSize());
+ REQUIRE_MSG("empty-1 "+rb->toString(), rb->isEmpty());
+ REQUIRE_MSG("empty-2 "+rb->toString(), rb->isEmpty2());
writeTestImpl(*rb, capacity, capacity, 0);
- fprintf(stderr, "test01_EmptyWrite: PostWrite / %s\n", rb->toString().c_str());
- CHECKM("Not full size "+rb->toString(), capacity, rb->getSize());
- CHECKTM("Not full-1 "+rb->toString(), rb->isFull());
- CHECKTM("Not full-2 "+rb->toString(), rb->isFull2());
+ INFO( std::string("test01_EmptyWrite: PostWrite / ") + rb->toString().c_str());
+ REQUIRE_MSG("full size "+rb->toString(), capacity == rb->getSize());
+ REQUIRE_MSG("full-1 "+rb->toString(), rb->isFull());
+ REQUIRE_MSG("full-2 "+rb->toString(), rb->isFull2());
readTestImpl(*rb, true, capacity, capacity, 0);
- fprintf(stderr, "test01_EmptyWrite: PostRead / %s\n", rb->toString().c_str());
- CHECKTM("Not empty-1 "+rb->toString(), rb->isEmpty());
- CHECKTM("Not empty-2 "+rb->toString(), rb->isEmpty2());
+ INFO( std::string("test01_EmptyWrite: PostRead / ") + rb->toString().c_str());
+ REQUIRE_MSG("empty-1 "+rb->toString(), rb->isEmpty());
+ REQUIRE_MSG("empty-2 "+rb->toString(), rb->isEmpty2());
}
void test03_FullReadReset() {
jau::nsize_t capacity = 11;
std::vector<SharedType> source = createIntArray(capacity, 0);
std::shared_ptr<SharedTypeRingbuffer> rb = createFull(source);
- fprintf(stderr, "test01_FullReadReset: Created / %s\n", rb->toString().c_str());
- CHECKTM("Not full-1 "+rb->toString(), rb->isFull());
- CHECKTM("Not full-2 "+rb->toString(), rb->isFull2());
+ INFO_STR("test01_FullReadReset: Created / " + rb->toString());
+ REQUIRE_MSG("full-1 "+rb->toString(), rb->isFull());
+ REQUIRE_MSG("full-2 "+rb->toString(), rb->isFull2());
rb->reset(source);
- fprintf(stderr, "test01_FullReadReset: Post Reset w/ source / %s\n", rb->toString().c_str());
- CHECKTM("Not full-1 "+rb->toString(), rb->isFull());
- CHECKTM("Not full-2 "+rb->toString(), rb->isFull2());
+ INFO_STR("test01_FullReadReset: Post Reset w/ source / " + rb->toString());
+ REQUIRE_MSG("full-1 "+rb->toString(), rb->isFull());
+ REQUIRE_MSG("full-2 "+rb->toString(), rb->isFull2());
readTestImpl(*rb, false, capacity, capacity, 0);
- fprintf(stderr, "test01_FullReadReset: Post Read / %s\n", rb->toString().c_str());
- CHECKTM("Not empty-1 "+rb->toString(), rb->isEmpty());
- CHECKTM("Not empty-2 "+rb->toString(), rb->isEmpty2());
+ INFO_STR("test01_FullReadReset: Post Read / " + rb->toString());
+ REQUIRE_MSG("empty-1 "+rb->toString(), rb->isEmpty());
+ REQUIRE_MSG("empty-2 "+rb->toString(), rb->isEmpty2());
rb->reset(source);
- fprintf(stderr, "test01_FullReadReset: Post Reset w/ source / %s\n", rb->toString().c_str());
- CHECKTM("Not full-1 "+rb->toString(), rb->isFull());
- CHECKTM("Not full-2 "+rb->toString(), rb->isFull2());
+ INFO_STR("test01_FullReadReset: Post Reset w/ source / " + rb->toString());
+ REQUIRE_MSG("full-1 "+rb->toString(), rb->isFull());
+ REQUIRE_MSG("full-2 "+rb->toString(), rb->isFull2());
readTestImpl(*rb, false, capacity, capacity, 0);
- fprintf(stderr, "test01_FullReadReset: Post Read / %s\n", rb->toString().c_str());
- CHECKTM("Not empty-1 "+rb->toString(), rb->isEmpty());
- CHECKTM("Not empty-2 "+rb->toString(), rb->isEmpty2());
+ INFO_STR("test01_FullReadReset: Post Read / " + rb->toString());
+ REQUIRE_MSG("empty-1 "+rb->toString(), rb->isEmpty());
+ REQUIRE_MSG("empty-2 "+rb->toString(), rb->isEmpty2());
}
void test04_EmptyWriteClear() {
jau::nsize_t capacity = 11;
std::shared_ptr<SharedTypeRingbuffer> rb = createEmpty(capacity);
- CHECKTM("Not empty-1 "+rb->toString(), rb->isEmpty());
- CHECKTM("Not empty-2 "+rb->toString(), rb->isEmpty2());
+ REQUIRE_MSG("empty-1 "+rb->toString(), rb->isEmpty());
+ REQUIRE_MSG("empty-2 "+rb->toString(), rb->isEmpty2());
rb->clear();
- CHECKTM("Not empty-1 "+rb->toString(), rb->isEmpty());
- CHECKTM("Not empty-2 "+rb->toString(), rb->isEmpty2());
+ REQUIRE_MSG("empty-1 "+rb->toString(), rb->isEmpty());
+ REQUIRE_MSG("empty-2 "+rb->toString(), rb->isEmpty2());
writeTestImpl(*rb, capacity, capacity, 0);
- CHECKTM("Not full-1 "+rb->toString(), rb->isFull());
- CHECKTM("Not full-2 "+rb->toString(), rb->isFull2());
+ REQUIRE_MSG("full-1 "+rb->toString(), rb->isFull());
+ REQUIRE_MSG("full-2 "+rb->toString(), rb->isFull2());
readTestImpl(*rb, false, capacity, capacity, 0);
- CHECKTM("Not empty-1 "+rb->toString(), rb->isEmpty());
- CHECKTM("Not empty-2 "+rb->toString(), rb->isEmpty2());
+ REQUIRE_MSG("empty-1 "+rb->toString(), rb->isEmpty());
+ REQUIRE_MSG("empty-2 "+rb->toString(), rb->isEmpty2());
rb->clear();
- CHECKTM("Not empty-1 "+rb->toString(), rb->isEmpty());
- CHECKTM("Not empty-2 "+rb->toString(), rb->isEmpty2());
+ REQUIRE_MSG("empty-1 "+rb->toString(), rb->isEmpty());
+ REQUIRE_MSG("empty-2 "+rb->toString(), rb->isEmpty2());
writeTestImpl(*rb, capacity, capacity, 0);
- CHECKTM("Not full-1 "+rb->toString(), rb->isFull());
- CHECKTM("Not full-2 "+rb->toString(), rb->isFull2());
+ REQUIRE_MSG("full-1 "+rb->toString(), rb->isFull());
+ REQUIRE_MSG("full-2 "+rb->toString(), rb->isFull2());
readTestImpl(*rb, false, capacity, capacity, 0);
- CHECKTM("Not empty-1 "+rb->toString(), rb->isEmpty());
- CHECKTM("Not empty-2 "+rb->toString(), rb->isEmpty2());
+ REQUIRE_MSG("empty-1 "+rb->toString(), rb->isEmpty());
+ REQUIRE_MSG("empty-2 "+rb->toString(), rb->isEmpty2());
}
void test05_ReadResetMid01() {
jau::nsize_t capacity = 11;
std::vector<SharedType> source = createIntArray(capacity, 0);
std::shared_ptr<SharedTypeRingbuffer> rb = createFull(source);
- CHECKTM("Not full-1 "+rb->toString(), rb->isFull());
- CHECKTM("Not full-2 "+rb->toString(), rb->isFull2());
+ REQUIRE_MSG("full-1 "+rb->toString(), rb->isFull());
+ REQUIRE_MSG("full-2 "+rb->toString(), rb->isFull2());
rb->reset(source);
- CHECKTM("Not full-1 "+rb->toString(), rb->isFull());
- CHECKTM("Not full-2 "+rb->toString(), rb->isFull2());
+ REQUIRE_MSG("full-1 "+rb->toString(), rb->isFull());
+ REQUIRE_MSG("full-2 "+rb->toString(), rb->isFull2());
readTestImpl(*rb, false, capacity, 5, 0);
- CHECKTM("Is empty "+rb->toString(), !rb->isEmpty());
- CHECKTM("Is Full "+rb->toString(), !rb->isFull());
+ REQUIRE_MSG("not empty "+rb->toString(), !rb->isEmpty());
+ REQUIRE_MSG("not Full "+rb->toString(), !rb->isFull());
rb->reset(source);
- CHECKTM("Not full-1 "+rb->toString(), rb->isFull());
- CHECKTM("Not full-2 "+rb->toString(), rb->isFull2());
+ REQUIRE_MSG("full-1 "+rb->toString(), rb->isFull());
+ REQUIRE_MSG("full-2 "+rb->toString(), rb->isFull2());
readTestImpl(*rb, false, capacity, capacity, 0);
- CHECKTM("Not empty-1 "+rb->toString(), rb->isEmpty());
- CHECKTM("Not empty-2 "+rb->toString(), rb->isEmpty2());
+ REQUIRE_MSG("empty-1 "+rb->toString(), rb->isEmpty());
+ REQUIRE_MSG("empty-2 "+rb->toString(), rb->isEmpty2());
}
void test06_ReadResetMid02() {
jau::nsize_t capacity = 11;
std::vector<SharedType> source = createIntArray(capacity, 0);
std::shared_ptr<SharedTypeRingbuffer> rb = createFull(source);
- CHECKTM("Not full-1 "+rb->toString(), rb->isFull());
- CHECKTM("Not full-2 "+rb->toString(), rb->isFull2());
+ REQUIRE_MSG("full-1 "+rb->toString(), rb->isFull());
+ REQUIRE_MSG("full-2 "+rb->toString(), rb->isFull2());
rb->reset(source);
- CHECKTM("Not full-1 "+rb->toString(), rb->isFull());
- CHECKTM("Not full-2 "+rb->toString(), rb->isFull2());
+ REQUIRE_MSG("full-1 "+rb->toString(), rb->isFull());
+ REQUIRE_MSG("full-2 "+rb->toString(), rb->isFull2());
moveGetPutImpl(*rb, 5);
readTestImpl(*rb, false, capacity, 5, 5);
- CHECKTM("Is empty "+rb->toString(), !rb->isEmpty());
- CHECKTM("Is Full "+rb->toString(), !rb->isFull());
+ REQUIRE_MSG("not empty "+rb->toString(), !rb->isEmpty());
+ REQUIRE_MSG("not Full "+rb->toString(), !rb->isFull());
rb->reset(source);
- CHECKTM("Not full-1 "+rb->toString(), rb->isFull());
- CHECKTM("Not full-2 "+rb->toString(), rb->isFull2());
+ REQUIRE_MSG("full-1 "+rb->toString(), rb->isFull());
+ REQUIRE_MSG("full-2 "+rb->toString(), rb->isFull2());
readTestImpl(*rb, false, capacity, capacity, 0);
- CHECKTM("Not empty-1 "+rb->toString(), rb->isEmpty());
- CHECKTM("Not empty-2 "+rb->toString(), rb->isEmpty2());
+ REQUIRE_MSG("empty-1 "+rb->toString(), rb->isEmpty());
+ REQUIRE_MSG("empty-2 "+rb->toString(), rb->isEmpty2());
}
+ private:
+
void test_GrowFullImpl(jau::nsize_t initialCapacity, jau::nsize_t pos) {
jau::nsize_t growAmount = 5;
jau::nsize_t grownCapacity = initialCapacity+growAmount;
@@ -263,52 +269,52 @@ class Cppunit_tests : public Cppunit {
for(jau::nsize_t i=0; i<initialCapacity; i++) {
SharedType svI = rb->get();
- CHECKTM("Empty at read #"+std::to_string(i+1)+": "+rb->toString(), svI!=nullptr);
- CHECKM("Wrong value at read #"+std::to_string(i+1)+": "+rb->toString(), (0+i)%initialCapacity, svI->intValue());
+ REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb->toString(), svI!=nullptr);
+ REQUIRE_MSG("value at read #"+std::to_string(i+1)+": "+rb->toString(), (0+i)%initialCapacity == svI->intValue());
}
- CHECKM("Not zero size "+rb->toString(), 0, rb->getSize());
+ REQUIRE_MSG("zero size "+rb->toString(), 0 == rb->getSize());
rb->reset(source);
- CHECKM("Not orig size "+rb->toString(), initialCapacity, rb->getSize());
+ REQUIRE_MSG("orig size "+rb->toString(), initialCapacity == rb->getSize());
moveGetPutImpl(*rb, pos);
// PRINTM("X02 "+rb->toString());
// rb->dump(stderr, "X02");
rb->recapacity(grownCapacity);
- CHECKM("Wrong capacity "+rb->toString(), grownCapacity, rb->capacity());
- CHECKM("Not orig size "+rb->toString(), initialCapacity, rb->getSize());
- CHECKTM("Is full "+rb->toString(), !rb->isFull());
- CHECKTM("Is empty "+rb->toString(), !rb->isEmpty());
+ REQUIRE_MSG("capacity "+rb->toString(), grownCapacity == rb->capacity());
+ REQUIRE_MSG("orig size "+rb->toString(), initialCapacity == rb->getSize());
+ REQUIRE_MSG("not full "+rb->toString(), !rb->isFull());
+ REQUIRE_MSG("not empty "+rb->toString(), !rb->isEmpty());
// PRINTM("X03 "+rb->toString());
// rb->dump(stderr, "X03");
for(jau::nsize_t i=0; i<growAmount; i++) {
- CHECKTM("Buffer is full at put #"+std::to_string(i)+": "+rb->toString(), rb->put( SharedType( new Integer(100+i) ) ) );
+ REQUIRE_MSG("buffer not full at put #"+std::to_string(i)+": "+rb->toString(), rb->put( SharedType( new Integer(100+i) ) ) );
}
- CHECKM("Not new size "+rb->toString(), grownCapacity, rb->getSize());
- CHECKTM("Not full-1 "+rb->toString(), rb->isFull());
- CHECKTM("Not full-2 "+rb->toString(), rb->isFull2());
+ REQUIRE_MSG("new size "+rb->toString(), grownCapacity == rb->getSize());
+ REQUIRE_MSG("full-1 "+rb->toString(), rb->isFull());
+ REQUIRE_MSG("full-2 "+rb->toString(), rb->isFull2());
for(jau::nsize_t i=0; i<initialCapacity; i++) {
SharedType svI = rb->get();
// PRINTM("X05["+std::to_string(i)+"]: "+rb->toString()+", svI-null: "+std::to_string(svI==nullptr));
- CHECKTM("Empty at read #"+std::to_string(i+1)+": "+rb->toString(), svI!=nullptr);
- CHECKM("Wrong value at read #"+std::to_string(i+1)+": "+rb->toString(), (pos+i)%initialCapacity, svI->intValue());
+ REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb->toString(), svI!=nullptr);
+ REQUIRE_MSG("value at read #"+std::to_string(i+1)+": "+rb->toString(), (pos+i)%initialCapacity == svI->intValue());
}
for(jau::nsize_t i=0; i<growAmount; i++) {
SharedType svI = rb->get();
// PRINTM("X07["+std::to_string(i)+"]: "+rb->toString()+", svI-null: "+std::to_string(svI==nullptr));
- CHECKTM("Empty at read #"+std::to_string(i+1)+": "+rb->toString(), svI!=nullptr);
- CHECKM("Wrong value at read #"+std::to_string(i+1)+": "+rb->toString(), 100+i, svI->intValue());
+ REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb->toString(), svI!=nullptr);
+ REQUIRE_MSG("value at read #"+std::to_string(i+1)+": "+rb->toString(), 100+i == svI->intValue());
}
- CHECKM("Not zero size "+rb->toString(), 0, rb->getSize());
- CHECKTM("Not empty-1 "+rb->toString(), rb->isEmpty());
- CHECKTM("Not empty-2 "+rb->toString(), rb->isEmpty2());
+ REQUIRE_MSG("zero size "+rb->toString(), 0 == rb->getSize());
+ REQUIRE_MSG("empty-1 "+rb->toString(), rb->isEmpty());
+ REQUIRE_MSG("empty-2 "+rb->toString(), rb->isEmpty2());
- CHECKTM("Is full "+rb->toString(), !rb->isFull());
+ REQUIRE_MSG("not full "+rb->toString(), !rb->isFull());
}
public:
@@ -338,30 +344,20 @@ class Cppunit_tests : public Cppunit {
test_GrowFullImpl(11, 11-1-3);
}
- void test_list() override {
- test01_FullRead();
- test02_EmptyWrite();
- test03_FullReadReset();
- test04_EmptyWriteClear();
- test05_ReadResetMid01();
- test06_ReadResetMid02();
-
- test20_GrowFull01_Begin();
- test21_GrowFull02_Begin1();
- test22_GrowFull03_Begin2();
- test23_GrowFull04_Begin3();
- test24_GrowFull05_End();
- test25_GrowFull11_End1();
- test26_GrowFull12_End2();
- test27_GrowFull13_End3();
- }
};
-int main(int argc, char *argv[]) {
- (void)argc;
- (void)argv;
-
- Cppunit_tests test1;
- return test1.run();
-}
+METHOD_AS_TEST_CASE( TestRingbuffer01::test01_FullRead, "Test TestRingbuffer 01- 01");
+METHOD_AS_TEST_CASE( TestRingbuffer01::test02_EmptyWrite, "Test TestRingbuffer 01- 02");
+METHOD_AS_TEST_CASE( TestRingbuffer01::test03_FullReadReset, "Test TestRingbuffer 01- 03");
+METHOD_AS_TEST_CASE( TestRingbuffer01::test04_EmptyWriteClear, "Test TestRingbuffer 01- 04");
+METHOD_AS_TEST_CASE( TestRingbuffer01::test05_ReadResetMid01, "Test TestRingbuffer 01- 05");
+METHOD_AS_TEST_CASE( TestRingbuffer01::test06_ReadResetMid02, "Test TestRingbuffer 01- 06");
+METHOD_AS_TEST_CASE( TestRingbuffer01::test20_GrowFull01_Begin, "Test TestRingbuffer 01- 20");
+METHOD_AS_TEST_CASE( TestRingbuffer01::test21_GrowFull02_Begin1, "Test TestRingbuffer 01- 21");
+METHOD_AS_TEST_CASE( TestRingbuffer01::test22_GrowFull03_Begin2, "Test TestRingbuffer 01- 22");
+METHOD_AS_TEST_CASE( TestRingbuffer01::test23_GrowFull04_Begin3, "Test TestRingbuffer 01- 23");
+METHOD_AS_TEST_CASE( TestRingbuffer01::test24_GrowFull05_End, "Test TestRingbuffer 01- 24");
+METHOD_AS_TEST_CASE( TestRingbuffer01::test25_GrowFull11_End1, "Test TestRingbuffer 01- 25");
+METHOD_AS_TEST_CASE( TestRingbuffer01::test26_GrowFull12_End2, "Test TestRingbuffer 01- 26");
+METHOD_AS_TEST_CASE( TestRingbuffer01::test27_GrowFull13_End3, "Test TestRingbuffer 01- 27");
diff --git a/test/test_lfringbuffer11.cpp b/test/test_lfringbuffer11.cpp
index fe824a6..9bcb86b 100644
--- a/test/test_lfringbuffer11.cpp
+++ b/test/test_lfringbuffer11.cpp
@@ -6,7 +6,9 @@
#include <thread>
#include <pthread.h>
-#include <cppunit.h>
+#define CATCH_CONFIG_MAIN
+#include <catch2/catch_amalgamated.hpp>
+#include <jau/test/catch2_ext.hpp>
#include <jau/ringbuffer.hpp>
@@ -36,7 +38,7 @@ typedef std::shared_ptr<Integer> SharedType;
typedef ringbuffer<SharedType, nullptr, jau::nsize_t> SharedTypeRingbuffer;
// Test examples.
-class Cppunit_tests : public Cppunit {
+class TestRingbuffer11 {
private:
std::shared_ptr<SharedTypeRingbuffer> createEmpty(jau::nsize_t initialCapacity) {
@@ -58,91 +60,92 @@ class Cppunit_tests : public Cppunit {
// std::thread::id this_id = std::this_thread::get_id();
// pthread_t this_id = pthread_self();
- fprintf(stderr, "%s: Created / %s\n", msg.c_str(), rb->toString().c_str());
+ // INFO_STR, INFO: Not thread safe yet
+ // INFO_STR(msg+": Created / " + rb->toString());
for(jau::nsize_t i=0; i<len; i++) {
SharedType svI = rb->getBlocking();
- CHECKTM(msg+": Empty at read #"+std::to_string(i+1)+": "+rb->toString(), svI!=nullptr);
- fprintf(stderr, "%s: Got %u / %s\n",
- msg.c_str(), svI->intValue(), rb->toString().c_str());
+ REQUIRE_MSG("not empty at read #"+std::to_string(i+1)+": "+rb->toString(), svI!=nullptr);
+ // INFO_STR("Got "+std::to_string(svI->intValue())+" / " + rb->toString());
}
- fprintf(stderr, "%s: Dies / %s\n", msg.c_str(), rb->toString().c_str());
+ // INFO_STR(msg+": Dies / " + rb->toString());
+ (void)msg;
}
void putThreadType01(const std::string msg, std::shared_ptr<SharedTypeRingbuffer> rb, jau::nsize_t len, jau::nsize_t startValue) {
// std::thread::id this_id = std::this_thread::get_id();
// pthread_t this_id = pthread_self();
- fprintf(stderr, "%s: Created / %s\n", msg.c_str(), rb->toString().c_str());
+ // INFO_STR(msg+": Created / " + rb->toString());
jau::nsize_t preSize = rb->getSize();
(void)preSize;
for(jau::nsize_t i=0; i<len; i++) {
Integer * vI = new Integer(startValue+i);
- fprintf(stderr, "%s: Putting %u ... / %s\n",
- msg.c_str(), vI->intValue(), rb->toString().c_str());
+ // INFO_STR("Putting "+std::to_string(vI->intValue())+" ... / " + rb->toString());
rb->putBlocking( SharedType( vI ) );
}
- fprintf(stderr, "%s: Dies / %s\n", msg.c_str(), rb->toString().c_str());
+ // INFO_STR(msg+": Dies / " + rb->toString());
+ (void)msg;
}
public:
void test01_Read1Write1() {
- fprintf(stderr, "\n\ntest01_Read1Write1\n");
+ INFO_STR("\n\ntest01_Read1Write1\n");
jau::nsize_t capacity = 100;
std::shared_ptr<SharedTypeRingbuffer> rb = createEmpty(capacity);
- CHECKM("Not empty size "+rb->toString(), 0, rb->getSize());
- CHECKTM("Not empty "+rb->toString(), rb->isEmpty());
+ REQUIRE_MSG("empty size "+rb->toString(), 0 == rb->getSize());
+ REQUIRE_MSG("empty "+rb->toString(), rb->isEmpty());
- std::thread getThread01(&Cppunit_tests::getThreadType01, this, "test01.get01", rb, capacity); // @suppress("Invalid arguments")
- std::thread putThread01(&Cppunit_tests::putThreadType01, this, "test01.put01", rb, capacity, 0); // @suppress("Invalid arguments")
+ std::thread getThread01(&TestRingbuffer11::getThreadType01, this, "test01.get01", rb, capacity); // @suppress("Invalid arguments")
+ std::thread putThread01(&TestRingbuffer11::putThreadType01, this, "test01.put01", rb, capacity, 0); // @suppress("Invalid arguments")
putThread01.join();
getThread01.join();
- CHECKTM("Not empty "+rb->toString(), rb->isEmpty());
- CHECKM("Not empty size "+rb->toString(), 0, rb->getSize());
+ REQUIRE_MSG("empty "+rb->toString(), rb->isEmpty());
+ REQUIRE_MSG("empty size "+rb->toString(), 0 == rb->getSize());
}
void test02_Read4Write1() {
- fprintf(stderr, "\n\ntest02_Read4Write1\n");
+ INFO_STR("\n\ntest02_Read4Write1\n");
jau::nsize_t capacity = 400;
std::shared_ptr<SharedTypeRingbuffer> rb = createEmpty(capacity);
- CHECKM("Not empty size "+rb->toString(), 0, rb->getSize());
- CHECKTM("Not empty "+rb->toString(), rb->isEmpty());
-
- std::thread getThread01(&Cppunit_tests::getThreadType01, this, "test02.get01", rb, capacity/4); // @suppress("Invalid arguments")
- std::thread getThread02(&Cppunit_tests::getThreadType01, this, "test02.get02", rb, capacity/4); // @suppress("Invalid arguments")
- std::thread putThread01(&Cppunit_tests::putThreadType01, this, "test02.put01", rb, capacity, 0); // @suppress("Invalid arguments")
- std::thread getThread03(&Cppunit_tests::getThreadType01, this, "test02.get03", rb, capacity/4); // @suppress("Invalid arguments")
- std::thread getThread04(&Cppunit_tests::getThreadType01, this, "test02.get04", rb, capacity/4); // @suppress("Invalid arguments")
+ REQUIRE_MSG("empty size "+rb->toString(), 0 == rb->getSize());
+ REQUIRE_MSG("empty "+rb->toString(), rb->isEmpty());
+
+ std::thread getThread01(&TestRingbuffer11::getThreadType01, this, "test02.get01", rb, capacity/4); // @suppress("Invalid arguments")
+ std::thread getThread02(&TestRingbuffer11::getThreadType01, this, "test02.get02", rb, capacity/4); // @suppress("Invalid arguments")
+ std::thread putThread01(&TestRingbuffer11::putThreadType01, this, "test02.put01", rb, capacity, 0); // @suppress("Invalid arguments")
+ std::thread getThread03(&TestRingbuffer11::getThreadType01, this, "test02.get03", rb, capacity/4); // @suppress("Invalid arguments")
+ std::thread getThread04(&TestRingbuffer11::getThreadType01, this, "test02.get04", rb, capacity/4); // @suppress("Invalid arguments")
putThread01.join();
getThread01.join();
getThread02.join();
getThread03.join();
getThread04.join();
- CHECKTM("Not empty "+rb->toString(), rb->isEmpty());
- CHECKM("Not empty size "+rb->toString(), 0, rb->getSize());
+ REQUIRE_MSG("empty "+rb->toString(), rb->isEmpty());
+ REQUIRE_MSG("empty size "+rb->toString(), 0 == rb->getSize());
}
void test03_Read8Write2() {
- fprintf(stderr, "\n\ntest03_Read8Write2\n");
+ INFO_STR("\n\ntest03_Read8Write2\n");
jau::nsize_t capacity = 800;
std::shared_ptr<SharedTypeRingbuffer> rb = createEmpty(capacity);
- CHECKM("Not empty size "+rb->toString(), 0, rb->getSize());
- CHECKTM("Not empty "+rb->toString(), rb->isEmpty());
+ REQUIRE_MSG("empty size "+rb->toString(), 0 == rb->getSize());
+ REQUIRE_MSG("empty "+rb->toString(), rb->isEmpty());
- std::thread getThread01(&Cppunit_tests::getThreadType01, this, "test03.get01", rb, capacity/8); // @suppress("Invalid arguments")
- std::thread getThread02(&Cppunit_tests::getThreadType01, this, "test03.get02", rb, capacity/8); // @suppress("Invalid arguments")
- std::thread putThread01(&Cppunit_tests::putThreadType01, this, "test03.put01", rb, capacity/2, 0); // @suppress("Invalid arguments")
- std::thread getThread03(&Cppunit_tests::getThreadType01, this, "test03.get03", rb, capacity/8); // @suppress("Invalid arguments")
- std::thread getThread04(&Cppunit_tests::getThreadType01, this, "test03.get04", rb, capacity/8); // @suppress("Invalid arguments")
+ std::thread getThread01(&TestRingbuffer11::getThreadType01, this, "test03.get01", rb, capacity/8); // @suppress("Invalid arguments")
+ std::thread getThread02(&TestRingbuffer11::getThreadType01, this, "test03.get02", rb, capacity/8); // @suppress("Invalid arguments")
+ std::thread putThread01(&TestRingbuffer11::putThreadType01, this, "test03.put01", rb, capacity/2, 0); // @suppress("Invalid arguments")
+ std::thread getThread03(&TestRingbuffer11::getThreadType01, this, "test03.get03", rb, capacity/8); // @suppress("Invalid arguments")
+ std::thread getThread04(&TestRingbuffer11::getThreadType01, this, "test03.get04", rb, capacity/8); // @suppress("Invalid arguments")
- std::thread getThread05(&Cppunit_tests::getThreadType01, this, "test03.get05", rb, capacity/8); // @suppress("Invalid arguments")
- std::thread getThread06(&Cppunit_tests::getThreadType01, this, "test03.get06", rb, capacity/8); // @suppress("Invalid arguments")
- std::thread putThread02(&Cppunit_tests::putThreadType01, this, "test03.put02", rb, capacity/2, 400); // @suppress("Invalid arguments")
- std::thread getThread07(&Cppunit_tests::getThreadType01, this, "test03.get07", rb, capacity/8); // @suppress("Invalid arguments")
- std::thread getThread08(&Cppunit_tests::getThreadType01, this, "test03.get08", rb, capacity/8); // @suppress("Invalid arguments")
+ std::thread getThread05(&TestRingbuffer11::getThreadType01, this, "test03.get05", rb, capacity/8); // @suppress("Invalid arguments")
+ std::thread getThread06(&TestRingbuffer11::getThreadType01, this, "test03.get06", rb, capacity/8); // @suppress("Invalid arguments")
+ std::thread putThread02(&TestRingbuffer11::putThreadType01, this, "test03.put02", rb, capacity/2, 400); // @suppress("Invalid arguments")
+ std::thread getThread07(&TestRingbuffer11::getThreadType01, this, "test03.get07", rb, capacity/8); // @suppress("Invalid arguments")
+ std::thread getThread08(&TestRingbuffer11::getThreadType01, this, "test03.get08", rb, capacity/8); // @suppress("Invalid arguments")
putThread01.join();
putThread02.join();
@@ -155,11 +158,11 @@ class Cppunit_tests : public Cppunit {
getThread07.join();
getThread08.join();
- CHECKTM("Not empty "+rb->toString(), rb->isEmpty());
- CHECKM("Not empty size "+rb->toString(), 0, rb->getSize());
+ REQUIRE_MSG("empty "+rb->toString(), rb->isEmpty());
+ REQUIRE_MSG("empty size "+rb->toString(), 0 == rb->getSize());
}
- void test_list() override {
+ void test_list() {
test01_Read1Write1();
test02_Read4Write1();
test03_Read8Write2();
@@ -174,11 +177,5 @@ class Cppunit_tests : public Cppunit {
}
};
-int main(int argc, char *argv[]) {
- (void)argc;
- (void)argv;
-
- Cppunit_tests test1;
- return test1.run();
-}
+METHOD_AS_TEST_CASE( TestRingbuffer11::test_list, "Test TestRingbuffer 11- test_list");
diff --git a/test/test_mm_sc_drf_00.cpp b/test/test_mm_sc_drf_00.cpp
index 6d40d7a..20e625e 100644
--- a/test/test_mm_sc_drf_00.cpp
+++ b/test/test_mm_sc_drf_00.cpp
@@ -9,7 +9,9 @@
#include <thread>
#include <pthread.h>
-#include <cppunit.h>
+#define CATCH_CONFIG_MAIN
+#include <catch2/catch_amalgamated.hpp>
+#include <jau/test/catch2_ext.hpp>
#include <jau/ordered_atomic.hpp>
@@ -32,7 +34,7 @@ static int loops = 10;
* </p>
* See 'test_mm_sc_drf_01' implementing same test using mutex-lock and condition wait.
*/
-class Cppunit_tests : public Cppunit {
+class TestMemModelSCDRF00 {
private:
enum Defaults : int {
array_size = 10
@@ -72,13 +74,13 @@ class Cppunit_tests : public Cppunit {
int _sync_value;
while( startValue != ( _sync_value = sync_value ) ) ; // SC-DRF acquire atomic with spin-lock waiting for startValue
- CHECKM(msg+": %s: Wrong value at read value1 (sync)", _sync_value, value1);
- CHECKM(msg+": %s: Wrong value at read value1 (start)", startValue, value1);
+ REQUIRE_MSG(msg+": %s: value at read value1 (sync)", _sync_value == value1);
+ REQUIRE_MSG(msg+": %s: value at read value1 (start)", startValue == value1);
for(int i=0; i<len; i++) {
int v = array[i];
- CHECKM(msg+": %s: Wrong sync value at read array #"+std::to_string(i), (_sync_value+i), v);
- CHECKM(msg+": %s: Wrong start value at read array #"+std::to_string(i), (startValue+i), v);
+ REQUIRE_MSG(msg+": %s: sync value at read array #"+std::to_string(i), (_sync_value+i) == v);
+ REQUIRE_MSG(msg+": %s: start value at read array #"+std::to_string(i), (startValue+i) == v);
}
sync_value = _sync_value; // SC-DRF release atomic
}
@@ -94,7 +96,7 @@ class Cppunit_tests : public Cppunit {
do {
_sync_value = sync_value;
} while( idx != (_sync_value * -1) - 1 );
- // fprintf(stderr, "putThreadType11.done @ %d (has %d, exp %d)\n", idx, _sync_value, (idx+1)*-1);
+ // INFO_STR("putThreadType11.done @ %d (has %d, exp %d)\n", idx, _sync_value, (idx+1)*-1);
_sync_value = idx;
value1 = idx;
array[idx] = idx; // last written checked first, SC-DRF should handle...
@@ -112,13 +114,13 @@ class Cppunit_tests : public Cppunit {
do {
_sync_value = sync_value;
} while( idx != _sync_value );
- CHECKM(msg+": %s: Wrong value at read array (a), idx "+std::to_string(idx), idx, array[idx]); // check last-written first
- CHECKM(msg+": %s: Wrong value at read value1, idx "+std::to_string(idx), idx, value1);
- CHECKM(msg+": %s: Wrong value at read sync, idx "+std::to_string(idx), idx, _sync_value);
+ REQUIRE_MSG(msg+": %s: value at read array (a), idx "+std::to_string(idx), idx == array[idx]); // check last-written first
+ REQUIRE_MSG(msg+": %s: value at read value1, idx "+std::to_string(idx), idx == value1);
+ REQUIRE_MSG(msg+": %s: value at read sync, idx "+std::to_string(idx), idx == _sync_value);
// next write encoded idx
_sync_value = (idx+1)%array_size;
_sync_value = ( _sync_value + 1 ) * -1;
- // fprintf(stderr, "getThreadType11.done for %d, next %d (v %d)\n", idx, (idx+1)%array_size, _sync_value);
+ // INFO_STR("getThreadType11.done for %d, next %d (v %d)\n", idx, (idx+1)%array_size, _sync_value);
value1 = _sync_value;
sync_value = _sync_value; // SC-DRF release atomic
}
@@ -126,37 +128,37 @@ class Cppunit_tests : public Cppunit {
public:
- Cppunit_tests()
+ TestMemModelSCDRF00()
: value1(0), sync_value(0) {}
void test01_Read1Write1() {
- fprintf(stderr, "\n\ntest01_Read1Write1.a\n");
+ INFO_STR("\n\ntest01_Read1Write1.a\n");
reset(0, 1010);
- std::thread getThread01(&Cppunit_tests::getThreadType01, this, "test01.get01", array_size, 3); // @suppress("Invalid arguments")
- std::thread putThread01(&Cppunit_tests::putThreadType01, this, array_size, 3); // @suppress("Invalid arguments")
+ std::thread getThread01(&TestMemModelSCDRF00::getThreadType01, this, "test01.get01", array_size, 3); // @suppress("Invalid arguments")
+ std::thread putThread01(&TestMemModelSCDRF00::putThreadType01, this, array_size, 3); // @suppress("Invalid arguments")
putThread01.join();
getThread01.join();
}
void test02_Read2Write1() {
- fprintf(stderr, "\n\ntest01_Read2Write1.a\n");
+ INFO_STR("\n\ntest01_Read2Write1.a\n");
reset(0, 1021);
{
- std::thread getThread00(&Cppunit_tests::getThreadType01, this, "test01.get00", array_size, 4); // @suppress("Invalid arguments")
- std::thread getThread01(&Cppunit_tests::getThreadType01, this, "test01.get01", array_size, 4); // @suppress("Invalid arguments")
- std::thread putThread01(&Cppunit_tests::putThreadType01, this, array_size, 4); // @suppress("Invalid arguments")
+ std::thread getThread00(&TestMemModelSCDRF00::getThreadType01, this, "test01.get00", array_size, 4); // @suppress("Invalid arguments")
+ std::thread getThread01(&TestMemModelSCDRF00::getThreadType01, this, "test01.get01", array_size, 4); // @suppress("Invalid arguments")
+ std::thread putThread01(&TestMemModelSCDRF00::putThreadType01, this, array_size, 4); // @suppress("Invalid arguments")
putThread01.join();
getThread00.join();
getThread01.join();
}
- fprintf(stderr, "\n\ntest01_Read2Write1.b\n");
+ INFO_STR("\n\ntest01_Read2Write1.b\n");
reset(0, 1022);
{
- std::thread putThread01(&Cppunit_tests::putThreadType01, this, array_size, 5); // @suppress("Invalid arguments")
- std::thread getThread00(&Cppunit_tests::getThreadType01, this, "test01.get00", array_size, 5); // @suppress("Invalid arguments")
- std::thread getThread01(&Cppunit_tests::getThreadType01, this, "test01.get01", array_size, 5); // @suppress("Invalid arguments")
+ std::thread putThread01(&TestMemModelSCDRF00::putThreadType01, this, array_size, 5); // @suppress("Invalid arguments")
+ std::thread getThread00(&TestMemModelSCDRF00::getThreadType01, this, "test01.get00", array_size, 5); // @suppress("Invalid arguments")
+ std::thread getThread01(&TestMemModelSCDRF00::getThreadType01, this, "test01.get01", array_size, 5); // @suppress("Invalid arguments")
putThread01.join();
getThread00.join();
getThread01.join();
@@ -164,14 +166,14 @@ class Cppunit_tests : public Cppunit {
}
void test03_Read4Write1() {
- fprintf(stderr, "\n\ntest02_Read4Write1\n");
+ INFO_STR("\n\ntest02_Read4Write1\n");
reset(0, 1030);
- std::thread getThread01(&Cppunit_tests::getThreadType01, this, "test02.get01", array_size, 6); // @suppress("Invalid arguments")
- std::thread getThread02(&Cppunit_tests::getThreadType01, this, "test02.get02", array_size, 6); // @suppress("Invalid arguments")
- std::thread putThread01(&Cppunit_tests::putThreadType01, this, array_size, 6); // @suppress("Invalid arguments")
- std::thread getThread03(&Cppunit_tests::getThreadType01, this, "test02.get03", array_size, 6); // @suppress("Invalid arguments")
- std::thread getThread04(&Cppunit_tests::getThreadType01, this, "test02.get04", array_size, 6); // @suppress("Invalid arguments")
+ std::thread getThread01(&TestMemModelSCDRF00::getThreadType01, this, "test02.get01", array_size, 6); // @suppress("Invalid arguments")
+ std::thread getThread02(&TestMemModelSCDRF00::getThreadType01, this, "test02.get02", array_size, 6); // @suppress("Invalid arguments")
+ std::thread putThread01(&TestMemModelSCDRF00::putThreadType01, this, array_size, 6); // @suppress("Invalid arguments")
+ std::thread getThread03(&TestMemModelSCDRF00::getThreadType01, this, "test02.get03", array_size, 6); // @suppress("Invalid arguments")
+ std::thread getThread04(&TestMemModelSCDRF00::getThreadType01, this, "test02.get04", array_size, 6); // @suppress("Invalid arguments")
putThread01.join();
getThread01.join();
getThread02.join();
@@ -180,16 +182,16 @@ class Cppunit_tests : public Cppunit {
}
void test11_Read10Write10() {
- fprintf(stderr, "\n\ntest11_Read10Write10\n");
+ INFO_STR("\n\ntest11_Read10Write10\n");
reset(-1, 1110); // start put idx 0
std::thread reader[array_size];
std::thread writer[array_size];
for(int i=0; i<number(array_size); i++) {
- reader[i] = std::thread(&Cppunit_tests::getThreadType11, this, "test11.get11", i); // @suppress("Invalid arguments") // @suppress("Symbol is not resolved")
+ reader[i] = std::thread(&TestMemModelSCDRF00::getThreadType11, this, "test11.get11", i); // @suppress("Invalid arguments") // @suppress("Symbol is not resolved")
}
for(int i=0; i<number(array_size); i++) {
- writer[i] = std::thread(&Cppunit_tests::putThreadType11, this, i); // @suppress("Invalid arguments") // @suppress("Symbol is not resolved")
+ writer[i] = std::thread(&TestMemModelSCDRF00::putThreadType11, this, i); // @suppress("Invalid arguments") // @suppress("Symbol is not resolved")
}
for(int i=0; i<number(array_size); i++) {
writer[i].join();
@@ -200,16 +202,16 @@ class Cppunit_tests : public Cppunit {
}
void test12_Read10Write10() {
- fprintf(stderr, "\n\ntest12_Read10Write10\n");
+ INFO_STR("\n\ntest12_Read10Write10\n");
reset(-1, 1120); // start put idx 0
std::thread reader[array_size];
std::thread writer[array_size];
for(int i=0; i<number(array_size); i++) {
- writer[i] = std::thread(&Cppunit_tests::putThreadType11, this, i); // @suppress("Invalid arguments") // @suppress("Symbol is not resolved")
+ writer[i] = std::thread(&TestMemModelSCDRF00::putThreadType11, this, i); // @suppress("Invalid arguments") // @suppress("Symbol is not resolved")
}
for(int i=0; i<number(array_size); i++) {
- reader[i] = std::thread(&Cppunit_tests::getThreadType11, this, "test12.get11", i); // @suppress("Invalid arguments") // @suppress("Symbol is not resolved")
+ reader[i] = std::thread(&TestMemModelSCDRF00::getThreadType11, this, "test12.get11", i); // @suppress("Invalid arguments") // @suppress("Symbol is not resolved")
}
for(int i=0; i<number(array_size); i++) {
writer[i].join();
@@ -219,7 +221,7 @@ class Cppunit_tests : public Cppunit {
}
}
- void test_list() override {
+ void test_list() {
for(int i=loops; i>0; i--) { test01_Read1Write1(); }
for(int i=loops; i>0; i--) { test02_Read2Write1(); }
for(int i=loops; i>0; i--) { test03_Read4Write1(); }
@@ -228,16 +230,4 @@ class Cppunit_tests : public Cppunit {
}
};
-int main(int argc, char *argv[]) {
- for(int i=1; i<argc; i++) {
- std::string arg(argv[i]);
- if( "-loops" == arg && argc > i+1 ) {
- loops = atoi(argv[i+1]);
- }
- }
- fprintf(stderr, "Loops %d\n", loops);
-
- Cppunit_tests test1;
- return test1.run();
-}
-
+METHOD_AS_TEST_CASE( TestMemModelSCDRF00::test_list, "Test TestMemModelSCDRF 00- test_list");
diff --git a/test/test_mm_sc_drf_01.cpp b/test/test_mm_sc_drf_01.cpp
index 1622591..e8fe6c0 100644
--- a/test/test_mm_sc_drf_01.cpp
+++ b/test/test_mm_sc_drf_01.cpp
@@ -11,7 +11,9 @@
#include <thread>
#include <pthread.h>
-#include <cppunit.h>
+#define CATCH_CONFIG_MAIN
+#include <catch2/catch_amalgamated.hpp>
+#include <jau/test/catch2_ext.hpp>
#include <jau/ordered_atomic.hpp>
@@ -29,7 +31,7 @@ static int loops = 10;
* </p>
* See 'test_mm_sc_drf_00' implementing same test using an atomic acquire/release critical block with spin-lock.
*/
-class Cppunit_tests : public Cppunit {
+class TestMemModelSCDRF01 {
private:
enum Defaults : int {
array_size = 10
@@ -70,11 +72,11 @@ class Cppunit_tests : public Cppunit {
while( startValue != value1 ) {
cvRead.wait(lock);
}
- CHECKM(msg+": %s: Wrong value at read value1 (start)", startValue, value1);
+ REQUIRE_MSG(msg+": %s: value at read value1 (start)", startValue == value1);
for(int i=0; i<len; i++) {
int v = array[i];
- CHECKM(msg+": %s: Wrong start value at read array #"+std::to_string(i), (startValue+i), v);
+ REQUIRE_MSG(msg+": %s: start value at read array #"+std::to_string(i), (startValue+i) == v);
}
}
@@ -89,7 +91,7 @@ class Cppunit_tests : public Cppunit {
while( idx != (value1 * -1) - 1 ) {
cvWrite.wait(lock);
}
- // fprintf(stderr, "putThreadType11.done @ %d (has %d, exp %d)\n", idx, value1, (idx+1)*-1);
+ // INFO_STR("putThreadType11.done @ %d (has %d, exp %d)\n", idx, value1, (idx+1)*-1);
value1 = idx;
array[idx] = idx; // last written checked first, SC-DRF should handle...
cvRead.notify_all();
@@ -104,15 +106,15 @@ class Cppunit_tests : public Cppunit {
// SC-DRF acquire atomic with spin-lock waiting for idx
std::unique_lock<std::mutex> lock(mtx_value);
while( idx != value1 ) {
- // fprintf(stderr, "getThreadType11.wait for has %d == exp %d\n", value1, idx);
+ // INFO_STR("getThreadType11.wait for has %d == exp %d\n", value1, idx);
cvRead.wait(lock);
}
- CHECKM(msg+": %s: Wrong value at read array (idx), idx "+std::to_string(idx), idx, array[idx]); // check last-written first
- CHECKM(msg+": %s: Wrong value at read value1 (idx), idx "+std::to_string(idx), idx, value1);
+ REQUIRE_MSG(msg+": %s: value at read array (idx), idx "+std::to_string(idx), idx == array[idx]); // check last-written first
+ REQUIRE_MSG(msg+": %s: value at read value1 (idx), idx "+std::to_string(idx), idx == value1);
// next write encoded idx
int next_idx = (idx+1)%array_size;
next_idx = ( next_idx + 1 ) * -1;
- // fprintf(stderr, "getThreadType11.done for %d, next %d (v %d)\n", idx, (idx+1)%array_size, next_idx);
+ // INFO_STR("getThreadType11.done for %d, next %d (v %d)\n", idx, (idx+1)%array_size, next_idx);
value1 = next_idx;
cvWrite.notify_all();
}
@@ -120,37 +122,37 @@ class Cppunit_tests : public Cppunit {
public:
- Cppunit_tests()
+ TestMemModelSCDRF01()
: value1(0) {}
void test01_Read1Write1() {
- fprintf(stderr, "\n\ntest01_Read1Write1.a\n");
+ INFO_STR("\n\ntest01_Read1Write1.a\n");
reset(0, 1010);
- std::thread getThread01(&Cppunit_tests::getThreadType01, this, "test01.get01", array_size, 3); // @suppress("Invalid arguments")
- std::thread putThread01(&Cppunit_tests::putThreadType01, this, array_size, 3); // @suppress("Invalid arguments")
+ std::thread getThread01(&TestMemModelSCDRF01::getThreadType01, this, "test01.get01", array_size, 3); // @suppress("Invalid arguments")
+ std::thread putThread01(&TestMemModelSCDRF01::putThreadType01, this, array_size, 3); // @suppress("Invalid arguments")
putThread01.join();
getThread01.join();
}
void test02_Read2Write1() {
- fprintf(stderr, "\n\ntest01_Read2Write1.a\n");
+ INFO_STR("\n\ntest01_Read2Write1.a\n");
reset(0, 1021);
{
- std::thread getThread00(&Cppunit_tests::getThreadType01, this, "test01.get00", array_size, 4); // @suppress("Invalid arguments")
- std::thread getThread01(&Cppunit_tests::getThreadType01, this, "test01.get01", array_size, 4); // @suppress("Invalid arguments")
- std::thread putThread01(&Cppunit_tests::putThreadType01, this, array_size, 4); // @suppress("Invalid arguments")
+ std::thread getThread00(&TestMemModelSCDRF01::getThreadType01, this, "test01.get00", array_size, 4); // @suppress("Invalid arguments")
+ std::thread getThread01(&TestMemModelSCDRF01::getThreadType01, this, "test01.get01", array_size, 4); // @suppress("Invalid arguments")
+ std::thread putThread01(&TestMemModelSCDRF01::putThreadType01, this, array_size, 4); // @suppress("Invalid arguments")
putThread01.join();
getThread00.join();
getThread01.join();
}
- fprintf(stderr, "\n\ntest01_Read2Write1.b\n");
+ INFO_STR("\n\ntest01_Read2Write1.b\n");
reset(0, 1022);
{
- std::thread putThread01(&Cppunit_tests::putThreadType01, this, array_size, 5); // @suppress("Invalid arguments")
- std::thread getThread00(&Cppunit_tests::getThreadType01, this, "test01.get00", array_size, 5); // @suppress("Invalid arguments")
- std::thread getThread01(&Cppunit_tests::getThreadType01, this, "test01.get01", array_size, 5); // @suppress("Invalid arguments")
+ std::thread putThread01(&TestMemModelSCDRF01::putThreadType01, this, array_size, 5); // @suppress("Invalid arguments")
+ std::thread getThread00(&TestMemModelSCDRF01::getThreadType01, this, "test01.get00", array_size, 5); // @suppress("Invalid arguments")
+ std::thread getThread01(&TestMemModelSCDRF01::getThreadType01, this, "test01.get01", array_size, 5); // @suppress("Invalid arguments")
putThread01.join();
getThread00.join();
getThread01.join();
@@ -158,14 +160,14 @@ class Cppunit_tests : public Cppunit {
}
void test03_Read4Write1() {
- fprintf(stderr, "\n\ntest02_Read4Write1\n");
+ INFO_STR("\n\ntest02_Read4Write1\n");
reset(0, 1030);
- std::thread getThread01(&Cppunit_tests::getThreadType01, this, "test02.get01", array_size, 6); // @suppress("Invalid arguments")
- std::thread getThread02(&Cppunit_tests::getThreadType01, this, "test02.get02", array_size, 6); // @suppress("Invalid arguments")
- std::thread putThread01(&Cppunit_tests::putThreadType01, this, array_size, 6); // @suppress("Invalid arguments")
- std::thread getThread03(&Cppunit_tests::getThreadType01, this, "test02.get03", array_size, 6); // @suppress("Invalid arguments")
- std::thread getThread04(&Cppunit_tests::getThreadType01, this, "test02.get04", array_size, 6); // @suppress("Invalid arguments")
+ std::thread getThread01(&TestMemModelSCDRF01::getThreadType01, this, "test02.get01", array_size, 6); // @suppress("Invalid arguments")
+ std::thread getThread02(&TestMemModelSCDRF01::getThreadType01, this, "test02.get02", array_size, 6); // @suppress("Invalid arguments")
+ std::thread putThread01(&TestMemModelSCDRF01::putThreadType01, this, array_size, 6); // @suppress("Invalid arguments")
+ std::thread getThread03(&TestMemModelSCDRF01::getThreadType01, this, "test02.get03", array_size, 6); // @suppress("Invalid arguments")
+ std::thread getThread04(&TestMemModelSCDRF01::getThreadType01, this, "test02.get04", array_size, 6); // @suppress("Invalid arguments")
putThread01.join();
getThread01.join();
getThread02.join();
@@ -174,16 +176,16 @@ class Cppunit_tests : public Cppunit {
}
void test11_Read10Write10() {
- fprintf(stderr, "\n\ntest11_Read10Write10\n");
+ INFO_STR("\n\ntest11_Read10Write10\n");
reset(-1, 1110);
std::thread reader[array_size];
std::thread writer[array_size];
for(int i=0; i<number(array_size); i++) {
- reader[i] = std::thread(&Cppunit_tests::getThreadType11, this, "test11.get11", i); // @suppress("Invalid arguments") // @suppress("Symbol is not resolved")
+ reader[i] = std::thread(&TestMemModelSCDRF01::getThreadType11, this, "test11.get11", i); // @suppress("Invalid arguments") // @suppress("Symbol is not resolved")
}
for(int i=0; i<number(array_size); i++) {
- writer[i] = std::thread(&Cppunit_tests::putThreadType11, this, i); // @suppress("Invalid arguments") // @suppress("Symbol is not resolved")
+ writer[i] = std::thread(&TestMemModelSCDRF01::putThreadType11, this, i); // @suppress("Invalid arguments") // @suppress("Symbol is not resolved")
}
for(int i=0; i<number(array_size); i++) {
writer[i].join();
@@ -194,16 +196,16 @@ class Cppunit_tests : public Cppunit {
}
void test12_Read10Write10() {
- fprintf(stderr, "\n\ntest12_Read10Write10\n");
+ INFO_STR("\n\ntest12_Read10Write10\n");
reset(-1, 1120);
std::thread reader[array_size];
std::thread writer[array_size];
for(int i=0; i<number(array_size); i++) {
- writer[i] = std::thread(&Cppunit_tests::putThreadType11, this, i); // @suppress("Invalid arguments") // @suppress("Symbol is not resolved")
+ writer[i] = std::thread(&TestMemModelSCDRF01::putThreadType11, this, i); // @suppress("Invalid arguments") // @suppress("Symbol is not resolved")
}
for(int i=0; i<number(array_size); i++) {
- reader[i] = std::thread(&Cppunit_tests::getThreadType11, this, "test12.get11", i); // @suppress("Invalid arguments") // @suppress("Symbol is not resolved")
+ reader[i] = std::thread(&TestMemModelSCDRF01::getThreadType11, this, "test12.get11", i); // @suppress("Invalid arguments") // @suppress("Symbol is not resolved")
}
for(int i=0; i<number(array_size); i++) {
writer[i].join();
@@ -213,7 +215,7 @@ class Cppunit_tests : public Cppunit {
}
}
- void test_list() override {
+ void test_list() {
for(int i=loops; i>0; i--) { test01_Read1Write1(); }
for(int i=loops; i>0; i--) { test02_Read2Write1(); }
for(int i=loops; i>0; i--) { test03_Read4Write1(); }
@@ -222,16 +224,4 @@ class Cppunit_tests : public Cppunit {
}
};
-int main(int argc, char *argv[]) {
- for(int i=1; i<argc; i++) {
- std::string arg(argv[i]);
- if( "-loops" == arg && argc > i+1 ) {
- loops = atoi(argv[i+1]);
- }
- }
- fprintf(stderr, "Loops %d\n", loops);
-
- Cppunit_tests test1;
- return test1.run();
-}
-
+METHOD_AS_TEST_CASE( TestMemModelSCDRF01::test_list, "Test TestMemModelSCDRF 01- test_list");