From b0d08082543e4a6767409232e78cb0f7b9a3ef5d Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 5 Aug 2016 18:42:46 +0300 Subject: Add empty file copy check to cpfile() test --- tests/cpfile/driver.cxx | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'tests') 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)); -- cgit v1.1