From 4962b5941c7d9cf62f59a9b0868de5bf07376313 Mon Sep 17 00:00:00 2001 From: Mateusz Loskot Date: Sun, 10 Feb 2013 01:48:58 +0000 Subject: [PATCH] PostgreSQL test for bytea - #46. Use case of bytea to dt_string mapping is unclear, so it needs to be confirmed if the ida is to allow the semantic as presented in the test_bytea() that data != (bin1 == bin1). --- .../postgresql/test/test-postgresql.cpp | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/backends/postgresql/test/test-postgresql.cpp b/src/backends/postgresql/test/test-postgresql.cpp index ccc863268..70827d880 100644 --- a/src/backends/postgresql/test/test-postgresql.cpp +++ b/src/backends/postgresql/test/test-postgresql.cpp @@ -544,6 +544,49 @@ void test12() std::cout << "test 12 passed" << std::endl; } +struct bytea_table_creator : public table_creator_base +{ + bytea_table_creator(session& sql) + : table_creator_base(sql) + { + sql << "drop table if exists soci_test;"; + sql << "create table soci_test ( val bytea null )"; + } +}; + +void test_bytea() +{ + { + session sql(backEnd, connectString); + bytea_table_creator tableCreator(sql); + + int v = 0x0A0B0C0D; + unsigned char* b = reinterpret_cast(&v); + std::string data; + std::copy(b, b + sizeof(v), std::back_inserter(data)); + { + + sql << "insert into soci_test(val) values(:val)", use(data); + + // 1) into string, no Oid mapping + std::string bin1; + sql << "select val from soci_test", into(bin1); + assert(bin1 == "\\x0d0c0b0a"); + + // 2) Oid-to-dt_string mapped + row r; + sql << "select * from soci_test", into(r); + + assert(r.size() == 1); + column_properties const& props = r.get_properties(0); + assert(props.get_data_type() == soci::dt_string); + std::string bin2 = r.get(0); + assert(bin2 == "\\x0d0c0b0a"); + } + } + std::cout << "test_bytea passed" << std::endl; +} + // DDL Creation objects for common tests struct table_creator_one : public table_creator_base { @@ -637,6 +680,8 @@ int main(int argc, char** argv) try { + test_bytea(); + test_context tc(backEnd, connectString); common_tests tests(tc); tests.run(); @@ -658,6 +703,7 @@ int main(int argc, char** argv) test10(); test11(); test12(); + test_bytea(); std::cout << "\nOK, all tests passed.\n\n"; return EXIT_SUCCESS;