still must match obs first
[ghsmtp.git] / SockBuffer-test.cpp
blob643101ed02cecbce267449080fe1249bfb4d518e
1 #include "SockBuffer.hpp"
3 #include <fcntl.h>
5 #include <fstream>
6 #include <iostream>
8 #include <fmt/format.h>
10 #include <glog/logging.h>
12 int main(int argc, char* argv[])
14 constexpr auto infile = "body.txt";
16 int fd_in = open(infile, O_RDONLY);
17 PCHECK(fd_in != -1) << "Can't open file " << infile;
19 char outfile[] = "/tmp/SockBuffer-test-XXXXXX";
21 int fd_out = mkstemp(outfile);
22 PCHECK(fd_out != -1);
24 auto read_hook = []() { std::cout << "read_hook\n"; };
26 boost::iostreams::stream<SockBuffer> iostream{fd_in,
27 fd_out,
28 read_hook,
29 std::chrono::seconds(10),
30 std::chrono::seconds(10),
31 std::chrono::seconds(1)};
33 std::string line;
34 while (std::getline(iostream, line)) {
35 iostream << line << '\n';
37 iostream.clear(); // unset eof bit, if set will short-circut flush
38 iostream << std::flush;
40 auto const diff_cmd{fmt::format("diff {} {}", infile, outfile)};
41 CHECK_EQ(system(diff_cmd.c_str()), 0);
43 PCHECK(!unlink(outfile)) << "unlink failed for " << outfile;
45 std::cout << "sizeof(SockBuffer) == " << sizeof(SockBuffer) << '\n';