MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / copyExistsFile

Method copyExistsFile

Tests/Libraries/FileSystem/FileSystemTest.cpp:232–271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

230}
231
232void SC::FileSystemTest::copyExistsFile()
233{
234 //! [copyExistsFileSnippet]
235 FileSystem fs;
236 // Make all operations relative to applicationRootDirectory
237 SC_TEST_EXPECT(fs.init(report.applicationRootDirectory.view()));
238
239 // Create a File names 'sourceFile.txt'
240 StringView contentSource = "this is some content";
241 SC_TEST_EXPECT(not fs.exists("sourceFile.txt"));
242 SC_TEST_EXPECT(fs.writeString("sourceFile.txt", contentSource));
243
244 // Check that 'sourceFile.txt' exist, but not 'destinationFile.txt'
245 SC_TEST_EXPECT(fs.existsAndIsFile("sourceFile.txt"));
246 SC_TEST_EXPECT(not fs.exists("destinationFile.txt"));
247
248 // Ask to copy sourceFile.txt to destinationFile.txt (eventually overwriting, but without cloning)
249 SC_TEST_EXPECT(fs.copyFile("sourceFile.txt", "destinationFile.txt",
250 FileSystem::CopyFlags().setOverwrite(true).setUseCloneIfSupported(false)));
251
252 // Now read the destinationFile.txt content and check if it's the same as source
253 String content = StringEncoding::Ascii;
254 SC_TEST_EXPECT(fs.read("destinationFile.txt", content));
255 SC_TEST_EXPECT(content.view() == contentSource);
256
257 // Copy again sourceFile.txt to destinationFile.txt but using clone this time
258 SC_TEST_EXPECT(fs.copyFile("sourceFile.txt", "destinationFile.txt",
259 FileSystem::CopyFlags().setOverwrite(true).setUseCloneIfSupported(true)));
260
261 // Check again if file exists and its content
262 SC_TEST_EXPECT(fs.existsAndIsFile("destinationFile.txt"));
263 SC_TEST_EXPECT(fs.read("destinationFile.txt", content));
264 SC_TEST_EXPECT(content.view() == contentSource);
265
266 // Remove all files created by the test
267 SC_TEST_EXPECT(fs.removeFiles({"sourceFile.txt", "destinationFile.txt"}));
268 SC_TEST_EXPECT(not fs.exists("sourceFile.txt"));
269 SC_TEST_EXPECT(not fs.exists("destinationFile.txt"));
270 //! [copyExistsFileSnippet]
271}
272
273void SC::FileSystemTest::copyDirectoryRecursive()
274{

Callers

nothing calls this directly

Calls 8

existsMethod · 0.80
existsAndIsFileMethod · 0.80
removeFilesMethod · 0.80
initMethod · 0.45
viewMethod · 0.45
writeStringMethod · 0.45
copyFileMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected