summaryrefslogtreecommitdiffstats
path: root/Tests/FindPostgreSQL
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2018-10-31 19:06:45 (GMT)
committerBrad King <brad.king@kitware.com>2018-11-01 17:23:38 (GMT)
commit7413f29fe63296cf34176c5fc68c2c5354b43202 (patch)
tree7a96b2879be58e4295688ca4edb6648bc50a7574 /Tests/FindPostgreSQL
parentd2235fd2538eca934f542ff82f21249c3ff314be (diff)
downloadCMake-7413f29fe63296cf34176c5fc68c2c5354b43202.zip
CMake-7413f29fe63296cf34176c5fc68c2c5354b43202.tar.gz
CMake-7413f29fe63296cf34176c5fc68c2c5354b43202.tar.bz2
Tests/FindPostgreSQL: add a test for FindPostgreSQL
Diffstat (limited to 'Tests/FindPostgreSQL')
-rw-r--r--Tests/FindPostgreSQL/CMakeLists.txt10
-rw-r--r--Tests/FindPostgreSQL/Test/CMakeLists.txt16
-rw-r--r--Tests/FindPostgreSQL/Test/main.c15
3 files changed, 41 insertions, 0 deletions
diff --git a/Tests/FindPostgreSQL/CMakeLists.txt b/Tests/FindPostgreSQL/CMakeLists.txt
new file mode 100644
index 0000000..50151ee
--- /dev/null
+++ b/Tests/FindPostgreSQL/CMakeLists.txt
@@ -0,0 +1,10 @@
+add_test(NAME FindPostgreSQL.Test COMMAND
+ ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>
+ --build-and-test
+ "${CMake_SOURCE_DIR}/Tests/FindPostgreSQL/Test"
+ "${CMake_BINARY_DIR}/Tests/FindPostgreSQL/Test"
+ ${build_generator_args}
+ --build-project TestFindPostgreSQL
+ --build-options ${build_options}
+ --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION>
+ )
diff --git a/Tests/FindPostgreSQL/Test/CMakeLists.txt b/Tests/FindPostgreSQL/Test/CMakeLists.txt
new file mode 100644
index 0000000..374e147
--- /dev/null
+++ b/Tests/FindPostgreSQL/Test/CMakeLists.txt
@@ -0,0 +1,16 @@
+cmake_minimum_required(VERSION 3.10)
+project(TestFindPostgreSQL C)
+include(CTest)
+
+find_package(PostgreSQL REQUIRED)
+
+add_definitions(-DCMAKE_EXPECTED_POSTGRESQL_VERSION="${PostgreSQL_VERSION_STRING}")
+
+add_executable(test_tgt main.c)
+target_link_libraries(test_tgt PostgreSQL::PostgreSQL)
+add_test(NAME test_tgt COMMAND test_tgt)
+
+add_executable(test_var main.c)
+target_include_directories(test_var PRIVATE ${PostgreSQL_INCLUDE_DIRS})
+target_link_libraries(test_var PRIVATE ${PostgreSQL_LIBRARIES})
+add_test(NAME test_var COMMAND test_var)
diff --git a/Tests/FindPostgreSQL/Test/main.c b/Tests/FindPostgreSQL/Test/main.c
new file mode 100644
index 0000000..2cfeed0
--- /dev/null
+++ b/Tests/FindPostgreSQL/Test/main.c
@@ -0,0 +1,15 @@
+#include <libpq-fe.h>
+#include <stdio.h>
+#include <string.h>
+
+int main()
+{
+ int version = PQlibVersion();
+ int major = version / 10000;
+ int minor = version % 10000;
+ char version_string[100];
+ snprintf(version_string, sizeof(version_string), "%d.%d", major, minor);
+ printf("Found PostgreSQL version %s, expected version %s\n", version_string,
+ CMAKE_EXPECTED_POSTGRESQL_VERSION);
+ return strcmp(version_string, CMAKE_EXPECTED_POSTGRESQL_VERSION);
+}