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