wibble
1.1
Main Page
Namespaces
Classes
Files
File List
File Members
wibble
sys
netbuffer.test.h
Go to the documentation of this file.
1
/* -*- C++ -*- (c) 2007 Petr Rockai <me@mornfall.net>
2
(c) 2007 Enrico Zini <enrico@enricozini.org> */
3
4
#include <
wibble/sys/netbuffer.h
>
5
6
#include <
wibble/test.h
>
7
#include <cstring>
8
9
using namespace
std;
10
using namespace
wibble::sys;
11
12
struct
TestNetBuffer
{
13
14
// Ensure that a plain NetBuffer starts from the beginning of the string
15
Test
startAtBeginning
() {
16
NetBuffer
buf(
"antani"
, 6);
17
18
assert_eq
(buf.
size
(), 6u);
19
assert
(memcmp(buf.
data
(),
"antani"
, 6) == 0);
20
21
assert_eq
(*buf.
cast
<
char
>(),
'a'
);
22
assert
(buf.
fits
<
short
int
>());
23
assert
(!buf.
fits
<
long
long
int
>());
24
}
25
26
// Try skipping some bytes
27
Test
skipBytes
() {
28
NetBuffer
buf(
"antani"
, 6);
29
30
NetBuffer
buf1(buf);
31
32
assert_eq
(buf1.
size
(), 6u);
33
assert
(memcmp(buf1.
data
(),
"antani"
, 6) == 0);
34
35
buf1 += 2;
36
assert_eq
(buf1.
size
(), 4u);
37
assert
(memcmp(buf1.
data
(),
"tani"
, 4) == 0);
38
assert_eq
(*buf1.
cast
<
char
>(),
't'
);
39
40
buf1 = buf + 2;
41
assert_eq
(buf1.
size
(), 4u);
42
assert
(memcmp(buf1.
data
(),
"tani"
, 4) == 0);
43
assert_eq
(*buf1.
cast
<
char
>(),
't'
);
44
45
buf1 = buf;
46
buf1.
skip
(2);
47
assert_eq
(buf1.
size
(), 4u);
48
assert
(memcmp(buf1.
data
(),
"tani"
, 4) == 0);
49
assert_eq
(*buf1.
cast
<
char
>(),
't'
);
50
51
buf1 = buf.
after
(2);
52
assert_eq
(buf1.
size
(), 4u);
53
assert
(memcmp(buf1.
data
(),
"tani"
, 4) == 0);
54
assert_eq
(*buf1.
cast
<
char
>(),
't'
);
55
56
buf1 = buf;
57
buf1.
skip
<
short
int
>();
58
assert_eq
(buf1.
size
(), 4u);
59
assert
(memcmp(buf1.
data
(),
"tani"
, 4) == 0);
60
assert_eq
(*buf1.
cast
<
char
>(),
't'
);
61
62
buf1 = buf.
after
<
short
int
>();
63
assert_eq
(buf1.
size
(), 4u);
64
assert
(memcmp(buf1.
data
(),
"tani"
, 4) == 0);
65
assert_eq
(*buf1.
cast
<
char
>(),
't'
);
66
}
67
68
};
69
70
// vim:set ts=4 sw=4:
Generated on Wed Oct 23 2013 17:14:25 for wibble by
1.8.4