| 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/build_settings.h" | 6 #include "tools/gn/build_settings.h" |
| 7 #include "tools/gn/config.h" | 7 #include "tools/gn/config.h" |
| 8 #include "tools/gn/settings.h" | 8 #include "tools/gn/settings.h" |
| 9 #include "tools/gn/target.h" | 9 #include "tools/gn/target.h" |
| 10 #include "tools/gn/toolchain.h" | 10 #include "tools/gn/toolchain.h" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 class TargetTest : public testing::Test { | 14 class TargetTest : public testing::Test { |
| 15 public: | 15 public: |
| 16 TargetTest() | 16 TargetTest() |
| 17 : build_settings_(), | 17 : build_settings_(), |
| 18 settings_(&build_settings_, std::string()), | 18 toolchain_(Label(SourceDir("//tc/"), "tc")), |
| 19 toolchain_(&settings_, Label(SourceDir("//tc/"), "tc")) { | 19 settings_(&build_settings_, &toolchain_, std::string()) { |
| 20 settings_.set_toolchain_label(toolchain_.label()); | |
| 21 } | 20 } |
| 22 virtual ~TargetTest() { | 21 virtual ~TargetTest() { |
| 23 } | 22 } |
| 24 | 23 |
| 25 protected: | 24 protected: |
| 26 BuildSettings build_settings_; | 25 BuildSettings build_settings_; |
| 26 Toolchain toolchain_; |
| 27 Settings settings_; | 27 Settings settings_; |
| 28 Toolchain toolchain_; | |
| 29 }; | 28 }; |
| 30 | 29 |
| 31 } // namespace | 30 } // namespace |
| 32 | 31 |
| 33 // Tests that depending on a group is like depending directly on the group's | 32 // Tests that depending on a group is like depending directly on the group's |
| 34 // deps. | 33 // deps. |
| 35 TEST_F(TargetTest, GroupDeps) { | 34 TEST_F(TargetTest, GroupDeps) { |
| 36 // Two low-level targets. | 35 // Two low-level targets. |
| 37 Target x(&settings_, Label(SourceDir("//component/"), "x")); | 36 Target x(&settings_, Label(SourceDir("//component/"), "x")); |
| 38 Target y(&settings_, Label(SourceDir("//component/"), "y")); | 37 Target y(&settings_, Label(SourceDir("//component/"), "y")); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 Target a(&settings_, Label(SourceDir("//foo/"), "a")); | 115 Target a(&settings_, Label(SourceDir("//foo/"), "a")); |
| 117 a.set_output_type(Target::EXECUTABLE); | 116 a.set_output_type(Target::EXECUTABLE); |
| 118 Target b(&settings_, Label(SourceDir("//foo/"), "b")); | 117 Target b(&settings_, Label(SourceDir("//foo/"), "b")); |
| 119 b.set_output_type(Target::STATIC_LIBRARY); | 118 b.set_output_type(Target::STATIC_LIBRARY); |
| 120 Target c(&settings_, Label(SourceDir("//foo/"), "c")); | 119 Target c(&settings_, Label(SourceDir("//foo/"), "c")); |
| 121 c.set_output_type(Target::STATIC_LIBRARY); | 120 c.set_output_type(Target::STATIC_LIBRARY); |
| 122 a.deps().push_back(LabelTargetPair(&b)); | 121 a.deps().push_back(LabelTargetPair(&b)); |
| 123 b.deps().push_back(LabelTargetPair(&c)); | 122 b.deps().push_back(LabelTargetPair(&c)); |
| 124 | 123 |
| 125 // Normal non-inherited config. | 124 // Normal non-inherited config. |
| 126 Config config(&settings_, Label(SourceDir("//foo/"), "config")); | 125 Config config(Label(SourceDir("//foo/"), "config")); |
| 127 c.configs().push_back(LabelConfigPair(&config)); | 126 c.configs().push_back(LabelConfigPair(&config)); |
| 128 | 127 |
| 129 // All dependent config. | 128 // All dependent config. |
| 130 Config all(&settings_, Label(SourceDir("//foo/"), "all")); | 129 Config all(Label(SourceDir("//foo/"), "all")); |
| 131 c.all_dependent_configs().push_back(LabelConfigPair(&all)); | 130 c.all_dependent_configs().push_back(LabelConfigPair(&all)); |
| 132 | 131 |
| 133 // Direct dependent config. | 132 // Direct dependent config. |
| 134 Config direct(&settings_, Label(SourceDir("//foo/"), "direct")); | 133 Config direct(Label(SourceDir("//foo/"), "direct")); |
| 135 c.direct_dependent_configs().push_back(LabelConfigPair(&direct)); | 134 c.direct_dependent_configs().push_back(LabelConfigPair(&direct)); |
| 136 | 135 |
| 137 c.OnResolved(); | 136 c.OnResolved(); |
| 138 b.OnResolved(); | 137 b.OnResolved(); |
| 139 a.OnResolved(); | 138 a.OnResolved(); |
| 140 | 139 |
| 141 // B should have gotten both dependent configs from C. | 140 // B should have gotten both dependent configs from C. |
| 142 ASSERT_EQ(2u, b.configs().size()); | 141 ASSERT_EQ(2u, b.configs().size()); |
| 143 EXPECT_EQ(&all, b.configs()[0].ptr); | 142 EXPECT_EQ(&all, b.configs()[0].ptr); |
| 144 EXPECT_EQ(&direct, b.configs()[1].ptr); | 143 EXPECT_EQ(&direct, b.configs()[1].ptr); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 162 b_fwd.OnResolved(); | 161 b_fwd.OnResolved(); |
| 163 a_fwd.OnResolved(); | 162 a_fwd.OnResolved(); |
| 164 | 163 |
| 165 // A_fwd should now have both configs. | 164 // A_fwd should now have both configs. |
| 166 ASSERT_EQ(2u, a_fwd.configs().size()); | 165 ASSERT_EQ(2u, a_fwd.configs().size()); |
| 167 EXPECT_EQ(&all, a_fwd.configs()[0].ptr); | 166 EXPECT_EQ(&all, a_fwd.configs()[0].ptr); |
| 168 EXPECT_EQ(&direct, a_fwd.configs()[1].ptr); | 167 EXPECT_EQ(&direct, a_fwd.configs()[1].ptr); |
| 169 ASSERT_EQ(1u, a_fwd.all_dependent_configs().size()); | 168 ASSERT_EQ(1u, a_fwd.all_dependent_configs().size()); |
| 170 EXPECT_EQ(&all, a_fwd.all_dependent_configs()[0].ptr); | 169 EXPECT_EQ(&all, a_fwd.all_dependent_configs()[0].ptr); |
| 171 } | 170 } |
| OLD | NEW |