test_FF7FLevelFileSerializer.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. -----------------------------------------------------------------------------
  3. The MIT License (MIT)
  4. Copyright (c) 2013-08-24 Tobias Peters <tobias.peters@kreativeffekt.at>
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. -----------------------------------------------------------------------------
  21. */
  22. #include <boost/test/unit_test.hpp>
  23. #include <Ogre.h>
  24. #include "data/VGearsFLevelFileSerializer.h"
  25. #include "data/VGearsBackgroundFileManager.h"
  26. #include "data/VGearsCameraMatrixFileManager.h"
  27. #include "data/VGearsHRCFileManager.h"
  28. #include "data/VGearsPaletteFileManager.h"
  29. #include "data/VGearsLZSFLevelFileManager.h"
  30. #include "data/FF7ModelListFileManager.h"
  31. #include "map/VGearsBackground2DFileManager.h"
  32. #include "map/VGearsWalkmeshFileManager.h"
  33. using namespace Ogre;
  34. BOOST_AUTO_TEST_CASE( read_file )
  35. {
  36. class TestFile : public VGears::FLevelFile
  37. {
  38. public:
  39. TestFile() : VGears::FLevelFile( NULL, "reference.flevel", 0, "General" ) {}
  40. };
  41. class TestTexture : public Texture
  42. {
  43. public:
  44. TestTexture( ResourceManager* creator, const String& name, ResourceHandle handle,
  45. const String& group, bool isManual = false, ManualResourceLoader* loader = 0 )
  46. : Texture( creator, name, handle, group, isManual, loader )
  47. {}
  48. protected:
  49. virtual void loadImpl() {}
  50. virtual void unloadImpl() {}
  51. // IVV compiler error
  52. //virtual HardwarePixelBufferSharedPtr getBuffer( size_t, size_t ){ return HardwarePixelBufferSharedPtr( NULL ); }
  53. virtual void createInternalResourcesImpl(){}
  54. virtual void freeInternalResourcesImpl(){}
  55. };
  56. class TestTextureManager : public TextureManager
  57. {
  58. public:
  59. virtual PixelFormat getNativeFormat( TextureType ttype, PixelFormat format, int usage )
  60. {
  61. return format;
  62. }
  63. virtual bool isHardwareFilteringSupported( TextureType ttype, PixelFormat format, int usage, bool preciseFormatOnly=false )
  64. {
  65. return false;
  66. }
  67. protected:
  68. virtual Resource* createImpl( const String &name
  69. , ResourceHandle handle, const String &group, bool isManual
  70. , ManualResourceLoader *loader
  71. , const NameValuePairList *createParams )
  72. {
  73. return new TestTexture( this, name, handle, group, isManual, loader );
  74. }
  75. };
  76. LogManager logMgr;
  77. Root root("","");
  78. ResourceGroupManager &rgm( ResourceGroupManager::getSingleton() );
  79. TestTextureManager tmgr;
  80. VGears::CameraMatrixFileManager cmgr;
  81. VGears::WalkmeshFileManager wmgr;
  82. VGears::PaletteFileManager pmgr;
  83. VGears::BackgroundFileManager bmgr;
  84. VGears::Background2DFileManager b2mgr;
  85. VGears::ModelListFileManager mmgr;
  86. VGears::HRCFileManager hmgr;
  87. VGears::LZSFLevelFileManager fmgr;
  88. logMgr.createLog( "Default Log", true, true, true );
  89. rgm.addResourceLocation( "misc", "FileSystem" );
  90. rgm.initialiseAllResourceGroups();
  91. TestFile file;
  92. DataStreamPtr stream( rgm.openResource( file.getName(), file.getGroup() ) );
  93. BOOST_REQUIRE( stream->isReadable() );
  94. VGears::FLevelFileSerializer ser;
  95. ser.importFLevelFile( stream, &file );
  96. BOOST_CHECK_EQUAL( 757890, stream->tell() );
  97. VGears::BackgroundFilePtr background ( file.getBackground() );
  98. VGears::CameraMatrixFilePtr camera_matrix( file.getCameraMatrix() );
  99. VGears::ModelListFilePtr model_list ( file.getModelList() );
  100. VGears::PaletteFilePtr palette ( file.getPalette() );
  101. VGears::WalkmeshFilePtr walkmesh ( file.getWalkmesh() );
  102. BOOST_REQUIRE(background != nullptr);
  103. BOOST_REQUIRE(camera_matrix != nullptr);
  104. BOOST_REQUIRE(model_list != nullptr);
  105. BOOST_REQUIRE(palette != nullptr);
  106. BOOST_REQUIRE(walkmesh != nullptr);
  107. BOOST_CHECK_EQUAL( "reference.background", background->getName() );
  108. BOOST_CHECK_EQUAL( "reference.cam_matrix", camera_matrix->getName() );
  109. BOOST_CHECK_EQUAL( "reference.model_list", model_list->getName() );
  110. BOOST_CHECK_EQUAL( "reference.palette" , palette->getName() );
  111. BOOST_CHECK_EQUAL( "reference.walkmesh" , walkmesh->getName() );
  112. Matrix3 m3_expected(
  113. 1, -0, -0
  114. ,0, -1, -0
  115. ,0, -0, -1
  116. );
  117. BOOST_CHECK_EQUAL( m3_expected, camera_matrix->getMatrix() );
  118. BOOST_CHECK_EQUAL( Vector3( -1, 2, -3 ), camera_matrix->getPosition() );
  119. BOOST_CHECK_EQUAL( 2, camera_matrix->getCount() );
  120. BOOST_CHECK_EQUAL( 12345, camera_matrix->getFocalLength() );
  121. Ogre::Image *image( background->createImage( palette ) );
  122. // TODO: FIX ME ON OSX
  123. //image->save( file.getName() + ".png" );
  124. delete image;
  125. VGears::FLevelFilePtr lzs_file = fmgr.load( "reference_compressed.flevel", "General" ).staticCast<VGears::FLevelFile>();
  126. BOOST_CHECK(lzs_file->getPalette() != nullptr);
  127. BOOST_CHECK(lzs_file->getBackground() != nullptr);
  128. image = lzs_file->getBackground()->createImage( lzs_file->getPalette() );
  129. // TODO: FIX ME ON OSX
  130. //image->save( lzs_file->getName() + ".png" );
  131. delete image;
  132. lzs_file.reset();
  133. logMgr.destroyLog( "Default Log" );
  134. stream->close();
  135. }