diff --git a/.idea/.gitignore b/.idea/.gitignore
deleted file mode 100644
index 13566b8..0000000
--- a/.idea/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
-# Editor-based HTTP Client requests
-/httpRequests/
-# Datasource local storage ignored files
-/dataSources/
-/dataSources.local.xml
diff --git a/.idea/.name b/.idea/.name
deleted file mode 100644
index 0710b69..0000000
--- a/.idea/.name
+++ /dev/null
@@ -1 +0,0 @@
-sembackup
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index afe2bde..2949565 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,18 +11,9 @@ add_link_options(-Ofast)
#add_link_options(-fsanitize=address -fsanitize=undefined -fno-sanitize-recover)
#add_link_options(-rdynamic)
-project(sembackup)
+project(backup)
-set(CMAKE_CXX_STANDARD 17)
+enable_testing()
-find_package(OpenSSL REQUIRED)
-find_package(ZLIB REQUIRED)
-
-add_executable(sembackup src/Config.cpp src/main.cpp src/repo/Object.cpp src/repo/Object.h src/repo/Repository.cpp src/repo/Repository.h src/repo/FileRepository.cpp src/repo/FileRepository.h src/repo/objects/Archive.cpp src/repo/objects/Archive.h src/repo/objects/File.cpp src/repo/objects/File.h src/repo/objects/Chunk.cpp src/repo/objects/Chunk.h src/repo/Serialize.h src/chunkers/Chunker.cpp src/chunkers/Chunker.h src/chunkers/ConstChunker.cpp src/chunkers/ConstChunker.h src/crypto/MD5.cpp src/crypto/MD5.h src/change_detectors/ChangeDetector.cpp src/change_detectors/ChangeDetector.h src/change_detectors/SizeChangeDetector.cpp src/change_detectors/SizeChangeDetector.h src/change_detectors/EditTimeChangeDetector.cpp src/change_detectors/EditTimeChangeDetector.h src/change_detectors/ChangeDetectorFactory.cpp src/change_detectors/ChangeDetectorFactory.h src/Signals.h src/Signals.cpp src/filters/Filter.cpp src/filters/Filter.h src/filters/FilterShift.cpp src/filters/FilterShift.h src/filters/FilterShiftSecret.cpp src/filters/FilterShiftSecret.h src/repo/objects/FileBuffer.cpp src/repo/objects/FileBuffer.h src/filters/FilterZlib.cpp src/filters/FilterZlib.h src/filters/FilterAES.cpp src/filters/FilterAES.h src/chunkers/BuzhashChunker.cpp src/chunkers/BuzhashChunker.h src/chunkers/Buzhash.cpp src/chunkers/Buzhash.h src/crypto/AES.cpp src/crypto/AES.h src/chunkers/ChunkerFactory.cpp src/chunkers/ChunkerFactory.h src/Exception.cpp src/Exception.h src/filters/FilterFactory.h src/filters/FilterContainer.h src/filters/FilterFactory.cpp src/filters/FilterContainer.cpp src/change_detectors/ChangeDetectorContainer.cpp src/change_detectors/ChangeDetectorContainer.h src/Progress.cpp src/Progress.h src/change_detectors/ContentsChangeDetector.cpp src/change_detectors/ContentsChangeDetector.h src/change_detectors/ComparableFile.cpp src/change_detectors/ComparableFile.h src/RunningAverage.cpp src/RunningAverage.h src/Diff.cpp src/Diff.h src/ThreadPool.cpp src/filters/CheckFilter.cpp src/filters/CheckFilter.h src/crypto/CRC32.cpp src/crypto/CRC32.h src/change_detectors/TypeChangeDetector.cpp src/change_detectors/TypeChangeDetector.h src/RunningDiffAverage.cpp src/RunningDiffAverage.h src/BytesFormatter.cpp src/BytesFormatter.h src/Logger.cpp src/Logger.h src/Context.h src/commands/Command.cpp src/commands/Command.h src/commands/CommandRun.cpp src/commands/CommandRun.h src/commands/CommandsCommon.cpp src/commands/CommandsCommon.h src/commands/CommandRestore.cpp src/commands/CommandRestore.h src/commands/CommandDiff.cpp src/commands/CommandDiff.h src/commands/CommandList.cpp src/commands/CommandList.h src/commands/CommandListFiles.cpp src/commands/CommandListFiles.h)
-add_executable(test src/Config.cpp src/crypto/MD5.cpp src/change_detectors/EditTimeChangeDetector.cpp tests/runTests.cpp tests/utils/Runnable.cpp tests/utils/HelpfulAssertTest.cpp tests/utils/HelpfulAssertTest.h tests/utils/TestGroup.cpp tests/utils/TestGroup.h tests/utils/Test.cpp tests/utils/Test.h tests/utils/TestGroupGenerator.h src/repo/Object.cpp src/repo/Object.h src/repo/Repository.cpp src/repo/Repository.h src/repo/FileRepository.cpp src/repo/FileRepository.h src/repo/objects/Archive.cpp src/repo/objects/Archive.h src/repo/objects/File.cpp src/repo/objects/File.h src/repo/objects/Chunk.cpp src/repo/objects/Chunk.h tests/repo/ChunkTest.cpp tests/repo/ChunkTest.h tests/repo/FileRepositoryTest.cpp tests/repo/FileRepositoryTest.h tests/utils/Cleaner.cpp tests/utils/Cleaner.h src/repo/Serialize.h src/chunkers/Chunker.cpp src/chunkers/Chunker.h src/chunkers/ConstChunker.cpp src/chunkers/ConstChunker.h tests/crypto/MD5Test.cpp tests/crypto/MD5Test.h tests/fulltests/FullTest.cpp tests/fulltests/FullTest.h src/change_detectors/ChangeDetector.cpp src/change_detectors/ChangeDetector.h src/change_detectors/SizeChangeDetector.cpp src/change_detectors/SizeChangeDetector.h src/change_detectors/ChangeDetectorFactory.cpp src/change_detectors/ChangeDetectorFactory.h src/filters/Filter.cpp src/filters/Filter.h src/filters/FilterShift.cpp src/filters/FilterShift.h src/filters/FilterShiftSecret.cpp src/filters/FilterShiftSecret.h src/repo/objects/FileBuffer.cpp src/repo/objects/FileBuffer.h src/filters/FilterZlib.cpp src/filters/FilterZlib.h src/filters/FilterAES.cpp src/filters/FilterAES.h src/chunkers/BuzhashChunker.cpp src/chunkers/BuzhashChunker.h src/chunkers/Buzhash.cpp src/chunkers/Buzhash.h tests/BuzhashTest.cpp tests/BuzhashTest.h src/crypto/AES.cpp src/crypto/AES.h tests/crypto/AESTest.cpp tests/crypto/AESTest.h src/chunkers/ChunkerFactory.cpp src/chunkers/ChunkerFactory.h src/Exception.cpp src/Exception.h src/filters/FilterFactory.h src/filters/FilterContainer.h src/filters/FilterFactory.cpp src/filters/FilterContainer.cpp src/change_detectors/ChangeDetectorContainer.cpp src/change_detectors/ChangeDetectorContainer.h src/Progress.cpp src/Progress.h src/change_detectors/ContentsChangeDetector.cpp src/change_detectors/ContentsChangeDetector.h src/change_detectors/ComparableFile.cpp src/change_detectors/ComparableFile.h src/RunningAverage.cpp src/RunningAverage.h src/Diff.cpp src/Diff.h src/ThreadPool.cpp tests/CLITestWrapper.cpp tests/CLITestWrapper.h src/filters/CheckFilter.cpp src/filters/CheckFilter.h src/crypto/CRC32.cpp src/crypto/CRC32.h src/change_detectors/TypeChangeDetector.cpp src/change_detectors/TypeChangeDetector.h src/RunningDiffAverage.cpp src/RunningDiffAverage.h src/BytesFormatter.cpp src/BytesFormatter.h src/Logger.cpp src/Logger.h src/Context.h src/commands/Command.cpp src/commands/Command.h src/commands/CommandRun.cpp src/commands/CommandRun.h src/commands/CommandsCommon.cpp src/commands/CommandsCommon.h src/commands/CommandRestore.cpp src/commands/CommandRestore.h src/commands/CommandList.cpp src/commands/CommandList.h src/commands/CommandListFiles.cpp src/commands/CommandListFiles.h)
-
-add_dependencies(test sembackup)
-
-target_link_libraries(sembackup OpenSSL::SSL ZLIB::ZLIB)
-target_link_libraries(test OpenSSL::SSL ZLIB::ZLIB)
-target_compile_definitions(test PUBLIC TEST)
\ No newline at end of file
+add_subdirectory(src)
+add_subdirectory(tests)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..397898b
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,15 @@
+cmake_minimum_required(VERSION 3.22)
+
+set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
+add_subdirectory(change_detectors)
+add_subdirectory(chunkers)
+add_subdirectory(commands)
+add_subdirectory(crypto)
+add_subdirectory(filters)
+add_subdirectory(repo)
+add_subdirectory(utils)
+
+add_executable(backup main.cpp)
+target_link_libraries(backup PRIVATE change_detectors chunkers commands crypto filters repo utils)
\ No newline at end of file
diff --git a/src/change_detectors/CMakeLists.txt b/src/change_detectors/CMakeLists.txt
new file mode 100644
index 0000000..4f28004
--- /dev/null
+++ b/src/change_detectors/CMakeLists.txt
@@ -0,0 +1,7 @@
+cmake_minimum_required(VERSION 3.22)
+
+add_library(change_detectors srcs/ChangeDetector.cpp srcs/ChangeDetectorContainer.cpp srcs/ChangeDetectorFactory.cpp srcs/ComparableFile.cpp srcs/ContentsChangeDetector.cpp srcs/EditTimeChangeDetector.cpp srcs/SizeChangeDetector.cpp srcs/TypeChangeDetector.cpp)
+
+target_include_directories(change_detectors PUBLIC includes)
+
+target_link_libraries(change_detectors utils)
diff --git a/src/change_detectors/ChangeDetector.h b/src/change_detectors/includes/ChangeDetector.h
similarity index 100%
rename from src/change_detectors/ChangeDetector.h
rename to src/change_detectors/includes/ChangeDetector.h
diff --git a/src/change_detectors/ChangeDetectorContainer.h b/src/change_detectors/includes/ChangeDetectorContainer.h
similarity index 100%
rename from src/change_detectors/ChangeDetectorContainer.h
rename to src/change_detectors/includes/ChangeDetectorContainer.h
diff --git a/src/change_detectors/ChangeDetectorFactory.h b/src/change_detectors/includes/ChangeDetectorFactory.h
similarity index 98%
rename from src/change_detectors/ChangeDetectorFactory.h
rename to src/change_detectors/includes/ChangeDetectorFactory.h
index 30221b5..9445ed3 100644
--- a/src/change_detectors/ChangeDetectorFactory.h
+++ b/src/change_detectors/includes/ChangeDetectorFactory.h
@@ -8,9 +8,9 @@
#include
#include
-#include "../Config.h"
#include "ChangeDetector.h"
#include "ChangeDetectorContainer.h"
+#include "Config.h"
/// Factory class for ChangeDetector
/** Can create either a vector of ChangeDetector%s according to Config,
diff --git a/src/change_detectors/ComparableFile.h b/src/change_detectors/includes/ComparableFile.h
similarity index 96%
rename from src/change_detectors/ComparableFile.h
rename to src/change_detectors/includes/ComparableFile.h
index fe45590..4282046 100644
--- a/src/change_detectors/ComparableFile.h
+++ b/src/change_detectors/includes/ComparableFile.h
@@ -9,8 +9,8 @@
#include
#include
-#include "../repo/Repository.h"
-#include "../repo/objects/File.h"
+#include "../../repo/includes/Repository.h"
+#include "../../repo/includes/objects/File.h"
/// Helper class to allow comparing files from different sources
/**
diff --git a/src/change_detectors/ContentsChangeDetector.h b/src/change_detectors/includes/ContentsChangeDetector.h
similarity index 100%
rename from src/change_detectors/ContentsChangeDetector.h
rename to src/change_detectors/includes/ContentsChangeDetector.h
diff --git a/src/change_detectors/EditTimeChangeDetector.h b/src/change_detectors/includes/EditTimeChangeDetector.h
similarity index 100%
rename from src/change_detectors/EditTimeChangeDetector.h
rename to src/change_detectors/includes/EditTimeChangeDetector.h
diff --git a/src/change_detectors/SizeChangeDetector.h b/src/change_detectors/includes/SizeChangeDetector.h
similarity index 100%
rename from src/change_detectors/SizeChangeDetector.h
rename to src/change_detectors/includes/SizeChangeDetector.h
diff --git a/src/change_detectors/TypeChangeDetector.h b/src/change_detectors/includes/TypeChangeDetector.h
similarity index 100%
rename from src/change_detectors/TypeChangeDetector.h
rename to src/change_detectors/includes/TypeChangeDetector.h
diff --git a/src/change_detectors/ChangeDetector.cpp b/src/change_detectors/srcs/ChangeDetector.cpp
similarity index 70%
rename from src/change_detectors/ChangeDetector.cpp
rename to src/change_detectors/srcs/ChangeDetector.cpp
index 1c7cb2d..1a7c8c1 100644
--- a/src/change_detectors/ChangeDetector.cpp
+++ b/src/change_detectors/srcs/ChangeDetector.cpp
@@ -2,6 +2,6 @@
// Created by Stepan Usatiuk on 16.04.2023.
//
-#include "ChangeDetector.h"
+#include "../includes/ChangeDetector.h"
ChangeDetector::~ChangeDetector() = default;
diff --git a/src/change_detectors/ChangeDetectorContainer.cpp b/src/change_detectors/srcs/ChangeDetectorContainer.cpp
similarity index 91%
rename from src/change_detectors/ChangeDetectorContainer.cpp
rename to src/change_detectors/srcs/ChangeDetectorContainer.cpp
index 8853456..760f441 100644
--- a/src/change_detectors/ChangeDetectorContainer.cpp
+++ b/src/change_detectors/srcs/ChangeDetectorContainer.cpp
@@ -2,7 +2,7 @@
// Created by Stepan Usatiuk on 04.05.2023.
//
-#include "ChangeDetectorContainer.h"
+#include "../includes/ChangeDetectorContainer.h"
#include
diff --git a/src/change_detectors/ChangeDetectorFactory.cpp b/src/change_detectors/srcs/ChangeDetectorFactory.cpp
similarity index 79%
rename from src/change_detectors/ChangeDetectorFactory.cpp
rename to src/change_detectors/srcs/ChangeDetectorFactory.cpp
index 6fe4e49..e1e1b04 100644
--- a/src/change_detectors/ChangeDetectorFactory.cpp
+++ b/src/change_detectors/srcs/ChangeDetectorFactory.cpp
@@ -2,15 +2,15 @@
// Created by Stepan Usatiuk on 16.04.2023.
//
-#include "ChangeDetectorFactory.h"
+#include "../includes/ChangeDetectorFactory.h"
#include
-#include "../Exception.h"
-#include "ContentsChangeDetector.h"
-#include "EditTimeChangeDetector.h"
-#include "SizeChangeDetector.h"
-#include "TypeChangeDetector.h"
+#include "../includes/ContentsChangeDetector.h"
+#include "../includes/EditTimeChangeDetector.h"
+#include "../includes/SizeChangeDetector.h"
+#include "../includes/TypeChangeDetector.h"
+#include "Exception.h"
std::unique_ptr ChangeDetectorFactory::getChangeDetector(const std::string &type) {
if (type == "etime") {
diff --git a/src/change_detectors/ComparableFile.cpp b/src/change_detectors/srcs/ComparableFile.cpp
similarity index 91%
rename from src/change_detectors/ComparableFile.cpp
rename to src/change_detectors/srcs/ComparableFile.cpp
index 473be47..dbb899c 100644
--- a/src/change_detectors/ComparableFile.cpp
+++ b/src/change_detectors/srcs/ComparableFile.cpp
@@ -3,13 +3,13 @@
//
-#include "ComparableFile.h"
+#include "../includes/ComparableFile.h"
#include
#include
-#include "../Exception.h"
-#include "../repo/objects/FileBuffer.h"
+#include "../../repo/includes/objects/FileBuffer.h"
+#include "../../utils/includes/Exception.h"
ComparableFile::ComparableFile(const File &file, const Repository *repo)
: path(file.name),
diff --git a/src/change_detectors/ContentsChangeDetector.cpp b/src/change_detectors/srcs/ContentsChangeDetector.cpp
similarity index 91%
rename from src/change_detectors/ContentsChangeDetector.cpp
rename to src/change_detectors/srcs/ContentsChangeDetector.cpp
index 3749c47..a6987b2 100644
--- a/src/change_detectors/ContentsChangeDetector.cpp
+++ b/src/change_detectors/srcs/ContentsChangeDetector.cpp
@@ -2,7 +2,7 @@
// Created by Stepan Usatiuk on 05.05.2023.
//
-#include "ContentsChangeDetector.h"
+#include "../includes/ContentsChangeDetector.h"
#include
diff --git a/src/change_detectors/EditTimeChangeDetector.cpp b/src/change_detectors/srcs/EditTimeChangeDetector.cpp
similarity index 79%
rename from src/change_detectors/EditTimeChangeDetector.cpp
rename to src/change_detectors/srcs/EditTimeChangeDetector.cpp
index d0716af..b880dfc 100644
--- a/src/change_detectors/EditTimeChangeDetector.cpp
+++ b/src/change_detectors/srcs/EditTimeChangeDetector.cpp
@@ -2,7 +2,7 @@
// Created by Stepan Usatiuk on 16.04.2023.
//
-#include "EditTimeChangeDetector.h"
+#include "../includes/EditTimeChangeDetector.h"
bool EditTimeChangeDetector::check(const ComparableFile &f1, const ComparableFile &f2) const {
return f1.mtime != f2.mtime;
diff --git a/src/change_detectors/SizeChangeDetector.cpp b/src/change_detectors/srcs/SizeChangeDetector.cpp
similarity index 80%
rename from src/change_detectors/SizeChangeDetector.cpp
rename to src/change_detectors/srcs/SizeChangeDetector.cpp
index 5cd0fb5..591030e 100644
--- a/src/change_detectors/SizeChangeDetector.cpp
+++ b/src/change_detectors/srcs/SizeChangeDetector.cpp
@@ -2,7 +2,7 @@
// Created by Stepan Usatiuk on 16.04.2023.
//
-#include "SizeChangeDetector.h"
+#include "../includes/SizeChangeDetector.h"
bool SizeChangeDetector::check(const ComparableFile &f1, const ComparableFile &f2) const {
return f1.bytes != f2.bytes;
diff --git a/src/change_detectors/TypeChangeDetector.cpp b/src/change_detectors/srcs/TypeChangeDetector.cpp
similarity index 80%
rename from src/change_detectors/TypeChangeDetector.cpp
rename to src/change_detectors/srcs/TypeChangeDetector.cpp
index 3ef9d3a..4b9bc51 100644
--- a/src/change_detectors/TypeChangeDetector.cpp
+++ b/src/change_detectors/srcs/TypeChangeDetector.cpp
@@ -2,7 +2,7 @@
// Created by Stepan Usatiuk on 12.05.2023.
//
-#include "TypeChangeDetector.h"
+#include "../includes/TypeChangeDetector.h"
bool TypeChangeDetector::check(const ComparableFile &f1, const ComparableFile &f2) const {
return f1.type != f2.type;
diff --git a/src/chunkers/CMakeLists.txt b/src/chunkers/CMakeLists.txt
new file mode 100644
index 0000000..8b4a8b5
--- /dev/null
+++ b/src/chunkers/CMakeLists.txt
@@ -0,0 +1,7 @@
+cmake_minimum_required(VERSION 3.22)
+
+add_library(chunkers srcs/Buzhash.cpp srcs/BuzhashChunker.cpp srcs/Chunker.cpp srcs/ChunkerFactory.cpp srcs/ConstChunker.cpp)
+
+target_include_directories(chunkers PUBLIC includes)
+
+target_link_libraries(chunkers crypto)
\ No newline at end of file
diff --git a/src/chunkers/Buzhash.h b/src/chunkers/includes/Buzhash.h
similarity index 100%
rename from src/chunkers/Buzhash.h
rename to src/chunkers/includes/Buzhash.h
diff --git a/src/chunkers/BuzhashChunker.h b/src/chunkers/includes/BuzhashChunker.h
similarity index 100%
rename from src/chunkers/BuzhashChunker.h
rename to src/chunkers/includes/BuzhashChunker.h
diff --git a/src/chunkers/Chunker.h b/src/chunkers/includes/Chunker.h
similarity index 100%
rename from src/chunkers/Chunker.h
rename to src/chunkers/includes/Chunker.h
diff --git a/src/chunkers/ChunkerFactory.h b/src/chunkers/includes/ChunkerFactory.h
similarity index 94%
rename from src/chunkers/ChunkerFactory.h
rename to src/chunkers/includes/ChunkerFactory.h
index 687cd9a..8e51929 100644
--- a/src/chunkers/ChunkerFactory.h
+++ b/src/chunkers/includes/ChunkerFactory.h
@@ -8,7 +8,7 @@
#include
#include
-#include "../Config.h"
+#include "../../utils/includes/Config.h"
#include "Chunker.h"
/// Factory for Chunker%s
diff --git a/src/chunkers/ConstChunker.h b/src/chunkers/includes/ConstChunker.h
similarity index 100%
rename from src/chunkers/ConstChunker.h
rename to src/chunkers/includes/ConstChunker.h
diff --git a/src/chunkers/Buzhash.cpp b/src/chunkers/srcs/Buzhash.cpp
similarity index 95%
rename from src/chunkers/Buzhash.cpp
rename to src/chunkers/srcs/Buzhash.cpp
index cb95bad..e83cc27 100644
--- a/src/chunkers/Buzhash.cpp
+++ b/src/chunkers/srcs/Buzhash.cpp
@@ -2,7 +2,7 @@
// Created by Stepan Usatiuk on 26.04.2023.
//
-#include "Buzhash.h"
+#include "../includes/Buzhash.h"
Buzhash::Buzhash(uint32_t blockSize) : blockSize(blockSize), history() {}
diff --git a/src/chunkers/BuzhashChunker.cpp b/src/chunkers/srcs/BuzhashChunker.cpp
similarity index 91%
rename from src/chunkers/BuzhashChunker.cpp
rename to src/chunkers/srcs/BuzhashChunker.cpp
index 78584c1..0b02f7e 100644
--- a/src/chunkers/BuzhashChunker.cpp
+++ b/src/chunkers/srcs/BuzhashChunker.cpp
@@ -2,10 +2,10 @@
// Created by Stepan Usatiuk on 26.04.2023.
//
-#include "BuzhashChunker.h"
+#include "../includes/BuzhashChunker.h"
-#include "../Exception.h"
-#include "../crypto/MD5.h"
+#include "../../crypto/includes/MD5.h"
+#include "../../utils/includes/Exception.h"
BuzhashChunker::BuzhashChunker(std::streambuf *buf, unsigned long long minBytes, unsigned long long maxBytes, unsigned long long mask, uint32_t window) : Chunker(buf, maxBytes), window(window), minBytes(minBytes), mask(mask), buzhash(window) {}
diff --git a/src/chunkers/Chunker.cpp b/src/chunkers/srcs/Chunker.cpp
similarity index 94%
rename from src/chunkers/Chunker.cpp
rename to src/chunkers/srcs/Chunker.cpp
index 4905df5..cff255f 100644
--- a/src/chunkers/Chunker.cpp
+++ b/src/chunkers/srcs/Chunker.cpp
@@ -2,9 +2,9 @@
// Created by Stepan Usatiuk on 15.04.2023.
//
-#include "Chunker.h"
+#include "../includes/Chunker.h"
-#include "../Exception.h"
+#include "../../utils/includes/Exception.h"
Chunker::Chunker(std::streambuf *buf, unsigned long long maxBytes) : buf(buf), maxBytes(maxBytes) {}
diff --git a/src/chunkers/ChunkerFactory.cpp b/src/chunkers/srcs/ChunkerFactory.cpp
similarity index 77%
rename from src/chunkers/ChunkerFactory.cpp
rename to src/chunkers/srcs/ChunkerFactory.cpp
index e19cb6b..ac4b854 100644
--- a/src/chunkers/ChunkerFactory.cpp
+++ b/src/chunkers/srcs/ChunkerFactory.cpp
@@ -2,11 +2,11 @@
// Created by Stepan Usatiuk on 30.04.2023.
//
-#include "ChunkerFactory.h"
+#include "../includes/ChunkerFactory.h"
-#include "../Exception.h"
-#include "BuzhashChunker.h"
-#include "ConstChunker.h"
+#include "../../utils/includes/Exception.h"
+#include "../includes/BuzhashChunker.h"
+#include "../includes/ConstChunker.h"
std::unique_ptr ChunkerFactory::getChunker(const Config &config, std::streambuf *buf) {
if (config.getStr("chunker") == "const") {
diff --git a/src/chunkers/ConstChunker.cpp b/src/chunkers/srcs/ConstChunker.cpp
similarity index 82%
rename from src/chunkers/ConstChunker.cpp
rename to src/chunkers/srcs/ConstChunker.cpp
index 08ab6fb..f41e1b5 100644
--- a/src/chunkers/ConstChunker.cpp
+++ b/src/chunkers/srcs/ConstChunker.cpp
@@ -2,10 +2,10 @@
// Created by Stepan Usatiuk on 15.04.2023.
//
-#include "ConstChunker.h"
+#include "../includes/ConstChunker.h"
-#include "../Exception.h"
-#include "../crypto/MD5.h"
+#include "../../crypto/includes/MD5.h"
+#include "../../utils/includes/Exception.h"
ConstChunker::ConstChunker(std::streambuf *buf, unsigned long long maxBytes) : Chunker(buf, maxBytes) {}
diff --git a/src/commands/CMakeLists.txt b/src/commands/CMakeLists.txt
new file mode 100644
index 0000000..975a83e
--- /dev/null
+++ b/src/commands/CMakeLists.txt
@@ -0,0 +1,7 @@
+cmake_minimum_required(VERSION 3.22)
+
+add_library(commands srcs/Command.cpp srcs/CommandDiff.cpp srcs/CommandList.cpp srcs/CommandListFiles.cpp srcs/CommandRestore.cpp srcs/CommandRun.cpp srcs/CommandsCommon.cpp srcs/Diff.cpp)
+
+target_include_directories(commands PUBLIC includes)
+
+target_link_libraries(commands crypto repo chunkers utils change_detectors)
diff --git a/src/commands/Command.h b/src/commands/includes/Command.h
similarity index 95%
rename from src/commands/Command.h
rename to src/commands/includes/Command.h
index bde1c2b..f67dde9 100644
--- a/src/commands/Command.h
+++ b/src/commands/includes/Command.h
@@ -5,7 +5,7 @@
#ifndef SEMBACKUP_COMMAND_H
#define SEMBACKUP_COMMAND_H
-#include "../Context.h"
+#include "Context.h"
/// Abstract base class for some process running with some Context
class Command {
diff --git a/src/commands/CommandDiff.h b/src/commands/includes/CommandDiff.h
similarity index 100%
rename from src/commands/CommandDiff.h
rename to src/commands/includes/CommandDiff.h
diff --git a/src/commands/CommandList.h b/src/commands/includes/CommandList.h
similarity index 100%
rename from src/commands/CommandList.h
rename to src/commands/includes/CommandList.h
diff --git a/src/commands/CommandListFiles.h b/src/commands/includes/CommandListFiles.h
similarity index 100%
rename from src/commands/CommandListFiles.h
rename to src/commands/includes/CommandListFiles.h
diff --git a/src/commands/CommandRestore.h b/src/commands/includes/CommandRestore.h
similarity index 94%
rename from src/commands/CommandRestore.h
rename to src/commands/includes/CommandRestore.h
index 6958a63..5eb2e03 100644
--- a/src/commands/CommandRestore.h
+++ b/src/commands/includes/CommandRestore.h
@@ -7,7 +7,7 @@
#include "Command.h"
-#include "../repo/objects/File.h"
+#include "../../repo/includes/objects/File.h"
#include "CommandsCommon.h"
diff --git a/src/commands/CommandRun.h b/src/commands/includes/CommandRun.h
similarity index 100%
rename from src/commands/CommandRun.h
rename to src/commands/includes/CommandRun.h
diff --git a/src/commands/CommandsCommon.h b/src/commands/includes/CommandsCommon.h
similarity index 100%
rename from src/commands/CommandsCommon.h
rename to src/commands/includes/CommandsCommon.h
diff --git a/src/Context.h b/src/commands/includes/Context.h
similarity index 61%
rename from src/Context.h
rename to src/commands/includes/Context.h
index 3772c57..50f1ebb 100644
--- a/src/Context.h
+++ b/src/commands/includes/Context.h
@@ -5,9 +5,9 @@
#ifndef SEMBACKUP_CONTEXT_H
#define SEMBACKUP_CONTEXT_H
-#include "Config.h"
-#include "Logger.h"
-#include "repo/Repository.h"
+#include "../../repo/includes/Repository.h"
+#include "../../utils/includes/Config.h"
+#include "../../utils/includes/Logger.h"
struct Context {
Logger *logger;
diff --git a/src/Diff.h b/src/commands/includes/Diff.h
similarity index 95%
rename from src/Diff.h
rename to src/commands/includes/Diff.h
index 3d0e576..e5a9c33 100644
--- a/src/Diff.h
+++ b/src/commands/includes/Diff.h
@@ -8,7 +8,7 @@
#include
#include
-#include "change_detectors/ComparableFile.h"
+#include "../../change_detectors/includes/ComparableFile.h"
/// Utility class to compute difference between two ComparableFile%s
class Diff {
diff --git a/src/commands/Command.cpp b/src/commands/srcs/Command.cpp
similarity index 81%
rename from src/commands/Command.cpp
rename to src/commands/srcs/Command.cpp
index 0e76daa..386d8e3 100644
--- a/src/commands/Command.cpp
+++ b/src/commands/srcs/Command.cpp
@@ -2,7 +2,7 @@
// Created by Stepan Usatiuk on 23.05.2023.
//
-#include "Command.h"
+#include "../includes/Command.h"
Command::Command(std::string name) : name(std::move(name)) {}
diff --git a/src/commands/CommandDiff.cpp b/src/commands/srcs/CommandDiff.cpp
similarity index 91%
rename from src/commands/CommandDiff.cpp
rename to src/commands/srcs/CommandDiff.cpp
index 848f741..dc504c2 100644
--- a/src/commands/CommandDiff.cpp
+++ b/src/commands/srcs/CommandDiff.cpp
@@ -2,20 +2,20 @@
// Created by Stepan Usatiuk on 23.05.2023.
//
-#include "CommandDiff.h"
+#include "../includes/CommandDiff.h"
-#include "../BytesFormatter.h"
-#include "../Diff.h"
-#include "../Exception.h"
-#include "../Progress.h"
-#include "../RunningDiffAverage.h"
-#include "../Signals.h"
-#include "../ThreadPool.h"
-#include "../change_detectors/ChangeDetectorFactory.h"
-#include "../chunkers/ChunkerFactory.h"
-#include "../repo/Serialize.h"
-#include "../repo/objects/Archive.h"
-#include "../repo/objects/Chunk.h"
+#include "../../change_detectors/includes/ChangeDetectorFactory.h"
+#include "../../chunkers/includes/ChunkerFactory.h"
+#include "../../repo/includes/Serialize.h"
+#include "../../repo/includes/objects/Archive.h"
+#include "../../repo/includes/objects/Chunk.h"
+#include "../../utils/includes/BytesFormatter.h"
+#include "../../utils/includes/Exception.h"
+#include "../../utils/includes/Progress.h"
+#include "../../utils/includes/RunningDiffAverage.h"
+#include "../../utils/includes/Signals.h"
+#include "../../utils/includes/ThreadPool.h"
+#include "../includes/Diff.h"
using namespace CommandsCommon;
diff --git a/src/commands/CommandList.cpp b/src/commands/srcs/CommandList.cpp
similarity index 92%
rename from src/commands/CommandList.cpp
rename to src/commands/srcs/CommandList.cpp
index 8171807..f61e07a 100644
--- a/src/commands/CommandList.cpp
+++ b/src/commands/srcs/CommandList.cpp
@@ -2,7 +2,7 @@
// Created by Stepan Usatiuk on 23.05.2023.
//
-#include "CommandList.h"
+#include "../includes/CommandList.h"
CommandList::CommandList() : Command("list") {
}
diff --git a/src/commands/CommandListFiles.cpp b/src/commands/srcs/CommandListFiles.cpp
similarity index 66%
rename from src/commands/CommandListFiles.cpp
rename to src/commands/srcs/CommandListFiles.cpp
index 2e8fa07..a2b1995 100644
--- a/src/commands/CommandListFiles.cpp
+++ b/src/commands/srcs/CommandListFiles.cpp
@@ -2,13 +2,13 @@
// Created by Stepan Usatiuk on 23.05.2023.
//
-#include "CommandListFiles.h"
+#include "../includes/CommandListFiles.h"
-#include "../BytesFormatter.h"
-#include "../repo/Serialize.h"
-#include "../repo/objects/Archive.h"
-#include "../repo/objects/Chunk.h"
-#include "../repo/objects/File.h"
+#include "../../repo/includes/Serialize.h"
+#include "../../repo/includes/objects/Archive.h"
+#include "../../repo/includes/objects/Chunk.h"
+#include "../../repo/includes/objects/File.h"
+#include "../../utils/includes/BytesFormatter.h"
CommandListFiles::CommandListFiles() : Command("list-files") {
}
diff --git a/src/commands/CommandRestore.cpp b/src/commands/srcs/CommandRestore.cpp
similarity index 90%
rename from src/commands/CommandRestore.cpp
rename to src/commands/srcs/CommandRestore.cpp
index 6297c0e..cd36429 100644
--- a/src/commands/CommandRestore.cpp
+++ b/src/commands/srcs/CommandRestore.cpp
@@ -2,21 +2,21 @@
// Created by Stepan Usatiuk on 23.05.2023.
//
-#include "CommandRestore.h"
+#include "../includes/CommandRestore.h"
#include
#include
-#include "../BytesFormatter.h"
-#include "../Exception.h"
-#include "../Progress.h"
-#include "../RunningDiffAverage.h"
-#include "../Signals.h"
-#include "../ThreadPool.h"
-#include "../chunkers/ChunkerFactory.h"
-#include "../repo/Serialize.h"
-#include "../repo/objects/Archive.h"
-#include "../repo/objects/Chunk.h"
+#include "../../chunkers/includes/ChunkerFactory.h"
+#include "../../repo/includes/Serialize.h"
+#include "../../repo/includes/objects/Archive.h"
+#include "../../repo/includes/objects/Chunk.h"
+#include "../../utils/includes/BytesFormatter.h"
+#include "../../utils/includes/Exception.h"
+#include "../../utils/includes/Progress.h"
+#include "../../utils/includes/RunningDiffAverage.h"
+#include "../../utils/includes/Signals.h"
+#include "../../utils/includes/ThreadPool.h"
using namespace CommandsCommon;
diff --git a/src/commands/CommandRun.cpp b/src/commands/srcs/CommandRun.cpp
similarity index 93%
rename from src/commands/CommandRun.cpp
rename to src/commands/srcs/CommandRun.cpp
index 868dfd3..6e9a0a3 100644
--- a/src/commands/CommandRun.cpp
+++ b/src/commands/srcs/CommandRun.cpp
@@ -2,27 +2,27 @@
// Created by Stepan Usatiuk on 23.05.2023.
//
-#include "CommandRun.h"
+#include "../includes/CommandRun.h"
#include
#include
#include
-#include "../BytesFormatter.h"
-#include "../Exception.h"
-#include "../Progress.h"
-#include "../RunningDiffAverage.h"
-#include "../Signals.h"
-#include "../ThreadPool.h"
-#include "../change_detectors/ChangeDetectorFactory.h"
-#include "../chunkers/ChunkerFactory.h"
-#include "../crypto/MD5.h"
-#include "../repo/Serialize.h"
-#include "../repo/objects/Archive.h"
-#include "../repo/objects/Chunk.h"
-#include "../repo/objects/File.h"
+#include "../../change_detectors/includes/ChangeDetectorFactory.h"
+#include "../../chunkers/includes/ChunkerFactory.h"
+#include "../../crypto/includes/MD5.h"
+#include "../../repo/includes/Serialize.h"
+#include "../../repo/includes/objects/Archive.h"
+#include "../../repo/includes/objects/Chunk.h"
+#include "../../repo/includes/objects/File.h"
+#include "../../utils/includes/BytesFormatter.h"
+#include "../../utils/includes/Exception.h"
+#include "../../utils/includes/Progress.h"
+#include "../../utils/includes/RunningDiffAverage.h"
+#include "../../utils/includes/Signals.h"
+#include "../../utils/includes/ThreadPool.h"
-#include "CommandsCommon.h"
+#include "../includes/CommandsCommon.h"
using namespace CommandsCommon;
diff --git a/src/commands/CommandsCommon.cpp b/src/commands/srcs/CommandsCommon.cpp
similarity index 95%
rename from src/commands/CommandsCommon.cpp
rename to src/commands/srcs/CommandsCommon.cpp
index 7b7c1af..1e14d74 100644
--- a/src/commands/CommandsCommon.cpp
+++ b/src/commands/srcs/CommandsCommon.cpp
@@ -2,13 +2,13 @@
// Created by Stepan Usatiuk on 23.05.2023.
//
-#include "CommandsCommon.h"
+#include "../includes/CommandsCommon.h"
#include
#include
-#include "../Exception.h"
-#include "../Signals.h"
+#include "../../utils/includes/Exception.h"
+#include "../../utils/includes/Signals.h"
void CommandsCommon::workerCallback(unsigned long long int bytesWritten, unsigned long long int bytesSkipped, unsigned long long int filesWritten, WorkerStats &to) {
to.bytesWritten += bytesWritten;
diff --git a/src/Diff.cpp b/src/commands/srcs/Diff.cpp
similarity index 93%
rename from src/Diff.cpp
rename to src/commands/srcs/Diff.cpp
index 8d5bab9..9b07270 100644
--- a/src/Diff.cpp
+++ b/src/commands/srcs/Diff.cpp
@@ -2,12 +2,12 @@
// Created by Stepan Usatiuk on 06.05.2023.
//
-#include "Diff.h"
+#include "../includes/Diff.h"
-#include "BytesFormatter.h"
-#include "Exception.h"
-#include "Signals.h"
-#include "chunkers/BuzhashChunker.h"
+#include "../../chunkers/includes/BuzhashChunker.h"
+#include "../../utils/includes/BytesFormatter.h"
+#include "../../utils/includes/Exception.h"
+#include "../../utils/includes/Signals.h"
bool Diff::isBinary(const ComparableFile &c) {
auto b = c.contents();
diff --git a/src/crypto/CMakeLists.txt b/src/crypto/CMakeLists.txt
new file mode 100644
index 0000000..142f644
--- /dev/null
+++ b/src/crypto/CMakeLists.txt
@@ -0,0 +1,9 @@
+cmake_minimum_required(VERSION 3.22)
+
+find_package(OpenSSL REQUIRED)
+
+add_library(crypto srcs/AES.cpp srcs/CRC32.cpp srcs/MD5.cpp)
+
+target_include_directories(crypto PUBLIC includes)
+
+target_link_libraries(crypto OpenSSL::SSL utils)
diff --git a/src/crypto/AES.h b/src/crypto/includes/AES.h
similarity index 100%
rename from src/crypto/AES.h
rename to src/crypto/includes/AES.h
diff --git a/src/crypto/CRC32.h b/src/crypto/includes/CRC32.h
similarity index 100%
rename from src/crypto/CRC32.h
rename to src/crypto/includes/CRC32.h
diff --git a/src/crypto/MD5.h b/src/crypto/includes/MD5.h
similarity index 100%
rename from src/crypto/MD5.h
rename to src/crypto/includes/MD5.h
diff --git a/src/crypto/AES.cpp b/src/crypto/srcs/AES.cpp
similarity index 97%
rename from src/crypto/AES.cpp
rename to src/crypto/srcs/AES.cpp
index 2b82f93..d691bd6 100644
--- a/src/crypto/AES.cpp
+++ b/src/crypto/srcs/AES.cpp
@@ -2,13 +2,13 @@
// Created by Stepan Usatiuk on 30.04.2023.
//
-#include "AES.h"
+#include "../includes/AES.h"
#include
#include
#include
-#include "../Exception.h"
+#include "../../utils/includes/Exception.h"
std::vector AES::encrypt(const std::vector &in, const std::string &password, const std::string &salt) {
return AES::encrypt(in, AES::deriveKey(password, salt));
diff --git a/src/crypto/CRC32.cpp b/src/crypto/srcs/CRC32.cpp
similarity index 89%
rename from src/crypto/CRC32.cpp
rename to src/crypto/srcs/CRC32.cpp
index d25a85b..a9838bd 100644
--- a/src/crypto/CRC32.cpp
+++ b/src/crypto/srcs/CRC32.cpp
@@ -2,7 +2,7 @@
// Created by Stepan Usatiuk on 12.05.2023.
//
-#include "CRC32.h"
+#include "../includes/CRC32.h"
CRC32::crcType CRC32::calculate(const std::vector &in) {
crcType res = crc32(0L, nullptr, 0);
diff --git a/src/crypto/MD5.cpp b/src/crypto/srcs/MD5.cpp
similarity index 93%
rename from src/crypto/MD5.cpp
rename to src/crypto/srcs/MD5.cpp
index d0b25b3..1c9b553 100644
--- a/src/crypto/MD5.cpp
+++ b/src/crypto/srcs/MD5.cpp
@@ -2,9 +2,9 @@
// Created by Stepan Usatiuk on 15.04.2023.
//
-#include "MD5.h"
+#include "../includes/MD5.h"
-#include "../Exception.h"
+#include "../../utils/includes/Exception.h"
std::string MD5::calculate(const std::vector &in) {
MD5 hasher;
diff --git a/src/filters/CMakeLists.txt b/src/filters/CMakeLists.txt
new file mode 100644
index 0000000..6e0f318
--- /dev/null
+++ b/src/filters/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.22)
+
+
+find_package(ZLIB REQUIRED)
+
+add_library(filters srcs/CheckFilter.cpp srcs/Filter.cpp srcs/FilterAES.cpp srcs/FilterContainer.cpp srcs/FilterShift.cpp srcs/FilterShiftSecret.cpp srcs/FilterZlib.cpp srcs/FilterFactory.cpp)
+
+target_include_directories(filters PUBLIC includes)
+
+target_link_libraries(filters ZLIB::ZLIB utils)
diff --git a/src/filters/CheckFilter.h b/src/filters/includes/CheckFilter.h
similarity index 100%
rename from src/filters/CheckFilter.h
rename to src/filters/includes/CheckFilter.h
diff --git a/src/filters/Filter.h b/src/filters/includes/Filter.h
similarity index 100%
rename from src/filters/Filter.h
rename to src/filters/includes/Filter.h
diff --git a/src/filters/FilterAES.h b/src/filters/includes/FilterAES.h
similarity index 100%
rename from src/filters/FilterAES.h
rename to src/filters/includes/FilterAES.h
diff --git a/src/filters/FilterContainer.h b/src/filters/includes/FilterContainer.h
similarity index 100%
rename from src/filters/FilterContainer.h
rename to src/filters/includes/FilterContainer.h
diff --git a/src/filters/FilterFactory.h b/src/filters/includes/FilterFactory.h
similarity index 94%
rename from src/filters/FilterFactory.h
rename to src/filters/includes/FilterFactory.h
index 715208d..e848c78 100644
--- a/src/filters/FilterFactory.h
+++ b/src/filters/includes/FilterFactory.h
@@ -8,7 +8,7 @@
#include
#include
-#include "../Config.h"
+#include "../../utils/includes/Config.h"
#include "Filter.h"
/// Utility factory class for Filter%s
diff --git a/src/filters/FilterShift.h b/src/filters/includes/FilterShift.h
similarity index 97%
rename from src/filters/FilterShift.h
rename to src/filters/includes/FilterShift.h
index 6391e51..ee604b5 100644
--- a/src/filters/FilterShift.h
+++ b/src/filters/includes/FilterShift.h
@@ -1,7 +1,6 @@
//
// Created by Stepan Usatiuk on 22.04.2023.
//
-#ifdef TEST
#ifndef SEMBACKUP_FILTERSHIFT_H
#define SEMBACKUP_FILTERSHIFT_H
@@ -27,4 +26,3 @@ private:
#endif//SEMBACKUP_FILTERSHIFT_H
-#endif//TEST
\ No newline at end of file
diff --git a/src/filters/FilterShiftSecret.h b/src/filters/includes/FilterShiftSecret.h
similarity index 97%
rename from src/filters/FilterShiftSecret.h
rename to src/filters/includes/FilterShiftSecret.h
index bd533df..910316e 100644
--- a/src/filters/FilterShiftSecret.h
+++ b/src/filters/includes/FilterShiftSecret.h
@@ -1,13 +1,11 @@
//
// Created by Stepan Usatiuk on 23.04.2023.
//
-#ifdef TEST
#ifndef SEMBACKUP_FILTERSHIFTSECRET_H
#define SEMBACKUP_FILTERSHIFTSECRET_H
-#include
-
#include "Filter.h"
+#include
/// Filter implementation that shifts every byte in input vector using two provided value
/// \warning For testing purposes only!
@@ -30,4 +28,3 @@ private:
#endif//SEMBACKUP_FILTERSHIFTSECRET_H
-#endif//TEST
\ No newline at end of file
diff --git a/src/filters/FilterZlib.h b/src/filters/includes/FilterZlib.h
similarity index 100%
rename from src/filters/FilterZlib.h
rename to src/filters/includes/FilterZlib.h
diff --git a/src/filters/CheckFilter.cpp b/src/filters/srcs/CheckFilter.cpp
similarity index 90%
rename from src/filters/CheckFilter.cpp
rename to src/filters/srcs/CheckFilter.cpp
index 361e076..abb0f59 100644
--- a/src/filters/CheckFilter.cpp
+++ b/src/filters/srcs/CheckFilter.cpp
@@ -2,9 +2,9 @@
// Created by Stepan Usatiuk on 12.05.2023.
//
-#include "CheckFilter.h"
-#include "../crypto/CRC32.h"
-#include "../repo/Serialize.h"
+#include "../includes/CheckFilter.h"
+#include "../../crypto/includes/CRC32.h"
+#include "../../repo/includes/Serialize.h"
std::vector CheckFilter::filterWrite(std::vector from) const {
return filterWriteStatic(std::move(from));
diff --git a/src/filters/Filter.cpp b/src/filters/srcs/Filter.cpp
similarity index 71%
rename from src/filters/Filter.cpp
rename to src/filters/srcs/Filter.cpp
index d2f5d64..97f5ee2 100644
--- a/src/filters/Filter.cpp
+++ b/src/filters/srcs/Filter.cpp
@@ -2,5 +2,5 @@
// Created by Stepan Usatiuk on 22.04.2023.
//
-#include "Filter.h"
+#include "../includes/Filter.h"
Filter::~Filter() = default;
\ No newline at end of file
diff --git a/src/filters/FilterAES.cpp b/src/filters/srcs/FilterAES.cpp
similarity index 84%
rename from src/filters/FilterAES.cpp
rename to src/filters/srcs/FilterAES.cpp
index 199820b..73b7cf7 100644
--- a/src/filters/FilterAES.cpp
+++ b/src/filters/srcs/FilterAES.cpp
@@ -2,9 +2,9 @@
// Created by Stepan Usatiuk on 23.04.2023.
//
-#include "FilterAES.h"
+#include "../includes/FilterAES.h"
-#include "../crypto/AES.h"
+#include "../../crypto/includes/AES.h"
std::vector FilterAES::filterWrite(std::vector from) const {
return AES::encrypt(from, key);
diff --git a/src/filters/FilterContainer.cpp b/src/filters/srcs/FilterContainer.cpp
similarity index 93%
rename from src/filters/FilterContainer.cpp
rename to src/filters/srcs/FilterContainer.cpp
index cc3cb63..cf0d4d6 100644
--- a/src/filters/FilterContainer.cpp
+++ b/src/filters/srcs/FilterContainer.cpp
@@ -2,7 +2,7 @@
// Created by Stepan Usatiuk on 22.04.2023.
//
-#include "FilterContainer.h"
+#include "../includes/FilterContainer.h"
FilterContainer::FilterContainer() = default;
diff --git a/src/filters/FilterFactory.cpp b/src/filters/srcs/FilterFactory.cpp
similarity index 72%
rename from src/filters/FilterFactory.cpp
rename to src/filters/srcs/FilterFactory.cpp
index 324837a..c41f26d 100644
--- a/src/filters/FilterFactory.cpp
+++ b/src/filters/srcs/FilterFactory.cpp
@@ -2,14 +2,14 @@
// Created by Stepan Usatiuk on 22.04.2023.
//
-#include "FilterFactory.h"
+#include "../includes/FilterFactory.h"
-#include "../Exception.h"
-#include "CheckFilter.h"
-#include "FilterAES.h"
-#include "FilterShift.h"
-#include "FilterShiftSecret.h"
-#include "FilterZlib.h"
+#include "../../utils/includes/Exception.h"
+#include "../includes/CheckFilter.h"
+#include "../includes/FilterAES.h"
+#include "../includes/FilterShift.h"
+#include "../includes/FilterShiftSecret.h"
+#include "../includes/FilterZlib.h"
std::unique_ptr FilterFactory::makeFilter(const std::string &type, const Config &config) {
if (type == "none") throw Exception("Trying to make a \"none\" filter!");
@@ -20,13 +20,10 @@ std::unique_ptr FilterFactory::makeFilter(const std::string &type, const
return std::make_unique(config.getInt("compression-level"));
} else if (type == "crc") {
return std::make_unique();
- }
-#ifdef TEST
- else if (type == "shiftC") {
+ } else if (type == "shiftC") {
return std::make_unique(config.getInt("compression-level"));
} else if (type == "shiftE")
return std::make_unique(config.getStr("password"), config.getStr("salt"));
-#endif
throw Exception("Unknown filter value");
}
diff --git a/src/filters/FilterShift.cpp b/src/filters/srcs/FilterShift.cpp
similarity index 89%
rename from src/filters/FilterShift.cpp
rename to src/filters/srcs/FilterShift.cpp
index 9474aef..14f9e7c 100644
--- a/src/filters/FilterShift.cpp
+++ b/src/filters/srcs/FilterShift.cpp
@@ -1,8 +1,7 @@
//
// Created by Stepan Usatiuk on 22.04.2023.
//
-#ifdef TEST
-#include "FilterShift.h"
+#include "../includes/FilterShift.h"
std::vector FilterShift::filterWrite(std::vector from) const {
for (auto &c: from) c += shiftVal;
@@ -15,4 +14,3 @@ std::vector FilterShift::filterRead(std::vector from) const {
}
FilterShift::FilterShift(int level) : shiftVal(level) {}
-#endif
\ No newline at end of file
diff --git a/src/filters/FilterShiftSecret.cpp b/src/filters/srcs/FilterShiftSecret.cpp
similarity index 90%
rename from src/filters/FilterShiftSecret.cpp
rename to src/filters/srcs/FilterShiftSecret.cpp
index 293b99c..2bd7c21 100644
--- a/src/filters/FilterShiftSecret.cpp
+++ b/src/filters/srcs/FilterShiftSecret.cpp
@@ -1,9 +1,8 @@
//
// Created by Stepan Usatiuk on 23.04.2023.
//
-#ifdef TEST
-#include "FilterShiftSecret.h"
+#include "../includes/FilterShiftSecret.h"
#include
@@ -20,4 +19,3 @@ std::vector FilterShiftSecret::filterRead(std::vector from) const {
FilterShiftSecret::FilterShiftSecret(const std::string &password, const std::string &salt) {
shiftVal = password[0] + salt[0];
}
-#endif
\ No newline at end of file
diff --git a/src/filters/FilterZlib.cpp b/src/filters/srcs/FilterZlib.cpp
similarity index 94%
rename from src/filters/FilterZlib.cpp
rename to src/filters/srcs/FilterZlib.cpp
index dac8676..482f866 100644
--- a/src/filters/FilterZlib.cpp
+++ b/src/filters/srcs/FilterZlib.cpp
@@ -2,11 +2,11 @@
// Created by Stepan Usatiuk on 23.04.2023.
//
-#include "FilterZlib.h"
+#include "../includes/FilterZlib.h"
#include
-#include "../repo/Serialize.h"
+#include "../../repo/includes/Serialize.h"
std::vector FilterZlib::filterWrite(std::vector from) const {
uLongf outSize = compressBound(from.size());
diff --git a/src/main.cpp b/src/main.cpp
index 6518295..08d4c39 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,23 +1,23 @@
#include
-#include "BytesFormatter.h"
-#include "Config.h"
-#include "Context.h"
-#include "Exception.h"
-#include "Logger.h"
-#include "Signals.h"
-#include "commands/Command.h"
-#include "commands/CommandDiff.h"
-#include "commands/CommandList.h"
-#include "commands/CommandListFiles.h"
-#include "commands/CommandRestore.h"
-#include "commands/CommandRun.h"
-#include "repo/FileRepository.h"
-#include "repo/Repository.h"
-#include "repo/Serialize.h"
-#include "repo/objects/Archive.h"
-#include "repo/objects/File.h"
+#include "commands/includes/Command.h"
+#include "commands/includes/CommandDiff.h"
+#include "commands/includes/CommandList.h"
+#include "commands/includes/CommandListFiles.h"
+#include "commands/includes/CommandRestore.h"
+#include "commands/includes/CommandRun.h"
+#include "commands/includes/Context.h"
+#include "repo/includes/FileRepository.h"
+#include "repo/includes/Repository.h"
+#include "repo/includes/Serialize.h"
+#include "repo/includes/objects/Archive.h"
+#include "repo/includes/objects/File.h"
+#include "utils/includes/BytesFormatter.h"
+#include "utils/includes/Config.h"
+#include "utils/includes/Exception.h"
+#include "utils/includes/Logger.h"
+#include "utils/includes/Signals.h"
Config getConf(int argc, char *argv[]) {
Config out;
diff --git a/src/repo/CMakeLists.txt b/src/repo/CMakeLists.txt
new file mode 100644
index 0000000..0a351b4
--- /dev/null
+++ b/src/repo/CMakeLists.txt
@@ -0,0 +1,7 @@
+cmake_minimum_required(VERSION 3.22)
+
+add_library(repo srcs/FileRepository.cpp srcs/Object.cpp srcs/Repository.cpp srcs/objects/Archive.cpp srcs/objects/Chunk.cpp srcs/objects/File.cpp srcs/objects/FileBuffer.cpp)
+
+target_include_directories(repo PUBLIC includes)
+
+target_link_libraries(repo filters)
\ No newline at end of file
diff --git a/src/repo/FileRepository.h b/src/repo/includes/FileRepository.h
similarity index 100%
rename from src/repo/FileRepository.h
rename to src/repo/includes/FileRepository.h
diff --git a/src/repo/Object.h b/src/repo/includes/Object.h
similarity index 100%
rename from src/repo/Object.h
rename to src/repo/includes/Object.h
diff --git a/src/repo/Repository.h b/src/repo/includes/Repository.h
similarity index 97%
rename from src/repo/Repository.h
rename to src/repo/includes/Repository.h
index c80cee6..17175d5 100644
--- a/src/repo/Repository.h
+++ b/src/repo/includes/Repository.h
@@ -9,8 +9,8 @@
#include
#include
-#include "../Config.h"
-#include "../filters/FilterContainer.h"
+#include "../../filters/includes/FilterContainer.h"
+#include "../../utils/includes/Config.h"
#include "Object.h"
/// Abstract base class for an Object Repository
diff --git a/src/repo/Serialize.h b/src/repo/includes/Serialize.h
similarity index 99%
rename from src/repo/Serialize.h
rename to src/repo/includes/Serialize.h
index 0202d6f..5208d70 100644
--- a/src/repo/Serialize.h
+++ b/src/repo/includes/Serialize.h
@@ -20,7 +20,7 @@
#include
#endif
-#include "../Exception.h"
+#include "../../utils/includes/Exception.h"
/// Serialization library
/**
diff --git a/src/repo/objects/Archive.h b/src/repo/includes/objects/Archive.h
similarity index 100%
rename from src/repo/objects/Archive.h
rename to src/repo/includes/objects/Archive.h
diff --git a/src/repo/objects/Chunk.h b/src/repo/includes/objects/Chunk.h
similarity index 100%
rename from src/repo/objects/Chunk.h
rename to src/repo/includes/objects/Chunk.h
diff --git a/src/repo/objects/File.h b/src/repo/includes/objects/File.h
similarity index 100%
rename from src/repo/objects/File.h
rename to src/repo/includes/objects/File.h
diff --git a/src/repo/objects/FileBuffer.h b/src/repo/includes/objects/FileBuffer.h
similarity index 100%
rename from src/repo/objects/FileBuffer.h
rename to src/repo/includes/objects/FileBuffer.h
diff --git a/src/repo/FileRepository.cpp b/src/repo/srcs/FileRepository.cpp
similarity index 97%
rename from src/repo/FileRepository.cpp
rename to src/repo/srcs/FileRepository.cpp
index 1556e15..01c6cc5 100644
--- a/src/repo/FileRepository.cpp
+++ b/src/repo/srcs/FileRepository.cpp
@@ -2,16 +2,16 @@
// Created by Stepan Usatiuk on 14.04.2023.
//
-#include "FileRepository.h"
+#include "../includes/FileRepository.h"
#include
#include
#include
-#include "../filters/CheckFilter.h"
-#include "../filters/FilterFactory.h"
-#include "Object.h"
-#include "Serialize.h"
+#include "../../filters/includes/CheckFilter.h"
+#include "../../filters/includes/FilterFactory.h"
+#include "../includes/Object.h"
+#include "../includes/Serialize.h"
FileRepository::FileRepository(Config config) : Repository(std::move(config)), root(std::filesystem::path(this->config.getStr("repo"))), writeCacheMax(config.getInt("repo-target") * 1024 * 1024) {}
diff --git a/src/repo/Object.cpp b/src/repo/srcs/Object.cpp
similarity index 88%
rename from src/repo/Object.cpp
rename to src/repo/srcs/Object.cpp
index 3a7c488..a8fd7d7 100644
--- a/src/repo/Object.cpp
+++ b/src/repo/srcs/Object.cpp
@@ -2,9 +2,9 @@
// Created by Stepan Usatiuk on 14.04.2023.
//
-#include "Object.h"
+#include "../includes/Object.h"
-#include "Serialize.h"
+#include "../includes/Serialize.h"
Object::Object(idType id, ObjectType type) : id(id), type(type) {}
diff --git a/src/repo/Repository.cpp b/src/repo/srcs/Repository.cpp
similarity index 86%
rename from src/repo/Repository.cpp
rename to src/repo/srcs/Repository.cpp
index 22568f7..dcde2e1 100644
--- a/src/repo/Repository.cpp
+++ b/src/repo/srcs/Repository.cpp
@@ -2,7 +2,7 @@
// Created by Stepan Usatiuk on 14.04.2023.
//
-#include "Repository.h"
+#include "../includes/Repository.h"
Repository::~Repository() = default;
Repository::Repository(Config config) : config(std::move(config)) {}
diff --git a/src/repo/objects/Archive.cpp b/src/repo/srcs/objects/Archive.cpp
similarity index 90%
rename from src/repo/objects/Archive.cpp
rename to src/repo/srcs/objects/Archive.cpp
index 5687aca..e7bc7c7 100644
--- a/src/repo/objects/Archive.cpp
+++ b/src/repo/srcs/objects/Archive.cpp
@@ -2,10 +2,10 @@
// Created by Stepan Usatiuk on 14.04.2023.
//
-#include "Archive.h"
+#include "../../includes/objects/Archive.h"
-#include "../../Exception.h"
-#include "../Serialize.h"
+#include "../../../utils/includes/Exception.h"
+#include "../../includes/Serialize.h"
Archive::Archive(Object::idType id, std::string name, unsigned long long mtime, std::vector files, bool full)
: Object(id, ObjectType::Archive), name(name), mtime(mtime), files(files), isFull(full) {}
diff --git a/src/repo/objects/Chunk.cpp b/src/repo/srcs/objects/Chunk.cpp
similarity index 89%
rename from src/repo/objects/Chunk.cpp
rename to src/repo/srcs/objects/Chunk.cpp
index 7e41bc7..550cb61 100644
--- a/src/repo/objects/Chunk.cpp
+++ b/src/repo/srcs/objects/Chunk.cpp
@@ -2,10 +2,10 @@
// Created by Stepan Usatiuk on 14.04.2023.
//
-#include "Chunk.h"
+#include "../../includes/objects/Chunk.h"
-#include "../../Exception.h"
-#include "../Serialize.h"
+#include "../../../utils/includes/Exception.h"
+#include "../../includes/Serialize.h"
Chunk::Chunk(idType id, std::string md5, std::vector data) : Object(id, ObjectType::Chunk), data(std::move(data)), md5(std::move(md5)), length(this->data.size()) {}
diff --git a/src/repo/objects/File.cpp b/src/repo/srcs/objects/File.cpp
similarity index 96%
rename from src/repo/objects/File.cpp
rename to src/repo/srcs/objects/File.cpp
index a4993a5..6725b3b 100644
--- a/src/repo/objects/File.cpp
+++ b/src/repo/srcs/objects/File.cpp
@@ -2,14 +2,14 @@
// Created by Stepan Usatiuk on 14.04.2023.
//
-#include "File.h"
+#include "../../includes/objects/File.h"
#include
#include
#include
-#include "../../Exception.h"
-#include "../Serialize.h"
+#include "../../../utils/includes/Exception.h"
+#include "../../includes/Serialize.h"
File::File(Object::idType id, std::string name, unsigned long long bytes, unsigned long long mtime, std::string md5, std::vector chunks, Type fileType)
: Object(id, ObjectType::File), name(name), bytes(bytes), mtime(mtime), md5(md5), fileType(fileType), chunks(chunks) {}
diff --git a/src/repo/objects/FileBuffer.cpp b/src/repo/srcs/objects/FileBuffer.cpp
similarity index 93%
rename from src/repo/objects/FileBuffer.cpp
rename to src/repo/srcs/objects/FileBuffer.cpp
index b3ad6c1..6e10e77 100644
--- a/src/repo/objects/FileBuffer.cpp
+++ b/src/repo/srcs/objects/FileBuffer.cpp
@@ -2,9 +2,9 @@
// Created by Stepan Usatiuk on 23.04.2023.
//
-#include "FileBuffer.h"
+#include "../../includes/objects/FileBuffer.h"
-#include "../Serialize.h"
+#include "../../includes/Serialize.h"
FileBuffer::FileBuffer(const Repository *repo, Object::idType fileId) : repo(repo), file(Serialize::deserialize(repo->getObject(fileId))), chunksQueue() {
for (auto const &id: file.chunks) chunksQueue.emplace(id);
diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt
new file mode 100644
index 0000000..9f86eab
--- /dev/null
+++ b/src/utils/CMakeLists.txt
@@ -0,0 +1,5 @@
+cmake_minimum_required(VERSION 3.22)
+
+add_library(utils srcs/BytesFormatter.cpp srcs/Config.cpp srcs/Exception.cpp srcs/Logger.cpp srcs/Progress.cpp srcs/RunningAverage.cpp srcs/RunningDiffAverage.cpp srcs/Signals.cpp srcs/ThreadPool.cpp)
+
+target_include_directories(utils PUBLIC includes)
\ No newline at end of file
diff --git a/src/BytesFormatter.h b/src/utils/includes/BytesFormatter.h
similarity index 100%
rename from src/BytesFormatter.h
rename to src/utils/includes/BytesFormatter.h
diff --git a/src/Config.h b/src/utils/includes/Config.h
similarity index 100%
rename from src/Config.h
rename to src/utils/includes/Config.h
diff --git a/src/Exception.h b/src/utils/includes/Exception.h
similarity index 100%
rename from src/Exception.h
rename to src/utils/includes/Exception.h
diff --git a/src/Logger.h b/src/utils/includes/Logger.h
similarity index 100%
rename from src/Logger.h
rename to src/utils/includes/Logger.h
diff --git a/src/Progress.h b/src/utils/includes/Progress.h
similarity index 100%
rename from src/Progress.h
rename to src/utils/includes/Progress.h
diff --git a/src/RunningAverage.h b/src/utils/includes/RunningAverage.h
similarity index 100%
rename from src/RunningAverage.h
rename to src/utils/includes/RunningAverage.h
diff --git a/src/RunningDiffAverage.h b/src/utils/includes/RunningDiffAverage.h
similarity index 100%
rename from src/RunningDiffAverage.h
rename to src/utils/includes/RunningDiffAverage.h
diff --git a/src/Signals.h b/src/utils/includes/Signals.h
similarity index 100%
rename from src/Signals.h
rename to src/utils/includes/Signals.h
diff --git a/src/ThreadPool.h b/src/utils/includes/ThreadPool.h
similarity index 100%
rename from src/ThreadPool.h
rename to src/utils/includes/ThreadPool.h
diff --git a/src/BytesFormatter.cpp b/src/utils/srcs/BytesFormatter.cpp
similarity index 96%
rename from src/BytesFormatter.cpp
rename to src/utils/srcs/BytesFormatter.cpp
index 8b96fcc..16e8eb9 100644
--- a/src/BytesFormatter.cpp
+++ b/src/utils/srcs/BytesFormatter.cpp
@@ -2,7 +2,7 @@
// Created by Stepan Usatiuk on 13.05.2023.
//
-#include "BytesFormatter.h"
+#include "../includes/BytesFormatter.h"
#include
#include
diff --git a/src/Config.cpp b/src/utils/srcs/Config.cpp
similarity index 95%
rename from src/Config.cpp
rename to src/utils/srcs/Config.cpp
index 67db35b..0d58eb7 100644
--- a/src/Config.cpp
+++ b/src/utils/srcs/Config.cpp
@@ -2,9 +2,9 @@
// Created by Stepan Usatiuk on 01.05.2023.
//
-#include "Config.h"
-#include "Exception.h"
-#include "repo/Serialize.h"
+#include "../includes/Config.h"
+#include "../../repo/includes/Serialize.h"
+#include "../includes/Exception.h"
#include
Config &Config::add(const std::string &k, const std::string &v) {
diff --git a/src/Exception.cpp b/src/utils/srcs/Exception.cpp
similarity index 95%
rename from src/Exception.cpp
rename to src/utils/srcs/Exception.cpp
index 46ae6e3..20a8700 100644
--- a/src/Exception.cpp
+++ b/src/utils/srcs/Exception.cpp
@@ -2,7 +2,7 @@
// Created by Stepan Usatiuk on 01.05.2023.
//
-#include "Exception.h"
+#include "../includes/Exception.h"
#include
#include
diff --git a/src/Logger.cpp b/src/utils/srcs/Logger.cpp
similarity index 92%
rename from src/Logger.cpp
rename to src/utils/srcs/Logger.cpp
index 8b80120..cb004d2 100644
--- a/src/Logger.cpp
+++ b/src/utils/srcs/Logger.cpp
@@ -2,7 +2,7 @@
// Created by Stepan Usatiuk on 23.05.2023.
//
-#include "Logger.h"
+#include "../includes/Logger.h"
Logger::Logger(int level, std::ostream &out) : loglevel(level), out(out) {
}
diff --git a/src/Progress.cpp b/src/utils/srcs/Progress.cpp
similarity index 97%
rename from src/Progress.cpp
rename to src/utils/srcs/Progress.cpp
index b1aa4c9..2a9818a 100644
--- a/src/Progress.cpp
+++ b/src/utils/srcs/Progress.cpp
@@ -2,7 +2,7 @@
// Created by Stepan Usatiuk on 05.05.2023.
//
-#include "Progress.h"
+#include "../includes/Progress.h"
#include
#include
diff --git a/src/RunningAverage.cpp b/src/utils/srcs/RunningAverage.cpp
similarity index 95%
rename from src/RunningAverage.cpp
rename to src/utils/srcs/RunningAverage.cpp
index c7d8bb8..3259608 100644
--- a/src/RunningAverage.cpp
+++ b/src/utils/srcs/RunningAverage.cpp
@@ -2,7 +2,7 @@
// Created by Stepan Usatiuk on 05.05.2023.
//
-#include "RunningAverage.h"
+#include "../includes/RunningAverage.h"
RunningAverage::RunningAverage(std::function getFunc, int max, int ms)
: getFunc(std::move(getFunc)), max(max), ms(ms), thread(&RunningAverage::loop, this) {
diff --git a/src/RunningDiffAverage.cpp b/src/utils/srcs/RunningDiffAverage.cpp
similarity index 91%
rename from src/RunningDiffAverage.cpp
rename to src/utils/srcs/RunningDiffAverage.cpp
index bb8ee8b..28b1215 100644
--- a/src/RunningDiffAverage.cpp
+++ b/src/utils/srcs/RunningDiffAverage.cpp
@@ -2,7 +2,7 @@
// Created by Stepan Usatiuk on 12.05.2023.
//
-#include "RunningDiffAverage.h"
+#include "../includes/RunningDiffAverage.h"
RunningDiffAverage::RunningDiffAverage(std::function getFunc, int max, int ms)
: runningAverage(
diff --git a/src/Signals.cpp b/src/utils/srcs/Signals.cpp
similarity index 83%
rename from src/Signals.cpp
rename to src/utils/srcs/Signals.cpp
index 907b61b..bec532b 100644
--- a/src/Signals.cpp
+++ b/src/utils/srcs/Signals.cpp
@@ -1,7 +1,7 @@
//
// Created by Stepan Usatiuk on 16.04.2023.
//
-#include "Signals.h"
+#include "../includes/Signals.h"
void Signals::setup() {
signal(SIGINT, handle);
diff --git a/src/ThreadPool.cpp b/src/utils/srcs/ThreadPool.cpp
similarity index 95%
rename from src/ThreadPool.cpp
rename to src/utils/srcs/ThreadPool.cpp
index fd96499..7bac4e9 100644
--- a/src/ThreadPool.cpp
+++ b/src/utils/srcs/ThreadPool.cpp
@@ -1,7 +1,7 @@
#include
-#include "Signals.h"
-#include "ThreadPool.h"
+#include "../includes/Signals.h"
+#include "../includes/ThreadPool.h"
ThreadPool::ThreadPool(std::function onError, std::size_t workersNum) : onError(std::move(onError)) {
for (int i = 0; i < workersNum; i++) threads.emplace_back(&ThreadPool::loop, this);
diff --git a/tests/BuzhashTest.cpp b/tests/BuzhashTest.cpp
deleted file mode 100644
index 54cce97..0000000
--- a/tests/BuzhashTest.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-//
-// Created by Stepan Usatiuk on 27.04.2023.
-//
-
-#include "BuzhashTest.h"
-#include "../src/chunkers/Buzhash.h"
-
-
-std::unique_ptr BuzhashTest::operator()() {
-
- auto tg = std::make_unique("Buzhash tests");
-
- tg->addTest(std::make_unique("Simple buzhash test", std::function([]() {
- std::string loremipsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
-
- for (int i = 15; i < 49; i++) {
- Buzhash b(i);
- std::string p1 = "reprehenderit in voluptate velit esse cillum dolore";
- for (auto c: p1) b.feed(static_cast(c));
- auto h1 = b.get();
-
- Buzhash b2(i);
- bool h1found = false;
-
- for (int i = 0; i < loremipsum.length(); i++) {
- b2.feed((uint8_t) loremipsum[i]);
- if (b2.get() == h1) {
- HelpfulAssert()(i, loremipsum.find("e eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non p"));
- h1found = true;
- break;
- }
- }
- HelpfulAssert()(h1found, true);
- }
-
- return true;
- })));
- return tg;
-}
diff --git a/tests/BuzhashTest.h b/tests/BuzhashTest.h
deleted file mode 100644
index 63786be..0000000
--- a/tests/BuzhashTest.h
+++ /dev/null
@@ -1,16 +0,0 @@
-//
-// Created by Stepan Usatiuk on 27.04.2023.
-//
-
-#ifndef SEMBACKUP_BUZHASHTEST_H
-#define SEMBACKUP_BUZHASHTEST_H
-
-#include "utils/TestGroupGenerator.h"
-
-class BuzhashTest : public TestGroupGenerator {
-public:
- std::unique_ptr operator()() override;
-};
-
-
-#endif//SEMBACKUP_BUZHASHTEST_H
diff --git a/tests/CLITestWrapper.cpp b/tests/CLITestWrapper.cpp
deleted file mode 100644
index 10fb980..0000000
--- a/tests/CLITestWrapper.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-//
-// Created by Stepan Usatiuk on 10.05.2023.
-//
-
-#include "CLITestWrapper.h"
-#include "utils/Cleaner.h"
-
-std::unique_ptr CLITestWrapper::operator()() {
- auto tg = std::make_unique("CLI tests");
-
- tg->addTest(std::make_unique("Test backup", std::function([]() {
- int ret = system("../tests/clitests/backup.sh");
- HelpfulAssert()(WEXITSTATUS(ret), 0);
- return true;
- })));
- tg->addTest(std::make_unique("Test ignore", std::function([]() {
- int ret = system("../tests/clitests/ignore.sh");
- HelpfulAssert()(WEXITSTATUS(ret), 0);
- return true;
- })));
-
- tg->addTest(std::make_unique("Test diff", std::function([]() {
- int ret = system("../tests/clitests/diff.sh");
- HelpfulAssert()(WEXITSTATUS(ret), 0);
- return true;
- })));
-
-
- return tg;
-}
diff --git a/tests/CLITestWrapper.h b/tests/CLITestWrapper.h
deleted file mode 100644
index 833e133..0000000
--- a/tests/CLITestWrapper.h
+++ /dev/null
@@ -1,15 +0,0 @@
-//
-// Created by Stepan Usatiuk on 10.05.2023.
-//
-
-#ifndef SEMBACKUP_CLITESTWRAPPER_H
-#define SEMBACKUP_CLITESTWRAPPER_H
-
-#include "utils/TestGroupGenerator.h"
-
-class CLITestWrapper : public TestGroupGenerator {
-public:
- std::unique_ptr operator()() override;
-};
-
-#endif//SEMBACKUP_CLITESTWRAPPER_H
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644
index 0000000..8a75b17
--- /dev/null
+++ b/tests/CMakeLists.txt
@@ -0,0 +1,28 @@
+cmake_minimum_required(VERSION 3.22)
+
+# GoogleTest requires at least C++14
+set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
+if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
+ cmake_policy(SET CMP0135 NEW)
+endif ()
+
+include(FetchContent)
+FetchContent_Declare(
+ googletest
+ GIT_REPOSITORY https://github.com/google/googletest.git
+ GIT_TAG release-1.12.1
+)
+# For Windows: Prevent overriding the parent project's compiler/linker settings
+set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
+FetchContent_MakeAvailable(googletest)
+include(GoogleTest)
+
+add_subdirectory(utils)
+
+add_subdirectory(chunkers)
+add_subdirectory(clitests)
+add_subdirectory(crypto)
+add_subdirectory(fulltests)
+add_subdirectory(repo)
\ No newline at end of file
diff --git a/tests/chunkers/CMakeLists.txt b/tests/chunkers/CMakeLists.txt
new file mode 100644
index 0000000..21f829b
--- /dev/null
+++ b/tests/chunkers/CMakeLists.txt
@@ -0,0 +1,12 @@
+cmake_minimum_required(VERSION 3.22)
+
+add_executable(
+ BuzhashTest
+ srcs/BuzhashTest.cpp
+)
+target_link_libraries(
+ BuzhashTest PRIVATE
+ GTest::gtest_main chunkers
+)
+gtest_discover_tests(BuzhashTest)
+
diff --git a/tests/chunkers/srcs/BuzhashTest.cpp b/tests/chunkers/srcs/BuzhashTest.cpp
new file mode 100644
index 0000000..d35ed5a
--- /dev/null
+++ b/tests/chunkers/srcs/BuzhashTest.cpp
@@ -0,0 +1,31 @@
+//
+// Created by Stepan Usatiuk on 27.04.2023.
+//
+
+#include "Buzhash.h"
+#include
+
+// Demonstrate some basic assertions.
+TEST(BuzhashTest, SimpleTest) {
+ std::string loremipsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
+
+ for (int i = 15; i < 49; i++) {
+ Buzhash b(i);
+ std::string p1 = "reprehenderit in voluptate velit esse cillum dolore";
+ for (auto c: p1) b.feed(static_cast(c));
+ auto h1 = b.get();
+
+ Buzhash b2(i);
+ bool h1found = false;
+
+ for (int i = 0; i < loremipsum.length(); i++) {
+ b2.feed((uint8_t) loremipsum[i]);
+ if (b2.get() == h1) {
+ EXPECT_EQ(i, loremipsum.find("e eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non p"));
+ h1found = true;
+ break;
+ }
+ }
+ EXPECT_EQ(h1found, true);
+ }
+}
diff --git a/tests/clitests/CMakeLists.txt b/tests/clitests/CMakeLists.txt
new file mode 100644
index 0000000..fd6a620
--- /dev/null
+++ b/tests/clitests/CMakeLists.txt
@@ -0,0 +1,15 @@
+cmake_minimum_required(VERSION 3.22)
+
+
+add_executable(
+ CLITests
+ srcs/CLITestWrapper.cpp
+)
+add_dependencies(CLITests backup)
+
+target_link_libraries(
+ CLITests PRIVATE
+ GTest::gtest_main testUtils
+)
+gtest_discover_tests(CLITests)
+
diff --git a/tests/clitests/backup.sh b/tests/clitests/scripts/backup.sh
similarity index 99%
rename from tests/clitests/backup.sh
rename to tests/clitests/scripts/backup.sh
index d3ac5f0..41505e0 100755
--- a/tests/clitests/backup.sh
+++ b/tests/clitests/scripts/backup.sh
@@ -2,7 +2,8 @@
TESTSIZE=16
-CMD=./sembackup
+# TODO: Don't hardcode this
+CMD="../../src/backup"
rm -rf testdata
rm -rf testdir
diff --git a/tests/clitests/diff.sh b/tests/clitests/scripts/diff.sh
similarity index 99%
rename from tests/clitests/diff.sh
rename to tests/clitests/scripts/diff.sh
index 8f1eb41..ba9051e 100755
--- a/tests/clitests/diff.sh
+++ b/tests/clitests/scripts/diff.sh
@@ -1,6 +1,7 @@
#!/bin/bash
-CMD=./sembackup
+# TODO: Don't hardcode this
+CMD="../../src/backup"
rm -rf testdata
rm -rf testdir
diff --git a/tests/clitests/ignore.sh b/tests/clitests/scripts/ignore.sh
similarity index 98%
rename from tests/clitests/ignore.sh
rename to tests/clitests/scripts/ignore.sh
index e6adb07..5c86a9e 100755
--- a/tests/clitests/ignore.sh
+++ b/tests/clitests/scripts/ignore.sh
@@ -1,6 +1,7 @@
#!/bin/bash
-CMD=./sembackup
+# TODO: Don't hardcode this
+CMD="../../src/backup"
rm -rf testdata
rm -rf testdir
diff --git a/tests/clitests/srcs/CLITestWrapper.cpp b/tests/clitests/srcs/CLITestWrapper.cpp
new file mode 100644
index 0000000..9af8a0c
--- /dev/null
+++ b/tests/clitests/srcs/CLITestWrapper.cpp
@@ -0,0 +1,23 @@
+//
+// Created by Stepan Usatiuk on 10.05.2023.
+//
+
+#include "Cleaner.h"
+#include
+
+//TODO: Don't hardcode scripts
+
+TEST(CLITest, Backup) {
+ int ret = system("../../../tests/clitests/scripts/backup.sh");
+ EXPECT_EQ(WEXITSTATUS(ret), 0);
+}
+
+TEST(CLITest, Ignore) {
+ int ret = system("../../../tests/clitests/scripts/ignore.sh");
+ EXPECT_EQ(WEXITSTATUS(ret), 0);
+}
+
+TEST(CLITest, Diff) {
+ int ret = system("../../../tests/clitests/scripts/diff.sh");
+ EXPECT_EQ(WEXITSTATUS(ret), 0);
+}
\ No newline at end of file
diff --git a/tests/crypto/AESTest.cpp b/tests/crypto/AESTest.cpp
deleted file mode 100644
index 9c56509..0000000
--- a/tests/crypto/AESTest.cpp
+++ /dev/null
@@ -1,40 +0,0 @@
-//
-// Created by Stepan Usatiuk on 30.04.2023.
-//
-
-#include "AESTest.h"
-#include "../../src/crypto/AES.h"
-
-std::unique_ptr AESTest::operator()() {
- auto tg = std::make_unique("AES tests");
-
- tg->addTest(std::make_unique("Simple AESTest test", std::function([]() {
- std::string in = "hello1";
- auto enc = AES::encrypt(std::vector(in.begin(), in.end()), "p1", "e");
- auto dec = AES::decrypt(enc, "p1", "e");
- HelpfulAssert()(in, std::string(dec.begin(), dec.end()));
-
- in = "1234567890asdfg";
- enc = AES::encrypt(std::vector(in.begin(), in.end()), "p1", "e");
- dec = AES::decrypt(enc, "p1", "e");
- HelpfulAssert()(in, std::string(dec.begin(), dec.end()));
-
- in = "1234567890asdfgh";
- enc = AES::encrypt(std::vector(in.begin(), in.end()), "p1", "e");
- dec = AES::decrypt(enc, "p1", "e");
- HelpfulAssert()(in, std::string(dec.begin(), dec.end()));
-
- in = "1234567890asdfghe";
- enc = AES::encrypt(std::vector(in.begin(), in.end()), "p1", "e");
- dec = AES::decrypt(enc, "p1", "e");
- HelpfulAssert()(in, std::string(dec.begin(), dec.end()));
-
- in = "1234567890asdfgheq";
- enc = AES::encrypt(std::vector(in.begin(), in.end()), "p1", "e");
- dec = AES::decrypt(enc, "p1", "e");
- HelpfulAssert()(in, std::string(dec.begin(), dec.end()));
-
- return true;
- })));
- return tg;
-}
diff --git a/tests/crypto/AESTest.h b/tests/crypto/AESTest.h
deleted file mode 100644
index 4e78821..0000000
--- a/tests/crypto/AESTest.h
+++ /dev/null
@@ -1,16 +0,0 @@
-//
-// Created by Stepan Usatiuk on 30.04.2023.
-//
-
-#ifndef SEMBACKUP_AESTEST_H
-#define SEMBACKUP_AESTEST_H
-
-#include "../utils/TestGroupGenerator.h"
-
-class AESTest : public TestGroupGenerator {
-public:
- std::unique_ptr operator()() override;
-};
-
-
-#endif//SEMBACKUP_AESTEST_H
diff --git a/tests/crypto/CMakeLists.txt b/tests/crypto/CMakeLists.txt
new file mode 100644
index 0000000..d0ede41
--- /dev/null
+++ b/tests/crypto/CMakeLists.txt
@@ -0,0 +1,14 @@
+cmake_minimum_required(VERSION 3.22)
+
+add_executable(
+ CryptoTests
+ srcs/CryptoTests.cpp
+)
+
+target_link_libraries(
+ CryptoTests PRIVATE
+ GTest::gtest_main crypto
+)
+
+gtest_discover_tests(CryptoTests)
+
diff --git a/tests/crypto/MD5Test.cpp b/tests/crypto/MD5Test.cpp
deleted file mode 100644
index f7244c5..0000000
--- a/tests/crypto/MD5Test.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-//
-// Created by Stepan Usatiuk on 15.04.2023.
-//
-
-#include "MD5Test.h"
-
-std::unique_ptr MD5Test::operator()() {
- auto tg = std::make_unique("MD5 tests");
-
- tg->addTest(std::make_unique("Simple MD5 test", std::function([]() {
- std::vector data{'h', 'e', 'l', 'l', 'o'};
- std::array excepted{0x5d, 0x41, 0x40, 0x2a, 0xbc, 0x4b, 0x2a, 0x76, 0xb9, 0x71, 0x9d, 0x91, 0x10, 0x17, 0xc5, 0x92};
-
- auto out = MD5::calculate(data);
-
- HelpfulAssert()(out.size(), 16);
- for (int i = 0; i < out.size(); i++) {
- HelpfulAssert()(out[i], excepted[i]);
- }
-
-
- return true;
- })));
- return tg;
-}
diff --git a/tests/crypto/MD5Test.h b/tests/crypto/MD5Test.h
deleted file mode 100644
index 068f259..0000000
--- a/tests/crypto/MD5Test.h
+++ /dev/null
@@ -1,17 +0,0 @@
-//
-// Created by Stepan Usatiuk on 15.04.2023.
-//
-
-#ifndef SEMBACKUP_MD5TEST_H
-#define SEMBACKUP_MD5TEST_H
-
-#include "../../src/crypto/MD5.h"
-#include "../utils/TestGroupGenerator.h"
-
-class MD5Test : public TestGroupGenerator {
-public:
- std::unique_ptr operator()() override;
-};
-
-
-#endif//SEMBACKUP_MD5TEST_H
diff --git a/tests/crypto/srcs/CryptoTests.cpp b/tests/crypto/srcs/CryptoTests.cpp
new file mode 100644
index 0000000..33089e6
--- /dev/null
+++ b/tests/crypto/srcs/CryptoTests.cpp
@@ -0,0 +1,47 @@
+//
+// Created by Stepan Usatiuk on 30.04.2023.
+//
+
+#include "AES.h"
+#include "MD5.h"
+
+#include
+
+TEST(CryptoTests, AES) {
+ std::string in = "hello1";
+ auto enc = AES::encrypt(std::vector(in.begin(), in.end()), "p1", "e");
+ auto dec = AES::decrypt(enc, "p1", "e");
+ EXPECT_EQ(in, std::string(dec.begin(), dec.end()));
+
+ in = "1234567890asdfg";
+ enc = AES::encrypt(std::vector(in.begin(), in.end()), "p1", "e");
+ dec = AES::decrypt(enc, "p1", "e");
+ EXPECT_EQ(in, std::string(dec.begin(), dec.end()));
+
+ in = "1234567890asdfgh";
+ enc = AES::encrypt(std::vector(in.begin(), in.end()), "p1", "e");
+ dec = AES::decrypt(enc, "p1", "e");
+ EXPECT_EQ(in, std::string(dec.begin(), dec.end()));
+
+ in = "1234567890asdfghe";
+ enc = AES::encrypt(std::vector(in.begin(), in.end()), "p1", "e");
+ dec = AES::decrypt(enc, "p1", "e");
+ EXPECT_EQ(in, std::string(dec.begin(), dec.end()));
+
+ in = "1234567890asdfgheq";
+ enc = AES::encrypt(std::vector(in.begin(), in.end()), "p1", "e");
+ dec = AES::decrypt(enc, "p1", "e");
+ EXPECT_EQ(in, std::string(dec.begin(), dec.end()));
+}
+
+TEST(CryptoTests, MD5) {
+ std::vector data{'h', 'e', 'l', 'l', 'o'};
+ std::array excepted{0x5d, 0x41, 0x40, 0x2a, 0xbc, 0x4b, 0x2a, 0x76, 0xb9, 0x71, 0x9d, 0x91, 0x10, 0x17, 0xc5, 0x92};
+
+ auto out = MD5::calculate(data);
+
+ EXPECT_EQ(out.size(), 16);
+ for (int i = 0; i < out.size(); i++) {
+ EXPECT_EQ(static_cast(out[i]), excepted[i]);
+ }
+}
diff --git a/tests/fulltests/CMakeLists.txt b/tests/fulltests/CMakeLists.txt
new file mode 100644
index 0000000..ce9cf4c
--- /dev/null
+++ b/tests/fulltests/CMakeLists.txt
@@ -0,0 +1,14 @@
+cmake_minimum_required(VERSION 3.22)
+
+add_executable(
+ FullTest
+ srcs/FullTest.cpp
+)
+
+target_link_libraries(
+ FullTest PRIVATE
+ GTest::gtest_main commands utils testUtils repo
+)
+
+gtest_discover_tests(FullTest)
+
diff --git a/tests/fulltests/FullTest.cpp b/tests/fulltests/FullTest.cpp
deleted file mode 100644
index 440a0bf..0000000
--- a/tests/fulltests/FullTest.cpp
+++ /dev/null
@@ -1,418 +0,0 @@
-//
-// Created by Stepan Usatiuk on 16.04.2023.
-//
-
-#include "FullTest.h"
-#include "../../src/Logger.h"
-#include "../../src/commands/CommandRestore.h"
-#include "../../src/commands/CommandRun.h"
-#include "../../src/repo/FileRepository.h"
-#include "../utils/Cleaner.h"
-
-#include
-#include
-#include
-
-void randomChange(std::string path) {
- std::fstream s(path);
- auto pos = rand() % 50;
- s.seekp(pos, std::ios::beg);
- char out = rand() % 254;
- s.write(&out, 1);
-}
-
-std::unique_ptr FullTest::operator()() {
- auto tg = std::make_unique("Full tests");
-
- tg->addTest(std::make_unique("Simple backup/restore test", std::function([]() {
- Cleaner c({"testfrom", "testto", "testtores"});
- int aid = -1;
- {
- std::filesystem::create_directories("testfrom");
- for (int i = 0; i < 257; i++) {
- std::ofstream o(std::filesystem::path("testfrom") / ("f" + std::to_string(i)), std::ios::binary | std::ios::out | std::ios::trunc);
- for (int j = 0; j < i; j++) o.put(j % 256);
- }
- std::filesystem::create_directories("testfrom/testdir");
-
- Config conf;
- conf.add("repo", "testto").add("from", "testfrom");
-
- auto repo = std::make_unique(conf);
- repo->init();
-
- std::stringstream runnerout;
- Logger logger(1, runnerout);
-
- CommandRun run;
- run.run(Context{&logger, repo.get()});
-
- aid = repo->getObjects(Object::ObjectType::Archive).begin()->second;
- }
- {
- Config conf;
- conf.add("repo", "testto").add("aid", std::to_string(aid)).add("to", "testtores");
-
- auto repo = std::make_unique(conf);
- repo->open();
- std::stringstream runnerout;
- Logger logger(1, runnerout);
-
- CommandRestore cmd;
- cmd.run(Context{&logger, repo.get()});
- }
- {
- try {
- HelpfulAssert()(std::filesystem::is_directory("testtores/testdir"), true);
- } catch (...) {
- std::cerr << "Empty directory doesn't exist!" << std::endl;
- throw;
- }
-
- for (int i = 0; i < 257; i++) {
- std::ifstream o(std::filesystem::path("testtores") / ("f" + std::to_string(i)), std::ios::binary | std::ios::in);
- try {
- HelpfulAssert()(o.is_open(), true);
- for (int j = 0; j < i; j++) {
- char c;
- HelpfulAssert()(o.get(c).operator bool(), true);
- HelpfulAssert()(j % 256, c);
- }
- } catch (...) {
- std::cerr << "Error comparing file " << i << std::endl;
- throw;
- }
- }
- }
-
-
- return true;
- })));
- tg->addTest(std::make_unique("Simple backup/restore with ignore test", std::function([]() {
- Cleaner c({"testfrom", "testto", "testtores"});
- int aid = -1;
- {
- std::filesystem::create_directories("testfrom");
- for (int i = 0; i < 257; i++) {
- std::ofstream o(std::filesystem::path("testfrom") / ("f" + std::to_string(i)), std::ios::binary | std::ios::out | std::ios::trunc);
- for (int j = 0; j < i; j++) o.put(j % 256);
- }
- std::filesystem::create_directories("testfrom/testdir");
- std::filesystem::create_directories("testfrom/testdir2/testdir3");
- std::filesystem::create_directories("testfrom/testdir2/testdir4");
- {
- std::ofstream file("testfrom/testdir2/.ignore");
- file << "hello.txt";
- }
- {
- std::ofstream file("testfrom/testdir2/testdir3/.ignore");
- file << ".*\\.txt";
- }
- {
- std::ofstream file("testfrom/testdir2/hello.txt");
- file << "hello";
- }
- {
- std::ofstream file("testfrom/testdir2/testdir3/hello.txt");
- file << "hello2";
- }
- {
- std::ofstream file("testfrom/testdir2/testdir3/asdf.txt");
- file << "asdf1";
- }
- {
- std::ofstream file("testfrom/testdir2/testdir4/asdf.txt");
- file << "asdf2";
- }
-
- Config conf;
- conf.add("repo", "testto").add("from", "testfrom");
-
- auto repo = std::make_unique(conf);
- repo->init();
- std::stringstream runnerout;
- Logger logger(1, runnerout);
-
- CommandRun cmd;
- cmd.run(Context{&logger, repo.get()});
- aid = repo->getObjects(Object::ObjectType::Archive).begin()->second;
- }
- {
- Config conf;
- conf.add("repo", "testto").add("aid", std::to_string(aid)).add("to", "testtores");
-
- auto repo = std::make_unique(conf);
- repo->open();
- std::stringstream runnerout;
- Logger logger(1, runnerout);
-
- CommandRestore cmd;
- cmd.run(Context{&logger, repo.get()});
- }
- {
- HelpfulAssert()(std::filesystem::is_directory("testtores/testdir"), true);
-
- for (int i = 0; i < 257; i++) {
- std::ifstream o(std::filesystem::path("testtores") / ("f" + std::to_string(i)), std::ios::binary | std::ios::in);
- HelpfulAssert()(o.is_open(), true);
- for (int j = 0; j < i; j++) {
- char c;
- HelpfulAssert()(o.get(c).operator bool(), true);
- HelpfulAssert()(j % 256, c);
- }
- }
-
- {
- std::ifstream file("testtores/testdir2/.ignore");
- std::string s;
- file >> s;
- HelpfulAssert()(s, "hello.txt");
- }
- {
- std::ifstream file("testtores/testdir2/testdir3/.ignore");
- std::string s;
- file >> s;
- HelpfulAssert()(s, ".*\\.txt");
- }
- {
- std::ifstream file("testtores/testdir2/hello.txt");
- HelpfulAssert()(!file, true);
- }
- {
- std::ifstream file("testtores/testdir2/testdir3/hello.txt");
- HelpfulAssert()(!file, true);
- }
- {
- std::ifstream file("testtores/testdir2/testdir3/asdf.txt");
- HelpfulAssert()(!file, true);
- }
- {
- std::ifstream file("testtores/testdir2/testdir4/asdf.txt");
- std::string s;
- file >> s;
- HelpfulAssert()(s, "asdf2");
- }
- }
-
-
- return true;
- })));
-
- tg->addTest(std::make_unique("Backup/restore test with compression", std::function([]() {
- Cleaner c({"testfrom", "testto", "testtores"});
- int aid = -1;
- {
- std::filesystem::create_directories("testfrom");
- for (int i = 0; i < 257; i++) {
- std::ofstream o(std::filesystem::path("testfrom") / ("f" + std::to_string(i)), std::ios::binary | std::ios::out | std::ios::trunc);
- for (int j = 0; j < i; j++) o.put(j % 256);
- }
- std::filesystem::create_directories("testfrom/testdir");
-
- Config conf;
- conf.add("repo", "testto").add("compression", "zlib").add("from", "testfrom");
-
- auto repo = std::make_unique(conf);
- repo->init();
- std::stringstream runnerout;
- Logger logger(1, runnerout);
-
- CommandRun cmd;
- cmd.run(Context{&logger, repo.get()});
- aid = repo->getObjects(Object::ObjectType::Archive).begin()->second;
- }
- {
- Config conf;
- conf.add("repo", "testto").add("aid", std::to_string(aid)).add("to", "testtores");
-
- auto repo = std::make_unique(conf);
- repo->open();
- std::stringstream runnerout;
- Logger logger(1, runnerout);
-
- CommandRestore cmd;
- cmd.run(Context{&logger, repo.get()});
- }
- {
- HelpfulAssert()(std::filesystem::is_directory("testtores/testdir"), true);
-
- for (int i = 0; i < 257; i++) {
- std::ifstream o(std::filesystem::path("testtores") / ("f" + std::to_string(i)), std::ios::binary | std::ios::in);
- HelpfulAssert()(o.is_open(), true);
- for (int j = 0; j < i; j++) {
- char c;
- HelpfulAssert()(o.get(c).operator bool(), true);
- HelpfulAssert()(j % 256, c);
- }
- }
- }
-
-
- return true;
- })));
- tg->addTest(std::make_unique("Backup/restore test with compression/encryption", std::function([]() {
- Cleaner c({"testfrom", "testto", "testtores"});
- int aid = -1;
- {
- std::filesystem::create_directories("testfrom");
- for (int i = 0; i < 257; i++) {
- std::ofstream o(std::filesystem::path("testfrom") / ("f" + std::to_string(i)), std::ios::binary | std::ios::out | std::ios::trunc);
- for (int j = 0; j < i; j++) o.put(j % 256);
- }
- std::filesystem::create_directories("testfrom/testdir");
-
- Config conf;
- conf.add("repo", "testto").add("compression", "zlib").add("from", "testfrom").add("encryption", "aes").add("password", "testp").add("salt", "tests");
-
- auto repo = std::make_unique(conf);
- repo->init();
-
- std::stringstream runnerout;
- Logger logger(1, runnerout);
-
- CommandRun cmd;
- cmd.run(Context{&logger, repo.get()});
- aid = repo->getObjects(Object::ObjectType::Archive).begin()->second;
- }
- {
- Config conf;
- conf.add("repo", "testto");
-
- auto repo = std::make_unique(conf);
-
- bool ok = true;
- try {
- HelpfulAssert()(repo->open(), false);
- ok = false;
- } catch (...) {}
- HelpfulAssert()(ok, true);
- }
- {
- Config conf;
- conf.add("repo", "testto").add("password", "testp").add("aid", std::to_string(aid)).add("to", "testtores");
-
- auto repo = std::make_unique(conf);
- repo->open();
-
- std::stringstream runnerout;
- Logger logger(1, runnerout);
-
- CommandRestore cmd;
- cmd.run(Context{&logger, repo.get()});
- }
- {
- HelpfulAssert()(std::filesystem::is_directory("testtores/testdir"), true);
-
- for (int i = 0; i < 257; i++) {
- std::ifstream o(std::filesystem::path("testtores") / ("f" + std::to_string(i)), std::ios::binary | std::ios::in);
- HelpfulAssert()(o.is_open(), true);
- for (int j = 0; j < i; j++) {
- char c;
- HelpfulAssert()(o.get(c).operator bool(), true);
- HelpfulAssert()(j % 256, c);
- }
- }
- }
-
-
- return true;
- })));
- tg->addTest(std::make_unique("Repo data fuzz test", std::function([]() {
- srand(time(nullptr));
- std::vector confs;
- Config conf;
- conf.add("repo", "testto").add("compression", "none").add("from", "testfrom").add("encryption", "none").add("password", "testp").add("salt", "tests").add("progress", "none");
- confs.emplace_back(conf);
- conf = Config();
- conf.add("repo", "testto").add("compression", "zlib").add("from", "testfrom").add("encryption", "none").add("password", "testp").add("salt", "tests").add("progress", "none");
- confs.emplace_back(conf);
- conf = Config();
- conf.add("repo", "testto").add("compression", "none").add("from", "testfrom").add("encryption", "zlib").add("password", "testp").add("salt", "tests").add("progress", "none");
- confs.emplace_back(conf);
- conf = Config();
- conf.add("repo", "testto").add("compression", "zlib").add("from", "testfrom").add("encryption", "aes").add("password", "testp").add("salt", "tests").add("progress", "none");
- confs.emplace_back(conf);
-
- for (auto const &conf: confs) {
- for (uint8_t filetobreak = 1; filetobreak <= 15; filetobreak++) {
- std::cout << static_cast(filetobreak) << " / 15 tests done" << std::endl;
- for (uint8_t cutoff = 1; cutoff < 20; cutoff++) {
- Cleaner c({"testfrom", "testto", "testtores"});
-
- int aid = -1;
- {
- std::filesystem::create_directories("testfrom");
- for (int i = 0; i < 2; i++) {
- std::ofstream o(std::filesystem::path("testfrom") / ("f" + std::to_string(i)), std::ios::binary | std::ios::out | std::ios::trunc);
- for (int j = 0; j < i; j++) o.put(j % 2);
- }
-
-
- auto repo = std::make_unique(conf);
- repo->init();
-
- std::stringstream runnerout;
- Logger logger(1, runnerout);
-
- CommandRun cmd;
- cmd.run(Context{&logger, repo.get()});
- aid = repo->getObjects(Object::ObjectType::Archive).begin()->second;
- }
-
- {
- if (filetobreak & 0b00000001) {
- for (int i = 0; i < cutoff; i++)
- randomChange("testto/1");
- if (cutoff > 5)
- std::filesystem::resize_file("testto/1", std::filesystem::file_size("testto/1") - cutoff);
- }
- if (filetobreak & 0b00000010) {
- for (int i = 0; i < cutoff; i++)
- randomChange("testto/index");
- if (cutoff > 5)
- std::filesystem::resize_file("testto/index", std::filesystem::file_size("testto/index") - cutoff);
- }
- if (filetobreak & 0b00000100) {
- for (int i = 0; i < cutoff; i++)
- randomChange("testto/offsets");
- if (cutoff > 5)
- std::filesystem::resize_file("testto/offsets", std::filesystem::file_size("testto/offsets") - cutoff);
- }
- if (filetobreak & 0b00001000) {
- for (int i = 0; i < cutoff; i++)
- randomChange("testto/info");
- if (cutoff > 5)
- std::filesystem::resize_file("testto/info", std::filesystem::file_size("testto/info") - cutoff);
- }
- }
-
-
- {
- bool ok = true;
- try {
- Config confr = conf;
- confr.add("aid", std::to_string(aid)).add("to", "testtores");
-
- auto repo = std::make_unique(confr);
- repo->open();
-
- std::stringstream runnerout;
- Logger logger(1, runnerout);
-
- CommandRestore cmd;
- cmd.run(Context{&logger, repo.get()});
- auto outstr = runnerout.str();
- if (outstr.find("Error") == std::string::npos)
- ok = false;
- } catch (...) {}
- HelpfulAssert()(ok, true);
- }
- }
- }
- }
-
-
- return true;
- })));
- return tg;
-}
diff --git a/tests/fulltests/FullTest.h b/tests/fulltests/FullTest.h
deleted file mode 100644
index fa3ddbd..0000000
--- a/tests/fulltests/FullTest.h
+++ /dev/null
@@ -1,17 +0,0 @@
-//
-// Created by Stepan Usatiuk on 16.04.2023.
-//
-
-#ifndef SEMBACKUP_FULLTEST_H
-#define SEMBACKUP_FULLTEST_H
-
-
-#include "../utils/TestGroupGenerator.h"
-
-class FullTest : public TestGroupGenerator {
-public:
- std::unique_ptr operator()() override;
-};
-
-
-#endif//SEMBACKUP_FULLTEST_H
diff --git a/tests/fulltests/srcs/FullTest.cpp b/tests/fulltests/srcs/FullTest.cpp
new file mode 100644
index 0000000..fb93c1f
--- /dev/null
+++ b/tests/fulltests/srcs/FullTest.cpp
@@ -0,0 +1,402 @@
+//
+// Created by Stepan Usatiuk on 16.04.2023.
+//
+#include
+
+#include "Cleaner.h"
+#include "CommandRestore.h"
+#include "CommandRun.h"
+#include "FileRepository.h"
+#include "Logger.h"
+
+#include
+#include
+#include
+
+void randomChange(std::string path) {
+ std::fstream s(path);
+ auto pos = rand() % 50;
+ s.seekp(pos, std::ios::beg);
+ char out = rand() % 254;
+ s.write(&out, 1);
+}
+
+TEST(FullTest, Simple) {
+ Cleaner c({"testfrom", "testto", "testtores"});
+ int aid = -1;
+ {
+ std::filesystem::create_directories("testfrom");
+ for (int i = 0; i < 257; i++) {
+ std::ofstream o(std::filesystem::path("testfrom") / ("f" + std::to_string(i)), std::ios::binary | std::ios::out | std::ios::trunc);
+ for (int j = 0; j < i; j++) o.put(static_cast(j % 256));
+ }
+ std::filesystem::create_directories("testfrom/testdir");
+
+ Config conf;
+ conf.add("repo", "testto").add("from", "testfrom");
+
+ auto repo = std::make_unique(conf);
+ repo->init();
+
+ std::stringstream runnerout;
+ Logger logger(1, runnerout);
+
+ CommandRun run;
+ run.run(Context{&logger, repo.get()});
+
+ aid = repo->getObjects(Object::ObjectType::Archive).begin()->second;
+ }
+ {
+ Config conf;
+ conf.add("repo", "testto").add("aid", std::to_string(aid)).add("to", "testtores");
+
+ auto repo = std::make_unique(conf);
+ repo->open();
+ std::stringstream runnerout;
+ Logger logger(1, runnerout);
+
+ CommandRestore cmd;
+ cmd.run(Context{&logger, repo.get()});
+ }
+ {
+ try {
+ EXPECT_EQ(std::filesystem::is_directory("testtores/testdir"), true);
+ } catch (...) {
+ std::cerr << "Empty directory doesn't exist!" << std::endl;
+ throw;
+ }
+
+ for (int i = 0; i < 257; i++) {
+ std::ifstream o(std::filesystem::path("testtores") / ("f" + std::to_string(i)), std::ios::binary | std::ios::in);
+ try {
+ EXPECT_EQ(o.is_open(), true);
+ for (int j = 0; j < i; j++) {
+ char c;
+ EXPECT_EQ(o.get(c).operator bool(), true);
+ EXPECT_EQ(static_cast(j % 256), c);
+ }
+ } catch (...) {
+ std::cerr << "Error comparing file " << i << std::endl;
+ throw;
+ }
+ }
+ }
+}
+
+TEST(FullTest, SimpleWithIgnore) {
+ Cleaner c({"testfrom", "testto", "testtores"});
+ int aid = -1;
+ {
+ std::filesystem::create_directories("testfrom");
+ for (int i = 0; i < 257; i++) {
+ std::ofstream o(std::filesystem::path("testfrom") / ("f" + std::to_string(i)), std::ios::binary | std::ios::out | std::ios::trunc);
+ for (int j = 0; j < i; j++) o.put(static_cast(j % 256));
+ }
+ std::filesystem::create_directories("testfrom/testdir");
+ std::filesystem::create_directories("testfrom/testdir2/testdir3");
+ std::filesystem::create_directories("testfrom/testdir2/testdir4");
+ {
+ std::ofstream file("testfrom/testdir2/.ignore");
+ file << "hello.txt";
+ }
+ {
+ std::ofstream file("testfrom/testdir2/testdir3/.ignore");
+ file << ".*\\.txt";
+ }
+ {
+ std::ofstream file("testfrom/testdir2/hello.txt");
+ file << "hello";
+ }
+ {
+ std::ofstream file("testfrom/testdir2/testdir3/hello.txt");
+ file << "hello2";
+ }
+ {
+ std::ofstream file("testfrom/testdir2/testdir3/asdf.txt");
+ file << "asdf1";
+ }
+ {
+ std::ofstream file("testfrom/testdir2/testdir4/asdf.txt");
+ file << "asdf2";
+ }
+
+ Config conf;
+ conf.add("repo", "testto").add("from", "testfrom");
+
+ auto repo = std::make_unique(conf);
+ repo->init();
+ std::stringstream runnerout;
+ Logger logger(1, runnerout);
+
+ CommandRun cmd;
+ cmd.run(Context{&logger, repo.get()});
+ aid = repo->getObjects(Object::ObjectType::Archive).begin()->second;
+ }
+ {
+ Config conf;
+ conf.add("repo", "testto").add("aid", std::to_string(aid)).add("to", "testtores");
+
+ auto repo = std::make_unique(conf);
+ repo->open();
+ std::stringstream runnerout;
+ Logger logger(1, runnerout);
+
+ CommandRestore cmd;
+ cmd.run(Context{&logger, repo.get()});
+ }
+ {
+ EXPECT_EQ(std::filesystem::is_directory("testtores/testdir"), true);
+
+ for (int i = 0; i < 257; i++) {
+ std::ifstream o(std::filesystem::path("testtores") / ("f" + std::to_string(i)), std::ios::binary | std::ios::in);
+ EXPECT_EQ(o.is_open(), true);
+ for (int j = 0; j < i; j++) {
+ char c;
+ EXPECT_EQ(o.get(c).operator bool(), true);
+ EXPECT_EQ(static_cast(j % 256), c);
+ }
+ }
+
+ {
+ std::ifstream file("testtores/testdir2/.ignore");
+ std::string s;
+ file >> s;
+ EXPECT_EQ(s, "hello.txt");
+ }
+ {
+ std::ifstream file("testtores/testdir2/testdir3/.ignore");
+ std::string s;
+ file >> s;
+ EXPECT_EQ(s, ".*\\.txt");
+ }
+ {
+ std::ifstream file("testtores/testdir2/hello.txt");
+ EXPECT_EQ(!file, true);
+ }
+ {
+ std::ifstream file("testtores/testdir2/testdir3/hello.txt");
+ EXPECT_EQ(!file, true);
+ }
+ {
+ std::ifstream file("testtores/testdir2/testdir3/asdf.txt");
+ EXPECT_EQ(!file, true);
+ }
+ {
+ std::ifstream file("testtores/testdir2/testdir4/asdf.txt");
+ std::string s;
+ file >> s;
+ EXPECT_EQ(s, "asdf2");
+ }
+ }
+}
+
+TEST(FullTest, SimpleWithCompress) {
+ Cleaner c({"testfrom", "testto", "testtores"});
+ int aid = -1;
+ {
+ std::filesystem::create_directories("testfrom");
+ for (int i = 0; i < 257; i++) {
+ std::ofstream o(std::filesystem::path("testfrom") / ("f" + std::to_string(i)), std::ios::binary | std::ios::out | std::ios::trunc);
+ for (int j = 0; j < i; j++) o.put(static_cast(j % 256));
+ }
+ std::filesystem::create_directories("testfrom/testdir");
+
+ Config conf;
+ conf.add("repo", "testto").add("compression", "zlib").add("from", "testfrom");
+
+ auto repo = std::make_unique(conf);
+ repo->init();
+ std::stringstream runnerout;
+ Logger logger(1, runnerout);
+
+ CommandRun cmd;
+ cmd.run(Context{&logger, repo.get()});
+ aid = repo->getObjects(Object::ObjectType::Archive).begin()->second;
+ }
+ {
+ Config conf;
+ conf.add("repo", "testto").add("aid", std::to_string(aid)).add("to", "testtores");
+
+ auto repo = std::make_unique(conf);
+ repo->open();
+ std::stringstream runnerout;
+ Logger logger(1, runnerout);
+
+ CommandRestore cmd;
+ cmd.run(Context{&logger, repo.get()});
+ }
+ {
+ EXPECT_EQ(std::filesystem::is_directory("testtores/testdir"), true);
+
+ for (int i = 0; i < 257; i++) {
+ std::ifstream o(std::filesystem::path("testtores") / ("f" + std::to_string(i)), std::ios::binary | std::ios::in);
+ EXPECT_EQ(o.is_open(), true);
+ for (int j = 0; j < i; j++) {
+ char c;
+ EXPECT_EQ(o.get(c).operator bool(), true);
+ EXPECT_EQ(static_cast(j % 256), c);
+ }
+ }
+ }
+}
+
+TEST(FullTest, SimpleWithCompEnd) {
+ Cleaner c({"testfrom", "testto", "testtores"});
+ int aid = -1;
+ {
+ std::filesystem::create_directories("testfrom");
+ for (int i = 0; i < 257; i++) {
+ std::ofstream o(std::filesystem::path("testfrom") / ("f" + std::to_string(i)), std::ios::binary | std::ios::out | std::ios::trunc);
+ for (int j = 0; j < i; j++) o.put(static_cast(j % 256));
+ }
+ std::filesystem::create_directories("testfrom/testdir");
+
+ Config conf;
+ conf.add("repo", "testto").add("compression", "zlib").add("from", "testfrom").add("encryption", "aes").add("password", "testp").add("salt", "tests");
+
+ auto repo = std::make_unique(conf);
+ repo->init();
+
+ std::stringstream runnerout;
+ Logger logger(1, runnerout);
+
+ CommandRun cmd;
+ cmd.run(Context{&logger, repo.get()});
+ aid = repo->getObjects(Object::ObjectType::Archive).begin()->second;
+ }
+ {
+ Config conf;
+ conf.add("repo", "testto");
+
+ auto repo = std::make_unique(conf);
+
+ bool ok = true;
+ try {
+ EXPECT_EQ(repo->open(), false);
+ ok = false;
+ } catch (...) {}
+ EXPECT_EQ(ok, true);
+ }
+ {
+ Config conf;
+ conf.add("repo", "testto").add("password", "testp").add("aid", std::to_string(aid)).add("to", "testtores");
+
+ auto repo = std::make_unique(conf);
+ repo->open();
+
+ std::stringstream runnerout;
+ Logger logger(1, runnerout);
+
+ CommandRestore cmd;
+ cmd.run(Context{&logger, repo.get()});
+ }
+ {
+ EXPECT_EQ(std::filesystem::is_directory("testtores/testdir"), true);
+
+ for (int i = 0; i < 257; i++) {
+ std::ifstream o(std::filesystem::path("testtores") / ("f" + std::to_string(i)), std::ios::binary | std::ios::in);
+ EXPECT_EQ(o.is_open(), true);
+ for (int j = 0; j < i; j++) {
+ char c;
+ EXPECT_EQ(o.get(c).operator bool(), true);
+ EXPECT_EQ(static_cast(j % 256), c);
+ }
+ }
+ }
+}
+
+TEST(FullTest, Fuzz) {
+ GTEST_SKIP();
+ srand(time(nullptr));
+ std::vector confs;
+ Config conf;
+ conf.add("repo", "testto").add("compression", "none").add("from", "testfrom").add("encryption", "none").add("password", "testp").add("salt", "tests").add("progress", "none");
+ confs.emplace_back(conf);
+ conf = Config();
+ conf.add("repo", "testto").add("compression", "zlib").add("from", "testfrom").add("encryption", "none").add("password", "testp").add("salt", "tests").add("progress", "none");
+ confs.emplace_back(conf);
+ conf = Config();
+ conf.add("repo", "testto").add("compression", "none").add("from", "testfrom").add("encryption", "zlib").add("password", "testp").add("salt", "tests").add("progress", "none");
+ confs.emplace_back(conf);
+ conf = Config();
+ conf.add("repo", "testto").add("compression", "zlib").add("from", "testfrom").add("encryption", "aes").add("password", "testp").add("salt", "tests").add("progress", "none");
+ confs.emplace_back(conf);
+
+ for (auto const &conf: confs) {
+ for (uint8_t filetobreak = 1; filetobreak <= 15; filetobreak++) {
+ std::cout << static_cast(filetobreak) << " / 15 tests done" << std::endl;
+ for (uint8_t cutoff = 1; cutoff < 20; cutoff++) {
+ Cleaner c({"testfrom", "testto", "testtores"});
+
+ int aid = -1;
+ {
+ std::filesystem::create_directories("testfrom");
+ for (int i = 0; i < 2; i++) {
+ std::ofstream o(std::filesystem::path("testfrom") / ("f" + std::to_string(i)), std::ios::binary | std::ios::out | std::ios::trunc);
+ for (int j = 0; j < i; j++) o.put(j % 2);
+ }
+
+
+ auto repo = std::make_unique(conf);
+ repo->init();
+
+ std::stringstream runnerout;
+ Logger logger(1, runnerout);
+
+ CommandRun cmd;
+ cmd.run(Context{&logger, repo.get()});
+ aid = repo->getObjects(Object::ObjectType::Archive).begin()->second;
+ }
+
+ {
+ if (filetobreak & 0b00000001) {
+ for (int i = 0; i < cutoff; i++)
+ randomChange("testto/1");
+ if (cutoff > 5)
+ std::filesystem::resize_file("testto/1", std::filesystem::file_size("testto/1") - cutoff);
+ }
+ if (filetobreak & 0b00000010) {
+ for (int i = 0; i < cutoff; i++)
+ randomChange("testto/index");
+ if (cutoff > 5)
+ std::filesystem::resize_file("testto/index", std::filesystem::file_size("testto/index") - cutoff);
+ }
+ if (filetobreak & 0b00000100) {
+ for (int i = 0; i < cutoff; i++)
+ randomChange("testto/offsets");
+ if (cutoff > 5)
+ std::filesystem::resize_file("testto/offsets", std::filesystem::file_size("testto/offsets") - cutoff);
+ }
+ if (filetobreak & 0b00001000) {
+ for (int i = 0; i < cutoff; i++)
+ randomChange("testto/info");
+ if (cutoff > 5)
+ std::filesystem::resize_file("testto/info", std::filesystem::file_size("testto/info") - cutoff);
+ }
+ }
+
+
+ {
+ bool ok = true;
+ try {
+ Config confr = conf;
+ confr.add("aid", std::to_string(aid)).add("to", "testtores");
+
+ auto repo = std::make_unique(confr);
+ repo->open();
+
+ std::stringstream runnerout;
+ Logger logger(1, runnerout);
+
+ CommandRestore cmd;
+ cmd.run(Context{&logger, repo.get()});
+ auto outstr = runnerout.str();
+ if (outstr.find("Error") == std::string::npos)
+ ok = false;
+ } catch (...) {}
+ EXPECT_EQ(ok, true);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/repo/CMakeLists.txt b/tests/repo/CMakeLists.txt
new file mode 100644
index 0000000..61f52f0
--- /dev/null
+++ b/tests/repo/CMakeLists.txt
@@ -0,0 +1,24 @@
+cmake_minimum_required(VERSION 3.22)
+
+add_executable(
+ FileRepositoryTest
+ srcs/FileRepositoryTest.cpp
+)
+
+target_link_libraries(
+ FileRepositoryTest PRIVATE
+ GTest::gtest_main commands utils testUtils repo
+)
+
+add_executable(
+ ChunkTest
+ srcs/ChunkTest.cpp
+)
+
+target_link_libraries(
+ ChunkTest PRIVATE
+ GTest::gtest_main commands utils testUtils repo
+)
+
+gtest_discover_tests(ChunkTest)
+gtest_discover_tests(FileRepositoryTest)
diff --git a/tests/repo/ChunkTest.cpp b/tests/repo/ChunkTest.cpp
deleted file mode 100644
index a9bbcdd..0000000
--- a/tests/repo/ChunkTest.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-//
-// Created by Stepan Usatiuk on 14.04.2023.
-//
-
-#include "ChunkTest.h"
-#include "../../src/repo/Serialize.h"
-#include "../utils/Cleaner.h"
-
-std::unique_ptr ChunkTest::operator()() {
- auto tg = std::make_unique("Chunk tests");
-
- tg->addTest(std::make_unique("De/serialize test", std::function([]() {
- std::vector s1, s2;
- {
- std::vector data1{'a', 'b', 'c', 'e'};
- Chunk o1(666, {0}, data1);
- std::vector data2{'q', 'w', 'e', 'r', 'b'};
- Chunk o2(777, {1}, data2);
-
- s1 = Serialize::serialize(o1);
- s2 = Serialize::serialize(o2);
- }
- {
- auto s1b = s1.cbegin();
- auto s2b = s2.cbegin();
- Chunk o1(s1b, s1.cend()), o2(s2b, s2.cend());
-
- std::vector data1{'a', 'b', 'c', 'e'};
- Chunk o1e(666, {0}, data1);
- std::vector data2{'q', 'w', 'e', 'r', 'b'};
- Chunk o2e(777, {1}, data2);
-
- HelpfulAssert()(o1.id, o1e.id);
- HelpfulAssert()(o2.id, o2e.id);
- HelpfulAssert()((int) o1.type, (int) o1e.type);
- HelpfulAssert()((int) o2.type, (int) o2e.type);
-
- HelpfulAssert()(o1.data.size(), o1e.data.size());
- HelpfulAssert()(o2.data.size(), o2e.data.size());
- for (int i = 0; i < o1.data.size(); i++) {
- HelpfulAssert()(o1.data[i], o1e.data[i]);
- }
- for (int i = 0; i < o2.data.size(); i++) {
- HelpfulAssert()(o2.data[i], o2e.data[i]);
- }
-
- for (int i = 0; i < o1.md5.size(); i++) {
- HelpfulAssert()(o1.md5[i], o1e.md5[i]);
- }
- for (int i = 0; i < o2.md5.size(); i++) {
- HelpfulAssert()(o2.md5[i], o2e.md5[i]);
- }
- }
-
- return true;
- })));
-
- tg->addTest(std::make_unique("Garbage throw test", std::function([]() {
- std::vector e{'a', 'b'};
- auto eb = e.cbegin();
- try {
- Chunk o1(eb, e.cend());
- } catch (...) {
- return true;
- }
- throw Exception("Object constructed with garbage data!");
- })));
- tg->addTest(std::make_unique("Garbage throw test2", std::function([]() {
- std::vector e{'s', 'e', 'm', 'b', 'a', 'a'};
- auto eb = e.cbegin();
- try {
- Chunk o1(eb, e.cend());
- } catch (...) {
- return true;
- }
- throw Exception("Object constructed with garbage data!");
- })));
- tg->addTest(std::make_unique("Garbage throw test3", std::function([]() {
- std::vector s1, s2;
- {
- std::vector data1{'a', 'b', 'c', 'e'};
- Chunk o1(666, {0}, data1);
- std::vector data2{'q', 'w', 'e', 'r', 'b'};
- Chunk o2(777, {1}, data2);
-
- s1 = Serialize::serialize(o1);
- s2 = Serialize::serialize(o2);
- }
- {
- s1.resize(s1.size() - 1);
- s2.resize(s1.size() - 2);
- bool fail = false;
-
- try {
- Chunk o1 = Serialize::deserialize(s1);
- fail = true;
- } catch (...) {
- }
-
- try {
- Chunk o2 = Serialize::deserialize(s2);
- fail = true;
- } catch (...) {
- }
-
- if (fail)
- throw Exception("Object constructed with garbage data!");
- }
- return true;
- })));
-
- return tg;
-}
\ No newline at end of file
diff --git a/tests/repo/ChunkTest.h b/tests/repo/ChunkTest.h
deleted file mode 100644
index 1822f1f..0000000
--- a/tests/repo/ChunkTest.h
+++ /dev/null
@@ -1,21 +0,0 @@
-//
-// Created by Stepan Usatiuk on 14.04.2023.
-//
-
-#ifndef SEMBACKUP_CHUNKTEST_H
-#define SEMBACKUP_CHUNKTEST_H
-
-#include
-#include
-#include
-
-#include "../../src/repo/objects/Chunk.h"
-#include "../utils/TestGroupGenerator.h"
-
-class ChunkTest : public TestGroupGenerator {
-public:
- std::unique_ptr operator()() override;
-};
-
-
-#endif//SEMBACKUP_CHUNKTEST_H
diff --git a/tests/repo/FileRepositoryTest.cpp b/tests/repo/FileRepositoryTest.cpp
deleted file mode 100644
index 20bb613..0000000
--- a/tests/repo/FileRepositoryTest.cpp
+++ /dev/null
@@ -1,301 +0,0 @@
-//
-// Created by Stepan Usatiuk on 14.04.2023.
-//
-
-#include "FileRepositoryTest.h"
-
-std::unique_ptr FileRepositoryTest::operator()() {
- auto tg = std::make_unique("FileRepository tests");
-
- tg->addTest(std::make_unique("De/serialize test", std::function([]() {
- Cleaner c({"testrepo"});
-
- {
- Config conf;
- conf.add("repo", "testrepo");
- FileRepository repo(conf);
- repo.init();
- std::vector
- data1{'a', 'b', 'c', 'e'};
-
- std::string o1k(16, '\0');
- std::string o2k(16, '\0');
- o2k[0] = 1;
- o2k[1] = 2;
-
- Chunk o1(666, o1k, data1);
- std::vector