forked from CloudPolis/webdav-client-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean.cpp
More file actions
183 lines (124 loc) · 4.95 KB
/
Copy pathclean.cpp
File metadata and controls
183 lines (124 loc) · 4.95 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*#***************************************************************************
# __ __ _____ _____
# Project | | | | | \ / ___|
# | |__| | | |\ \ / /
# | | | | ) ) ( (
# | /\ | | |/ / \ \___
# \_/ \_/ |_____/ \_____|
#
# Copyright (C) 2016, The WDC Project, <designerror@yandex.ru>, et al.
#
# This software is licensed as described in the file LICENSE, which
# you should have received as part of this distribution.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the LICENSE file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
############################################################################*/
#include <catch.hpp>
#include <webdav/client.hpp>
#include "fixture.hpp"
SCENARIO("Client must clean an existing remote resources", "[clean]") {
auto options = fixture::get_options();
auto content = fixture::get_buff_content();
auto dirname = fixture::get_dir_name();
auto filename = fixture::get_file_name();
CAPTURE(dirname);
CAPTURE(filename);
std::unique_ptr<WebDAV::Client> client(WebDAV::Client::Init(options));
GIVEN("An existing remote resource") {
std::string existing_file = filename;
std::string existing_directory = dirname;
client->upload_from(existing_file, (char *)content.c_str(), content.length());
client->create_directory(existing_directory);
WHEN("Clean an existing remote file") {
REQUIRE(client->check(existing_file));
auto is_success = client->clean(existing_file);
THEN("The file is cleaning") {
CHECK(is_success);
CHECK_FALSE(client->check(existing_file));
}
}
WHEN("Clean an existing directory") {
REQUIRE(client->check(existing_directory));
auto is_success = client->clean(existing_directory);
THEN("The directory is cleaning") {
CHECK(is_success);
CHECK_FALSE(client->check(existing_directory));
}
}
}
}
SCENARIO("Client must clean not an existing remote resources", "[clean]") {
auto options = fixture::get_options();
std::unique_ptr<WebDAV::Client> client(WebDAV::Client::Init(options));
GIVEN("Not an existing remote resource") {
std::string not_existing_file = "not_existing_file.dat";
std::string not_existing_directory = "not_existing_directory/";
WHEN("Clean not an existing remote file") {
REQUIRE_FALSE(client->check(not_existing_file));
auto is_success = client->clean(not_existing_file);
THEN("The file is cleaning") {
CHECK(is_success);
CHECK_FALSE(client->check(not_existing_file));
}
}
WHEN("Clean not an existing directory") {
REQUIRE_FALSE(client->check(not_existing_directory));
auto is_success = client->clean(not_existing_directory);
THEN("The directory is cleaning") {
CHECK(is_success);
CHECK_FALSE(client->check(not_existing_directory));
}
}
}
}
SCENARIO("Client must clean not an empty remote directories", "[clean]") {
auto options = fixture::get_options();
auto content = fixture::get_buff_content();
auto dirname = fixture::get_dir_name();
CAPTURE(dirname);
std::unique_ptr<WebDAV::Client> client(WebDAV::Client::Init(options));
GIVEN("Not an empty remote directory") {
std::string not_empty_directory = dirname;
std::string attached_file = not_empty_directory + "/" + "attached_file.dat";
std::string attached_directory = not_empty_directory + "/" + "attached_directory/";
client->create_directory(not_empty_directory);
client->upload_from(attached_file, (char *)content.c_str(), content.length());
client->create_directory(attached_directory);
WHEN("Clean not an empty directory") {
REQUIRE(client->check(not_empty_directory));
REQUIRE(client->check(attached_file));
REQUIRE(client->check(attached_directory));
auto is_success = client->clean(not_empty_directory);
REQUIRE(is_success);
THEN("The directory and the attached resources are cleaning") {
CHECK_FALSE(client->check(not_empty_directory));
CHECK_FALSE(client->check(attached_file));
CHECK_FALSE(client->check(attached_directory));
}
}
}
}
SCENARIO("Client must clean a remote directory", "[clean]") {
auto options = fixture::get_options();
auto dirname = fixture::get_dir_name();
CAPTURE(dirname);
std::unique_ptr<WebDAV::Client> client(WebDAV::Client::Init(options));
GIVEN("An existing directory") {
std::string directory_name = dirname;
client->create_directory(directory_name);
WHEN("Clean directory by a name") {
REQUIRE(client->check(directory_name));
auto is_success = client->clean(directory_name);
REQUIRE(is_success);
THEN("The directory is cleaning") {
CHECK_FALSE(client->check(directory_name));
}
}
}
}