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 std::stringstream input; | 34 Sync sync; |
30 input << content; | 35 |
31 fileSystem.Write(testPath, input); | 36 fileSystem->Write(testPath, content, [&sync](const std::string& error) |
| 37 { |
| 38 EXPECT_TRUE(error.empty()); |
| 39 |
| 40 sync.Set(); |
| 41 }); |
| 42 |
| 43 sync.WaitFor(); |
32 } | 44 } |
33 } | 45 } |
34 | 46 |
35 TEST(DefaultFileSystemTest, WriteReadRemove) | 47 TEST(DefaultFileSystemTest, WriteReadRemove) |
36 { | 48 { |
37 AdblockPlus::DefaultFileSystem fileSystem; | 49 Sync sync; |
| 50 AdblockPlus::FileSystemPtr fileSystem = AdblockPlus::CreateDefaultFileSystem()
; |
38 WriteString(fileSystem, "foo"); | 51 WriteString(fileSystem, "foo"); |
39 std::stringstream output; | 52 fileSystem->Read(testPath, [fileSystem, &sync](std::string&& content, const st
d::string& error) |
40 output << fileSystem.Read(testPath)->rdbuf(); | 53 { |
41 fileSystem.Remove(testPath); | 54 EXPECT_TRUE(error.empty()); |
42 ASSERT_EQ("foo", output.str()); | 55 EXPECT_EQ("foo", content); |
| 56 |
| 57 fileSystem->Remove(testPath, [&sync](const std::string& error) |
| 58 { |
| 59 EXPECT_TRUE(error.empty()); |
| 60 sync.Set(); |
| 61 }); |
| 62 }); |
| 63 |
| 64 EXPECT_TRUE(sync.WaitFor()); |
43 } | 65 } |
44 | 66 |
45 TEST(DefaultFileSystemTest, StatWorkingDirectory) | 67 TEST(DefaultFileSystemTest, StatWorkingDirectory) |
46 { | 68 { |
47 AdblockPlus::DefaultFileSystem fileSystem; | 69 Sync sync; |
48 const AdblockPlus::FileSystem::StatResult result = fileSystem.Stat("."); | 70 AdblockPlus::FileSystemPtr fileSystem = AdblockPlus::CreateDefaultFileSystem()
; |
49 ASSERT_TRUE(result.exists); | 71 fileSystem->Stat(".", |
50 ASSERT_TRUE(result.isDirectory); | 72 [fileSystem, &sync](const IFileSystem::StatResult result, const std::string&
error) |
51 ASSERT_FALSE(result.isFile); | 73 { |
52 ASSERT_NE(0, result.lastModified); | 74 EXPECT_TRUE(error.empty()); |
| 75 ASSERT_TRUE(result.exists); |
| 76 ASSERT_TRUE(result.isDirectory); |
| 77 ASSERT_FALSE(result.isFile); |
| 78 ASSERT_NE(0, result.lastModified); |
| 79 sync.Set(); |
| 80 }); |
| 81 |
| 82 EXPECT_TRUE(sync.WaitFor()); |
53 } | 83 } |
54 | 84 |
55 TEST(DefaultFileSystemTest, WriteMoveStatRemove) | 85 TEST(DefaultFileSystemTest, WriteMoveStatRemove) |
56 { | 86 { |
57 AdblockPlus::DefaultFileSystem fileSystem; | 87 Sync sync; |
| 88 AdblockPlus::FileSystemPtr fileSystem = AdblockPlus::CreateDefaultFileSystem()
; |
58 WriteString(fileSystem, "foo"); | 89 WriteString(fileSystem, "foo"); |
59 AdblockPlus::FileSystem::StatResult result = fileSystem.Stat(testPath); | 90 |
60 ASSERT_TRUE(result.exists); | 91 fileSystem->Stat(testPath, |
61 ASSERT_TRUE(result.isFile); | 92 [fileSystem, &sync](const IFileSystem::StatResult& result, const std::string
& error) |
62 ASSERT_FALSE(result.isDirectory); | 93 { |
63 ASSERT_NE(0, result.lastModified); | 94 EXPECT_TRUE(error.empty()); |
64 const std::string newTestPath = testPath + "-new"; | 95 ASSERT_TRUE(result.exists); |
65 fileSystem.Move(testPath, newTestPath); | 96 ASSERT_TRUE(result.isFile); |
66 result = fileSystem.Stat(testPath); | 97 ASSERT_FALSE(result.isDirectory); |
67 ASSERT_FALSE(result.exists); | 98 ASSERT_NE(0, result.lastModified); |
68 result = fileSystem.Stat(newTestPath); | 99 const std::string newTestPath = testPath + "-new"; |
69 ASSERT_TRUE(result.exists); | 100 fileSystem->Move(testPath, newTestPath, [fileSystem, &sync, newTestPath](c
onst std::string& error) |
70 fileSystem.Remove(newTestPath); | 101 { |
71 result = fileSystem.Stat(newTestPath); | 102 EXPECT_TRUE(error.empty()); |
72 ASSERT_FALSE(result.exists); | 103 fileSystem->Stat(testPath, [fileSystem, &sync, newTestPath](const IFileS
ystem::StatResult& result, const std::string& error) |
| 104 { |
| 105 EXPECT_TRUE(error.empty()); |
| 106 ASSERT_FALSE(result.exists); |
| 107 fileSystem->Stat(newTestPath, [fileSystem, &sync, newTestPath](const I
FileSystem::StatResult& result, const std::string& error) |
| 108 { |
| 109 EXPECT_TRUE(error.empty()); |
| 110 ASSERT_TRUE(result.exists); |
| 111 fileSystem->Remove(newTestPath, [fileSystem, &sync, newTestPath](con
st std::string& error) |
| 112 { |
| 113 EXPECT_TRUE(error.empty()); |
| 114 fileSystem->Stat(newTestPath, [fileSystem, &sync, newTestPath](con
st IFileSystem::StatResult& result, const std::string& error) |
| 115 { |
| 116 EXPECT_TRUE(error.empty()); |
| 117 ASSERT_FALSE(result.exists); |
| 118 sync.Set(); |
| 119 }); |
| 120 }); |
| 121 }); |
| 122 }); |
| 123 }); |
| 124 }); |
| 125 |
| 126 EXPECT_TRUE(sync.WaitFor()); |
73 } | 127 } |
OLD | NEW |