|
|
|
@@ -15,13 +15,14 @@
|
|
|
|
|
#include "internal/platform/implementation/linux/file_path.h"
|
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <filesystem>
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include <internal/platform/implementation/linux/device_info.h>
|
|
|
|
|
#include <internal/platform/implementation/linux/utils.h>
|
|
|
|
|
#include "internal/platform/implementation/linux/device_info.h"
|
|
|
|
|
#include "internal/platform/implementation/linux/utils.h"
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
|
|
namespace nearby {
|
|
|
|
@@ -55,14 +56,13 @@ class FilePathTests : public testing::Test {
|
|
|
|
|
// You can define per-test set-up logic as usual.
|
|
|
|
|
FilePathTests() {
|
|
|
|
|
default_download_path_ =
|
|
|
|
|
string_to_wstring(DeviceInfo().GetDownloadPath().value_or(
|
|
|
|
|
std::string(getenv("HOME")).append("/Downloads")));
|
|
|
|
|
string_to_wstring(std::string(getenv("HOME")).append("/Downloads"));
|
|
|
|
|
}
|
|
|
|
|
std::wstring default_download_path_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPathWithEmptyStringArguments\
|
|
|
|
|
ShouldReturnBaseDownloadPath) {
|
|
|
|
|
TEST_F(FilePathTests,
|
|
|
|
|
GetDownloadPathWithEmptyStringArgumentsShouldReturnBaseDownloadPath) {
|
|
|
|
|
std::wstring parent_folder(L"");
|
|
|
|
|
std::wstring file_name(L"");
|
|
|
|
|
|
|
|
|
@@ -71,8 +71,9 @@ ShouldReturnBaseDownloadPath) {
|
|
|
|
|
EXPECT_EQ(actual, default_download_path_);
|
|
|
|
|
} // NOLINT false lint error here
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPathWithSlashParent\
|
|
|
|
|
FolderArgumentsShouldReturnBaseDownloadPath) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPathWithSlashParentFolderArgumentsShouldReturnBaseDownloadPath) {
|
|
|
|
|
std::wstring parent_folder(L"/");
|
|
|
|
|
std::wstring file_name(L"");
|
|
|
|
|
|
|
|
|
@@ -81,8 +82,9 @@ FolderArgumentsShouldReturnBaseDownloadPath) {
|
|
|
|
|
EXPECT_EQ(actual, default_download_path_);
|
|
|
|
|
} // NOLINT false lint error here
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPathWithBackslashParent\
|
|
|
|
|
FolderArgumentsShouldReturnBaseDownloadPath) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPathWithBackslashParentFolderArgumentsShouldReturnBaseDownloadPath) {
|
|
|
|
|
std::wstring parent_folder(L"\\");
|
|
|
|
|
std::wstring file_name(L"");
|
|
|
|
|
|
|
|
|
@@ -91,8 +93,9 @@ FolderArgumentsShouldReturnBaseDownloadPath) {
|
|
|
|
|
EXPECT_EQ(actual, default_download_path_);
|
|
|
|
|
} // NOLINT false lint error here
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPathWithAttemptToEscape\
|
|
|
|
|
UsersDownloadFolderShouldReturnDownloadPathNotEscapingUsersDownloadFolder) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPathWithAttemptToEscapeUsersDownloadFolderShouldReturnDownloadPathNotEscapingUsersDownloadFolder) {
|
|
|
|
|
std::wstring parent_folder(kImmediateEscape);
|
|
|
|
|
std::wstring file_name(L"");
|
|
|
|
|
|
|
|
|
@@ -101,9 +104,9 @@ UsersDownloadFolderShouldReturnDownloadPathNotEscapingUsersDownloadFolder) {
|
|
|
|
|
EXPECT_EQ(actual, default_download_path_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPathWithMultiple\
|
|
|
|
|
AttemptsToEscapeUsersDownloadFolderWithBackslashShouldReturnDownloadPath\
|
|
|
|
|
NotEscapingUsersDownloadFolder) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPathWithMultipleAttemptsToEscapeUsersDownloadFolderWithBackslashShouldReturnDownloadPathNotEscapingUsersDownloadFolder) {
|
|
|
|
|
std::wstring parent_folder(kLongEscapeBackSlash);
|
|
|
|
|
std::wstring file_name(L"");
|
|
|
|
|
|
|
|
|
@@ -112,9 +115,9 @@ NotEscapingUsersDownloadFolder) {
|
|
|
|
|
EXPECT_EQ(actual, default_download_path_ + kTwoLevelFolder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPathWithMultiple\
|
|
|
|
|
AttemptsToEscapeUsersDownloadFolderShouldReturnDownloadPathNotEscapingUsers\
|
|
|
|
|
DownloadFolder) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPathWithMultipleAttemptsToEscapeUsersDownloadFolderShouldReturnDownloadPathNotEscapingUsersDownloadFolder) {
|
|
|
|
|
std::wstring parent_folder(kLongEscapeSlash);
|
|
|
|
|
std::wstring file_name(L"");
|
|
|
|
|
|
|
|
|
@@ -123,9 +126,9 @@ DownloadFolder) {
|
|
|
|
|
EXPECT_EQ(actual, default_download_path_ + kTwoLevelFolder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPathWithMultiple\
|
|
|
|
|
AttemptsToEscapeUsersDownloadFolderWithMixedSlashShouldReturnDownloadPath\
|
|
|
|
|
NotEscapingUsersDownloadFolder) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPathWithMultipleAttemptsToEscapeUsersDownloadFolderWithMixedSlashShouldReturnDownloadPathNotEscapingUsersDownloadFolder) {
|
|
|
|
|
std::wstring parent_folder(kLongEscapeMixedSlash);
|
|
|
|
|
std::wstring file_name(L"");
|
|
|
|
|
|
|
|
|
@@ -134,9 +137,9 @@ NotEscapingUsersDownloadFolder) {
|
|
|
|
|
EXPECT_EQ(actual, default_download_path_ + kTwoLevelFolder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPathWithMultiple\
|
|
|
|
|
AttemptsToEscapeUsersDownloadFolderWithEndingEscapeShouldReturnDownload\
|
|
|
|
|
PathNotEscapingUsersDownloadFolder) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPathWithMultipleAttemptsToEscapeUsersDownloadFolderWithEndingEscapeShouldReturnDownloadPathNotEscapingUsersDownloadFolder) {
|
|
|
|
|
std::wstring parent_folder(kLongEscapeEndingEscape);
|
|
|
|
|
std::wstring file_name(L"");
|
|
|
|
|
|
|
|
|
@@ -145,9 +148,9 @@ PathNotEscapingUsersDownloadFolder) {
|
|
|
|
|
EXPECT_EQ(actual, default_download_path_ + kTwoLevelFolder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPathWithMultiple\
|
|
|
|
|
AttemptsToEscapeUsersDownloadFolderWithEndingSlashShouldReturnDownloadPathNot\
|
|
|
|
|
EscapingUsersDownloadFolder) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPathWithMultipleAttemptsToEscapeUsersDownloadFolderWithEndingSlashShouldReturnDownloadPathNotEscapingUsersDownloadFolder) {
|
|
|
|
|
std::wstring parent_folder(kLongEscapeEndingEscapeWithSlash);
|
|
|
|
|
std::wstring file_name(L"");
|
|
|
|
|
|
|
|
|
@@ -156,8 +159,8 @@ EscapingUsersDownloadFolder) {
|
|
|
|
|
EXPECT_EQ(actual, default_download_path_ + kTwoLevelFolder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPathWithSlashFileName\
|
|
|
|
|
ArgumentsShouldReturnBaseDownloadPath) {
|
|
|
|
|
TEST_F(FilePathTests,
|
|
|
|
|
GetDownloadPathWithSlashFileNameArgumentsShouldReturnBaseDownloadPath) {
|
|
|
|
|
std::wstring parent_folder(L"");
|
|
|
|
|
std::wstring file_name(L"/");
|
|
|
|
|
|
|
|
|
@@ -166,8 +169,9 @@ ArgumentsShouldReturnBaseDownloadPath) {
|
|
|
|
|
EXPECT_EQ(actual, default_download_path_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPathWithBackslashFile\
|
|
|
|
|
NameArgumentsShouldReturnBaseDownloadPath) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPathWithBackslashFileNameArgumentsShouldReturnBaseDownloadPath) {
|
|
|
|
|
std::wstring parent_folder(L"");
|
|
|
|
|
std::wstring file_name(L"\\");
|
|
|
|
|
|
|
|
|
@@ -179,8 +183,9 @@ NameArgumentsShouldReturnBaseDownloadPath) {
|
|
|
|
|
EXPECT_EQ(actual, default_download_path_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPathWithParentFolder\
|
|
|
|
|
ShouldReturnParentFolderAppendedToBaseDownloadPath) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPathWithParentFolderShouldReturnParentFolderAppendedToBaseDownloadPath) {
|
|
|
|
|
std::wstring parent_folder(L"test_parent_folder");
|
|
|
|
|
std::wstring file_name(L"");
|
|
|
|
|
|
|
|
|
@@ -194,8 +199,9 @@ ShouldReturnParentFolderAppendedToBaseDownloadPath) {
|
|
|
|
|
EXPECT_EQ(actual, expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPathWithParentFolder\
|
|
|
|
|
StartingWithSlashArgumentsShouldReturnParentFolderAppendedToBaseDownloadPath) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPathWithParentFolderStartingWithSlashArgumentsShouldReturnParentFolderAppendedToBaseDownloadPath) {
|
|
|
|
|
std::wstring parent_folder(L"/test_parent_folder");
|
|
|
|
|
std::wstring file_name(L"");
|
|
|
|
|
|
|
|
|
@@ -209,9 +215,9 @@ StartingWithSlashArgumentsShouldReturnParentFolderAppendedToBaseDownloadPath) {
|
|
|
|
|
EXPECT_EQ(actual, expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPathWithParentFolder\
|
|
|
|
|
StartingWithBackslashArgumentsShouldReturnParentFolderAppendedToBase\
|
|
|
|
|
DownloadPath) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPathWithParentFolderStartingWithBackslashArgumentsShouldReturnParentFolderAppendedToBaseDownloadPath) {
|
|
|
|
|
std::wstring parent_folder(L"\\test_parent_folder");
|
|
|
|
|
std::wstring file_name(L"");
|
|
|
|
|
|
|
|
|
@@ -225,8 +231,9 @@ DownloadPath) {
|
|
|
|
|
EXPECT_EQ(actual, expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPathWithParentFolder\
|
|
|
|
|
EndingWithSlashArgumentsShouldReturnParentFolderAppendedToBaseDownloadPath) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPathWithParentFolderEndingWithSlashArgumentsShouldReturnParentFolderAppendedToBaseDownloadPath) {
|
|
|
|
|
std::wstring parent_folder(L"test_parent_folder/");
|
|
|
|
|
std::wstring file_name(L"");
|
|
|
|
|
|
|
|
|
@@ -240,9 +247,9 @@ EndingWithSlashArgumentsShouldReturnParentFolderAppendedToBaseDownloadPath) {
|
|
|
|
|
EXPECT_EQ(actual, expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPathWithParentFolder\
|
|
|
|
|
EndingWithBackslashArguments\
|
|
|
|
|
ShouldReturnParentFolderAppendedToBaseDownloadPath) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPathWithParentFolderEndingWithBackslashArgumentsShouldReturnParentFolderAppendedToBaseDownloadPath) {
|
|
|
|
|
std::wstring parent_folder(L"test_parent_folder\\");
|
|
|
|
|
std::wstring file_name(L"");
|
|
|
|
|
|
|
|
|
@@ -256,8 +263,9 @@ ShouldReturnParentFolderAppendedToBaseDownloadPath) {
|
|
|
|
|
EXPECT_EQ(actual, expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPathWithFileName\
|
|
|
|
|
BeginningWithSlashArgumentsShouldReturnFileNameAppendedToBaseDownloadPath) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPathWithFileNameBeginningWithSlashArgumentsShouldReturnFileNameAppendedToBaseDownloadPath) {
|
|
|
|
|
std::wstring parent_folder(L"");
|
|
|
|
|
std::wstring file_name(L"/test_file_name.name");
|
|
|
|
|
|
|
|
|
@@ -271,8 +279,9 @@ BeginningWithSlashArgumentsShouldReturnFileNameAppendedToBaseDownloadPath) {
|
|
|
|
|
EXPECT_EQ(actual, expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPathWithFileName\
|
|
|
|
|
BeginningWithBackslashArgumentsShouldReturnFileNameAppendedToBaseDownloadPath) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPathWithFileNameBeginningWithBackslashArgumentsShouldReturnFileNameAppendedToBaseDownloadPath) {
|
|
|
|
|
std::wstring parent_folder(L"");
|
|
|
|
|
std::wstring file_name(L"\\test_file_name.name");
|
|
|
|
|
|
|
|
|
@@ -284,8 +293,9 @@ BeginningWithBackslashArgumentsShouldReturnFileNameAppendedToBaseDownloadPath) {
|
|
|
|
|
EXPECT_EQ(actual, path.str().c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPathWithFileNameEnding\
|
|
|
|
|
WithSlashArgumentsShouldReturnFileNameAppendedToBaseDownloadPath) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPathWithFileNameEndingWithSlashArgumentsShouldReturnFileNameAppendedToBaseDownloadPath) {
|
|
|
|
|
std::wstring parent_folder(L"");
|
|
|
|
|
std::wstring file_name(L"test_file_name.name/");
|
|
|
|
|
|
|
|
|
@@ -299,8 +309,9 @@ WithSlashArgumentsShouldReturnFileNameAppendedToBaseDownloadPath) {
|
|
|
|
|
EXPECT_EQ(actual, expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPathWithFileNameEnding\
|
|
|
|
|
WithBackslashArgumentsShouldReturnFileNameAppendedToBaseDownloadPath) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPathWithFileNameEndingWithBackslashArgumentsShouldReturnFileNameAppendedToBaseDownloadPath) {
|
|
|
|
|
std::wstring parent_folder(L"");
|
|
|
|
|
std::wstring file_name(L"test_file_name.name\\");
|
|
|
|
|
|
|
|
|
@@ -314,9 +325,9 @@ WithBackslashArgumentsShouldReturnFileNameAppendedToBaseDownloadPath) {
|
|
|
|
|
EXPECT_EQ(actual, expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPathWithParentFolderAnd\
|
|
|
|
|
FileNameArgumentsShould\
|
|
|
|
|
ReturnParentFolderAndFileNameAppendedToBaseDownloadPath) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPathWithParentFolderAndFileNameArgumentsShouldReturnParentFolderAndFileNameAppendedToBaseDownloadPath) {
|
|
|
|
|
std::wstring parent_folder(L"test_parent_folder");
|
|
|
|
|
std::wstring file_name(L"test_file_name.name");
|
|
|
|
|
|
|
|
|
@@ -332,9 +343,9 @@ ReturnParentFolderAndFileNameAppendedToBaseDownloadPath) {
|
|
|
|
|
EXPECT_EQ(actual, expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPathWithParentFolder\
|
|
|
|
|
EndingWithBackslashAndFileNameArgumentsShouldReturnParentFolderAndFileName\
|
|
|
|
|
AppendedToBaseDownloadPath) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPathWithParentFolderEndingWithBackslashAndFileNameArgumentsShouldReturnParentFolderAndFileNameAppendedToBaseDownloadPath) {
|
|
|
|
|
std::wstring parent_folder(L"test_parent_folder\\");
|
|
|
|
|
std::wstring file_name(L"test_file_name.name");
|
|
|
|
|
|
|
|
|
@@ -350,9 +361,9 @@ AppendedToBaseDownloadPath) {
|
|
|
|
|
EXPECT_EQ(actual, expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPathWithFileName\
|
|
|
|
|
StartingWithBackslashAndParentFolderArgumentsShouldReturnParentFolderAnd\
|
|
|
|
|
FileNameAppendedToBaseDownloadPath) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPathWithFileNameStartingWithBackslashAndParentFolderArgumentsShouldReturnParentFolderAndFileNameAppendedToBaseDownloadPath) {
|
|
|
|
|
std::wstring parent_folder(L"test_parent_folder");
|
|
|
|
|
std::wstring file_name(L"\\test_file_name.name");
|
|
|
|
|
|
|
|
|
@@ -368,8 +379,9 @@ FileNameAppendedToBaseDownloadPath) {
|
|
|
|
|
EXPECT_EQ(actual, expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPath_IllegalFileNameCharacters\
|
|
|
|
|
ReturnsFileNameWithUnderbarSubstituted) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPath_IllegalFileNameCharactersReturnsFileNameWithUnderbarSubstituted) {
|
|
|
|
|
// char illegal_character_sequence[]{ 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x05,
|
|
|
|
|
// 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0 };
|
|
|
|
|
auto illegal_character_sequence(L"Test\x5Test");
|
|
|
|
@@ -384,8 +396,9 @@ ReturnsFileNameWithUnderbarSubstituted) {
|
|
|
|
|
EXPECT_EQ(actual, expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPath_LowestIllegalFileNameCharacter\
|
|
|
|
|
ReturnsFileNameWithUnderbarSubstituted) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPath_LowestIllegalFileNameCharacterReturnsFileNameWithUnderbarSubstituted) {
|
|
|
|
|
// char illegal_character_sequence[]{ 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x01,
|
|
|
|
|
// 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0 };
|
|
|
|
|
auto illegal_character_sequence(L"Test\x1Test");
|
|
|
|
@@ -401,8 +414,9 @@ ReturnsFileNameWithUnderbarSubstituted) {
|
|
|
|
|
EXPECT_EQ(actual, expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPath_HighestIllegalFileNameCharacter\
|
|
|
|
|
ReturnsFileNameWithUnderbarSubstituted) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPath_HighestIllegalFileNameCharacterReturnsFileNameWithUnderbarSubstituted) {
|
|
|
|
|
// char illegal_character_sequence[]{ 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x1f,
|
|
|
|
|
// 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0 };
|
|
|
|
|
auto illegal_character_sequence(L"Test\x1fTest");
|
|
|
|
@@ -418,8 +432,9 @@ ReturnsFileNameWithUnderbarSubstituted) {
|
|
|
|
|
EXPECT_EQ(actual, expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPath_IllegalFileNameCharacterQuestionMark\
|
|
|
|
|
ReturnsFileNameWithUnderbarSubstituted) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPath_IllegalFileNameCharacterQuestionMarkReturnsFileNameWithUnderbarSubstituted) {
|
|
|
|
|
// char illegal_character_sequence[]{ 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2f,
|
|
|
|
|
// 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0 };
|
|
|
|
|
auto illegal_character_sequence(L"Test?Test");
|
|
|
|
@@ -435,8 +450,9 @@ ReturnsFileNameWithUnderbarSubstituted) {
|
|
|
|
|
EXPECT_EQ(actual, expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPath_IllegalFileNameCharacterAsterisk\
|
|
|
|
|
ReturnsFileNameWithUnderbarSubstituted) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPath_IllegalFileNameCharacterAsteriskReturnsFileNameWithUnderbarSubstituted) {
|
|
|
|
|
// char illegal_character_sequence[]{ 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2f,
|
|
|
|
|
// 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0 };
|
|
|
|
|
auto illegal_character_sequence(L"Test*Test");
|
|
|
|
@@ -452,8 +468,9 @@ ReturnsFileNameWithUnderbarSubstituted) {
|
|
|
|
|
EXPECT_EQ(actual, expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPath_IllegalFileNameCharacterLessThan\
|
|
|
|
|
ReturnsFileNameWithUnderbarSubstituted) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPath_IllegalFileNameCharacterLessThanReturnsFileNameWithUnderbarSubstituted) {
|
|
|
|
|
// char illegal_character_sequence[]{ 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2f,
|
|
|
|
|
// 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0 };
|
|
|
|
|
auto illegal_character_sequence(L"Test<Test");
|
|
|
|
@@ -469,8 +486,9 @@ ReturnsFileNameWithUnderbarSubstituted) {
|
|
|
|
|
EXPECT_EQ(actual, expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPath_IllegalFileNameCharacterGreaterThan\
|
|
|
|
|
ReturnsFileNameWithUnderbarSubstituted) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPath_IllegalFileNameCharacterGreaterThanReturnsFileNameWithUnderbarSubstituted) {
|
|
|
|
|
// char illegal_character_sequence[]{ 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2f,
|
|
|
|
|
// 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0 };
|
|
|
|
|
auto illegal_character_sequence(L"Test>Test");
|
|
|
|
@@ -486,8 +504,9 @@ ReturnsFileNameWithUnderbarSubstituted) {
|
|
|
|
|
EXPECT_EQ(actual, expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPath_IllegalFileNameCharacterVerticalBar\
|
|
|
|
|
ReturnsFileNameWithUnderbarSubstituted) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPath_IllegalFileNameCharacterVerticalBarReturnsFileNameWithUnderbarSubstituted) {
|
|
|
|
|
// char illegal_character_sequence[]{ 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2f,
|
|
|
|
|
// 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0 };
|
|
|
|
|
auto illegal_character_sequence(L"Test|Test");
|
|
|
|
@@ -503,8 +522,9 @@ ReturnsFileNameWithUnderbarSubstituted) {
|
|
|
|
|
EXPECT_EQ(actual, expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPath_IllegalFileNameCharacterColon\
|
|
|
|
|
ReturnsFileNameWithUnderbarSubstituted) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPath_IllegalFileNameCharacterColonReturnsFileNameWithUnderbarSubstituted) {
|
|
|
|
|
// char illegal_character_sequence[]{ 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2f,
|
|
|
|
|
// 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0 };
|
|
|
|
|
auto illegal_character_sequence(L"Test:Test");
|
|
|
|
@@ -520,8 +540,8 @@ ReturnsFileNameWithUnderbarSubstituted) {
|
|
|
|
|
EXPECT_EQ(actual, expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPath_FileDoesntExist\
|
|
|
|
|
ReturnsFileWithPassedName) {
|
|
|
|
|
TEST_F(FilePathTests,
|
|
|
|
|
GetDownloadPath_FileDoesntExistReturnsFileWithPassedName) {
|
|
|
|
|
std::wstring file_name(kFileName);
|
|
|
|
|
std::wstring parent_folder(L"");
|
|
|
|
|
|
|
|
|
@@ -534,8 +554,8 @@ ReturnsFileWithPassedName) {
|
|
|
|
|
EXPECT_EQ(actual, expected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPath_FileExistsReturns\
|
|
|
|
|
FileWithIncrementedName) {
|
|
|
|
|
TEST_F(FilePathTests,
|
|
|
|
|
GetDownloadPath_FileExistsReturnsFileWithIncrementedName) {
|
|
|
|
|
std::wstring file_name(kFileName);
|
|
|
|
|
std::wstring renamed_file_name(kFirstIterationFileName);
|
|
|
|
|
std::wstring parent_folder(L"");
|
|
|
|
@@ -571,8 +591,8 @@ FileWithIncrementedName) {
|
|
|
|
|
ASSERT_FALSE(input_file.rdstate() == std::ifstream::goodbit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPath_MultipleFilesExist\
|
|
|
|
|
ReturnsNextIncrementedFileName) {
|
|
|
|
|
TEST_F(FilePathTests,
|
|
|
|
|
GetDownloadPath_MultipleFilesExistReturnsNextIncrementedFileName) {
|
|
|
|
|
std::ofstream output_file;
|
|
|
|
|
std::ifstream input_file;
|
|
|
|
|
|
|
|
|
@@ -586,7 +606,8 @@ ReturnsNextIncrementedFileName) {
|
|
|
|
|
expected.append(second_renamed_file_name.c_str());
|
|
|
|
|
|
|
|
|
|
std::wstring output_file1_path(default_download_path_);
|
|
|
|
|
output_file1_path.append(L"/" + file_name);
|
|
|
|
|
output_file1_path.append(L"/");
|
|
|
|
|
output_file1_path.append(file_name);
|
|
|
|
|
|
|
|
|
|
std::wstring output_file2_path(default_download_path_);
|
|
|
|
|
output_file2_path.append(first_renamed_file_name);
|
|
|
|
@@ -610,7 +631,8 @@ ReturnsNextIncrementedFileName) {
|
|
|
|
|
// Remove the test files and check that it is removed
|
|
|
|
|
// File 1
|
|
|
|
|
std::filesystem::remove(wstring_to_string(output_file1_path).c_str());
|
|
|
|
|
input_file.open(output_file1_path, std::ifstream::binary | std::ifstream::in);
|
|
|
|
|
input_file.open(wstring_to_string(output_file1_path),
|
|
|
|
|
std::ifstream::binary | std::ifstream::in);
|
|
|
|
|
|
|
|
|
|
ASSERT_FALSE(input_file.rdstate() == std::ifstream::goodbit);
|
|
|
|
|
|
|
|
|
@@ -624,8 +646,9 @@ ReturnsNextIncrementedFileName) {
|
|
|
|
|
ASSERT_FALSE(input_file.rdstate() == std::ifstream::goodbit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPath_FileNameContains\
|
|
|
|
|
MultipleDotsReturnsIncrementBeforeFirstDot) {
|
|
|
|
|
TEST_F(
|
|
|
|
|
FilePathTests,
|
|
|
|
|
GetDownloadPath_FileNameContainsMultipleDotsReturnsIncrementBeforeFirstDot) {
|
|
|
|
|
std::ifstream input_file;
|
|
|
|
|
std::ofstream output_file;
|
|
|
|
|
|
|
|
|
@@ -635,7 +658,8 @@ MultipleDotsReturnsIncrementBeforeFirstDot) {
|
|
|
|
|
std::wstring parent_folder(L"");
|
|
|
|
|
|
|
|
|
|
std::wstring output_file1_path(default_download_path_);
|
|
|
|
|
output_file1_path.append(L"/" + file_name);
|
|
|
|
|
output_file1_path.append(L"/");
|
|
|
|
|
output_file1_path.append(file_name);
|
|
|
|
|
|
|
|
|
|
std::wstring output_file2_path(default_download_path_);
|
|
|
|
|
output_file2_path.append(renamed_file_name);
|
|
|
|
@@ -659,8 +683,8 @@ MultipleDotsReturnsIncrementBeforeFirstDot) {
|
|
|
|
|
ASSERT_FALSE(input_file.rdstate() == std::ifstream::goodbit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPath_FileNameContainsNo\
|
|
|
|
|
DotsReturnsWithIncrementAtEnd) {
|
|
|
|
|
TEST_F(FilePathTests,
|
|
|
|
|
GetDownloadPath_FileNameContainsNoDotsReturnsWithIncrementAtEnd) {
|
|
|
|
|
std::ifstream input_file;
|
|
|
|
|
std::ofstream output_file;
|
|
|
|
|
|
|
|
|
@@ -670,10 +694,12 @@ DotsReturnsWithIncrementAtEnd) {
|
|
|
|
|
std::wstring parent_folder(L"");
|
|
|
|
|
|
|
|
|
|
std::wstring output_file1_path(default_download_path_);
|
|
|
|
|
output_file1_path.append(L"/" + file_name);
|
|
|
|
|
output_file1_path.append(L"/");
|
|
|
|
|
output_file1_path.append(file_name);
|
|
|
|
|
|
|
|
|
|
std::wstring output_file2_path(default_download_path_);
|
|
|
|
|
output_file2_path.append(L"/" + renamed_file_name);
|
|
|
|
|
output_file2_path.append(L"/");
|
|
|
|
|
output_file2_path.append(renamed_file_name);
|
|
|
|
|
|
|
|
|
|
std::wstring expected(default_download_path_);
|
|
|
|
|
expected.append(renamed_file_name);
|
|
|
|
@@ -694,8 +720,8 @@ DotsReturnsWithIncrementAtEnd) {
|
|
|
|
|
ASSERT_FALSE(input_file.rdstate() == std::ifstream::goodbit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(FilePathTests, GetDownloadPath_FileNameExistsWith\
|
|
|
|
|
AHoleBetweenRenamedFiles) {
|
|
|
|
|
TEST_F(FilePathTests,
|
|
|
|
|
GetDownloadPath_FileNameExistsWithAHoleBetweenRenamedFiles) {
|
|
|
|
|
std::ifstream input_file;
|
|
|
|
|
std::ofstream output_file;
|
|
|
|
|
|
|
|
|
@@ -708,8 +734,8 @@ AHoleBetweenRenamedFiles) {
|
|
|
|
|
|
|
|
|
|
// Create the path for the original file name
|
|
|
|
|
std::wstring output_file_path(default_download_path_);
|
|
|
|
|
output_file_path.append(L"/");
|
|
|
|
|
output_file_path.append(
|
|
|
|
|
L"/" +
|
|
|
|
|
file_name); // Original file name example: "increment_file_test.txt"
|
|
|
|
|
|
|
|
|
|
// Create the path for the first iteration of the original file name
|
|
|
|
|