input_(file_stream_)
{
file_stream_.open(filename, std::fstream::in);
+ if (file_stream_.fail()) {
+ isc_throw(OpenError,
+ "Error opening the input source file: " << filename);
+ }
}
InputSource::~InputSource()
/// \brief Constructor which takes a filename to read from. The
/// associated file stream is managed internally.
+ ///
+ /// \throws OpenError when opening the input file fails.
InputSource(const char* filename);
/// \brief Destructor
{}
};
+ /// \brief Exception thrown when we fail to open the input file.
+ struct OpenError : public Unexpected {
+ OpenError(const char* file, size_t line, const char* what) :
+ Unexpected(file, line, what)
+ {}
+ };
+
/// \brief Returned by getChar() when end of stream is reached.
static const int END_OF_STREAM;
EXPECT_EQ(TEST_DATA_SRCDIR "/masterload.txt", source2.getName());
}
+TEST_F(InputSourceTest, nonExistentFile) {
+ EXPECT_THROW({
+ InputSource source(TEST_DATA_SRCDIR "/videokilledtheradiostar");
+ }, InputSource::OpenError);
+}
+
// getChar() should return characters from the input stream in
// sequence. ungetChar() should skip backwards.
void