summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2006-10-13 23:03:23 +0000
committerChris Wilson <chris+github@qwirx.com>2006-10-13 23:03:23 +0000
commit9635631135e1f0df36a0b038f047384dd9d8c8c0 (patch)
tree23c91d2ea5ba5b6e00c853bdff67cd222f7c6768 /test
parentf1ae01e66e6d2ed9072d17943fb04ccea0dbe592 (diff)
* Added support for Win32 temporary files
* Added InvisibleTempFileStream class and unit tests for it * Use InvisibleTempFileStream instead of FileStream for temporary files (refs #3)
Diffstat (limited to 'test')
-rw-r--r--test/common/testcommon.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/common/testcommon.cpp b/test/common/testcommon.cpp
index 5565b406..5a88b3f9 100644
--- a/test/common/testcommon.cpp
+++ b/test/common/testcommon.cpp
@@ -16,6 +16,7 @@
#include "FdGetLine.h"
#include "Guards.h"
#include "FileStream.h"
+#include "InvisibleTempFileStream.h"
#include "IOStreamGetLine.h"
#include "NamedLock.h"
#include "ReadGatherStream.h"
@@ -134,6 +135,54 @@ ConfigurationVerify verify =
int test(int argc, const char *argv[])
{
+ // Test self-deleting temporary file streams
+ std::string tempfile("testfiles/tempfile");
+ TEST_CHECK_THROWS(InvisibleTempFileStream fs(tempfile.c_str()),
+ CommonException, OSFileOpenError);
+ InvisibleTempFileStream fs(tempfile.c_str(), O_CREAT);
+
+#ifdef WIN32
+ // file is still visible under Windows
+ TEST_THAT(TestFileExists(tempfile.c_str()));
+
+ // opening it again should work
+ InvisibleTempFileStream fs2(tempfile.c_str());
+ TEST_THAT(TestFileExists(tempfile.c_str()));
+
+ // opening it to create should work
+ InvisibleTempFileStream fs3(tempfile.c_str(), O_CREAT);
+ TEST_THAT(TestFileExists(tempfile.c_str()));
+
+ // opening it to create exclusively should fail
+ TEST_CHECK_THROWS(InvisibleTempFileStream fs4(tempfile.c_str(),
+ O_CREAT | O_EXCL), CommonException, OSFileOpenError);
+
+#else
+ // file is not visible under Unix
+ TEST_THAT(!TestFileExists(tempfile.c_str()));
+
+ // opening it again should fail
+ TEST_CHECK_THROWS(InvisibleTempFileStream fs2(tempfile.c_str()),
+ CommonException, OSFileOpenError);
+
+ // opening it to create should work
+ InvisibleTempFileStream fs3(tempfile.c_str(), O_CREAT);
+ TEST_THAT(!TestFileExists(tempfile.c_str()));
+
+ // opening it to create exclusively should work
+ InvisibleTempFileStream fs4(tempfile.c_str(), O_CREAT | O_EXCL);
+ TEST_THAT(!TestFileExists(tempfile.c_str()));
+
+ fs4.Close();
+#endif
+
+ fs.Close();
+ fs2.Close();
+ fs3.Close();
+
+ // now that it's closed, it should be invisible on all platforms
+ TEST_THAT(!TestFileExists(tempfile.c_str()));
+
// Test memory leak detection
#ifdef BOX_MEMORY_LEAK_TESTING
{