test_FF7WalkmeshFileSerializer.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. -----------------------------------------------------------------------------
  3. Copyright (c) 06.10.2013 Tobias Peters <tobias.peters@kreativeffekt.at>
  4. This file is part of V-Gears
  5. V-Gears is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, version 2.0 (GPLv2) of the License.
  8. V-Gears is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. -----------------------------------------------------------------------------
  13. */
  14. #include <fstream>
  15. #include <boost/test/unit_test.hpp>
  16. #include <Ogre.h>
  17. #include "map/FF7WalkmeshFileSerializer.h"
  18. BOOST_AUTO_TEST_CASE( read_file )
  19. {
  20. class TestFile : public VGears::WalkmeshFile
  21. {
  22. public:
  23. TestFile() : VGears::WalkmeshFile( NULL, "", 0, "" ) {}
  24. size_t getCalculatedSize() const { return calculateSize(); }
  25. virtual void unload( void ) {}
  26. };
  27. const char* file_name( "misc/reference.walkmesh" );
  28. std::ifstream *ifs( OGRE_NEW_T( std::ifstream, Ogre::MEMCATEGORY_GENERAL )( file_name, std::ifstream::binary ) );
  29. BOOST_REQUIRE( ifs->is_open() );
  30. Ogre::DataStreamPtr stream( OGRE_NEW Ogre::FileStreamDataStream( ifs ) );
  31. BOOST_REQUIRE( stream->isReadable() );
  32. Ogre::LogManager logMgr;
  33. VGears::WalkmeshFileSerializer ser;
  34. TestFile f;
  35. logMgr.createLog( "Default Log", true, true, true );
  36. ser.importWalkmeshFile( stream, &f );
  37. VGears::WalkmeshFile::TriangleList &triangles( f.getTriangles() );
  38. BOOST_CHECK_EQUAL( 39, triangles.size() );
  39. VGears::WalkmeshFile::Triangle &t1( triangles.front() );
  40. BOOST_CHECK_EQUAL( Ogre::Vector3( 3784, 27544, 325 ), t1.a );
  41. BOOST_CHECK_EQUAL( Ogre::Vector3( 3778, 27434, 325 ), t1.b );
  42. BOOST_CHECK_EQUAL( Ogre::Vector3( 3751, 27410, 310 ), t1.c );
  43. BOOST_CHECK_EQUAL( 26, t1.access_side[0] );
  44. BOOST_CHECK_EQUAL( -1, t1.access_side[1] );
  45. BOOST_CHECK_EQUAL( 1, t1.access_side[2] );
  46. VGears::WalkmeshFile::Triangle &t2( triangles.back() );
  47. BOOST_CHECK_EQUAL( Ogre::Vector3( 3506, 29251, 432 ), t2.a );
  48. BOOST_CHECK_EQUAL( Ogre::Vector3( 3527, 29405, 432 ), t2.b );
  49. BOOST_CHECK_EQUAL( Ogre::Vector3( 3566, 29245, 400 ), t2.c );
  50. BOOST_CHECK_EQUAL( -1, t2.access_side[0] );
  51. BOOST_CHECK_EQUAL( 37, t2.access_side[1] );
  52. BOOST_CHECK_EQUAL( -1, t2.access_side[2] );
  53. BOOST_CHECK_EQUAL( 1174, stream->tell() );
  54. logMgr.destroyLog( "Default Log" );
  55. ifs->close();
  56. }