1 //
2 // sio_8211Buffer_t.cpp
3 //
4 
5 #include <cassert>
6 #include <memory.h>
7 
8 #include <iostream>
9 
10 
11 
12 using namespace std;
13 
14 
15 #include <sdts++/io/sio_Buffer.h>
16 
17 
18 
19 void
copy_test(sio_Buffer buffer,vector<char> const & data)20 copy_test( sio_Buffer buffer, vector<char> const& data )
21 {
22     // should be identical to the original string
23     assert ( equal( data.begin(), data.end(), buffer.data().begin() ) );
24 }
25 
26 
27 int
main(int argc,char ** argv)28 main(int argc, char** argv)
29 {
30                                 // create a test data string and then
31                                 // convert it over to the container
32                                 // that sio_Buffer expects
33 
34     char text[] = "0123456789";
35     vector<char> data( strlen(text) );
36 
37     copy( &text[0], &text[strlen(text)], data.begin() );
38 
39     sio_Buffer buffer;
40 
41 
42     assert( buffer.addData( &data[0], data.size() ) );
43 
44 
45     // the data in the buffer should be identical to the string we used
46     // to add data to it in the first place
47 
48     assert ( equal( data.begin(), data.end(), buffer.data().begin() ) );
49 
50 
51     // now add more data
52     assert( buffer.addData( text, strlen(text) ) );
53 
54 
55     // it should be twice as big
56     assert( data.size() * 2 == buffer.length() );
57 
58     // and the second half should be identical to the original string
59     assert ( equal( buffer.data().begin() + strlen(text),
60                     buffer.data().end(), data.begin() ) );
61 
62 
63     // now blow the buffer away
64     assert ( buffer.reset() );
65 
66 
67     // the length should be zero
68     assert ( 0 == buffer.length() );
69 
70 
71 
72     // now add data again
73     assert( buffer.addData( &data[0], data.size() ) );
74 
75 
76     // again, it should be the same as the original text
77     assert( data.size() == buffer.length() );
78 
79 
80     // and it should be identical to the original string
81 
82     assert ( equal( data.begin(), data.end(), buffer.data().begin() ) );
83 
84 
85     copy_test( buffer, data );
86 
87 
88     return 0;
89 }
90