LRAUV  revA
MappedIOStream_Test.h
Go to the documentation of this file.
1 
9 #ifndef _MAPPEDIOSTREAM_TEST_H_
10 #define _MAPPEDIOSTREAM_TEST_H_
11 
12 #include "MappedIOStream.h"
13 
14 #include <sys/stat.h>
15 
16 #include <cxxtest/TestSuite.h>
17 
23 class MappedIOStream_Test : public CxxTest::TestSuite
24 {
25 public:
26 
27  void test1Write( void )
28  {
29  MappedIOStream stream( "MappedIOStream_Test.log", true, 8 );
30  stream << "Hello";
31  TS_ASSERT_EQUALS( stream.bytesWritten(), 5U );
32  stream.write( " Worldly", 6 );
33  TS_ASSERT_EQUALS( stream.bytesWritten(), 6U );
34 
35  const struct stat statBuf( stream.getStat() );
36  TS_ASSERT_EQUALS( statBuf.st_size, 16 );
37  }
38 
39  void test2Read( void )
40  {
41  MappedIOStream stream( "MappedIOStream_Test.log", false, 8 );
42  Str str;
43  char buffer[16];
44  stream.read( buffer, 16 );
45  TS_ASSERT_EQUALS( stream.bytesRead(), 16U );
46  TS_ASSERT_SAME_DATA( buffer, "Hello World", 12 );
47 
48  stream.seek( 4 );
49  char buf[4];
50  buf[3] = 0;
51  stream.read( buf, 3 );
52  TS_ASSERT_EQUALS( stream.bytesRead(), 3U );
53  TS_ASSERT_SAME_DATA( buf, "o W", 4 );
54 
55  remove( "MappedIOStream_Test.log" );
56  }
57 
58 };
59 
60 #endif // _MAPPEDIOSTREAM_TEST_H
bool seek(unsigned int location)
Definition: MappedIOStream.cpp:66
size_t bytesRead()
Indicates the number of bytes read in the last operation.
Definition: InStream.h:162
Replacement for standard template class string.
Definition: Str.h:12
Contains the MappedIOStream class declaration.
virtual IOStream & read(char *buffer, size_t num)
reads num bytes from buffer to the output buffer/stream
Definition: MappedIOStream.cpp:38
size_t bytesWritten()
Definition: OutStream.h:203
void test2Read(void)
Definition: MappedIOStream_Test.h:39
void test1Write(void)
Definition: MappedIOStream_Test.h:27
IOStream & write(const char *buffer, size_t num)
writes num bytes from buffer to the output buffer/stream
Definition: MappedIOStream.cpp:92
Wraps Memory mapped file with an IOStream class.
Definition: MappedIOStream.h:27
Unit tests for MappedIOStream class.
Definition: MappedIOStream_Test.h:23