1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#include <cerrno>
#include <cstring>
#include <iostream>
#include "test_helpers.hxx"
using namespace pqxx;
namespace
{
const std::string Contents = "Large object test contents";
// Mixed-mode, seeking test program for libpqxx's Large Objects interface.
void test_058()
{
connection conn;
perform(
[&conn]()
{
work tx{conn};
largeobjectaccess A(tx);
A.write(Contents);
char Buf[200];
const size_t Size = sizeof(Buf) - 1;
PQXX_CHECK_EQUAL(
A.read(Buf, Size),
0,
"Could read bytes from large object after writing.");
// Overwrite terminating zero.
auto Here = A.seek(-1, std::ios::cur);
PQXX_CHECK_EQUAL(
Here,
largeobject::size_type(Contents.size()-1),
"Ended up in wrong place after moving back 1 byte.");
A.write("!", 1);
// Now check that we really did.
PQXX_CHECK_EQUAL(
A.seek(-1, std::ios::cur),
largeobject::size_type(Contents.size()-1),
"Inconsistent seek.");
char Check;
PQXX_CHECK_EQUAL(
A.read(&Check, 1),
1,
"Unexpected result from read().");
PQXX_CHECK_EQUAL(
std::string(&Check, 1),
"!",
"Read back wrong character.");
PQXX_CHECK_EQUAL(
A.seek(0, std::ios::beg),
0,
"Ended up in wrong place after seeking back to beginning.");
PQXX_CHECK_EQUAL(
A.read(&Check, 1),
1,
"Unexpected result when trying to read back 1st byte.");
PQXX_CHECK_EQUAL(
std::string(&Check, 1),
std::string(Contents, 0, 1),
"Wrong first character in large object.");
// Clean up after ourselves
A.remove(tx);
tx.commit();
});
}
PQXX_REGISTER_TEST(test_058);
} // namespace
|