mdbx-test: use mdbx::buffer from mdbx++.

This commit is contained in:
Leonid Yuriev 2021-04-19 17:44:04 +03:00
parent c4a696be1d
commit 62889b5b7f
5 changed files with 18 additions and 14 deletions

View File

@ -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 $$@

View File

@ -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)

View File

@ -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"

View File

@ -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) {

View File

@ -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<const char *>(v.iov_base), v.iov_len)
@ -149,7 +145,8 @@ protected:
return iov2dataview(b->value);
}
using Item = std::pair<std::string, std::string>;
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) {