Add data getter

This commit is contained in:
TheAssassin
2018-11-09 03:15:47 +01:00
parent 156b45f819
commit 8b4feb5fd5
3 changed files with 29 additions and 0 deletions

View File

@@ -146,6 +146,10 @@ namespace linuxdeploy {
return d->path;
}
DesktopFile::sections_t DesktopFileReader::data() const {
return d->sections;
}
DesktopFile::section_t DesktopFileReader::operator[](const std::string& name) const {
auto it = d->sections.find(name);

View File

@@ -56,6 +56,10 @@ namespace linuxdeploy {
// get a specific section from the parsed data
// throws std::range_error if section does not exist
DesktopFile::section_t operator[](const std::string& name) const;
// get copy of internal data storage
// can be handed to a DesktopFileWriter instance, or to manually hack on the data
DesktopFile::sections_t data() const;
};
}
}

View File

@@ -166,3 +166,24 @@ TEST_F(DesktopFileReaderFixture, testParseFileWithLeadingAndTrailingWhitespaceIn
EXPECT_EQ(section["Name"].value(), "name");
EXPECT_EQ(section["Exec"].value(), "exec");
}
TEST_F(DesktopFileReaderFixture, testDataGetter) {
std::stringstream ss;
ss << "[Desktop File]" << std::endl
<< "Name= name" << std::endl
<< "Exec =exec" << std::endl;
DesktopFileReader reader(ss);
auto section = reader["Desktop File"];
EXPECT_FALSE(section.empty());
auto data = reader.data();
auto expected = DesktopFile::section_t({
{"Name", DesktopFileEntry("Name", "name")},
{"Exec", DesktopFileEntry("Exec", "exec")},
});
EXPECT_EQ(data["Desktop File"], expected);
}