This source file includes following definitions.
- toolchain_
- TEST_F
- TEST_F
- TEST_F
#include "testing/gtest/include/gtest/gtest.h"
#include "tools/gn/build_settings.h"
#include "tools/gn/config.h"
#include "tools/gn/settings.h"
#include "tools/gn/target.h"
#include "tools/gn/toolchain.h"
namespace {
class TargetTest : public testing::Test {
public:
TargetTest()
: build_settings_(),
settings_(&build_settings_, std::string()),
toolchain_(&settings_, Label(SourceDir("//tc/"), "tc")) {
settings_.set_toolchain_label(toolchain_.label());
}
virtual ~TargetTest() {
}
protected:
BuildSettings build_settings_;
Settings settings_;
Toolchain toolchain_;
};
}
TEST_F(TargetTest, GroupDeps) {
Target x(&settings_, Label(SourceDir("//component/"), "x"));
Target y(&settings_, Label(SourceDir("//component/"), "y"));
Target g(&settings_, Label(SourceDir("//group/"), "g"));
g.set_output_type(Target::GROUP);
g.deps().push_back(LabelTargetPair(&x));
g.deps().push_back(LabelTargetPair(&y));
Target b(&settings_, Label(SourceDir("//app/"), "b"));
Target a(&settings_, Label(SourceDir("//app/"), "a"));
a.set_output_type(Target::EXECUTABLE);
a.deps().push_back(LabelTargetPair(&g));
a.deps().push_back(LabelTargetPair(&b));
a.OnResolved();
ASSERT_EQ(4u, a.deps().size());
EXPECT_EQ(&g, a.deps()[0].ptr);
EXPECT_EQ(&x, a.deps()[1].ptr);
EXPECT_EQ(&y, a.deps()[2].ptr);
EXPECT_EQ(&b, a.deps()[3].ptr);
}
TEST_F(TargetTest, LibInheritance) {
const std::string lib("foo");
const SourceDir libdir("/foo_dir/");
Target z(&settings_, Label(SourceDir("//foo/"), "z"));
z.set_output_type(Target::STATIC_LIBRARY);
z.config_values().libs().push_back(lib);
z.config_values().lib_dirs().push_back(libdir);
z.OnResolved();
ASSERT_EQ(1u, z.all_libs().size());
EXPECT_EQ(lib, z.all_libs()[0]);
ASSERT_EQ(1u, z.all_lib_dirs().size());
EXPECT_EQ(libdir, z.all_lib_dirs()[0]);
const std::string second_lib("bar");
const SourceDir second_libdir("/bar_dir/");
Target shared(&settings_, Label(SourceDir("//foo/"), "shared"));
shared.set_output_type(Target::SHARED_LIBRARY);
shared.config_values().libs().push_back(second_lib);
shared.config_values().lib_dirs().push_back(second_libdir);
shared.deps().push_back(LabelTargetPair(&z));
shared.OnResolved();
ASSERT_EQ(2u, shared.all_libs().size());
EXPECT_EQ(second_lib, shared.all_libs()[0]);
EXPECT_EQ(lib, shared.all_libs()[1]);
ASSERT_EQ(2u, shared.all_lib_dirs().size());
EXPECT_EQ(second_libdir, shared.all_lib_dirs()[0]);
EXPECT_EQ(libdir, shared.all_lib_dirs()[1]);
Target exec(&settings_, Label(SourceDir("//foo/"), "exec"));
exec.set_output_type(Target::EXECUTABLE);
exec.deps().push_back(LabelTargetPair(&shared));
exec.OnResolved();
EXPECT_EQ(0u, exec.all_libs().size());
EXPECT_EQ(0u, exec.all_lib_dirs().size());
}
TEST_F(TargetTest, DependentConfigs) {
Target a(&settings_, Label(SourceDir("//foo/"), "a"));
a.set_output_type(Target::EXECUTABLE);
Target b(&settings_, Label(SourceDir("//foo/"), "b"));
b.set_output_type(Target::STATIC_LIBRARY);
Target c(&settings_, Label(SourceDir("//foo/"), "c"));
c.set_output_type(Target::STATIC_LIBRARY);
a.deps().push_back(LabelTargetPair(&b));
b.deps().push_back(LabelTargetPair(&c));
Config config(&settings_, Label(SourceDir("//foo/"), "config"));
c.configs().push_back(LabelConfigPair(&config));
Config all(&settings_, Label(SourceDir("//foo/"), "all"));
c.all_dependent_configs().push_back(LabelConfigPair(&all));
Config direct(&settings_, Label(SourceDir("//foo/"), "direct"));
c.direct_dependent_configs().push_back(LabelConfigPair(&direct));
c.OnResolved();
b.OnResolved();
a.OnResolved();
ASSERT_EQ(2u, b.configs().size());
EXPECT_EQ(&all, b.configs()[0].ptr);
EXPECT_EQ(&direct, b.configs()[1].ptr);
ASSERT_EQ(1u, b.all_dependent_configs().size());
EXPECT_EQ(&all, b.all_dependent_configs()[0].ptr);
ASSERT_EQ(1u, a.configs().size());
EXPECT_EQ(&all, a.configs()[0].ptr);
EXPECT_EQ(&all, a.all_dependent_configs()[0].ptr);
Target a_fwd(&settings_, Label(SourceDir("//foo/"), "a_fwd"));
a_fwd.set_output_type(Target::EXECUTABLE);
Target b_fwd(&settings_, Label(SourceDir("//foo/"), "b_fwd"));
b_fwd.set_output_type(Target::STATIC_LIBRARY);
a_fwd.deps().push_back(LabelTargetPair(&b_fwd));
b_fwd.deps().push_back(LabelTargetPair(&c));
b_fwd.forward_dependent_configs().push_back(LabelTargetPair(&c));
b_fwd.OnResolved();
a_fwd.OnResolved();
ASSERT_EQ(2u, a_fwd.configs().size());
EXPECT_EQ(&all, a_fwd.configs()[0].ptr);
EXPECT_EQ(&direct, a_fwd.configs()[1].ptr);
ASSERT_EQ(1u, a_fwd.all_dependent_configs().size());
EXPECT_EQ(&all, a_fwd.all_dependent_configs()[0].ptr);
}