OLD | NEW |
(Empty) | |
| 1 #include <AdblockPlus.h> |
| 2 #include <gtest/gtest.h> |
| 3 |
| 4 #include "../src/Utils.h" |
| 5 |
| 6 namespace |
| 7 { |
| 8 const std::string testPath = "libadblockplus-test-file"; |
| 9 |
| 10 void WriteString(AdblockPlus::FileSystem& fileSystem, |
| 11 const std::string& content) |
| 12 { |
| 13 std::tr1::shared_ptr<std::stringstream> input(new std::stringstream); |
| 14 *input << content; |
| 15 fileSystem.Write(testPath, input); |
| 16 } |
| 17 } |
| 18 |
| 19 TEST(DefaultFileSystemTest, WriteReadRemove) |
| 20 { |
| 21 AdblockPlus::DefaultFileSystem fileSystem; |
| 22 WriteString(fileSystem, "foo"); |
| 23 std::string output = AdblockPlus::Utils::Slurp(*fileSystem.Read(testPath)); |
| 24 fileSystem.Remove(testPath); |
| 25 ASSERT_EQ("foo", output); |
| 26 } |
| 27 |
| 28 TEST(DefaultFileSystemTest, StatWorkingDirectory) |
| 29 { |
| 30 AdblockPlus::DefaultFileSystem fileSystem; |
| 31 const AdblockPlus::FileSystem::StatResult result = fileSystem.Stat("."); |
| 32 ASSERT_TRUE(result.exists); |
| 33 ASSERT_TRUE(result.isDirectory); |
| 34 ASSERT_FALSE(result.isFile); |
| 35 ASSERT_NE(0, result.lastModified); |
| 36 } |
| 37 |
| 38 TEST(DefaultFileSystemTest, WriteMoveStatRemove) |
| 39 { |
| 40 AdblockPlus::DefaultFileSystem fileSystem; |
| 41 WriteString(fileSystem, "foo"); |
| 42 AdblockPlus::FileSystem::StatResult result = fileSystem.Stat(testPath); |
| 43 ASSERT_TRUE(result.exists); |
| 44 ASSERT_TRUE(result.isFile); |
| 45 ASSERT_FALSE(result.isDirectory); |
| 46 ASSERT_NE(0, result.lastModified); |
| 47 const std::string newTestPath = testPath + "-new"; |
| 48 fileSystem.Move(testPath, newTestPath); |
| 49 result = fileSystem.Stat(testPath); |
| 50 ASSERT_FALSE(result.exists); |
| 51 result = fileSystem.Stat(newTestPath); |
| 52 ASSERT_TRUE(result.exists); |
| 53 fileSystem.Remove(newTestPath); |
| 54 result = fileSystem.Stat(newTestPath); |
| 55 ASSERT_FALSE(result.exists); |
| 56 } |
OLD | NEW |