OLD | NEW |
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/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 const std::string& source); | 33 const std::string& source); |
34 | 34 |
35 // Returns true if there is/are pending load(s) matching the given file(s). | 35 // Returns true if there is/are pending load(s) matching the given file(s). |
36 bool HasOnePending(const SourceFile& f) const; | 36 bool HasOnePending(const SourceFile& f) const; |
37 bool HasTwoPending(const SourceFile& f1, const SourceFile& f2) const; | 37 bool HasTwoPending(const SourceFile& f1, const SourceFile& f2) const; |
38 | 38 |
39 void IssueAllPending(); | 39 void IssueAllPending(); |
40 | 40 |
41 private: | 41 private: |
42 struct CannedResult { | 42 struct CannedResult { |
43 scoped_ptr<InputFile> input_file; | 43 std::unique_ptr<InputFile> input_file; |
44 std::vector<Token> tokens; | 44 std::vector<Token> tokens; |
45 scoped_ptr<ParseNode> root; | 45 std::unique_ptr<ParseNode> root; |
46 }; | 46 }; |
47 | 47 |
48 bool AsyncLoadFile(const LocationRange& origin, | 48 bool AsyncLoadFile(const LocationRange& origin, |
49 const BuildSettings* build_settings, | 49 const BuildSettings* build_settings, |
50 const SourceFile& file_name, | 50 const SourceFile& file_name, |
51 const Callback& callback, | 51 const Callback& callback, |
52 Err* err) { | 52 Err* err) { |
53 pending_.push_back(std::make_pair(file_name, callback)); | 53 pending_.push_back(std::make_pair(file_name, callback)); |
54 return true; | 54 return true; |
55 } | 55 } |
56 | 56 |
57 typedef std::map<SourceFile, scoped_ptr<CannedResult> > CannedResponseMap; | 57 typedef std::map<SourceFile, std::unique_ptr<CannedResult>> CannedResponseMap; |
58 CannedResponseMap canned_responses_; | 58 CannedResponseMap canned_responses_; |
59 | 59 |
60 std::vector< std::pair<SourceFile, Callback> > pending_; | 60 std::vector< std::pair<SourceFile, Callback> > pending_; |
61 }; | 61 }; |
62 | 62 |
63 LoaderImpl::AsyncLoadFileCallback MockInputFileManager::GetCallback() { | 63 LoaderImpl::AsyncLoadFileCallback MockInputFileManager::GetCallback() { |
64 return base::Bind(&MockInputFileManager::AsyncLoadFile, | 64 return base::Bind(&MockInputFileManager::AsyncLoadFile, |
65 base::Unretained(this)); | 65 base::Unretained(this)); |
66 } | 66 } |
67 | 67 |
68 // Sets a given response for a given source file. | 68 // Sets a given response for a given source file. |
69 void MockInputFileManager::AddCannedResponse(const SourceFile& source_file, | 69 void MockInputFileManager::AddCannedResponse(const SourceFile& source_file, |
70 const std::string& source) { | 70 const std::string& source) { |
71 scoped_ptr<CannedResult> canned(new CannedResult); | 71 std::unique_ptr<CannedResult> canned(new CannedResult); |
72 canned->input_file.reset(new InputFile(source_file)); | 72 canned->input_file.reset(new InputFile(source_file)); |
73 canned->input_file->SetContents(source); | 73 canned->input_file->SetContents(source); |
74 | 74 |
75 // Tokenize. | 75 // Tokenize. |
76 Err err; | 76 Err err; |
77 canned->tokens = Tokenizer::Tokenize(canned->input_file.get(), &err); | 77 canned->tokens = Tokenizer::Tokenize(canned->input_file.get(), &err); |
78 EXPECT_FALSE(err.has_error()); | 78 EXPECT_FALSE(err.has_error()); |
79 | 79 |
80 // Parse. | 80 // Parse. |
81 canned->root = Parser::Parse(canned->tokens, &err); | 81 canned->root = Parser::Parse(canned->tokens, &err); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 loader->Load(third_file, LocationRange(), second_tc); | 177 loader->Load(third_file, LocationRange(), second_tc); |
178 EXPECT_TRUE(mock_ifm_.HasOnePending(build_config)); | 178 EXPECT_TRUE(mock_ifm_.HasOnePending(build_config)); |
179 | 179 |
180 // Running the build config file should make our third file pending. | 180 // Running the build config file should make our third file pending. |
181 mock_ifm_.IssueAllPending(); | 181 mock_ifm_.IssueAllPending(); |
182 scheduler_.main_loop()->RunUntilIdle(); | 182 scheduler_.main_loop()->RunUntilIdle(); |
183 EXPECT_TRUE(mock_ifm_.HasTwoPending(second_file, third_file)); | 183 EXPECT_TRUE(mock_ifm_.HasTwoPending(second_file, third_file)); |
184 | 184 |
185 EXPECT_FALSE(scheduler_.is_failed()); | 185 EXPECT_FALSE(scheduler_.is_failed()); |
186 } | 186 } |
OLD | NEW |