diff --git a/GNUmakefile b/GNUmakefile index 82f865b4..ca31d7fb 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -349,7 +349,7 @@ mdbx_example: mdbx.h example/example-mdbx.c libmdbx.$(SO_SUFFIX) build-test: all mdbx_example mdbx_test define test-rule -$(patsubst %.cc,%.o,$(1)): $(1) $(TEST_INC) mdbx.h $(lastword $(MAKEFILE_LIST)) +$(patsubst %.cc,%.o,$(1)): $(1) $(TEST_INC) $(HEADERS) $(lastword $(MAKEFILE_LIST)) @echo ' CC $$@' $(QUIET)$$(CXX) $$(CXXFLAGS) $$(MDBX_BUILD_OPTIONS) -c $(1) -o $$@ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d97b78e1..82858066 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,7 +1,7 @@ enable_language(CXX) include(../cmake/compiler.cmake) -add_executable(mdbx_test +set(LIBMDBX_TEST_SOURCES base.h cases.cc chrono.cc @@ -30,6 +30,12 @@ add_executable(mdbx_test nested.cc ) +if(NOT MDBX_BUILD_CXX) + list(APPEND LIBMDBX_TEST_SOURCES "${MDBX_SOURCE_DIR}/mdbx.c++" ../mdbx.h++) +endif() + +add_executable(mdbx_test ${LIBMDBX_TEST_SOURCES}) + if(MDBX_CXX_STANDARD) set_target_properties(mdbx_test PROPERTIES CXX_STANDARD ${MDBX_CXX_STANDARD} CXX_STANDARD_REQUIRED ON) diff --git a/test/base.h b/test/base.h index be8e05e3..790ffd0f 100644 --- a/test/base.h +++ b/test/base.h @@ -86,7 +86,7 @@ #define MDBX_INTERNAL_FUNC #define MDBX_INTERNAL_VAR extern #define xMDBX_TOOLS /* Avoid using internal mdbx_assert() */ -#include "../mdbx.h" +#include "../mdbx.h++" #include "../src/defs.h" #include "../src/osal.h" diff --git a/test/test.cc b/test/test.cc index cf50decb..f1494f8e 100644 --- a/test/test.cc +++ b/test/test.cc @@ -1058,10 +1058,8 @@ bool testcase::speculum_verify() { const auto S_key = iov2dataview(akey); const auto S_data = iov2dataview(avalue); if (it != speculum.cend()) { - mkey.iov_base = (void *)it->first.c_str(); - mkey.iov_len = it->first.size(); - mvalue.iov_base = (void *)it->second.c_str(); - mvalue.iov_len = it->second.size(); + mkey = it->first; + mvalue = it->second; } if (err == MDBX_SUCCESS && it != speculum.cend() && S_key == it->first && S_data == it->second) { diff --git a/test/test.h b/test/test.h index cbd3d710..57b707c7 100644 --- a/test/test.h +++ b/test/test.h @@ -135,11 +135,7 @@ public: class testcase { protected: -#if HAVE_cxx17_std_string_view - using data_view = std::string_view; -#else - using data_view = std::string; -#endif + using data_view = mdbx::slice; static inline data_view iov2dataview(const MDBX_val &v) { return (v.iov_base && v.iov_len) ? data_view(static_cast(v.iov_base), v.iov_len) @@ -149,7 +145,8 @@ protected: return iov2dataview(b->value); } - using Item = std::pair; + using Item = std::pair<::mdbx::buffer<>, ::mdbx::buffer<>>; + static MDBX_val dataview2iov(const data_view &v) { MDBX_val r; r.iov_base = (void *)v.data(); @@ -158,10 +155,13 @@ protected: } struct ItemCompare { const testcase *context; - ItemCompare(const testcase *owner) : context(owner) {} + ItemCompare(const testcase *owner) : context(owner) { + /* The context->txn_guard may be empty/null here */ + } bool operator()(const Item &a, const Item &b) const { MDBX_val va = dataview2iov(a.first), vb = dataview2iov(b.first); + assert(context->txn_guard.get() != nullptr); int cmp = mdbx_cmp(context->txn_guard.get(), context->dbi, &va, &vb); if (cmp == 0 && (context->config.params.table_flags & MDBX_DUPSORT) != 0) {