| 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 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 ASSERT_EQ(1u, fileSystemTasks.size()); | 67 ASSERT_EQ(1u, fileSystemTasks.size()); |
| 67 (*fileSystemTasks.begin())(); | 68 (*fileSystemTasks.begin())(); |
| 68 fileSystemTasks.pop_front(); | 69 fileSystemTasks.pop_front(); |
| 69 } | 70 } |
| 70 | 71 |
| 71 std::list<SchedulerTask> fileSystemTasks; | 72 std::list<SchedulerTask> fileSystemTasks; |
| 72 FileSystemPtr fileSystem; | 73 FileSystemPtr fileSystem; |
| 73 }; | 74 }; |
| 74 } | 75 } |
| 75 | 76 |
| 77 #ifdef _WIN32 |
| 78 #define SLASH_STRING "\\" |
| 79 #else |
| 80 #define SLASH_STRING "/" |
| 81 #endif |
| 82 |
| 83 TEST(DefaultFileSystemBasePathTest, BasePathAndResolveTest) |
| 84 { |
| 85 class TestFSSync : public DefaultFileSystemSync |
| 86 { |
| 87 public: |
| 88 explicit TestFSSync(const std::string& basePath) |
| 89 : DefaultFileSystemSync(basePath) |
| 90 { |
| 91 } |
| 92 const std::string& base() const |
| 93 { |
| 94 return basePath; |
| 95 } |
| 96 }; |
| 97 |
| 98 { |
| 99 auto fs = std::unique_ptr<TestFSSync>(new TestFSSync("")); |
| 100 EXPECT_EQ("", fs->base()); |
| 101 std::string fullPath = fs->Resolve("bar" SLASH_STRING "baz.txt"); |
| 102 EXPECT_EQ("bar" SLASH_STRING "baz.txt", fullPath); |
| 103 } |
| 104 { |
| 105 auto fs = std::unique_ptr<TestFSSync>(new TestFSSync(SLASH_STRING)); |
| 106 EXPECT_EQ(SLASH_STRING, fs->base()); |
| 107 std::string fullPath = fs->Resolve("bar" SLASH_STRING "baz.txt"); |
| 108 EXPECT_EQ(SLASH_STRING "bar" SLASH_STRING "baz.txt", fullPath); |
| 109 } |
| 110 { |
| 111 auto fs = std::unique_ptr<TestFSSync>( |
| 112 new TestFSSync(SLASH_STRING "foo" SLASH_STRING)); |
| 113 EXPECT_EQ(SLASH_STRING "foo", fs->base()); |
| 114 std::string fullPath = fs->Resolve("bar" SLASH_STRING "baz.txt"); |
| 115 EXPECT_EQ(SLASH_STRING "foo" SLASH_STRING "bar" SLASH_STRING "baz.txt", |
| 116 fullPath); |
| 117 } |
| 118 { |
| 119 auto fs = std::unique_ptr<TestFSSync>( |
| 120 new TestFSSync(SLASH_STRING "foo")); |
| 121 EXPECT_EQ(SLASH_STRING "foo", fs->base()); |
| 122 std::string fullPath = fs->Resolve("bar" SLASH_STRING "baz.txt"); |
| 123 EXPECT_EQ(SLASH_STRING "foo" SLASH_STRING "bar" SLASH_STRING "baz.txt", |
| 124 fullPath); |
| 125 } |
| 126 } |
| 127 |
| 76 TEST_F(DefaultFileSystemTest, WriteReadRemove) | 128 TEST_F(DefaultFileSystemTest, WriteReadRemove) |
| 77 { | 129 { |
| 78 WriteString("foo"); | 130 WriteString("foo"); |
| 79 | 131 |
| 80 bool hasReadRun = false; | 132 bool hasReadRun = false; |
| 81 fileSystem->Read(testFileName, | 133 fileSystem->Read(testFileName, |
| 82 [this, &hasReadRun](IFileSystem::IOBuffer&& content, const std::string& erro
r) | 134 [this, &hasReadRun](IFileSystem::IOBuffer&& content, const std::string& erro
r) |
| 83 { | 135 { |
| 84 EXPECT_TRUE(error.empty()); | 136 EXPECT_TRUE(error.empty()); |
| 85 EXPECT_EQ("foo", std::string(content.cbegin(), content.cend())); | 137 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) | 232 fileSystem->Stat(newTestFileName, [&hasStatRemovedFileRun](const IFileSystem::
StatResult& result, const std::string& error) |
| 181 { | 233 { |
| 182 EXPECT_TRUE(error.empty()); | 234 EXPECT_TRUE(error.empty()); |
| 183 ASSERT_FALSE(result.exists); | 235 ASSERT_FALSE(result.exists); |
| 184 hasStatRemovedFileRun = true; | 236 hasStatRemovedFileRun = true; |
| 185 }); | 237 }); |
| 186 EXPECT_FALSE(hasStatRemovedFileRun); | 238 EXPECT_FALSE(hasStatRemovedFileRun); |
| 187 PumpTask(); | 239 PumpTask(); |
| 188 EXPECT_TRUE(hasStatRemovedFileRun); | 240 EXPECT_TRUE(hasStatRemovedFileRun); |
| 189 } | 241 } |
| OLD | NEW |