test_QGearsLGPArchive.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. -----------------------------------------------------------------------------
  3. The MIT License (MIT)
  4. Copyright (c) 2013-09-22 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/QGearsLGPArchiveFactory.h"
  25. BOOST_AUTO_TEST_CASE( load )
  26. {
  27. Ogre::LogManager logMgr;
  28. logMgr.createLog( "Default Log", true, true, true );
  29. const char* filename_1( "Filename 1" );
  30. const char* filename_2( "max length filename!" );
  31. class TestLGPArchive : public QGears::LGPArchive
  32. {
  33. public:
  34. TestLGPArchive() :
  35. QGears::LGPArchive( "misc/reference.lgp", "LGP" )
  36. , test_stream( NULL )
  37. {}
  38. void load()
  39. {
  40. QGears::LGPArchive::load( test_stream );
  41. }
  42. Ogre::DataStream* test_stream;
  43. };
  44. TestLGPArchive lgp;
  45. // TODO: use Ogre::MemoryDataStream and include data via byte array
  46. std::ifstream *ifs( OGRE_NEW_T( std::ifstream, Ogre::MEMCATEGORY_GENERAL )( lgp.getName().c_str(), std::ifstream::binary ) );
  47. lgp.test_stream = OGRE_NEW Ogre::FileStreamDataStream( ifs );
  48. BOOST_CHECK_EQUAL( true, lgp.getFiles().empty() );
  49. BOOST_CHECK_EQUAL( false, lgp.exists( filename_1 ) );
  50. BOOST_CHECK_EQUAL( false, lgp.exists( filename_2 ) );
  51. lgp.load();
  52. BOOST_CHECK_EQUAL( 2, lgp.getFiles().size() );
  53. BOOST_CHECK_EQUAL( true, lgp.exists( filename_1 ) );
  54. BOOST_CHECK_EQUAL( true, lgp.exists( filename_2 ) );
  55. BOOST_CHECK_EQUAL( lgp.getFiles().size(), lgp.list()->size() );
  56. BOOST_CHECK_EQUAL( lgp.getFiles().size(), lgp.listFileInfo()->size() );
  57. QGears::LGPArchive::FileEntry& entry( lgp.getFiles()[0] );
  58. BOOST_CHECK_EQUAL( filename_1, entry.file_name );
  59. BOOST_CHECK_EQUAL( entry.file_name, lgp.list()->at( 0 ) );
  60. BOOST_CHECK_EQUAL( 0x00000050, entry.file_offset );
  61. BOOST_CHECK_EQUAL( "FILENAME 1", entry.data_file_name );
  62. BOOST_CHECK_EQUAL( 0x00000018, entry.data_size );
  63. BOOST_CHECK_EQUAL( 0x00000068, entry.data_offset );
  64. Ogre::FileInfoListPtr file_infos( lgp.listFileInfo() );
  65. Ogre::FileInfo& file_info( file_infos->at( 0 ) );
  66. BOOST_CHECK_EQUAL( &lgp, file_info.archive );
  67. BOOST_CHECK_EQUAL( entry.file_name, file_info.filename );
  68. BOOST_CHECK_EQUAL( entry.file_name, file_info.basename );
  69. BOOST_CHECK_EQUAL( "", file_info.path );
  70. BOOST_CHECK_EQUAL( entry.data_size, file_info.uncompressedSize );
  71. BOOST_CHECK_EQUAL( file_info.uncompressedSize, file_info.compressedSize );
  72. BOOST_CHECK_EQUAL( 1, lgp.find( "Filename*" )->size() );
  73. BOOST_CHECK_EQUAL( 1, lgp.find( "*!" )->size() );
  74. BOOST_CHECK_EQUAL( 2, lgp.find( "*name*" )->size() );
  75. Ogre::StringVectorPtr found( lgp.find( "*name*" ) );
  76. BOOST_CHECK_EQUAL( 2, found->size() );
  77. BOOST_CHECK_EQUAL( filename_1, found->at( 0 ) );
  78. BOOST_CHECK_EQUAL( filename_2, found->at( 1 ) );
  79. Ogre::DataStreamPtr stream( lgp.open( filename_1 ) );
  80. BOOST_CHECK_EQUAL( false, stream.isNull() );
  81. BOOST_CHECK_EQUAL( entry.data_size, stream->size() );
  82. BOOST_CHECK_EQUAL( "data of file 1 for test!", stream->getLine() );
  83. BOOST_CHECK_EQUAL( true, stream->eof() );
  84. lgp.unload();
  85. BOOST_CHECK_EQUAL( false, lgp.exists( filename_1 ) );
  86. BOOST_CHECK_EQUAL( false, lgp.exists( filename_2 ) );
  87. logMgr.destroyLog( "Default Log" );
  88. }