29#include <boost/range/algorithm_ext/iota.hpp>
30#include <boost/range/algorithm/equal.hpp>
31#include <gtest/gtest.h>
40 enum class choice :
unsigned {};
41 enum class big_choice :
unsigned long {};
54 return (*cmp)(&left_val, &right_val);
71 enum class negative_choice :
int {};
75 (std::is_same<
unsigned long,
decltype(
lmdb::to_native(big_choice(0)))>())
87 static_assert(-100 ==
lmdb::to_native(negative_choice(-100)),
"to_native failed");
98 const one test{big_choice(100), choice(95)};
99 one
test2{big_choice(1000), choice(950)};
166 boost::iota(test.j.data, 10);
168 const one
test2 = test;
175 test.j.data[15] = 100;
190 static_assert(test.flags == 0,
"bad flags");
192 static_assert(test.value_cmp ==
nullptr,
"bad value_cmp");
206 boost::iota(record.i.data, 0);
207 boost::iota(record.i.data, 20);
210 EXPECT_TRUE(boost::equal(record.i.data, record_copy.i.data));
211 EXPECT_TRUE(boost::equal(record.j.data, record_copy.j.data));
216 EXPECT_TRUE(boost::equal(record.j.data, j_copy.data));
219 test.get_key_stream(test_cursor{}).matches(std::errc::invalid_argument)
222 test2.get_key_stream(test_cursor{}).matches(std::errc::invalid_argument)
227 test.get_value_stream(choice(0), test_cursor{}).matches(std::errc::invalid_argument)
230 test2.get_value_stream(big_choice(0), test_cursor{}).matches(std::errc::invalid_argument)
238 EXPECT_TRUE(test.resize().matches(std::errc::invalid_argument));
239 EXPECT_TRUE(test.create_read_txn().matches(std::errc::invalid_argument));
241 EXPECT_TRUE(test.create_write_txn().matches(std::errc::invalid_argument));
245 test.try_write( [](
MDB_txn&) { return success(); } ).matches(std::errc::invalid_argument)
260 EXPECT_TRUE((std::is_same<one,
decltype(*(test.make_iterator()))>()));
261 EXPECT_TRUE((std::is_same<one,
decltype(*(test.make_range().begin()))>()));
263 (std::is_same<bytes,
decltype(*(test.make_iterator<
ELECTRONEUM_FIELD(one, k)>()))>())
266 (std::is_same<bytes,
decltype(*(test.make_range<
ELECTRONEUM_FIELD(one, k)>().begin()))>())
281TEST(LMDB, InvalidValueIterator)
339 using record = std::pair<choice, boost::iterator_range<lmdb::value_iterator<one>>>;
343 EXPECT_TRUE((std::is_same<record,
decltype(*(test.make_iterator()))>()));
344 EXPECT_TRUE((std::is_same<record,
decltype(*(test.make_range().begin()))>()));
365 using record = std::pair<choice, boost::iterator_range<lmdb::value_iterator<one>>>;
371 EXPECT_TRUE((std::is_same<one,
decltype(*(
test1.make_value_iterator()))>()));
372 EXPECT_TRUE((std::is_same<one,
decltype(*(
test1.make_value_range().begin()))>()));
Manages a LMDB environment for safe memory-map resizing. Thread-safe.
#define ELECTRONEUM_UNWRAP(...)
#define EXPECT_NO_THROW(statement)
#define EXPECT_EQ(val1, val2)
#define EXPECT_NE(val1, val2)
#define EXPECT_GT(val1, val2)
#define EXPECT_TRUE(condition)
#define EXPECT_STREQ(s1, s2)
#define TEST(test_case_name, test_name)
#define EXPECT_FALSE(condition)
#define EXPECT_LT(val1, val2)
struct MDB_txn MDB_txn
Opaque structure for a transaction handle.
int MDB_cmp_func(const MDB_val *a, const MDB_val *b)
A callback function used to compare two keys in a database.
std::unique_ptr< MDB_txn, abort_write_txn > write_txn
std::unique_ptr< MDB_env, close_env > environment
constexpr epee::span< const std::uint8_t > to_byte_span(MDB_val value) noexcept
int compare(MDB_val const *left, MDB_val const *right) noexcept
int less(MDB_val const *left, MDB_val const *right) noexcept
constexpr U to_native(T value) noexcept
MDB_val to_val(T &&value) noexcept
std::unique_ptr< MDB_txn, release_read_txn > read_txn
typename std::conditional< std::is_enum< T >::value, std::underlying_type< T >, identity< T > >::type::type native_type
#define ELECTRONEUM_FIELD(obj, field)
#define ELECTRONEUM_COMPARE(obj, field)
Expands to lmdb::compare for the value field within obj.
#define ELECTRONEUM_SORT_BY(obj, field)
Expands to lmdb::less for the value field within obj.
Generic structure used for passing keys and data in and out of the database.
Helper for grouping typical LMDB DBI options when key and value are fixed types.
#define ELECTRONEUM_CURSOR(name)
Uses C++ type system to differentiate between cursors.