Blame IlmImfUtilTest/main.cpp

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