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

Delta Between Two Patch Sets: test/DefaultFileSystem.cpp

Issue 29449592: Issue 5183 - Provide async interface for FileSystem (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Left Patch Set: Remove a #include Utils.h from test. Created June 2, 2017, 7:38 p.m.
Right Patch Set: Rebase on master. Last changes. Created July 7, 2017, 1:36 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « test/BaseJsTest.cpp ('k') | test/FileSystemJsObject.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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" 22 #include "BaseJsTest.h"
23 23
24 using AdblockPlus::IFileSystem; 24 using AdblockPlus::IFileSystem;
25 25 using AdblockPlus::Sync;
26 26
27 namespace 27 namespace
28 { 28 {
29 const std::string testPath = "libadblockplus-t\xc3\xa4st-file"; 29 const std::string testPath = "libadblockplus-t\xc3\xa4st-file";
30 30
31 void WriteString(const AdblockPlus::FileSystemPtr& fileSystem, 31 void WriteString(const AdblockPlus::FileSystemPtr& fileSystem,
32 const std::string& content) 32 const std::string& content)
33 { 33 {
34 Sync sync; 34 Sync sync;
35 35
36 auto input = std::make_shared<std::stringstream>(); 36 fileSystem->Write(testPath,
37 *input << content; 37 IFileSystem::IOBuffer(content.cbegin(), content.cend()),
38 fileSystem->Write(testPath, input, [&sync](const std::string& error) 38 [&sync](const std::string& error)
39 { 39 {
40 ASSERT_TRUE(error.empty()); 40 EXPECT_TRUE(error.empty());
sergei 2017/06/16 15:05:56 What about EXPECT_TRUE when it's acceptable here a
hub 2017/06/16 21:52:55 Done.
41 41
42 sync.Set(); 42 sync.Set();
43 }); 43 });
44 44
45 sync.Wait(); 45 sync.WaitFor();
46 } 46 }
47 } 47 }
48 48
49 TEST(DefaultFileSystemTest, WriteReadRemove) 49 TEST(DefaultFileSystemTest, WriteReadRemove)
50 { 50 {
51 Sync sync; 51 Sync sync;
52 AdblockPlus::FileSystemPtr fileSystem = AdblockPlus::CreateDefaultFileSystem() ; 52 AdblockPlus::FileSystemPtr fileSystem = AdblockPlus::CreateDefaultFileSystem() ;
53 WriteString(fileSystem, "foo"); 53 WriteString(fileSystem, "foo");
54 fileSystem->Read(testPath, [fileSystem, &sync](std::string&& content, const st d::string& error) 54 fileSystem->Read(testPath,
55 { 55 [fileSystem, &sync](IFileSystem::IOBuffer&& content, const std::string& erro r)
56 ASSERT_TRUE(error.empty()); 56 {
57 ASSERT_EQ("foo", content); 57 EXPECT_TRUE(error.empty());
58 EXPECT_EQ("foo", std::string(content.cbegin(), content.cend()));
58 59
59 fileSystem->Remove(testPath, [&sync](const std::string& error) 60 fileSystem->Remove(testPath, [&sync](const std::string& error)
60 { 61 {
61 ASSERT_TRUE(error.empty()); 62 EXPECT_TRUE(error.empty());
62 sync.Set(); 63 sync.Set();
63 }); 64 });
64 }); 65 });
65 66
66 sync.Wait(); 67 EXPECT_TRUE(sync.WaitFor());
67 } 68 }
68 69
69 TEST(DefaultFileSystemTest, StatWorkingDirectory) 70 TEST(DefaultFileSystemTest, StatWorkingDirectory)
70 { 71 {
71 Sync sync; 72 Sync sync;
72 AdblockPlus::FileSystemPtr fileSystem = AdblockPlus::CreateDefaultFileSystem() ; 73 AdblockPlus::FileSystemPtr fileSystem = AdblockPlus::CreateDefaultFileSystem() ;
73 fileSystem->Stat(".", 74 fileSystem->Stat(".",
74 [fileSystem, &sync](const IFileSystem::StatResult result, const std::string& error) 75 [fileSystem, &sync](const IFileSystem::StatResult result, const std::string& error)
75 { 76 {
76 ASSERT_TRUE(error.empty()); 77 EXPECT_TRUE(error.empty());
77 ASSERT_TRUE(result.exists); 78 ASSERT_TRUE(result.exists);
78 ASSERT_TRUE(result.isDirectory); 79 ASSERT_TRUE(result.isDirectory);
79 ASSERT_FALSE(result.isFile); 80 ASSERT_FALSE(result.isFile);
80 ASSERT_NE(0, result.lastModified); 81 ASSERT_NE(0, result.lastModified);
81 sync.Set(); 82 sync.Set();
82 }); 83 });
83 84
84 sync.Wait(); 85 EXPECT_TRUE(sync.WaitFor());
85 } 86 }
86 87
87 TEST(DefaultFileSystemTest, WriteMoveStatRemove) 88 TEST(DefaultFileSystemTest, WriteMoveStatRemove)
88 { 89 {
89 Sync sync; 90 Sync sync;
90 AdblockPlus::FileSystemPtr fileSystem = AdblockPlus::CreateDefaultFileSystem() ; 91 AdblockPlus::FileSystemPtr fileSystem = AdblockPlus::CreateDefaultFileSystem() ;
91 WriteString(fileSystem, "foo"); 92 WriteString(fileSystem, "foo");
92 93
93 fileSystem->Stat(testPath, 94 fileSystem->Stat(testPath,
94 [fileSystem, &sync](const IFileSystem::StatResult& result, const std::string & error) 95 [fileSystem, &sync](const IFileSystem::StatResult& result, const std::string & error)
95 { 96 {
96 ASSERT_TRUE(error.empty()); 97 EXPECT_TRUE(error.empty());
97 ASSERT_TRUE(result.exists); 98 ASSERT_TRUE(result.exists);
98 ASSERT_TRUE(result.isFile); 99 ASSERT_TRUE(result.isFile);
99 ASSERT_FALSE(result.isDirectory); 100 ASSERT_FALSE(result.isDirectory);
100 ASSERT_NE(0, result.lastModified); 101 ASSERT_NE(0, result.lastModified);
101 const std::string newTestPath = testPath + "-new"; 102 const std::string newTestPath = testPath + "-new";
102 fileSystem->Move(testPath, newTestPath, [fileSystem, &sync, newTestPath](c onst std::string& error) 103 fileSystem->Move(testPath, newTestPath, [fileSystem, &sync, newTestPath](c onst std::string& error)
103 { 104 {
104 ASSERT_TRUE(error.empty()); 105 EXPECT_TRUE(error.empty());
105 fileSystem->Stat(testPath, [fileSystem, &sync, newTestPath](const IFileS ystem::StatResult& result, const std::string& error) 106 fileSystem->Stat(testPath, [fileSystem, &sync, newTestPath](const IFileS ystem::StatResult& result, const std::string& error)
106 { 107 {
107 ASSERT_TRUE(error.empty()); 108 EXPECT_TRUE(error.empty());
108 ASSERT_FALSE(result.exists); 109 ASSERT_FALSE(result.exists);
109 fileSystem->Stat(newTestPath, [fileSystem, &sync, newTestPath](const I FileSystem::StatResult& result, const std::string& error) 110 fileSystem->Stat(newTestPath, [fileSystem, &sync, newTestPath](const I FileSystem::StatResult& result, const std::string& error)
110 { 111 {
111 ASSERT_TRUE(error.empty()); 112 EXPECT_TRUE(error.empty());
112 ASSERT_TRUE(result.exists); 113 ASSERT_TRUE(result.exists);
113 fileSystem->Remove(newTestPath, [fileSystem, &sync, newTestPath](con st std::string& error) 114 fileSystem->Remove(newTestPath, [fileSystem, &sync, newTestPath](con st std::string& error)
114 { 115 {
115 ASSERT_TRUE(error.empty()); 116 EXPECT_TRUE(error.empty());
116 fileSystem->Stat(newTestPath, [fileSystem, &sync, newTestPath](con st IFileSystem::StatResult& result, const std::string& error) 117 fileSystem->Stat(newTestPath, [fileSystem, &sync, newTestPath](con st IFileSystem::StatResult& result, const std::string& error)
117 { 118 {
118 ASSERT_TRUE(error.empty()); 119 EXPECT_TRUE(error.empty());
119 ASSERT_FALSE(result.exists); 120 ASSERT_FALSE(result.exists);
120 sync.Set(); 121 sync.Set();
121 }); 122 });
sergei 2017/06/16 15:05:55 OK :)
hub 2017/06/16 21:52:55 I know, right?
122 }); 123 });
123 }); 124 });
124 }); 125 });
125 }); 126 });
126 }); 127 });
127 128
128 sync.Wait(); 129 EXPECT_TRUE(sync.WaitFor());
129 } 130 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld