/*
-----------------------------------------------------------------------------
The MIT License (MIT)

Copyright (c) 2013-09-02 Tobias Peters <tobias.peters@kreativeffekt.at>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#include <boost/test/unit_test.hpp>

#include <Ogre.h>

#include "data/QGearsCameraMatrixFileSerializer.h"

BOOST_AUTO_TEST_SUITE( QGearsCameraMatrixFileSerializer )

BOOST_AUTO_TEST_CASE( read_file )
{
    class TestFile : public QGears::CameraMatrixFile
    {
    public:
        TestFile() : QGears::CameraMatrixFile( NULL, "", 0, "" ) {}
        size_t getCalculatedSize() const { return calculateSize(); }

        virtual void unload( void ) {};
    };

	Ogre::LogManager                    logMgr;
    logMgr.createLog( "Default Log", true, true, true );

    const char*                         file_name( "reference.cam_matrix" );
    TestFile                            file;
    QGears::CameraMatrixFileSerializer  ser;
    std::ifstream *ifs(  OGRE_NEW_T( std::ifstream, Ogre::MEMCATEGORY_GENERAL )( file_name, std::ifstream::binary ) );
    BOOST_REQUIRE( ifs->is_open() );

    Ogre::DataStreamPtr stream( OGRE_NEW Ogre::FileStreamDataStream( ifs ) );
    BOOST_REQUIRE( stream->isReadable() );

    ser.importCameraMatrixFile( stream, &file );
    BOOST_CHECK_EQUAL( Ogre::Quaternion( 0.864826, 0.382658, 0.131622, 0.297191 ), file.getOrientation() );
    BOOST_CHECK_EQUAL( Ogre::Vector3( -998, 930, 5141 ), file.getPosition() );
    BOOST_CHECK_EQUAL( 0, file.getOffset().x );
    BOOST_CHECK_EQUAL( 0, file.getOffset().y );
    BOOST_CHECK_EQUAL( 703, file.getFocalLength() );
    Ogre::Quaternion dir( file.getMatrix() );
    BOOST_CHECK_EQUAL( 38, stream->tell() );

    logMgr.destroyLog( "Default Log" );
    ifs->close();
}
BOOST_AUTO_TEST_SUITE_END()
