diff --git a/.gitignore b/.gitignore index 851ef09..0b9ff8b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ .*.swp .AppleDouble lib +test* +!test.cc diff --git a/Libraries/Logging b/Libraries/Logging new file mode 120000 index 0000000..e18bda1 --- /dev/null +++ b/Libraries/Logging @@ -0,0 +1 @@ +../../Logging \ No newline at end of file diff --git a/Makefile.conf b/Makefile.conf index 3030ffb..a82a2ac 100644 --- a/Makefile.conf +++ b/Makefile.conf @@ -2,6 +2,10 @@ # Makefile.conf # +LFLAGS += -lLogging +LFLAGS += -L$(ROOTPATH)/Libraries/Logging/lib/$(ARCH) +CFLAGS += -I$(ROOTPATH)/Libraries/Logging/include + LFLAGS += -lUtilities LFLAGS += -L$(ROOTPATH)/lib/$(ARCH) CFLAGS += -I$(ROOTPATH) -I$(ROOTPATH)/include diff --git a/Makefile.target b/Makefile.target index 45baf98..688ae80 100644 --- a/Makefile.target +++ b/Makefile.target @@ -8,6 +8,11 @@ Utilities.a.$(ARCH) : $(OBJECTS) Utilities.a: $(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 -TARGETS += Utilities.a +TARGETS += Utilities.a test diff --git a/Test/Makefile b/Test/Makefile new file mode 120000 index 0000000..d0b0e8e --- /dev/null +++ b/Test/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/Test/StringAlgorithm.cpp b/Test/StringAlgorithm.cpp new file mode 100644 index 0000000..d290329 --- /dev/null +++ b/Test/StringAlgorithm.cpp @@ -0,0 +1,140 @@ +#include "Test.h" +#include "StringAlgorithm.h" +#include +#include +#include +#include + + +namespace Utilities { +namespace Test { + +bool TestSplitInstance(const std::string& subject, const char& delimiter, unsigned expectedSize) +{ + std::stringstream ss; + std::vector 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 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 diff --git a/Test/Test.cc b/Test/Test.cc new file mode 100644 index 0000000..89237f1 --- /dev/null +++ b/Test/Test.cc @@ -0,0 +1,25 @@ +#include "Test.h" +#include + + +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; +} diff --git a/Test/Test.h b/Test/Test.h new file mode 100644 index 0000000..6a87f6d --- /dev/null +++ b/Test/Test.h @@ -0,0 +1,8 @@ +namespace Utilities { +namespace Test { + +bool TestStringAlgorithm(); +bool TestTribool(); + +} // namespace Test +} // namespace Utilities diff --git a/Test/Tribool.cpp b/Test/Tribool.cpp new file mode 100644 index 0000000..d6c3a65 --- /dev/null +++ b/Test/Tribool.cpp @@ -0,0 +1,133 @@ +#include "Test.h" +#include "Tribool.h" +#include +#include +#include + + +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