diff --git a/alib2algo/makefile.conf b/alib2algo/makefile.conf index c540021aa628f8263cf1a1dbe0959c4aae2a621d..ca3e031071740e8d4426ac28204af726fe8fde31 100644 --- a/alib2algo/makefile.conf +++ b/alib2algo/makefile.conf @@ -1,5 +1,5 @@ LIBRARY:=alib2algo TESTBIN:=alib2test -LINK_PATHS=../alib2str/ ../alib2data_experimental/ ../alib2data/ ../alib2common/ ../alib2std/ -LINK_LIBRARIES=alib2str alib2data_experimental alib2data alib2common alib2std xml2 -INCLUDE_PATHS=\$$(SOURCES_BASE_DIR)/../../alib2str/src/ \$$(SOURCES_BASE_DIR)/../../alib2data_experimental/src/ \$$(SOURCES_BASE_DIR)/../../alib2data/src/ \$$(SOURCES_BASE_DIR)/../../alib2common/src/ \$$(SOURCES_BASE_DIR)/../../alib2std/src/ /usr/include/libxml2/ +LINK_PATHS=../alib2str/ ../alib2data/ ../alib2common/ ../alib2std/ +LINK_LIBRARIES=alib2str alib2data alib2common alib2std xml2 +INCLUDE_PATHS=\$$(SOURCES_BASE_DIR)/../../alib2str/src/ \$$(SOURCES_BASE_DIR)/../../alib2data/src/ \$$(SOURCES_BASE_DIR)/../../alib2common/src/ \$$(SOURCES_BASE_DIR)/../../alib2std/src/ /usr/include/libxml2/ diff --git a/alib2algo_experimental/makefile.conf b/alib2algo_experimental/makefile.conf index d20b57d260583948d475a9f975d6f7525c90bf15..614b42fe268b1bddd23687cf9029bf2d299f98e6 100644 --- a/alib2algo_experimental/makefile.conf +++ b/alib2algo_experimental/makefile.conf @@ -1,5 +1,5 @@ LIBRARY:=alib2algo_experimental TESTBIN:=alib2test -LINK_PATHS=../alib2algo/ ../alib2str/ ../alib2data_experimental/ ../alib2data/ ../alib2common/ ../alib2std/ -LINK_LIBRARIES=alib2algo alib2str alib2data_experimental alib2data alib2common alib2std xml2 -INCLUDE_PATHS=\$$(SOURCES_BASE_DIR)/../../alib2algo/src/ \$$(SOURCES_BASE_DIR)/../../alib2str/src/ \$$(SOURCES_BASE_DIR)/../../alib2data_experimental/src/ \$$(SOURCES_BASE_DIR)/../../alib2data/src/ \$$(SOURCES_BASE_DIR)/../../alib2common/src/ \$$(SOURCES_BASE_DIR)/../../alib2std/src/ /usr/include/libxml2/ +LINK_PATHS=../alib2algo/ ../alib2str_experimental/ ../alib2str/ ../alib2data_experimental/ ../alib2data/ ../alib2common/ ../alib2std/ +LINK_LIBRARIES=alib2algo alib2str_experimental alib2str alib2data_experimental alib2data alib2common alib2std xml2 +INCLUDE_PATHS=\$$(SOURCES_BASE_DIR)/../../alib2algo/src/ \$$(SOURCES_BASE_DIR)/../../alib2str_experimental/src/ \$$(SOURCES_BASE_DIR)/../../alib2str/src/ \$$(SOURCES_BASE_DIR)/../../alib2data_experimental/src/ \$$(SOURCES_BASE_DIR)/../../alib2data/src/ \$$(SOURCES_BASE_DIR)/../../alib2common/src/ \$$(SOURCES_BASE_DIR)/../../alib2std/src/ /usr/include/libxml2/ diff --git a/alib2str/makefile.conf b/alib2str/makefile.conf index 15808d4f413adeaf3d96d05470a7119233424019..a9b0a7165267c4208fd7579eeac658eafa01c799 100644 --- a/alib2str/makefile.conf +++ b/alib2str/makefile.conf @@ -1,5 +1,5 @@ LIBRARY:=alib2str TESTBIN:=alib2test -LINK_PATHS=../alib2data_experimental/ ../alib2data/ ../alib2common/ ../alib2std/ -LINK_LIBRARIES=alib2data_experimental alib2data alib2common alib2std xml2 -INCLUDE_PATHS=\$$(SOURCES_BASE_DIR)/../../alib2data_experimental/src/ \$$(SOURCES_BASE_DIR)/../../alib2data/src/ \$$(SOURCES_BASE_DIR)/../../alib2common/src/ \$$(SOURCES_BASE_DIR)/../../alib2std/src/ /usr/include/libxml2/ +LINK_PATHS=../alib2data/ ../alib2common/ ../alib2std/ +LINK_LIBRARIES=alib2data alib2common alib2std xml2 +INCLUDE_PATHS=\$$(SOURCES_BASE_DIR)/../../alib2data/src/ \$$(SOURCES_BASE_DIR)/../../alib2common/src/ \$$(SOURCES_BASE_DIR)/../../alib2std/src/ /usr/include/libxml2/ diff --git a/alib2str_experimental/makefile b/alib2str_experimental/makefile new file mode 100644 index 0000000000000000000000000000000000000000..38bca86b66f086f610da9ff2985a30493671b4ef --- /dev/null +++ b/alib2str_experimental/makefile @@ -0,0 +1,214 @@ +SHELL:=/bin/bash +USE_RAMDISK ?= 0 +-include makefile.conf + +FULL_LIBRARY:=lib$(LIBRARY).so +define NEW_LINE + + +endef + +export NEW_LINE + +space := $(eval) $(eval) + +LDFLAGS_DEBUG:=-rdynamic -shared +TEST_LDFLAGS_DEBUG:=-Wl,-no-as-needed -Llib-debug $(addprefix -L, $(addsuffix lib-debug, $(LINK_PATHS))) -rdynamic -l$(LIBRARY) $(addprefix -l, $(LINK_LIBRARIES)) -lcppunit -Wl,-rpath,. + +LDFLAGS_RELEASE:=-rdynamic -shared +TEST_LDFLAGS_RELEASE:=-Wl,-no-as-needed -Llib-release $(addprefix -L, $(addsuffix lib-release, $(LINK_PATHS))) -rdynamic -l$(LIBRARY) $(addprefix -l, $(LINK_LIBRARIES)) -lcppunit -Wl,-rpath,. + +OBJECTS_DEBUG:=$(patsubst src/%.cpp, obj-debug/%.o, $(shell find src/ -name *cpp)) +TEST_OBJECTS_DEBUG:=$(patsubst test-src/%.cpp, test-obj-debug/%.o, $(shell find test-src/ -name *cpp)) + +OBJECTS_RELEASE:=$(patsubst src/%.cpp, obj-release/%.o, $(filter-out $(wildcard src/debug/*), $(shell find src/ -name *cpp))) +TEST_OBJECTS_RELEASE:=$(patsubst test-src/%.cpp, test-obj-release/%.o, $(shell find test-src/ -name *cpp)) + +.PHONY: all debug release clean build-debug build-release clean-debug clean-release doc + +all: + @echo "What to do master?" + +FORCE: + +# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +# make subdir makefile + +%/makefile: makefile makefile.conf + if [ ! -w $(dir $@) ] && [ $(USE_RAMDISK) -eq 1 ]; then\ + ln -s /tmp/`date +'%s%N'`-$(dir $@) $(subst /, , $(dir $@)) 2>/dev/null;\ + fi;\ + if [ -L $(subst /, , $(dir $@)) ]; then\ + mkdir -p `readlink $(subst /, , $(dir $@))`;\ + else\ + mkdir -p $(dir $@);\ + fi + echo "\ + SHELL:=/bin/bash$${NEW_LINE}\ + SRCDIR:=$${NEW_LINE}\ + $${NEW_LINE}\ + define NEW_LINE$${NEW_LINE}\ + $${NEW_LINE}\ + $${NEW_LINE}\ + endef$${NEW_LINE}\ + $${NEW_LINE}\ + export NEW_LINE$${NEW_LINE}\ + $${NEW_LINE}\ + CXXFLAGS:= -pipe -std=c++11 \$$(CXX_OTHER_FLAGS) -c -Wall -pedantic -Wextra -Werror -fPIC \$$(addprefix -I, \$$(realpath $(INCLUDE_PATHS))) -I\$$(realpath \$$(SOURCES_BASE_DIR)/../src/)$${NEW_LINE}\ + $${NEW_LINE}\ + SOURCES:= \$$(shell find \$$(SOURCES_BASE_DIR)/\$$(SRCDIR) -maxdepth 1 -type f -name \"*.cpp\")$${NEW_LINE}\ + DEPENDENCIES:= \$$(patsubst \$$(SOURCES_BASE_DIR)/\$$(SRCDIR)%.cpp, \$$(OBJECTS_BASE_DIR)/\$$(SRCDIR)%.d, \$$(SOURCES))$${NEW_LINE}\ + OBJECTS:= \$$(patsubst %.d, %.o, \$$(DEPENDENCIES))$${NEW_LINE}\ + SOURCES_DIRS:= \$$(shell find \$$(SOURCES_BASE_DIR)/\$$(SRCDIR) -maxdepth 1 -mindepth 1 -type d)$${NEW_LINE}\ + OBJECTS_DIRS:= \$$(patsubst \$$(SOURCES_BASE_DIR)/\$$(SRCDIR)%, %/, \$$(SOURCES_DIRS))$${NEW_LINE}\ + OBJECTS_DIRS_MAKEFILES:= \$$(patsubst %, %makefile, \$$(OBJECTS_DIRS))$${NEW_LINE}\ + $${NEW_LINE}\ + .PHONY: all$${NEW_LINE}\ + .PRECIOUS: \$$(DEPENDECIES) \$$(OBJECTS_DIRS_MAKEFILES)$${NEW_LINE}\ + $${NEW_LINE}\ + all: \$$(OBJECTS_DIRS) \$$(OBJECTS)$${NEW_LINE}\ + $${NEW_LINE}\ + %.d: makefile$${NEW_LINE}\ + @echo \"\\$${NEW_LINE}\ + \$$(shell sha1sum <<< \"\$$@\" | sed \"s/ -//g\") = \\$$\$$(shell (\\$$\$$(CXX) -M \\$$\$$(CXXFLAGS) \$$(patsubst \$$(OBJECTS_BASE_DIR)/\$$(SRCDIR)%.d,\$$(SOURCES_BASE_DIR)/\$$(SRCDIR)%.cpp, \$$@) 2>/dev/null || echo \\\"\$$(patsubst \$$(OBJECTS_BASE_DIR)/\$$(SRCDIR)%.d,\$$(SOURCES_BASE_DIR)/\$$(SRCDIR)%.cpp, \$$@) FORCE\\\") | sed \\\"s/.*://g;s/\\\\\\\\\\\\\\\\//g\\\")\$$\$${NEW_LINE}\\$${NEW_LINE}\ + \$$(patsubst %.d,%.o, \$$@): \\$$\$$(\$$(shell sha1sum <<< \"\$$@\" | sed \"s/ -//g\")) makefile\$$\$${NEW_LINE}\\$${NEW_LINE}\ + \\$$\$$(CXX) \\$$\$$(CXXFLAGS) \\$$\$$< -o \$$(patsubst %.d,%.o, \$$@)\$$\$${NEW_LINE}\\$${NEW_LINE}\ + \" > \$$@$${NEW_LINE}\ + $${NEW_LINE}\ + %/makefile: makefile$${NEW_LINE}\ + mkdir -p \$$(dir \$$@)$${NEW_LINE}\ + cp makefile \$$@$${NEW_LINE}\ + $${NEW_LINE}\ + %/: FORCE | %/makefile$${NEW_LINE}\ + @accesstime=\`stat -c %Y \$$@\` && \\$${NEW_LINE}\ + \$$(MAKE) -C \$$@ SRCDIR=\$$(SRCDIR)\$$(notdir \$$(patsubst %/, %, \$$@))/ OBJECTS_BASE_DIR=\$$(OBJECTS_BASE_DIR) SOURCES_BASE_DIR=\$$(SOURCES_BASE_DIR) CXX_OTHER_FLAGS=\"\$$(CXX_OTHER_FLAGS)\" && \\$${NEW_LINE}\ + accesstime2=\`stat -c %Y \$$@\` && \\$${NEW_LINE}\ + if [ "\$$\$$accesstime" -ne "\$$\$$accesstime2" ]; then \\$${NEW_LINE}\ + touch .; \\$${NEW_LINE}\ + fi$${NEW_LINE}\ + $${NEW_LINE}\ + FORCE:$${NEW_LINE}\ + $${NEW_LINE}\ + -include \$$(DEPENDENCIES)" > $@ + +# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +# final lib/bin construction + +lib-debug/$(FULL_LIBRARY): $(OBJECTS_DEBUG) obj-debug/ + if [ ! -w $(dir $@) ] && [ $(USE_RAMDISK) -eq 1 ]; then\ + ln -s /tmp/`date +'%s%N'`-$(dir $@) $(subst /, , $(dir $@)) 2>/dev/null;\ + fi;\ + if [ -L $(subst /, , $(dir $@)) ]; then\ + mkdir -p `readlink $(subst /, , $(dir $@))`;\ + else\ + mkdir -p $(dir $@);\ + fi + $(CXX) $(OBJECTS_DEBUG) -o $@ $(LDFLAGS_DEBUG) + +lib-release/$(FULL_LIBRARY): $(OBJECTS_RELEASE) obj-release/ + if [ ! -w $(dir $@) ] && [ $(USE_RAMDISK) -eq 1 ]; then\ + ln -s /tmp/`date +'%s%N'`-$(dir $@) $(subst /, , $(dir $@)) 2>/dev/null;\ + fi;\ + if [ -L $(subst /, , $(dir $@)) ]; then\ + mkdir -p `readlink $(subst /, , $(dir $@))`;\ + else\ + mkdir -p $(dir $@);\ + fi + $(CXX) $(OBJECTS_RELEASE) -o $@ $(LDFLAGS_RELEASE) + +test-bin-debug/$(TESTBIN): lib-debug/$(FULL_LIBRARY) $(TEST_OBJECTS_DEBUG) test-obj-debug/ + if [ ! -w $(dir $@) ] && [ $(USE_RAMDISK) -eq 1 ]; then\ + ln -s /tmp/`date +'%s%N'`-$(dir $@) $(subst /, , $(dir $@)) 2>/dev/null;\ + fi;\ + if [ -L $(subst /, , $(dir $@)) ]; then\ + mkdir -p `readlink $(subst /, , $(dir $@))`;\ + else\ + mkdir -p $(dir $@);\ + fi + $(CXX) $(TEST_OBJECTS_DEBUG) -o $@ $(TEST_LDFLAGS_DEBUG) + +test-bin-release/$(TESTBIN): lib-release/$(FULL_LIBRARY) $(TEST_OBJECTS_RELEASE) test-obj-release/ + if [ ! -w $(dir $@) ] && [ $(USE_RAMDISK) -eq 1 ]; then\ + ln -s /tmp/`date +'%s%N'`-$(dir $@) $(subst /, , $(dir $@)) 2>/dev/null;\ + fi;\ + if [ -L $(subst /, , $(dir $@)) ]; then\ + mkdir -p `readlink $(subst /, , $(dir $@))`;\ + else\ + mkdir -p $(dir $@);\ + fi + $(CXX) $(TEST_OBJECTS_RELEASE) -o $@ $(TEST_LDFLAGS_RELEASE) + +# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +# subdir make calls + +obj-debug/: FORCE obj-debug/makefile + $(MAKE) -C $@ OBJECTS_BASE_DIR=$(realpath obj-debug) SOURCES_BASE_DIR=$(realpath src) CXX_OTHER_FLAGS="-g -O0 -DDEBUG" + +obj-release/: FORCE obj-release/makefile + $(MAKE) -C $@ OBJECTS_BASE_DIR=$(realpath obj-release) SOURCES_BASE_DIR=$(realpath src) CXX_OTHER_FLAGS="-O3 -DNDEBUG -DRELEASE" + +test-obj-debug/: FORCE test-obj-debug/makefile + $(MAKE) -C $@ OBJECTS_BASE_DIR=$(realpath test-obj-debug) SOURCES_BASE_DIR=$(realpath test-src) CXX_OTHER_FLAGS="-g -O0 -DDEBUG" + +test-obj-release/: FORCE test-obj-release/makefile + $(MAKE) -C $@ OBJECTS_BASE_DIR=$(realpath test-obj-release) SOURCES_BASE_DIR=$(realpath test-src) CXX_OTHER_FLAGS="-O3 -DNDEBUG -DRELEASE" + +# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +# objects dependencies + +$(OBJECTS_DEBUG): obj-debug/ + +$(OBJECTS_RELEASE): obj-release/ + +$(TEST_OBJECTS_DEBUG): test-obj-debug/ + +$(TEST_OBJECTS_RELEASE): test-obj-release/ + +# ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +# main targets + +debug: test-bin-debug/$(TESTBIN) + LD_LIBRARY_PATH="$(subst $(space),;,$(addsuffix lib-debug;,$(LINK_PATHS)))lib-debug" test-bin-debug/$(TESTBIN) + +release: test-bin-release/$(TESTBIN) + LD_LIBRARY_PATH="$(subst $(space),;,$(addsuffix lib-release;,$(LINK_PATHS)))lib-release" test-bin-release/$(TESTBIN) + +clean: clean-debug clean-release + $(RM) -r doc + +build-debug: lib-debug/$(FULL_LIBRARY) + +build-release: lib-release/$(FULL_LIBRARY) + +clean-debug: + if [ -L obj-debug ]; then\ + $(RM) -r `readlink obj-debug`;\ + fi + if [ -L lib-debug ]; then\ + $(RM) -r `readlink lib-debug`;\ + fi + if [ -L test-obj-debug ]; then\ + $(RM) -r `readlink test-obj-debug`;\ + fi + if [ -L test-bin-debug ]; then\ + $(RM) -r `readlink test-bin-debug`;\ + fi + $(RM) -r *.o *.d lib-debug obj-debug test-bin-debug test-obj-debug CppUnitTestResults.xml + +clean-release: + if [ -L obj-release ]; then\ + $(RM) -r `readlink obj-release`;\ + fi + if [ -L lib-release ]; then\ + $(RM) -r `readlink lib-release`;\ + fi + if [ -L test-obj-release ]; then\ + $(RM) -r `readlink test-obj-release`;\ + fi + if [ -L test-bin-release ]; then\ + $(RM) -r `readlink test-bin-release`;\ + fi + $(RM) -r *.o *.d lib-release obj-release test-bin-release test-obj-release CppUnitTestResults.xml + +doc: + doxygen diff --git a/alib2str_experimental/makefile.conf b/alib2str_experimental/makefile.conf new file mode 100644 index 0000000000000000000000000000000000000000..0a3876ca398826244526eaf06d84e9f154ccd199 --- /dev/null +++ b/alib2str_experimental/makefile.conf @@ -0,0 +1,5 @@ +LIBRARY:=alib2str_experimental +TESTBIN:=alib2test +LINK_PATHS=../alib2str/ ../alib2data_experimental/ ../alib2data/ ../alib2common/ ../alib2std/ +LINK_LIBRARIES=alib2str alib2data_experimental alib2data alib2common alib2std xml2 +INCLUDE_PATHS=\$$(SOURCES_BASE_DIR)/../../alib2str/src/ \$$(SOURCES_BASE_DIR)/../../alib2data_experimental/src/ \$$(SOURCES_BASE_DIR)/../../alib2data/src/ \$$(SOURCES_BASE_DIR)/../../alib2common/src/ \$$(SOURCES_BASE_DIR)/../../alib2std/src/ /usr/include/libxml2/ diff --git a/alib2str/src/graph/GraphFromStringLexer.cpp b/alib2str_experimental/src/graph/GraphFromStringLexer.cpp similarity index 100% rename from alib2str/src/graph/GraphFromStringLexer.cpp rename to alib2str_experimental/src/graph/GraphFromStringLexer.cpp diff --git a/alib2str/src/graph/GraphFromStringLexer.h b/alib2str_experimental/src/graph/GraphFromStringLexer.h similarity index 100% rename from alib2str/src/graph/GraphFromStringLexer.h rename to alib2str_experimental/src/graph/GraphFromStringLexer.h diff --git a/alib2str/src/graph/GraphFromStringParser.cpp b/alib2str_experimental/src/graph/GraphFromStringParser.cpp similarity index 99% rename from alib2str/src/graph/GraphFromStringParser.cpp rename to alib2str_experimental/src/graph/GraphFromStringParser.cpp index fe9ad7cb72750a5329c09045ed5cab50ba1ecbb7..c925353e8b9f769b9c07f266328b1827939194e0 100644 --- a/alib2str/src/graph/GraphFromStringParser.cpp +++ b/alib2str_experimental/src/graph/GraphFromStringParser.cpp @@ -10,7 +10,8 @@ #include "exception/CommonException.h" #include "graph/GraphClasses.h" -#include "../StringApi.hpp" +#include <StringApi.hpp> +#include <label/LabelStringApi.hpp> namespace graph { diff --git a/alib2str/src/graph/GraphFromStringParser.h b/alib2str_experimental/src/graph/GraphFromStringParser.h similarity index 100% rename from alib2str/src/graph/GraphFromStringParser.h rename to alib2str_experimental/src/graph/GraphFromStringParser.h diff --git a/alib2str/src/graph/GraphStringApi.cpp b/alib2str_experimental/src/graph/GraphStringApi.cpp similarity index 100% rename from alib2str/src/graph/GraphStringApi.cpp rename to alib2str_experimental/src/graph/GraphStringApi.cpp diff --git a/alib2str/src/graph/GraphStringApi.hpp b/alib2str_experimental/src/graph/GraphStringApi.hpp similarity index 93% rename from alib2str/src/graph/GraphStringApi.hpp rename to alib2str_experimental/src/graph/GraphStringApi.hpp index 041c7f0200d67cb9987ed2e2fe638dd87395293f..cc2f5d0ba49f03bf80ca7a5bf81e655a3519b67f 100644 --- a/alib2str/src/graph/GraphStringApi.hpp +++ b/alib2str_experimental/src/graph/GraphStringApi.hpp @@ -8,7 +8,7 @@ #ifndef GRAPH_STRING_API_HPP_ #define GRAPH_STRING_API_HPP_ -#include "../StringApi.hpp" +#include <StringApi.hpp> #include <graph/Graph.h> namespace alib { diff --git a/alib2str/src/graph/GraphToStringComposer.cpp b/alib2str_experimental/src/graph/GraphToStringComposer.cpp similarity index 98% rename from alib2str/src/graph/GraphToStringComposer.cpp rename to alib2str_experimental/src/graph/GraphToStringComposer.cpp index 84228906b0b06c4bfe225b59542ab28db6ebade5..d9276cd59a183e0b75e0a702d0c7f65e350f9af1 100644 --- a/alib2str/src/graph/GraphToStringComposer.cpp +++ b/alib2str_experimental/src/graph/GraphToStringComposer.cpp @@ -8,7 +8,8 @@ #include "GraphToStringComposer.h" #include "graph/GraphClasses.h" -#include "../StringApi.hpp" +#include <StringApi.hpp> +#include <label/LabelStringApi.hpp> namespace graph { diff --git a/alib2str/src/graph/GraphToStringComposer.h b/alib2str_experimental/src/graph/GraphToStringComposer.h similarity index 100% rename from alib2str/src/graph/GraphToStringComposer.h rename to alib2str_experimental/src/graph/GraphToStringComposer.h diff --git a/alib2str/test-src/graph/GraphTest.cpp b/alib2str_experimental/test-src/graph/GraphTest.cpp similarity index 100% rename from alib2str/test-src/graph/GraphTest.cpp rename to alib2str_experimental/test-src/graph/GraphTest.cpp diff --git a/alib2str/test-src/graph/GraphTest.h b/alib2str_experimental/test-src/graph/GraphTest.h similarity index 100% rename from alib2str/test-src/graph/GraphTest.h rename to alib2str_experimental/test-src/graph/GraphTest.h diff --git a/alib2str_experimental/test-src/main.cpp b/alib2str_experimental/test-src/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fd442ebd124cc1580de43b2e1846e5063fefde68 --- /dev/null +++ b/alib2str_experimental/test-src/main.cpp @@ -0,0 +1,164 @@ +#include <tclap/CmdLine.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/XmlOutputter.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> + +#include <exception/CommonException.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 © ); + + void operator =( const TestProgressListener © ); + +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 argc, char* argv[]) { + try { + TCLAP::CmdLine cmd("Main test binary.", ' ', "0.01"); + + TCLAP::MultiArg<std::string> testPathSegments("p", "path", "test path", false, "string" ); + cmd.add( testPathSegments ); + + cmd.parse(argc, argv); + + CppUnit::TestResult controller; + + CppUnit::TestResultCollector result; + controller.addListener( &result ); + + CppUnit::TestProgressListener progressListener; + controller.addListener( &progressListener ); + + CppUnit::Test *suite = NULL; + std::string testPath = ""; + if(testPathSegments.getValue().size() == 0) { + // Get the top level suite from the registry + suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest(); + } else if(testPathSegments.getValue().size() == 1) { + suite = CppUnit::TestFactoryRegistry::getRegistry(testPathSegments.getValue()[0]).makeTest(); + } else { + suite = CppUnit::TestFactoryRegistry::getRegistry(testPathSegments.getValue()[0]).makeTest(); + bool first = true; + for(const std::string& path : testPathSegments.getValue()) { + if(first) { + first = false; + continue; + } + testPath += path + "/"; + } + testPath.pop_back(); + } + + // 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, testPath ); + + progressListener.printResults(); + + std::ofstream xmlFileResults("CppUnitTestResults.xml"); + CppUnit::XmlOutputter xmlOut(&result, xmlFileResults); + xmlOut.write(); + + return progressListener.getResult(); + } catch(const exception::CommonException& exception) { + std::cerr << exception.getCause() << std::endl; + return 1; + } catch(const TCLAP::ArgException& exception) { + std::cerr << exception.error() << std::endl; + return 2; + } catch (const std::exception& exception) { + std::cerr << "Exception caught: " << exception.what() << std::endl; + return 3; + } catch(...) { + std::cerr << "Unknown exception caught." << std::endl; + return 127; + } +} diff --git a/makefile b/makefile index d4976aef4644da0e7ba5b33636a573b03020b216..7076fe85825e626a9a2fc098b04dcfefaa362b7a 100644 --- a/makefile +++ b/makefile @@ -19,6 +19,7 @@ SUBDIRS_LIBS = alib2std \ alib2data \ alib2data_experimental \ alib2str \ + alib2str_experimental \ alib2raw \ alib2algo \ alib2algo_experimental \