PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms 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
Possible License(s): BSD-3-Clause
  1. // Copyright (c) 2009 - Mozy, Inc.
  2. #include "mordor/streams/memory.h"
  3. #include "mordor/streams/test.h"
  4. #include "mordor/streams/transfer.h"
  5. #include "mordor/test/test.h"
  6. using namespace Mordor;
  7. MORDOR_UNITTEST(TransferStream, exactLengthMultipleReads)
  8. {
  9. Stream::ptr inStream(new MemoryStream());
  10. TestStream::ptr testStream(new TestStream(inStream));
  11. testStream->maxReadSize(2);
  12. MemoryStream outStream;
  13. inStream->write("hello", 5);
  14. inStream->write("world", 5);
  15. inStream->seek(0, Stream::BEGIN);
  16. transferStream(testStream, outStream, 7);
  17. MORDOR_TEST_ASSERT_EQUAL(outStream.size(), 7);
  18. MORDOR_TEST_ASSERT_EQUAL(inStream->tell(), 7);
  19. }
  20. MORDOR_UNITTEST(TransferStream, untilEof)
  21. {
  22. MemoryStream inStream(Buffer("hello"));
  23. MemoryStream outStream;
  24. MORDOR_TEST_ASSERT_EQUAL(transferStream(inStream, outStream, 10, UNTILEOF),
  25. 5ull);
  26. inStream.seek(0);
  27. MORDOR_TEST_ASSERT_EXCEPTION(transferStream(inStream, outStream, 10,
  28. EXACT), UnexpectedEofException);
  29. inStream.seek(0);
  30. MORDOR_TEST_ASSERT_EXCEPTION(transferStream(inStream, outStream, 10),
  31. UnexpectedEofException);
  32. }
  33. MORDOR_UNITTEST(TransferStream, inferEof)
  34. {
  35. MemoryStream inStream(Buffer("hello"));
  36. MemoryStream outStream;
  37. MORDOR_TEST_ASSERT_EQUAL(transferStream(inStream, outStream), 5ull);
  38. }