JDierkse 5 rokov pred
rodič
commit
ef25d9f1f0
9 zmenil súbory, kde vykonal 320 pridanie a 1 odobranie
  1. 2 0
      .gitignore
  2. 1 0
      Libraries/Logging
  3. 4 0
      Makefile.conf
  4. 6 1
      Makefile.target
  5. 1 0
      Test/Makefile
  6. 140 0
      Test/StringAlgorithm.cpp
  7. 25 0
      Test/Test.cc
  8. 8 0
      Test/Test.h
  9. 133 0
      Test/Tribool.cpp

+ 2 - 0
.gitignore

@@ -4,3 +4,5 @@
 .*.swp
 .AppleDouble
 lib
+test*
+!test.cc

+ 1 - 0
Libraries/Logging

@@ -0,0 +1 @@
+../../Logging

+ 4 - 0
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

+ 6 - 1
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

+ 1 - 0
Test/Makefile

@@ -0,0 +1 @@
+../Makefile

+ 140 - 0
Test/StringAlgorithm.cpp

@@ -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 - 0
Test/Test.cc

@@ -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 - 0
Test/Test.h

@@ -0,0 +1,8 @@
+namespace Utilities {
+namespace Test {
+
+bool TestStringAlgorithm();
+bool TestTribool();
+
+} // namespace Test
+} // namespace Utilities

+ 133 - 0
Test/Tribool.cpp

@@ -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