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

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: rm comment 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 typedef std::map<SourceFile, scoped_ptr<CannedResult> > CannedResponseMap;
59 typedef std::map<SourceFile, linked_ptr<CannedResult> > CannedResponseMap;
60 CannedResponseMap canned_responses_; 58 CannedResponseMap canned_responses_;
61 59
62 std::vector< std::pair<SourceFile, Callback> > pending_; 60 std::vector< std::pair<SourceFile, Callback> > pending_;
63 }; 61 };
64 62
65 LoaderImpl::AsyncLoadFileCallback MockInputFileManager::GetCallback() { 63 LoaderImpl::AsyncLoadFileCallback MockInputFileManager::GetCallback() {
66 return base::Bind(&MockInputFileManager::AsyncLoadFile, 64 return base::Bind(&MockInputFileManager::AsyncLoadFile,
67 base::Unretained(this)); 65 base::Unretained(this));
68 } 66 }
69 67
70 // Sets a given response for a given source file. 68 // Sets a given response for a given source file.
71 void MockInputFileManager::AddCannedResponse(const SourceFile& source_file, 69 void MockInputFileManager::AddCannedResponse(const SourceFile& source_file,
72 const std::string& source) { 70 const std::string& source) {
73 CannedResult* canned = new CannedResult; 71 scoped_ptr<CannedResult> canned(new CannedResult);
74 canned->input_file.reset(new InputFile(source_file)); 72 canned->input_file.reset(new InputFile(source_file));
75 canned->input_file->SetContents(source); 73 canned->input_file->SetContents(source);
76 74
77 // Tokenize. 75 // Tokenize.
78 Err err; 76 Err err;
79 canned->tokens = Tokenizer::Tokenize(canned->input_file.get(), &err); 77 canned->tokens = Tokenizer::Tokenize(canned->input_file.get(), &err);
80 EXPECT_FALSE(err.has_error()); 78 EXPECT_FALSE(err.has_error());
81 79
82 // Parse. 80 // Parse.
83 canned->root = Parser::Parse(canned->tokens, &err).Pass(); 81 canned->root = Parser::Parse(canned->tokens, &err).Pass();
84 EXPECT_FALSE(err.has_error()); 82 EXPECT_FALSE(err.has_error());
85 83
86 canned_responses_[source_file] = linked_ptr<CannedResult>(canned); 84 canned_responses_[source_file] = std::move(canned);
87 } 85 }
88 86
89 bool MockInputFileManager::HasOnePending(const SourceFile& f) const { 87 bool MockInputFileManager::HasOnePending(const SourceFile& f) const {
90 return pending_.size() == 1u && pending_[0].first == f; 88 return pending_.size() == 1u && pending_[0].first == f;
91 } 89 }
92 90
93 bool MockInputFileManager::HasTwoPending(const SourceFile& f1, 91 bool MockInputFileManager::HasTwoPending(const SourceFile& f1,
94 const SourceFile& f2) const { 92 const SourceFile& f2) const {
95 if (pending_.size() != 2u) 93 if (pending_.size() != 2u)
96 return false; 94 return false;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 loader->Load(third_file, LocationRange(), second_tc); 177 loader->Load(third_file, LocationRange(), second_tc);
180 EXPECT_TRUE(mock_ifm_.HasOnePending(build_config)); 178 EXPECT_TRUE(mock_ifm_.HasOnePending(build_config));
181 179
182 // Running the build config file should make our third file pending. 180 // Running the build config file should make our third file pending.
183 mock_ifm_.IssueAllPending(); 181 mock_ifm_.IssueAllPending();
184 scheduler_.main_loop()->RunUntilIdle(); 182 scheduler_.main_loop()->RunUntilIdle();
185 EXPECT_TRUE(mock_ifm_.HasTwoPending(second_file, third_file)); 183 EXPECT_TRUE(mock_ifm_.HasTwoPending(second_file, third_file));
186 184
187 EXPECT_FALSE(scheduler_.is_failed()); 185 EXPECT_FALSE(scheduler_.is_failed());
188 } 186 }
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