mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-01 06:25:34 +00:00
[2369] Throw a custom exception in ungetChar()
This commit is contained in:
@@ -13,7 +13,6 @@
|
|||||||
// PERFORMANCE OF THIS SOFTWARE.
|
// PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
#include <dns/inputsource.h>
|
#include <dns/inputsource.h>
|
||||||
#include <exceptions/exceptions.h>
|
|
||||||
|
|
||||||
namespace isc {
|
namespace isc {
|
||||||
namespace dns {
|
namespace dns {
|
||||||
@@ -53,7 +52,7 @@ InputSource::ungetChar() {
|
|||||||
if (at_eof_) {
|
if (at_eof_) {
|
||||||
at_eof_ = false;
|
at_eof_ = false;
|
||||||
} else if (buffer_pos_ == 0) {
|
} else if (buffer_pos_ == 0) {
|
||||||
isc_throw(OutOfRange, "Cannot skip before the start of buffer");
|
isc_throw(UngetError, "Cannot skip before the start of buffer");
|
||||||
} else {
|
} else {
|
||||||
buffer_pos_--;
|
buffer_pos_--;
|
||||||
if (buffer_[buffer_pos_] == '\n') {
|
if (buffer_[buffer_pos_] == '\n') {
|
||||||
|
@@ -15,6 +15,8 @@
|
|||||||
#ifndef DNS_INPUTSOURCE_H
|
#ifndef DNS_INPUTSOURCE_H
|
||||||
#define DNS_INPUTSOURCE_H 1
|
#define DNS_INPUTSOURCE_H 1
|
||||||
|
|
||||||
|
#include <exceptions/exceptions.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -50,6 +52,14 @@ public:
|
|||||||
saved_line_ = line_;
|
saved_line_ = line_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// \brief Exception thrown when ungetChar() is made to go before
|
||||||
|
/// the start of buffer.
|
||||||
|
struct UngetError : public OutOfRange {
|
||||||
|
UngetError(const char* file, size_t line, const char* what) :
|
||||||
|
OutOfRange(file, line, what)
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
int getChar();
|
int getChar();
|
||||||
void ungetChar();
|
void ungetChar();
|
||||||
void ungetAll();
|
void ungetAll();
|
||||||
|
@@ -96,7 +96,7 @@ TEST_F(InputSourceTest, getAndUngetChar) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Skipping past the start of buffer should throw.
|
// Skipping past the start of buffer should throw.
|
||||||
EXPECT_THROW(source_.ungetChar(), isc::OutOfRange);
|
EXPECT_THROW(source_.ungetChar(), InputSource::UngetError);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ungetAll() should skip back to the place where the InputSource
|
// ungetAll() should skip back to the place where the InputSource
|
||||||
@@ -162,7 +162,7 @@ TEST_F(InputSourceTest, lines) {
|
|||||||
((line - 1) == source_.getCurrentLine())));
|
((line - 1) == source_.getCurrentLine())));
|
||||||
line = source_.getCurrentLine();
|
line = source_.getCurrentLine();
|
||||||
}
|
}
|
||||||
}, isc::OutOfRange);
|
}, InputSource::UngetError);
|
||||||
|
|
||||||
// Now we are back to where we started.
|
// Now we are back to where we started.
|
||||||
EXPECT_EQ(1, source_.getCurrentLine());
|
EXPECT_EQ(1, source_.getCurrentLine());
|
||||||
|
Reference in New Issue
Block a user