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

Side by Side Diff: test/BaseJsTest.h

Issue 29535562: Issue 5508 - implement InMemoryFS for tests (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created Sept. 4, 2017, 9:23 a.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 | « no previous file | test/FilterEngine.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-present eyeo GmbH 3 * Copyright (C) 2006-present 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
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 { 201 {
202 result.exists = true; 202 result.exists = true;
203 } 203 }
204 callback(result, ""); 204 callback(result, "");
205 }); 205 });
206 } 206 }
207 public: 207 public:
208 Scheduler scheduler; 208 Scheduler scheduler;
209 }; 209 };
210 210
211 class InMemoryFileSystem : public LazyFileSystem
212 {
213 std::map<std::string, IOBuffer> files;
214 public:
215 using LazyFileSystem::LazyFileSystem;
216 void Read(const std::string& fileName, const ReadCallback& callback) const ove rride
217 {
218 scheduler([this, fileName, callback]()
219 {
220 auto ii_file = files.find(fileName);
221 if (ii_file == files.end())
222 {
223 callback(IOBuffer(), "File not found, " + fileName);
224 return;
225 }
226 callback(IOBuffer(ii_file->second), "");
227 });
228 }
229
230 void Write(const std::string& fileName, const IOBuffer& data,
231 const Callback& callback) override
232 {
233 scheduler([this, fileName, data, callback]()
234 {
235 files[fileName] = data;
236 callback("");
237 });
238 }
239
240 void Move(const std::string& fromFileName, const std::string& toFileName,
241 const Callback& callback) override
242 {
243 scheduler([this, fromFileName, toFileName, callback]()
244 {
245 auto ii_fromFile = files.find(fromFileName);
246 if (ii_fromFile == files.end())
247 {
248 callback("File (from) not found, " + fromFileName);
249 return;
250 }
251 Write(toFileName, ii_fromFile->second, [this, fromFileName, callback](cons t std::string& error)
252 {
253 if (!error.empty())
254 {
255 callback(error);
256 return;
257 }
258 Remove(fromFileName, callback);
259 });
260 });
261 }
262
263 void Remove(const std::string& fileName, const Callback& callback) override
264 {
265 scheduler([this, fileName, callback]()
266 {
267 files.erase(fileName);
268 callback("");
269 });
270 }
271
272 void Stat(const std::string& fileName, const StatCallback& callback) const ove rride
273 {
274 scheduler([this, fileName, callback]()
275 {
276 StatResult result;
277 result.exists = files.find(fileName) != files.end();
278 callback(result, "");
279 });
280 }
281 };
282
211 AdblockPlus::FilterEngine& CreateFilterEngine(LazyFileSystem& fileSystem, 283 AdblockPlus::FilterEngine& CreateFilterEngine(LazyFileSystem& fileSystem,
212 AdblockPlus::Platform& platform, 284 AdblockPlus::Platform& platform,
213 const AdblockPlus::FilterEngine::CreationParameters& creationParams = AdblockP lus::FilterEngine::CreationParameters()); 285 const AdblockPlus::FilterEngine::CreationParameters& creationParams = AdblockP lus::FilterEngine::CreationParameters());
214 286
215 class NoopWebRequest : public AdblockPlus::IWebRequest 287 class NoopWebRequest : public AdblockPlus::IWebRequest
216 { 288 {
217 public: 289 public:
218 void GET(const std::string& url, const AdblockPlus::HeaderList& requestHeaders , const GetCallback& callback) override 290 void GET(const std::string& url, const AdblockPlus::HeaderList& requestHeaders , const GetCallback& callback) override
219 { 291 {
220 } 292 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 } 341 }
270 342
271 void TearDown() override 343 void TearDown() override
272 { 344 {
273 if (platform) 345 if (platform)
274 platform.reset(); 346 platform.reset();
275 } 347 }
276 }; 348 };
277 349
278 #endif 350 #endif
OLDNEW
« no previous file with comments | « no previous file | test/FilterEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld