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

example tests of alib2

parent bbb7fa11
No related branches found
No related tags found
No related merge requests found
CC=g++ CC=g++
LIBRARY=libalib2.so LIBRARY=libalib2.so
TESTBIN=alib2test
CCFLAGS= -std=c++11 -O2 -g -c -Wall -pedantic -fPIC -I/usr/include/libxml2/ CCFLAGS= -std=c++11 -O2 -g -c -Wall -pedantic -fPIC -I/usr/include/libxml2/
LDFLAGS= -shared -lxml2 LDFLAGS= -shared -lxml2
TEST_CCFLAGS= -std=c++11 -O2 -g -c -Wall -pedantic -I../alib2/src -I/usr/include/libxml2/
TEST_LDFLAGS= -L../alib2/lib -lxml2 -lalib2 -lcppunit -Wl,-rpath,.
   
SOURCES=$(shell find src/ -name *cpp) SOURCES=$(shell find src/ -name *cpp)
OBJECTS=$(patsubst src/%.cpp, obj/%.o, $(SOURCES)) OBJECTS=$(patsubst src/%.cpp, obj/%.o, $(SOURCES))
   
all: $(SOURCES) lib/$(LIBRARY) TEST_SOURCES=$(shell find test-src/ -name *cpp)
TEST_OBJECTS=$(patsubst test-src/%.cpp, test-obj/%.o, $(TEST_SOURCES))
all: lib/$(LIBRARY) test-bin/$(TESTBIN) test
   
lib/$(LIBRARY): $(OBJECTS) lib/$(LIBRARY): $(OBJECTS)
mkdir -p lib mkdir -p lib
...@@ -16,5 +22,16 @@ obj/%.o: src/%.cpp ...@@ -16,5 +22,16 @@ obj/%.o: src/%.cpp
mkdir -p $(dir $@) mkdir -p $(dir $@)
$(CC) $(CCFLAGS) $< -o $@ $(CC) $(CCFLAGS) $< -o $@
   
test-bin/$(TESTBIN): $(TEST_OBJECTS) lib/$(LIBRARY)
mkdir -p test-bin
$(CC) $(TEST_OBJECTS) -o $@ $(TEST_LDFLAGS)
test-obj/%.o: test-src/%.cpp
mkdir -p $(dir $@)
$(CC) $(TEST_CCFLAGS) $< -o $@
test: test-bin/$(TESTBIN)
LD_LIBRARY_PATH=lib test-bin/$(TESTBIN)
clean: clean:
$(RM) -r *.o *.d lib obj $(RM) -r *.o *.d lib obj test-bin test-obj
//#include "stdafx.h"
#include <cppunit/CompilerOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
int main(int , char*[])
{
// 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.
bool wasSucessful = runner.run();
// Return error code 1 if the one of test failed.
return wasSucessful ? 0 : 1;
}
#include "RegExpTest.h"
#include "regexp/RegExp.h"
#include "regexp/RegExpFromStringParser.h"
#include "regexp/RegExpToStringComposer.h"
CPPUNIT_TEST_SUITE_REGISTRATION( RegExpTest );
void RegExpTest::setUp() {
}
void RegExpTest::tearDown() {
}
void RegExpTest::testEqual() {
std::string input = "a+a";
regexp::RegExpFromStringParser parser(input);
regexp::RegExp regexp = parser.parse();
regexp::RegExpToStringComposer composer;
std::string output = composer.compose(regexp);
regexp::RegExpFromStringParser parser2(input);
regexp::RegExp regexp2 = parser2.parse();
CPPUNIT_ASSERT( regexp == regexp2 );
}
#ifndef REG_EXP_TEST_H_
#define REG_EXP_TEST_H_
#include <cppunit/extensions/HelperMacros.h>
class RegExpTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( RegExpTest );
CPPUNIT_TEST( testEqual );
CPPUNIT_TEST_SUITE_END();
public:
void setUp();
void tearDown();
void testEqual();
};
#endif // REG_EXP_TEST_H_
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