[Box Backup-commit] COMMIT r3264 - box/trunk/test/backupstore

subversion at boxbackup.org subversion at boxbackup.org
Thu Feb 13 20:19:07 GMT 2014


Author: chris
Date: 2014-02-13 20:19:05 +0000 (Thu, 13 Feb 2014)
New Revision: 3264

Modified:
   box/trunk/test/backupstore/testbackupstore.cpp
Log:
Overwrite existing files left by previous tests.

Will help to ensure that individual test cases run properly, even if a
previous test didn't clear up after itself. Splitting up testbackupstore
into idempotent testcases is coming soon.

Modified: box/trunk/test/backupstore/testbackupstore.cpp
===================================================================
--- box/trunk/test/backupstore/testbackupstore.cpp	2014-02-11 19:36:18 UTC (rev 3263)
+++ box/trunk/test/backupstore/testbackupstore.cpp	2014-02-13 20:19:05 UTC (rev 3264)
@@ -133,6 +133,8 @@
 // file which will be moved (as well as it's old version)
 #define UPLOAD_FILE_TO_MOVE	8
 
+#define UNLINK_IF_EXISTS(filename) \
+	if (FileExists(filename)) { TEST_THAT(unlink(filename) == 0); }
 
 // Nice random data for testing written files
 class R250 {
@@ -760,7 +762,7 @@
 
 		// Write this to a file
 		{
-			FileStream f("testfiles/file1", O_WRONLY | O_CREAT | O_EXCL);
+			FileStream f("testfiles/file1", O_WRONLY | O_CREAT);
 			f.Write(encfile, sizeof(encfile));
 		}
 		
@@ -808,7 +810,7 @@
 	// Store a file -- first make the encoded file
 	BackupStoreFilenameClear store1name("file1");
 	{
-		FileStream out("testfiles/file1_upload1", O_WRONLY | O_CREAT | O_EXCL);
+		FileStream out("testfiles/file1_upload1", O_WRONLY | O_CREAT);
 		std::auto_ptr<IOStream> encoded(BackupStoreFile::EncodeFile("testfiles/file1", BackupProtocolListDirectory::RootDirectory, store1name));
 		encoded->CopyStreamTo(out);
 	}
@@ -844,6 +846,7 @@
 			filestream->CopyStreamTo(f);
 			f.SetForReading();
 			// Get and decode
+			UNLINK_IF_EXISTS("testfiles/file1_upload_retrieved");
 			BackupStoreFile::DecodeFile(f, "testfiles/file1_upload_retrieved", IOStream::TimeOutInfinite);
 		}
 
@@ -852,6 +855,8 @@
 		TEST_THAT(getobj->GetObjectID() == store1objid);
 		// BLOCK
 		{
+			UNLINK_IF_EXISTS("testfiles/file1_upload_retrieved_str");
+
 			// Get stream
 			std::auto_ptr<IOStream> filestream(protocol.ReceiveStream());
 			// Get and decode
@@ -1303,7 +1308,7 @@
 			TEST_THAT(TestGetFileSize(TEST_FILE_FOR_PATCHING) == TEST_FILE_FOR_PATCHING_SIZE);
 			FileStream in(TEST_FILE_FOR_PATCHING);
 			void *buf = ::malloc(TEST_FILE_FOR_PATCHING_SIZE);
-			FileStream out(TEST_FILE_FOR_PATCHING ".mod", O_WRONLY | O_CREAT | O_EXCL);
+			FileStream out(TEST_FILE_FOR_PATCHING ".mod", O_WRONLY | O_CREAT);
 			TEST_THAT(in.Read(buf, TEST_FILE_FOR_PATCHING_PATCH_AT) == TEST_FILE_FOR_PATCHING_PATCH_AT);
 			out.Write(buf, TEST_FILE_FOR_PATCHING_PATCH_AT);
 			char insert[13] = "INSERTINSERT";
@@ -1357,7 +1362,7 @@
 			TEST_THAT(isCompletelyDifferent == false);
 			// Sent this to a file, so we can check the size, rather than uploading it directly
 			{
-				FileStream patch(TEST_FILE_FOR_PATCHING ".patch", O_WRONLY | O_CREAT | O_EXCL);
+				FileStream patch(TEST_FILE_FOR_PATCHING ".patch", O_WRONLY | O_CREAT);
 				patchstream->CopyStreamTo(patch);
 			}
 			// Make sure the stream is a plausible size for a patch containing only one new block
@@ -1815,13 +1820,13 @@
 		
 		// The test block to a file
 		{
-			FileStream f("testfiles/testenc1", O_WRONLY | O_CREAT | O_EXCL);
+			FileStream f("testfiles/testenc1", O_WRONLY | O_CREAT);
 			f.Write(encfile, sizeof(encfile));
 		}
 		
 		// Encode it
 		{
-			FileStream out("testfiles/testenc1_enc", O_WRONLY | O_CREAT | O_EXCL);
+			FileStream out("testfiles/testenc1_enc", O_WRONLY | O_CREAT);
 			BackupStoreFilenameClear name("testfiles/testenc1");
 
 			std::auto_ptr<IOStream> encoded(BackupStoreFile::EncodeFile("testfiles/testenc1", 32, name));
@@ -1836,6 +1841,7 @@
 		
 		// Decode it
 		{
+			UNLINK_IF_EXISTS("testfiles/testenc1_orig");
 			FileStream enc("testfiles/testenc1_enc");
 			BackupStoreFile::DecodeFile(enc, "testfiles/testenc1_orig", IOStream::TimeOutInfinite);
 		}
@@ -1865,7 +1871,7 @@
 		// Test that the last block in a file, if less than 256 bytes, gets put into the last block
 		{
 			#define FILE_SIZE_JUST_OVER	((4096*2)+58)
-			FileStream f("testfiles/testenc2", O_WRONLY | O_CREAT | O_EXCL);
+			FileStream f("testfiles/testenc2", O_WRONLY | O_CREAT);
 			f.Write(encfile + 2, FILE_SIZE_JUST_OVER);
 			BackupStoreFilenameClear name("testenc2");
 			std::auto_ptr<IOStream> encoded(BackupStoreFile::EncodeFile("testfiles/testenc2", 32, name));
@@ -1899,6 +1905,7 @@
 #ifndef WIN32 // no symlinks on Win32
 		// Try out doing this on a symlink
 		{
+			UNLINK_IF_EXISTS("testfiles/testsymlink");
 			TEST_THAT(::symlink("does/not/exist", "testfiles/testsymlink") == 0);
 			BackupStoreFilenameClear name("testsymlink");
 			std::auto_ptr<IOStream> encoded(BackupStoreFile::EncodeFile("testfiles/testsymlink", 32, name));
@@ -1908,6 +1915,7 @@
 			encoded->CopyStreamTo(b);
 			b.SetForReading();
 			// Decode it
+			UNLINK_IF_EXISTS("testfiles/testsymlink_2");
 			BackupStoreFile::DecodeFile(b, "testfiles/testsymlink_2", IOStream::TimeOutInfinite);
 		}
 #endif




More information about the Boxbackup-commit mailing list