OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "testing/gtest/include/gtest/gtest.h" |
| 6 #include "tools/gn/config.h" |
| 7 #include "tools/gn/test_with_scope.h" |
| 8 |
| 9 // Tests that the "resolved" values are the same as "own" values when there |
| 10 // are no subconfigs. |
| 11 TEST(Config, ResolvedNoSub) { |
| 12 TestWithScope setup; |
| 13 Err err; |
| 14 |
| 15 Config config(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
| 16 config.own_values().defines().push_back("FOO"); |
| 17 ASSERT_TRUE(config.OnResolved(&err)); |
| 18 |
| 19 // The resolved values should be the same as the value we put in to |
| 20 // own_values(). |
| 21 ASSERT_EQ(1u, config.resolved_values().defines().size()); |
| 22 EXPECT_EQ("FOO", config.resolved_values().defines()[0]); |
| 23 |
| 24 // As an optimization, the string should actually refer to the original. This |
| 25 // isn't required to pass for semantic correctness, though. |
| 26 EXPECT_TRUE(&config.own_values() == &config.resolved_values()); |
| 27 } |
| 28 |
| 29 // Tests that subconfigs are resolved in the correct order. |
| 30 TEST(Config, ResolvedSub) { |
| 31 TestWithScope setup; |
| 32 Err err; |
| 33 |
| 34 Config sub1(setup.settings(), Label(SourceDir("//foo/"), "1")); |
| 35 sub1.own_values().defines().push_back("ONE"); |
| 36 ASSERT_TRUE(sub1.OnResolved(&err)); |
| 37 |
| 38 Config sub2(setup.settings(), Label(SourceDir("//foo/"), "2")); |
| 39 sub2.own_values().defines().push_back("TWO"); |
| 40 ASSERT_TRUE(sub2.OnResolved(&err)); |
| 41 |
| 42 Config config(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
| 43 config.own_values().defines().push_back("FOO"); |
| 44 config.configs().push_back(LabelConfigPair(&sub1)); |
| 45 config.configs().push_back(LabelConfigPair(&sub2)); |
| 46 ASSERT_TRUE(config.OnResolved(&err)); |
| 47 |
| 48 // The resolved values should be the same as the value we put in to |
| 49 // own_values(). |
| 50 ASSERT_EQ(3u, config.resolved_values().defines().size()); |
| 51 EXPECT_EQ("FOO", config.resolved_values().defines()[0]); |
| 52 EXPECT_EQ("ONE", config.resolved_values().defines()[1]); |
| 53 EXPECT_EQ("TWO", config.resolved_values().defines()[2]); |
| 54 |
| 55 // The "own" values should be unchanged. |
| 56 ASSERT_EQ(1u, config.own_values().defines().size()); |
| 57 EXPECT_EQ("FOO", config.own_values().defines()[0]); |
| 58 } |
| 59 |
| 60 // Tests that subconfigs of subconfigs are resolved properly. |
| 61 TEST(Config, SubSub) { |
| 62 TestWithScope setup; |
| 63 Err err; |
| 64 |
| 65 // Set up first -> middle -> last configs. |
| 66 Config last(setup.settings(), Label(SourceDir("//foo/"), "last")); |
| 67 last.own_values().defines().push_back("LAST"); |
| 68 ASSERT_TRUE(last.OnResolved(&err)); |
| 69 |
| 70 Config middle(setup.settings(), Label(SourceDir("//foo/"), "middle")); |
| 71 middle.own_values().defines().push_back("MIDDLE"); |
| 72 middle.configs().push_back(LabelConfigPair(&last)); |
| 73 ASSERT_TRUE(middle.OnResolved(&err)); |
| 74 |
| 75 Config first(setup.settings(), Label(SourceDir("//foo/"), "first")); |
| 76 first.own_values().defines().push_back("FIRST"); |
| 77 first.configs().push_back(LabelConfigPair(&middle)); |
| 78 ASSERT_TRUE(first.OnResolved(&err)); |
| 79 |
| 80 // Check final resolved defines on "first". |
| 81 ASSERT_EQ(3u, first.resolved_values().defines().size()); |
| 82 EXPECT_EQ("FIRST", first.resolved_values().defines()[0]); |
| 83 EXPECT_EQ("MIDDLE", first.resolved_values().defines()[1]); |
| 84 EXPECT_EQ("LAST", first.resolved_values().defines()[2]); |
| 85 } |
OLD | NEW |