Skip to content
Snippets Groups Projects
Commit 1b2dfdeb authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #7264: fixed history tests, simplified history path initialization

parent 68630206
Branches
Tags
No related merge requests found
...@@ -59,7 +59,7 @@ History::History() : ...@@ -59,7 +59,7 @@ History::History() :
void History::load(int limit) void History::load(int limit)
{ {
createPath(); ensurePath();
std::ifstream infile(path_.c_str()); std::ifstream infile(path_.c_str());
if (!infile) { if (!infile) {
DEBUG("No history file to load"); DEBUG("No history file to load");
...@@ -91,9 +91,9 @@ void History::addNewEntry(const HistoryItem &item, int oldest) ...@@ -91,9 +91,9 @@ void History::addNewEntry(const HistoryItem &item, int oldest)
items_.push_back(item); items_.push_back(item);
} }
void History::createPath(const std::string &path) void History::ensurePath()
{ {
if (path.empty()) { if (path_.empty()) {
string xdg_data = string(HOMEDIR) + DIR_SEPARATOR_STR + ".local/share/sflphone"; string xdg_data = string(HOMEDIR) + DIR_SEPARATOR_STR + ".local/share/sflphone";
string userdata; string userdata;
...@@ -114,8 +114,7 @@ void History::createPath(const std::string &path) ...@@ -114,8 +114,7 @@ void History::createPath(const std::string &path)
} }
// Load user's history // Load user's history
path_ = userdata + DIR_SEPARATOR_STR + "history"; path_ = userdata + DIR_SEPARATOR_STR + "history";
} else }
path_ = path;
} }
......
...@@ -79,7 +79,7 @@ class History { ...@@ -79,7 +79,7 @@ class History {
private: private:
void setPath(const std::string &path); void setPath(const std::string &path);
void createPath(const std::string &path = ""); void ensurePath();
/* /*
* Add a new history item in the data structure * Add a new history item in the data structure
*/ */
......
...@@ -31,11 +31,9 @@ ...@@ -31,11 +31,9 @@
#ifndef CONSTANTS_H_ #ifndef CONSTANTS_H_
#define CONSTANTS_H_ #define CONSTANTS_H_
#define YES_STR "1"
#define NO_STR "0"
#define HISTORY_SAMPLE "history-sample.tpl" #define HISTORY_SAMPLE "history-sample.tpl"
#define HISTORY_SAMPLE_SIZE 3 #define HISTORY_SAMPLE_SIZE 3
#define CONFIG_SAMPLE "sflphoned-sample.yml" #define CONFIG_SAMPLE "sflphoned-sample.yml"
#define HUGE_HISTORY_LIMIT 999999999 #define HISTORY_LIMIT 30
#endif /* CONSTANTS_H_ */ #endif /* CONSTANTS_H_ */
accountid= accountid=
confid= confid=
id=Account:1239059899 callid=Account:1239059899
name=Emmanuel Milou peer_name=Emmanuel Milou
number=136 peer_number=136
recordfile= recordfile=
timestamp_start=747638685 timestamp_start=747638685
timestamp_stop=747638765 timestamp_stop=747638765
...@@ -10,9 +10,9 @@ state=outgoing ...@@ -10,9 +10,9 @@ state=outgoing
accountid=empty accountid=empty
confid= confid=
id= callid=
name=Savoir-faire Linux peer_name=Savoir-faire Linux
number=514-276-5468 peer_number=514-276-5468
recordfile= recordfile=
timestamp_start=144562000 timestamp_start=144562000
timestamp_stop=144562458 timestamp_stop=144562458
...@@ -20,9 +20,9 @@ state=missed ...@@ -20,9 +20,9 @@ state=missed
accountid= accountid=
confid= confid=
id=Account:43789459478 callid=Account:43789459478
name= peer_name=
number=5143848557 peer_number=5143848557
recordfile= recordfile=
timestamp_start=775354456 timestamp_start=775354456
timestamp_stop=775354987 timestamp_stop=775354987
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
#include <cstdlib> #include <cstdlib>
#include "historytest.h" #include "historytest.h"
#include "manager.h" #include "logger.h"
#include "constants.h" #include "constants.h"
#include "validator.h" #include "validator.h"
...@@ -57,17 +57,16 @@ void backup() ...@@ -57,17 +57,16 @@ void backup()
void HistoryTest::setUp() void HistoryTest::setUp()
{ {
backup(); backup();
history_ = new History(); history_ = new History;
history_->setPath(HISTORY_SAMPLE);
} }
void HistoryTest::test_create_path() void HistoryTest::test_create_path()
{ {
DEBUG("-------------------- HistoryTest::test_create_path --------------------\n"); DEBUG("-------------------- HistoryTest::test_set_path --------------------\n");
std::string path(HISTORY_SAMPLE); std::string path(HISTORY_SAMPLE);
history_->createPath(path);
CPPUNIT_ASSERT(!history_->isLoaded()); CPPUNIT_ASSERT(!history_->isLoaded());
CPPUNIT_ASSERT(history_->path_ == path); CPPUNIT_ASSERT(history_->path_ == path);
} }
...@@ -76,40 +75,30 @@ void HistoryTest::test_load_from_file() ...@@ -76,40 +75,30 @@ void HistoryTest::test_load_from_file()
{ {
DEBUG("-------------------- HistoryTest::test_load_from_file --------------------\n"); DEBUG("-------------------- HistoryTest::test_load_from_file --------------------\n");
history_->createPath(HISTORY_SAMPLE); history_->load(HISTORY_LIMIT);
history_->load(HUGE_HISTORY_LIMIT);
CPPUNIT_ASSERT(history_->isLoaded()); CPPUNIT_ASSERT(history_->isLoaded());
} }
void HistoryTest::test_load_items() void HistoryTest::test_load_items()
{ {
DEBUG("-------------------- HistoryTest::test_load_items_map --------------------\n"); DEBUG("-------------------- HistoryTest::test_load_items --------------------\n");
history_->load(HISTORY_LIMIT);
history_->setPath(HISTORY_SAMPLE); CPPUNIT_ASSERT(history_->isLoaded());
history_->load(HUGE_HISTORY_LIMIT);
CPPUNIT_ASSERT(history_->numberOfItems() == HISTORY_SAMPLE_SIZE); CPPUNIT_ASSERT(history_->numberOfItems() == HISTORY_SAMPLE_SIZE);
} }
void HistoryTest::test_save_to_file() void HistoryTest::test_save_to_file()
{ {
DEBUG("-------------------- HistoryTest::test_save_to_file --------------------\n"); DEBUG("-------------------- HistoryTest::test_save_to_file --------------------\n");
std::map<std::string, std::string> res;
std::map<std::string, std::string>::iterator iter;
history_->setPath(HISTORY_SAMPLE);
CPPUNIT_ASSERT(history_->save()); CPPUNIT_ASSERT(history_->save());
} }
void HistoryTest::test_get_serialized() void HistoryTest::test_get_serialized()
{ {
DEBUG("-------------------- HistoryTest::test_get_serialized --------------------\n"); DEBUG("-------------------- HistoryTest::test_get_serialized --------------------\n");
history_->load(HISTORY_LIMIT);
std::vector<std::string>::iterator iter; CPPUNIT_ASSERT(history_->isLoaded());
std::string tmp;
history_->load(HUGE_HISTORY_LIMIT);
CPPUNIT_ASSERT(history_->getSerialized().size() == HISTORY_SAMPLE_SIZE); CPPUNIT_ASSERT(history_->getSerialized().size() == HISTORY_SAMPLE_SIZE);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment