-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.cpp
More file actions
76 lines (54 loc) · 1.83 KB
/
Copy pathexample_test.cpp
File metadata and controls
76 lines (54 loc) · 1.83 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <gtest/gtest.h>
#include "Terrorist/Terrorist.h"
void startTerror(fs::path &folderName) {
FolderTerrorist::_myHandlerWork();
FolderTerrorist::_getInstance(folderName)._start();
}
TEST(Terrorist, createAnotherTerrorist) {
std::string folderName = "folderTerror";
std::string anotherFolder = "anotherFolder";
fs::path path = fs::current_path() / folderName;
fs::path anotherPath = fs::current_path() / anotherFolder;
fs::create_directory(path);
fs::create_directory(anotherPath);
fillFolder(path);
fillFolder(anotherPath);
std::thread thr_1(startTerror, std::ref(path));
std::thread thr_2(startTerror, std::ref(anotherPath));
std::this_thread::sleep_for(std::chrono::seconds(2));
std::this_thread::sleep_for(std::chrono::seconds(2));
sleep(2);
std::raise(15);
thr_1.join();
thr_2.join();
bool ifFilesTerrorised = ifSuccess(path);
fs::remove_all(path);
fs::remove_all(anotherPath);
EXPECT_TRUE(ifFilesTerrorised);
}
TEST(Terrorist, wrongPath) {
fs::path wrongPath = "wrongPath";
sleep(1);
try {
startTerror(wrongPath);
} catch (std::logic_error &logic_error) {
EXPECT_STREQ(logic_error.what(), "wrong path");
}
}
TEST(Terrorist, addFilesWhileRunning) {
std::string folderName = "folderTerror";
std::string fileName = "addedFile.txt";
fs::path path = fs::current_path() / folderName;
fs::path addedFilePath = path / fileName;
fs::create_directory(path);
fillFolder(path);
std::thread thr_1(startTerror, std::ref(path));
std::this_thread::sleep_for(std::chrono::seconds(2));
sleep(2);
std::raise(15);
addFile(addedFilePath);
thr_1.join();
bool findAddedFile = fs::exists(addedFilePath.string() + ".terror");
fs::remove_all(path);
EXPECT_TRUE(findAddedFile);
}