2
0
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:
Mukund Sivaraman
2012-10-29 08:35:20 +05:30
parent cb9e761c57
commit a6093a8ef8
3 changed files with 13 additions and 4 deletions

View File

@@ -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') {

View File

@@ -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();

View File

@@ -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());