PDAL/PDAL — pull request #369 by gadomski (2014-05-19 21:15:12+00:00)
Title: Check for null pointers when using pg_query_once

`pdal::drivers::pgpointcloud::pg_query_once` is C-ish -- it returns a
raw `char *` from `strdup`. In our driver code, we were not checking
that pointer against `NULL`, which lead to PDAL crashing when the target
postgres database existed, but did not have the [`pointcloud`
extension](https://github.com/pramsey/pointcloud) installed.

This patch updates all uses of `pg_query_once` in the codebase with a
check for pointer validity, throwing a `pdal_error` if the returned
pointer is `NULL`. Note that other functions in
`include/pdal/drivers/pgpointcloud/common.hpp` also return raw pointers,
but their usage has not been checked or modified for this patch, due
primarily to developer laziness but rationalized as commendable commit
cleanliness/avoidance of mission creep.

This patch also adds a test harness for the pgpointcloud drivers, which
helped verify the correctness of the fix. Since the unit tests require a
running postgres instance with a already-created database, the postgres
unit tests are disabled by default. They can be enabled by enabling the
dependent cmake option `WITH_PGPOINTCLOUD_TESTS`. The database
connection parameters can then be configured with CMake variables.

I think it would be better to allow configuration of the postgres test
database with some sort of configuration file (so a change to the
postgres test database configuration didn't require a rebuild), but
leveraging the existing CMake configuration system was quicker than
doing my own config parsing.

Fixes #292.