Skip to content

Commit fe1bb30

Browse files
committed
1 parent db745d7 commit fe1bb30

13 files changed

Lines changed: 310 additions & 172 deletions

File tree

CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,23 @@ endif()
5151
hunter_add_package(OpenSSL)
5252
hunter_add_package(CURL)
5353
hunter_add_package(pugixml)
54+
hunter_add_package(Boost COMPONENTS system filesystem)
5455

5556
find_package(OpenSSL REQUIRED)
5657
find_package(CURL CONFIG REQUIRED)
5758
find_package(pugixml CONFIG REQUIRED)
59+
find_package(Boost CONFIG REQUIRED system filesystem)
5860

5961
file(GLOB ${PROJECT_NAME}_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/sources/*.cpp")
6062
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/)
6163

6264
add_library(${PROJECT_NAME} ${${PROJECT_NAME}_SOURCES})
6365

64-
target_link_libraries(${PROJECT_NAME} OpenSSL::SSL OpenSSL::Crypto CURL::libcurl pugixml)
66+
target_link_libraries(${PROJECT_NAME} OpenSSL::SSL OpenSSL::Crypto CURL::libcurl pugixml Boost::filesystem Boost::system)
6567

6668
target_include_directories(${PROJECT_NAME} PUBLIC
67-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
68-
$<INSTALL_INTERFACE:include>
69+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
70+
$<INSTALL_INTERFACE:include>
6971
)
7072

7173
install(TARGETS ${PROJECT_NAME}
@@ -86,7 +88,7 @@ if(BUILD_TESTS)
8688
enable_testing()
8789
file(GLOB ${PROJECT_NAME}_TEST_SOURCES tests/*.cpp)
8890
add_executable(check ${${PROJECT_NAME}_TEST_SOURCES})
89-
target_link_libraries(check ${PROJECT_NAME} ${DEPENDS_LIBRARIES})
91+
target_link_libraries(check ${PROJECT_NAME})
9092
add_test(NAME check COMMAND check "-s" "-r" "compact" "--use-colour" "yes")
9193
endif()
9294

include/webdav/client.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ namespace WebDAV
102102
/// Checks whether the resource directory
103103
/// \param[in] remote_resource
104104
///
105-
auto is_dir(const std::string& remote_resource) const noexcept -> bool;
105+
auto is_directory(const std::string& remote_resource) const noexcept -> bool;
106106

107107
///
108108
/// List a remote directory

sources/client.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -568,13 +568,13 @@ namespace WebDAV
568568
}
569569

570570
bool
571-
Client::is_dir(const std::string& remote_resource) const noexcept
571+
Client::is_directory(const std::string& remote_resource) const noexcept
572572
{
573573
auto information = this->info(remote_resource);
574574
auto resource_type = information["type"];
575-
bool is_directory = resource_type.compare("d:collection") == 0;
576-
is_directory |= resource_type.compare("D:collection") == 0;
577-
return is_directory;
575+
bool is_dir = resource_type.compare("d:collection") == 0;
576+
is_dir |= resource_type.compare("D:collection") == 0;
577+
return is_dir;
578578
}
579579

580580
strings_t
@@ -584,8 +584,6 @@ namespace WebDAV
584584
bool is_existed = this->check(remote_directory);
585585
if (!is_existed) return strings_t();
586586

587-
bool is_directory = this->is_dir(remote_directory);
588-
if (!is_directory) return strings_t();
589587
auto target_urn = Path(clientImpl->webdav_root, true) + remote_directory;
590588
target_urn = Path(target_urn.path(), true);
591589

tests/check.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,29 @@
2020
#
2121
############################################################################*/
2222

23-
#include "stdafx.h"
2423
#include "catch.hpp"
24+
#include "fixture.hpp"
25+
26+
#include <webdav/client.hpp>
2527

2628
SCENARIO("Client must check an existing remote resources", "[check]") {
2729

30+
auto options = fixture::get_options();
31+
auto content = fixture::get_buff_content();
32+
auto dirname = fixture::get_dir_name();
33+
auto filename = fixture::get_file_name();
34+
35+
CAPTURE(dirname);
36+
CAPTURE(filename);
37+
2838
std::unique_ptr<WebDAV::Client> client(WebDAV::Client::Init(options));
2939

3040
GIVEN("An existing remote resource") {
3141

32-
std::string existing_file = "file.dat";
33-
std::string existing_directory = "dir/";
42+
std::string existing_file = filename;
43+
std::string existing_directory = dirname;
3444

35-
client->upload_from(existing_file, (char *)file_content.c_str(), file_content.length());
45+
client->upload_from(existing_file, (char *)content.c_str(), content.length());
3646
client->create_directory(existing_directory);
3747

3848
WHEN("Check for existence of an existing remote file") {
@@ -63,6 +73,8 @@ SCENARIO("Client must check an existing remote resources", "[check]") {
6373

6474
SCENARIO("Client must check not an existing remote resources", "[check]") {
6575

76+
auto options = fixture::get_options();
77+
6678
std::unique_ptr<WebDAV::Client> client(WebDAV::Client::Init(options));
6779

6880
GIVEN("Not an existing remote resource") {
@@ -94,4 +106,4 @@ SCENARIO("Client must check not an existing remote resources", "[check]") {
94106
}
95107
}
96108
}
97-
}
109+
}

tests/clean.cpp

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,29 @@
2020
#
2121
############################################################################*/
2222

23-
#include "stdafx.h"
2423
#include "catch.hpp"
24+
#include "fixture.hpp"
25+
26+
#include <webdav/client.hpp>
2527

2628
SCENARIO("Client must clean an existing remote resources", "[clean]") {
2729

30+
auto options = fixture::get_options();
31+
auto content = fixture::get_buff_content();
32+
auto dirname = fixture::get_dir_name();
33+
auto filename = fixture::get_file_name();
34+
35+
CAPTURE(dirname);
36+
CAPTURE(filename);
37+
2838
std::unique_ptr<WebDAV::Client> client(WebDAV::Client::Init(options));
2939

3040
GIVEN("An existing remote resource") {
3141

32-
std::string existing_file = "file.dat";
33-
std::string existing_directory = "existing_directory/";
42+
std::string existing_file = filename;
43+
std::string existing_directory = dirname;
3444

35-
client->upload_from(existing_file, (char *)file_content.c_str(), file_content.length());
45+
client->upload_from(existing_file, (char *)content.c_str(), content.length());
3646
client->create_directory(existing_directory);
3747

3848
WHEN("Clean an existing remote file") {
@@ -65,6 +75,8 @@ SCENARIO("Client must clean an existing remote resources", "[clean]") {
6575

6676
SCENARIO("Client must clean not an existing remote resources", "[clean]") {
6777

78+
auto options = fixture::get_options();
79+
6880
std::unique_ptr<WebDAV::Client> client(WebDAV::Client::Init(options));
6981

7082
GIVEN("Not an existing remote resource") {
@@ -102,16 +114,22 @@ SCENARIO("Client must clean not an existing remote resources", "[clean]") {
102114

103115
SCENARIO("Client must clean not an empty remote directories", "[clean]") {
104116

117+
auto options = fixture::get_options();
118+
auto content = fixture::get_buff_content();
119+
auto dirname = fixture::get_dir_name();
120+
121+
CAPTURE(dirname);
122+
105123
std::unique_ptr<WebDAV::Client> client(WebDAV::Client::Init(options));
106124

107125
GIVEN("Not an empty remote directory") {
108126

109-
std::string not_empty_directory = "not_empty_directory/";
110-
std::string attached_file = "not_empty_directory/attached_file.dat";
111-
std::string attached_directory = "not_empty_directory/attached_directory/";
127+
std::string not_empty_directory = dirname;
128+
std::string attached_file = not_empty_directory + "/" + "attached_file.dat";
129+
std::string attached_directory = not_empty_directory + "/" + "attached_directory/";
112130

113131
client->create_directory(not_empty_directory);
114-
client->upload_from(attached_file, (char *)file_content.c_str(), file_content.length());
132+
client->upload_from(attached_file, (char *)content.c_str(), content.length());
115133
client->create_directory(attached_directory);
116134

117135
WHEN("Clean not an empty directory") {
@@ -136,11 +154,16 @@ SCENARIO("Client must clean not an empty remote directories", "[clean]") {
136154

137155
SCENARIO("Client must clean a remote directory", "[clean]") {
138156

157+
auto options = fixture::get_options();
158+
auto dirname = fixture::get_dir_name();
159+
160+
CAPTURE(dirname);
161+
139162
std::unique_ptr<WebDAV::Client> client(WebDAV::Client::Init(options));
140163

141164
GIVEN("An existing directory") {
142165

143-
std::string directory_name = "directory";
166+
std::string directory_name = dirname;
144167
client->create_directory(directory_name);
145168

146169
WHEN("Clean directory by a name") {
@@ -155,4 +178,4 @@ SCENARIO("Client must clean a remote directory", "[clean]") {
155178
}
156179
}
157180
}
158-
}
181+
}

tests/config.hpp

Lines changed: 0 additions & 50 deletions
This file was deleted.

tests/download.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,25 @@
2020
#
2121
############################################################################*/
2222

23-
#include "stdafx.h"
2423
#include "catch.hpp"
24+
#include "fixture.hpp"
25+
26+
#include <webdav/client.hpp>
2527

2628
SCENARIO("Client must download into buffer", "[download][buffer]") {
2729

30+
auto options = fixture::get_options();
31+
auto content = fixture::get_buff_content();
32+
auto filename = fixture::get_file_name();
33+
34+
CAPTURE(filename);
35+
2836
std::unique_ptr<WebDAV::Client> client(WebDAV::Client::Init(options));
2937

3038
GIVEN("A buffer") {
3139

32-
std::string source_buffer = "content of the buffer";
33-
std::string remote_resource = "file.dat";
40+
std::string source_buffer = content;
41+
std::string remote_resource = filename;
3442

3543
auto buffer_pointer = const_cast<char *>(source_buffer.c_str());
3644
unsigned long long buffer_size = (source_buffer.length() + 1)* sizeof(source_buffer.c_str()[0]);
@@ -56,14 +64,20 @@ SCENARIO("Client must download into buffer", "[download][buffer]") {
5664

5765
SCENARIO("Client must download stream", "[download][stream]") {
5866

67+
auto options = fixture::get_options();
68+
auto content = fixture::get_buff_content();
69+
auto filename = fixture::get_file_name();
70+
71+
CAPTURE(filename);
72+
5973
std::unique_ptr<WebDAV::Client> client(WebDAV::Client::Init(options));
6074

6175
GIVEN("A stream") {
6276

6377
std::stringstream destination_stream;
6478

65-
std::stringstream source_stream("content of the stream");
66-
std::string remote_resource = "file.dat";
79+
std::stringstream source_stream(content);
80+
std::string remote_resource = filename;
6781

6882
auto is_success = client->upload_from(remote_resource, source_stream);
6983
REQUIRE(is_success);
@@ -86,4 +100,4 @@ SCENARIO("Client must download stream", "[download][stream]") {
86100
}
87101
}
88102
}
89-
}
103+
}

0 commit comments

Comments
 (0)