Initial infrastructure to support CppUnit

This commit is contained in:
Tiago Gomes 2013-03-13 14:47:14 +00:00
parent 5e5feb5674
commit 23469e6f94
2 changed files with 58 additions and 11 deletions

View File

@ -43,6 +43,7 @@ SO=@SO@
#4.1VPATH=@srcdir@:@srcdir@/OPTYap #4.1VPATH=@srcdir@:@srcdir@/OPTYap
CWD=$(PWD) CWD=$(PWD)
utestsdir=@srcdir@/unit_tests
HEADERS = \ HEADERS = \
$(srcdir)/BayesBall.h \ $(srcdir)/BayesBall.h \
@ -74,7 +75,7 @@ HEADERS = \
$(srcdir)/VarElim.h \ $(srcdir)/VarElim.h \
$(srcdir)/WeightedBp.h $(srcdir)/WeightedBp.h
CPP_SOURCES = \ MAIN_SOURCES = \
$(srcdir)/BayesBall.cpp \ $(srcdir)/BayesBall.cpp \
$(srcdir)/BayesBallGraph.cpp \ $(srcdir)/BayesBallGraph.cpp \
$(srcdir)/BeliefProp.cpp \ $(srcdir)/BeliefProp.cpp \
@ -103,7 +104,14 @@ CPP_SOURCES = \
$(srcdir)/VarElim.cpp \ $(srcdir)/VarElim.cpp \
$(srcdir)/WeightedBp.cpp $(srcdir)/WeightedBp.cpp
LIB_OBJS = \ UTESTS_SOURCES = \
$(utestsdir)/UnitTesting.cpp
SOURCES = \
$(MAIN_SOURCES) \
$(UTESTS_SOURCES)
OBJS = \
BayesBall.o \ BayesBall.o \
BayesBallGraph.o \ BayesBallGraph.o \
BeliefProp.o \ BeliefProp.o \
@ -115,7 +123,6 @@ LIB_OBJS = \
GenericFactor.o \ GenericFactor.o \
GroundSolver.o \ GroundSolver.o \
Histogram.o \ Histogram.o \
HorusYap.o \
Indexer.o \ Indexer.o \
LiftedBp.o \ LiftedBp.o \
LiftedKc.o \ LiftedKc.o \
@ -131,6 +138,10 @@ LIB_OBJS = \
VarElim.o \ VarElim.o \
WeightedBp.o WeightedBp.o
LIB_OBJS = \
$(OBJS) \
HorusYap.o
HCLI_OBJS = \ HCLI_OBJS = \
BayesBall.o \ BayesBall.o \
BayesBallGraph.o \ BayesBallGraph.o \
@ -148,12 +159,22 @@ HCLI_OBJS = \
VarElim.o \ VarElim.o \
WeightedBp.o WeightedBp.o
UTESTS_OBJS = \
$(OBJS) \
$(utestsdir)/UnitTesting.o
LIB = $(srcdir)/horus.@SO@ LIB = $(srcdir)/horus.@SO@
HCLI = $(srcdir)/hcli HCLI = $(srcdir)/hcli
UTESTING = $(srcdir)/run_tests
all: $(LIB) $(HCLI) # Don't require $(UTESTING) by default as we
# don't want a hard dependency on CppUnit
default: $(LIB) $(HCLI)
all: $(LIB) $(HCLI) $(UTESTING)
@DO_SECOND_LD@$(LIB): $(LIB_OBJS) @DO_SECOND_LD@$(LIB): $(LIB_OBJS)
@ -164,6 +185,10 @@ $(HCLI): $(HCLI_OBJS)
$(CXX) -o $@ $(HCLI_OBJS) $(CXX) -o $@ $(HCLI_OBJS)
$(UTESTING): $(UTESTS_OBJS)
$(CXX) -o $@ $(UTESTS_OBJS) -lcppunit
# default rule # default rule
%.o : $(srcdir)/%.cpp %.o : $(srcdir)/%.cpp
$(CXX) -o $@ -c $(CXXFLAGS) $< $(CXX) -o $@ -c $(CXXFLAGS) $<
@ -175,20 +200,27 @@ install: all
clean: clean:
rm -f $(LIB) $(HCLI) *.o *~ rm -f $(LIB) $(HCLI) $(UTESTING) *.o *~
erase_dots: remove_dots:
rm -f *.dot *.png rm -f *.dot *.png *.svg
depend: $(CPP_SOURCES) $(HEADERS) depend: $(SOURCES) $(HEADERS)
-@if test "$(GCC)" = yes; then\ -@if test "$(GCC)" = yes; then\
$(CC) -std=c++0x -MM -MG $(CFLAGS) -I$(srcdir) -I$(srcdir)/../../../../include -I$(srcdir)/../../../../H $(CPP_SOURCES) >> Makefile;\ for F in $(SOURCES); do \
D=`dirname $$F`; \
B=`basename $$F .cpp`; \
$(CXX) $(CXXFLAGS) -MM -MG -MT "$$D/$$B.o" -I$(srcdir)/../../../../H -I$(srcdir)/../../../../include $$F >> Makefile; \
done; \
else\ else\
makedepend -f - -- $(CFLAGS) -I$(srcdir)/../../../../H -I$(srcdir)/../../../../include -- $(CPP_SOURCES) |\ makedepend -- $(CXXFLAGS) -- -I$(srcdir)/../../../../H -I$(srcdir)/../../../../include $(SOURCES); \
sed 's|.*/\([^:]*\):|\1:|' >> Makefile ;\
fi fi
.PHONY: default all install clean remove_dots depend
# DO NOT DELETE THIS LINE -- make depend depends on it. # DO NOT DELETE THIS LINE -- make depend depends on it.

View File

@ -0,0 +1,15 @@
#include "../Factor.h"
#include <cppunit/ui/text/TestRunner.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
int main()
{
CppUnit::TextUi::TestRunner runner;
CppUnit::TestFactoryRegistry& registry =
CppUnit::TestFactoryRegistry::getRegistry();
runner.addTest (registry.makeTest());
return runner.run() ? 1 : 0;
}