From 5d78e2f5e44ecc65960472c6b6ac0dcb5cc9584f Mon Sep 17 00:00:00 2001 From: EinMByte Date: Thu, 16 Jul 2015 22:28:57 +0200 Subject: [PATCH] Setup unit test environment. --- .gitignore | 1 + Makefile | 12 ++++++++++-- Makefile.bsd | 1 + Makefile.linux | 3 +++ Makefile.osx | 1 + filelist.mk | 3 +++ tests/Identity.cpp | 12 ++++++++++++ tests/Utility.cpp | 19 +++++++++++++++++++ 8 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 tests/Identity.cpp create mode 100644 tests/Utility.cpp diff --git a/.gitignore b/.gitignore index 156872a9..1adbe1ef 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ i2p libi2pd.so netDb tunnels.cfg +tests/tests # Autotools autom4te.cache diff --git a/Makefile b/Makefile index d256c36e..26079a2a 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/Makefile.bsd b/Makefile.bsd index c6c3ce65..cd6948f3 100644 --- a/Makefile.bsd +++ b/Makefile.bsd @@ -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 diff --git a/Makefile.linux b/Makefile.linux index 8af84edf..a2bfed17 100644 --- a/Makefile.linux +++ b/Makefile.linux @@ -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 diff --git a/Makefile.osx b/Makefile.osx index 7af2247b..fddf5a6b 100644 --- a/Makefile.osx +++ b/Makefile.osx @@ -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 diff --git a/filelist.mk b/filelist.mk index 623a1b33..f2aae727 100644 --- a/filelist.mk +++ b/filelist.mk @@ -23,3 +23,6 @@ DAEMON_SRC = $(COMMON_SRC) \ LIB_SRC := $(COMMON_SRC) \ api.cpp + +TESTS_SRC := $(COMMON_SRC) \ + tests/Utility.cpp tests/Identity.cpp diff --git a/tests/Identity.cpp b/tests/Identity.cpp new file mode 100644 index 00000000..597a2ba0 --- /dev/null +++ b/tests/Identity.cpp @@ -0,0 +1,12 @@ +#define BOOST_TEST_MAIN +#define BOOST_TEST_DYN_LINK + +#include +#include "../Identity.h" + +BOOST_AUTO_TEST_SUITE(IdentityTests) + + + + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/Utility.cpp b/tests/Utility.cpp new file mode 100644 index 00000000..2790c1fd --- /dev/null +++ b/tests/Utility.cpp @@ -0,0 +1,19 @@ +#include +#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()