Setup unit test environment.

This commit is contained in:
EinMByte 2015-07-16 22:28:57 +02:00
parent 4ce7b0e9ef
commit 5d78e2f5e4
8 changed files with 50 additions and 2 deletions

1
.gitignore vendored
View File

@ -6,6 +6,7 @@ i2p
libi2pd.so
netDb
tunnels.cfg
tests/tests
# Autotools
autom4te.cache

View File

@ -1,6 +1,7 @@
UNAME := $(shell uname -s)
SHLIB := libi2pd.so
I2PD := i2p
TESTS := tests/tests
GREP := fgrep
DEPS := obj/make.dep
@ -22,10 +23,11 @@ else # win32
DAEMON_SRC += DaemonWin32.cpp
endif
all: mk_build_dir $(SHLIB) $(I2PD)
all: mk_build_dir $(SHLIB) $(I2PD) $(TESTS)
mk_build_dir:
mkdir -p obj
mkdir -p obj/tests
api: $(SHLIB)
@ -38,11 +40,13 @@ api: $(SHLIB)
deps:
@mkdir -p obj
@mkdir -p obj/tests
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) -MM *.cpp > $(DEPS)
@sed -i -e '/\.o:/ s/^/obj\//' $(DEPS)
obj/%.o : %.cpp
@mkdir -p obj
@mkdir -p obj/tests
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) $(CPU_FLAGS) -c -o $@ $<
# '-' is 'ignore if missing' on first run
@ -56,9 +60,13 @@ ifneq ($(USE_STATIC),yes)
$(CXX) $(LDFLAGS) $(LDLIBS) -shared -o $@ $^
endif
$(TESTS): $(patsubst %.cpp,obj/%.o,$(TESTS_SRC))
$(CXX) -o $@ $^ $(LDLIBS) $(LDTESTLIBS) $(LDFLAGS)
clean:
rm -rf obj
$(RM) $(I2PD) $(SHLIB)
$(RM) $(I2PD) $(SHLIB) $(TESTS)
LATEST_TAG=$(shell git describe --tags --abbrev=0 master)
dist:

View File

@ -10,3 +10,4 @@ NEEDED_CXXFLAGS = -std=c++11
INCFLAGS = -I/usr/include/ -I/usr/local/include/
LDFLAGS = -Wl,-rpath,/usr/local/lib -L/usr/local/lib
LDLIBS = -lcryptopp -lboost_system -lboost_date_time -lboost_filesystem -lboost_regex -lboost_program_options -lpthread
LDTESTLIBS = -lboost_unit_test_framework

View File

@ -40,6 +40,9 @@ else
LDLIBS = -lcryptopp -lboost_system -lboost_date_time -lboost_filesystem -lboost_regex -lboost_program_options -lpthread
endif
# Always link with test framework dynamically
LDTESTLIBS = -lboost_unit_test_framework
# UPNP Support (miniupnpc 1.5 or 1.6)
ifeq ($(USE_UPNP),1)
LDFLAGS += -ldl

View File

@ -4,6 +4,7 @@ CXXFLAGS = -g -Wall -std=c++11 -DCRYPTOPP_DISABLE_ASM -DMAC_OSX
INCFLAGS = -I/usr/local/include
LDFLAGS = -Wl,-rpath,/usr/local/lib -L/usr/local/lib
LDLIBS = -lcryptopp -lboost_system -lboost_date_time -lboost_filesystem -lboost_regex -lboost_program_options -lpthread
LDTESTLIBS = -lboost_unit_test_framework
ifeq ($(USE_UPNP),1)
LDFLAGS += -ldl

View File

@ -23,3 +23,6 @@ DAEMON_SRC = $(COMMON_SRC) \
LIB_SRC := $(COMMON_SRC) \
api.cpp
TESTS_SRC := $(COMMON_SRC) \
tests/Utility.cpp tests/Identity.cpp

12
tests/Identity.cpp Normal file
View File

@ -0,0 +1,12 @@
#define BOOST_TEST_MAIN
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "../Identity.h"
BOOST_AUTO_TEST_SUITE(IdentityTests)
BOOST_AUTO_TEST_SUITE_END()

19
tests/Utility.cpp Normal file
View File

@ -0,0 +1,19 @@
#include <boost/test/unit_test.hpp>
#include "../util.h"
BOOST_AUTO_TEST_SUITE(UtilityTests)
using namespace i2p::util::http;
BOOST_AUTO_TEST_CASE(DecodeEmptyUrl)
{
BOOST_CHECK_EQUAL(urlDecode(""), "");
}
BOOST_AUTO_TEST_CASE(DecodeUrl)
{
BOOST_CHECK_EQUAL(urlDecode("%20"), " ");
}
BOOST_AUTO_TEST_SUITE_END()