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 +++++++++++++++++++++++++++++++++++++++++++++++++ src/unit/taf.unit | 10 ++++++++++ 2 files changed, 62 insertions(+) create mode 100644 src/unit/substream.unit (limited to 'src/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() ); +} + diff --git a/src/unit/taf.unit b/src/unit/taf.unit index eeddd53..a9329fe 100644 --- a/src/unit/taf.unit +++ b/src/unit/taf.unit @@ -109,3 +109,13 @@ // Woot } } + +{%bypath1} +{ + Bu::MemBuf mb("{outer: \"Hello=\" {inner: {final: test=hi} } }"); + Bu::TafReader tr( mb ); + const Bu::TafGroup *g = tr.readGroup(); + unitTest( g->getChildByPath("inner/final")->getProperty("test") == "hi" ); + unitTest( g->getByPath("inner/final/test") == "hi" ); +} + -- cgit v1.2.3