Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: tools/gn/loader_unittest.cc

Issue 1480423003: tools/gn: replace usage of linked_ptr by using scoped_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
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 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <map> 5 #include <map>
6 #include <utility> 6 #include <utility>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/linked_ptr.h"
11 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
12 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
13 #include "tools/gn/build_settings.h" 12 #include "tools/gn/build_settings.h"
14 #include "tools/gn/err.h" 13 #include "tools/gn/err.h"
15 #include "tools/gn/loader.h" 14 #include "tools/gn/loader.h"
16 #include "tools/gn/parse_tree.h" 15 #include "tools/gn/parse_tree.h"
17 #include "tools/gn/parser.h" 16 #include "tools/gn/parser.h"
18 #include "tools/gn/scheduler.h" 17 #include "tools/gn/scheduler.h"
19 #include "tools/gn/tokenizer.h" 18 #include "tools/gn/tokenizer.h"
20 19
(...skipping 27 matching lines...) Expand all
48 47
49 bool AsyncLoadFile(const LocationRange& origin, 48 bool AsyncLoadFile(const LocationRange& origin,
50 const BuildSettings* build_settings, 49 const BuildSettings* build_settings,
51 const SourceFile& file_name, 50 const SourceFile& file_name,
52 const Callback& callback, 51 const Callback& callback,
53 Err* err) { 52 Err* err) {
54 pending_.push_back(std::make_pair(file_name, callback)); 53 pending_.push_back(std::make_pair(file_name, callback));
55 return true; 54 return true;
56 } 55 }
57 56
58 // Owning pointers. 57 // Owning pointers.
brettw 2015/12/01 20:28:49 Can you delete this comment now?
tfarina 2015/12/01 20:40:25 Done.
59 typedef std::map<SourceFile, linked_ptr<CannedResult> > CannedResponseMap; 58 typedef std::map<SourceFile, scoped_ptr<CannedResult> > CannedResponseMap;
60 CannedResponseMap canned_responses_; 59 CannedResponseMap canned_responses_;
61 60
62 std::vector< std::pair<SourceFile, Callback> > pending_; 61 std::vector< std::pair<SourceFile, Callback> > pending_;
63 }; 62 };
64 63
65 LoaderImpl::AsyncLoadFileCallback MockInputFileManager::GetCallback() { 64 LoaderImpl::AsyncLoadFileCallback MockInputFileManager::GetCallback() {
66 return base::Bind(&MockInputFileManager::AsyncLoadFile, 65 return base::Bind(&MockInputFileManager::AsyncLoadFile,
67 base::Unretained(this)); 66 base::Unretained(this));
68 } 67 }
69 68
70 // Sets a given response for a given source file. 69 // Sets a given response for a given source file.
71 void MockInputFileManager::AddCannedResponse(const SourceFile& source_file, 70 void MockInputFileManager::AddCannedResponse(const SourceFile& source_file,
72 const std::string& source) { 71 const std::string& source) {
73 CannedResult* canned = new CannedResult; 72 scoped_ptr<CannedResult> canned(new CannedResult);
74 canned->input_file.reset(new InputFile(source_file)); 73 canned->input_file.reset(new InputFile(source_file));
75 canned->input_file->SetContents(source); 74 canned->input_file->SetContents(source);
76 75
77 // Tokenize. 76 // Tokenize.
78 Err err; 77 Err err;
79 canned->tokens = Tokenizer::Tokenize(canned->input_file.get(), &err); 78 canned->tokens = Tokenizer::Tokenize(canned->input_file.get(), &err);
80 EXPECT_FALSE(err.has_error()); 79 EXPECT_FALSE(err.has_error());
81 80
82 // Parse. 81 // Parse.
83 canned->root = Parser::Parse(canned->tokens, &err).Pass(); 82 canned->root = Parser::Parse(canned->tokens, &err).Pass();
84 EXPECT_FALSE(err.has_error()); 83 EXPECT_FALSE(err.has_error());
85 84
86 canned_responses_[source_file] = linked_ptr<CannedResult>(canned); 85 canned_responses_[source_file] = std::move(canned);
87 } 86 }
88 87
89 bool MockInputFileManager::HasOnePending(const SourceFile& f) const { 88 bool MockInputFileManager::HasOnePending(const SourceFile& f) const {
90 return pending_.size() == 1u && pending_[0].first == f; 89 return pending_.size() == 1u && pending_[0].first == f;
91 } 90 }
92 91
93 bool MockInputFileManager::HasTwoPending(const SourceFile& f1, 92 bool MockInputFileManager::HasTwoPending(const SourceFile& f1,
94 const SourceFile& f2) const { 93 const SourceFile& f2) const {
95 if (pending_.size() != 2u) 94 if (pending_.size() != 2u)
96 return false; 95 return false;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 loader->Load(third_file, LocationRange(), second_tc); 178 loader->Load(third_file, LocationRange(), second_tc);
180 EXPECT_TRUE(mock_ifm_.HasOnePending(build_config)); 179 EXPECT_TRUE(mock_ifm_.HasOnePending(build_config));
181 180
182 // Running the build config file should make our third file pending. 181 // Running the build config file should make our third file pending.
183 mock_ifm_.IssueAllPending(); 182 mock_ifm_.IssueAllPending();
184 scheduler_.main_loop()->RunUntilIdle(); 183 scheduler_.main_loop()->RunUntilIdle();
185 EXPECT_TRUE(mock_ifm_.HasTwoPending(second_file, third_file)); 184 EXPECT_TRUE(mock_ifm_.HasTwoPending(second_file, third_file));
186 185
187 EXPECT_FALSE(scheduler_.is_failed()); 186 EXPECT_FALSE(scheduler_.is_failed());
188 } 187 }
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 408576698