From ad279f5dac75f98a3f00e5efb3ea4fd424ef0668 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Mon, 14 Jul 2014 20:14:42 +0200
Subject: [PATCH] empty alib2algo library

---
 alib2algo/makefile          | 131 ++++++++++++++++++++++++++++++++++++
 alib2algo/test-src/main.cpp | 120 +++++++++++++++++++++++++++++++++
 2 files changed, 251 insertions(+)
 create mode 100644 alib2algo/makefile
 create mode 100644 alib2algo/test-src/main.cpp

diff --git a/alib2algo/makefile b/alib2algo/makefile
new file mode 100644
index 0000000000..5a76aa4a43
--- /dev/null
+++ b/alib2algo/makefile
@@ -0,0 +1,131 @@
+SHELL:=/bin/bash
+LIBRARY:=libalib2algo.so 
+TESTBIN:=alib2test
+
+LDFLAGS:= -L../alib2data/lib -rdynamic -shared -lalib2data
+TEST_LDFLAGS:= -L../alib2data/lib -L../alib2algo/lib -rdynamic -lalib2data -lalib2algo -lcppunit -Wl,-rpath,.
+
+OBJECTS:=$(patsubst src/%.cpp, obj/%.o, $(shell find src/ -name *cpp))
+TEST_OBJECTS:=$(patsubst test-src/%.cpp, test-obj/%.o, $(shell find test-src/ -name *cpp))
+
+.PHONY: all build test clean
+
+all: build test
+
+
+
+lib/$(LIBRARY): obj/ $(OBJECTS)
+	mkdir -p lib
+	$(CXX) $(OBJECTS) -o $@ $(LDFLAGS)
+
+obj/makefile: makefile
+	mkdir -p $(dir $@)
+	echo "SHELL:=/bin/bash" > $@
+	echo "SRCDIR:=" >> $@
+	echo "DEPTH:=" >> $@
+	echo "" >> $@
+	echo "CXXFLAGS:= -std=c++11 -O0 -g -c -Wall -pedantic -Wextra -fPIC -I../../alib2data/src/" >> $@
+	echo "" >> $@
+	echo "SOURCES:= \$$(shell find ../\$$(DEPTH)src/\$$(SRCDIR) -maxdepth 1 -type f -name \"*.cpp\")" >> $@
+	echo "DEPENDENCIES:= \$$(patsubst ../\$$(DEPTH)src/\$$(SRCDIR)%.cpp, ../\$$(DEPTH)obj/\$$(SRCDIR)%.d, \$$(SOURCES))" >> $@
+	echo "OBJECTS:= \$$(patsubst %.d, %.o, \$$(DEPENDENCIES))" >> $@
+	echo "SOURCES_DIRS:= \$$(shell find ../\$$(DEPTH)src/\$$(SRCDIR) -maxdepth 1 -mindepth 1 -type d)" >> $@
+	echo "OBJECTS_DIRS:= \$$(patsubst ../\$$(DEPTH)src/\$$(SRCDIR)%, %/, \$$(SOURCES_DIRS))" >> $@
+	echo "OBJECTS_DIRS_MAKEFILES:= \$$(patsubst %, %makefile, \$$(OBJECTS_DIRS))" >> $@
+	echo "" >> $@
+	echo ".PHONY: all" >> $@
+	echo ".PRECIOUS: \$$(DEPENDECIES) \$$(OBJECTS_DIRS_MAKEFILES)" >> $@
+	echo "" >> $@
+	echo "all: \$$(OBJECTS_DIRS) \$$(OBJECTS)" >> $@
+	echo "" >> $@
+	echo "%.d:" >> $@
+	echo "	@echo \"\$$(shell sha1sum <<< \"\$$@\" | sed \"s/  -//g\") = \\$$\$$(shell (\\$$\$$(CXX) -MM \\$$\$$(CXXFLAGS) \$$(patsubst ../\$$(DEPTH)obj/\$$(SRCDIR)%.d,../\$$(DEPTH)src/\$$(SRCDIR)%.cpp, \$$@) 2>/dev/null || echo \\\"\$$(patsubst ../\$$(DEPTH)obj/\$$(SRCDIR)%.d,../\$$(DEPTH)src/\$$(SRCDIR)%.cpp, \$$@) FORCE\\\") | sed \\\"s/.*://g;s/\\\\\\\\\\\\\\\\//g\\\")\" > \$$@" >> $@
+	echo "	@echo \"\$$(patsubst %.d,%.o, \$$@): \\$$\$$(\$$(shell sha1sum <<< \"\$$@\" | sed \"s/  -//g\"))\" >> \$$@" >> $@
+	echo "	@echo \"	\\$$\$$(CXX) \\$$\$$(CXXFLAGS) \\$$\$$< -o \$$(patsubst %.d,%.o, \$$@)\" >> \$$@" >> $@
+	echo "" >> $@
+	echo "%/makefile: makefile" >> $@
+	echo "	mkdir -p \$$(dir \$$@)" >> $@
+	echo "	cp makefile \$$@" >> $@
+	echo "" >> $@
+	echo "%/: FORCE | %/makefile" >> $@
+	echo "	@accesstime=\`stat -c %Y \$$@\` && \\" >> $@
+	echo "	\$$(MAKE) -C \$$@ SRCDIR=\$$(SRCDIR)\$$(notdir \$$(patsubst %/, %, \$$@))/ DEPTH=\$$(DEPTH)../ && \\" >> $@
+	echo "	accesstime2=\`stat -c %Y \$$@\` && \\" >> $@
+	echo "	if [ "\$$\$$accesstime" -ne "\$$\$$accesstime2" ]; then \\" >> $@
+	echo "		touch .; \\" >> $@
+	echo "	fi" >> $@
+	echo "" >> $@
+	echo "FORCE:" >> $@
+	echo "" >> $@
+	echo "-include \$$(DEPENDENCIES)" >> $@
+
+obj/: FORCE | obj/makefile
+	$(MAKE) -C $@
+
+$(OBJECTS): obj/
+
+
+build: lib/$(LIBRARY)
+
+
+
+test-bin/$(TESTBIN): test-obj/ lib/$(LIBRARY) $(TEST_OBJECTS)
+	mkdir -p test-bin
+	$(CXX) $(TEST_OBJECTS) -o $@ $(TEST_LDFLAGS)
+
+test-obj/makefile: makefile
+	mkdir -p $(dir $@)
+	echo "SHELL:=/bin/bash" > $@
+	echo "SRCDIR:=" >> $@
+	echo "DEPTH:=" >> $@
+	echo "" >> $@
+	echo "CXXFLAGS:= -std=c++11 -O0 -g -c -Wall -pedantic -Wextra -I../\$$(DEPTH)src/ -I../../alib2data/src" >> $@
+	echo "" >> $@
+	echo "SOURCES:= \$$(shell find ../\$$(DEPTH)test-src/\$$(SRCDIR) -maxdepth 1 -type f -name \"*.cpp\")" >> $@
+	echo "DEPENDENCIES:= \$$(patsubst ../\$$(DEPTH)test-src/\$$(SRCDIR)%.cpp, ../\$$(DEPTH)test-obj/\$$(SRCDIR)%.d, \$$(SOURCES))" >> $@
+	echo "OBJECTS:= \$$(patsubst %.d, %.o, \$$(DEPENDENCIES))" >> $@
+	echo "SOURCES_DIRS:= \$$(shell find ../\$$(DEPTH)test-src/\$$(SRCDIR) -maxdepth 1 -mindepth 1 -type d)" >> $@
+	echo "OBJECTS_DIRS:= \$$(patsubst ../\$$(DEPTH)test-src/\$$(SRCDIR)%, %/, \$$(SOURCES_DIRS))" >> $@
+	echo "OBJECTS_DIRS_MAKEFILES:= \$$(patsubst %, %makefile, \$$(OBJECTS_DIRS))" >> $@
+	echo "" >> $@
+	echo ".PHONY: all" >> $@
+	echo ".PRECIOUS: \$$(DEPENDECIES) \$$(OBJECTS_DIRS_MAKEFILES)" >> $@
+	echo "" >> $@
+	echo "all: \$$(OBJECTS_DIRS) \$$(OBJECTS)" >> $@
+	echo "" >> $@
+	echo "%.d:" >> $@
+	echo "	@echo \"\$$(shell sha1sum <<< \"\$$@\" | sed \"s/  -//g\") = \\$$\$$(shell (\\$$\$$(CXX) -MM \\$$\$$(CXXFLAGS) \$$(patsubst ../\$$(DEPTH)test-obj/\$$(SRCDIR)%.d,../\$$(DEPTH)test-src/\$$(SRCDIR)%.cpp, \$$@) 2>/dev/null || echo \\\"\$$(patsubst ../\$$(DEPTH)test-obj/\$$(SRCDIR)%.d,../\$$(DEPTH)test-src/\$$(SRCDIR)%.cpp, \$$@) FORCE\\\") | sed \\\"s/.*://g;s/\\\\\\\\\\\\\\\\//g\\\")\" > \$$@" >> $@
+	echo "	@echo \"\$$(patsubst %.d,%.o, \$$@): \\$$\$$(\$$(shell sha1sum <<< \"\$$@\" | sed \"s/  -//g\"))\" >> \$$@" >> $@
+	echo "	@echo \"	\\$$\$$(CXX) \\$$\$$(CXXFLAGS) \\$$\$$< -o \$$(patsubst %.d,%.o, \$$@)\" >> \$$@" >> $@
+	echo "" >> $@
+	echo "%/makefile: makefile" >> $@
+	echo "	mkdir -p \$$(dir \$$@)" >> $@
+	echo "	cp makefile \$$@" >> $@
+	echo "" >> $@
+	echo "%/: FORCE | %/makefile" >> $@
+	echo "	@accesstime=\`stat -c %Y \$$@\` && \\" >> $@
+	echo "	\$$(MAKE) -C \$$@ SRCDIR=\$$(SRCDIR)\$$(notdir \$$(patsubst %/, %, \$$@))/ DEPTH=\$$(DEPTH)../ && \\" >> $@
+	echo "	accesstime2=\`stat -c %Y \$$@\` && \\" >> $@
+	echo "	if [ "\$$\$$accesstime" -ne "\$$\$$accesstime2" ]; then \\" >> $@
+	echo "		touch .; \\" >> $@
+	echo "	fi" >> $@
+	echo "" >> $@
+	echo "FORCE:" >> $@
+	echo "" >> $@
+	echo "-include \$$(DEPENDENCIES)" >> $@
+
+test-obj/: FORCE | test-obj/makefile
+	$(MAKE) -C $@
+
+$(TEST_OBJECTS): test-obj/
+
+test: test-bin/$(TESTBIN)
+	LD_LIBRARY_PATH="lib;../alib2data/lib" test-bin/$(TESTBIN)
+
+
+
+clean:
+	$(RM) -r *.o *.d lib obj test-bin test-obj
+
+FORCE:
+
diff --git a/alib2algo/test-src/main.cpp b/alib2algo/test-src/main.cpp
new file mode 100644
index 0000000000..1b3e032257
--- /dev/null
+++ b/alib2algo/test-src/main.cpp
@@ -0,0 +1,120 @@
+//#include "stdafx.h"
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/TestResultCollector.h>
+#include <cppunit/TestResult.h>
+
+#include <cppunit/Test.h>
+#include <cppunit/TestFailure.h>
+#include <cppunit/portability/Stream.h>
+#include <cppunit/TestListener.h>
+#include <cppunit/SourceLine.h>
+#include <cppunit/Exception.h>
+
+CPPUNIT_NS_BEGIN
+
+class CPPUNIT_API TestProgressListener : public TestListener
+{
+public:
+  TestProgressListener();
+
+  virtual ~TestProgressListener();
+
+  void startTest( Test *test );
+
+  void addFailure( const TestFailure &failure );
+
+  void endTest( Test *test );
+
+  int getResult() const;
+
+  void printResults() const;
+
+private:
+  TestProgressListener( const TestProgressListener &copy );
+
+  void operator =( const TestProgressListener &copy );
+
+private:
+  int m_Failures;
+  int m_Tests;
+  int m_Assertions;
+  bool m_lastTestFailed;
+};
+
+TestProgressListener::TestProgressListener() : m_Failures( 0 ), m_Tests(0), m_Assertions(0), m_lastTestFailed( false )
+{
+}
+
+TestProgressListener::~TestProgressListener()
+{
+}
+
+void TestProgressListener::startTest( Test * test )
+{
+	stdCOut() << test->getName() << ":" << "\n";
+	stdCOut().flush();
+
+	m_lastTestFailed = false;
+	m_Tests++;
+}
+
+void TestProgressListener::addFailure( const TestFailure &failure )
+{
+	stdCOut() << (failure.isError() ? "error" : "assertion") << " : " << failure.failedTestName() << " : " << failure.sourceLine().lineNumber() << "\n";
+	stdCOut() << "Exception " << failure.thrownException()->message().details();
+
+	m_lastTestFailed = true;
+	if(failure.isError()) m_Failures++; else m_Assertions++;
+}
+
+void TestProgressListener::endTest( Test * test)
+{
+	stdCOut() << "Result (" << test->getName() << ")";
+	stdCOut().flush();
+
+	if ( !m_lastTestFailed )
+		stdCOut() <<  " : OK";
+	else
+		stdCOut() << " : Fail";
+	stdCOut() << "\n\n";
+}
+
+int TestProgressListener::getResult() const {
+	return m_Failures + m_Assertions;
+}
+
+void TestProgressListener::printResults() const {
+	stdCOut() << "Overal result: Tests: " << m_Tests << " Assertions: " << m_Assertions << " Failures: " << m_Failures << "\n";
+}
+
+CPPUNIT_NS_END
+
+int main(int , char*[])
+{
+  CppUnit::TestResult controller;
+
+  CppUnit::TestResultCollector result;
+  controller.addListener( &result );
+
+  CppUnit::TestProgressListener progressListener;
+  controller.addListener( &progressListener );
+
+  // Get the top level suite from the registry
+  CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
+
+  // Adds the test to the list of test to run
+  CppUnit::TextUi::TestRunner runner;
+  runner.addTest( suite );
+
+  // Change the default outputter to a compiler error format outputter
+  runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
+                                                       std::cerr ) );
+  // Run the tests.
+  runner.run( controller );
+
+  progressListener.printResults();
+
+  return progressListener.getResult();
+}
-- 
GitLab