Permalink
Browse files

Added JSON test. Notice require version PSQL server 9.2 but does not …

…check version number
  • Loading branch information...
Poul Bondo
Poul Bondo committed Feb 22, 2013
1 parent 14e2a75 commit 27c3c3f165ef398a643ec4e00f3cbb7c05eeb18f
Showing with 41 additions and 0 deletions.
  1. +41 −0 src/backends/postgresql/test/test-postgresql.cpp
@@ -629,6 +629,46 @@ struct table_creator_for_get_affected_rows : table_creator_base
}
};
struct table_creator_json : public table_creator_base
{
table_creator_json(session& sql)
: table_creator_base(sql)
{
sql << "drop table if exists soci_json_test;";
sql << "create table soci_json_test(data json)";
}
};
// Test JSON. Only valid for PostgreSQL Server 9.2++
void test_json()
{
{
bool exception = false;
session sql(backEnd, connectString);
std::string result;
std::string valid_input = "{\"tool\":\"soci\",\"result\":42}";
std::string invalid_input = "{\"tool\":\"other\",\"result\":invalid}";
table_creator_json tableCreator(sql);
sql << "insert into soci_json_test (data) values(:data)",use(valid_input);
sql << "select data from soci_json_test",into(result);
assert(result == valid_input);
try
{
sql << "insert into soci_json_test (data) values(:data)",use(invalid_input);
}
catch(soci_error &_exception)
{
exception = true;
}
assert(exception);
}
std::cout << "test json passed" << std::endl;
}
//
// Support for soci Common Tests
//
@@ -714,6 +754,7 @@ int main(int argc, char** argv)
test11();
test12();
test_bytea();
test_json();
std::cout << "\nOK, all tests passed.\n\n";

0 comments on commit 27c3c3f

Please sign in to comment.