From efcea3a80da7c4479d5fe168435ecc9fd06bdc72 Mon Sep 17 00:00:00 2001 From: John Turner Date: Sun, 14 Sep 2025 00:16:10 -0400 Subject: Squashed 'subprojects/boost-sqlite/' content from commit 3378e35 git-subtree-dir: subprojects/boost-sqlite git-subtree-split: 3378e353705271e569cf4ba15c467b840a39798c --- test/blob.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 test/blob.cpp (limited to 'test/blob.cpp') diff --git a/test/blob.cpp b/test/blob.cpp new file mode 100644 index 0000000..ca6ce83 --- /dev/null +++ b/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 +#include + +#include + +#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 blobby; + blobby.resize(4096*4096); + std::random_device dev; + std::mt19937 rng(dev()); + std::uniform_int_distribution dist(0,255); // distribution in range [1, 6] + + std::generate(blobby.begin(), blobby.end(), + [&]{return static_cast(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(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 -- cgit v1.2.3