replace boost filesystem with std filesystem; upgrade gtest and find it using cmake.
This commit is contained in:
@@ -12,7 +12,8 @@ set(AT_TARGET_NAME webcc_autotest)
|
||||
set(AT_LIBS
|
||||
webcc
|
||||
jsoncpp
|
||||
gtest
|
||||
GTest::GTest
|
||||
GTest::Main
|
||||
Boost::filesystem
|
||||
Boost::system
|
||||
Boost::date_time
|
||||
|
||||
+19
-17
@@ -1,16 +1,17 @@
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "boost/algorithm/string.hpp"
|
||||
#include "boost/filesystem/fstream.hpp"
|
||||
#include "boost/filesystem/operations.hpp"
|
||||
|
||||
#include "json/json.h"
|
||||
|
||||
#include "webcc/client_session.h"
|
||||
#include "webcc/string.h"
|
||||
|
||||
namespace bfs = boost::filesystem;
|
||||
namespace sfs = std::filesystem;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@@ -195,15 +196,15 @@ TEST(ClientTest, Get_Jpeg_Stream) {
|
||||
EXPECT_TRUE(!file_body->path().empty());
|
||||
|
||||
// Backup the path of the temp file.
|
||||
const webcc::Path ori_path = file_body->path();
|
||||
const sfs::path ori_path = file_body->path();
|
||||
|
||||
const webcc::Path new_path("./wolf.jpeg");
|
||||
const sfs::path new_path("./wolf.jpeg");
|
||||
|
||||
bool moved = file_body->Move(new_path);
|
||||
EXPECT_TRUE(moved);
|
||||
EXPECT_TRUE(boost::filesystem::exists(new_path));
|
||||
EXPECT_TRUE(sfs::exists(new_path));
|
||||
// The file in the original path should not exist any more.
|
||||
EXPECT_TRUE(!boost::filesystem::exists(ori_path));
|
||||
EXPECT_TRUE(!sfs::exists(ori_path));
|
||||
|
||||
// After move, the original path should be reset.
|
||||
EXPECT_TRUE(file_body->path().empty());
|
||||
@@ -219,7 +220,7 @@ TEST(ClientTest, Get_Jpeg_Stream_NoMove) {
|
||||
webcc::ClientSession session;
|
||||
|
||||
try {
|
||||
webcc::Path ori_path;
|
||||
sfs::path ori_path;
|
||||
|
||||
{
|
||||
auto r = session.Send(webcc::RequestBuilder{}.
|
||||
@@ -237,7 +238,7 @@ TEST(ClientTest, Get_Jpeg_Stream_NoMove) {
|
||||
}
|
||||
|
||||
// The temp file should be deleted.
|
||||
EXPECT_TRUE(!boost::filesystem::exists(ori_path));
|
||||
EXPECT_TRUE(!sfs::exists(ori_path));
|
||||
|
||||
} catch (const webcc::Error& error) {
|
||||
std::cerr << error << std::endl;
|
||||
@@ -310,22 +311,23 @@ TEST(ClientTest, Post) {
|
||||
}
|
||||
}
|
||||
|
||||
static bfs::path GenerateTempFile(const std::string& data) {
|
||||
static sfs::path GenerateTempFile(const std::string& data) {
|
||||
try {
|
||||
bfs::path path = bfs::temp_directory_path() / bfs::unique_path();
|
||||
sfs::path path =
|
||||
sfs::temp_directory_path() / webcc::string::RandomString(10);
|
||||
|
||||
bfs::ofstream ofs;
|
||||
std::ofstream ofs;
|
||||
ofs.open(path, std::ios::binary);
|
||||
if (ofs.fail()) {
|
||||
return bfs::path{};
|
||||
return sfs::path{};
|
||||
}
|
||||
|
||||
ofs << data;
|
||||
|
||||
return path;
|
||||
|
||||
} catch (const bfs::filesystem_error&) {
|
||||
return bfs::path{};
|
||||
} catch (const sfs::filesystem_error&) {
|
||||
return sfs::path{};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,8 +358,8 @@ TEST(ClientTest, Post_FileBody) {
|
||||
}
|
||||
|
||||
// Remove the temp file.
|
||||
boost::system::error_code ec;
|
||||
bfs::remove(path, ec);
|
||||
std::error_code ec;
|
||||
sfs::remove(path, ec);
|
||||
}
|
||||
|
||||
#if WEBCC_ENABLE_GZIP
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include <filesystem>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "webcc/logger.h"
|
||||
|
||||
Reference in New Issue
Block a user