Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: test/DefaultFileSystem.cpp

Issue 29481704: Noissue - Use buffer for FileSystem IO (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Removed Utils::Slurp() we no longer need Created July 6, 2017, 9:32 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/BaseJsTest.h ('k') | test/FileSystemJsObject.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 namespace 22 namespace
23 { 23 {
24 const std::string testPath = "libadblockplus-t\xc3\xa4st-file"; 24 const std::string testPath = "libadblockplus-t\xc3\xa4st-file";
25 25
26 void WriteString(AdblockPlus::FileSystem& fileSystem, 26 void WriteString(AdblockPlus::FileSystem& fileSystem,
27 const std::string& content) 27 const std::string& content)
28 { 28 {
29 std::stringstream input; 29 AdblockPlus::FileSystem::IOBuffer buffer(content.cbegin(), content.cend());
30 input << content; 30 fileSystem.Write(testPath, buffer);
31 fileSystem.Write(testPath, input);
32 } 31 }
33 } 32 }
34 33
35 TEST(DefaultFileSystemTest, WriteReadRemove) 34 TEST(DefaultFileSystemTest, WriteReadRemove)
36 { 35 {
37 AdblockPlus::DefaultFileSystem fileSystem; 36 AdblockPlus::DefaultFileSystem fileSystem;
38 WriteString(fileSystem, "foo"); 37 WriteString(fileSystem, "foo");
39 std::stringstream output; 38 auto output = fileSystem.Read(testPath);
40 output << fileSystem.Read(testPath)->rdbuf();
41 fileSystem.Remove(testPath); 39 fileSystem.Remove(testPath);
42 ASSERT_EQ("foo", output.str()); 40 ASSERT_EQ("foo", std::string(output.cbegin(), output.cend()));
43 } 41 }
44 42
45 TEST(DefaultFileSystemTest, StatWorkingDirectory) 43 TEST(DefaultFileSystemTest, StatWorkingDirectory)
46 { 44 {
47 AdblockPlus::DefaultFileSystem fileSystem; 45 AdblockPlus::DefaultFileSystem fileSystem;
48 const AdblockPlus::FileSystem::StatResult result = fileSystem.Stat("."); 46 const AdblockPlus::FileSystem::StatResult result = fileSystem.Stat(".");
49 ASSERT_TRUE(result.exists); 47 ASSERT_TRUE(result.exists);
50 ASSERT_TRUE(result.isDirectory); 48 ASSERT_TRUE(result.isDirectory);
51 ASSERT_FALSE(result.isFile); 49 ASSERT_FALSE(result.isFile);
52 ASSERT_NE(0, result.lastModified); 50 ASSERT_NE(0, result.lastModified);
(...skipping 11 matching lines...) Expand all
64 const std::string newTestPath = testPath + "-new"; 62 const std::string newTestPath = testPath + "-new";
65 fileSystem.Move(testPath, newTestPath); 63 fileSystem.Move(testPath, newTestPath);
66 result = fileSystem.Stat(testPath); 64 result = fileSystem.Stat(testPath);
67 ASSERT_FALSE(result.exists); 65 ASSERT_FALSE(result.exists);
68 result = fileSystem.Stat(newTestPath); 66 result = fileSystem.Stat(newTestPath);
69 ASSERT_TRUE(result.exists); 67 ASSERT_TRUE(result.exists);
70 fileSystem.Remove(newTestPath); 68 fileSystem.Remove(newTestPath);
71 result = fileSystem.Stat(newTestPath); 69 result = fileSystem.Stat(newTestPath);
72 ASSERT_FALSE(result.exists); 70 ASSERT_FALSE(result.exists);
73 } 71 }
OLDNEW
« no previous file with comments | « test/BaseJsTest.h ('k') | test/FileSystemJsObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld