diff --git a/daemon/test/constants.h b/daemon/test/constants.h index 6fc38e17ccca4f8c82e14dc21a47a44f1b205b0c..74b8374dd6b6b242a5aa1b310f969ab049ef13e5 100644 --- a/daemon/test/constants.h +++ b/daemon/test/constants.h @@ -34,8 +34,10 @@ #define XSTRINGIFY(s) STRINGIFY(s) #define STRINGIFY(s) #s #define HISTORY_SAMPLE XSTRINGIFY(WORKSPACE) "history-sample.tpl" +#define HISTORY_SAMPLE_BAK HISTORY_SAMPLE ".bak" #define CONFIG_SAMPLE XSTRINGIFY(WORKSPACE) "sflphoned-sample.yml" +#define CONFIG_SAMPLE_BAK CONFIG_SAMPLE ".bak" #define HISTORY_SAMPLE_SIZE 3 #define HISTORY_LIMIT 30 diff --git a/daemon/test/historytest.cpp b/daemon/test/historytest.cpp index 63e7e72ed741df677aa03a034433811fd02b8d02..fe6aa20baed4d2764e77dc9f0427973bf6328cee 100644 --- a/daemon/test/historytest.cpp +++ b/daemon/test/historytest.cpp @@ -35,8 +35,23 @@ #include "logger.h" #include "constants.h" +namespace { +void restore() +{ + if (system("mv " HISTORY_SAMPLE_BAK " " HISTORY_SAMPLE) < 0) + ERROR("Restoration of %s failed", HISTORY_SAMPLE); +} + +void backup() +{ + if (system("cp " HISTORY_SAMPLE " " HISTORY_SAMPLE_BAK) < 0) + ERROR("Backup of %s failed", HISTORY_SAMPLE); +} +} + void HistoryTest::setUp() { + backup(); history_ = new History; history_->setPath(HISTORY_SAMPLE); } @@ -83,4 +98,5 @@ void HistoryTest::test_get_serialized() void HistoryTest::tearDown() { delete history_; + restore(); } diff --git a/daemon/test/main.cpp b/daemon/test/main.cpp index 01df7f979eb286f3f6917dcfbd41f8ba5d12ca00..624c6531e33ab4299ea1b1c1c553cce1a498700f 100644 --- a/daemon/test/main.cpp +++ b/daemon/test/main.cpp @@ -40,6 +40,19 @@ #include <cppunit/extensions/TestFactoryRegistry.h> #include <cppunit/ui/text/TextTestRunner.h> +namespace { + void restore() + { + if (system("mv " CONFIG_SAMPLE_BAK " " CONFIG_SAMPLE) < 0) + ERROR("Restoration of %s failed", CONFIG_SAMPLE); + } + void backup() + { + if (system("cp " CONFIG_SAMPLE " " CONFIG_SAMPLE_BAK) < 0) + ERROR("Backup of %s failed", CONFIG_SAMPLE); + } +} + int main(int argc, char* argv[]) { printf("\nSFLphone Daemon Test Suite, by Savoir-Faire Linux 2004-2010\n\n"); @@ -93,6 +106,7 @@ int main(int argc, char* argv[]) } printf("\n\n=== SFLphone initialization ===\n\n"); + backup(); Manager::instance().init(CONFIG_SAMPLE); // Get the top level suite from the registry @@ -101,6 +115,7 @@ int main(int argc, char* argv[]) if (suite->getChildTestCount() == 0) { ERROR("Invalid test suite name: %s", testSuiteName.c_str()); + restore(); return 1; } @@ -124,5 +139,7 @@ int main(int argc, char* argv[]) printf("=== Test suite terminate ===\n"); Manager::instance().terminate(); + restore(); + return wasSuccessful ? 0 : 1; }