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)
245 test.
try_write( [](
MDB_txn&) { return success(); } ).matches(std::errc::invalid_argument)
281TEST(LMDB, InvalidValueIterator)
339 using record = std::pair<choice, boost::iterator_range<lmdb::value_iterator<one>>>;
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.
expect< suspended_txn > reset_txn(read_txn txn) noexcept
expect< void > commit(write_txn txn) noexcept
Commit the read-write transaction.
expect< write_txn > create_write_txn() noexcept
expect< void > resize() noexcept
std::result_of< F(MDB_txn &)>::type try_write(F f, unsigned attempts=3)
expect< read_txn > create_read_txn(suspended_txn txn=nullptr) noexcept
std::unique_ptr< MDB_cursor, D > give_cursor() noexcept
boost::iterator_range< key_iterator< K, V > > make_range() const
key_iterator< K, V > make_iterator() const
std::size_t count() const
std::unique_ptr< MDB_cursor, D > give_cursor() noexcept
value_iterator< U, F, offset > make_iterator() const
boost::iterator_range< value_iterator< U, F, offset > > make_range() const
#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.
static expect< value_stream< V, D > > get_value_stream(K const &key, std::unique_ptr< MDB_cursor, D > cur) noexcept
static expect< F > get_value(MDB_val value) noexcept
static expect< key_stream< K, V, D > > get_key_stream(std::unique_ptr< MDB_cursor, D > cur) noexcept
MDB_cmp_func *const value_cmp
MDB_cmp_func *const key_cmp
#define ELECTRONEUM_CURSOR(name)
Uses C++ type system to differentiate between cursors.