LRAUV  revA
StrIOStream_Test.h
Go to the documentation of this file.
1 
9 #ifndef _STRIOSTREAM_TEST_H_
10 #define _STRIOSTREAM_TEST_H_
11 
12 #include "StrIOStream.h"
13 
14 #include <cxxtest/TestSuite.h>
15 
21 class StrIOStream_Test : public CxxTest::TestSuite
22 {
23 public:
24 
25  // dummy test
26  void testWrite( void )
27  {
28  Str str;
29  StrIOStream strIOStream( str );
30  strIOStream << "Hello";
31  TS_ASSERT_EQUALS( str, "Hello" );
32  TS_ASSERT_EQUALS( strIOStream.bytesWritten(), 5U );
33 
34  strIOStream.write( " Worldly", 6 );
35  TS_ASSERT_EQUALS( str, "Hello World" );
36  TS_ASSERT_EQUALS( strIOStream.bytesWritten(), 6U );
37  }
38 
40  {
41  Str str;
42  StrIOStream strIOStream( str );
43  unsigned short foo( ( ( '<' >> 2 ) << 8 ) | ( 'E' >> 2 ) );
44  strIOStream.writeUShortCompact( foo );
45  TS_ASSERT_EQUALS( str, "E<" );
46 
47  str = Str::EMPTY_STR;
48  unsigned short bar( '*' >> 1 | 1 );
49  strIOStream.writeUShortCompact( bar );
50  TS_ASSERT_EQUALS( str, "*" );
51 
52  }
53 
54  void testLongLongCompact( void )
55  {
56  const int nValues = 16;
57  long long values[nValues] = { -0x1234567812345678LL,
58  -0x12345678123456LL,
59  -0x123456781234LL,
60  -0x1234567812LL,
61  -0x12345678LL,
62  -0x123456LL,
63  -0x1234LL,
64  -0x12LL,
65  0x12LL,
66  0x1234LL,
67  0x123456LL,
68  0x12345678LL,
69  0x1234567812LL,
70  0x123456781234LL,
71  0x12345678123456LL,
72  0x1234567812345678LL,
73  };
74 
75  Str str;
76  StrIOStream strIOStream( str );
77  for( int i = 0; i < nValues; ++i )
78  {
79  long long value = values[i];
80  strIOStream.writeLongLongCompact( value );
81  long long newValue;
82  strIOStream.readLongLongCompact( newValue );
83  TS_ASSERT_EQUALS( value, newValue );
84  strIOStream.clear();
85  }
86  }
87 
88  void testRead( void )
89  {
90  Str str( "Hello World" );
91  StrIOStream strIOStream( str );
92  char buffer[16];
93 
94  strIOStream.read( buffer, 5 );
95  TS_ASSERT_SAME_DATA( buffer, "Hello", 5 );
96  TS_ASSERT_EQUALS( strIOStream.bytesRead(), 5U );
97 
98  strIOStream.read( buffer, 20 );
99  TS_ASSERT_SAME_DATA( buffer, " World", 6 );
100  TS_ASSERT_EQUALS( strIOStream.bytesRead(), 6U );
101 
102 
103  }
104 
105  void testReadUntil( void )
106  {
107  Str str( "Hello World" );
108  StrIOStream strIOStream( str );
109  char buffer[16];
110 
111  strIOStream.readUntil( buffer, 11, 'o' );
112  TS_ASSERT_SAME_DATA( buffer, "Hello", 6 );
113  TS_ASSERT_EQUALS( strIOStream.bytesRead(), 5U );
114 
115  strIOStream.readUntil( buffer, 6, '~' );
116  TS_ASSERT_SAME_DATA( buffer, " World", 6 );
117  TS_ASSERT_EQUALS( strIOStream.bytesRead(), 6U );
118 
119  }
120 
121 };
122 
123 #endif // _STRIOSTREAM_TEST_H
virtual OutStream & write(const char *buffer, size_t num)
writes num bytes from buffer to the output buffer/stream
Definition: StrIOStream.h:84
size_t bytesRead()
Indicates the number of bytes read in the last operation.
Definition: InStream.h:162
OutStream & writeUShortCompact(const unsigned short &value)
writes an unsigned short integer as 1 to 3 bytes, encoded as follows: xxxxxxx0 - 7 bit value...
Definition: OutStream.cpp:86
void clear()
Definition: StrIOStream.h:60
void testWrite(void)
Definition: StrIOStream_Test.h:26
virtual InStream & read(char *buffer, size_t num)
reads num bytes from stream to the buffer
Definition: StrIOStream.h:38
void testWriteUShortCompact(void)
Definition: StrIOStream_Test.h:39
OutStream & writeLongLongCompact(const long long &value)
writes a signed long long integer as 1 to 9 bytes, encoded as follows: 0xxxxxxx - 7 bit value...
Definition: OutStream.cpp:121
Wraps a Str with an IOStream class.
Definition: StrIOStream.h:24
Replacement for standard template class string.
Definition: Str.h:12
InStream & readLongLongCompact(long long &value)
reads a signed long long integer as 1 to 9 bytes, encoded as follows: 0xxxxxxx - 7 bit value...
Definition: InStream.cpp:130
Unit tests for StrIOStream class.
Definition: StrIOStream_Test.h:21
void testRead(void)
Definition: StrIOStream_Test.h:88
void testReadUntil(void)
Definition: StrIOStream_Test.h:105
static const Str EMPTY_STR
Definition: Str.h:19
size_t bytesWritten()
Definition: OutStream.h:203
void testLongLongCompact(void)
Definition: StrIOStream_Test.h:54
Contains the StrIOStream class declaration.
virtual InStream & readUntil(char *buf, unsigned int num, unsigned char match)
Definition: InStream.cpp:242