CMapFormatTest.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 "MapComparer.h"
  18. static const int TEST_RANDOM_SEED = 1337;
  19. static std::unique_ptr<CMap> initialMap;
  20. class CMapTestFixture
  21. {
  22. public:
  23. CMapTestFixture()
  24. {
  25. CMapGenOptions opt;
  26. opt.setHeight(72);
  27. opt.setWidth(72);
  28. opt.setHasTwoLevels(false);
  29. opt.setPlayerCount(2);
  30. CMapGenerator gen;
  31. initialMap = gen.generate(&opt, TEST_RANDOM_SEED);
  32. };
  33. ~CMapTestFixture()
  34. {
  35. initialMap.reset();
  36. };
  37. };
  38. BOOST_GLOBAL_FIXTURE(CMapTestFixture);
  39. BOOST_AUTO_TEST_CASE(CMapFormatVCMI_Simple)
  40. {
  41. try
  42. {
  43. CMemoryBuffer serializeBuffer;
  44. CMapSaverJson saver(&serializeBuffer);
  45. saver.saveMap(initialMap);
  46. CMapLoaderJson loader(&serializeBuffer);
  47. serializeBuffer.seek(0);
  48. std::unique_ptr<CMap> serialized = loader.loadMap();
  49. MapComparer c;
  50. BOOST_REQUIRE_MESSAGE(c(initialMap, serialized), "Serialize cycle failed");
  51. }
  52. catch(const std::exception & e)
  53. {
  54. logGlobal-> errorStream() << e.what();
  55. throw;
  56. }
  57. }