-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTests.cpp
More file actions
62 lines (55 loc) · 2.25 KB
/
Copy pathTests.cpp
File metadata and controls
62 lines (55 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "Functional/FolderTerrorist.h"
#include <gtest/gtest.h>
using namespace BMSTU;
void createFiles(const std::filesystem::path &path_to_folder);
void addFile(const std::filesystem::path &path_to_folder);
void startTerror(const std::filesystem::path &path_to_folder, int &res) {
FolderTerror::signalProcessing();
FolderTerror::getInstance(path_to_folder).startTerror();
res = FolderTerror::checkTerFiles(path_to_folder);
}
TEST(FirstTest, CheckTerFiles) {
int res = 0;
std::filesystem::path path_to_folder = "Terror";
std::filesystem::remove_all(path_to_folder);
std::filesystem::create_directory(path_to_folder);
createFiles(path_to_folder);
std::thread thread(startTerror, std::ref(path_to_folder), std::ref(res));
std::this_thread::sleep_for(std::chrono::seconds(1));
raise(SIGTERM);
thread.join();
EXPECT_NO_THROW(true);
}
TEST(SecondTest, ProhibitionOnTheCreationOfASecondInstanceOfTheClass) {
int res1 = 0, res2 = 0;
std::filesystem::path path_to_folder_one = "Terror";
std::filesystem::path path_to_folder_two = "NoTerror";
std::filesystem::remove_all(path_to_folder_one);
std::filesystem::remove_all(path_to_folder_two);
std::filesystem::create_directory(path_to_folder_one);
std::filesystem::create_directory(path_to_folder_two);
createFiles(path_to_folder_one);
createFiles(path_to_folder_two);
std::thread thread_one(startTerror, std::ref(path_to_folder_one), std::ref(res1));
std::this_thread::sleep_for(std::chrono::seconds(1));
std::thread thread_two(startTerror, std::ref(path_to_folder_two), std::ref(res2));
std::this_thread::sleep_for(std::chrono::seconds(1));
raise(SIGTERM);
thread_one.join();
thread_two.join();
EXPECT_NO_THROW(true);
}
TEST(ThirdTest, CheckForTerrorAfterSignal) {
int res = 0;
std::filesystem::path path_to_folder = "Terror";
std::filesystem::remove_all(path_to_folder);
std::filesystem::create_directory(path_to_folder);
createFiles(path_to_folder);
std::thread thread(startTerror, std::ref(path_to_folder), std::ref(res));
addFile(path_to_folder);
std::this_thread::sleep_for(std::chrono::seconds(3));
raise(SIGTERM);
addFile(path_to_folder);
thread.join();
EXPECT_NO_THROW(true);
}