summaryrefslogtreecommitdiff
path: root/subprojects/boost-sqlite/test/blob.cpp
diff options
context:
space:
mode:
authorJohn Turner <jturner.usa@gmail.com>2025-09-14 00:16:10 -0400
committerJohn Turner <jturner.usa@gmail.com>2025-09-14 00:16:10 -0400
commit13e0821fd783a1d5083d825af53cf20e8dcbfd76 (patch)
tree1ea363b0f13b3e87d177100e6ae6b9f30a2de1b8 /subprojects/boost-sqlite/test/blob.cpp
parentaa55cb93036a89c64c08e08f4e1de4fa1fd5a775 (diff)
parentefcea3a80da7c4479d5fe168435ecc9fd06bdc72 (diff)
downloadsqlite-kv-bench-13e0821fd783a1d5083d825af53cf20e8dcbfd76.tar.gz
Merge commit 'efcea3a80da7c4479d5fe168435ecc9fd06bdc72' as 'subprojects/boost-sqlite'
Diffstat (limited to 'subprojects/boost-sqlite/test/blob.cpp')
-rw-r--r--subprojects/boost-sqlite/test/blob.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/subprojects/boost-sqlite/test/blob.cpp b/subprojects/boost-sqlite/test/blob.cpp
new file mode 100644
index 0000000..ca6ce83
--- /dev/null
+++ b/subprojects/boost-sqlite/test/blob.cpp
@@ -0,0 +1,56 @@
+//
+// Copyright (c) 2022 Klemens Morgenstern (klemens.morgenstern@gmx.net)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+
+#include <boost/sqlite/blob.hpp>
+#include <boost/sqlite/connection.hpp>
+
+#include <random>
+
+#include "test.hpp"
+
+using namespace boost;
+
+BOOST_AUTO_TEST_CASE(blob)
+{
+ sqlite::connection conn{":memory:"};
+ // language=sqlite
+ conn.execute("create table blobs(id integer primary key autoincrement, bb blob);");
+
+ std::vector<unsigned char> blobby;
+ blobby.resize(4096*4096);
+ std::random_device dev;
+ std::mt19937 rng(dev());
+ std::uniform_int_distribution<std::mt19937::result_type> dist(0,255); // distribution in range [1, 6]
+
+ std::generate(blobby.begin(), blobby.end(),
+ [&]{return static_cast<unsigned char>(dist(rng));});
+
+
+ conn.prepare("insert into blobs(bb) values ($1);").execute(std::make_tuple(sqlite::zero_blob(4096 * 4096 )));
+
+ auto bh = open_blob(conn, "main", "blobs", "bb", 1);
+
+ BOOST_CHECK(bh.size() == 4096 * 4096);
+
+
+ unsigned char buf[4096];
+ std::generate(std::begin(buf), std::end(buf), [&]{return static_cast<unsigned char>(dist(rng));});
+ bh.read_at(buf, 4096, 4096);
+ BOOST_CHECK(std::all_of(std::begin(buf), std::end(buf), [](unsigned char c) {return c == 0u;}));
+
+ bh.write_at(blobby.data(), blobby.size(), 0u);
+ bh.read_at(buf, 4096, 4096);
+ BOOST_CHECK(std::memcmp(buf, blobby.data() + 4096, 4096) == 0);
+
+ BOOST_CHECK_THROW(open_blob(conn, "main", "doesnt-exit", "blobber", 2), boost::system::system_error);
+
+ sqlite::blob_handle bb;
+ BOOST_CHECK_THROW(bb.read_at(blobby.data(), blobby.size(), 0), boost::system::system_error);
+ BOOST_CHECK_THROW(bb.write_at(blobby.data(), blobby.size(), 0), boost::system::system_error);
+
+} \ No newline at end of file