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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 #include "tools/gn/builder.h" | 6 #include "tools/gn/builder.h" |
7 #include "tools/gn/loader.h" | 7 #include "tools/gn/loader.h" |
8 #include "tools/gn/target.h" | 8 #include "tools/gn/target.h" |
9 #include "tools/gn/test_with_scope.h" | 9 #include "tools/gn/test_with_scope.h" |
10 #include "tools/gn/toolchain.h" | 10 #include "tools/gn/toolchain.h" |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 class MockLoader : public Loader { | 14 class MockLoader : public Loader { |
15 public: | 15 public: |
16 MockLoader() { | 16 MockLoader() { |
17 } | 17 } |
18 | 18 |
19 // Loader implementation: | 19 // Loader implementation: |
20 virtual void Load(const SourceFile& file, | 20 void Load(const SourceFile& file, |
21 const LocationRange& origin, | 21 const LocationRange& origin, |
22 const Label& toolchain_name) override { | 22 const Label& toolchain_name) override { |
23 files_.push_back(file); | 23 files_.push_back(file); |
24 } | 24 } |
25 virtual void ToolchainLoaded(const Toolchain* toolchain) override { | 25 void ToolchainLoaded(const Toolchain* toolchain) override {} |
26 } | 26 Label GetDefaultToolchain() const override { return Label(); } |
27 virtual Label GetDefaultToolchain() const override { | 27 const Settings* GetToolchainSettings(const Label& label) const override { |
28 return Label(); | |
29 } | |
30 virtual const Settings* GetToolchainSettings( | |
31 const Label& label) const override { | |
32 return NULL; | 28 return NULL; |
33 } | 29 } |
34 | 30 |
35 bool HasLoadedNone() const { | 31 bool HasLoadedNone() const { |
36 return files_.empty(); | 32 return files_.empty(); |
37 } | 33 } |
38 | 34 |
39 // Returns true if two loads have been requested and they match the given | 35 // Returns true if two loads have been requested and they match the given |
40 // file. This will clear the records so it will be empty for the next call. | 36 // file. This will clear the records so it will be empty for the next call. |
41 bool HasLoadedTwo(const SourceFile& a, const SourceFile& b) { | 37 bool HasLoadedTwo(const SourceFile& a, const SourceFile& b) { |
42 if (files_.size() != 2u) { | 38 if (files_.size() != 2u) { |
43 files_.clear(); | 39 files_.clear(); |
44 return false; | 40 return false; |
45 } | 41 } |
46 | 42 |
47 bool match = ( | 43 bool match = ( |
48 (files_[0] == a && files_[1] == b) || | 44 (files_[0] == a && files_[1] == b) || |
49 (files_[0] == b && files_[1] == a)); | 45 (files_[0] == b && files_[1] == a)); |
50 files_.clear(); | 46 files_.clear(); |
51 return match; | 47 return match; |
52 } | 48 } |
53 | 49 |
54 private: | 50 private: |
55 virtual ~MockLoader() {} | 51 ~MockLoader() override {} |
56 | 52 |
57 std::vector<SourceFile> files_; | 53 std::vector<SourceFile> files_; |
58 }; | 54 }; |
59 | 55 |
60 class BuilderTest : public testing::Test { | 56 class BuilderTest : public testing::Test { |
61 public: | 57 public: |
62 BuilderTest() | 58 BuilderTest() |
63 : loader_(new MockLoader), | 59 : loader_(new MockLoader), |
64 builder_(new Builder(loader_.get())), | 60 builder_(new Builder(loader_.get())), |
65 settings_(&build_settings_, std::string()), | 61 settings_(&build_settings_, std::string()), |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 a->set_output_type(Target::EXECUTABLE); | 209 a->set_output_type(Target::EXECUTABLE); |
214 builder_->ItemDefined(scoped_ptr<Item>(a)); | 210 builder_->ItemDefined(scoped_ptr<Item>(a)); |
215 | 211 |
216 // A should have the generate bit set since it's in the default toolchain. | 212 // A should have the generate bit set since it's in the default toolchain. |
217 BuilderRecord* a_record = builder_->GetRecord(a_label); | 213 BuilderRecord* a_record = builder_->GetRecord(a_label); |
218 EXPECT_TRUE(a_record->should_generate()); | 214 EXPECT_TRUE(a_record->should_generate()); |
219 | 215 |
220 // It should have gotten pushed to B. | 216 // It should have gotten pushed to B. |
221 EXPECT_TRUE(b_record->should_generate()); | 217 EXPECT_TRUE(b_record->should_generate()); |
222 } | 218 } |
OLD | NEW |