Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: tools/gn/inherited_libraries_unittest.cc

Issue 2940873002: Implement tracking of BUILD.gn files used to define target, toolchain or (Closed)
Patch Set: Fix compilation after rebase. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/gn/import_manager.cc ('k') | tools/gn/input_conversion.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/inherited_libraries.h" 6 #include "tools/gn/inherited_libraries.h"
7 #include "tools/gn/target.h" 7 #include "tools/gn/target.h"
8 #include "tools/gn/test_with_scope.h" 8 #include "tools/gn/test_with_scope.h"
9 9
10 namespace { 10 namespace {
11 11
12 // In these tests, Pair can't be used conveniently because the 12 // In these tests, Pair can't be used conveniently because the
13 // "const" won't be inferred and the types won't match. This helper makes the 13 // "const" won't be inferred and the types won't match. This helper makes the
14 // right type of pair with the const Target. 14 // right type of pair with the const Target.
15 std::pair<const Target*, bool> Pair(const Target* t, bool b) { 15 std::pair<const Target*, bool> Pair(const Target* t, bool b) {
16 return std::pair<const Target*, bool>(t, b); 16 return std::pair<const Target*, bool>(t, b);
17 } 17 }
18 18
19 } // namespace 19 } // namespace
20 20
21 TEST(InheritedLibraries, Unique) { 21 TEST(InheritedLibraries, Unique) {
22 TestWithScope setup; 22 TestWithScope setup;
23 23
24 Target a(setup.settings(), Label(SourceDir("//foo/"), "a")); 24 Target a(setup.settings(), Label(SourceDir("//foo/"), "a"), {});
25 Target b(setup.settings(), Label(SourceDir("//foo/"), "b")); 25 Target b(setup.settings(), Label(SourceDir("//foo/"), "b"), {});
26 26
27 // Setup, add the two targets as private. 27 // Setup, add the two targets as private.
28 InheritedLibraries libs; 28 InheritedLibraries libs;
29 libs.Append(&a, false); 29 libs.Append(&a, false);
30 libs.Append(&b, false); 30 libs.Append(&b, false);
31 auto result = libs.GetOrderedAndPublicFlag(); 31 auto result = libs.GetOrderedAndPublicFlag();
32 ASSERT_EQ(2u, result.size()); 32 ASSERT_EQ(2u, result.size());
33 EXPECT_EQ(Pair(&a, false), result[0]); 33 EXPECT_EQ(Pair(&a, false), result[0]);
34 EXPECT_EQ(Pair(&b, false), result[1]); 34 EXPECT_EQ(Pair(&b, false), result[1]);
35 35
(...skipping 18 matching lines...) Expand all
54 libs.Append(&b, false); 54 libs.Append(&b, false);
55 result = libs.GetOrderedAndPublicFlag(); 55 result = libs.GetOrderedAndPublicFlag();
56 ASSERT_EQ(2u, result.size()); 56 ASSERT_EQ(2u, result.size());
57 EXPECT_EQ(Pair(&a, true), result[0]); 57 EXPECT_EQ(Pair(&a, true), result[0]);
58 EXPECT_EQ(Pair(&b, true), result[1]); 58 EXPECT_EQ(Pair(&b, true), result[1]);
59 } 59 }
60 60
61 TEST(InheritedLibraries, AppendInherited) { 61 TEST(InheritedLibraries, AppendInherited) {
62 TestWithScope setup; 62 TestWithScope setup;
63 63
64 Target a(setup.settings(), Label(SourceDir("//foo/"), "a")); 64 Target a(setup.settings(), Label(SourceDir("//foo/"), "a"), {});
65 Target b(setup.settings(), Label(SourceDir("//foo/"), "b")); 65 Target b(setup.settings(), Label(SourceDir("//foo/"), "b"), {});
66 Target w(setup.settings(), Label(SourceDir("//foo/"), "w")); 66 Target w(setup.settings(), Label(SourceDir("//foo/"), "w"), {});
67 Target x(setup.settings(), Label(SourceDir("//foo/"), "x")); 67 Target x(setup.settings(), Label(SourceDir("//foo/"), "x"), {});
68 Target y(setup.settings(), Label(SourceDir("//foo/"), "y")); 68 Target y(setup.settings(), Label(SourceDir("//foo/"), "y"), {});
69 Target z(setup.settings(), Label(SourceDir("//foo/"), "z")); 69 Target z(setup.settings(), Label(SourceDir("//foo/"), "z"), {});
70 70
71 InheritedLibraries libs; 71 InheritedLibraries libs;
72 libs.Append(&a, false); 72 libs.Append(&a, false);
73 libs.Append(&b, false); 73 libs.Append(&b, false);
74 74
75 // Appending these things with private inheritance should make them private, 75 // Appending these things with private inheritance should make them private,
76 // no matter how they're listed in the appended class. 76 // no matter how they're listed in the appended class.
77 InheritedLibraries append_private; 77 InheritedLibraries append_private;
78 append_private.Append(&a, true); 78 append_private.Append(&a, true);
79 append_private.Append(&b, false); 79 append_private.Append(&b, false);
(...skipping 24 matching lines...) Expand all
104 EXPECT_EQ(Pair(&x, false), result[3]); 104 EXPECT_EQ(Pair(&x, false), result[3]);
105 EXPECT_EQ(Pair(&y, true), result[4]); // Appended as public. 105 EXPECT_EQ(Pair(&y, true), result[4]); // Appended as public.
106 EXPECT_EQ(Pair(&z, false), result[5]); 106 EXPECT_EQ(Pair(&z, false), result[5]);
107 } 107 }
108 108
109 TEST(InheritedLibraries, AppendPublicSharedLibraries) { 109 TEST(InheritedLibraries, AppendPublicSharedLibraries) {
110 TestWithScope setup; 110 TestWithScope setup;
111 InheritedLibraries append; 111 InheritedLibraries append;
112 112
113 // Two source sets. 113 // Two source sets.
114 Target set_pub(setup.settings(), Label(SourceDir("//foo/"), "set_pub")); 114 Target set_pub(setup.settings(), Label(SourceDir("//foo/"), "set_pub"), {});
115 set_pub.set_output_type(Target::SOURCE_SET); 115 set_pub.set_output_type(Target::SOURCE_SET);
116 append.Append(&set_pub, true); 116 append.Append(&set_pub, true);
117 Target set_priv(setup.settings(), Label(SourceDir("//foo/"), "set_priv")); 117 Target set_priv(setup.settings(), Label(SourceDir("//foo/"), "set_priv"), {});
118 set_priv.set_output_type(Target::SOURCE_SET); 118 set_priv.set_output_type(Target::SOURCE_SET);
119 append.Append(&set_priv, false); 119 append.Append(&set_priv, false);
120 120
121 // Two shared libraries. 121 // Two shared libraries.
122 Target sh_pub(setup.settings(), Label(SourceDir("//foo/"), "sh_pub")); 122 Target sh_pub(setup.settings(), Label(SourceDir("//foo/"), "sh_pub"), {});
123 sh_pub.set_output_type(Target::SHARED_LIBRARY); 123 sh_pub.set_output_type(Target::SHARED_LIBRARY);
124 append.Append(&sh_pub, true); 124 append.Append(&sh_pub, true);
125 Target sh_priv(setup.settings(), Label(SourceDir("//foo/"), "sh_priv")); 125 Target sh_priv(setup.settings(), Label(SourceDir("//foo/"), "sh_priv"), {});
126 sh_priv.set_output_type(Target::SHARED_LIBRARY); 126 sh_priv.set_output_type(Target::SHARED_LIBRARY);
127 append.Append(&sh_priv, false); 127 append.Append(&sh_priv, false);
128 128
129 InheritedLibraries libs; 129 InheritedLibraries libs;
130 libs.AppendPublicSharedLibraries(append, true); 130 libs.AppendPublicSharedLibraries(append, true);
131 131
132 auto result = libs.GetOrderedAndPublicFlag(); 132 auto result = libs.GetOrderedAndPublicFlag();
133 ASSERT_EQ(1u, result.size()); 133 ASSERT_EQ(1u, result.size());
134 EXPECT_EQ(Pair(&sh_pub, true), result[0]); 134 EXPECT_EQ(Pair(&sh_pub, true), result[0]);
135 } 135 }
OLDNEW
« no previous file with comments | « tools/gn/import_manager.cc ('k') | tools/gn/input_conversion.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698