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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 <sstream> | 18 #include <sstream> |
19 #include <AdblockPlus.h> | 19 #include <AdblockPlus.h> |
20 #include <gtest/gtest.h> | 20 #include <gtest/gtest.h> |
21 | 21 |
| 22 #include "BaseJsTest.h" |
| 23 |
| 24 using AdblockPlus::IFileSystem; |
| 25 using AdblockPlus::Sync; |
| 26 |
22 namespace | 27 namespace |
23 { | 28 { |
24 const std::string testPath = "libadblockplus-t\xc3\xa4st-file"; | 29 const std::string testPath = "libadblockplus-t\xc3\xa4st-file"; |
25 | 30 |
26 void WriteString(AdblockPlus::FileSystem& fileSystem, | 31 void WriteString(const AdblockPlus::FileSystemPtr& fileSystem, |
27 const std::string& content) | 32 const std::string& content) |
28 { | 33 { |
29 AdblockPlus::FileSystem::IOBuffer buffer(content.cbegin(), content.cend()); | 34 Sync sync; |
30 fileSystem.Write(testPath, buffer); | 35 |
| 36 fileSystem->Write(testPath, |
| 37 IFileSystem::IOBuffer(content.cbegin(), content.cend()), |
| 38 [&sync](const std::string& error) |
| 39 { |
| 40 EXPECT_TRUE(error.empty()); |
| 41 |
| 42 sync.Set(); |
| 43 }); |
| 44 |
| 45 sync.WaitFor(); |
31 } | 46 } |
32 } | 47 } |
33 | 48 |
34 TEST(DefaultFileSystemTest, WriteReadRemove) | 49 TEST(DefaultFileSystemTest, WriteReadRemove) |
35 { | 50 { |
36 AdblockPlus::DefaultFileSystem fileSystem; | 51 Sync sync; |
| 52 AdblockPlus::FileSystemPtr fileSystem = AdblockPlus::CreateDefaultFileSystem()
; |
37 WriteString(fileSystem, "foo"); | 53 WriteString(fileSystem, "foo"); |
38 auto output = fileSystem.Read(testPath); | 54 fileSystem->Read(testPath, |
39 fileSystem.Remove(testPath); | 55 [fileSystem, &sync](IFileSystem::IOBuffer&& content, const std::string& erro
r) |
40 ASSERT_EQ("foo", std::string(output.cbegin(), output.cend())); | 56 { |
| 57 EXPECT_TRUE(error.empty()); |
| 58 EXPECT_EQ("foo", std::string(content.cbegin(), content.cend())); |
| 59 |
| 60 fileSystem->Remove(testPath, [&sync](const std::string& error) |
| 61 { |
| 62 EXPECT_TRUE(error.empty()); |
| 63 sync.Set(); |
| 64 }); |
| 65 }); |
| 66 |
| 67 EXPECT_TRUE(sync.WaitFor()); |
41 } | 68 } |
42 | 69 |
43 TEST(DefaultFileSystemTest, StatWorkingDirectory) | 70 TEST(DefaultFileSystemTest, StatWorkingDirectory) |
44 { | 71 { |
45 AdblockPlus::DefaultFileSystem fileSystem; | 72 Sync sync; |
46 const AdblockPlus::FileSystem::StatResult result = fileSystem.Stat("."); | 73 AdblockPlus::FileSystemPtr fileSystem = AdblockPlus::CreateDefaultFileSystem()
; |
47 ASSERT_TRUE(result.exists); | 74 fileSystem->Stat(".", |
48 ASSERT_TRUE(result.isDirectory); | 75 [fileSystem, &sync](const IFileSystem::StatResult result, const std::string&
error) |
49 ASSERT_FALSE(result.isFile); | 76 { |
50 ASSERT_NE(0, result.lastModified); | 77 EXPECT_TRUE(error.empty()); |
| 78 ASSERT_TRUE(result.exists); |
| 79 ASSERT_TRUE(result.isDirectory); |
| 80 ASSERT_FALSE(result.isFile); |
| 81 ASSERT_NE(0, result.lastModified); |
| 82 sync.Set(); |
| 83 }); |
| 84 |
| 85 EXPECT_TRUE(sync.WaitFor()); |
51 } | 86 } |
52 | 87 |
53 TEST(DefaultFileSystemTest, WriteMoveStatRemove) | 88 TEST(DefaultFileSystemTest, WriteMoveStatRemove) |
54 { | 89 { |
55 AdblockPlus::DefaultFileSystem fileSystem; | 90 Sync sync; |
| 91 AdblockPlus::FileSystemPtr fileSystem = AdblockPlus::CreateDefaultFileSystem()
; |
56 WriteString(fileSystem, "foo"); | 92 WriteString(fileSystem, "foo"); |
57 AdblockPlus::FileSystem::StatResult result = fileSystem.Stat(testPath); | 93 |
58 ASSERT_TRUE(result.exists); | 94 fileSystem->Stat(testPath, |
59 ASSERT_TRUE(result.isFile); | 95 [fileSystem, &sync](const IFileSystem::StatResult& result, const std::string
& error) |
60 ASSERT_FALSE(result.isDirectory); | 96 { |
61 ASSERT_NE(0, result.lastModified); | 97 EXPECT_TRUE(error.empty()); |
62 const std::string newTestPath = testPath + "-new"; | 98 ASSERT_TRUE(result.exists); |
63 fileSystem.Move(testPath, newTestPath); | 99 ASSERT_TRUE(result.isFile); |
64 result = fileSystem.Stat(testPath); | 100 ASSERT_FALSE(result.isDirectory); |
65 ASSERT_FALSE(result.exists); | 101 ASSERT_NE(0, result.lastModified); |
66 result = fileSystem.Stat(newTestPath); | 102 const std::string newTestPath = testPath + "-new"; |
67 ASSERT_TRUE(result.exists); | 103 fileSystem->Move(testPath, newTestPath, [fileSystem, &sync, newTestPath](c
onst std::string& error) |
68 fileSystem.Remove(newTestPath); | 104 { |
69 result = fileSystem.Stat(newTestPath); | 105 EXPECT_TRUE(error.empty()); |
70 ASSERT_FALSE(result.exists); | 106 fileSystem->Stat(testPath, [fileSystem, &sync, newTestPath](const IFileS
ystem::StatResult& result, const std::string& error) |
| 107 { |
| 108 EXPECT_TRUE(error.empty()); |
| 109 ASSERT_FALSE(result.exists); |
| 110 fileSystem->Stat(newTestPath, [fileSystem, &sync, newTestPath](const I
FileSystem::StatResult& result, const std::string& error) |
| 111 { |
| 112 EXPECT_TRUE(error.empty()); |
| 113 ASSERT_TRUE(result.exists); |
| 114 fileSystem->Remove(newTestPath, [fileSystem, &sync, newTestPath](con
st std::string& error) |
| 115 { |
| 116 EXPECT_TRUE(error.empty()); |
| 117 fileSystem->Stat(newTestPath, [fileSystem, &sync, newTestPath](con
st IFileSystem::StatResult& result, const std::string& error) |
| 118 { |
| 119 EXPECT_TRUE(error.empty()); |
| 120 ASSERT_FALSE(result.exists); |
| 121 sync.Set(); |
| 122 }); |
| 123 }); |
| 124 }); |
| 125 }); |
| 126 }); |
| 127 }); |
| 128 |
| 129 EXPECT_TRUE(sync.WaitFor()); |
71 } | 130 } |
OLD | NEW |