CMapFormatTest.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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(CMapHeader::MAP_SIZE_SMALL);
  28. opt.setWidth(CMapHeader::MAP_SIZE_SMALL);
  29. opt.setHasTwoLevels(true);
  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. logGlobal->info("CMapFormatVCMI_Simple start");
  44. CMemoryBuffer serializeBuffer;
  45. {
  46. CMapSaverJson saver(&serializeBuffer);
  47. saver.saveMap(initialMap);
  48. }
  49. #if 1
  50. {
  51. auto path = VCMIDirs::get().userDataPath()/"temp.zip";
  52. boost::filesystem::remove(path);
  53. boost::filesystem::ofstream tmp(path, boost::filesystem::ofstream::binary);
  54. tmp.write((const char *)serializeBuffer.getBuffer().data(),serializeBuffer.getSize());
  55. tmp.flush();
  56. tmp.close();
  57. }
  58. #endif // 1
  59. serializeBuffer.seek(0);
  60. {
  61. CMapLoaderJson loader(&serializeBuffer);
  62. std::unique_ptr<CMap> serialized = loader.loadMap();
  63. MapComparer c;
  64. c(serialized, initialMap);
  65. }
  66. logGlobal->info("CMapFormatVCMI_Simple finish");
  67. }