mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Cleanup the code. Change inputs on ImplementationPlatform::GetDownloadPath from std::string& to absl::string_view.
PiperOrigin-RevId: 472770249
This commit is contained in:
committed by
Copybara-Service
parent
92bf3356ee
commit
55c4714b99
@@ -316,12 +316,14 @@ std::unique_ptr<InternalPayload> CreateOutgoingInternalPayload(
|
||||
}
|
||||
|
||||
std::string make_path(std::string& parent_folder, std::string& file_name) {
|
||||
return api::ImplementationPlatform::GetDownloadPath(parent_folder, file_name);
|
||||
return std::string(
|
||||
api::ImplementationPlatform::GetDownloadPath(parent_folder, file_name));
|
||||
}
|
||||
|
||||
std::string make_path(std::string& parent_folder, int64_t id) {
|
||||
std::string file_name(std::to_string(id));
|
||||
return api::ImplementationPlatform::GetDownloadPath(parent_folder, file_name);
|
||||
return std::string(
|
||||
api::ImplementationPlatform::GetDownloadPath(parent_folder, file_name));
|
||||
}
|
||||
|
||||
std::unique_ptr<InternalPayload> CreateIncomingInternalPayload(
|
||||
|
||||
@@ -106,7 +106,7 @@ ByteArray GenerateRandomAdvertisementHash() {
|
||||
class BlePeripheralStub : public api::ble_v2::BlePeripheral {
|
||||
public:
|
||||
explicit BlePeripheralStub(absl::string_view mac_address) {
|
||||
mac_address_ = mac_address;
|
||||
mac_address_ = std::string(mac_address);
|
||||
}
|
||||
|
||||
std::string GetAddress() const override { return mac_address_; }
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "file/base/path.h"
|
||||
#include "absl/memory/memory.h"
|
||||
@@ -60,8 +61,8 @@ namespace location {
|
||||
namespace nearby {
|
||||
namespace api {
|
||||
|
||||
std::string ImplementationPlatform::GetDownloadPath(std::string& parent_folder,
|
||||
std::string& file_name) {
|
||||
std::string ImplementationPlatform::GetDownloadPath(
|
||||
absl::string_view parent_folder, absl::string_view file_name) {
|
||||
std::string fullPath("/tmp");
|
||||
|
||||
return file::JoinPath("/tmp", file_name);
|
||||
|
||||
@@ -36,8 +36,8 @@ namespace location {
|
||||
namespace nearby {
|
||||
namespace api {
|
||||
|
||||
std::string ImplementationPlatform::GetDownloadPath(std::string& parent_folder,
|
||||
std::string& file_name) {
|
||||
std::string ImplementationPlatform::GetDownloadPath(absl::string_view parent_folder,
|
||||
absl::string_view file_name) {
|
||||
// TODO(jfcarroll): This needs to be done correctly, we now have a file name and parent folder,
|
||||
// they should be combined with the default download path
|
||||
NSString* fileName = ObjCStringFromCppString(file_name);
|
||||
|
||||
@@ -65,10 +65,10 @@ class ImplementationPlatform {
|
||||
// - CountDownLatch : to ensure at least N threads are waiting.
|
||||
// - file I/O
|
||||
// - Logging
|
||||
static std::string GetDownloadPath(std::string& parent_folder,
|
||||
std::string& file_name);
|
||||
static std::string GetDownloadPath(absl::string_view parent_folder,
|
||||
absl::string_view file_name);
|
||||
|
||||
static std::string GetDownloadPath(std::string& file_name);
|
||||
static std::string GetDownloadPath(absl::string_view file_name);
|
||||
|
||||
static std::string GetAppDataPath(absl::string_view file_name);
|
||||
|
||||
|
||||
@@ -58,8 +58,8 @@ namespace api {
|
||||
namespace {
|
||||
constexpr absl::string_view kUpOneLevel("/..");
|
||||
|
||||
std::string GetDownloadPathInternal(std::string& parent_folder,
|
||||
std::string& file_name) {
|
||||
std::string GetDownloadPathInternal(absl::string_view parent_folder,
|
||||
absl::string_view file_name) {
|
||||
PWSTR basePath;
|
||||
|
||||
// Retrieves the full path of a known folder identified by the folder's
|
||||
@@ -81,54 +81,54 @@ std::string GetDownloadPathInternal(std::string& parent_folder,
|
||||
std::string fullpathUTF8(bufferSize - 1, '\0');
|
||||
wcstombs_s(&bufferSize, fullpathUTF8.data(), bufferSize, basePath, _TRUNCATE);
|
||||
|
||||
std::string parent_folder_path(parent_folder);
|
||||
|
||||
std::replace(fullpathUTF8.begin(), fullpathUTF8.end(), '\\', '/');
|
||||
|
||||
// If parent_folder starts with a \\ or /, then strip it
|
||||
while (!parent_folder.empty() &&
|
||||
(*parent_folder.begin() == '\\' || *parent_folder.begin() == '/')) {
|
||||
parent_folder.erase(0, 1);
|
||||
while (!parent_folder_path.empty() && (*parent_folder_path.begin() == '\\' ||
|
||||
*parent_folder_path.begin() == '/')) {
|
||||
parent_folder_path.erase(0, 1);
|
||||
}
|
||||
|
||||
// If parent_folder ends with a \\ or /, then strip it
|
||||
while (!parent_folder.empty() &&
|
||||
(*parent_folder.rbegin() == '\\' || *parent_folder.rbegin() == '/')) {
|
||||
parent_folder.erase(parent_folder.size() - 1, 1);
|
||||
while (!parent_folder_path.empty() && (*parent_folder_path.rbegin() == '\\' ||
|
||||
*parent_folder_path.rbegin() == '/')) {
|
||||
parent_folder_path.erase(parent_folder_path.size() - 1, 1);
|
||||
}
|
||||
|
||||
std::string file_name_path(file_name);
|
||||
|
||||
// If file_name starts with a \\, then strip it
|
||||
while (!file_name.empty() &&
|
||||
(*file_name.begin() == '\\' || *file_name.begin() == '/')) {
|
||||
file_name.erase(0, 1);
|
||||
while (!file_name_path.empty() &&
|
||||
(*file_name_path.begin() == '\\' || *file_name_path.begin() == '/')) {
|
||||
file_name_path.erase(0, 1);
|
||||
}
|
||||
|
||||
// If file_name ends with a \\, then strip it
|
||||
while (!file_name.empty() &&
|
||||
(*file_name.rbegin() == '\\' || *file_name.rbegin() == '/')) {
|
||||
file_name.erase(file_name.size() - 1, 1);
|
||||
while (!file_name_path.empty() && (*file_name_path.rbegin() == '\\' ||
|
||||
*file_name_path.rbegin() == '/')) {
|
||||
file_name_path.erase(file_name_path.size() - 1, 1);
|
||||
}
|
||||
|
||||
CoTaskMemFree(basePath);
|
||||
|
||||
std::stringstream path("");
|
||||
std::string path("");
|
||||
|
||||
if (parent_folder.empty() && file_name.empty()) {
|
||||
if (parent_folder_path.empty() && file_name_path.empty()) {
|
||||
return fullpathUTF8;
|
||||
}
|
||||
if (parent_folder.empty()) {
|
||||
path << fullpathUTF8.c_str() << "/" << file_name.c_str();
|
||||
std::string retVal = path.str();
|
||||
return retVal;
|
||||
if (parent_folder_path.empty()) {
|
||||
path += fullpathUTF8 + "/" + file_name_path;
|
||||
return path;
|
||||
}
|
||||
if (file_name.empty()) {
|
||||
path << fullpathUTF8.c_str() << "/" << parent_folder.c_str();
|
||||
std::string retVal = path.str();
|
||||
return retVal;
|
||||
if (file_name_path.empty()) {
|
||||
path += fullpathUTF8 + "/" + parent_folder_path;
|
||||
return path;
|
||||
}
|
||||
|
||||
path << fullpathUTF8.c_str() << "/" << parent_folder.c_str() << "/"
|
||||
<< file_name.c_str();
|
||||
std::string retVal = path.str();
|
||||
return retVal;
|
||||
path += fullpathUTF8 + "/" + parent_folder_path + "/" + file_name_path;
|
||||
return path;
|
||||
}
|
||||
|
||||
void SanitizePath(std::string& path) {
|
||||
@@ -228,13 +228,14 @@ bool FolderExists(const std::string& folder_name) {
|
||||
|
||||
} // namespace
|
||||
|
||||
std::string ImplementationPlatform::GetDownloadPath(std::string& parent_folder,
|
||||
std::string& file_name) {
|
||||
std::string ImplementationPlatform::GetDownloadPath(
|
||||
absl::string_view parent_folder, absl::string_view file_name) {
|
||||
return CreateOutputFileWithRename(
|
||||
GetDownloadPathInternal(parent_folder, file_name));
|
||||
}
|
||||
|
||||
std::string ImplementationPlatform::GetDownloadPath(std::string& file_name) {
|
||||
std::string ImplementationPlatform::GetDownloadPath(
|
||||
absl::string_view file_name) {
|
||||
std::string fake_parent_path;
|
||||
return GetDownloadPathInternal(fake_parent_path, file_name);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace location::nearby::windows {
|
||||
|
||||
namespace {
|
||||
constexpr absl::string_view kFileName("/increment_file_test.txt");
|
||||
constexpr absl::string_view kFirstIterationFileName(
|
||||
@@ -47,12 +49,14 @@ constexpr absl::string_view kLongEscapeEndingEscapeWithSlash(
|
||||
"../test/../../test/../../../");
|
||||
} // namespace
|
||||
|
||||
using ::location::nearby::api::ImplementationPlatform;
|
||||
|
||||
// Can't run on google 3, I presume the SHGetKnownFolderPath
|
||||
// fails.
|
||||
class ImplementationPlatformTests : public testing::Test {
|
||||
protected:
|
||||
// You can define per-test set-up logic as usual.
|
||||
void SetUp() override {
|
||||
ImplementationPlatformTests() {
|
||||
PWSTR basePath;
|
||||
|
||||
SHGetKnownFolderPath(
|
||||
@@ -85,171 +89,138 @@ class ImplementationPlatformTests : public testing::Test {
|
||||
std::string default_download_path_;
|
||||
};
|
||||
|
||||
TEST_F(ImplementationPlatformTests, DISABLED_GetDownloadPathWithEmptyString\
|
||||
ArgumentsShouldReturnBaseDownloadPath) {
|
||||
// Arrange
|
||||
TEST_F(ImplementationPlatformTests,
|
||||
DISABLED_GetDownloadPathWithEmptyStringArguments\
|
||||
ShouldReturnBaseDownloadPath) {
|
||||
std::string parent_folder("");
|
||||
std::string file_name("");
|
||||
|
||||
// Act
|
||||
auto result = location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
auto result =
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(result, default_download_path_);
|
||||
}
|
||||
} // NOLINT false lint error here
|
||||
|
||||
TEST_F(ImplementationPlatformTests, DISABLED_GetDownloadPathWithSlashParent\
|
||||
FolderArgumentsShouldReturnBaseDownloadPath) {
|
||||
// Arrange
|
||||
std::string parent_folder("/");
|
||||
std::string file_name("");
|
||||
|
||||
// Act
|
||||
auto result = location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
auto result =
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(result, default_download_path_);
|
||||
}
|
||||
|
||||
TEST_F(ImplementationPlatformTests, DISABLED_GetDownloadPathWithBackslashParent\
|
||||
FolderArgumentsShouldReturnBaseDownloadPath) {
|
||||
// Arrange
|
||||
std::string parent_folder("\\");
|
||||
std::string file_name("");
|
||||
|
||||
// Act
|
||||
auto result = location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
auto result =
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(result, default_download_path_);
|
||||
}
|
||||
|
||||
TEST_F(ImplementationPlatformTests, DISABLED_GetDownloadPathWithAttemptToEscape\
|
||||
UsersDownloadFolderShouldReturnDownloadPathNotEscapingUsersDownloadFolder) {
|
||||
// Arrange
|
||||
std::string parent_folder(kImmediateEscape);
|
||||
std::string file_name("");
|
||||
|
||||
// Act
|
||||
auto result = location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
auto result =
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(result, default_download_path_);
|
||||
}
|
||||
|
||||
TEST_F(ImplementationPlatformTests, DISABLED_GetDownloadPathWithMultiple\
|
||||
AttemptsToEscapeUsersDownloadFolderWithBackslashShouldReturnDownloadPath\
|
||||
NotEscapingUsersDownloadFolder) {
|
||||
// Arrange
|
||||
std::string parent_folder(kLongEscapeBackSlash);
|
||||
std::string file_name("");
|
||||
|
||||
// Act
|
||||
auto result = location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
auto result =
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(result, default_download_path_ + kTwoLevelFolder.data());
|
||||
}
|
||||
|
||||
TEST_F(ImplementationPlatformTests, DISABLED_GetDownloadPathWithMultiple\
|
||||
AttemptsToEscapeUsersDownloadFolderShouldReturnDownloadPathNotEscapingUsers\
|
||||
DownloadFolder) {
|
||||
// Arrange
|
||||
std::string parent_folder(kLongEscapeSlash);
|
||||
std::string file_name("");
|
||||
|
||||
// Act
|
||||
auto result = location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
auto result =
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(result, default_download_path_ + kTwoLevelFolder.data());
|
||||
}
|
||||
|
||||
TEST_F(ImplementationPlatformTests, DISABLED_GetDownloadPathWithMultiple\
|
||||
AttemptsToEscapeUsersDownloadFolderWithMixedSlashShouldReturnDownloadPath\
|
||||
NotEscapingUsersDownloadFolder) {
|
||||
// Arrange
|
||||
std::string parent_folder(kLongEscapeMixedSlash);
|
||||
std::string file_name("");
|
||||
|
||||
// Act
|
||||
auto result = location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
auto result =
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(result, default_download_path_ + kTwoLevelFolder.data());
|
||||
}
|
||||
|
||||
TEST_F(ImplementationPlatformTests, DISABLED_GetDownloadPathWithMultiple\
|
||||
AttemptsToEscapeUsersDownloadFolderWithEndingEscapeShouldReturnDownload\
|
||||
PathNotEscapingUsersDownloadFolder) {
|
||||
// Arrange
|
||||
std::string parent_folder(kLongEscapeEndingEscape);
|
||||
std::string file_name("");
|
||||
|
||||
// Act
|
||||
auto result = location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
auto result =
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(result, default_download_path_ + kTwoLevelFolder.data());
|
||||
}
|
||||
|
||||
TEST_F(ImplementationPlatformTests, DISABLED_GetDownloadPathWithMultiple\
|
||||
AttemptsToEscapeUsersDownloadFolderWithEndingSlashShouldReturnDownloadPathNot\
|
||||
EscapingUsersDownloadFolder) {
|
||||
// Arrange
|
||||
std::string parent_folder(kLongEscapeEndingEscapeWithSlash);
|
||||
std::string file_name("");
|
||||
|
||||
// Act
|
||||
auto result = location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
auto result =
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(result, default_download_path_ + kTwoLevelFolder.data());
|
||||
}
|
||||
|
||||
TEST_F(ImplementationPlatformTests, DISABLED_GetDownloadPathWithSlashFileName\
|
||||
ArgumentsShouldReturnBaseDownloadPath) {
|
||||
// Arrange
|
||||
std::string parent_folder("");
|
||||
std::string file_name("/");
|
||||
|
||||
// Act
|
||||
auto result = location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
auto result =
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(result, default_download_path_);
|
||||
}
|
||||
|
||||
TEST_F(ImplementationPlatformTests, DISABLED_GetDownloadPathWithBackslashFile\
|
||||
NameArgumentsShouldReturnBaseDownloadPath) {
|
||||
// Arrange
|
||||
std::string parent_folder("");
|
||||
std::string file_name("\\");
|
||||
|
||||
// Act
|
||||
auto result = location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
auto result =
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name);
|
||||
|
||||
auto result_size = result.size();
|
||||
auto default_size = default_download_path_.size();
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(result, default_download_path_);
|
||||
}
|
||||
|
||||
TEST_F(ImplementationPlatformTests, DISABLED_GetDownloadPathWithParentFolder\
|
||||
ShouldReturnParentFolderAppendedToBaseDownloadPath) {
|
||||
// Arrange
|
||||
std::string parent_folder("test_parent_folder");
|
||||
std::string file_name("");
|
||||
|
||||
@@ -259,17 +230,14 @@ ShouldReturnParentFolderAppendedToBaseDownloadPath) {
|
||||
|
||||
std::string expected = path.str();
|
||||
|
||||
// Act
|
||||
auto result = location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
auto result =
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(result, expected);
|
||||
}
|
||||
|
||||
TEST_F(ImplementationPlatformTests, DISABLED_GetDownloadPathWithParentFolder\
|
||||
StartingWithSlashArgumentsShouldReturnParentFolderAppendedToBaseDownloadPath) {
|
||||
// Arrange
|
||||
std::string parent_folder("/test_parent_folder");
|
||||
std::string file_name("");
|
||||
|
||||
@@ -279,18 +247,15 @@ StartingWithSlashArgumentsShouldReturnParentFolderAppendedToBaseDownloadPath) {
|
||||
|
||||
std::string expected = path.str();
|
||||
|
||||
// Act
|
||||
auto result = location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
auto result =
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(result, expected);
|
||||
}
|
||||
|
||||
TEST_F(ImplementationPlatformTests, DISABLED_GetDownloadPathWithParentFolder\
|
||||
StartingWithBackslashArgumentsShouldReturnParentFolderAppendedToBase\
|
||||
DownloadPath) {
|
||||
// Arrange
|
||||
std::string parent_folder("\\test_parent_folder");
|
||||
std::string file_name("");
|
||||
|
||||
@@ -300,17 +265,14 @@ DownloadPath) {
|
||||
|
||||
std::string expected = path.str();
|
||||
|
||||
// Act
|
||||
auto result = location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
auto result =
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(result, expected);
|
||||
}
|
||||
|
||||
TEST_F(ImplementationPlatformTests, DISABLED_GetDownloadPathWithParentFolder\
|
||||
EndingWithSlashArgumentsShouldReturnParentFolderAppendedToBaseDownloadPath) {
|
||||
// Arrange
|
||||
std::string parent_folder("test_parent_folder/");
|
||||
std::string file_name("");
|
||||
|
||||
@@ -320,18 +282,15 @@ EndingWithSlashArgumentsShouldReturnParentFolderAppendedToBaseDownloadPath) {
|
||||
|
||||
std::string expected = path.str();
|
||||
|
||||
// Act
|
||||
auto result = location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
auto result =
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(result, expected);
|
||||
}
|
||||
|
||||
TEST_F(ImplementationPlatformTests, DISABLED_GetDownloadPathWithParentFolder\
|
||||
EndingWithBackslashArgumentsShouldReturnParentFolderAppendedToBaseDownloadPath)
|
||||
{
|
||||
// Arrange
|
||||
EndingWithBackslashArguments\
|
||||
ShouldReturnParentFolderAppendedToBaseDownloadPath) {
|
||||
std::string parent_folder("test_parent_folder\\");
|
||||
std::string file_name("");
|
||||
|
||||
@@ -341,17 +300,14 @@ EndingWithBackslashArgumentsShouldReturnParentFolderAppendedToBaseDownloadPath)
|
||||
|
||||
std::string expected = path.str();
|
||||
|
||||
// Act
|
||||
auto result = location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
auto result =
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(result, expected);
|
||||
}
|
||||
|
||||
TEST_F(ImplementationPlatformTests, DISABLED_GetDownloadPathWithFileName\
|
||||
BeginningWithSlashArgumentsShouldReturnFileNameAppendedToBaseDownloadPath) {
|
||||
// Arrange
|
||||
std::string parent_folder("");
|
||||
std::string file_name("/test_file_name.name");
|
||||
|
||||
@@ -361,17 +317,14 @@ BeginningWithSlashArgumentsShouldReturnFileNameAppendedToBaseDownloadPath) {
|
||||
|
||||
std::string expected = path.str();
|
||||
|
||||
// Act
|
||||
auto result = location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
auto result =
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(result, expected);
|
||||
}
|
||||
|
||||
TEST_F(ImplementationPlatformTests, DISABLED_GetDownloadPathWithFileName\
|
||||
BeginningWithBackslashArgumentsShouldReturnFileNameAppendedToBaseDownloadPath) {
|
||||
// Arrange
|
||||
std::string parent_folder("");
|
||||
std::string file_name("\\test_file_name.name");
|
||||
|
||||
@@ -379,17 +332,14 @@ BeginningWithBackslashArgumentsShouldReturnFileNameAppendedToBaseDownloadPath) {
|
||||
path << default_download_path_ << "/"
|
||||
<< "test_file_name.name";
|
||||
|
||||
// Act
|
||||
auto result = location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
auto result =
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(result, path.str().c_str());
|
||||
}
|
||||
|
||||
TEST_F(ImplementationPlatformTests, DISABLED_GetDownloadPathWithFileNameEnding\
|
||||
WithSlashArgumentsShouldReturnFileNameAppendedToBaseDownloadPath) {
|
||||
// Arrange
|
||||
std::string parent_folder("");
|
||||
std::string file_name("test_file_name.name/");
|
||||
|
||||
@@ -399,17 +349,14 @@ WithSlashArgumentsShouldReturnFileNameAppendedToBaseDownloadPath) {
|
||||
|
||||
std::string expected = path.str();
|
||||
|
||||
// Act
|
||||
auto result = location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
auto result =
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(result, expected);
|
||||
}
|
||||
|
||||
TEST_F(ImplementationPlatformTests, DISABLED_GetDownloadPathWithFileNameEnding\
|
||||
WithBackslashArgumentsShouldReturnFileNameAppendedToBaseDownloadPath) {
|
||||
// Arrange
|
||||
std::string parent_folder("");
|
||||
std::string file_name("test_file_name.name\\");
|
||||
|
||||
@@ -419,18 +366,15 @@ WithBackslashArgumentsShouldReturnFileNameAppendedToBaseDownloadPath) {
|
||||
|
||||
std::string expected = path.str();
|
||||
|
||||
// Act
|
||||
auto result = location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
auto result =
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(result, expected);
|
||||
}
|
||||
|
||||
TEST_F(ImplementationPlatformTests, DISABLED_GetDownloadPathWithParentFolderAnd\
|
||||
FileNameArgumentsShouldReturnParentFolderAndFileNameAppendedToBaseDownloadPath)
|
||||
{
|
||||
// Arrange
|
||||
FileNameArgumentsShould\
|
||||
ReturnParentFolderAndFileNameAppendedToBaseDownloadPath) {
|
||||
std::string parent_folder("test_parent_folder");
|
||||
std::string file_name("test_file_name.name");
|
||||
|
||||
@@ -442,18 +386,15 @@ FileNameArgumentsShouldReturnParentFolderAndFileNameAppendedToBaseDownloadPath)
|
||||
|
||||
std::string expected = path.str();
|
||||
|
||||
// Act
|
||||
auto result = location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
auto result =
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(result, expected);
|
||||
}
|
||||
|
||||
TEST_F(ImplementationPlatformTests, DISABLED_GetDownloadPathWithParentFolder\
|
||||
EndingWithBackslashAndFileNameArgumentsShouldReturnParentFolderAndFileName\
|
||||
AppendedToBaseDownloadPath) {
|
||||
// Arrange
|
||||
std::string parent_folder("test_parent_folder\\");
|
||||
std::string file_name("test_file_name.name");
|
||||
|
||||
@@ -465,18 +406,15 @@ AppendedToBaseDownloadPath) {
|
||||
|
||||
std::string expected = path.str();
|
||||
|
||||
// Act
|
||||
auto result = location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
auto result =
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(result, expected);
|
||||
}
|
||||
|
||||
TEST_F(ImplementationPlatformTests, DISABLED_GetDownloadPathWithFileName\
|
||||
StartingWithBackslashAndParentFolderArgumentsShouldReturnParentFolderAnd\
|
||||
FileNameAppendedToBaseDownloadPath) {
|
||||
// Arrange
|
||||
std::string parent_folder("test_parent_folder");
|
||||
std::string file_name("\\test_file_name.name");
|
||||
|
||||
@@ -488,35 +426,28 @@ FileNameAppendedToBaseDownloadPath) {
|
||||
|
||||
std::string expected = path.str();
|
||||
|
||||
// Act
|
||||
auto result = location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
auto result =
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(result, expected);
|
||||
}
|
||||
|
||||
TEST_F(ImplementationPlatformTests, DISABLED_GetDownloadPath_FileDoesntExist\
|
||||
ReturnsFileWithPassedName) {
|
||||
// Arrange
|
||||
std::string file_name(kFileName);
|
||||
std::string parent_folder("");
|
||||
|
||||
std::string expected(default_download_path_);
|
||||
expected.append(file_name.c_str());
|
||||
|
||||
// Act
|
||||
std::string actual =
|
||||
location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
std::string actual(
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name));
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(actual, expected);
|
||||
}
|
||||
|
||||
TEST_F(ImplementationPlatformTests, DISABLED_GetDownloadPath_FileExistsReturns\
|
||||
FileWithIncrementedName) {
|
||||
// Arrange
|
||||
std::string file_name(kFileName);
|
||||
std::string renamed_file_name(kFirstIterationFileName);
|
||||
std::string parent_folder("");
|
||||
@@ -537,12 +468,9 @@ FileWithIncrementedName) {
|
||||
|
||||
output_file.close();
|
||||
|
||||
// Act
|
||||
std::string actual =
|
||||
location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
std::string actual(
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name));
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(actual, expected);
|
||||
|
||||
// Remove the file and check that it is removed
|
||||
@@ -556,7 +484,6 @@ FileWithIncrementedName) {
|
||||
|
||||
TEST_F(ImplementationPlatformTests, DISABLED_GetDownloadPath_MultipleFilesExist\
|
||||
ReturnsNextIncrementedFileName) {
|
||||
// Arrange
|
||||
std::ofstream output_file;
|
||||
std::ifstream input_file;
|
||||
|
||||
@@ -587,12 +514,9 @@ ReturnsNextIncrementedFileName) {
|
||||
ASSERT_TRUE(output_file.rdstate() == std::ofstream::goodbit);
|
||||
output_file.close();
|
||||
|
||||
// Act
|
||||
std::string actual =
|
||||
location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
std::string actual(
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name));
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(expected, actual);
|
||||
|
||||
// Remove the test files and check that it is removed
|
||||
@@ -613,7 +537,6 @@ ReturnsNextIncrementedFileName) {
|
||||
|
||||
TEST_F(ImplementationPlatformTests, DISABLED_GetDownloadPath_FileNameContains\
|
||||
MultipleDotsReturnsIncrementBeforeFirstDot) {
|
||||
// Arrange
|
||||
std::ifstream input_file;
|
||||
std::ofstream output_file;
|
||||
|
||||
@@ -636,12 +559,9 @@ MultipleDotsReturnsIncrementBeforeFirstDot) {
|
||||
ASSERT_TRUE(output_file.rdstate() == std::ofstream::goodbit);
|
||||
output_file.close();
|
||||
|
||||
// Act
|
||||
std::string actual =
|
||||
location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
std::string actual(
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name));
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(expected, actual);
|
||||
|
||||
std::remove(output_file1_path.c_str());
|
||||
@@ -674,12 +594,9 @@ DotsReturnsWithIncrementAtEnd) {
|
||||
ASSERT_TRUE(output_file.rdstate() == std::ofstream::goodbit);
|
||||
output_file.close();
|
||||
|
||||
// Act
|
||||
std::string actual =
|
||||
location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
std::string actual(
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name));
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(expected, actual);
|
||||
|
||||
std::remove(output_file1_path.c_str());
|
||||
@@ -743,13 +660,10 @@ AHoleBetweenRenamedFiles) {
|
||||
ASSERT_TRUE(output_file.rdstate() == std::ofstream::goodbit);
|
||||
output_file.close();
|
||||
|
||||
// Act
|
||||
// This should return the second iteration of the original file
|
||||
std::string actual =
|
||||
location::nearby::api::ImplementationPlatform::GetDownloadPath(
|
||||
parent_folder, file_name);
|
||||
std::string actual(
|
||||
ImplementationPlatform::GetDownloadPath(parent_folder, file_name));
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(expected, actual);
|
||||
|
||||
// Delete the original file
|
||||
@@ -769,3 +683,4 @@ AHoleBetweenRenamedFiles) {
|
||||
input_file.open(output_file3_path, std::ifstream::binary | std::ifstream::in);
|
||||
ASSERT_FALSE(input_file.rdstate() == std::ifstream::goodbit);
|
||||
}
|
||||
} // namespace location::nearby::windows
|
||||
|
||||
@@ -63,7 +63,8 @@ std::string GetPayloadPath(location::nearby::PayloadId payload_id) {
|
||||
std::stringstream path("");
|
||||
|
||||
path << fullPath << "\\" << std::to_string(payload_id);
|
||||
auto retval = path.str();
|
||||
return retval;
|
||||
|
||||
return path.str();
|
||||
}
|
||||
|
||||
} // namespace test_utils
|
||||
|
||||
Reference in New Issue
Block a user