|
Packit Service |
6754ca |
//////////////////////////////////////////////////////////////////////////
|
|
Packit Service |
6754ca |
//
|
|
Packit Service |
6754ca |
// Copyright (c) 2003-2012, 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 <ImfVersion.h>
|
|
Packit Service |
6754ca |
#include <ImfTestFile.h>
|
|
Packit Service |
6754ca |
#include <ImfStdIO.h>
|
|
Packit Service |
6754ca |
#include <iostream>
|
|
Packit Service |
6754ca |
#include <exception>
|
|
Packit Service |
6754ca |
#include <stdio.h>
|
|
Packit Service |
6754ca |
#include <assert.h>
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
#ifndef ILM_IMF_TEST_IMAGEDIR
|
|
Packit Service |
6754ca |
#define ILM_IMF_TEST_IMAGEDIR
|
|
Packit Service |
6754ca |
#endif
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
using namespace OPENEXR_IMF_NAMESPACE;
|
|
Packit Service |
6754ca |
using namespace std;
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
namespace {
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
void
|
|
Packit Service |
6754ca |
testFile1 (const char fileName[], bool isImfFile)
|
|
Packit Service |
6754ca |
{
|
|
Packit Service |
6754ca |
cout << fileName << " " << flush;
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
ifstream f (fileName, ios_base::binary);
|
|
Packit Service |
6754ca |
assert (!!f);
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
char bytes[4];
|
|
Packit Service |
6754ca |
f.read (bytes, sizeof (bytes));
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
assert (!!f && isImfFile == isImfMagic (bytes));
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
cout << "is " << (isImfMagic (bytes)? "": "not ") << "an OpenEXR file\n";
|
|
Packit Service |
6754ca |
}
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
void
|
|
Packit Service |
6754ca |
testFile2 (const char fileName[], bool exists, bool exrFile, bool tiledFile)
|
|
Packit Service |
6754ca |
{
|
|
Packit Service |
6754ca |
cout << fileName << " " << flush;
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
bool exr, tiled;
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
exr = isOpenExrFile (fileName, tiled);
|
|
Packit Service |
6754ca |
assert (exr == exrFile && tiled == tiledFile);
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
exr = isOpenExrFile (fileName);
|
|
Packit Service |
6754ca |
assert (exr == exrFile);
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
tiled = isTiledOpenExrFile (fileName);
|
|
Packit Service |
6754ca |
assert (tiled == tiledFile);
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
if (exists)
|
|
Packit Service |
6754ca |
{
|
|
Packit Service |
6754ca |
StdIFStream is (fileName);
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
exr = isOpenExrFile (is, tiled);
|
|
Packit Service |
6754ca |
assert (exr == exrFile && tiled == tiledFile);
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
if (exr)
|
|
Packit Service |
6754ca |
assert (is.tellg() == 0);
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
exr = isOpenExrFile (is);
|
|
Packit Service |
6754ca |
assert (exr == exrFile);
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
if (exr)
|
|
Packit Service |
6754ca |
assert (is.tellg() == 0);
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
tiled = isTiledOpenExrFile (is);
|
|
Packit Service |
6754ca |
assert (tiled == tiledFile);
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
if (tiled)
|
|
Packit Service |
6754ca |
assert (is.tellg() == 0);
|
|
Packit Service |
6754ca |
}
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
cout << (exists? "exists": "does not exist") << ", " <<
|
|
Packit Service |
6754ca |
(exrFile? "is an OpenEXR file": "is not an OpenEXR file") << ", " <<
|
|
Packit Service |
6754ca |
(tiledFile? "is tiled": "is not tiled") << endl;
|
|
Packit Service |
6754ca |
}
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
} // namespace
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
void
|
|
Packit Service |
6754ca |
testMagic (const std::string &)
|
|
Packit Service |
6754ca |
{
|
|
Packit Service |
6754ca |
try
|
|
Packit Service |
6754ca |
{
|
|
Packit Service |
6754ca |
cout << "Testing magic number" << endl;
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
testFile1 (ILM_IMF_TEST_IMAGEDIR "comp_none.exr", true);
|
|
Packit Service |
6754ca |
testFile1 (ILM_IMF_TEST_IMAGEDIR "invalid.exr", false);
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
testFile2 (ILM_IMF_TEST_IMAGEDIR "tiled.exr", true, true, true);
|
|
Packit Service |
6754ca |
testFile2 (ILM_IMF_TEST_IMAGEDIR "comp_none.exr", true, true, false);
|
|
Packit Service |
6754ca |
testFile2 (ILM_IMF_TEST_IMAGEDIR "invalid.exr", true, false, false);
|
|
Packit Service |
6754ca |
testFile2 (ILM_IMF_TEST_IMAGEDIR "does_not_exist.exr", false, false, false);
|
|
Packit Service |
6754ca |
|
|
Packit Service |
6754ca |
cout << "ok\n" << endl;
|
|
Packit Service |
6754ca |
}
|
|
Packit Service |
6754ca |
catch (const std::exception &e)
|
|
Packit Service |
6754ca |
{
|
|
Packit Service |
6754ca |
cerr << "ERROR -- caught exception: " << e.what() << endl;
|
|
Packit Service |
6754ca |
assert (false);
|
|
Packit Service |
6754ca |
}
|
|
Packit Service |
6754ca |
}
|