Skip to content
Snippets Groups Projects
Commit 63eae71e authored by Jan Trávníček's avatar Jan Trávníček
Browse files

draft acat2

parent db889a75
No related branches found
No related tags found
No related merge requests found
SHELL:=/bin/bash
EXECUTABLE:=acat2
TESTBIN:=acat2test
LDFLAGS= -L../alib2/lib -rdynamic -lxml2 -lalib2 -Wl,-rpath,.
TEST_LDFLAGS:= -L../alib2/lib -rdynamic -lxml2 -lalib2 -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
bin/$(EXECUTABLE): obj/ $(OBJECTS)
mkdir -p bin
$(CXX) $(OBJECTS) -o $@ $(LDFLAGS)
obj/makefile: makefile
mkdir -p $(dir $@)
echo "SHELL:=/bin/bash" >> $@
echo "SRCDIR:=" >> $@
echo "DEPTH:=" >> $@
echo "" >> $@
echo "CXXFLAGS:= -std=c++11 -Og -g -c -Wall -pedantic -Wextra -I../../alib2/src/ -I/usr/include/libxml2/" >> $@
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:" >> $@
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: bin/$(EXECUTABLE)
test-bin/$(TESTBIN): test-obj/ bin/$(EXECUTABLE) $(TEST_OBJECTS)
mkdir -p test-bin
$(CXX) $(TEST_OBJECTS) -o $@ $(TEST_LDFLAGS)
test-obj/makefile:
mkdir -p $(dir $@)
echo "SHELL:=/bin/bash" >> $@
echo "SRCDIR:=" >> $@
echo "DEPTH:=" >> $@
echo "" >> $@
echo "CXXFLAGS:= -std=c++11 -Og -g -c -Wall -pedantic -Wextra -I../\$$(DEPTH)src/ -I/usr/include/libxml2/" >> $@
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:" >> $@
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=../alib2/lib test-bin/$(TESTBIN)
clean:
$(RM) -r *.o *.d lib obj test-bin test-obj
FORCE:
//============================================================================
// Name : acat.cpp
// Author : Martin Zak
//============================================================================
#include <iostream>
#include <string>
#include <set>
#include <cstdlib>
#include <unistd.h>
#include <exception>
#include "AlibException.h"
#include "FromXMLParsers.h"
#include "sax/SaxParseInterface.h"
#include "sax/ParserException.h"
#define VERSION "0.0.1"
#define USAGE "Usage: catPDA [-c] [input]";
void getAutomaton(std::list<sax::Token>& tokens) {
automaton::Automaton automaton = alib::FromXMLParsers::automatonParser.parseValue(tokens);
std::cout << automaton;
}
void getRegExp(std::list<sax::Token>& tokens) {
regexp::RegExp regexp = alib::FromXMLParsers::regexpParser.parseValue(tokens);
std::cout << regexp;
}
int main(int argc, char** argv) {
if(argc == 2 && std::string(argv[1])=="-v" ) {
std::cout << argv[0] << " version " << VERSION << "\n";
std::cout << USAGE;
std::cout << std::endl;
return EXIT_SUCCESS;
}
int i=getopt(argc, argv, "t:");
while(i!=-1) {
switch(i){
default:
optind--;
break;
}
i=getopt(argc, argv, "t:");
}
std::list<sax::Token> tokens;
if(optind == argc) {
std::string input(std::istreambuf_iterator<char>(std::cin), std::istreambuf_iterator<char>());
sax::SaxParseInterface::parseMemory(input, tokens);
} else {
sax::SaxParseInterface::parseFile(argv[optind],tokens);
}
if (tokens.front().getData() == "automaton") {
getAutomaton(tokens);
} else if (tokens.front().getData() == "regexp") {
getRegExp(tokens);
} else {
throw alib::AlibException( "Expected root tag automaton, grammar or regexp. Read: " + tokens.front().getData());
}
}
//#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();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment