Skip to content

Commit

Permalink
Use temp directory for tests under win32, properly cleanup files from…
Browse files Browse the repository at this point in the history
… util tests

Signed-off-by: Kimball Thurston <kdt3rd@gmail.com>
  • Loading branch information
kdt3rd committed Aug 12, 2019
1 parent 02fbde4 commit 1d0b240
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
31 changes: 23 additions & 8 deletions OpenEXR/IlmImfTest/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@
#include <string.h>
#include <time.h>

#if defined(OPENEXR_IMF_HAVE_LINUX_PROCFS) || defined(OPENEXR_IMF_HAVE_DARWIN)
#include <unistd.h>
#include <sstream>
#ifdef _WIN32
# include <windows.h>
#else
# include <unistd.h>
#endif
#include <sstream>

using namespace std;

Expand All @@ -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);

Expand Down Expand Up @@ -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
Expand All @@ -236,7 +251,7 @@ main (int argc, char *argv[])

std::cout << std::endl;

#endif
#endif

return 0;
}
21 changes: 18 additions & 3 deletions OpenEXR/IlmImfUtilTest/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@
#include <cstring>
#include <time.h>

#if defined(OPENEXR_IMF_HAVE_LINUX_PROCFS) || defined(OPENEXR_IMF_HAVE_DARWIN)
#include <unistd.h>
#ifdef _WIN32
# include <windows.h>
#else
# include <unistd.h>
#endif

using namespace std;
Expand All @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion OpenEXR/IlmImfUtilTest/testDeepImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,9 @@ testCropping (const string &fileName)
verifyPixelsAreEqual <half> (img3.level(0).channel ("A"),
img1.level(0).channel ("A"),
0, 0);
}

remove (fileName.c_str ());
}

void
testRenameChannel ()
Expand Down
2 changes: 1 addition & 1 deletion OpenEXR/IlmImfUtilTest/testFlatImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,9 @@ testCropping (const string &fileName)
verifyPixelsAreEqual <half> (img3.level(0).channel ("A"),
img1.level(0).channel ("A"),
0, 0);
remove (fileName.c_str ());
}


void
testRenameChannel ()
{
Expand Down
1 change: 1 addition & 0 deletions OpenEXR/IlmImfUtilTest/testIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,5 @@ testIO (const string &tempDir)
cerr << "ERROR -- caught exception: " << e.what() << endl;
assert (false);
}
remove ((tempDir + "io.exr").c_str());
}

0 comments on commit 1d0b240

Please sign in to comment.