From eb348ca34c3b1ae44ee45793a9339cc76ce8bb51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Fri, 6 Oct 2023 22:11:21 +0300 Subject: [PATCH] =?UTF-8?q?mdbx-test-extra:=20=D0=B4=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=82=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=B0=20dupfixed=5Fmultiple.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/CMakeLists.txt | 7 ++ test/extra/dupfixed_multiple.c++ | 210 +++++++++++++++++++++++++++++++ 2 files changed, 217 insertions(+) create mode 100644 test/extra/dupfixed_multiple.c++ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 65dddb72..a09402dc 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -80,6 +80,13 @@ if(UNIX AND NOT SUBPROJECT) set_target_properties(test_extra_maindb_ordinal PROPERTIES CXX_STANDARD ${MDBX_CXX_STANDARD} CXX_STANDARD_REQUIRED ON) endif() + add_executable(test_extra_dupfixed_multiple extra/dupfixed_multiple.c++) + target_include_directories(test_extra_dupfixed_multiple PRIVATE "${PROJECT_SOURCE_DIR}") + target_link_libraries(test_extra_dupfixed_multiple ${TOOL_MDBX_LIB}) + if(MDBX_CXX_STANDARD) + set_target_properties(test_extra_dupfixed_multiple PROPERTIES + CXX_STANDARD ${MDBX_CXX_STANDARD} CXX_STANDARD_REQUIRED ON) + endif() endif() endif() diff --git a/test/extra/dupfixed_multiple.c++ b/test/extra/dupfixed_multiple.c++ new file mode 100644 index 00000000..f45b8892 --- /dev/null +++ b/test/extra/dupfixed_multiple.c++ @@ -0,0 +1,210 @@ +#include "mdbx.h++" +#include +#include +#include + +int main(int argc, const char *argv[]) { + (void)argc; + (void)argv; + + unlink("." MDBX_DATANAME); + unlink("." MDBX_LOCKNAME); + + mdbx::env_managed env(".", mdbx::env_managed::create_parameters(), + mdbx::env::operate_parameters()); + + using buffer = + mdbx::buffer; + auto txn = env.start_write(); + auto map = txn.create_map(nullptr, mdbx::key_mode::ordinal, + mdbx::value_mode::multi_ordinal); + + txn.insert(map, buffer::key_from_u64(21), buffer::key_from_u64(18)); + txn.insert(map, buffer::key_from_u64(7), buffer::key_from_u64(19)); + txn.insert(map, buffer::key_from_u64(22), buffer::key_from_u64(17)); + txn.insert(map, buffer::key_from_u64(26), buffer::key_from_u64(13)); + txn.insert(map, buffer::key_from_u64(24), buffer::key_from_u64(15)); + txn.insert(map, buffer::key_from_u64(23), buffer::key_from_u64(16)); + txn.insert(map, buffer::key_from_u64(25), buffer::key_from_u64(14)); + txn.insert(map, buffer::key_from_u64(27), buffer::key_from_u64(12)); + txn.commit(); + + txn = env.start_read(); + auto cursor = txn.open_cursor(map); + if (cursor.to_first().value.as_uint64() != 19 || + cursor.to_next().value.as_uint64() != 18 || + cursor.to_next().value.as_uint64() != 17 || + cursor.to_next().value.as_uint64() != 16 || + cursor.to_next().value.as_uint64() != 15 || + cursor.to_next().value.as_uint64() != 14 || + cursor.to_next().value.as_uint64() != 13 || + cursor.to_next().value.as_uint64() != 12 || cursor.to_next(false).done || + !cursor.eof()) { + std::cerr << "Fail\n"; + return EXIT_FAILURE; + } + txn.abort(); + + const uint64_t array[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 42, 17, 99, 0, 33, 333}; + txn = env.start_write(); + txn.put_multiple(map, buffer::key_from_u64(13), array + 3, 4, mdbx::upsert); + txn.put_multiple(map, buffer::key_from_u64(10), array + 0, 1, mdbx::upsert); + txn.put_multiple(map, buffer::key_from_u64(12), array + 2, 3, mdbx::upsert); + txn.put_multiple(map, buffer::key_from_u64(15), array + 5, 6, mdbx::upsert); + txn.put_multiple(map, buffer::key_from_u64(14), array + 4, 5, mdbx::upsert); + txn.put_multiple(map, buffer::key_from_u64(11), array + 1, 2, mdbx::upsert); + txn.put_multiple(map, buffer::key_from_u64(16), array + 6, 7, mdbx::upsert); + txn.commit(); + + txn = env.start_read(); + cursor = txn.open_cursor(map); + if (/* key = 7 */ cursor.to_first().value.as_uint64() != 19 || + + /* key = 10: 1 элемент */ + cursor.to_next().value.as_uint64() != 1 || + + /* key = 11: 2 элемента, пропуск 1 */ + cursor.to_next().value.as_uint64() != 2 || + cursor.to_next().value.as_uint64() != 3 || + + /* key = 12: 3 элемента, пропуск 2 */ + cursor.to_next().value.as_uint64() != 3 || + cursor.to_next().value.as_uint64() != 4 || + cursor.to_next().value.as_uint64() != 5 || + + /* key = 13: 4 элемента, пропуск 3 */ + cursor.to_next().value.as_uint64() != 4 || + cursor.to_next().value.as_uint64() != 5 || + cursor.to_next().value.as_uint64() != 6 || + cursor.to_next().value.as_uint64() != 7 || + + /* key = 14: 5 элементов, пропуск 4 */ + cursor.to_next().value.as_uint64() != 5 || + cursor.to_next().value.as_uint64() != 6 || + cursor.to_next().value.as_uint64() != 7 || + cursor.to_next().value.as_uint64() != 8 || + cursor.to_next().value.as_uint64() != 9 || + + /* key = 15: 6 элементов, пропуск 5 */ + cursor.to_next().value.as_uint64() != 6 || + cursor.to_next().value.as_uint64() != 7 || + cursor.to_next().value.as_uint64() != 8 || + cursor.to_next().value.as_uint64() != 9 || + cursor.to_next().value.as_uint64() != 17 || + cursor.to_next().value.as_uint64() != 42 || + + /* key = 16: 7 элементов, пропуск 6 */ + cursor.to_next().value.as_uint64() != 0 || + cursor.to_next().value.as_uint64() != 7 || + cursor.to_next().value.as_uint64() != 8 || + cursor.to_next().value.as_uint64() != 9 || + cursor.to_next().value.as_uint64() != 17 || + cursor.to_next().value.as_uint64() != 42 || + cursor.to_next().value.as_uint64() != 99 || + + /* key = 21 */ cursor.to_next().value.as_uint64() != 18 || + /* key = 22 */ cursor.to_next().value.as_uint64() != 17 || + /* key = 23 */ cursor.to_next().value.as_uint64() != 16 || + /* key = 24 */ cursor.to_next().value.as_uint64() != 15 || + /* key = 25 */ cursor.to_next().value.as_uint64() != 14 || + /* key = 26 */ cursor.to_next().value.as_uint64() != 13 || + /* key = 27 */ cursor.to_next().value.as_uint64() != 12 || + cursor.to_next(false).done || !cursor.eof()) { + std::cerr << "Fail\n"; + return EXIT_FAILURE; + } + txn.abort(); + + txn = env.start_write(); + txn.put_multiple(map, buffer::key_from_u64(7), array + 3, 4, mdbx::update); + txn.upsert(map, buffer::key_from_u64(10), buffer::key_from_u64(14)); + txn.put_multiple(map, buffer::key_from_u64(11), array + 4, 5, mdbx::upsert); + txn.put_multiple(map, buffer::key_from_u64(12), array + 0, 1, mdbx::update); + txn.update(map, buffer::key_from_u64(13), buffer::key_from_u64(18)); + txn.put_multiple(map, buffer::key_from_u64(14), array + 2, 3, mdbx::update); + txn.update(map, buffer::key_from_u64(15), buffer::key_from_u64(13)); + txn.put_multiple(map, buffer::key_from_u64(16), array + 6, 9, mdbx::update); + txn.update(map, buffer::key_from_u64(21), buffer::key_from_u64(17)); + txn.update(map, buffer::key_from_u64(22), buffer::key_from_u64(15)); + txn.put_multiple(map, buffer::key_from_u64(23), array + 1, 2, mdbx::update); + txn.update(map, buffer::key_from_u64(24), buffer::key_from_u64(16)); + txn.put_multiple(map, buffer::key_from_u64(25), array + 5, 6, mdbx::update); + txn.upsert(map, buffer::key_from_u64(26), buffer::key_from_u64(12)); + txn.put_multiple(map, buffer::key_from_u64(27), array + 12, 3, mdbx::update); + txn.commit(); + + txn = env.start_read(); + cursor = txn.open_cursor(map); + if (/* key = 7 */ + cursor.to_first().value.as_uint64() != 4 || + cursor.to_next().value.as_uint64() != 5 || + cursor.to_next().value.as_uint64() != 6 || + cursor.to_next().value.as_uint64() != 7 || + + /* key = 10: 1 элемент */ + cursor.to_next().value.as_uint64() != 1 || + /* +1 upsert */ + cursor.to_next().value.as_uint64() != 14 || + + /* key = 11: 2 элемента, пропуск 1 */ + cursor.to_next().value.as_uint64() != 2 || + cursor.to_next().value.as_uint64() != 3 || + /* +5 элементов, пропуск 4 */ + cursor.to_next().value.as_uint64() != 5 || + cursor.to_next().value.as_uint64() != 6 || + cursor.to_next().value.as_uint64() != 7 || + cursor.to_next().value.as_uint64() != 8 || + cursor.to_next().value.as_uint64() != 9 || + + /* key = 12: 1 элемент */ + cursor.to_next().value.as_uint64() != 1 || + /* key = 13 */ cursor.to_next().value.as_uint64() != 18 || + + /* key = 14: 3 элемента, пропуск 2 */ + cursor.to_next().value.as_uint64() != 3 || + cursor.to_next().value.as_uint64() != 4 || + cursor.to_next().value.as_uint64() != 5 || + + /* key = 15 */ cursor.to_next().value.as_uint64() != 13 || + + /* key = 16: 9 элементов, пропуск 6 */ + cursor.to_next().value.as_uint64() != 0 || + cursor.to_next().value.as_uint64() != 7 || + cursor.to_next().value.as_uint64() != 8 || + cursor.to_next().value.as_uint64() != 9 || + cursor.to_next().value.as_uint64() != 17 || + cursor.to_next().value.as_uint64() != 33 || + cursor.to_next().value.as_uint64() != 42 || + cursor.to_next().value.as_uint64() != 99 || + cursor.to_next().value.as_uint64() != 333 || + + /* key = 21 */ cursor.to_next().value.as_uint64() != 17 || + /* key = 22 */ cursor.to_next().value.as_uint64() != 15 || + /* key = 23: 2 элемента, пропуск 1 */ + cursor.to_next().value.as_uint64() != 2 || + cursor.to_next().value.as_uint64() != 3 || + /* key = 24 */ cursor.to_next().value.as_uint64() != 16 || + /* key = 25: 6 элемента, пропуск 5 */ + cursor.to_next().value.as_uint64() != 6 || + cursor.to_next().value.as_uint64() != 7 || + cursor.to_next().value.as_uint64() != 8 || + cursor.to_next().value.as_uint64() != 9 || + cursor.to_next().value.as_uint64() != 17 || + cursor.to_next().value.as_uint64() != 42 || + + /* key = 26, 1+1 upsert */ + cursor.to_next().value.as_uint64() != 12 || + cursor.to_next().value.as_uint64() != 13 || + + /* key = 27: 3 элемента, пропуск 12 */ + cursor.to_next().value.as_uint64() != 0 || + cursor.to_next().value.as_uint64() != 33 || + cursor.to_next().value.as_uint64() != 333 || + + cursor.to_next(false).done || !cursor.eof()) { + std::cerr << "Fail\n"; + return EXIT_FAILURE; + } + std::cout << "OK\n"; + return EXIT_SUCCESS; +}