#pragma once #include #include #include namespace pgtest { /// Value of the TEST_DATABASE_URL environment variable, if set and non-empty. std::optional baseUrl(); /// Same as baseUrl() but with the database name replaced. QString urlForDb(const QString &db); /// True when a server is configured and the template database was created. bool available(); /// server_version_num of the server under test (0 when unavailable). int serverVersionNum(); /// Portable process id. qint64 processId(); /// Name of the template database for this process. QString templateDbName(); /// Name of the login role without superuser rights, unique per process. QString plainRoleName(); /// Same as urlForDb() but with the plain role as user. QString urlForDbAsPlainRole(const QString &db); /// Quotes an identifier for use in SQL. QString quoteIdent(const QString &name); /// Global environment, register it in main(): /// ::testing::AddGlobalTestEnvironment(new pgtest::PgEnv(PGTEST_FIXTURE_DIR)); /// Creates a template database from /schema.sql once per process. class PgEnv : public ::testing::Environment { public: explicit PgEnv(QString fixtureDir) : fixtureDir_(std::move(fixtureDir)) {} void SetUp() override; void TearDown() override; private: QString fixtureDir_; }; } // namespace pgtest #define REQUIRE_PG_AT_LEAST(v) \ if (pgtest::serverVersionNum() < (v) * 10000) GTEST_SKIP() << "needs PG " #v