Blame IlmImfUtilTest/main.cpp

Packit 0d464f
///////////////////////////////////////////////////////////////////////////
Packit 0d464f
//
Packit 0d464f
// Copyright (c) 2014, Industrial Light & Magic, a division of Lucas
Packit 0d464f
// Digital Ltd. LLC
Packit 0d464f
// 
Packit 0d464f
// All rights reserved.
Packit 0d464f
// 
Packit 0d464f
// Redistribution and use in source and binary forms, with or without
Packit 0d464f
// modification, are permitted provided that the following conditions are
Packit 0d464f
// met:
Packit 0d464f
// *       Redistributions of source code must retain the above copyright
Packit 0d464f
// notice, this list of conditions and the following disclaimer.
Packit 0d464f
// *       Redistributions in binary form must reproduce the above
Packit 0d464f
// copyright notice, this list of conditions and the following disclaimer
Packit 0d464f
// in the documentation and/or other materials provided with the
Packit 0d464f
// distribution.
Packit 0d464f
// *       Neither the name of Industrial Light & Magic nor the names of
Packit 0d464f
// its contributors may be used to endorse or promote products derived
Packit 0d464f
// from this software without specific prior written permission. 
Packit 0d464f
// 
Packit 0d464f
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit 0d464f
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit 0d464f
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Packit 0d464f
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Packit 0d464f
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Packit 0d464f
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Packit 0d464f
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit 0d464f
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit 0d464f
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit 0d464f
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit 0d464f
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 0d464f
//
Packit 0d464f
///////////////////////////////////////////////////////////////////////////
Packit 0d464f
Packit 0d464f
#include "ImfNamespace.h"
Packit 0d464f
Packit 0d464f
#include "testFlatImage.h"
Packit 0d464f
#include "testDeepImage.h"
Packit 0d464f
#include "testIO.h"
Packit 0d464f
#include "tmpDir.h"
Packit 0d464f
#include <ImathRandom.h>
Packit 0d464f
Packit 0d464f
#include <cerrno>
Packit 0d464f
#include <cstdlib>
Packit 0d464f
#include <iostream>
Packit 0d464f
#include <cstring>
Packit 0d464f
#include <time.h>
Packit 0d464f
Packit 0d464f
#if defined(OPENEXR_IMF_HAVE_LINUX_PROCFS) || defined(OPENEXR_IMF_HAVE_DARWIN)
Packit 0d464f
    #include <unistd.h>
Packit 0d464f
#endif
Packit 0d464f
Packit 0d464f
using namespace std;
Packit 0d464f
Packit 0d464f
#define TEST(test) {if (argc < 2 || !strcmp (argv[1], #test)) test(tempDir);}
Packit 0d464f
Packit 0d464f
Packit 0d464f
int
Packit 0d464f
main (int argc, char *argv[])
Packit 0d464f
{
Packit 0d464f
    //
Packit 0d464f
    // Create temporary files in a uniquely named private temporary
Packit 0d464f
    // subdirectory of IMF_TMP_DIR to avoid colliding with other running
Packit 0d464f
    // instances of this program.
Packit 0d464f
    //
Packit 0d464f
Packit 0d464f
    IMATH_NAMESPACE::Rand48 rand48 (time ((time_t*)0) );
Packit 0d464f
    std::string tempDir;
Packit 0d464f
Packit 0d464f
    while (true)
Packit 0d464f
    {
Packit 0d464f
        tempDir = IMF_TMP_DIR "IlmImfTest_";
Packit 0d464f
Packit 0d464f
        for (int i = 0; i < 8; ++i)
Packit 0d464f
            tempDir += ('A' + rand48.nexti() % 26);
Packit 0d464f
Packit 0d464f
        if (mkdir (tempDir.c_str(), 0777) == 0)
Packit 0d464f
        {
Packit 0d464f
            tempDir += IMF_PATH_SEPARATOR;
Packit 0d464f
            break; // success
Packit 0d464f
        }
Packit 0d464f
Packit 0d464f
        if (errno != EEXIST)
Packit 0d464f
        {
Packit 0d464f
            cerr << "Cannot create directory " << tempDir << ". " <<
Packit 0d464f
                    strerror (errno) << endl;
Packit 0d464f
Packit 0d464f
            return 1;
Packit 0d464f
        }
Packit 0d464f
    }
Packit 0d464f
Packit 0d464f
    cout << "using temporary directory " << tempDir << endl;
Packit 0d464f
Packit 0d464f
    TEST (testFlatImage);
Packit 0d464f
    TEST (testDeepImage);
Packit 0d464f
    TEST (testIO);
Packit 0d464f
Packit 0d464f
    cout << "removing temporary directory " << tempDir << endl;
Packit 0d464f
    rmdir (tempDir.c_str());
Packit 0d464f
Packit 0d464f
    return 0;
Packit 0d464f
}