From bf53de3dfa4db68627f2935e6b2144835604df3a Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 16 Oct 2009 16:09:02 +0000 Subject: Finally added the substream class, and added getByPath (for properties) and getChildByPath (for groups) to the TafGroup class. --- src/unit/substream.unit | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/unit/substream.unit (limited to 'src/unit/substream.unit') diff --git a/src/unit/substream.unit b/src/unit/substream.unit new file mode 100644 index 0000000..ef6c70b --- /dev/null +++ b/src/unit/substream.unit @@ -0,0 +1,52 @@ +// vim: syntax=cpp +/* + * Copyright (C) 2007-2008 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/membuf.h" +#include "bu/substream.h" + +{=Init} + +{%testRead01} +{ + Bu::MemBuf mb("abcdefghijklmnopqrstuvwxyz"); + mb.seek( 4 ); + Bu::SubStream ss( mb, 10 ); + unitTest( ss.readLine() == "efghijklmn" ); +} + +{%testRead02} +{ + Bu::MemBuf mb("abcdefghijklmnopqrstuvwxyz"); + mb.seek( 4 ); + Bu::SubStream ss( mb, 10 ); + char buf[8]; + size_t iRead = ss.read( buf, 8 ); + unitTest( iRead == 8 ); + unitTest( strncmp( buf, "efghijkl", 8 ) == 0 ); + unitTest( !ss.isEos() ); + iRead = ss.read( buf, 8 ); + unitTest( iRead == 2 ); + unitTest( strncmp( buf, "mn", 2 ) == 0 ); + unitTest( ss.isEos() ); +} + +{%testRead03} +{ + Bu::MemBuf mb("abcdefghijklmnopqrstuvwxyz"); + mb.seek( 20 ); + Bu::SubStream ss( mb, 10 ); + char buf[8]; + size_t iRead = ss.read( buf, 8 ); + unitTest( iRead == 6 ); + unitTest( strncmp( buf, "uvwxyz", 6 ) == 0 ); + unitTest( ss.isEos() ); + iRead = ss.read( buf, 8 ); + unitTest( iRead == 0 ); + unitTest( ss.isEos() ); +} + -- cgit v1.2.3