From e8ad581a9f3ccc5449c45fb82d598f2a4678e732 Mon Sep 17 00:00:00 2001
From: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
Date: Tue, 17 Apr 2012 13:55:14 -0400
Subject: [PATCH] Revert "* #8586: don't restore and save test files"

This reverts commit 097dd6070e453e5d85467116f2293b553219830a.
Config file and history file restoration work fine without breaking make
distcheck.
---
 daemon/test/constants.h     |  2 ++
 daemon/test/historytest.cpp | 16 ++++++++++++++++
 daemon/test/main.cpp        | 17 +++++++++++++++++
 3 files changed, 35 insertions(+)

diff --git a/daemon/test/constants.h b/daemon/test/constants.h
index 6fc38e17cc..74b8374dd6 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 63e7e72ed7..fe6aa20bae 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 01df7f979e..624c6531e3 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;
 }
-- 
GitLab