summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2023-01-07 14:07:13 +0100
committerRoland Reichwein <mail@reichwein.it>2023-01-07 14:07:13 +0100
commit63fc8e14be5e450df8ccc18fe76e02c5f0827660 (patch)
treed1e37837b277b75e0eb9289b41a47f5dc86b4360 /tests
parent7feaf1a9d7fb09985b9b17cd48fd1aa8eb15d8b3 (diff)
Test statistics
Diffstat (limited to 'tests')
-rw-r--r--tests/test-config.cpp1
-rw-r--r--tests/test-statistics.cpp69
-rw-r--r--tests/test-webserver.cpp1
3 files changed, 69 insertions, 2 deletions
diff --git a/tests/test-config.cpp b/tests/test-config.cpp
index c16c519..fe482f8 100644
--- a/tests/test-config.cpp
+++ b/tests/test-config.cpp
@@ -41,6 +41,7 @@ BOOST_FIXTURE_TEST_CASE(config, ConfigFixture)
<user>user1</user>
<group>www-data</group>
<threads>10</threads>
+ <statisticspath>stats.db</statisticspath>
<!--
<plugin-directory>/usr/lib/webserver/plugins</plugin-directory>
<plugin-directory>/usr/local/lib/webserver/plugins</plugin-directory>
diff --git a/tests/test-statistics.cpp b/tests/test-statistics.cpp
index 9ed7d06..fbc8cfb 100644
--- a/tests/test-statistics.cpp
+++ b/tests/test-statistics.cpp
@@ -6,23 +6,88 @@
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
+#include <filesystem>
#include <sstream>
#include <string>
#include "statistics.h"
+#include "config.h"
+
using namespace std::string_literals;
+namespace fs = std::filesystem;
class StatisticsFixture
{
public:
StatisticsFixture(){}
~StatisticsFixture(){}
- void setup(){}
- void teardown(){}
+ void setup()
+ {
+ std::error_code ec;
+ fs::remove("stats.db", ec);
+ }
+ void teardown()
+ {
+ std::error_code ec;
+ fs::remove("stats.db", ec);
+ }
};
BOOST_FIXTURE_TEST_CASE(statistics, StatisticsFixture)
{
+ {
+ Statistics stats;
+
+ BOOST_CHECK_EQUAL(stats.getValues(), "");
+
+ stats.count(10, 1000, false, true, true);
+
+ auto v{stats.getValues()};
+ BOOST_CHECK_GT(v.size(), 0);
+
+ auto pos{v.find(",")};
+ BOOST_CHECK(pos != std::string::npos);
+ BOOST_CHECK_GT(pos, 0);
+
+ std::string v2{v.substr(pos)};
+
+ BOOST_CHECK_EQUAL(v2, ",1,0,10,1000,1,0,10,1000,1,0,10,1000\n");
+
+ stats.save();
+
+ BOOST_CHECK_EQUAL(v2, ",1,0,10,1000,1,0,10,1000,1,0,10,1000\n");
+ }
+
+ {
+ Statistics stats("stats.db");
+ auto v{stats.getValues()};
+ BOOST_CHECK_GT(v.size(), 0);
+
+ auto pos{v.find(",")};
+ BOOST_CHECK(pos != std::string::npos);
+ BOOST_CHECK_GT(pos, 0);
+
+ std::string v2{v.substr(pos)};
+
+ BOOST_CHECK_EQUAL(v2, ",1,0,10,1000,1,0,10,1000,1,0,10,1000\n");
+
+ stats.count(10, 1000, false, true, true);
+ BOOST_CHECK_EQUAL(stats.getValues().substr(pos), ",2,0,20,2000,2,0,20,2000,2,0,20,2000\n");
+ stats.count(10, 1000, true, true, true);
+ BOOST_CHECK_EQUAL(stats.getValues().substr(pos), ",3,1,30,3000,3,1,30,3000,3,1,30,3000\n");
+ stats.count(10, 1000, false, false, false);
+ BOOST_CHECK_EQUAL(stats.getValues().substr(pos), ",4,1,40,4000,3,1,30,3000,3,1,30,3000\n");
+ stats.count(10, 1000, false, true, false);
+ BOOST_CHECK_EQUAL(stats.getValues().substr(pos), ",5,1,50,5000,4,1,40,4000,3,1,30,3000\n");
+ stats.count(10, 1000, false, false, true);
+ BOOST_CHECK_EQUAL(stats.getValues().substr(pos), ",6,1,60,6000,4,1,40,4000,4,1,40,4000\n");
+ }
+}
+
+BOOST_FIXTURE_TEST_CASE(statistics_non_existing, StatisticsFixture)
+{
+ Statistics stats("nonexistingpath/stats.db");
+ BOOST_CHECK_EQUAL(stats.getValues(), "");
}
diff --git a/tests/test-webserver.cpp b/tests/test-webserver.cpp
index 53aa9cc..ef3b15f 100644
--- a/tests/test-webserver.cpp
+++ b/tests/test-webserver.cpp
@@ -65,6 +65,7 @@ public:
<user>www-data</user>
<group>www-data</group>
<threads>10</threads>
+ <statisticspath>stats.db</sttaisticspath>
<plugin-directory>../plugins</plugin-directory>
<sites>
<site>