summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2022-12-31 13:45:31 +0100
committerRoland Reichwein <mail@reichwein.it>2022-12-31 13:45:31 +0100
commit06a5b6fe71abac44286adf9c9f439ad5a2e3a519 (patch)
treefba06f886db2b116030e2316646ebc83245a94d3
parent921c799f3aa0163cd2eeda5a1c3c8d10d5989e9c (diff)
Added tests
-rw-r--r--Makefile8
-rw-r--r--TODO2
-rw-r--r--common.mk10
-rw-r--r--main.cpp10
-rw-r--r--tests/Makefile1
-rw-r--r--tests/test-environment.cpp48
-rw-r--r--tests/test-webserver.cpp38
-rw-r--r--webserver.cpp2
-rw-r--r--webserver.h4
9 files changed, 91 insertions, 32 deletions
diff --git a/Makefile b/Makefile
index 87d9240..94bbe46 100644
--- a/Makefile
+++ b/Makefile
@@ -45,9 +45,10 @@ PROGSRC=\
privileges.cpp \
response.cpp \
statistics.cpp \
- server.cpp
+ server.cpp \
+ webserver.cpp
-SRC=$(PROGSRC) webserver.cpp
+SRC=$(PROGSRC) main.cpp
build: $(PROJECTNAME) $(PLUGINS)
@@ -131,6 +132,7 @@ DISTFILES= \
http.h \
https.cpp \
https.h \
+ main.cpp \
os.cpp \
os.h \
plugin.cpp \
@@ -145,7 +147,9 @@ DISTFILES= \
statistics.cpp \
statistics.h \
tests/Makefile \
+ tests/test-environment.cpp \
tests/test-webserver.cpp \
+ webserver.h \
webserver.cpp \
webserver.1 \
README.txt \
diff --git a/TODO b/TODO
index ae2b5ef..1131af1 100644
--- a/TODO
+++ b/TODO
@@ -1,3 +1,5 @@
+Big file bug
+
stats.png
cgi unhandled headers
git via smart http / cgi
diff --git a/common.mk b/common.mk
index 8df3809..fa3d023 100644
--- a/common.mk
+++ b/common.mk
@@ -1,4 +1,8 @@
+CXX=clang++-14
+
+ifeq ($(shell which $(CXX)),)
CXX=clang++-13
+endif
ifeq ($(shell which $(CXX)),)
CXX=clang++-11
@@ -51,6 +55,8 @@ CXXFLAGS+=-DYEAR=\"$(YEAR)\"
CXXFLAGS+=-pthread
ifeq ($(CXX),clang++-11)
CXXFLAGS+=-std=c++20 #-stdlib=libc++
+else ifeq ($(CXX),clang++-14)
+CXXFLAGS+=-std=c++2b #-stdlib=libc++
else ifeq ($(CXX),clang++-13)
CXXFLAGS+=-std=c++2b #-stdlib=libc++
else ifeq ($(CXX),g++-11)
@@ -67,6 +73,10 @@ LIBS+= \
#-lc++abi
#-lc++fs
#-lstdc++fs
+else ifeq ($(CXX),clang++-14)
+LIBS+= \
+-fuse-ld=lld-14 \
+-lstdc++
else ifeq ($(CXX),clang++-13)
LIBS+= \
-fuse-ld=lld-13 \
diff --git a/main.cpp b/main.cpp
new file mode 100644
index 0000000..c0e1884
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,10 @@
+// The webserver main() function. The actual webserver resides in
+// webserver.cpp as webserver() for testability.
+
+#include "webserver.h"
+
+int main(int argc, char* argv[])
+{
+ return webserver(argc, argv);
+}
+
diff --git a/tests/Makefile b/tests/Makefile
index 1785e09..5903b52 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -20,6 +20,7 @@ LIBS=\
LDFLAGS+=-pie -L../libcommon
TESTSRC=\
+ test-environment.cpp \
test-webserver.cpp \
$(PROGSRC)
diff --git a/tests/test-environment.cpp b/tests/test-environment.cpp
new file mode 100644
index 0000000..da8e4e0
--- /dev/null
+++ b/tests/test-environment.cpp
@@ -0,0 +1,48 @@
+#include <boost/test/unit_test.hpp>
+#include <boost/test/data/dataset.hpp>
+#include <boost/test/data/monomorphic.hpp>
+#include <boost/test/data/test_case.hpp>
+
+#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 ptree construction and xml serialization
+BOOST_AUTO_TEST_CASE(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)*/);
+
+ BOOST_CHECK_EQUAL(ss.str(), "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<list><listentry type=\"file1\">name1.txt</listentry><listentry type=\"file2\">name2.txt</listentry></list>");
+}
+
+// test std::stoul for negative numbers
+BOOST_AUTO_TEST_CASE(string_stoul)
+{
+ unsigned long l = std::stoul("-1");
+
+ BOOST_CHECK_EQUAL(l, std::numeric_limits<unsigned long>::max());
+}
diff --git a/tests/test-webserver.cpp b/tests/test-webserver.cpp
index 7683b93..1668c60 100644
--- a/tests/test-webserver.cpp
+++ b/tests/test-webserver.cpp
@@ -1,6 +1,8 @@
+// Main unit test compilation unit
+// boost mandates that exactly one compilation unit contains the following two lines:
#define BOOST_TEST_MODULE webserver_test
-
#include <boost/test/included/unit_test.hpp>
+
#include <boost/test/data/dataset.hpp>
#include <boost/test/data/monomorphic.hpp>
#include <boost/test/data/test_case.hpp>
@@ -14,35 +16,13 @@
using namespace std::string_literals;
namespace pt = boost::property_tree;
-BOOST_AUTO_TEST_CASE(property_tree_put)
+class Fixture
{
- 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));
+public:
+ Fixture(){}
+ ~Fixture(){}
+};
- std::stringstream ss;
-
- pt::xml_parser::write_xml(ss, p /*, pt::xml_parser::xml_writer_make_settings<std::string>(' ', 1)*/);
-
- BOOST_CHECK_EQUAL(ss.str(), "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<list><listentry type=\"file1\">name1.txt</listentry><listentry type=\"file2\">name2.txt</listentry></list>");
-}
-
-BOOST_AUTO_TEST_CASE(string_stoul)
+BOOST_FIXTURE_TEST_CASE(http_download, Fixture)
{
- unsigned long l = std::stoul("-1");
-
- BOOST_CHECK_EQUAL(l, std::numeric_limits<unsigned long>::max());
}
diff --git a/webserver.cpp b/webserver.cpp
index e848fd1..4591fc9 100644
--- a/webserver.cpp
+++ b/webserver.cpp
@@ -24,7 +24,7 @@ void initlocale() {
}
}
-int main(int argc, char* argv[])
+int webserver(int argc, char* argv[])
{
try {
//initlocale(); // TODO: breaks plugins
diff --git a/webserver.h b/webserver.h
new file mode 100644
index 0000000..fa9f1c2
--- /dev/null
+++ b/webserver.h
@@ -0,0 +1,4 @@
+#pragma once
+
+int webserver(int argc, char* argv[]);
+