diff options
Diffstat (limited to 'src/test/modules/libpq_pipeline/libpq_pipeline.c')
-rw-r--r-- | src/test/modules/libpq_pipeline/libpq_pipeline.c | 113 |
1 files changed, 111 insertions, 2 deletions
diff --git a/src/test/modules/libpq_pipeline/libpq_pipeline.c b/src/test/modules/libpq_pipeline/libpq_pipeline.c index ac9ac95135f..9a3c0236325 100644 --- a/src/test/modules/libpq_pipeline/libpq_pipeline.c +++ b/src/test/modules/libpq_pipeline/libpq_pipeline.c @@ -206,15 +206,17 @@ copy_connection(PGconn *conn) PQconninfoOption *opts = PQconninfo(conn); const char **keywords; const char **vals; - int nopts = 1; - int i = 0; + int nopts = 0; + int i; for (PQconninfoOption *opt = opts; opt->keyword != NULL; ++opt) nopts++; + nopts++; /* for the NULL terminator */ keywords = pg_malloc(sizeof(char *) * nopts); vals = pg_malloc(sizeof(char *) * nopts); + i = 0; for (PQconninfoOption *opt = opts; opt->keyword != NULL; ++opt) { if (opt->val) @@ -1405,6 +1407,110 @@ test_prepared(PGconn *conn) fprintf(stderr, "ok\n"); } +/* + * Test max_protocol_version options. + */ +static void +test_protocol_version(PGconn *conn) +{ + const char **keywords; + const char **vals; + int nopts; + PQconninfoOption *opts = PQconninfo(conn); + int protocol_version; + int max_protocol_version_index; + int i; + + /* + * Prepare keywords/vals arrays, copied from the existing connection, with + * an extra slot for 'max_protocol_version'. + */ + nopts = 0; + for (PQconninfoOption *opt = opts; opt->keyword != NULL; ++opt) + nopts++; + nopts++; /* max_protocol_version */ + nopts++; /* NULL terminator */ + + keywords = pg_malloc0(sizeof(char *) * nopts); + vals = pg_malloc0(sizeof(char *) * nopts); + + i = 0; + for (PQconninfoOption *opt = opts; opt->keyword != NULL; ++opt) + { + if (opt->val) + { + keywords[i] = opt->keyword; + vals[i] = opt->val; + i++; + } + } + + max_protocol_version_index = i; + keywords[i] = "max_protocol_version"; /* value is filled in below */ + i++; + keywords[i] = vals[i] = NULL; + + /* + * Test max_protocol_version=3.0 + */ + vals[max_protocol_version_index] = "3.0"; + conn = PQconnectdbParams(keywords, vals, false); + + if (PQstatus(conn) != CONNECTION_OK) + pg_fatal("Connection to database failed: %s", + PQerrorMessage(conn)); + + protocol_version = PQfullProtocolVersion(conn); + if (protocol_version != 30000) + pg_fatal("expected 30000, got %d", protocol_version); + + PQfinish(conn); + + /* + * Test max_protocol_version=3.1. It's not valid, we went straight from + * 3.0 to 3.2. + */ + vals[max_protocol_version_index] = "3.1"; + conn = PQconnectdbParams(keywords, vals, false); + + if (PQstatus(conn) != CONNECTION_BAD) + pg_fatal("Connecting with max_protocol_version 3.1 should have failed."); + + PQfinish(conn); + + /* + * Test max_protocol_version=3.2 + */ + vals[max_protocol_version_index] = "3.2"; + conn = PQconnectdbParams(keywords, vals, false); + + if (PQstatus(conn) != CONNECTION_OK) + pg_fatal("Connection to database failed: %s", + PQerrorMessage(conn)); + + protocol_version = PQfullProtocolVersion(conn); + if (protocol_version != 30002) + pg_fatal("expected 30002, got %d", protocol_version); + + PQfinish(conn); + + /* + * Test max_protocol_version=latest. 'latest' currently means '3.2'. + */ + vals[max_protocol_version_index] = "latest"; + conn = PQconnectdbParams(keywords, vals, false); + + if (PQstatus(conn) != CONNECTION_OK) + pg_fatal("Connection to database failed: %s", + PQerrorMessage(conn)); + + protocol_version = PQfullProtocolVersion(conn); + if (protocol_version != 30002) + pg_fatal("expected 30002, got %d", protocol_version); + + PQfinish(conn); +} + /* Notice processor: print notices, and count how many we got */ static void notice_processor(void *arg, const char *message) @@ -2153,6 +2259,7 @@ print_test_list(void) printf("pipeline_idle\n"); printf("pipelined_insert\n"); printf("prepared\n"); + printf("protocol_version\n"); printf("simple_pipeline\n"); printf("singlerow\n"); printf("transaction\n"); @@ -2263,6 +2370,8 @@ main(int argc, char **argv) test_pipelined_insert(conn, numrows); else if (strcmp(testname, "prepared") == 0) test_prepared(conn); + else if (strcmp(testname, "protocol_version") == 0) + test_protocol_version(conn); else if (strcmp(testname, "simple_pipeline") == 0) test_simple_pipeline(conn); else if (strcmp(testname, "singlerow") == 0) |