Skip to content

Commit

Permalink
Merge pull request #744 from strk/libpq
Browse files Browse the repository at this point in the history
Allow running pgpointcloud tests against non-default installs
  • Loading branch information
hobu committed Feb 4, 2015
2 parents fc7850d + 8a09cfd commit ab52c4f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
10 changes: 6 additions & 4 deletions plugins/pgpointcloud/CMakeLists.txt
Expand Up @@ -34,12 +34,14 @@ PDAL_ADD_PLUGIN(writer_libname writer pgpointcloud
# PgPointCloud tests
#
if (BUILD_PGPOINTCLOUD_TESTS)
set(PGPOINTCLOUD_TEST_DB_HOST localhost CACHE STRING
set(PGPOINTCLOUD_TEST_DB_USER $ENV{PGUSER} CACHE STRING
"Postgres test database user, must be able to create databases")
set(PGPOINTCLOUD_TEST_DB_HOST $ENV{PGHOST} CACHE STRING
"Postgres test database host")
set(PGPOINTCLOUD_TEST_DB_PORT 5432 CACHE STRING
set(PGPOINTCLOUD_TEST_DB_PORT $ENV{PGPORT} CACHE STRING
"Postgres test database port")
set(PGPOINTCLOUD_TEST_DB_NAME pdal_test CACHE STRING
"Postgres test database name, must exist and must be able to create databases")
set(PGPOINTCLOUD_TEST_DB_NAME template1 CACHE STRING
"Postgres master database name, must exist")
set(PGPOINTCLOUD_TEST_DB_TEMPNAME pdal_test_tmp CACHE STRING
"Postgres test database temp database name")

Expand Down
41 changes: 37 additions & 4 deletions plugins/pgpointcloud/test/PgpointcloudWriterTest.cpp
Expand Up @@ -43,11 +43,44 @@

using namespace pdal;

namespace { // anonymous

std::string getTestConnBase()
{
std::string s;
if ( ! testDbPort.empty() )
s += " port='" + testDbPort + "'";
if ( ! testDbHost.empty() )
s += " host='" + testDbHost + "'";
if ( ! testDbUser.empty() )
s += " user='" + testDbUser + "'";
return s;
}

std::string getConnectionString(const std::string& dbname)
{
std::string s = getTestConnBase()
+ " dbname='" + dbname + "'";
return s;
}

std::string getTestDBTempConn()
{
return getConnectionString(testDbTempname);
}

std::string getMasterDBConn()
{
return getConnectionString(testDbName);
}

} // anonymous namespace

Options getWriterOptions()
{
Options options;

options.add(Option("connection", testDbTempConn));
options.add(Option("connection", getTestDBTempConn()));
options.add(Option("table", "pdal_test_table"));
options.add(Option("srid", "4326"));
options.add(Option("capacity", "10000"));
Expand All @@ -64,7 +97,8 @@ class PgpointcloudWriterTest : public testing::Test
{
try
{
m_masterConnection = pg_connect(testDbConn);
std::string connstr = getMasterDBConn();
m_masterConnection = pg_connect( connstr );
} catch (pdal::pdal_error&)
{
m_masterConnection = 0;
Expand All @@ -84,8 +118,7 @@ class PgpointcloudWriterTest : public testing::Test

try
{

m_testConnection = pg_connect( testDbTempConn);
m_testConnection = pg_connect( getTestDBTempConn() );
} catch (pdal::pdal_error&)
{
m_testConnection = 0;
Expand Down
8 changes: 1 addition & 7 deletions plugins/pgpointcloud/test/Pgtest-Support.hpp.in
Expand Up @@ -38,18 +38,12 @@ namespace pdal
{


static const std::string testDbUser("@PGPOINTCLOUD_TEST_DB_USER@");
static const std::string testDbHost("@PGPOINTCLOUD_TEST_DB_HOST@");
static const std::string testDbPort("@PGPOINTCLOUD_TEST_DB_PORT@");
static const std::string testDbName("@PGPOINTCLOUD_TEST_DB_NAME@");
static const std::string testDbTempname("@PGPOINTCLOUD_TEST_DB_TEMPNAME@");

static const std::string testDbConn(std::string("dbname='@PGPOINTCLOUD_TEST_DB_NAME@' ") +
"user='postgres' host='@PGPOINTCLOUD_TEST_DB_HOST@' port='@PGPOINTCLOUD_TEST_DB_PORT@'");
static const std::string testDbTempConn(std::string("dbname='@PGPOINTCLOUD_TEST_DB_TEMPNAME@'") +
"user='postgres' host='@PGPOINTCLOUD_TEST_DB_HOST@' port='@PGPOINTCLOUD_TEST_DB_PORT@'");





//boost::property_tree::ptree Reader::serializePipeline(PointContext ctx) const
Expand Down

0 comments on commit ab52c4f

Please sign in to comment.