aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2016-08-05 18:42:46 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2016-08-05 18:42:46 +0300
commitb0d08082543e4a6767409232e78cb0f7b9a3ef5d (patch)
treecffaf7832c6c3cae34c897895fdb0a685128bdde
parentcf44895dc00f6a776ea716a8f1a16e1faedd9ee2 (diff)
Add empty file copy check to cpfile() test
-rw-r--r--tests/cpfile/driver.cxx25
1 files changed, 19 insertions, 6 deletions
diff --git a/tests/cpfile/driver.cxx b/tests/cpfile/driver.cxx
index 23b6fc3..0da2035 100644
--- a/tests/cpfile/driver.cxx
+++ b/tests/cpfile/driver.cxx
@@ -22,9 +22,14 @@ static string
from_file (const path& f)
{
ifdstream ifs (f, ios::binary);
-
string s;
- getline (ifs, s, '\0');
+
+ // 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');
+
ifs.close (); // Not to miss failed close of the underlying file descriptor.
return s;
}
@@ -50,15 +55,23 @@ main ()
assert (try_mkdir (td) == mkdir_status::success);
path from (td / path ("from"));
- to_file (from, text1);
+ path to (td / path ("to"));
- permissions p (path_permissions (from));
- path_permissions (from, permissions::ru | permissions::xu);
+ // Copy empty file.
+ //
+ to_file (from, "");
+ cpfile (from, to);
+ assert (from_file (to) == "");
+ assert (try_rmfile (to) == rmfile_status::success);
// Check that content and permissions of newly created destination file are
// the same as that ones of the source file.
//
- path to (td / path ("to"));
+ to_file (from, text1);
+
+ permissions p (path_permissions (from));
+ path_permissions (from, permissions::ru | permissions::xu);
+
cpfile (from, to, cpflags::none);
assert (from_file (to) == text1);
assert (path_permissions (to) == path_permissions (from));