aboutsummaryrefslogtreecommitdiff
path: root/src/unit/substream.unit
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-10-16 16:09:02 +0000
committerMike Buland <eichlan@xagasoft.com>2009-10-16 16:09:02 +0000
commitbf53de3dfa4db68627f2935e6b2144835604df3a (patch)
treee5e50c0b0e7df827dcdc8a162f1ff5fb61ac3277 /src/unit/substream.unit
parent96b07a22f5392f5d7f821f5743deb3d64bd94e89 (diff)
downloadlibbu++-bf53de3dfa4db68627f2935e6b2144835604df3a.tar.gz
libbu++-bf53de3dfa4db68627f2935e6b2144835604df3a.tar.bz2
libbu++-bf53de3dfa4db68627f2935e6b2144835604df3a.tar.xz
libbu++-bf53de3dfa4db68627f2935e6b2144835604df3a.zip
Finally added the substream class, and added getByPath (for properties) and
getChildByPath (for groups) to the TafGroup class.
Diffstat (limited to 'src/unit/substream.unit')
-rw-r--r--src/unit/substream.unit52
1 files changed, 52 insertions, 0 deletions
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 @@
1// vim: syntax=cpp
2/*
3 * Copyright (C) 2007-2008 Xagasoft, All rights reserved.
4 *
5 * This file is part of the libbu++ library and is released under the
6 * terms of the license contained in the file LICENSE.
7 */
8
9#include "bu/membuf.h"
10#include "bu/substream.h"
11
12{=Init}
13
14{%testRead01}
15{
16 Bu::MemBuf mb("abcdefghijklmnopqrstuvwxyz");
17 mb.seek( 4 );
18 Bu::SubStream ss( mb, 10 );
19 unitTest( ss.readLine() == "efghijklmn" );
20}
21
22{%testRead02}
23{
24 Bu::MemBuf mb("abcdefghijklmnopqrstuvwxyz");
25 mb.seek( 4 );
26 Bu::SubStream ss( mb, 10 );
27 char buf[8];
28 size_t iRead = ss.read( buf, 8 );
29 unitTest( iRead == 8 );
30 unitTest( strncmp( buf, "efghijkl", 8 ) == 0 );
31 unitTest( !ss.isEos() );
32 iRead = ss.read( buf, 8 );
33 unitTest( iRead == 2 );
34 unitTest( strncmp( buf, "mn", 2 ) == 0 );
35 unitTest( ss.isEos() );
36}
37
38{%testRead03}
39{
40 Bu::MemBuf mb("abcdefghijklmnopqrstuvwxyz");
41 mb.seek( 20 );
42 Bu::SubStream ss( mb, 10 );
43 char buf[8];
44 size_t iRead = ss.read( buf, 8 );
45 unitTest( iRead == 6 );
46 unitTest( strncmp( buf, "uvwxyz", 6 ) == 0 );
47 unitTest( ss.isEos() );
48 iRead = ss.read( buf, 8 );
49 unitTest( iRead == 0 );
50 unitTest( ss.isEos() );
51}
52