From 1d0b240557a230cf704c8797f97ce373a3ca5474 Mon Sep 17 00:00:00 2001 From: Kimball Thurston Date: Mon, 12 Aug 2019 23:49:07 +1200 Subject: [PATCH] Use temp directory for tests under win32, properly cleanup files from util tests Signed-off-by: Kimball Thurston --- OpenEXR/IlmImfTest/main.cpp | 31 ++++++++++++++++++------ OpenEXR/IlmImfUtilTest/main.cpp | 21 +++++++++++++--- OpenEXR/IlmImfUtilTest/testDeepImage.cpp | 3 ++- OpenEXR/IlmImfUtilTest/testFlatImage.cpp | 2 +- OpenEXR/IlmImfUtilTest/testIO.cpp | 1 + 5 files changed, 45 insertions(+), 13 deletions(-) diff --git a/OpenEXR/IlmImfTest/main.cpp b/OpenEXR/IlmImfTest/main.cpp index a87366e556..e7e9153a7a 100644 --- a/OpenEXR/IlmImfTest/main.cpp +++ b/OpenEXR/IlmImfTest/main.cpp @@ -105,10 +105,12 @@ #include #include -#if defined(OPENEXR_IMF_HAVE_LINUX_PROCFS) || defined(OPENEXR_IMF_HAVE_DARWIN) - #include - #include +#ifdef _WIN32 +# include +#else +# include #endif +#include using namespace std; @@ -131,8 +133,21 @@ main (int argc, char *argv[]) while (true) { +#ifdef _WIN32 + char tmpbuf[4096]; + DWORD len = GetTempPathA (4096, tmpbuf); + if (len == 0 || len > 4095) + { + cerr << "Cannot retrieve temporary directory" << endl; + return 1; + } + tempDir = tmpbuf; + // windows does this automatically + // tempDir += IMF_PATH_SEPARATOR; + tempDir += "IlmImfTest_"; +#else tempDir = IMF_TMP_DIR "IlmImfTest_"; - +#endif for (int i = 0; i < 8; ++i) tempDir += ('A' + rand48.nexti() % 26); @@ -210,15 +225,15 @@ main (int argc, char *argv[]) //#ifdef ENABLE_IMFHUGETEST // defined via configure with --enable-imfhugetest=yes/no - #if 0 +#if 0 TEST (testDeepScanLineHuge, "deep"); - #endif +#endif std::cout << "removing temp dir " << tempDir << std::endl; rmdir (tempDir.c_str()); - #ifdef OPENEXR_IMF_HAVE_LINUX_PROCFS +#ifdef OPENEXR_IMF_HAVE_LINUX_PROCFS // // Allow the user to check for file descriptor leaks @@ -236,7 +251,7 @@ main (int argc, char *argv[]) std::cout << std::endl; - #endif +#endif return 0; } diff --git a/OpenEXR/IlmImfUtilTest/main.cpp b/OpenEXR/IlmImfUtilTest/main.cpp index dc744be48f..38ee42d2a2 100644 --- a/OpenEXR/IlmImfUtilTest/main.cpp +++ b/OpenEXR/IlmImfUtilTest/main.cpp @@ -51,8 +51,10 @@ #include #include -#if defined(OPENEXR_IMF_HAVE_LINUX_PROCFS) || defined(OPENEXR_IMF_HAVE_DARWIN) - #include +#ifdef _WIN32 +# include +#else +# include #endif using namespace std; @@ -74,8 +76,21 @@ main (int argc, char *argv[]) while (true) { +#ifdef _WIN32 + char tmpbuf[4096]; + DWORD len = GetTempPathA(4096, tmpbuf); + if ( len == 0 || len > 4095 ) + { + cerr << "Cannot retrieve temporary directory" << endl; + return 1; + } + tempDir = tmpbuf; + // windows does this automatically + // tempDir += IMF_PATH_SEPARATOR; + tempDir += "IlmImfTest_"; +#else tempDir = IMF_TMP_DIR "IlmImfTest_"; - +#endif for (int i = 0; i < 8; ++i) tempDir += ('A' + rand48.nexti() % 26); diff --git a/OpenEXR/IlmImfUtilTest/testDeepImage.cpp b/OpenEXR/IlmImfUtilTest/testDeepImage.cpp index 5e25363bd3..2b729e7236 100644 --- a/OpenEXR/IlmImfUtilTest/testDeepImage.cpp +++ b/OpenEXR/IlmImfUtilTest/testDeepImage.cpp @@ -595,8 +595,9 @@ testCropping (const string &fileName) verifyPixelsAreEqual (img3.level(0).channel ("A"), img1.level(0).channel ("A"), 0, 0); -} + remove (fileName.c_str ()); +} void testRenameChannel () diff --git a/OpenEXR/IlmImfUtilTest/testFlatImage.cpp b/OpenEXR/IlmImfUtilTest/testFlatImage.cpp index d1219b83fa..451f4c1c0e 100644 --- a/OpenEXR/IlmImfUtilTest/testFlatImage.cpp +++ b/OpenEXR/IlmImfUtilTest/testFlatImage.cpp @@ -495,9 +495,9 @@ testCropping (const string &fileName) verifyPixelsAreEqual (img3.level(0).channel ("A"), img1.level(0).channel ("A"), 0, 0); + remove (fileName.c_str ()); } - void testRenameChannel () { diff --git a/OpenEXR/IlmImfUtilTest/testIO.cpp b/OpenEXR/IlmImfUtilTest/testIO.cpp index ce9551f181..1b43d65799 100644 --- a/OpenEXR/IlmImfUtilTest/testIO.cpp +++ b/OpenEXR/IlmImfUtilTest/testIO.cpp @@ -250,4 +250,5 @@ testIO (const string &tempDir) cerr << "ERROR -- caught exception: " << e.what() << endl; assert (false); } + remove ((tempDir + "io.exr").c_str()); }