7#include <gtest/gtest.h>
13TEST(ComponentV2, ParseProgramMetadataDefaultAssets) {
15 std::vector<fuchsia::data::DictionaryEntry> entries;
17 fuchsia::data::DictionaryEntry data_entry;
18 data_entry.key =
"data";
19 data_entry.value = std::make_unique<fuchsia::data::DictionaryValue>(
20 fuchsia::data::DictionaryValue::WithStr(
"foobar"));
21 entries.push_back(std::move(data_entry));
23 fuchsia::data::Dictionary program_metadata;
24 program_metadata.set_entries(std::move(entries));
28 EXPECT_EQ(
result.data_path,
"pkg/foobar");
29 EXPECT_EQ(
result.assets_path,
"pkg/foobar");
30 EXPECT_EQ(
result.old_gen_heap_size, std::nullopt);
33TEST(ComponentV2, ParseProgramMetadataIgnoreInvalidKeys) {
35 std::vector<fuchsia::data::DictionaryEntry> entries;
37 fuchsia::data::DictionaryEntry not_data_entry;
38 not_data_entry.key =
"not_data";
39 not_data_entry.value = std::make_unique<fuchsia::data::DictionaryValue>(
40 fuchsia::data::DictionaryValue::WithStr(
"foo"));
41 entries.push_back(std::move(not_data_entry));
43 fuchsia::data::DictionaryEntry data_entry;
44 data_entry.key =
"data";
45 data_entry.value = std::make_unique<fuchsia::data::DictionaryValue>(
46 fuchsia::data::DictionaryValue::WithStr(
"bar"));
47 entries.push_back(std::move(data_entry));
49 fuchsia::data::DictionaryEntry assets_entry;
50 assets_entry.key =
"assets";
51 assets_entry.value = std::make_unique<fuchsia::data::DictionaryValue>(
52 fuchsia::data::DictionaryValue::WithStr(
"baz"));
53 entries.push_back(std::move(assets_entry));
55 fuchsia::data::Dictionary program_metadata;
56 program_metadata.set_entries(std::move(entries));
60 EXPECT_EQ(
result.data_path,
"pkg/bar");
61 EXPECT_EQ(
result.assets_path,
"pkg/baz");
62 EXPECT_EQ(
result.old_gen_heap_size, std::nullopt);
65TEST(ComponentV2, ParseProgramMetadataOldGenHeapSize) {
67 std::vector<fuchsia::data::DictionaryEntry> entries;
69 fuchsia::data::DictionaryEntry args_entry;
70 args_entry.key =
"args";
71 args_entry.value = std::make_unique<fuchsia::data::DictionaryValue>(
72 fuchsia::data::DictionaryValue::WithStrVec({
"--old_gen_heap_size=100"}));
73 entries.push_back(std::move(args_entry));
75 fuchsia::data::Dictionary program_metadata;
76 program_metadata.set_entries(std::move(entries));
80 EXPECT_EQ(
result.data_path,
"");
81 EXPECT_EQ(
result.assets_path,
"");
82 EXPECT_EQ(
result.old_gen_heap_size, 100);
85TEST(ComponentV2, ParseProgramMetadataOldGenHeapSizeInvalid) {
87 std::vector<fuchsia::data::DictionaryEntry> entries;
89 fuchsia::data::DictionaryEntry args_entry;
90 args_entry.key =
"args";
91 args_entry.value = std::make_unique<fuchsia::data::DictionaryValue>(
92 fuchsia::data::DictionaryValue::WithStrVec(
93 {
"--old_gen_heap_size=asdf100"}));
94 entries.push_back(std::move(args_entry));
96 fuchsia::data::Dictionary program_metadata;
97 program_metadata.set_entries(std::move(entries));
101 EXPECT_EQ(
result.data_path,
"");
102 EXPECT_EQ(
result.assets_path,
"");
103 EXPECT_EQ(
result.old_gen_heap_size, std::nullopt);
106TEST(ComponentV2, ParseProgramMetadataNoExposeDirs) {
108 std::vector<fuchsia::data::DictionaryEntry> entries;
110 fuchsia::data::Dictionary program_metadata;
111 program_metadata.set_entries(std::move(entries));
115 EXPECT_EQ(
result.expose_dirs.empty(),
true);
118TEST(ComponentV2, ParseProgramMetadataWithSingleExposeDirs) {
120 std::vector<fuchsia::data::DictionaryEntry> entries;
122 fuchsia::data::DictionaryEntry args_entry;
123 args_entry.key =
"args";
124 args_entry.value = std::make_unique<fuchsia::data::DictionaryValue>(
125 fuchsia::data::DictionaryValue::WithStrVec({
"--expose_dirs=foo"}));
126 entries.push_back(std::move(args_entry));
128 fuchsia::data::Dictionary program_metadata;
129 program_metadata.set_entries(std::move(entries));
133 ASSERT_EQ(
result.expose_dirs.size(), 1u);
134 EXPECT_EQ(
result.expose_dirs[0],
"foo");
137TEST(ComponentV2, ParseProgramMetadataWithMultipleExposeDirs) {
139 std::vector<fuchsia::data::DictionaryEntry> entries;
141 fuchsia::data::DictionaryEntry args_entry;
142 args_entry.key =
"args";
143 args_entry.value = std::make_unique<fuchsia::data::DictionaryValue>(
144 fuchsia::data::DictionaryValue::WithStrVec(
145 {
"--expose_dirs=foo,bar,baz"}));
146 entries.push_back(std::move(args_entry));
148 fuchsia::data::Dictionary program_metadata;
149 program_metadata.set_entries(std::move(entries));
153 ASSERT_EQ(
result.expose_dirs.size(), 3u);
154 EXPECT_EQ(
result.expose_dirs[0],
"foo");
155 EXPECT_EQ(
result.expose_dirs[1],
"bar");
156 EXPECT_EQ(
result.expose_dirs[2],
"baz");
159TEST(ComponentV2, ParseProgramMetadataWithSingleExposeDirsAndOtherArgs) {
161 std::vector<fuchsia::data::DictionaryEntry> entries;
163 fuchsia::data::DictionaryEntry args_entry;
164 args_entry.key =
"args";
165 args_entry.value = std::make_unique<fuchsia::data::DictionaryValue>(
166 fuchsia::data::DictionaryValue::WithStrVec(
167 {
"--expose_dirs=foo",
"--foo=bar"}));
168 entries.push_back(std::move(args_entry));
170 fuchsia::data::Dictionary program_metadata;
171 program_metadata.set_entries(std::move(entries));
175 ASSERT_EQ(
result.expose_dirs.size(), 1u);
176 EXPECT_EQ(
result.expose_dirs[0],
"foo");
static ProgramMetadata ParseProgramMetadata(const fuchsia::data::Dictionary &program_metadata)
TEST(RunnerTZDataTest, LoadsWithoutTZDataPresent)