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
f142087f
Commit
f142087f
authored
Nov 02, 2012
by
Mukund Sivaraman
Browse files
[2369] Add a file test as well
parent
e32617d5
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/lib/dns/tests/master_lexer_inputsource_unittest.cc
View file @
f142087f
...
...
@@ -61,48 +61,67 @@ TEST_F(InputSourceTest, getName) {
// getChar() should return characters from the input stream in
// sequence. ungetChar() should skip backwards.
TEST_F
(
InputSourceTest
,
getAndUngetChar
)
{
for
(
size_t
i
=
0
;
i
<
str_length_
;
i
++
)
{
EXPECT_EQ
(
str_
[
i
],
source_
.
getChar
());
EXPECT_FALSE
(
source_
.
atEOF
());
void
checkGetAndUngetChar
(
InputSource
&
source
,
const
char
*
str
,
size_t
str_length
)
{
for
(
size_t
i
=
0
;
i
<
str_length
;
i
++
)
{
EXPECT_EQ
(
str
[
i
],
source
.
getChar
());
EXPECT_FALSE
(
source
.
atEOF
());
}
// At this point, we still have not reached EOF.
EXPECT_FALSE
(
source
_
.
atEOF
());
EXPECT_FALSE
(
source
.
atEOF
());
// This should cause EOF to be set.
EXPECT_EQ
(
InputSource
::
END_OF_STREAM
,
source
_
.
getChar
());
EXPECT_EQ
(
InputSource
::
END_OF_STREAM
,
source
.
getChar
());
// Now, EOF should be set.
EXPECT_TRUE
(
source
_
.
atEOF
());
EXPECT_TRUE
(
source
.
atEOF
());
// Now, let's go backwards. This should cause the EOF to be set to
// false.
source
_
.
ungetChar
();
source
.
ungetChar
();
// Now, EOF should be false.
EXPECT_FALSE
(
source
_
.
atEOF
());
EXPECT_FALSE
(
source
.
atEOF
());
// This should cause EOF to be set again.
EXPECT_EQ
(
InputSource
::
END_OF_STREAM
,
source
_
.
getChar
());
EXPECT_EQ
(
InputSource
::
END_OF_STREAM
,
source
.
getChar
());
// Now, EOF should be set.
EXPECT_TRUE
(
source
_
.
atEOF
());
EXPECT_TRUE
(
source
.
atEOF
());
// Now, let's go backwards in a loop. Start by skipping the EOF.
source
_
.
ungetChar
();
source
.
ungetChar
();
for
(
size_t
i
=
0
;
i
<
str_length
_
;
i
++
)
{
size_t
index
=
str_length
_
-
1
-
i
;
for
(
size_t
i
=
0
;
i
<
str_length
;
i
++
)
{
size_t
index
=
str_length
-
1
-
i
;
// Skip one character.
source
_
.
ungetChar
();
EXPECT_EQ
(
str
_
[
index
],
source
_
.
getChar
());
source
.
ungetChar
();
EXPECT_EQ
(
str
[
index
],
source
.
getChar
());
// Skip the character we received again.
source
_
.
ungetChar
();
source
.
ungetChar
();
}
// Skipping past the start of buffer should throw.
EXPECT_THROW
(
source_
.
ungetChar
(),
InputSource
::
UngetBeforeBeginning
);
EXPECT_THROW
(
source
.
ungetChar
(),
InputSource
::
UngetBeforeBeginning
);
}
TEST_F
(
InputSourceTest
,
stream
)
{
checkGetAndUngetChar
(
source_
,
str_
,
str_length_
);
}
TEST_F
(
InputSourceTest
,
file
)
{
const
char
*
str
=
";; a simple (incomplete) zone file
\n
"
"
\n
"
"example.com. 3600 IN TXT
\"
test data
\"\n
"
"www.example.com. 60 IN A 192.0.2.1
\n
"
"www.example.com. 60 IN A 192.0.2.2
\n
"
;
size_t
str_length
=
strlen
(
str
);
InputSource
source
(
TEST_DATA_SRCDIR
"/masterload.txt"
);
checkGetAndUngetChar
(
source
,
str
,
str_length
);
}
// ungetAll() should skip back to the place where the InputSource
...
...
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