From c7ec29b2d6a66700933ede6ae2371e1d54744d67 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 30 May 2017 19:05:43 +0300 Subject: Add ifdstream::read_text() and ifdstream::read_binary() --- tests/cpfile/driver.cxx | 9 +-------- tests/fdstream/driver.cxx | 3 +-- tests/openssl/driver.cxx | 5 ++--- tests/process/driver.cxx | 12 +++--------- 4 files changed, 7 insertions(+), 22 deletions(-) (limited to 'tests') diff --git a/tests/cpfile/driver.cxx b/tests/cpfile/driver.cxx index 6fa1567..3a19322 100644 --- a/tests/cpfile/driver.cxx +++ b/tests/cpfile/driver.cxx @@ -22,14 +22,7 @@ static string from_file (const path& f) { ifdstream ifs (f, ios::binary); - string s; - - // Note that the eof check is important: if the stream is at eof (empty - // file) then getline() will fail. - // - if (ifs.peek () != ifdstream::traits_type::eof ()) - getline (ifs, s, '\0'); - + string s (ifs.read_text ()); ifs.close (); // Not to miss failed close of the underlying file descriptor. return s; } diff --git a/tests/fdstream/driver.cxx b/tests/fdstream/driver.cxx index c8748b1..41a39b0 100644 --- a/tests/fdstream/driver.cxx +++ b/tests/fdstream/driver.cxx @@ -37,8 +37,7 @@ static const string text3 ("ABCDEF\r\nXYZ"); static string from_stream (ifdstream& is) { - string s; - getline (is, s, '\0'); + string s (is.read_text ()); is.close (); // Not to miss failed close of the underlying file descriptor. return s; } diff --git a/tests/openssl/driver.cxx b/tests/openssl/driver.cxx index 769c77e..b0e37ae 100644 --- a/tests/openssl/driver.cxx +++ b/tests/openssl/driver.cxx @@ -22,10 +22,9 @@ try { openssl os (nullfd, path ("-"), 2, path ("openssl"), "rand", 128); - vector r - ((istreambuf_iterator (os.in)), istreambuf_iterator ()); - + vector r (os.in.read_binary ()); os.in.close (); + return os.wait () && r.size () == 128 ? 0 : 1; } catch (const system_error& e) diff --git a/tests/process/driver.cxx b/tests/process/driver.cxx index b154bce..4694d5b 100644 --- a/tests/process/driver.cxx +++ b/tests/process/driver.cxx @@ -94,9 +94,7 @@ exec (const path& p, cwd, args.data (), pr, bin_mode (move (pr3.out_fd)).get (), -2); ifdstream is (bin_mode (move (pr3.in_ofd))); - - o = vector ( - (istreambuf_iterator (is)), istreambuf_iterator ()); + o = is.read_binary (); r = pr2.wait () && r; r = pr3.wait () && r; @@ -104,9 +102,7 @@ exec (const path& p, else { ifdstream is (bin_mode (move (pr.in_ofd))); - - o = vector ( - (istreambuf_iterator (is)), istreambuf_iterator ()); + o = is.read_binary (); } if (err) @@ -125,9 +121,7 @@ exec (const path& p, if (err && !out) { ifdstream is (bin_mode (move (pr.in_efd))); - - vector e - ((istreambuf_iterator (is)), istreambuf_iterator ()); + vector e (is.read_binary ()); r = in == e && r; } -- cgit v1.1