Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
a2090f1d
Commit
a2090f1d
authored
Nov 02, 2012
by
Mukund Sivaraman
Browse files
[2369] Throw OpenError when opening the input file fails
parent
f142087f
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/lib/dns/master_lexer_inputsource.cc
View file @
a2090f1d
...
...
@@ -47,6 +47,10 @@ InputSource::InputSource(const char* filename) :
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
()
...
...
src/lib/dns/master_lexer_inputsource.h
View file @
a2090f1d
...
...
@@ -43,6 +43,8 @@ public:
/// \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
...
...
@@ -87,6 +89,13 @@ public:
{}
};
/// \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
;
...
...
src/lib/dns/tests/master_lexer_inputsource_unittest.cc
View file @
a2090f1d
...
...
@@ -59,6 +59,12 @@ TEST_F(InputSourceTest, getName) {
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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment