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

Side by Side Diff: test/FileSystemJsObject.cpp

Issue 5163715573841920: Issue 768 - Switch from TR1 to C++11 (Closed)
Patch Set: address comments Created Aug. 6, 2015, 7:34 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 | « test/DefaultFileSystem.cpp ('k') | 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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 std::tr1::shared_ptr<std::istream> Read(const std::string& path) const 44 std::shared_ptr<std::istream> Read(const std::string& path) const
45 { 45 {
46 if (!success) 46 if (!success)
47 throw std::runtime_error("Unable to read " + path); 47 throw std::runtime_error("Unable to read " + path);
48 std::stringstream* const stream = new std::stringstream; 48 std::stringstream* const stream = new std::stringstream;
49 *stream << contentToRead; 49 *stream << contentToRead;
50 return std::tr1::shared_ptr<std::istream>(stream); 50 return std::shared_ptr<std::istream>(stream);
51 } 51 }
52 52
53 void Write(const std::string& path, std::tr1::shared_ptr<std::istream> data) 53 void Write(const std::string& path, std::shared_ptr<std::istream> data)
54 { 54 {
55 if (!success) 55 if (!success)
56 throw std::runtime_error("Unable to write to " + path); 56 throw std::runtime_error("Unable to write to " + path);
57 lastWrittenPath = path; 57 lastWrittenPath = path;
58 58
59 std::stringstream content; 59 std::stringstream content;
60 content << data->rdbuf(); 60 content << data->rdbuf();
61 lastWrittenContent = content.str(); 61 lastWrittenContent = content.str();
62 } 62 }
63 63
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 100
101 void ReadFile(AdblockPlus::JsEnginePtr jsEngine, std::string& content, 101 void ReadFile(AdblockPlus::JsEnginePtr jsEngine, std::string& content,
102 std::string& error) 102 std::string& error)
103 { 103 {
104 jsEngine->Evaluate("_fileSystem.read('', function(r) {result = r})"); 104 jsEngine->Evaluate("_fileSystem.read('', function(r) {result = r})");
105 AdblockPlus::Sleep(50); 105 AdblockPlus::Sleep(50);
106 content = jsEngine->Evaluate("result.content")->AsString(); 106 content = jsEngine->Evaluate("result.content")->AsString();
107 error = jsEngine->Evaluate("result.error")->AsString(); 107 error = jsEngine->Evaluate("result.error")->AsString();
108 } 108 }
109 109
110 typedef std::tr1::shared_ptr<MockFileSystem> MockFileSystemPtr; 110 typedef std::shared_ptr<MockFileSystem> MockFileSystemPtr;
111 111
112 class FileSystemJsObjectTest : public BaseJsTest 112 class FileSystemJsObjectTest : public BaseJsTest
113 { 113 {
114 protected: 114 protected:
115 MockFileSystemPtr mockFileSystem; 115 MockFileSystemPtr mockFileSystem;
116 116
117 void SetUp() 117 void SetUp()
118 { 118 {
119 BaseJsTest::SetUp(); 119 BaseJsTest::SetUp();
120 mockFileSystem = MockFileSystemPtr(new MockFileSystem); 120 mockFileSystem = MockFileSystemPtr(new MockFileSystem);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 ASSERT_ANY_THROW(jsEngine->Evaluate("_fileSystem.stat('', '')")); 239 ASSERT_ANY_THROW(jsEngine->Evaluate("_fileSystem.stat('', '')"));
240 } 240 }
241 241
242 TEST_F(FileSystemJsObjectTest, StatError) 242 TEST_F(FileSystemJsObjectTest, StatError)
243 { 243 {
244 mockFileSystem->success = false; 244 mockFileSystem->success = false;
245 jsEngine->Evaluate("_fileSystem.stat('foo', function(r) {result = r})"); 245 jsEngine->Evaluate("_fileSystem.stat('foo', function(r) {result = r})");
246 AdblockPlus::Sleep(50); 246 AdblockPlus::Sleep(50);
247 ASSERT_NE("", jsEngine->Evaluate("result.error")->AsString()); 247 ASSERT_NE("", jsEngine->Evaluate("result.error")->AsString());
248 } 248 }
OLDNEW
« no previous file with comments | « test/DefaultFileSystem.cpp ('k') | test/FilterEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld