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