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