| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 #include <memory> | |
| 18 #include <sstream> | 19 #include <sstream> |
| 19 #include <AdblockPlus.h> | 20 #include <AdblockPlus.h> |
| 20 #include <gtest/gtest.h> | 21 #include <gtest/gtest.h> |
| 21 #include "../src/DefaultFileSystem.h" | 22 #include "../src/DefaultFileSystem.h" |
| 22 #include "BaseJsTest.h" | 23 #include "BaseJsTest.h" |
| 23 | 24 |
| 24 using AdblockPlus::IFileSystem; | 25 using AdblockPlus::IFileSystem; |
| 25 using AdblockPlus::FileSystemPtr; | 26 using AdblockPlus::FileSystemPtr; |
| 26 using AdblockPlus::SchedulerTask; | 27 using AdblockPlus::SchedulerTask; |
| 27 | 28 |
| 28 using namespace AdblockPlus; | 29 using namespace AdblockPlus; |
| 29 namespace | 30 namespace |
| 30 { | 31 { |
| 31 const std::string testFileName = "libadblockplus-t\xc3\xa4st-file"; | 32 const std::string testFileName = "libadblockplus-t\xc3\xa4st-file"; |
| 32 | 33 |
| 33 FileSystemPtr CreateDefaultFileSystem(const Scheduler& scheduler) | 34 FileSystemPtr CreateDefaultFileSystem(const Scheduler& scheduler) |
| 34 { | 35 { |
| 35 return FileSystemPtr(new DefaultFileSystem(scheduler, std::unique_ptr<Defaul tFileSystemSync>(new DefaultFileSystemSync("")))); | 36 return FileSystemPtr(new DefaultFileSystem(scheduler, std::unique_ptr<Defaul tFileSystemSync>(new DefaultFileSystemSync("")))); |
| 36 } | 37 } |
| 37 | 38 |
| 39 class BasePathTest : public ::testing::Test | |
|
sergei
2017/09/08 08:11:40
It seems this fixture is not required, one can sim
hub
2017/09/08 13:10:26
Done.
| |
| 40 { | |
| 41 }; | |
| 42 | |
| 38 class DefaultFileSystemTest : public ::testing::Test | 43 class DefaultFileSystemTest : public ::testing::Test |
| 39 { | 44 { |
| 40 public: | 45 public: |
| 41 void SetUp() override | 46 void SetUp() override |
| 42 { | 47 { |
| 43 fileSystem = CreateDefaultFileSystem([this](const SchedulerTask& task) | 48 fileSystem = CreateDefaultFileSystem([this](const SchedulerTask& task) |
| 44 { | 49 { |
| 45 fileSystemTasks.emplace_back(task); | 50 fileSystemTasks.emplace_back(task); |
| 46 }); | 51 }); |
| 47 } | 52 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 66 ASSERT_EQ(1u, fileSystemTasks.size()); | 71 ASSERT_EQ(1u, fileSystemTasks.size()); |
| 67 (*fileSystemTasks.begin())(); | 72 (*fileSystemTasks.begin())(); |
| 68 fileSystemTasks.pop_front(); | 73 fileSystemTasks.pop_front(); |
| 69 } | 74 } |
| 70 | 75 |
| 71 std::list<SchedulerTask> fileSystemTasks; | 76 std::list<SchedulerTask> fileSystemTasks; |
| 72 FileSystemPtr fileSystem; | 77 FileSystemPtr fileSystem; |
| 73 }; | 78 }; |
| 74 } | 79 } |
| 75 | 80 |
| 81 #ifdef _WIN32 | |
| 82 #define SLASH_STRING "\\" | |
| 83 #else | |
| 84 #define SLASH_STRING "/" | |
|
sergei
2017/09/08 08:11:40
These defines are already available as PATH_SEPARA
hub
2017/09/08 13:10:26
but they are single char, while this is a string.
sergei
2017/09/08 13:20:18
Acknowledged.
| |
| 85 #endif | |
| 86 | |
| 87 | |
| 88 TEST_F(BasePathTest, BasePathTest) | |
|
sergei
2017/09/08 08:11:40
What about renaming it into something emphasizing
hub
2017/09/08 13:10:26
Done.
| |
| 89 { | |
| 90 class TestFSSync : public DefaultFileSystemSync | |
| 91 { | |
| 92 public: | |
| 93 explicit TestFSSync(const std::string& basePath) | |
| 94 : DefaultFileSystemSync(basePath) | |
| 95 { | |
| 96 } | |
| 97 const std::string& base() const | |
| 98 { | |
| 99 return basePath; | |
| 100 } | |
| 101 }; | |
| 102 | |
| 103 { | |
| 104 auto fs = std::unique_ptr<TestFSSync>(new TestFSSync("")); | |
| 105 EXPECT_EQ("", fs->base()); | |
| 106 std::string fullPath = fs->Resolve("bar" SLASH_STRING "baz.txt"); | |
| 107 EXPECT_EQ("bar" SLASH_STRING "baz.txt", fullPath); | |
| 108 } | |
| 109 { | |
| 110 auto fs = std::unique_ptr<TestFSSync>(new TestFSSync(SLASH_STRING)); | |
| 111 EXPECT_EQ(SLASH_STRING, fs->base()); | |
| 112 std::string fullPath = fs->Resolve("bar" SLASH_STRING "baz.txt"); | |
| 113 EXPECT_EQ(SLASH_STRING "bar" SLASH_STRING "baz.txt", fullPath); | |
| 114 } | |
| 115 { | |
| 116 auto fs = std::unique_ptr<TestFSSync>( | |
| 117 new TestFSSync(SLASH_STRING "foo" SLASH_STRING)); | |
| 118 EXPECT_EQ(SLASH_STRING "foo", fs->base()); | |
| 119 std::string fullPath = fs->Resolve("bar" SLASH_STRING "baz.txt"); | |
| 120 EXPECT_EQ(SLASH_STRING "foo" SLASH_STRING "bar" SLASH_STRING "baz.txt", | |
| 121 fullPath); | |
| 122 } | |
| 123 { | |
| 124 auto fs = std::unique_ptr<TestFSSync>( | |
| 125 new TestFSSync(SLASH_STRING "foo")); | |
| 126 EXPECT_EQ(SLASH_STRING "foo", fs->base()); | |
| 127 std::string fullPath = fs->Resolve("bar" SLASH_STRING "baz.txt"); | |
| 128 EXPECT_EQ(SLASH_STRING "foo" SLASH_STRING "bar" SLASH_STRING "baz.txt", | |
| 129 fullPath); | |
| 130 } | |
| 131 } | |
| 132 | |
| 76 TEST_F(DefaultFileSystemTest, WriteReadRemove) | 133 TEST_F(DefaultFileSystemTest, WriteReadRemove) |
| 77 { | 134 { |
| 78 WriteString("foo"); | 135 WriteString("foo"); |
| 79 | 136 |
| 80 bool hasReadRun = false; | 137 bool hasReadRun = false; |
| 81 fileSystem->Read(testFileName, | 138 fileSystem->Read(testFileName, |
| 82 [this, &hasReadRun](IFileSystem::IOBuffer&& content, const std::string& erro r) | 139 [this, &hasReadRun](IFileSystem::IOBuffer&& content, const std::string& erro r) |
| 83 { | 140 { |
| 84 EXPECT_TRUE(error.empty()); | 141 EXPECT_TRUE(error.empty()); |
| 85 EXPECT_EQ("foo", std::string(content.cbegin(), content.cend())); | 142 EXPECT_EQ("foo", std::string(content.cbegin(), content.cend())); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 fileSystem->Stat(newTestFileName, [&hasStatRemovedFileRun](const IFileSystem:: StatResult& result, const std::string& error) | 237 fileSystem->Stat(newTestFileName, [&hasStatRemovedFileRun](const IFileSystem:: StatResult& result, const std::string& error) |
| 181 { | 238 { |
| 182 EXPECT_TRUE(error.empty()); | 239 EXPECT_TRUE(error.empty()); |
| 183 ASSERT_FALSE(result.exists); | 240 ASSERT_FALSE(result.exists); |
| 184 hasStatRemovedFileRun = true; | 241 hasStatRemovedFileRun = true; |
| 185 }); | 242 }); |
| 186 EXPECT_FALSE(hasStatRemovedFileRun); | 243 EXPECT_FALSE(hasStatRemovedFileRun); |
| 187 PumpTask(); | 244 PumpTask(); |
| 188 EXPECT_TRUE(hasStatRemovedFileRun); | 245 EXPECT_TRUE(hasStatRemovedFileRun); |
| 189 } | 246 } |
| OLD | NEW |