mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-30 13:52:06 +08:00
mdbx-test: use mdbx::buffer
from mdbx++.
This commit is contained in:
parent
c4a696be1d
commit
62889b5b7f
@ -349,7 +349,7 @@ mdbx_example: mdbx.h example/example-mdbx.c libmdbx.$(SO_SUFFIX)
|
|||||||
build-test: all mdbx_example mdbx_test
|
build-test: all mdbx_example mdbx_test
|
||||||
|
|
||||||
define test-rule
|
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 $$@'
|
@echo ' CC $$@'
|
||||||
$(QUIET)$$(CXX) $$(CXXFLAGS) $$(MDBX_BUILD_OPTIONS) -c $(1) -o $$@
|
$(QUIET)$$(CXX) $$(CXXFLAGS) $$(MDBX_BUILD_OPTIONS) -c $(1) -o $$@
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
enable_language(CXX)
|
enable_language(CXX)
|
||||||
include(../cmake/compiler.cmake)
|
include(../cmake/compiler.cmake)
|
||||||
|
|
||||||
add_executable(mdbx_test
|
set(LIBMDBX_TEST_SOURCES
|
||||||
base.h
|
base.h
|
||||||
cases.cc
|
cases.cc
|
||||||
chrono.cc
|
chrono.cc
|
||||||
@ -30,6 +30,12 @@ add_executable(mdbx_test
|
|||||||
nested.cc
|
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)
|
if(MDBX_CXX_STANDARD)
|
||||||
set_target_properties(mdbx_test PROPERTIES
|
set_target_properties(mdbx_test PROPERTIES
|
||||||
CXX_STANDARD ${MDBX_CXX_STANDARD} CXX_STANDARD_REQUIRED ON)
|
CXX_STANDARD ${MDBX_CXX_STANDARD} CXX_STANDARD_REQUIRED ON)
|
||||||
|
@ -86,7 +86,7 @@
|
|||||||
#define MDBX_INTERNAL_FUNC
|
#define MDBX_INTERNAL_FUNC
|
||||||
#define MDBX_INTERNAL_VAR extern
|
#define MDBX_INTERNAL_VAR extern
|
||||||
#define xMDBX_TOOLS /* Avoid using internal mdbx_assert() */
|
#define xMDBX_TOOLS /* Avoid using internal mdbx_assert() */
|
||||||
#include "../mdbx.h"
|
#include "../mdbx.h++"
|
||||||
#include "../src/defs.h"
|
#include "../src/defs.h"
|
||||||
#include "../src/osal.h"
|
#include "../src/osal.h"
|
||||||
|
|
||||||
|
@ -1058,10 +1058,8 @@ bool testcase::speculum_verify() {
|
|||||||
const auto S_key = iov2dataview(akey);
|
const auto S_key = iov2dataview(akey);
|
||||||
const auto S_data = iov2dataview(avalue);
|
const auto S_data = iov2dataview(avalue);
|
||||||
if (it != speculum.cend()) {
|
if (it != speculum.cend()) {
|
||||||
mkey.iov_base = (void *)it->first.c_str();
|
mkey = it->first;
|
||||||
mkey.iov_len = it->first.size();
|
mvalue = it->second;
|
||||||
mvalue.iov_base = (void *)it->second.c_str();
|
|
||||||
mvalue.iov_len = it->second.size();
|
|
||||||
}
|
}
|
||||||
if (err == MDBX_SUCCESS && it != speculum.cend() && S_key == it->first &&
|
if (err == MDBX_SUCCESS && it != speculum.cend() && S_key == it->first &&
|
||||||
S_data == it->second) {
|
S_data == it->second) {
|
||||||
|
14
test/test.h
14
test/test.h
@ -135,11 +135,7 @@ public:
|
|||||||
|
|
||||||
class testcase {
|
class testcase {
|
||||||
protected:
|
protected:
|
||||||
#if HAVE_cxx17_std_string_view
|
using data_view = mdbx::slice;
|
||||||
using data_view = std::string_view;
|
|
||||||
#else
|
|
||||||
using data_view = std::string;
|
|
||||||
#endif
|
|
||||||
static inline data_view iov2dataview(const MDBX_val &v) {
|
static inline data_view iov2dataview(const MDBX_val &v) {
|
||||||
return (v.iov_base && v.iov_len)
|
return (v.iov_base && v.iov_len)
|
||||||
? data_view(static_cast<const char *>(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);
|
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) {
|
static MDBX_val dataview2iov(const data_view &v) {
|
||||||
MDBX_val r;
|
MDBX_val r;
|
||||||
r.iov_base = (void *)v.data();
|
r.iov_base = (void *)v.data();
|
||||||
@ -158,10 +155,13 @@ protected:
|
|||||||
}
|
}
|
||||||
struct ItemCompare {
|
struct ItemCompare {
|
||||||
const testcase *context;
|
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 {
|
bool operator()(const Item &a, const Item &b) const {
|
||||||
MDBX_val va = dataview2iov(a.first), vb = dataview2iov(b.first);
|
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);
|
int cmp = mdbx_cmp(context->txn_guard.get(), context->dbi, &va, &vb);
|
||||||
if (cmp == 0 &&
|
if (cmp == 0 &&
|
||||||
(context->config.params.table_flags & MDBX_DUPSORT) != 0) {
|
(context->config.params.table_flags & MDBX_DUPSORT) != 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user