summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rwxr-xr-xMakefile2
-rw-r--r--common.mk1
-rw-r--r--debian/changelog1
-rw-r--r--debian/control2
-rw-r--r--file.cpp46
-rw-r--r--file.h15
-rw-r--r--tests/Makefile5
-rw-r--r--tests/test-config.cpp3
-rw-r--r--tests/test-storage.cpp38
-rw-r--r--whiteboard.cpp3
10 files changed, 29 insertions, 87 deletions
diff --git a/Makefile b/Makefile
index baba6ef..ab1ac3c 100755
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@ DISTROS=base debian11
VERSION=$(shell dpkg-parsechangelog --show-field Version)
INCLUDES=-I.
-HEADERS=file.h config.h qrcode.h storage.h whiteboard.h compiledsql.h
+HEADERS=config.h qrcode.h storage.h whiteboard.h compiledsql.h
SOURCES=$(HEADERS:.h=.cpp)
OBJECTS=$(HEADERS:.h=.o)
TARGETS=whiteboard.fcgi
diff --git a/common.mk b/common.mk
index cffe297..2555a6d 100644
--- a/common.mk
+++ b/common.mk
@@ -63,4 +63,5 @@ endif
CXXFLAGS+=$(shell pkg-config --cflags qrcodegencpp Magick++ fmt sqlite3)
LIBS+=-lfcgi -lboost_filesystem -lpthread
LIBS+=-lSQLiteCpp $(shell pkg-config --libs qrcodegencpp Magick++ fmt sqlite3)
+LIBS+=-lreichwein
diff --git a/debian/changelog b/debian/changelog
index ad9fd1e..8639658 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,6 +2,7 @@ whiteboard (1.4) unstable; urgency=medium
* Move from filesystem based documents to sqlite
* Add tests
+ * Separated out libreichwein
-- Roland Reichwein <mail@reichwein.it> Fri, 30 Dec 2022 13:08:49 +0100
diff --git a/debian/control b/debian/control
index 167e8ad..aecfa97 100644
--- a/debian/control
+++ b/debian/control
@@ -2,7 +2,7 @@ Source: whiteboard
Section: web
Priority: optional
Maintainer: Roland Reichwein <mail@reichwein.it>
-Build-Depends: debhelper (>= 12), libboost-all-dev | libboost1.71-all-dev, clang | g++-9, llvm | g++-9, lld | g++-9, uglifyjs, python3-pkg-resources, htmlmin, cleancss, libfcgi-dev, libqrcodegencpp-dev, libmagick++-dev, pkg-config, libfmt-dev, libsqlitecpp-dev, googletest, gcovr, webserver
+Build-Depends: debhelper (>= 12), libboost-all-dev | libboost1.71-all-dev, clang | g++-9, llvm | g++-9, lld | g++-9, uglifyjs, python3-pkg-resources, htmlmin, cleancss, libfcgi-dev, libqrcodegencpp-dev, libmagick++-dev, pkg-config, libfmt-dev, libsqlitecpp-dev, googletest, gcovr, webserver, libreichwein-dev
Standards-Version: 4.5.0
Homepage: http://www.reichwein.it/whiteboard/
diff --git a/file.cpp b/file.cpp
deleted file mode 100644
index 47ab8be..0000000
--- a/file.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-#include "file.h"
-
-#include <fstream>
-
-namespace fs = std::filesystem;
-
-using namespace std::string_literals;
-
-std::string File::getFile(const fs::path& filename)
-{
- std::ifstream file(filename.string(), std::ios::in | std::ios::binary | std::ios::ate);
-
- if (file.is_open()) {
- std::ifstream::pos_type fileSize = file.tellg();
- file.seekg(0, std::ios::beg);
-
- std::string bytes(fileSize, ' ');
- file.read(reinterpret_cast<char*>(bytes.data()), fileSize);
-
- return bytes;
-
- } else {
- throw std::runtime_error("Opening "s + filename.string() + " for reading");
- }
-}
-
-void File::setFile(const fs::path& filename, const std::string& s)
-{
- File::setFile(filename, s.data(), s.size());
-}
-
-void File::setFile(const fs::path& filename, const char* data, size_t size)
-{
- std::ofstream file(filename.string(), std::ios::out | std::ios::binary);
- if (file.is_open()) {
- file.write(data, size);
- } else {
- throw std::runtime_error("Opening "s + filename.string() + " for writing");
- }
-}
-
-void File::setFile(const fs::path& filename, const std::vector<uint8_t>& data)
-{
- File::setFile(filename, reinterpret_cast<const char*>(data.data()), data.size());
-}
-
diff --git a/file.h b/file.h
deleted file mode 100644
index e7e4cf6..0000000
--- a/file.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#pragma once
-
-#include <cstdint>
-#include <filesystem>
-#include <string>
-#include <vector>
-
-namespace File {
-
-std::string getFile(const std::filesystem::path& filename);
-void setFile(const std::filesystem::path& filename, const std::string& s);
-void setFile(const std::filesystem::path& filename, const char* data, size_t size);
-void setFile(const std::filesystem::path& filename, const std::vector<uint8_t>& data);
-
-}
diff --git a/tests/Makefile b/tests/Makefile
index 4ade005..057eae9 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -11,7 +11,7 @@ CXXFLAGS+=--coverage
LDFLAGS+=--coverage
endif
-UNITS=storage.cpp config.cpp file.cpp compiledsql.cpp qrcode.cpp whiteboard.cpp
+UNITS=storage.cpp config.cpp compiledsql.cpp qrcode.cpp whiteboard.cpp
UNITTESTS=test-config.cpp \
test-storage.cpp
@@ -47,9 +47,6 @@ unittests: libgmock.a $(UNITTESTS:.cpp=.o) $(UNITS:.cpp=.o)
config.o: ../config.cpp
$(CXX) $(CXXFLAGS) -o $@ -c $<
-file.o: ../file.cpp
- $(CXX) $(CXXFLAGS) -o $@ -c $<
-
storage.o: ../storage.cpp
$(CXX) $(CXXFLAGS) -o $@ -c $<
diff --git a/tests/test-config.cpp b/tests/test-config.cpp
index cd358a6..1aafcf9 100644
--- a/tests/test-config.cpp
+++ b/tests/test-config.cpp
@@ -4,8 +4,9 @@
#include <string>
#include <system_error>
+#include "libreichwein/file.h"
+
#include "config.h"
-#include "file.h"
namespace fs = std::filesystem;
diff --git a/tests/test-storage.cpp b/tests/test-storage.cpp
index 158a9bd..b9994fb 100644
--- a/tests/test-storage.cpp
+++ b/tests/test-storage.cpp
@@ -1,11 +1,13 @@
#include <gtest/gtest.h>
#include <filesystem>
+#include <memory>
#include <string>
#include <system_error>
+#include "libreichwein/file.h"
+
#include "config.h"
-#include "file.h"
#include "storage.h"
namespace fs = std::filesystem;
@@ -35,7 +37,7 @@ protected:
std::error_code ec;
fs::remove(testDbFilename, ec);
- m_config = Config{testConfigFilename};
+ m_config = std::make_shared<Config>(testConfigFilename);
}
void TearDown() override
@@ -45,7 +47,7 @@ protected:
fs::remove(testConfigFilename, ec);
}
- Config m_config;
+ std::shared_ptr<Config> m_config;
};
TEST_F(StorageTest, create)
@@ -53,9 +55,9 @@ TEST_F(StorageTest, create)
ASSERT_TRUE(!fs::exists(testDbFilename));
{
- ASSERT_EQ(m_config.getDataPath(), ".");
+ ASSERT_EQ(m_config->getDataPath(), ".");
ASSERT_TRUE(!fs::exists(testDbFilename));
- Storage storage(m_config);
+ Storage storage(*m_config);
}
ASSERT_TRUE(fs::exists(testDbFilename));
@@ -63,7 +65,7 @@ TEST_F(StorageTest, create)
TEST_F(StorageTest, getNumberOfDocuments)
{
- Storage storage(m_config);
+ Storage storage(*m_config);
EXPECT_EQ(storage.getNumberOfDocuments(), 0UL);
storage.setDocument("123", "abc");
EXPECT_EQ(storage.getNumberOfDocuments(), 1UL);
@@ -73,7 +75,7 @@ TEST_F(StorageTest, getNumberOfDocuments)
TEST_F(StorageTest, cleanup_empty)
{
- Storage storage(m_config);
+ Storage storage(*m_config);
EXPECT_EQ(storage.getNumberOfDocuments(), 0UL);
storage.cleanup();
EXPECT_EQ(storage.getNumberOfDocuments(), 0UL);
@@ -81,7 +83,7 @@ TEST_F(StorageTest, cleanup_empty)
TEST_F(StorageTest, cleanup)
{
- Storage storage(m_config);
+ Storage storage(*m_config);
EXPECT_EQ(storage.getNumberOfDocuments(), 0UL);
storage.setDocument("123", "abc");
EXPECT_EQ(storage.getNumberOfDocuments(), 1UL);
@@ -91,7 +93,7 @@ TEST_F(StorageTest, cleanup)
TEST_F(StorageTest, exists)
{
- Storage storage(m_config);
+ Storage storage(*m_config);
EXPECT_EQ(storage.exists(""), false);
EXPECT_EQ(storage.exists("0"), false);
EXPECT_EQ(storage.exists("123"), false);
@@ -109,7 +111,7 @@ TEST_F(StorageTest, exists)
TEST_F(StorageTest, setDocument)
{
- Storage storage(m_config);
+ Storage storage(*m_config);
storage.setDocument("0", "abc");
EXPECT_EQ(storage.getNumberOfDocuments(), 1UL);
EXPECT_EQ(storage.getDocument("0"), "abc");
@@ -117,7 +119,7 @@ TEST_F(StorageTest, setDocument)
TEST_F(StorageTest, setRevision)
{
- Storage storage(m_config);
+ Storage storage(*m_config);
storage.setDocument("0", "abc");
storage.setRevision("0", 123);
@@ -127,7 +129,7 @@ TEST_F(StorageTest, setRevision)
TEST_F(StorageTest, setCursorPos)
{
- Storage storage(m_config);
+ Storage storage(*m_config);
storage.setDocument("0", "abc");
storage.setCursorPos("0", 1234);
@@ -137,7 +139,7 @@ TEST_F(StorageTest, setCursorPos)
TEST_F(StorageTest, setRow)
{
- Storage storage(m_config);
+ Storage storage(*m_config);
storage.setRow("0", "abc", 56, 67);
EXPECT_EQ(storage.getNumberOfDocuments(), 1UL);
@@ -148,7 +150,7 @@ TEST_F(StorageTest, setRow)
TEST_F(StorageTest, getDocument)
{
- Storage storage(m_config);
+ Storage storage(*m_config);
storage.setDocument("0", "xyz");
storage.setDocument("0bc", "xyz2");
storage.setDocument("iabc", "xyz3");
@@ -159,7 +161,7 @@ TEST_F(StorageTest, getDocument)
TEST_F(StorageTest, getRevision)
{
- Storage storage(m_config);
+ Storage storage(*m_config);
storage.setRow("0", "abc", 123, 456);
EXPECT_EQ(storage.getRevision("0"), 123);
@@ -167,7 +169,7 @@ TEST_F(StorageTest, getRevision)
TEST_F(StorageTest, getCursorPos)
{
- Storage storage(m_config);
+ Storage storage(*m_config);
storage.setRow("0", "abc", 123, 456);
EXPECT_EQ(storage.getCursorPos("0"), 456);
@@ -175,7 +177,7 @@ TEST_F(StorageTest, getCursorPos)
TEST_F(StorageTest, getRow)
{
- Storage storage(m_config);
+ Storage storage(*m_config);
storage.setRow("0", "abc", 123, 456);
auto row{storage.getRow("0")};
@@ -186,7 +188,7 @@ TEST_F(StorageTest, getRow)
TEST_F(StorageTest, revision_increment)
{
- Storage storage(m_config);
+ Storage storage(*m_config);
storage.setDocument("0", "xyz");
storage.setDocument("0bc", "xyz2");
storage.setDocument("iabc", "xyz3");
diff --git a/whiteboard.cpp b/whiteboard.cpp
index 48125a8..3abccad 100644
--- a/whiteboard.cpp
+++ b/whiteboard.cpp
@@ -26,8 +26,9 @@
#include <ImageMagick-6/Magick++.h>
+#include "libreichwein/file.h"
+
#include "config.h"
-#include "file.h"
#include "qrcode.h"
#include "storage.h"