diff options
author | Roland Reichwein <mail@reichwein.it> | 2020-05-16 13:28:52 +0200 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2020-05-16 13:28:52 +0200 |
commit | 6b2a9dabbfad4d64268967a32dff0f1dc55763de (patch) | |
tree | b3a1f68d8b44090b98ac3bdcf1c8423ebc08c846 /tests | |
parent | 83b25165218281c2a2e98b5e72a0375a7e6a71ca (diff) |
Makefile cleanup, included missing files
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile | 112 | ||||
-rw-r--r-- | tests/test-webserver.cpp | 44 |
2 files changed, 156 insertions, 0 deletions
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 <boost/property_tree/ptree.hpp> +#include <boost/property_tree/xml_parser.hpp> + +#include <sstream> +#include <string> + +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("<xmlattr>.type", "file1"); + + list.push_back(pt::ptree::value_type("listentry", entry)); + + entry.put_value("name2.txt"); + entry.put("<xmlattr>.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<std::string>(' ', 1)*/); + + EXPECT_EQ(ss.str(), "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<list><listentry type=\"file1\">name1.txt</listentry><listentry type=\"file2\">name2.txt</listentry></list>"); +} + + +int main(int argc, char* argv[]) { + ::testing::InitGoogleMock(&argc, argv); + return RUN_ALL_TESTS(); +} + |