test_QGearsMapFileXMLSerializer.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. -----------------------------------------------------------------------------
  3. Copyright (c) 27.10.2013 Tobias Peters <tobias.peters@kreativeffekt.at>
  4. This file is part of Q-Gears
  5. Q-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. Q-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/QGearsMapFileXMLSerializer.h"
  18. BOOST_AUTO_TEST_CASE( read_file )
  19. {
  20. class TestFile : public QGears::MapFile
  21. {
  22. public:
  23. TestFile() : QGears::MapFile( NULL, "", 0, "" ) {}
  24. size_t getCalculatedSize() const { return calculateSize(); }
  25. virtual void unload( void ) {}
  26. };
  27. const char* file_name( "misc/map.xml" );
  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. QGears::MapFileXMLSerializer ser;
  34. TestFile f;
  35. logMgr.createLog( "Default Log", true, true, true );
  36. ser.importMapFile( stream, &f );
  37. BOOST_CHECK_EQUAL( "path/to/script.lua" , f.getScriptName() );
  38. BOOST_CHECK_EQUAL( "background_2d_resource_name", f.getBackground2dName() );
  39. BOOST_CHECK_EQUAL( "walkmesh_resource_name" , f.getWalkmeshName() );
  40. BOOST_CHECK_CLOSE( -5.625, f.getForwardDirection(), 0.001 );
  41. QGears::MapFile::PointList &points( f.getPoints() );
  42. BOOST_REQUIRE_EQUAL( 1, points.size() );
  43. QGears::MapFile::PointList::value_type &point( points.at(0) );
  44. BOOST_CHECK_EQUAL( "Spawn_md1_1", point.GetName() );
  45. BOOST_CHECK( Ogre::Vector3( 29.0547f, 229.234f, 2.56082f ).positionEquals( point.GetPosition() ) );
  46. BOOST_CHECK_CLOSE( 67.7647, point.GetRotation(), 0.001 );
  47. QGears::MapFile::TriggerList &triggers( f.getTriggers() );
  48. BOOST_REQUIRE_EQUAL( 1, triggers.size() );
  49. QGears::MapFile::TriggerList::value_type &trigger( triggers.at(0) );
  50. BOOST_CHECK_EQUAL( "Gateway0", trigger.GetName() );
  51. BOOST_CHECK( Ogre::Vector3( 28.6016f, 228.562f, 2.75781f ).positionEquals( trigger.GetPoint1() ) );
  52. BOOST_CHECK( Ogre::Vector3( 28.6641f, 229.438f, 2.75781f ).positionEquals( trigger.GetPoint2() ) );
  53. BOOST_CHECK_EQUAL( true, trigger.IsEnabled() );
  54. logMgr.destroyLog( "Default Log" );
  55. ifs->close();
  56. }