From 6778ed99fe197a05bd109eab1ec047ddcba07ca4 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 21 Jun 2010 14:56:21 +0000 Subject: Fixed a bug in Bu::Buffer that resulted from a false negative on isEos if the underlying stream was empty. --- src/buffer.cpp | 2 +- src/unit/buffer.unit | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/unit/buffer.unit diff --git a/src/buffer.cpp b/src/buffer.cpp index fa27116..234dc92 100644 --- a/src/buffer.cpp +++ b/src/buffer.cpp @@ -153,6 +153,6 @@ void Bu::Buffer::flush() bool Bu::Buffer::isEos() { - return iReadPos == (iReadBufFill-1) && rNext.isEos(); + return (iReadPos >= (iReadBufFill-1)) && (rNext.isEos()); } diff --git a/src/unit/buffer.unit b/src/unit/buffer.unit new file mode 100644 index 0000000..8ed1ec5 --- /dev/null +++ b/src/unit/buffer.unit @@ -0,0 +1,27 @@ +// vim: syntax=cpp +/* + * Copyright (C) 2007-2010 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#include "bu/file.h" +#include "bu/membuf.h" +#include "bu/buffer.h" + +suite Buffer +{ + test emptyFile + { + Bu::FString sTmp("empty-XXXXXX"); + Bu::File fEmpty = tempFile(sTmp); + Bu::Buffer buf( fEmpty ); + + unitTest( buf.isEos() == false ); + Bu::FString sLine = buf.readLine(); + unitTest( sLine == "" ); + unitTest( fEmpty.isEos() == true ); + unitTest( buf.isEos() == true ); + } +} -- cgit v1.2.3