1 // Copyright (c) 2014 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.
5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "tools/gn/builder_record.h"
7 #include "tools/gn/gyp_binary_target_writer.h"
8 #include "tools/gn/test_with_scope.h"
10 TEST(GypBinaryTargetWriter
, ProductExtension
) {
12 setup
.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
14 // A shared library w/ the product_extension set to a custom value.
15 scoped_ptr
<Target
> target(
16 new Target(setup
.settings(), Label(SourceDir("//foo/"), "bar")));
17 target
->set_output_type(Target::SHARED_LIBRARY
);
18 target
->set_output_extension(std::string("so.6"));
19 target
->sources().push_back(SourceFile("//foo/input1.cc"));
20 target
->sources().push_back(SourceFile("//foo/input2.cc"));
22 BuilderRecord
record(BuilderRecord::ITEM_TARGET
, target
->label());
23 record
.set_item(target
.PassAs
<Item
>());
24 GypTargetWriter::TargetGroup group
;
25 group
.debug
= &record
;
26 group
.release
= &record
;
28 setup
.settings()->set_target_os(Settings::LINUX
);
30 std::ostringstream out
;
31 GypBinaryTargetWriter
writer(group
, setup
.toolchain(),
32 SourceDir("//out/gn_gyp/"), out
);
35 const char expected
[] =
37 " 'target_name': 'bar',\n"
38 " 'product_name': 'bar',\n"
39 " 'product_extension': 'so.6',\n"
40 " 'type': 'shared_library',\n"
41 " 'target_conditions': [\n"
42 " ['_toolset == \"target\"', {\n"
43 " 'configurations': {\n"
52 " '<(DEPTH)/foo/input1.cc',\n"
53 " '<(DEPTH)/foo/input2.cc',\n"
58 std::string out_str
= out
.str();
59 EXPECT_EQ(expected
, out_str
);
62 TEST(GypBinaryTargetWriter
, EmptyProductExtension
) {
64 setup
.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
66 // This test is the same as ProductExtension, except that
67 // we call set_output_extension("") and ensure that we still get the default.
68 scoped_ptr
<Target
> target(
69 new Target(setup
.settings(), Label(SourceDir("//foo/"), "bar")));
70 target
->set_output_type(Target::SHARED_LIBRARY
);
72 target
->sources().push_back(SourceFile("//foo/input1.cc"));
73 target
->sources().push_back(SourceFile("//foo/input2.cc"));
74 target
->set_output_extension(std::string());
76 BuilderRecord
record(BuilderRecord::ITEM_TARGET
, target
->label());
77 record
.set_item(target
.PassAs
<Item
>());
78 GypTargetWriter::TargetGroup group
;
79 group
.debug
= &record
;
80 group
.release
= &record
;
82 setup
.settings()->set_target_os(Settings::LINUX
);
84 std::ostringstream out
;
85 GypBinaryTargetWriter
writer(group
, setup
.toolchain(),
86 SourceDir("//out/gn_gyp/"), out
);
89 const char expected
[] =
91 " 'target_name': 'bar',\n"
92 " 'product_name': 'bar',\n"
93 " 'type': 'shared_library',\n"
94 " 'target_conditions': [\n"
95 " ['_toolset == \"target\"', {\n"
96 " 'configurations': {\n"
105 " '<(DEPTH)/foo/input1.cc',\n"
106 " '<(DEPTH)/foo/input2.cc',\n"
111 std::string out_str
= out
.str();
112 EXPECT_EQ(expected
, out_str
);