summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2015-07-25 19:17:37 +0000
committerChris Wilson <chris+github@qwirx.com>2015-07-25 19:17:37 +0000
commitc8b85e5be8ab0e58bd4f946dec4683a376df4381 (patch)
tree0bcb4a69545564c84a98c61c6857c80f271bf8e6
parentde7046406341c59c9c8c57b79fce99bdc123c794 (diff)
Move load_config_file to Test.cpp to allow reuse.
-rw-r--r--lib/common/Test.cpp13
-rw-r--r--lib/common/Test.h4
-rw-r--r--test/bbackupd/testbbackupd.cpp28
3 files changed, 27 insertions, 18 deletions
diff --git a/lib/common/Test.cpp b/lib/common/Test.cpp
index ba99d496..9385d8c3 100644
--- a/lib/common/Test.cpp
+++ b/lib/common/Test.cpp
@@ -512,3 +512,16 @@ void safe_sleep(int seconds)
{
ShortSleep(SecondsToBoxTime(seconds), true);
}
+
+std::auto_ptr<Configuration> load_config_file(const std::string& config_file,
+ const ConfigurationVerify& verify)
+{
+ std::string errs;
+ std::auto_ptr<Configuration> config(
+ Configuration::LoadAndVerify(config_file, &verify, errs));
+ TEST_EQUAL_LINE(0, errs.size(), "Failed to load configuration file: " + config_file +
+ ": " + errs);
+ TEST_EQUAL_OR(0, errs.size(), config.reset());
+ return config;
+}
+
diff --git a/lib/common/Test.h b/lib/common/Test.h
index a69fdae8..f6bbb49d 100644
--- a/lib/common/Test.h
+++ b/lib/common/Test.h
@@ -14,6 +14,8 @@
#include <list>
#include <map>
+#include "Configuration.h"
+
#ifdef WIN32
#define BBACKUPCTL "..\\..\\bin\\bbackupctl\\bbackupctl.exe"
#define BBACKUPD "..\\..\\bin\\bbackupd\\bbackupd.exe"
@@ -236,5 +238,7 @@ void terminate_bbackupd(int pid);
// Wait a given number of seconds for something to complete
void wait_for_operation(int seconds, const char* message);
void safe_sleep(int seconds);
+std::auto_ptr<Configuration> load_config_file(const std::string& config_file,
+ const ConfigurationVerify& verify);
#endif // TEST__H
diff --git a/test/bbackupd/testbbackupd.cpp b/test/bbackupd/testbbackupd.cpp
index bf8684da..58995e33 100644
--- a/test/bbackupd/testbbackupd.cpp
+++ b/test/bbackupd/testbbackupd.cpp
@@ -89,9 +89,10 @@
#endif
// two cycles and a bit
-#define TIME_TO_WAIT_FOR_BACKUP_OPERATION 12
+#define TIME_TO_WAIT_FOR_BACKUP_OPERATION 12
#define SHORT_TIMEOUT 5000
#define BACKUP_ERROR_DELAY_SHORTENED 10
+#define DEFAULT_BBACKUPD_CONFIG_FILE "testfiles/bbackupd.conf"
void wait_for_backup_operation(const char* message)
{
@@ -462,13 +463,13 @@ bool setup_test_bbackupd(BackupDaemon& bbackupd, bool do_unpack_files = true,
TEST_THAT(create_account(10000, 20000));
#define SETUP_WITHOUT_FILES() \
- SETUP_TEST_BBACKUPD() \
+ SETUP_TEST_BBACKUPD(); \
BackupDaemon bbackupd; \
TEST_THAT_OR(setup_test_bbackupd(bbackupd, false), FAIL); \
TEST_THAT_OR(::mkdir("testfiles/TestDir1", 0755) == 0, FAIL);
#define SETUP_WITH_BBSTORED() \
- SETUP_TEST_BBACKUPD() \
+ SETUP_TEST_BBACKUPD(); \
BackupDaemon bbackupd; \
TEST_THAT_OR(setup_test_bbackupd(bbackupd), FAIL);
@@ -985,23 +986,12 @@ bool compare(BackupQueries::ReturnCode::Type expected_status,
return (returnValue == expected_system_result);
}
-std::auto_ptr<Configuration> load_config_file(
- std::string config_file = "testfiles/bbackupd.conf")
-{
- std::string errs;
- std::auto_ptr<Configuration> config(
- Configuration::LoadAndVerify
- ("testfiles/bbackupd.conf", &BackupDaemonConfigVerify, errs));
- TEST_EQUAL_LINE(0, errs.size(), "Failed to load configuration file: " + errs);
- TEST_EQUAL_OR(0, errs.size(), config.reset());
- return config;
-}
-
bool compare_local(BackupQueries::ReturnCode::Type expected_status,
BackupProtocolCallable& client,
const std::string& compare_options = "acQ")
{
- std::auto_ptr<Configuration> config = load_config_file();
+ std::auto_ptr<Configuration> config =
+ load_config_file(DEFAULT_BBACKUPD_CONFIG_FILE, BackupDaemonConfigVerify);
TEST_THAT_OR(config.get(), return false);
BackupQueries bbackupquery(client, *config, false);
@@ -1191,7 +1181,8 @@ bool test_bbackupquery_parser_escape_slashes()
dirname, // dirname,
attrStream)->GetObjectID();
- std::auto_ptr<Configuration> config = load_config_file();
+ std::auto_ptr<Configuration> config =
+ load_config_file(DEFAULT_BBACKUPD_CONFIG_FILE, BackupDaemonConfigVerify);
TEST_THAT_OR(config.get(), return false);
BackupQueries query(connection, *config, false); // read-only
@@ -1210,7 +1201,8 @@ bool test_getobject_on_nonexistent_file()
SETUP_WITH_BBSTORED();
{
- std::auto_ptr<Configuration> config = load_config_file();
+ std::auto_ptr<Configuration> config =
+ load_config_file(DEFAULT_BBACKUPD_CONFIG_FILE, BackupDaemonConfigVerify);
TEST_THAT_OR(config.get(), return false);
std::auto_ptr<BackupProtocolCallable> connection =