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

Side by Side Diff: test/FileSystemJsObject.cpp

Issue 29499577: Noissue - code style: use override for overridden methods of MockFileSystem (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created July 27, 2017, 8:48 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 | no next file » | 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
(...skipping 23 matching lines...) Expand all
34 mutable std::string statPath; 34 mutable std::string statPath;
35 bool statExists; 35 bool statExists;
36 bool statIsDirectory; 36 bool statIsDirectory;
37 bool statIsFile; 37 bool statIsFile;
38 int statLastModified; 38 int statLastModified;
39 39
40 MockFileSystem() : success(true) 40 MockFileSystem() : success(true)
41 { 41 {
42 } 42 }
43 43
44 void Read(const std::string& path, const ReadCallback& callback) const 44 void Read(const std::string& path, const ReadCallback& callback) const overr ide
45 { 45 {
46 if (!success) 46 if (!success)
47 { 47 {
48 callback(IOBuffer(), "Unable to read " + path); 48 callback(IOBuffer(), "Unable to read " + path);
49 return; 49 return;
50 } 50 }
51 callback(IOBuffer(contentToRead), ""); 51 callback(IOBuffer(contentToRead), "");
52 } 52 }
53 53
54 void Write(const std::string& path, const IOBuffer& data, 54 void Write(const std::string& path, const IOBuffer& data,
55 const Callback& callback) 55 const Callback& callback) override
56 { 56 {
57 if (!success) 57 if (!success)
58 { 58 {
59 callback("Unable to write to " + path); 59 callback("Unable to write to " + path);
60 return; 60 return;
61 } 61 }
62 lastWrittenPath = path; 62 lastWrittenPath = path;
63 63
64 lastWrittenContent = data; 64 lastWrittenContent = data;
65 callback(""); 65 callback("");
66 } 66 }
67 67
68 void Move(const std::string& fromPath, const std::string& toPath, 68 void Move(const std::string& fromPath, const std::string& toPath,
69 const Callback& callback) 69 const Callback& callback) override
70 { 70 {
71 if (!success) 71 if (!success)
72 { 72 {
73 callback("Unable to move " + fromPath + " to " + toPath); 73 callback("Unable to move " + fromPath + " to " + toPath);
74 return; 74 return;
75 } 75 }
76 movedFrom = fromPath; 76 movedFrom = fromPath;
77 movedTo = toPath; 77 movedTo = toPath;
78 callback(""); 78 callback("");
79 } 79 }
80 80
81 void Remove(const std::string& path, const Callback& callback) 81 void Remove(const std::string& path, const Callback& callback) override
82 { 82 {
83 if (!success) 83 if (!success)
84 { 84 {
85 callback("Unable to remove " + path); 85 callback("Unable to remove " + path);
86 return; 86 return;
87 } 87 }
88 removedPath = path; 88 removedPath = path;
89 callback(""); 89 callback("");
90 } 90 }
91 91
92 void Stat(const std::string& path, 92 void Stat(const std::string& path, const StatCallback& callback) const overr ide
93 const StatCallback& callback) const
94 { 93 {
95 StatResult result; 94 StatResult result;
96 std::string error; 95 std::string error;
97 if (!success) 96 if (!success)
98 error = "Unable to stat " + path; 97 error = "Unable to stat " + path;
99 else 98 else
100 { 99 {
101 statPath = path; 100 statPath = path;
102 result.exists = statExists; 101 result.exists = statExists;
103 result.isDirectory = statIsDirectory; 102 result.isDirectory = statIsDirectory;
104 result.isFile = statIsFile; 103 result.isFile = statIsFile;
105 result.lastModified = statLastModified; 104 result.lastModified = statLastModified;
106 } 105 }
107 callback(result, error); 106 callback(result, error);
108 } 107 }
109 108
110 std::string Resolve(const std::string& path) const 109 std::string Resolve(const std::string& path) const override
111 { 110 {
112 if (!success) 111 if (!success)
113 throw std::runtime_error("Unable to stat " + path); 112 throw std::runtime_error("Unable to stat " + path);
114 return path; 113 return path;
115 } 114 }
116 }; 115 };
117 116
118 void ReadFile(AdblockPlus::JsEnginePtr jsEngine, std::string& content, 117 void ReadFile(AdblockPlus::JsEnginePtr jsEngine, std::string& content,
119 std::string& error) 118 std::string& error)
120 { 119 {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 ASSERT_ANY_THROW(jsEngine->Evaluate("_fileSystem.stat('', '')")); 258 ASSERT_ANY_THROW(jsEngine->Evaluate("_fileSystem.stat('', '')"));
260 } 259 }
261 260
262 TEST_F(FileSystemJsObjectTest, StatError) 261 TEST_F(FileSystemJsObjectTest, StatError)
263 { 262 {
264 mockFileSystem->success = false; 263 mockFileSystem->success = false;
265 jsEngine->Evaluate("_fileSystem.stat('foo', function(r) {result = r})"); 264 jsEngine->Evaluate("_fileSystem.stat('foo', function(r) {result = r})");
266 AdblockPlus::Sleep(50); 265 AdblockPlus::Sleep(50);
267 ASSERT_FALSE(jsEngine->Evaluate("result.error").IsUndefined()); 266 ASSERT_FALSE(jsEngine->Evaluate("result.error").IsUndefined());
268 } 267 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld