29 #include <boost/range/algorithm_ext/iota.hpp> 30 #include <boost/range/algorithm/equal.hpp> 31 #include <gtest/gtest.h> 54 return (*cmp)(&left_val, &right_val);
71 enum class negative_choice : int {};
87 static_assert(-100 ==
lmdb::to_native(negative_choice(-100)),
"to_native failed");
134 EXPECT_EQ(0, run_compare(0u, 0u, &lmdb::less<unsigned>));
135 EXPECT_EQ(-1, run_compare(0u, 1u, &lmdb::less<unsigned>));
136 EXPECT_EQ(1, run_compare(1u, 0u, &lmdb::less<unsigned>));
138 EXPECT_EQ(0, run_compare<one>({0, 1}, {0, 1}, &lmdb::less<unsigned, sizeof(unsigned)>));
139 EXPECT_EQ(-1, run_compare<one>({0, 0}, {0, 1}, &lmdb::less<unsigned, sizeof(unsigned)>));
140 EXPECT_EQ(1, run_compare<one>({0, 1}, {0, 0}, &lmdb::less<unsigned, sizeof(unsigned)>));
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");
191 static_assert(&lmdb::less<unsigned> == test.key_cmp,
"bad key_cmp");
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()))>())
281 TEST(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()))>()));
#define EXPECT_NO_THROW(statement)
#define EXPECT_GT(val1, val2)
#define EXPECT_TRUE(condition)
#define EXPECT_STREQ(s1, s2)
#define ELECTRONEUM_CURSOR(name)
Uses C++ type system to differentiate between cursors.
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
#define ELECTRONEUM_SORT_BY(obj, field)
Expands to lmdb::less for the value field within obj.
std::unique_ptr< MDB_env, close_env > environment
std::unique_ptr< MDB_txn, release_read_txn > read_txn
struct MDB_txn MDB_txn
Opaque structure for a transaction handle.
#define EXPECT_LT(val1, val2)
Helper for grouping typical LMDB DBI options when key and value are fixed types.
#define EXPECT_NE(val1, val2)
#define ELECTRONEUM_COMPARE(obj, field)
Expands to lmdb::compare for the value field within obj.
#define ELECTRONEUM_FIELD(obj, field)
Generic structure used for passing keys and data in and out of the database.
#define ELECTRONEUM_UNWRAP(...)
MDB_val to_val(T &&value) noexcept
constexpr U to_native(T value) noexcept
#define EXPECT_FALSE(condition)
typename std::conditional< std::is_enum< T >::value, std::underlying_type< T >, identity< T > >::type::type native_type
Manages a LMDB environment for safe memory-map resizing. Thread-safe.
constexpr epee::span< const std::uint8_t > to_byte_span(MDB_val value) noexcept
#define EXPECT_EQ(val1, val2)