test_VGearsWalkmeshFileXMLSerializer.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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/VGearsWalkmeshFileXMLSerializer.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 VGears::WalkmeshFile::calculateSize(); }
  25. virtual void unload( void ) {}
  26. };
  27. const char* file_name( "misc/walkmesh.xml" );
  28. std::ifstream ifs( file_name, std::ifstream::binary );
  29. BOOST_REQUIRE( ifs.is_open() );
  30. Ogre::DataStreamPtr stream( OGRE_NEW Ogre::FileStreamDataStream( &ifs, false ) );
  31. BOOST_REQUIRE( stream->isReadable() );
  32. Ogre::LogManager logMgr;
  33. VGears::WalkmeshFileXMLSerializer 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( 2, triangles.size() );
  39. VGears::WalkmeshFile::Triangle &t1( triangles.front() );
  40. BOOST_CHECK_EQUAL( Ogre::Vector3( 1, 2, 4 ), t1.a );
  41. BOOST_CHECK_EQUAL( Ogre::Vector3( 8, 16, 32 ), t1.b );
  42. BOOST_CHECK_EQUAL( Ogre::Vector3( 64, 128, 256 ), t1.c );
  43. BOOST_CHECK_EQUAL( 1, 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( 4, 2, 1 ), t2.a );
  48. BOOST_CHECK_EQUAL( Ogre::Vector3( 32, 16, 8 ), t2.b );
  49. BOOST_CHECK_EQUAL( Ogre::Vector3( 256, 128, 64 ), t2.c );
  50. BOOST_CHECK_EQUAL( -1, t2.access_side[0] );
  51. BOOST_CHECK_EQUAL( 0, t2.access_side[1] );
  52. BOOST_CHECK_EQUAL( -1, t2.access_side[2] );
  53. logMgr.destroyLog( "Default Log" );
  54. ifs.close();
  55. }