<webview>: Define API endpoints for webview.contextMenus API.
[chromium-blink-merge.git] / tools / gn / gyp_binary_target_writer_unittest.cc
blob4903ab902c7ee02e5938bafeee0abc0720c1a5a0
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) {
11 TestWithScope setup;
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);
33 writer.Run();
35 const char expected[] =
36 " {\n"
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"
44 " 'Debug': {\n"
45 " 'ldflags': [ ],\n"
46 " },\n"
47 " 'Release': {\n"
48 " 'ldflags': [ ],\n"
49 " },\n"
50 " },\n"
51 " 'sources': [\n"
52 " '<(DEPTH)/foo/input1.cc',\n"
53 " '<(DEPTH)/foo/input2.cc',\n"
54 " ],\n"
55 " },],\n"
56 " ],\n"
57 " },\n";
58 std::string out_str = out.str();
59 EXPECT_EQ(expected, out_str);
62 TEST(GypBinaryTargetWriter, EmptyProductExtension) {
63 TestWithScope setup;
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);
87 writer.Run();
89 const char expected[] =
90 " {\n"
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"
97 " 'Debug': {\n"
98 " 'ldflags': [ ],\n"
99 " },\n"
100 " 'Release': {\n"
101 " 'ldflags': [ ],\n"
102 " },\n"
103 " },\n"
104 " 'sources': [\n"
105 " '<(DEPTH)/foo/input1.cc',\n"
106 " '<(DEPTH)/foo/input2.cc',\n"
107 " ],\n"
108 " },],\n"
109 " ],\n"
110 " },\n";
111 std::string out_str = out.str();
112 EXPECT_EQ(expected, out_str);