test: Changed ProjectSettingsTestSuite to SettingsTestSuite and extended it substantially
This commit is contained in:
+5
@@ -1,5 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<config>
|
||||
<Bool>1</Bool>
|
||||
<Int>42</Int>
|
||||
<Float>3.1416</Float>
|
||||
<String>Hello World!</String>
|
||||
|
||||
<SourcePath>data</SourcePath>
|
||||
</config>
|
||||
|
||||
@@ -3,6 +3,21 @@ Token.cpp ERROR: Location Id was not referenced by this Token.
|
||||
Node.cpp WARNING: Cannot change NodeType after it was already set from namespace to class
|
||||
Edge.cpp ERROR: Nodes are not plain copies.
|
||||
Graph.cpp ERROR: Can't remove member edge, without removing the child node.
|
||||
Settings.cpp WARNING: File for Settings not found.
|
||||
ConfigManager.cpp ERROR: value Bool is not present in config.
|
||||
ConfigManager.cpp ERROR: value Int is not present in config.
|
||||
ConfigManager.cpp ERROR: value Float is not present in config.
|
||||
ConfigManager.cpp ERROR: value String is not present in config.
|
||||
Settings.cpp WARNING: File for Settings not found.
|
||||
ConfigManager.cpp ERROR: value Bool is not present in config.
|
||||
ConfigManager.cpp ERROR: value Int is not present in config.
|
||||
ConfigManager.cpp ERROR: value Float is not present in config.
|
||||
ConfigManager.cpp ERROR: value String is not present in config.
|
||||
ConfigManager.cpp ERROR: value Bool is not present in config.
|
||||
ConfigManager.cpp ERROR: value Int is not present in config.
|
||||
ConfigManager.cpp ERROR: value Float is not present in config.
|
||||
ConfigManager.cpp ERROR: value String is not present in config.
|
||||
ConfigManager.cpp ERROR: value NewBool is not present in config.
|
||||
TextAccess.cpp WARNING: Index 'firstLine' has to be lower or equal index 'lastLine', is 3 > 2
|
||||
TextAccess.cpp WARNING: Tried to access index 10. Maximum index is 8
|
||||
TextAccess.cpp WARNING: Tried to access index 10. Maximum index is 8
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
Settings::Settings()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
Settings::~Settings()
|
||||
|
||||
@@ -16,6 +16,7 @@ public:
|
||||
void save(const std::string& filePath);
|
||||
void clear();
|
||||
|
||||
protected:
|
||||
template<typename T>
|
||||
T getValue(const std::string& key, T defaultValue) const;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ add_files(
|
||||
GraphTestSuite.h
|
||||
LogManagerTestSuite.h
|
||||
MessageQueueTestSuite.h
|
||||
ProjectSettingsTestSuite.h
|
||||
SettingsTestSuite.h
|
||||
TestSuiteFixture.cpp
|
||||
TestSuiteFixture.h
|
||||
TextAccessTestSuite.h
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include "ProjectSettings.h"
|
||||
|
||||
class ProjectSettingsTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void test_loading_projectSettings_from_file()
|
||||
{
|
||||
TS_ASSERT(ProjectSettings::getInstance()->load("data/ProjectSettingsTestSuite/settings.xml"));
|
||||
}
|
||||
|
||||
void test_load_sourcepath_from_file()
|
||||
{
|
||||
ProjectSettings::getInstance()->load("data/ProjectSettingsTestSuite/settings.xml");
|
||||
TS_ASSERT_EQUALS(ProjectSettings::getInstance()->getSourcePath(), "data");
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,175 @@
|
||||
#include <cxxtest/TestSuite.h>
|
||||
|
||||
#include "ProjectSettings.h"
|
||||
#include "Settings.h"
|
||||
|
||||
class SettingsTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void test_settings_get_loaded_from_file()
|
||||
{
|
||||
Settings settings;
|
||||
TS_ASSERT(settings.load("data/SettingsTestSuite/settings.xml"));
|
||||
}
|
||||
|
||||
void test_settings_get_not_loaded_from_file()
|
||||
{
|
||||
Settings settings;
|
||||
TS_ASSERT(!settings.load("data/SettingsTestSuite/wrong_settings.xml"));
|
||||
}
|
||||
|
||||
void test_settings_get_loaded_value()
|
||||
{
|
||||
TestSettings settings;
|
||||
TS_ASSERT(settings.load("data/SettingsTestSuite/settings.xml"));
|
||||
|
||||
TS_ASSERT_EQUALS(settings.getBool(), true);
|
||||
TS_ASSERT_EQUALS(settings.getInt(), 42);
|
||||
TS_ASSERT_EQUALS(settings.getFloat(), 3.1416f);
|
||||
TS_ASSERT_EQUALS(settings.getString(), "Hello World!");
|
||||
}
|
||||
|
||||
void test_settings_get_default_value_when_not_loaded()
|
||||
{
|
||||
TestSettings settings;
|
||||
TS_ASSERT_EQUALS(settings.getBool(), false);
|
||||
TS_ASSERT_EQUALS(settings.getInt(), -1);
|
||||
TS_ASSERT_EQUALS(settings.getFloat(), 0.01f);
|
||||
TS_ASSERT_EQUALS(settings.getString(), "<empty>");
|
||||
}
|
||||
|
||||
void test_settings_get_default_value_when_wrongly_loaded()
|
||||
{
|
||||
TestSettings settings;
|
||||
TS_ASSERT(!settings.load("data/SettingsTestSuite/wrong_settings.xml"));
|
||||
|
||||
TS_ASSERT_EQUALS(settings.getBool(), false);
|
||||
TS_ASSERT_EQUALS(settings.getInt(), -1);
|
||||
TS_ASSERT_EQUALS(settings.getFloat(), 0.01f);
|
||||
TS_ASSERT_EQUALS(settings.getString(), "<empty>");
|
||||
}
|
||||
|
||||
void test_settings_get_default_value_after_clearing()
|
||||
{
|
||||
TestSettings settings;
|
||||
TS_ASSERT(settings.load("data/SettingsTestSuite/settings.xml"));
|
||||
|
||||
settings.clear();
|
||||
TS_ASSERT_EQUALS(settings.getBool(), false);
|
||||
TS_ASSERT_EQUALS(settings.getInt(), -1);
|
||||
TS_ASSERT_EQUALS(settings.getFloat(), 0.01f);
|
||||
TS_ASSERT_EQUALS(settings.getString(), "<empty>");
|
||||
}
|
||||
|
||||
void test_settings_can_be_set_when_not_loaded()
|
||||
{
|
||||
TestSettings settings;
|
||||
|
||||
TS_ASSERT(settings.setBool(false));
|
||||
TS_ASSERT_EQUALS(settings.getBool(), false);
|
||||
|
||||
TS_ASSERT(settings.setInt(2));
|
||||
TS_ASSERT_EQUALS(settings.getInt(), 2);
|
||||
|
||||
TS_ASSERT(settings.setFloat(2.5f));
|
||||
TS_ASSERT_EQUALS(settings.getFloat(), 2.5f);
|
||||
|
||||
TS_ASSERT(settings.setString("foobar"));
|
||||
TS_ASSERT_EQUALS(settings.getString(), "foobar");
|
||||
}
|
||||
|
||||
void test_settings_can_be_replaced_when_loaded()
|
||||
{
|
||||
TestSettings settings;
|
||||
TS_ASSERT(settings.load("data/SettingsTestSuite/settings.xml"));
|
||||
|
||||
TS_ASSERT(settings.setBool(false));
|
||||
TS_ASSERT_EQUALS(settings.getBool(), false);
|
||||
|
||||
TS_ASSERT(settings.setInt(2));
|
||||
TS_ASSERT_EQUALS(settings.getInt(), 2);
|
||||
|
||||
TS_ASSERT(settings.setFloat(2.5f));
|
||||
TS_ASSERT_EQUALS(settings.getFloat(), 2.5f);
|
||||
|
||||
TS_ASSERT(settings.setString("foobar"));
|
||||
TS_ASSERT_EQUALS(settings.getString(), "foobar");
|
||||
}
|
||||
|
||||
void test_settings_can_be_added_when_loaded()
|
||||
{
|
||||
TestSettings settings;
|
||||
TS_ASSERT(settings.load("data/SettingsTestSuite/settings.xml"));
|
||||
|
||||
TS_ASSERT_EQUALS(settings.getNewBool(), false);
|
||||
TS_ASSERT(settings.setNewBool(true));
|
||||
TS_ASSERT_EQUALS(settings.getNewBool(), true);
|
||||
}
|
||||
|
||||
void test_load_project_settings_from_file()
|
||||
{
|
||||
TS_ASSERT(ProjectSettings::getInstance()->load("data/SettingsTestSuite/settings.xml"));
|
||||
}
|
||||
|
||||
void test_load_source_path_from_file()
|
||||
{
|
||||
ProjectSettings::getInstance()->load("data/SettingsTestSuite/settings.xml");
|
||||
TS_ASSERT_EQUALS(ProjectSettings::getInstance()->getSourcePath(), "data");
|
||||
}
|
||||
|
||||
private:
|
||||
class TestSettings
|
||||
: public Settings
|
||||
{
|
||||
public:
|
||||
bool getBool() const
|
||||
{
|
||||
return getValue<bool>("Bool", false);
|
||||
}
|
||||
|
||||
bool setBool(bool value)
|
||||
{
|
||||
return setValue<bool>("Bool", value);
|
||||
}
|
||||
|
||||
int getInt() const
|
||||
{
|
||||
return getValue<int>("Int", -1);
|
||||
}
|
||||
|
||||
bool setInt(int value)
|
||||
{
|
||||
return setValue<int>("Int", value);
|
||||
}
|
||||
|
||||
float getFloat() const
|
||||
{
|
||||
return getValue<float>("Float", 0.01f);
|
||||
}
|
||||
|
||||
bool setFloat(float value)
|
||||
{
|
||||
return setValue<float>("Float", value);
|
||||
}
|
||||
|
||||
std::string getString() const
|
||||
{
|
||||
return getValue<std::string>("String", "<empty>");
|
||||
}
|
||||
|
||||
bool setString(const std::string& value)
|
||||
{
|
||||
return setValue<std::string>("String", value);
|
||||
}
|
||||
|
||||
bool getNewBool() const
|
||||
{
|
||||
return getValue<bool>("NewBool", false);
|
||||
}
|
||||
|
||||
bool setNewBool(bool value)
|
||||
{
|
||||
return setValue<bool>("NewBool", value);
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user