Get rid of "soci_use_common_tests" hack

This can be avoided by using a different base test context class for the
non-empty tests.
This commit is contained in:
Vadim Zeitlin
2024-11-06 14:54:37 +01:00
parent 72cdda53a1
commit 0aa2c1f27b
13 changed files with 37 additions and 65 deletions

View File

@@ -50,8 +50,6 @@
#include "test-context.h"
#include "test-myint.h"
bool soci_use_common_tests = false;
// Although SQL standard mandates right padding CHAR(N) values to their length
// with spaces, some backends don't confirm to it:
//
@@ -6762,6 +6760,10 @@ TEST_CASE_METHOD(common_tests, "Failover", "[keep-alive][.]")
} // namespace test_cases
// Implement test_context_common ctor here, even if it's trivial: like this,
// just using this class pulls in the tests defined in this file.
test_context_common::test_context_common() = default;
} // namespace tests
} // namespace soci

View File

@@ -64,13 +64,10 @@ struct table_creator_for_get_affected_rows : table_creator_base
}
};
class test_context :public test_context_base
class test_context :public test_context_common
{
public:
test_context()
{
soci_use_common_tests = true;
}
test_context() = default;
std::string get_example_connection_string() const override
{

View File

@@ -139,16 +139,14 @@ TEST_CASE("Dummy test", "[empty]")
// Each test must define the test context class which implements the base class
// pure virtual functions in a backend-specific way.
//
// Unlike in all the other tests we inherit directly from test_context_base and
// not test_context_common because we don't want to link in, and hence run, all
// the common tests that would fail for this dummy empty backend.
class test_context :public test_context_base
{
public:
test_context()
{
// Unlike in all the other tests, we do _not_ reference
// soci_use_common_tests variable defined in test-common.cpp here,
// which means that this file is not getting linked and common tests
// are not executed for this backend (as they would all fail anyhow).
}
test_context() = default;
std::string get_example_connection_string() const override
{

View File

@@ -1186,13 +1186,10 @@ struct TableCreatorXML : public tests::table_creator_base
}
};
class test_context : public tests::test_context_base
class test_context : public tests::test_context_common
{
public:
test_context()
{
soci_use_common_tests = true;
}
test_context() = default;
std::string get_example_connection_string() const override
{

View File

@@ -63,13 +63,10 @@ struct table_creator_for_blob : public tests::table_creator_base
// Support for SOCI Common Tests
//
class test_context : public test_context_base
class test_context : public test_context_common
{
public:
test_context()
{
soci_use_common_tests = true;
}
test_context() = default;
std::string get_example_connection_string() const override
{

View File

@@ -68,14 +68,11 @@ struct table_creator_for_get_affected_rows : table_creator_base
// Support for SOCI Common Tests
//
class test_context : public test_context_base
class test_context : public test_context_common
{
public:
test_context()
{
soci_use_common_tests = true;
}
test_context() = default;
std::string get_example_connection_string() const override
{

View File

@@ -64,13 +64,10 @@ struct table_creator_for_get_affected_rows : table_creator_base
// Support for SOCI Common Tests
//
class test_context : public test_context_base
class test_context : public test_context_common
{
public:
test_context()
{
soci_use_common_tests = true;
}
test_context() = default;
std::string get_example_connection_string() const override
{

View File

@@ -151,13 +151,10 @@ struct table_creator_for_get_last_insert_id : table_creator_base
// Support for SOCI Common Tests
//
class test_context : public test_context_base
class test_context : public test_context_common
{
public:
test_context()
{
soci_use_common_tests = true;
}
test_context() = default;
std::string get_example_connection_string() const override
{

View File

@@ -152,13 +152,10 @@ struct table_creator_for_clob : table_creator_base
// Support for SOCI Common Tests
//
class test_context : public test_context_base
class test_context : public test_context_common
{
public:
test_context()
{
soci_use_common_tests = true;
}
test_context() = default;
bool initialize_connect_string(std::string argFromCommandLine) override
{

View File

@@ -1479,13 +1479,10 @@ struct table_creator_for_blob : public tests::table_creator_base
}
};
class test_context :public test_context_base
class test_context :public test_context_common
{
public:
test_context()
{
soci_use_common_tests = true;
}
test_context() = default;
std::string get_example_connection_string() const override
{

View File

@@ -1476,13 +1476,10 @@ struct table_creator_for_blob : public tests::table_creator_base
};
class test_context : public test_context_base
class test_context : public test_context_common
{
public:
test_context()
{
soci_use_common_tests = true;
}
test_context() = default;
std::string get_example_connection_string() const override
{

View File

@@ -898,13 +898,10 @@ struct table_creator_for_blob : public tests::table_creator_base
}
};
class test_context : public test_context_base
class test_context : public test_context_common
{
public:
test_context()
{
soci_use_common_tests = true;
}
test_context() = default;
bool initialize_connect_string(std::string argFromCommandLine) override
{

View File

@@ -20,12 +20,6 @@
extern std::string connectString;
extern soci::backend_factory const &backEnd;
// This variable can be referenced by the tests to force linking the object
// file that this source file is compiled into with them and must be used to
// avoid linking the common tests into the "empty" test, while allowing to
// request linking with it in all the other tests.
extern bool soci_use_common_tests;
namespace soci
{
@@ -251,6 +245,14 @@ private:
SOCI_NOT_COPYABLE(test_context_base)
};
// Base class for all "normal" tests, i.e. those that run common tests.
class test_context_common : public test_context_base
{
public:
// This is implemented in test-common.cpp.
test_context_common();
};
} // namespace tests
} // namespace soci