| 230 | } |
| 231 | |
| 232 | void 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 | |
| 273 | void SC::FileSystemTest::copyDirectoryRecursive() |
| 274 | { |
nothing calls this directly
no test coverage detected