1 // Copyright 2022 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 "gn/resolved_target_deps.h"
6 #include "gn/test_with_scope.h"
7 #include "util/test/test.h"
8
TEST(ResolvedTargetDeps,DefaultConstruction)9 TEST(ResolvedTargetDeps, DefaultConstruction) {
10 ResolvedTargetDeps deps;
11 EXPECT_EQ(0u, deps.size());
12 EXPECT_TRUE(deps.public_deps().empty());
13 EXPECT_TRUE(deps.private_deps().empty());
14 EXPECT_TRUE(deps.data_deps().empty());
15 EXPECT_TRUE(deps.linked_deps().empty());
16 EXPECT_TRUE(deps.all_deps().empty());
17 }
18
TEST(ResolvedTargetDeps,Construction)19 TEST(ResolvedTargetDeps, Construction) {
20 TestWithScope setup;
21 TestTarget a(setup, "//foo:a", Target::STATIC_LIBRARY);
22 TestTarget b(setup, "//foo:b", Target::SOURCE_SET);
23 TestTarget c(setup, "//foo:c", Target::SOURCE_SET);
24 TestTarget d(setup, "//foo:d", Target::SOURCE_SET);
25 TestTarget e(setup, "//foo:e", Target::EXECUTABLE);
26
27 LabelTargetVector public_vec;
28 LabelTargetVector private_vec;
29 LabelTargetVector data_vec;
30
31 public_vec.emplace_back(&a);
32 public_vec.emplace_back(&b);
33 private_vec.emplace_back(&c);
34 private_vec.emplace_back(&d);
35 data_vec.emplace_back(&e);
36
37 ResolvedTargetDeps deps(public_vec, private_vec, data_vec);
38 EXPECT_EQ(5u, deps.size());
39
40 EXPECT_EQ(2u, deps.public_deps().size());
41 EXPECT_EQ(&a, deps.public_deps()[0]);
42 EXPECT_EQ(&b, deps.public_deps()[1]);
43
44 EXPECT_EQ(2u, deps.private_deps().size());
45 EXPECT_EQ(&c, deps.private_deps()[0]);
46 EXPECT_EQ(&d, deps.private_deps()[1]);
47
48 EXPECT_EQ(1u, deps.data_deps().size());
49 EXPECT_EQ(&e, deps.data_deps()[0]);
50
51 EXPECT_EQ(4u, deps.linked_deps().size());
52 EXPECT_EQ(&a, deps.linked_deps()[0]);
53 EXPECT_EQ(&b, deps.linked_deps()[1]);
54 EXPECT_EQ(&c, deps.linked_deps()[2]);
55 EXPECT_EQ(&d, deps.linked_deps()[3]);
56
57 EXPECT_EQ(5u, deps.all_deps().size());
58 EXPECT_EQ(&a, deps.all_deps()[0]);
59 EXPECT_EQ(&b, deps.all_deps()[1]);
60 EXPECT_EQ(&c, deps.all_deps()[2]);
61 EXPECT_EQ(&d, deps.all_deps()[3]);
62 EXPECT_EQ(&e, deps.all_deps()[4]);
63 }
64