Allow construction from istream

This commit is contained in:
TheAssassin
2018-11-09 00:43:02 +01:00
parent 793b35dc61
commit aa2e8b9105
3 changed files with 15 additions and 0 deletions
+4
View File
@@ -48,6 +48,10 @@ DesktopFileReader::DesktopFileReader(boost::filesystem::path path) : DesktopFile
d->parse(ifs);
}
DesktopFileReader::DesktopFileReader(std::istream& is) : DesktopFileReader() {
d->parse(is);
}
DesktopFileReader::DesktopFileReader(const DesktopFileReader& other) : DesktopFileReader() {
d->copyData(other.d);
}
+4
View File
@@ -2,6 +2,7 @@
// system includes
#include <memory>
#include <istream>
// library includes
#include <boost/filesystem.hpp>
@@ -19,6 +20,9 @@ public:
// construct from path
explicit DesktopFileReader(boost::filesystem::path path);
// construct from existing istream
explicit DesktopFileReader(std::istream& is);
// copy constructor
DesktopFileReader(const DesktopFileReader& other);
+7
View File
@@ -25,6 +25,13 @@ TEST_F(DesktopFileReaderFixture, testPathConstructor) {
EXPECT_FALSE(reader.isEmpty());
}
TEST_F(DesktopFileReaderFixture, testStreamConstructor) {
std::stringstream ss;
DesktopFileReader reader(ss);
EXPECT_TRUE(reader.isEmpty());
}
TEST_F(DesktopFileReaderFixture, testPathConstructorWithEmptyPath) {
ASSERT_THROW(DesktopFileReader(""), std::invalid_argument);
}