summaryrefslogtreecommitdiff
path: root/libpq/tests
diff options
context:
space:
mode:
Diffstat (limited to 'libpq/tests')
-rw-r--r--libpq/tests/.gitignore3
-rw-r--r--libpq/tests/build/.gitignore3
-rw-r--r--libpq/tests/build/bootstrap.build9
-rw-r--r--libpq/tests/build/root.build22
-rw-r--r--libpq/tests/buildfile5
-rw-r--r--libpq/tests/conninfo/buildfile13
-rw-r--r--libpq/tests/conninfo/driver.c74
-rw-r--r--libpq/tests/conninfo/expected.out171
-rw-r--r--libpq/tests/conninfo/postgres_fe.h19
-rw-r--r--libpq/tests/conninfo/regress.in57
-rw-r--r--libpq/tests/conninfo/testscript5
l---------libpq/tests/conninfo/uri-regress.c1
12 files changed, 382 insertions, 0 deletions
diff --git a/libpq/tests/.gitignore b/libpq/tests/.gitignore
new file mode 100644
index 0000000..2e508a9
--- /dev/null
+++ b/libpq/tests/.gitignore
@@ -0,0 +1,3 @@
+driver
+test/
+test-*/
diff --git a/libpq/tests/build/.gitignore b/libpq/tests/build/.gitignore
new file mode 100644
index 0000000..4a730a3
--- /dev/null
+++ b/libpq/tests/build/.gitignore
@@ -0,0 +1,3 @@
+config.build
+root/
+bootstrap/
diff --git a/libpq/tests/build/bootstrap.build b/libpq/tests/build/bootstrap.build
new file mode 100644
index 0000000..6212d9b
--- /dev/null
+++ b/libpq/tests/build/bootstrap.build
@@ -0,0 +1,9 @@
+# file : tests/build/bootstrap.build
+# copyright : Copyright (c) 2016-2019 Code Synthesis Ltd
+# license : PostgreSQL License; see accompanying COPYRIGHT file
+
+project = # Unnamed subproject.
+
+using config
+using dist
+using test
diff --git a/libpq/tests/build/root.build b/libpq/tests/build/root.build
new file mode 100644
index 0000000..e374ddd
--- /dev/null
+++ b/libpq/tests/build/root.build
@@ -0,0 +1,22 @@
+# file : tests/build/root.build
+# copyright : Copyright (c) 2016-2019 Code Synthesis Ltd
+# license : PostgreSQL License; see accompanying COPYRIGHT file
+
+using c
+
+h{*}: extension = h
+c{*}: extension = c
+
+if ($c.target.system == 'win32-msvc')
+ c.poptions += -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS
+
+if ($c.class == 'msvc')
+ c.coptions += /wd4251 /wd4275 /wd4800
+
+# Every exe{} in this subproject is by default a test.
+#
+exe{*}: test = true
+
+# Specify the test target for cross-testing.
+#
+test.target = $c.target
diff --git a/libpq/tests/buildfile b/libpq/tests/buildfile
new file mode 100644
index 0000000..098486c
--- /dev/null
+++ b/libpq/tests/buildfile
@@ -0,0 +1,5 @@
+# file : tests/buildfile
+# copyright : Copyright (c) 2016-2019 Code Synthesis Ltd
+# license : PostgreSQL License; see accompanying COPYRIGHT file
+
+./: {*/ -build/}
diff --git a/libpq/tests/conninfo/buildfile b/libpq/tests/conninfo/buildfile
new file mode 100644
index 0000000..d9d4bab
--- /dev/null
+++ b/libpq/tests/conninfo/buildfile
@@ -0,0 +1,13 @@
+# file : tests/conninfo/buildfile
+# copyright : Copyright (c) 2016-2019 Code Synthesis Ltd
+# license : PostgreSQL License; see accompanying COPYRIGHT file
+
+# Here we reproduce the upstream's libpq test. See the
+# src/interfaces/libpq/test/ in the upstream package for details.
+#
+import libs = libpq%lib{pq}
+
+exe{driver}: {h c}{* -uri-regress} $libs testscript \
+ file{uri-regress.c regress.in expected.out}
+
+c.poptions =+ "-I$src_base"
diff --git a/libpq/tests/conninfo/driver.c b/libpq/tests/conninfo/driver.c
new file mode 100644
index 0000000..1a13af2
--- /dev/null
+++ b/libpq/tests/conninfo/driver.c
@@ -0,0 +1,74 @@
+/* file : tests/conninfo/driver.c
+ * copyright : Copyright (c) 2016-2019 Code Synthesis Ltd
+ * license : PostgreSQL License; see accompanying COPYRIGHT file
+ */
+
+/*
+ * Include the upstream package test and rename it's main() function to test()
+ * (see below for details).
+ */
+#define main test
+#include <uri-regress.c>
+#undef main
+
+/*
+ * Enable assertions.
+ */
+#ifdef NDEBUG
+# undef NDEBUG
+#endif
+
+#include <stdio.h>
+#include <assert.h>
+#include <string.h> /* strlen() */
+
+/*
+ * Usage: argv[0]
+ *
+ * Read connection info strings from STDIN and call upstream test main()
+ * function for each of them. The function prints the parsed connection info to
+ * stdout on success or error message to stderr on failure.
+ */
+int
+main (int argc, char* argv[])
+{
+ assert (argc == 1);
+
+ char s[1024];
+
+ while (fgets (s, sizeof(s), stdin) != NULL)
+ {
+ /*
+ * Print the conninfo string that will be tested.
+ */
+ printf ("trying %s", s);
+
+ /*
+ * Strip the newline character and make sure it is printed to stdout.
+ */
+ size_t n = strlen (s);
+ if (n != 0 && s[n - 1] == '\n')
+ s[n - 1] = '\0';
+ else
+ printf ("\n");
+
+ /*
+ * Make sure the output make sense if stderr is redirected to stdout (and
+ * vice versa).
+ */
+ fflush (stdout);
+
+ /*
+ * Run the test.
+ *
+ * Note that we need to print the trailing newline character ourselves.
+ */
+ char* args[] = {argv[0], s, NULL};
+ int r = test (2, args);
+
+ fprintf (r == 0 ? stdout : stderr, "\n");
+ fflush (r == 0 ? stdout : stderr);
+ }
+
+ return 0;
+}
diff --git a/libpq/tests/conninfo/expected.out b/libpq/tests/conninfo/expected.out
new file mode 100644
index 0000000..d375e82
--- /dev/null
+++ b/libpq/tests/conninfo/expected.out
@@ -0,0 +1,171 @@
+trying postgresql://uri-user:secret@host:12345/db
+user='uri-user' password='secret' dbname='db' host='host' port='12345' (inet)
+
+trying postgresql://uri-user@host:12345/db
+user='uri-user' dbname='db' host='host' port='12345' (inet)
+
+trying postgresql://uri-user@host/db
+user='uri-user' dbname='db' host='host' (inet)
+
+trying postgresql://host:12345/db
+dbname='db' host='host' port='12345' (inet)
+
+trying postgresql://host/db
+dbname='db' host='host' (inet)
+
+trying postgresql://uri-user@host:12345/
+user='uri-user' host='host' port='12345' (inet)
+
+trying postgresql://uri-user@host/
+user='uri-user' host='host' (inet)
+
+trying postgresql://uri-user@
+user='uri-user' (local)
+
+trying postgresql://host:12345/
+host='host' port='12345' (inet)
+
+trying postgresql://host:12345
+host='host' port='12345' (inet)
+
+trying postgresql://host/db
+dbname='db' host='host' (inet)
+
+trying postgresql://host/
+host='host' (inet)
+
+trying postgresql://host
+host='host' (inet)
+
+trying postgresql://
+(local)
+
+trying postgresql://?hostaddr=127.0.0.1
+hostaddr='127.0.0.1' (inet)
+
+trying postgresql://example.com?hostaddr=63.1.2.4
+host='example.com' hostaddr='63.1.2.4' (inet)
+
+trying postgresql://%68ost/
+host='host' (inet)
+
+trying postgresql://host/db?user=uri-user
+user='uri-user' dbname='db' host='host' (inet)
+
+trying postgresql://host/db?user=uri-user&port=12345
+user='uri-user' dbname='db' host='host' port='12345' (inet)
+
+trying postgresql://host/db?u%73er=someotheruser&port=12345
+user='someotheruser' dbname='db' host='host' port='12345' (inet)
+
+trying postgresql://host/db?u%7aer=someotheruser&port=12345
+uri-regress: invalid URI query parameter: "uzer"
+
+trying postgresql://host:12345?user=uri-user
+user='uri-user' host='host' port='12345' (inet)
+
+trying postgresql://host?user=uri-user
+user='uri-user' host='host' (inet)
+
+trying postgresql://host?
+host='host' (inet)
+
+trying postgresql://[::1]:12345/db
+dbname='db' host='::1' port='12345' (inet)
+
+trying postgresql://[::1]/db
+dbname='db' host='::1' (inet)
+
+trying postgresql://[2001:db8::1234]/
+host='2001:db8::1234' (inet)
+
+trying postgresql://[200z:db8::1234]/
+host='200z:db8::1234' (inet)
+
+trying postgresql://[::1]
+host='::1' (inet)
+
+trying postgres://
+(local)
+
+trying postgres:///
+(local)
+
+trying postgres:///db
+dbname='db' (local)
+
+trying postgres://uri-user@/db
+user='uri-user' dbname='db' (local)
+
+trying postgres://?host=/path/to/socket/dir
+host='/path/to/socket/dir' (local)
+
+trying postgresql://host?uzer=
+uri-regress: invalid URI query parameter: "uzer"
+
+trying postgre://
+uri-regress: missing "=" after "postgre://" in connection info string
+
+trying postgres://[::1
+uri-regress: end of string reached when looking for matching "]" in IPv6 host address in URI: "postgres://[::1"
+
+trying postgres://[]
+uri-regress: IPv6 host address may not be empty in URI: "postgres://[]"
+
+trying postgres://[::1]z
+uri-regress: unexpected character "z" at position 17 in URI (expected ":" or "/"): "postgres://[::1]z"
+
+trying postgresql://host?zzz
+uri-regress: missing key/value separator "=" in URI query parameter: "zzz"
+
+trying postgresql://host?value1&value2
+uri-regress: missing key/value separator "=" in URI query parameter: "value1"
+
+trying postgresql://host?key=key=value
+uri-regress: extra key/value separator "=" in URI query parameter: "key"
+
+trying postgres://host?dbname=%XXfoo
+uri-regress: invalid percent-encoded token: "%XXfoo"
+
+trying postgresql://a%00b
+uri-regress: forbidden value %00 in percent-encoded value: "a%00b"
+
+trying postgresql://%zz
+uri-regress: invalid percent-encoded token: "%zz"
+
+trying postgresql://%1
+uri-regress: invalid percent-encoded token: "%1"
+
+trying postgresql://%
+uri-regress: invalid percent-encoded token: "%"
+
+trying postgres://@host
+host='host' (inet)
+
+trying postgres://host:/
+host='host' (inet)
+
+trying postgres://:12345/
+port='12345' (local)
+
+trying postgres://otheruser@?host=/no/such/directory
+user='otheruser' host='/no/such/directory' (local)
+
+trying postgres://otheruser@/?host=/no/such/directory
+user='otheruser' host='/no/such/directory' (local)
+
+trying postgres://otheruser@:12345?host=/no/such/socket/path
+user='otheruser' host='/no/such/socket/path' port='12345' (local)
+
+trying postgres://otheruser@:12345/db?host=/path/to/socket
+user='otheruser' dbname='db' host='/path/to/socket' port='12345' (local)
+
+trying postgres://:12345/db?host=/path/to/socket
+dbname='db' host='/path/to/socket' port='12345' (local)
+
+trying postgres://:12345?host=/path/to/socket
+host='/path/to/socket' port='12345' (local)
+
+trying postgres://%2Fvar%2Flib%2Fpostgresql/dbname
+dbname='dbname' host='/var/lib/postgresql' (local)
+
diff --git a/libpq/tests/conninfo/postgres_fe.h b/libpq/tests/conninfo/postgres_fe.h
new file mode 100644
index 0000000..0dd2ed2
--- /dev/null
+++ b/libpq/tests/conninfo/postgres_fe.h
@@ -0,0 +1,19 @@
+/* file : tests/conninfo/postgres_fe.h
+ * copyright : Copyright (c) 2016-2019 Code Synthesis Ltd
+ * license : PostgreSQL License; see accompanying COPYRIGHT file
+ */
+
+/*
+ * The upstream's uri-regress.c includes src/include/postgres_fe.h that is
+ * located in libpq/include/ in our source tree. This file is not installed,
+ * so to keep the test as a subproject and be able to test against the
+ * installed libpq library we replace it with the header stub, containing the
+ * bare minimum that is required the test to compile.
+ */
+#ifndef TESTS_CONNINFO_POSTGRES_FE_H
+#define TESTS_CONNINFO_POSTGRES_FE_H
+
+#include <stdbool.h>
+#include <string.h>
+
+#endif /* TESTS_CONNINFO_POSTGRES_FE_H */
diff --git a/libpq/tests/conninfo/regress.in b/libpq/tests/conninfo/regress.in
new file mode 100644
index 0000000..de034f3
--- /dev/null
+++ b/libpq/tests/conninfo/regress.in
@@ -0,0 +1,57 @@
+postgresql://uri-user:secret@host:12345/db
+postgresql://uri-user@host:12345/db
+postgresql://uri-user@host/db
+postgresql://host:12345/db
+postgresql://host/db
+postgresql://uri-user@host:12345/
+postgresql://uri-user@host/
+postgresql://uri-user@
+postgresql://host:12345/
+postgresql://host:12345
+postgresql://host/db
+postgresql://host/
+postgresql://host
+postgresql://
+postgresql://?hostaddr=127.0.0.1
+postgresql://example.com?hostaddr=63.1.2.4
+postgresql://%68ost/
+postgresql://host/db?user=uri-user
+postgresql://host/db?user=uri-user&port=12345
+postgresql://host/db?u%73er=someotheruser&port=12345
+postgresql://host/db?u%7aer=someotheruser&port=12345
+postgresql://host:12345?user=uri-user
+postgresql://host?user=uri-user
+postgresql://host?
+postgresql://[::1]:12345/db
+postgresql://[::1]/db
+postgresql://[2001:db8::1234]/
+postgresql://[200z:db8::1234]/
+postgresql://[::1]
+postgres://
+postgres:///
+postgres:///db
+postgres://uri-user@/db
+postgres://?host=/path/to/socket/dir
+postgresql://host?uzer=
+postgre://
+postgres://[::1
+postgres://[]
+postgres://[::1]z
+postgresql://host?zzz
+postgresql://host?value1&value2
+postgresql://host?key=key=value
+postgres://host?dbname=%XXfoo
+postgresql://a%00b
+postgresql://%zz
+postgresql://%1
+postgresql://%
+postgres://@host
+postgres://host:/
+postgres://:12345/
+postgres://otheruser@?host=/no/such/directory
+postgres://otheruser@/?host=/no/such/directory
+postgres://otheruser@:12345?host=/no/such/socket/path
+postgres://otheruser@:12345/db?host=/path/to/socket
+postgres://:12345/db?host=/path/to/socket
+postgres://:12345?host=/path/to/socket
+postgres://%2Fvar%2Flib%2Fpostgresql/dbname
diff --git a/libpq/tests/conninfo/testscript b/libpq/tests/conninfo/testscript
new file mode 100644
index 0000000..bf278ae
--- /dev/null
+++ b/libpq/tests/conninfo/testscript
@@ -0,0 +1,5 @@
+# file : tests/conninfo/testscript
+# copyright : Copyright (c) 2016-2019 Code Synthesis Ltd
+# license : PostgreSQL License; see accompanying COPYRIGHT file
+
+$* <<<$src_base/regress.in >>>$src_base/expected.out 2>&1
diff --git a/libpq/tests/conninfo/uri-regress.c b/libpq/tests/conninfo/uri-regress.c
new file mode 120000
index 0000000..fbab965
--- /dev/null
+++ b/libpq/tests/conninfo/uri-regress.c
@@ -0,0 +1 @@
+../../../upstream/src/interfaces/libpq/test/uri-regress.c \ No newline at end of file