00001 #include "util/stream/io.hh"
00002
00003 #include "util/stream/chain.hh"
00004 #include "util/file.hh"
00005
00006 #define BOOST_TEST_MODULE IOTest
00007 #include <boost/test/unit_test.hpp>
00008
00009 #include <unistd.h>
00010
00011 namespace util { namespace stream { namespace {
00012
00013 BOOST_AUTO_TEST_CASE(CopyFile) {
00014 std::string temps("io_test_temp");
00015
00016 scoped_fd in(MakeTemp(temps));
00017 for (uint64_t i = 0; i < 100000; ++i) {
00018 WriteOrThrow(in.get(), &i, sizeof(uint64_t));
00019 }
00020 SeekOrThrow(in.get(), 0);
00021 scoped_fd out(MakeTemp(temps));
00022
00023 ChainConfig config;
00024 config.entry_size = 8;
00025 config.total_memory = 1024;
00026 config.block_count = 10;
00027
00028 Chain(config) >> PRead(in.get()) >> Write(out.get());
00029
00030 SeekOrThrow(out.get(), 0);
00031 for (uint64_t i = 0; i < 100000; ++i) {
00032 uint64_t got;
00033 ReadOrThrow(out.get(), &got, sizeof(uint64_t));
00034 BOOST_CHECK_EQUAL(i, got);
00035 }
00036 }
00037
00038 }}}