[Scummvm-cvs-logs] scummvm master -> 6b6b7532aea5efe236f76f25f26d1b455b8d5b04

lordhoto lordhoto at gmail.com
Tue Oct 9 23:08:34 CEST 2012


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
efe2fe7e1f COMMON: Properly handle error indicator in MemoryWriteStream.
6b6b7532ae TEST: Add two (simple) tests for MemoryWriteStream.


Commit: efe2fe7e1ffcb423d0349ee2a508f8ec0d715642
    https://github.com/scummvm/scummvm/commit/efe2fe7e1ffcb423d0349ee2a508f8ec0d715642
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2012-10-09T14:06:25-07:00

Commit Message:
COMMON: Properly handle error indicator in MemoryWriteStream.

Thanks to waltervn for noticing that MemoryWriteStream::write doesn't handle
setting the error indicator properly.

Changed paths:
    common/memstream.h



diff --git a/common/memstream.h b/common/memstream.h
index 69fe6ec..497a178 100644
--- a/common/memstream.h
+++ b/common/memstream.h
@@ -92,13 +92,17 @@ private:
 	byte *_ptr;
 	const uint32 _bufSize;
 	uint32 _pos;
+	bool _err;
 public:
-	MemoryWriteStream(byte *buf, uint32 len) : _ptr(buf), _bufSize(len), _pos(0) {}
+	MemoryWriteStream(byte *buf, uint32 len) : _ptr(buf), _bufSize(len), _pos(0), _err(false) {}
 
 	uint32 write(const void *dataPtr, uint32 dataSize) {
 		// Write at most as many bytes as are still available...
-		if (dataSize > _bufSize - _pos)
+		if (dataSize > _bufSize - _pos) {
 			dataSize = _bufSize - _pos;
+			// We couldn't write all the data => set error indicator
+			_err = true;
+		}
 		memcpy(_ptr, dataPtr, dataSize);
 		_ptr += dataSize;
 		_pos += dataSize;
@@ -107,6 +111,9 @@ public:
 
 	uint32 pos() const { return _pos; }
 	uint32 size() const { return _bufSize; }
+
+	virtual bool err() const { return _err; }
+	virtual void clearErr() { _err = false; }
 };
 
 /**


Commit: 6b6b7532aea5efe236f76f25f26d1b455b8d5b04
    https://github.com/scummvm/scummvm/commit/6b6b7532aea5efe236f76f25f26d1b455b8d5b04
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2012-10-09T14:06:35-07:00

Commit Message:
TEST: Add two (simple) tests for MemoryWriteStream.

Changed paths:
  A test/common/memorywritestream.h



diff --git a/test/common/memorywritestream.h b/test/common/memorywritestream.h
new file mode 100644
index 0000000..43a137a
--- /dev/null
+++ b/test/common/memorywritestream.h
@@ -0,0 +1,31 @@
+#include <cxxtest/TestSuite.h>
+
+#include "common/memstream.h"
+
+class MemoryWriteStreamTestSuite : public CxxTest::TestSuite {
+	public:
+	void test_err() {
+		byte temp = 0;
+
+		Common::MemoryWriteStream stream(&temp, 0);
+		TS_ASSERT(!stream.err());
+
+		// Make sure the error indicator gets set
+		stream.write(&temp, 1);
+		TS_ASSERT(stream.err());
+
+		// Test whether the error indicator can be cleared
+		stream.clearErr();
+		TS_ASSERT(!stream.err());
+	}
+
+	void test_write() {
+		byte buffer[7] = {};
+		Common::MemoryWriteStream stream(buffer, sizeof(buffer));
+
+		const byte data[7] = { 7, 4, 3, 0, 10, 12, 1 };
+		stream.write(data, sizeof(data));
+		TS_ASSERT(memcmp(buffer, data, sizeof(data)) == 0);
+		TS_ASSERT(!stream.err());
+	}
+};






More information about the Scummvm-git-logs mailing list