PageRenderTime 19ms CodeModel.GetById 11ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/mordor/tests/transfer_stream.cpp

http://github.com/mozy/mordor
C++ | 43 lines | 37 code | 5 blank | 1 comment | 0 complexity | dc839d6d3d836af1bab7270e0e571c5c MD5 | raw file
 1// Copyright (c) 2009 - Mozy, Inc.
 2
 3#include "mordor/streams/memory.h"
 4#include "mordor/streams/test.h"
 5#include "mordor/streams/transfer.h"
 6#include "mordor/test/test.h"
 7
 8using namespace Mordor;
 9
10MORDOR_UNITTEST(TransferStream, exactLengthMultipleReads)
11{
12    Stream::ptr inStream(new MemoryStream());
13    TestStream::ptr testStream(new TestStream(inStream));
14    testStream->maxReadSize(2);
15    MemoryStream outStream;
16    inStream->write("hello", 5);
17    inStream->write("world", 5);
18    inStream->seek(0, Stream::BEGIN);
19    transferStream(testStream, outStream, 7);
20    MORDOR_TEST_ASSERT_EQUAL(outStream.size(), 7);
21    MORDOR_TEST_ASSERT_EQUAL(inStream->tell(), 7);
22}
23
24MORDOR_UNITTEST(TransferStream, untilEof)
25{
26    MemoryStream inStream(Buffer("hello"));
27    MemoryStream outStream;
28    MORDOR_TEST_ASSERT_EQUAL(transferStream(inStream, outStream, 10, UNTILEOF),
29        5ull);
30    inStream.seek(0);
31    MORDOR_TEST_ASSERT_EXCEPTION(transferStream(inStream, outStream, 10,
32        EXACT), UnexpectedEofException);
33    inStream.seek(0);
34    MORDOR_TEST_ASSERT_EXCEPTION(transferStream(inStream, outStream, 10),
35        UnexpectedEofException);
36}
37
38MORDOR_UNITTEST(TransferStream, inferEof)
39{
40    MemoryStream inStream(Buffer("hello"));
41    MemoryStream outStream;
42    MORDOR_TEST_ASSERT_EQUAL(transferStream(inStream, outStream), 5ull);
43}