From 6b2a9dabbfad4d64268967a32dff0f1dc55763de Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 16 May 2020 13:28:52 +0200 Subject: Makefile cleanup, included missing files --- .gitignore | 2 + Makefile | 39 ++++++--------- libcommon/Makefile | 23 +-------- libcommon/tempfile.cpp | 27 ++++++++++ libcommon/tempfile.h | 16 ++++++ plugins/cgi/Makefile | 23 +-------- plugins/fcgi/Makefile | 23 +-------- plugins/redirect/Makefile | 27 ++-------- plugins/static-files/Makefile | 23 ++------- plugins/statistics/Makefile | 27 ++-------- plugins/webbox/Makefile | 27 ++-------- plugins/weblog/Makefile | 20 ++------ test-webserver.cpp | 44 ----------------- tests/Makefile | 112 ++++++++++++++++++++++++++++++++++++++++++ tests/test-webserver.cpp | 44 +++++++++++++++++ 15 files changed, 236 insertions(+), 241 deletions(-) create mode 100644 libcommon/tempfile.cpp create mode 100644 libcommon/tempfile.h delete mode 100644 test-webserver.cpp create mode 100644 tests/Makefile create mode 100644 tests/test-webserver.cpp diff --git a/.gitignore b/.gitignore index bf43ad2..51a5c69 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ +*.a *.o *.d +*.pem *.so *.swp default.profraw diff --git a/Makefile b/Makefile index 45beff4..f6a0ced 100644 --- a/Makefile +++ b/Makefile @@ -31,17 +31,15 @@ endif # -fprofile-instr-generate -fcoverage-mapping # gcc:--coverage -CXXFLAGS+= -Wall -I. -DVERSION=\"$(VERSION)\" -fPIE +CXXFLAGS+=-Wall -I. -DVERSION=\"$(VERSION)\" -fPIE -CXXFLAGS+= -pthread +CXXFLAGS+=-pthread ifeq ($(CXX),clang++-10) CXXFLAGS+=-std=c++20 #-stdlib=libc++ else CXXFLAGS+=-std=c++17 endif -CXXTESTFLAGS=-Igoogletest/include -Igooglemock/include/ -Igoogletest -Igooglemock - LIBS=\ -lcommon \ -lboost_context \ @@ -87,38 +85,25 @@ PROGSRC=\ statistics.cpp \ server.cpp -TESTSRC=\ - test-webserver.cpp \ - googlemock/src/gmock-all.cpp \ - googletest/src/gtest-all.cpp \ - $(PROGSRC) - SRC=$(PROGSRC) webserver.cpp -build: $(PROJECTNAME) test-$(PROJECTNAME) +build: $(PROJECTNAME) +set -e ; for i in $(PLUGINS) ; do make -C plugins/$$i ; done - ./test-$(PROJECTNAME) all: build ./webserver -c webserver.conf -# testsuite ---------------------------------------------- -test-$(PROJECTNAME): $(TESTSRC:.cpp=.o) - $(CXX) $(LDFLAGS) $^ $(LDLIBS) $(LIBS) -o $@ - $(PROJECTNAME): libcommon/libcommon.a $(SRC:.cpp=.o) $(CXX) $(LDFLAGS) $^ $(LDLIBS) $(LIBS) -o $@ libcommon/libcommon.a: $(MAKE) -C libcommon -dep: $(TESTSRC:.cpp=.d) - %.d: %.cpp - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -MM -MP -MF $@ -c $< + $(CXX) $(CXXFLAGS) -MM -MP -MF $@ -c $< %.o: %.cpp %.d - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ + $(CXX) $(CXXFLAGS) -c $< -o $@ googletest/src/%.o: googletest/src/%.cc $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ @@ -127,6 +112,9 @@ googletest/src/%.o: googletest/src/%.cc ADD_DEP=Makefile +test: + $(MAKE) -C tests + install: mkdir -p $(DESTDIR)/usr/bin cp webserver $(DESTDIR)/usr/bin @@ -156,11 +144,11 @@ $(DISTROS): deb-src debs: $(DISTROS) clean: - -rm -f test-$(PROJECTNAME) $(PROJECTNAME) + -rm -f $(PROJECTNAME) -rm -f plugins/*.so -find . -name '*.o' -o -name '*.d' -o -name '*.gcno' -o -name '*.gcda' | xargs rm -f - for i in $(PLUGINS) ; do make -C plugins/$$i clean ; done - $(MAKE) -C libcommon clean + #for i in $(PLUGINS) ; do $(MAKE) -C plugins/$$i clean ; done + for i in libcommon tests ; do $(MAKE) -C $$i clean ; done DISTFILES= \ archive.h \ @@ -187,7 +175,8 @@ DISTFILES= \ server.h \ statistics.cpp \ statistics.h \ - test-webserver.cpp \ + tests/Makefile \ + tests/test-webserver.cpp \ webserver.cpp \ webserver.1 \ README.txt \ @@ -262,6 +251,6 @@ dist: clean rm -rf $(PROJECTNAME)-$(VERSION) ls -l ../$(PROJECTNAME)-$(VERSION).tar.xz -.PHONY: clean all zip install deb deb-src debs all $(DISTROS) +.PHONY: clean all zip test install deb deb-src debs all $(DISTROS) -include $(wildcard $(SRC:.cpp=.d)) diff --git a/libcommon/Makefile b/libcommon/Makefile index 932ee90..ab76ed1 100644 --- a/libcommon/Makefile +++ b/libcommon/Makefile @@ -30,8 +30,6 @@ else CXXFLAGS+=-std=c++17 endif -CXXTESTFLAGS=-Igoogletest/include -Igooglemock/include/ -Igoogletest -Igooglemock - LIBS=\ -lboost_context \ -lboost_coroutine \ @@ -64,33 +62,18 @@ PROGSRC=\ stringutil.cpp \ tempfile.cpp -TESTSRC=\ - test-webserver.cpp \ - googlemock/src/gmock-all.cpp \ - googletest/src/gtest-all.cpp \ - $(PROGSRC) - SRC=$(PROGSRC) all: $(PROJECTNAME).a -# testsuite ---------------------------------------------- -test-$(PROJECTNAME): $(TESTSRC:.cpp=.o) - $(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@ - $(PROJECTNAME).a: $(SRC:.cpp=.o) ar rcs $@ $^ -dep: $(TESTSRC:.cpp=.d) - %.d: %.cpp - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -MM -MP -MF $@ -c $< + $(CXX) $(CXXFLAGS) -MM -MP -MF $@ -c $< %.o: %.cpp %.d - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ - -googletest/src/%.o: googletest/src/%.cc - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ + $(CXX) $(CXXFLAGS) -c $< -o $@ # dependencies @@ -111,8 +94,6 @@ $(DISTROS): deb-src debs: $(DISTROS) clean: - -rm -f test-$(PROJECTNAME) $(PROJECTNAME) - -find . -name '*.a' -o -name '*.o' -o -name '*.so' -o -name '*.d' -o -name '*.gcno' -o -name '*.gcda' | xargs rm -f zip: clean -rm -f ../$(PROJECTNAME).zip diff --git a/libcommon/tempfile.cpp b/libcommon/tempfile.cpp new file mode 100644 index 0000000..5d3a086 --- /dev/null +++ b/libcommon/tempfile.cpp @@ -0,0 +1,27 @@ +#include "tempfile.h" + +#include + +namespace fs = std::filesystem; +using namespace std::string_literals; + +fs::path Tempfile::GetPath() const +{ + return m_path; +} + +Tempfile::Tempfile() { + try { + m_path = std::string{tmpnam(NULL)} + ".zip"s; + } catch (const std::exception& ex) { + throw std::runtime_error("Tempfile error: "s + ex.what()); + } +} + +Tempfile::~Tempfile() { + try { + fs::remove_all(m_path); + } catch (const std::exception& ex) { + std::cerr << "Warning: Couldn't remove temporary file " << m_path << std::endl; + } +} diff --git a/libcommon/tempfile.h b/libcommon/tempfile.h new file mode 100644 index 0000000..5938fb9 --- /dev/null +++ b/libcommon/tempfile.h @@ -0,0 +1,16 @@ +#pragma once + +#include + +class Tempfile +{ + std::filesystem::path m_path; + + public: + std::filesystem::path GetPath() const; + + Tempfile(); + ~Tempfile(); + }; + + diff --git a/plugins/cgi/Makefile b/plugins/cgi/Makefile index a4fdb15..2d86c50 100644 --- a/plugins/cgi/Makefile +++ b/plugins/cgi/Makefile @@ -28,8 +28,6 @@ else CXXFLAGS+=-std=c++17 endif -CXXTESTFLAGS=-Igoogletest/include -Igooglemock/include/ -Igoogletest -Igooglemock - LIBS=\ -lcommon \ -lboost_context \ @@ -62,33 +60,18 @@ LDFLAGS=-L../../libcommon PROGSRC=\ cgi.cpp -TESTSRC=\ - test-webserver.cpp \ - googlemock/src/gmock-all.cpp \ - googletest/src/gtest-all.cpp \ - $(PROGSRC) - SRC=$(PROGSRC) all: $(PROJECTNAME).so -# testsuite ---------------------------------------------- -test-$(PROJECTNAME): $(TESTSRC:.cpp=.o) - $(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@ - $(PROJECTNAME).so: ../../libcommon/libcommon.a $(SRC:.cpp=.o) $(CXX) $(LDFLAGS) $^ -shared $(LDLIBS) $(LIBS) -o $@ -dep: $(TESTSRC:.cpp=.d) - %.d: %.cpp - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -MM -MP -MF $@ -c $< + $(CXX) $(CXXFLAGS) -MM -MP -MF $@ -c $< %.o: %.cpp %.d - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ - -googletest/src/%.o: googletest/src/%.cc - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ + $(CXX) $(CXXFLAGS) -c $< -o $@ # dependencies @@ -112,8 +95,6 @@ $(DISTROS): deb-src debs: $(DISTROS) clean: - -rm -f test-$(PROJECTNAME) $(PROJECTNAME) - -find . -name '*.o' -o -name '*.so' -o -name '*.d' -o -name '*.gcno' -o -name '*.gcda' | xargs rm -f zip: clean -rm -f ../$(PROJECTNAME).zip diff --git a/plugins/fcgi/Makefile b/plugins/fcgi/Makefile index 0cafe54..8937689 100644 --- a/plugins/fcgi/Makefile +++ b/plugins/fcgi/Makefile @@ -28,8 +28,6 @@ else CXXFLAGS+=-std=c++17 endif -CXXTESTFLAGS=-Igoogletest/include -Igooglemock/include/ -Igoogletest -Igooglemock - LIBS=\ -lboost_context \ -lboost_coroutine \ @@ -61,33 +59,18 @@ PROGSRC=\ fcgiid.cpp \ socket.cpp -TESTSRC=\ - test-webserver.cpp \ - googlemock/src/gmock-all.cpp \ - googletest/src/gtest-all.cpp \ - $(PROGSRC) - SRC=$(PROGSRC) all: $(PROJECTNAME).so -# testsuite ---------------------------------------------- -test-$(PROJECTNAME): $(TESTSRC:.cpp=.o) - $(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@ - $(PROJECTNAME).so: $(SRC:.cpp=.o) $(CXX) $(CXXFLAGS) $^ -shared $(LIBS) -o $@ -dep: $(TESTSRC:.cpp=.d) - %.d: %.cpp - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -MM -MP -MF $@ -c $< + $(CXX) $(CXXFLAGS) -MM -MP -MF $@ -c $< %.o: %.cpp %.d - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ - -googletest/src/%.o: googletest/src/%.cc - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ + $(CXX) $(CXXFLAGS) -c $< -o $@ # dependencies @@ -111,8 +94,6 @@ $(DISTROS): deb-src debs: $(DISTROS) clean: - -rm -f test-$(PROJECTNAME) $(PROJECTNAME) - -find . -name '*.o' -o -name '*.so' -o -name '*.d' -o -name '*.gcno' -o -name '*.gcda' | xargs rm -f zip: clean -rm -f ../$(PROJECTNAME).zip diff --git a/plugins/redirect/Makefile b/plugins/redirect/Makefile index 99aedb1..77b496b 100644 --- a/plugins/redirect/Makefile +++ b/plugins/redirect/Makefile @@ -28,8 +28,6 @@ else CXXFLAGS+=-std=c++17 endif -CXXTESTFLAGS=-Igoogletest/include -Igooglemock/include/ -Igoogletest -Igooglemock - LIBS=\ -lboost_context \ -lboost_coroutine \ @@ -59,37 +57,18 @@ endif PROGSRC=\ redirect.cpp -TESTSRC=\ - test-webserver.cpp \ - googlemock/src/gmock-all.cpp \ - googletest/src/gtest-all.cpp \ - $(PROGSRC) - SRC=$(PROGSRC) all: $(PROJECTNAME).so -# testsuite ---------------------------------------------- -test-$(PROJECTNAME): $(TESTSRC:.cpp=.o) - $(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@ - $(PROJECTNAME).so: $(SRC:.cpp=.o) $(CXX) $(CXXFLAGS) $^ -shared $(LIBS) -o $@ -dep: $(TESTSRC:.cpp=.d) - %.d: %.cpp - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -MM -MP -MF $@ -c $< + $(CXX) $(CXXFLAGS) -MM -MP -MF $@ -c $< %.o: %.cpp %.d - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ - -googletest/src/%.o: googletest/src/%.cc - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ - -# dependencies - -ADD_DEP=Makefile + $(CXX) $(CXXFLAGS) -c $< -o $@ install: mkdir -p $(DESTDIR)/usr/lib/webserver/plugins @@ -109,7 +88,7 @@ $(DISTROS): deb-src debs: $(DISTROS) clean: - -rm -f test-$(PROJECTNAME) $(PROJECTNAME) + -rm -f $(PROJECTNAME) -find . -name '*.o' -o -name '*.so' -o -name '*.d' -o -name '*.gcno' -o -name '*.gcda' | xargs rm -f zip: clean diff --git a/plugins/static-files/Makefile b/plugins/static-files/Makefile index 14c6c17..9834e96 100644 --- a/plugins/static-files/Makefile +++ b/plugins/static-files/Makefile @@ -28,8 +28,6 @@ else CXXFLAGS+=-std=c++17 endif -CXXTESTFLAGS=-Igoogletest/include -Igooglemock/include/ -Igoogletest -Igooglemock - LIBS=\ -lcommon \ -lboost_context \ @@ -62,33 +60,18 @@ LDFLAGS=-L../../libcommon PROGSRC=\ static-files.cpp -TESTSRC=\ - test-webserver.cpp \ - googlemock/src/gmock-all.cpp \ - googletest/src/gtest-all.cpp \ - $(PROGSRC) - SRC=$(PROGSRC) all: $(PROJECTNAME).so -# testsuite ---------------------------------------------- -test-$(PROJECTNAME): $(TESTSRC:.cpp=.o) - $(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@ - $(PROJECTNAME).so: ../../libcommon/libcommon.a $(SRC:.cpp=.o) $(CXX) $(LDFLAGS) $^ -shared $(LDLIBS) $(LIBS) -o $@ -dep: $(TESTSRC:.cpp=.d) - %.d: %.cpp - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -MM -MP -MF $@ -c $< + $(CXX) $(CXXFLAGS) -MM -MP -MF $@ -c $< %.o: %.cpp %.d - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ - -googletest/src/%.o: googletest/src/%.cc - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ + $(CXX) $(CXXFLAGS) -c $< -o $@ # dependencies @@ -112,7 +95,7 @@ $(DISTROS): deb-src debs: $(DISTROS) clean: - -rm -f test-$(PROJECTNAME) $(PROJECTNAME) + -rm -f $(PROJECTNAME) -find . -name '*.o' -o -name '*.so' -o -name '*.d' -o -name '*.gcno' -o -name '*.gcda' | xargs rm -f zip: clean diff --git a/plugins/statistics/Makefile b/plugins/statistics/Makefile index 3dee26e..2a0d246 100644 --- a/plugins/statistics/Makefile +++ b/plugins/statistics/Makefile @@ -28,8 +28,6 @@ else CXXFLAGS+=-std=c++17 endif -CXXTESTFLAGS=-Igoogletest/include -Igooglemock/include/ -Igoogletest -Igooglemock - LIBS=\ -lboost_context \ -lboost_coroutine \ @@ -59,37 +57,18 @@ endif PROGSRC=\ statistics.cpp -TESTSRC=\ - test-webserver.cpp \ - googlemock/src/gmock-all.cpp \ - googletest/src/gtest-all.cpp \ - $(PROGSRC) - SRC=$(PROGSRC) all: $(PROJECTNAME).so -# testsuite ---------------------------------------------- -test-$(PROJECTNAME): $(TESTSRC:.cpp=.o) - $(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@ - $(PROJECTNAME).so: $(SRC:.cpp=.o) $(CXX) $(CXXFLAGS) $^ -shared $(LIBS) -o $@ -dep: $(TESTSRC:.cpp=.d) - %.d: %.cpp - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -MM -MP -MF $@ -c $< + $(CXX) $(CXXFLAGS) -MM -MP -MF $@ -c $< %.o: %.cpp %.d - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ - -googletest/src/%.o: googletest/src/%.cc - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ - -# dependencies - -ADD_DEP=Makefile + $(CXX) $(CXXFLAGS) -c $< -o $@ install: mkdir -p $(DESTDIR)/usr/lib/webserver/plugins @@ -109,7 +88,7 @@ $(DISTROS): deb-src debs: $(DISTROS) clean: - -rm -f test-$(PROJECTNAME) $(PROJECTNAME) + -rm -f $(PROJECTNAME) -find . -name '*.o' -o -name '*.so' -o -name '*.d' -o -name '*.gcno' -o -name '*.gcda' | xargs rm -f zip: clean diff --git a/plugins/webbox/Makefile b/plugins/webbox/Makefile index 34f253b..861b5d4 100644 --- a/plugins/webbox/Makefile +++ b/plugins/webbox/Makefile @@ -28,8 +28,6 @@ else CXXFLAGS+=-std=c++17 endif -CXXTESTFLAGS=-Igoogletest/include -Igooglemock/include/ -Igoogletest -Igooglemock - LIBS=\ -lcommon \ -lboost_context \ @@ -62,37 +60,18 @@ LDFLAGS+=-L../../libcommon PROGSRC=\ webbox.cpp -TESTSRC=\ - test-webserver.cpp \ - googlemock/src/gmock-all.cpp \ - googletest/src/gtest-all.cpp \ - $(PROGSRC) - SRC=$(PROGSRC) all: $(PROJECTNAME).so -# testsuite ---------------------------------------------- -test-$(PROJECTNAME): $(TESTSRC:.cpp=.o) - $(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@ - $(PROJECTNAME).so: ../../libcommon/libcommon.a $(SRC:.cpp=.o) $(CXX) $(LDFLAGS) $^ -shared $(LDLIBS) $(LIBS) -o $@ -dep: $(TESTSRC:.cpp=.d) - %.d: %.cpp - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -MM -MP -MF $@ -c $< + $(CXX) $(CXXFLAGS) -MM -MP -MF $@ -c $< %.o: %.cpp %.d - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ - -googletest/src/%.o: googletest/src/%.cc - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ - -# dependencies - -ADD_DEP=Makefile + $(CXX) $(CXXFLAGS) -c $< -o $@ install: mkdir -p $(DESTDIR)/usr/lib/webserver/plugins @@ -120,7 +99,7 @@ $(DISTROS): deb-src debs: $(DISTROS) clean: - -rm -f test-$(PROJECTNAME) $(PROJECTNAME) + -rm -f $(PROJECTNAME) -find . -name '*.o' -o -name '*.so' -o -name '*.d' -o -name '*.gcno' -o -name '*.gcda' | xargs rm -f zip: clean diff --git a/plugins/weblog/Makefile b/plugins/weblog/Makefile index 466ddbd..a21b464 100644 --- a/plugins/weblog/Makefile +++ b/plugins/weblog/Makefile @@ -28,8 +28,6 @@ else CXXFLAGS+=-std=c++17 endif -CXXTESTFLAGS=-Igoogletest/include -Igooglemock/include/ -Igoogletest -Igooglemock - LIBS=\ -lcommon \ -lboost_context \ @@ -62,33 +60,21 @@ LDFLAGS=-L../../libcommon PROGSRC=\ weblog.cpp -TESTSRC=\ - test-webserver.cpp \ - googlemock/src/gmock-all.cpp \ - googletest/src/gtest-all.cpp \ - $(PROGSRC) - SRC=$(PROGSRC) all: $(PROJECTNAME).so -# testsuite ---------------------------------------------- -test-$(PROJECTNAME): $(TESTSRC:.cpp=.o) - $(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@ - $(PROJECTNAME).so: ../../libcommon/libcommon.a $(SRC:.cpp=.o) $(CXX) $(LDFLAGS) $^ -shared $(LDLIBS) $(LIBS) -o $@ -dep: $(TESTSRC:.cpp=.d) - %.d: %.cpp - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -MM -MP -MF $@ -c $< + $(CXX) $(CXXFLAGS) -MM -MP -MF $@ -c $< %.o: %.cpp %.d - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ + $(CXX) $(CXXFLAGS) -c $< -o $@ googletest/src/%.o: googletest/src/%.cc - $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ + $(CXX) $(CXXFLAGS) -c $< -o $@ # dependencies diff --git a/test-webserver.cpp b/test-webserver.cpp deleted file mode 100644 index f7020af..0000000 --- a/test-webserver.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -#include -#include - -#include -#include - -using namespace std::string_literals; -namespace pt = boost::property_tree; - -TEST(property_tree, put) -{ - pt::ptree p; - pt::ptree list; - - pt::ptree entry; - - entry.put_value("name1.txt"); - entry.put(".type", "file1"); - - list.push_back(pt::ptree::value_type("listentry", entry)); - - entry.put_value("name2.txt"); - entry.put(".type", "file2"); - - list.push_back(pt::ptree::value_type("listentry", entry)); - - p.push_back(pt::ptree::value_type("list", list)); - - std::stringstream ss; - - pt::xml_parser::write_xml(ss, p /*, pt::xml_parser::xml_writer_make_settings(' ', 1)*/); - - EXPECT_EQ(ss.str(), "\nname1.txtname2.txt"); -} - - -int main(int argc, char* argv[]) { - ::testing::InitGoogleMock(&argc, argv); - return RUN_ALL_TESTS(); -} - diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..2bccae4 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,112 @@ +DISTROS=debian10 ubuntu1910 ubuntu2004 +PROJECTNAME=test-webserver + +CXX=clang++-10 + +ifeq ($(shell which $(CXX)),) +CXX=clang++ +endif + +ifeq ($(shell which $(CXX)),) +CXX=g++-9 +endif + +ifeq ($(shell which $(CXX)),) +CXX=g++ +endif + +ifeq ($(CXXFLAGS),) +#CXXFLAGS=-O2 -DNDEBUG +CXXFLAGS=-O0 -g -D_DEBUG +endif +# -fprofile-instr-generate -fcoverage-mapping +# gcc:--coverage + +CXXFLAGS+= -Wall -I. -fPIE + +CXXFLAGS+= -pthread +ifeq ($(CXX),clang++-10) +CXXFLAGS+=-std=c++20 #-stdlib=libc++ +else +CXXFLAGS+=-std=c++17 +endif + +CXXTESTFLAGS=-I../googletest/include -I../googlemock/include/ -I../googletest -I../googlemock + +LIBS=\ +-lcommon \ +-lboost_context \ +-lboost_filesystem \ +-lboost_timer \ +-lboost_system \ +-lcrypt \ +-lpthread \ +-lssl -lcrypto \ +-ldl + +#-lboost_coroutine \ +#-lboost_program_options \ +#-lboost_thread \ +#-lboost_regex \ + +ifeq ($(CXX),clang++-10) +LIBS+= \ +-fuse-ld=lld-10 \ +-lstdc++ +#-lc++ \ +#-lc++abi +#-lc++fs +#-lstdc++fs +else +LIBS+= \ +-lstdc++ \ +-lstdc++fs +endif + +LDFLAGS+=-pie -L../libcommon + +TESTSRC=\ + test-webserver.cpp \ + ../googlemock/src/gmock-all.cpp \ + ../googletest/src/gtest-all.cpp \ + $(PROGSRC) + +build: $(PROJECTNAME) + +set -e ; for i in $(PLUGINS) ; do make -C plugins/$$i ; done + ./$(PROJECTNAME) + +all: build + ./webserver -c webserver.conf + +$(PROJECTNAME): ../libcommon/libcommon.a $(TESTSRC:.cpp=.o) + $(CXX) $(LDFLAGS) $^ $(LDLIBS) $(LIBS) -o $@ + +dep: $(TESTSRC:.cpp=.d) + +%.d: %.cpp + $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -MM -MP -MF $@ -c $< + +%.o: %.cpp %.d + $(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ + +install: + mkdir -p $(DESTDIR)/usr/bin + cp webserver $(DESTDIR)/usr/bin + + mkdir -p $(DESTDIR)/usr/lib/webserver/plugins + set -e ; for i in $(PLUGINS) ; do make -C plugins/$$i install ; done + + mkdir -p $(DESTDIR)/usr/local/lib/webserver/plugins + + #mkdir -p $(DESTDIR)/etc + #cp webserver.conf $(DESTDIR)/etc/webserver.conf + +# misc --------------------------------------------------- + +clean: + -rm -f $(PROJECTNAME) + -find . -name '*.o' -o -name '*.d' -o -name '*.gcno' -o -name '*.gcda' | xargs rm -f + +.PHONY: clean all install all $(DISTROS) + +-include $(wildcard $(TESTSRC:.cpp=.d)) diff --git a/tests/test-webserver.cpp b/tests/test-webserver.cpp new file mode 100644 index 0000000..f7020af --- /dev/null +++ b/tests/test-webserver.cpp @@ -0,0 +1,44 @@ +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include +#include + +#include +#include + +using namespace std::string_literals; +namespace pt = boost::property_tree; + +TEST(property_tree, put) +{ + pt::ptree p; + pt::ptree list; + + pt::ptree entry; + + entry.put_value("name1.txt"); + entry.put(".type", "file1"); + + list.push_back(pt::ptree::value_type("listentry", entry)); + + entry.put_value("name2.txt"); + entry.put(".type", "file2"); + + list.push_back(pt::ptree::value_type("listentry", entry)); + + p.push_back(pt::ptree::value_type("list", list)); + + std::stringstream ss; + + pt::xml_parser::write_xml(ss, p /*, pt::xml_parser::xml_writer_make_settings(' ', 1)*/); + + EXPECT_EQ(ss.str(), "\nname1.txtname2.txt"); +} + + +int main(int argc, char* argv[]) { + ::testing::InitGoogleMock(&argc, argv); + return RUN_ALL_TESTS(); +} + -- cgit v1.2.3