From 61c6372712b53ea543e49a5d90627282db2aee6b Mon Sep 17 00:00:00 2001
From: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
Date: Wed, 18 Aug 2010 15:08:53 -0400
Subject: [PATCH] [#3883] Fix history unit test failure

---
 sflphone-common/src/config/config.cpp         |  5 +++++
 .../src/history/historymanager.cpp            | 10 ++++++---
 sflphone-common/test/configurationtest.cpp    |  7 ++----
 sflphone-common/test/constants.h              |  4 ++--
 sflphone-common/test/history-sample           | 21 ------------------
 sflphone-common/test/history-sample.tpl       | 15 +++++++------
 sflphone-common/test/historytest.h            |  2 +-
 sflphone-common/test/sequence.yml             | 22 -------------------
 .../test/{sequence2.yml => ymlParser.yml}     |  0
 9 files changed, 25 insertions(+), 61 deletions(-)
 delete mode 100644 sflphone-common/test/history-sample
 delete mode 100755 sflphone-common/test/sequence.yml
 rename sflphone-common/test/{sequence2.yml => ymlParser.yml} (100%)

diff --git a/sflphone-common/src/config/config.cpp b/sflphone-common/src/config/config.cpp
index 839c992020..2c4c68dc45 100644
--- a/sflphone-common/src/config/config.cpp
+++ b/sflphone-common/src/config/config.cpp
@@ -273,6 +273,8 @@ ConfigTree::setConfigTreeItem (const std::string& section,
 bool
 ConfigTree::saveConfigTree (const std::string& fileName)
 {
+    _debug ("ConfigTree: Save %s", fileName.c_str());
+
     if (fileName.empty() && _sections.begin() == _sections.end()) {
         return false;
     }
@@ -321,6 +323,8 @@ ConfigTree::populateFromFile (const std::string& fileName)
 {
     bool out = false;
 
+    _debug ("ConfigTree: Populate from file %s", fileName.c_str());
+
     if (fileName.empty()) {
         return 0;
     }
@@ -378,6 +382,7 @@ ConfigTree::populateFromFile (const std::string& fileName)
                 val = line.substr (pos + 1, line.length() - pos);
 
                 if (key.length() > 0 && val.length() > 0) {
+                    _debug ("setconfigtreeitem %s, %s", section.c_str(), val.c_str());
                     setConfigTreeItem (section, key, val);
                 }
 
diff --git a/sflphone-common/src/history/historymanager.cpp b/sflphone-common/src/history/historymanager.cpp
index 909f20fd06..57a70f8459 100644
--- a/sflphone-common/src/history/historymanager.cpp
+++ b/sflphone-common/src/history/historymanager.cpp
@@ -77,12 +77,14 @@ bool HistoryManager::save_history (void)
 
 bool HistoryManager::load_history_from_file (Conf::ConfigTree *history_list)
 {
-    bool exist;
+    int exist;
 
-    exist = history_list->populateFromFile (_history_path);
+    _debug ("HistoryManager: Load history from file %s", _history_path.c_str());
+
+    exist = history_list->populateFromFile (_history_path.c_str());
     _history_loaded = (exist == 2) ? false : true;
 
-    return exist;
+    return _history_loaded;
 }
 
 int HistoryManager::load_history_items_map (Conf::ConfigTree *history_list, int limit)
@@ -97,6 +99,8 @@ int HistoryManager::load_history_items_map (Conf::ConfigTree *history_list, int
     int history_limit;
     time_t current_timestamp;
 
+    _debug ("HistoryManager: Load history items");
+
     // We want to save only the items recent enough (ie compared to CONFIG_HISTORY_LIMIT)
     // Get the current timestamp
     (void) time (&current_timestamp);
diff --git a/sflphone-common/test/configurationtest.cpp b/sflphone-common/test/configurationtest.cpp
index 85abfe2a19..e79fc1d07e 100644
--- a/sflphone-common/test/configurationtest.cpp
+++ b/sflphone-common/test/configurationtest.cpp
@@ -154,12 +154,9 @@ void ConfigurationTest::testYamlParser()
 
     try {
 
-        parser = new Conf::YamlParser ("sequence2.yml");
-
+        parser = new Conf::YamlParser ("ymlParser.yml");
         parser->serializeEvents();
-
         parser->composeEvents();
-
         parser->constructNativeData();
 
         delete parser;
@@ -276,7 +273,7 @@ void ConfigurationTest::testYamlEmitter()
     tlsmap.setKeyValue (verifyServerKey, &verifyserver);
 
     try {
-        emitter = new Conf::YamlEmitter ("/tmp/sequenceEmiter.txt");
+        emitter = new Conf::YamlEmitter ("/tmp/ymlEmiter.txt");
 
         emitter->serializeAccount (&accountmap);
         emitter->serializeAccount (&accountmap);
diff --git a/sflphone-common/test/constants.h b/sflphone-common/test/constants.h
index 15bcd85860..9272bfd7a8 100644
--- a/sflphone-common/test/constants.h
+++ b/sflphone-common/test/constants.h
@@ -33,9 +33,9 @@
 
 #define YES_STR "1"
 #define NO_STR "0"
-#define HISTORY_SAMPLE  "history-sample"
+#define HISTORY_SAMPLE  "history-sample.tpl"
 #define HISTORY_SAMPLE_SIZE     3
 #define CONFIG_SAMPLE   "sflphoned-sample.yml"
-#define HUGE_HISTORY_LIMIT      20000
+#define HUGE_HISTORY_LIMIT      999999999
 
 #endif /* CONSTANTS_H_ */
diff --git a/sflphone-common/test/history-sample b/sflphone-common/test/history-sample
deleted file mode 100644
index a6f39f4ed3..0000000000
--- a/sflphone-common/test/history-sample
+++ /dev/null
@@ -1,21 +0,0 @@
-[144562436]
-accountid=
-name=Savoir-faire Linux
-number=514-276-5468
-timestamp_stop=144562458
-type=0
-
-[747638685]
-accountid=Account:1239059899
-name=Emmanuel Milou
-number=136
-timestamp_stop=747638765
-type=2
-
-[775354456]
-accountid=Account:43789459478
-name=
-number=5143848557
-timestamp_stop=775354987
-type=1
-
diff --git a/sflphone-common/test/history-sample.tpl b/sflphone-common/test/history-sample.tpl
index 221e449538..a6f39f4ed3 100644
--- a/sflphone-common/test/history-sample.tpl
+++ b/sflphone-common/test/history-sample.tpl
@@ -1,20 +1,21 @@
 [144562436]
-number=514-276-5468
+accountid=
 name=Savoir-faire Linux
-type=0
+number=514-276-5468
 timestamp_stop=144562458
-accountid=
+type=0
 
 [747638685]
+accountid=Account:1239059899
 name=Emmanuel Milou
-timestamp_stop=747638765
 number=136
+timestamp_stop=747638765
 type=2
-accountid=Account:1239059899
 
 [775354456]
-number=5143848557
+accountid=Account:43789459478
 name=
+number=5143848557
 timestamp_stop=775354987
 type=1
-accountid=Account:43789459478
+
diff --git a/sflphone-common/test/historytest.h b/sflphone-common/test/historytest.h
index 84b1e7a5ec..fac450afdf 100644
--- a/sflphone-common/test/historytest.h
+++ b/sflphone-common/test/historytest.h
@@ -54,13 +54,13 @@ class HistoryTest : public CppUnit::TestCase {
      */
     CPPUNIT_TEST_SUITE (HistoryTest);
         CPPUNIT_TEST (test_create_history_path);
-        CPPUNIT_TEST (test_save_history_to_file);
         CPPUNIT_TEST (test_save_history_items_map);
         CPPUNIT_TEST (test_load_history_from_file);
         CPPUNIT_TEST (test_load_history_items_map);
         CPPUNIT_TEST (test_get_history_serialized);
         CPPUNIT_TEST (test_set_serialized_history);
         CPPUNIT_TEST (test_set_serialized_history_with_limit);
+	CPPUNIT_TEST (test_save_history_to_file);
     CPPUNIT_TEST_SUITE_END ();
 
     public:
diff --git a/sflphone-common/test/sequence.yml b/sflphone-common/test/sequence.yml
deleted file mode 100755
index 9cb54dd636..0000000000
--- a/sflphone-common/test/sequence.yml
+++ /dev/null
@@ -1,22 +0,0 @@
-accounts:
- - id:			1234
-   alias:   		sfl-181
-   username:		181   
-   password:  		sfl-181pw
-   hostname:  		sflphone.org
-   enable:		true
-   type:		sip
-
- - id:			2345
-   alias:		sfl-431
-   username:		431     
-   password:  		alexandre
-   hostname:		192.168.50.3
-   enable:		true
-   type:		sip
-
-
-
-
-
-
diff --git a/sflphone-common/test/sequence2.yml b/sflphone-common/test/ymlParser.yml
similarity index 100%
rename from sflphone-common/test/sequence2.yml
rename to sflphone-common/test/ymlParser.yml
-- 
GitLab