This commit is contained in:
2020-06-10 10:59:19 +02:00
parent 61c3eaa1ff
commit ef25d9f1f0
9 changed files with 320 additions and 1 deletions
+2
View File
@@ -4,3 +4,5 @@
.*.swp .*.swp
.AppleDouble .AppleDouble
lib lib
test*
!test.cc
+1
View File
@@ -0,0 +1 @@
../../Logging
+4
View File
@@ -2,6 +2,10 @@
# Makefile.conf # Makefile.conf
# #
LFLAGS += -lLogging
LFLAGS += -L$(ROOTPATH)/Libraries/Logging/lib/$(ARCH)
CFLAGS += -I$(ROOTPATH)/Libraries/Logging/include
LFLAGS += -lUtilities LFLAGS += -lUtilities
LFLAGS += -L$(ROOTPATH)/lib/$(ARCH) LFLAGS += -L$(ROOTPATH)/lib/$(ARCH)
CFLAGS += -I$(ROOTPATH) -I$(ROOTPATH)/include CFLAGS += -I$(ROOTPATH) -I$(ROOTPATH)/include
+6 -1
View File
@@ -8,6 +8,11 @@ Utilities.a.$(ARCH) : $(OBJECTS)
Utilities.a: Utilities.a:
$(call build_target,$@) $(call build_target,$@)
test.$(ARCH): $(OBJECTS) Test/Test.o.$(ARCH) | Utilities.a.$(ARCH)
$(call build_target_arch,$@,$^)
test:
$(call build_target,$@)
.DEFAULT_GOAL := Utilities.a .DEFAULT_GOAL := Utilities.a
TARGETS += Utilities.a TARGETS += Utilities.a test
+1
View File
@@ -0,0 +1 @@
../Makefile
+140
View File
@@ -0,0 +1,140 @@
#include "Test.h"
#include "StringAlgorithm.h"
#include <Logging.h>
#include <string>
#include <sstream>
#include <vector>
namespace Utilities {
namespace Test {
bool TestSplitInstance(const std::string& subject, const char& delimiter, unsigned expectedSize)
{
std::stringstream ss;
std::vector<std::string> vector = StringAlgorithm::split(subject, delimiter);
ss << "Vector Size - " << vector.size() << std::endl;
for (auto& item : vector)
ss << item << std::endl;
Logging::Log(Logging::Severity::Info, ss.str());
if (vector.size() != expectedSize)
return false;
return true;
}
bool TestSplitInstance(const std::string& subject, const std::string& delimiters, unsigned expectedSize)
{
std::stringstream ss;
std::vector<std::string> vector = StringAlgorithm::split(subject, delimiters);
ss << "Vector Size - " << vector.size() << std::endl;
for (auto& item : vector)
ss << item << std::endl;
Logging::Log(Logging::Severity::Info, ss.str());
if (vector.size() != expectedSize)
return false;
return true;
}
bool TestSplit()
{
bool success = true;
std::string testString = "a/b/c/d";
success = success && TestSplitInstance(testString, '/', 4);
testString = "a/ /c/ e";
success = success && TestSplitInstance(testString, '/', 4);
testString = "a//c/";
success = success && TestSplitInstance(testString, '/', 4);
testString = "a/.b/";
success = success && TestSplitInstance(testString, "/.", 4);
return success;
}
bool TestIsNumeric()
{
std::stringstream ss;
ss << "\"Test\" != Numeric";
if (StringAlgorithm::is_numeric("Test"))
{
ss << " -> FAIL";
Logging::Log(Logging::Severity::Info, ss.str());
return false;
}
ss << std::endl << "\"1\" == Numeric";
if (!StringAlgorithm::is_numeric("1"))
{
ss << " -> FAIL";
Logging::Log(Logging::Severity::Info, ss.str());
return false;
}
ss << std::endl << "\"1.43\" == Numeric";
if (!StringAlgorithm::is_numeric("1.43"))
{
ss << " -> FAIL";
Logging::Log(Logging::Severity::Info, ss.str());
return false;
}
ss << std::endl << "\"0\" == Numeric";
if (!StringAlgorithm::is_numeric("0"))
{
ss << " -> FAIL";
Logging::Log(Logging::Severity::Info, ss.str());
return false;
}
ss << std::endl << "\"034dfj\" != Numeric";
if (StringAlgorithm::is_numeric("034dfj"))
{
ss << " -> FAIL";
Logging::Log(Logging::Severity::Info, ss.str());
return false;
}
ss << std::endl << "\"dfj354\" != Numeric";
if (StringAlgorithm::is_numeric("dfj354"))
{
ss << " -> FAIL";
Logging::Log(Logging::Severity::Info, ss.str());
return false;
}
Logging::Log(Logging::Severity::Info, ss.str());
return true;
}
bool TestStringAlgorithm()
{
std::stringstream ss;
ss << "----------------------------------" << std::endl;
ss << "| TestStringAlgorithm |" << std::endl;
ss << "----------------------------------" << std::endl;
Logging::Log(Logging::Severity::Info, ss.str());
bool success = TestSplit();
ss.str("");
ss << "----------------------------------" << std::endl;
Logging::Log(Logging::Severity::Info, ss.str());
success = TestIsNumeric() && success;
ss.str("");
ss << "==================================" << std::endl << std::endl;
Logging::Log(Logging::Severity::Info, ss.str());
return success;
}
} // namespace Test
} // namespace Utilities
+25
View File
@@ -0,0 +1,25 @@
#include "Test.h"
#include <Logging.h>
int main(int /*argc*/, char** /*argv*/)
{
Logging::OpenLog();
Logging::SetLogMask(Logging::Severity::Info);
if (
Utilities::Test::TestStringAlgorithm() &&
Utilities::Test::TestTribool()
)
{
Logging::Log(Logging::Severity::Info, "Pass");
Logging::CloseLog();
return 0;
}
Logging::Log(Logging::Severity::Info, "Error");
Logging::CloseLog();
return -1;
}
+8
View File
@@ -0,0 +1,8 @@
namespace Utilities {
namespace Test {
bool TestStringAlgorithm();
bool TestTribool();
} // namespace Test
} // namespace Utilities
+133
View File
@@ -0,0 +1,133 @@
#include "Test.h"
#include "Tribool.h"
#include <Logging.h>
#include <ios>
#include <sstream>
namespace Utilities {
namespace Test {
void TestUtilTribool()
{
Tribool::Tribool x;
std::stringstream ss;
std::ostringstream out;
ss.str("");
out.str(std::string());
x = false;
out << x;
ss << "Output false (noboolalpha): " << out.str() << std::endl;
Logging::Log(Logging::Severity::Info, ss.str());
ss.str("");
out.str(std::string());
x = true;
out << x;
ss << "Output true (noboolalpha): " << out.str() << std::endl;
Logging::Log(Logging::Severity::Info, ss.str());
ss.str("");
out.str(std::string());
x = Tribool::Tribool::Indeterminate;
out << x;
ss << "Output indeterminate (noboolalpha): " << out.str() << std::endl;
Logging::Log(Logging::Severity::Info, ss.str());
ss.str("");
out.str(std::string());
out << Tribool::Tribool::Indeterminate;
ss << "Output indeterminate (noboolalpha): " << out.str() << std::endl;
Logging::Log(Logging::Severity::Info, ss.str());
ss.str("");
out.str(std::string());
x = false;
out << std::boolalpha << x;
ss << "Output false (boolalpha): " << out.str() << std::endl;
Logging::Log(Logging::Severity::Info, ss.str());
ss.str("");
out.str(std::string());
x = true;
out << std::boolalpha << x;
ss << "Output true (boolalpha): " << out.str() << std::endl;
Logging::Log(Logging::Severity::Info, ss.str());
ss.str("");
out.str(std::string());
x = Tribool::Tribool::Indeterminate;
out << std::boolalpha << x;
ss << "Output indeterminate (boolalpha - default name): " << out.str() << std::endl;
Logging::Log(Logging::Severity::Info, ss.str());
ss.str("");
out.str(std::string());
out << std::boolalpha << Tribool::Tribool::Indeterminate;
ss << "Output indeterminate (boolalpha - default name): " << out.str() << std::endl;
Logging::Log(Logging::Severity::Info, ss.str());
ss.str("");
ss << "----------------------------------" << std::endl;
Logging::Log(Logging::Severity::Info, ss.str());
ss.str("");
Tribool::Tribool b;
ss << "Tribool::Tribool b = " << std::boolalpha << b << std::endl;
Logging::Log(Logging::Severity::Info, ss.str());
b = true;
b = false;
b = Tribool::Tribool::Indeterminate;
ss.str("");
if (b)
ss << "indeterminate = true" << std::endl;
else if (!b)
ss << "indeterminate = false" << std::endl;
else
ss << "indeterminate = indeterminate" << std::endl;
Logging::Log(Logging::Severity::Info, ss.str());
ss.setf(std::ios::boolalpha);
ss.str("");
Tribool::Tribool b1 = true;
ss << "true || indeterminate = " << (b1 || Tribool::Tribool::Indeterminate) << std::endl;
ss << "true && indeterminate = " << (b1 && Tribool::Tribool::Indeterminate) << std::endl;
Logging::Log(Logging::Severity::Info, ss.str());
ss.str("");
Tribool::Tribool b2 = false;
ss << "false || indeterminate = " << (b2 || Tribool::Tribool::Indeterminate) << std::endl;
ss << "false && indeterminate = " << (b2 && Tribool::Tribool::Indeterminate) << std::endl;
Logging::Log(Logging::Severity::Info, ss.str());
ss.str("");
Tribool::Tribool b3 = Tribool::Tribool::Indeterminate;
ss << "indeterminate || indeterminate = " << (b3 || b3) << std::endl;
ss << "indeterminate && indeterminate = " << (b3 && b3) << std::endl;
Logging::Log(Logging::Severity::Info, ss.str());
}
bool TestTribool()
{
std::stringstream ss;
ss << "----------------------------------" << std::endl;
ss << "| Test::Tribool |" << std::endl;
ss << "----------------------------------" << std::endl;
Logging::Log(Logging::Severity::Info, ss.str());
TestUtilTribool();
ss.str("");
ss << "==================================" << std::endl << std::endl;
Logging::Log(Logging::Severity::Info, ss.str());
return true;
}
} // namespace Test
} // namespace Utilities