CMapFormatTest.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * CMapFormatTest.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include <boost/test/unit_test.hpp>
  12. #include "../lib/filesystem/CMemoryBuffer.h"
  13. #include "../lib/mapping/CMap.h"
  14. #include "../lib/rmg/CMapGenOptions.h"
  15. #include "../lib/rmg/CMapGenerator.h"
  16. #include "../lib/mapping/MapFormatJson.h"
  17. #include "../lib/VCMIDirs.h"
  18. #include "MapComparer.h"
  19. static const int TEST_RANDOM_SEED = 1337;
  20. static std::unique_ptr<CMap> initialMap;
  21. class CMapTestFixture
  22. {
  23. public:
  24. CMapTestFixture()
  25. {
  26. CMapGenOptions opt;
  27. opt.setHeight(72);
  28. opt.setWidth(72);
  29. opt.setHasTwoLevels(false);
  30. opt.setPlayerCount(2);
  31. CMapGenerator gen;
  32. initialMap = gen.generate(&opt, TEST_RANDOM_SEED);
  33. initialMap->name = "Test";
  34. };
  35. ~CMapTestFixture()
  36. {
  37. initialMap.reset();
  38. };
  39. };
  40. BOOST_GLOBAL_FIXTURE(CMapTestFixture);
  41. BOOST_AUTO_TEST_CASE(CMapFormatVCMI_Simple)
  42. {
  43. try
  44. {
  45. logGlobal->info("CMapFormatVCMI_Simple start");
  46. CMemoryBuffer serializeBuffer;
  47. {
  48. CMapSaverJson saver(&serializeBuffer);
  49. saver.saveMap(initialMap);
  50. }
  51. #if 1
  52. {
  53. std::ofstream tmp((VCMIDirs::get().userDataPath()/"temp.zip").string());
  54. tmp.write((const char *)&serializeBuffer.getBuffer()[0],serializeBuffer.getSize());
  55. tmp.flush();
  56. }
  57. #endif // 1
  58. serializeBuffer.seek(0);
  59. {
  60. CMapLoaderJson loader(&serializeBuffer);
  61. std::unique_ptr<CMap> serialized = loader.loadMap();
  62. MapComparer c;
  63. c(initialMap, serialized);
  64. }
  65. logGlobal->info("CMapFormatVCMI_Simple finish");
  66. }
  67. catch(...)
  68. {
  69. handleException();
  70. BOOST_FAIL("Test case crashed");
  71. }
  72. }