summaryrefslogtreecommitdiff
path: root/src/unit/substream.unit
blob: 802ad4c5e74ed7df28ec90cee8e9d7d0e2b948bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// vim: syntax=cpp
/*
 * Copyright (C) 2007-2010 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() );
}