[Scummvm-cvs-logs] SF.net SVN: scummvm: [24715] scummvm/trunk/test/common

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Mon Nov 13 23:06:27 CET 2006


Revision: 24715
          http://svn.sourceforge.net/scummvm/?rev=24715&view=rev
Author:   fingolfin
Date:     2006-11-13 14:06:27 -0800 (Mon, 13 Nov 2006)

Log Message:
-----------
Patch #1583931: (Seekable)SubReadStream (the unit tests were missing, as I accidentally commited from the wrong directory)

Added Paths:
-----------
    scummvm/trunk/test/common/seekablesubreadstream.h
    scummvm/trunk/test/common/subreadstream.h

Added: scummvm/trunk/test/common/seekablesubreadstream.h
===================================================================
--- scummvm/trunk/test/common/seekablesubreadstream.h	                        (rev 0)
+++ scummvm/trunk/test/common/seekablesubreadstream.h	2006-11-13 22:06:27 UTC (rev 24715)
@@ -0,0 +1,72 @@
+#include <cxxtest/TestSuite.h>
+
+#include "common/stdafx.h"
+#include "common/stream.h"
+
+class SeekableSubReadStreamTestSuite : public CxxTest::TestSuite
+{
+	public:
+	void test_traverse( void )
+	{
+		byte contents[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+		Common::MemoryReadStream ms = Common::MemoryReadStream(contents, 10);
+
+		int start = 2, end = 8;
+
+		Common::SeekableSubReadStream ssrs = Common::SeekableSubReadStream(&ms, start, end);
+
+		int i;
+		byte b;
+		for (i = start; i < end; ++i)
+		{
+			TS_ASSERT( !ssrs.eos() );
+
+			TS_ASSERT_EQUALS( i - start, ssrs.pos() );
+
+			ssrs.read(&b, 1);
+			TS_ASSERT_EQUALS( i, b );
+		}
+
+		TS_ASSERT( ssrs.eos() );
+	}
+
+	void test_seek( void )
+	{
+		byte contents[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+		Common::MemoryReadStream ms = Common::MemoryReadStream(contents, 10);
+
+		Common::SeekableSubReadStream ssrs = Common::SeekableSubReadStream(&ms, 1, 9);
+		byte b;
+
+		TS_ASSERT_EQUALS( ssrs.pos(), 0 );
+
+		ssrs.seek(1, SEEK_SET);
+		TS_ASSERT_EQUALS( ssrs.pos(), 1 );
+		b = ssrs.readByte();
+		TS_ASSERT_EQUALS( b, 2 );
+
+		ssrs.seek(5, SEEK_CUR);
+		TS_ASSERT_EQUALS( ssrs.pos(), 7 );
+		b = ssrs.readByte();
+		TS_ASSERT_EQUALS( b, 8 );
+
+		ssrs.seek(-3, SEEK_CUR);
+		TS_ASSERT_EQUALS( ssrs.pos(), 5 );
+		b = ssrs.readByte();
+		TS_ASSERT_EQUALS( b, 6 );
+
+		ssrs.seek(0, SEEK_END);
+		TS_ASSERT_EQUALS( ssrs.pos(), 8 );
+		TS_ASSERT( ssrs.eos() );
+
+		ssrs.seek(3, SEEK_END);
+		TS_ASSERT_EQUALS( ssrs.pos(), 5 );
+		b = ssrs.readByte();
+		TS_ASSERT_EQUALS( b, 6 );
+
+		ssrs.seek(8, SEEK_END);
+		TS_ASSERT_EQUALS( ssrs.pos(), 0 );
+		b = ssrs.readByte();
+		TS_ASSERT_EQUALS( b, 1 );
+	}
+};


Property changes on: scummvm/trunk/test/common/seekablesubreadstream.h
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native

Added: scummvm/trunk/test/common/subreadstream.h
===================================================================
--- scummvm/trunk/test/common/subreadstream.h	                        (rev 0)
+++ scummvm/trunk/test/common/subreadstream.h	2006-11-13 22:06:27 UTC (rev 24715)
@@ -0,0 +1,30 @@
+#include <cxxtest/TestSuite.h>
+
+#include "common/stdafx.h"
+#include "common/stream.h"
+
+class SubReadStreamTestSuite : public CxxTest::TestSuite
+{
+	public:
+	void test_traverse( void )
+	{
+		byte contents[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+		Common::MemoryReadStream ms = Common::MemoryReadStream(contents, 10);
+
+		int end = 5;
+
+		Common::SubReadStream srs = Common::SubReadStream(&ms, end);
+
+		int i;
+		byte b;
+		for (i = 0; i < end; ++i)
+		{
+			TS_ASSERT( !srs.eos() );
+
+			srs.read(&b, 1);
+			TS_ASSERT_EQUALS( i, b );
+		}
+
+		TS_ASSERT( srs.eos() );
+	}
+};


Property changes on: scummvm/trunk/test/common/subreadstream.h
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list