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

Side by Side Diff: test/DefaultFileSystem.cpp

Issue 29449592: Issue 5183 - Provide async interface for FileSystem (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Updated implementation. Created June 2, 2017, 3:49 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
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 #include "BaseJsTest.h"
23
24 using AdblockPlus::IFileSystem;
25
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 auto input = std::make_shared<std::stringstream>();
37 *input << content;
38 fileSystem->Write(testPath, input, [&sync](const std::string& error)
39 {
40 ASSERT_TRUE(error.empty());
41
42 sync.Set();
43 });
44
45 sync.Wait();
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::string&& content, const st d::string& error)
40 output << fileSystem.Read(testPath)->rdbuf(); 55 {
41 fileSystem.Remove(testPath); 56 ASSERT_TRUE(error.empty());
42 ASSERT_EQ("foo", output.str()); 57 ASSERT_EQ("foo", content);
58
59 fileSystem->Remove(testPath, [&sync](const std::string& error)
60 {
61 ASSERT_TRUE(error.empty());
62 sync.Set();
63 });
64 });
65
66 sync.Wait();
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 ASSERT_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 sync.Wait();
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 ASSERT_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 ASSERT_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 ASSERT_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 ASSERT_TRUE(error.empty());
112 ASSERT_TRUE(result.exists);
113 fileSystem->Remove(newTestPath, [fileSystem, &sync, newTestPath](con st std::string& error)
114 {
115 ASSERT_TRUE(error.empty());
116 fileSystem->Stat(newTestPath, [fileSystem, &sync, newTestPath](con st IFileSystem::StatResult& result, const std::string& error)
117 {
118 ASSERT_TRUE(error.empty());
119 ASSERT_FALSE(result.exists);
120 sync.Set();
121 });
122 });
123 });
124 });
125 });
126 });
127
128 sync.Wait();
73 } 129 }
OLDNEW
« lib/init.js ('K') | « test/BaseJsTest.cpp ('k') | test/FileSystemJsObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld