浏览代码

Advance map format simple test

AlexVinS 10 年之前
父节点
当前提交
0cc47f00c5
共有 6 个文件被更改,包括 69 次插入18 次删除
  1. 6 7
      lib/mapping/MapFormatJson.cpp
  2. 1 2
      lib/mapping/MapFormatJson.h
  3. 2 0
      test/CMakeLists.txt
  4. 20 9
      test/CMapFormatTest.cpp
  5. 20 0
      test/MapComparer.cpp
  6. 20 0
      test/MapComparer.h

+ 6 - 7
lib/mapping/MapFormatJson.cpp

@@ -110,10 +110,9 @@ CMapLoaderJson::CMapLoaderJson(CInputStream * stream):
 std::unique_ptr<CMap> CMapLoaderJson::loadMap()
 {
 	map = new CMap();
-	mapHeader.reset(map);
+	mapHeader = std::unique_ptr<CMapHeader>(dynamic_cast<CMapHeader *>(map));
 	readMap();
-	mapHeader.reset();
-	return std::unique_ptr<CMap>(map);
+	return std::unique_ptr<CMap>(dynamic_cast<CMap *>(mapHeader.release()));
 }
 
 std::unique_ptr<CMapHeader> CMapLoaderJson::loadMapHeader()
@@ -167,7 +166,7 @@ JsonNode eventToJson(const EventCondition & cond)
 void CMapLoaderJson::readMap()
 {
 	readHeader();
-	assert(0); // Not implemented, vcmi does not have its own map format right now
+	//TODO:readMap
 }
 
 void CMapLoaderJson::readHeader()
@@ -175,12 +174,12 @@ void CMapLoaderJson::readHeader()
 	//TODO: read such data like map name & size
 //	readTriggeredEvents();
 	readPlayerInfo();
-	assert(0); // Not implemented
+	//TODO: readHeader
 }
 
 void CMapLoaderJson::readPlayerInfo()
 {
-	assert(0); // Not implemented
+	//TODO: readPlayerInfo
 }
 
 ///CMapSaverJson
@@ -193,6 +192,6 @@ CMapSaverJson::CMapSaverJson(COutputStream * stream):
 
 void CMapSaverJson::saveMap(const std::unique_ptr<CMap>& map)
 {
-	assert(0); // Not implemented	
+	//TODO: saveMap
 }
 

+ 1 - 2
lib/mapping/MapFormatJson.h

@@ -1,6 +1,5 @@
-
 /*
- * MapFormatH3M.h, part of VCMI engine
+ * MapFormatJSON.h, part of VCMI engine
  *
  * Authors: listed in file AUTHORS in main folder
  *

+ 2 - 0
test/CMakeLists.txt

@@ -8,6 +8,8 @@ set(test_SRCS
 		StdInc.cpp
 		CVcmiTestConfig.cpp
 		CMapEditManagerTest.cpp
+                MapComparer.cpp
+                CMapFormatTest.cpp
 )
 
 add_executable(vcmitest ${test_SRCS})

+ 20 - 9
test/CMapFormatTest.cpp

@@ -8,18 +8,22 @@
  * Full text of license available in license.txt file, in main folder
  *
  */
-
-
 #include "StdInc.h"
+
 #include <boost/test/unit_test.hpp>
 
+#include "../lib/filesystem/CMemoryBuffer.h"
+
 #include "../lib/mapping/CMap.h"
 #include "../lib/rmg/CMapGenOptions.h"
 #include "../lib/rmg/CMapGenerator.h"
+#include "../lib/mapping/MapFormatJSON.h"
+
+#include "MapComparer.h"
 
 static const int TEST_RANDOM_SEED = 1337;
 
-static CMap * initialMap;
+static std::unique_ptr<CMap> initialMap;
 
 class CMapTestFixture
 {
@@ -35,11 +39,11 @@ public:
 		
 		CMapGenerator gen;
 		
-		initialMap = gen.generate(&opt, TEST_RANDOM_SEED).release();
+		initialMap = gen.generate(&opt, TEST_RANDOM_SEED);
 	};
 	~CMapTestFixture()
 	{
-		delete initialMap;
+		initialMap.reset();
 	};
 };
 
@@ -49,11 +53,18 @@ BOOST_AUTO_TEST_CASE(CMapFormatVCMI_Simple)
 {
 	try
 	{
-
-		//TODO: serialize map
-		//TODO: deserialize map
-		//TODO: compare results
+		CMemoryBuffer serializeBuffer;
+		CMapSaverJson saver(&serializeBuffer);
+		saver.saveMap(initialMap);
+		
+		CMapLoaderJson loader(&serializeBuffer);
+		serializeBuffer.seek(0);		
+		std::unique_ptr<CMap> serialized = loader.loadMap();
+		
+		
+		MapComparer c;
 		
+		BOOST_REQUIRE_MESSAGE(c(initialMap, serialized), "Serialize cycle failed");
 	}
 	catch(const std::exception & e)
 	{

+ 20 - 0
test/MapComparer.cpp

@@ -0,0 +1,20 @@
+/*
+ * MapComparer.cpp, part of VCMI engine
+ *
+ * Authors: listed in file AUTHORS in main folder
+ *
+ * License: GNU General Public License v2.0 or later
+ * Full text of license available in license.txt file, in main folder
+ *
+ */
+#include "StdInc.h"
+
+#include <boost/test/unit_test.hpp>
+
+#include "MapComparer.h"
+
+bool MapComparer::operator() (const std::unique_ptr<CMap>& lhs, const std::unique_ptr<CMap>&  rhs)
+{
+	BOOST_ERROR(" MapComparer::operator() not implemented");
+	return false;
+}

+ 20 - 0
test/MapComparer.h

@@ -0,0 +1,20 @@
+/*
+ * MapComparer.h, part of VCMI engine
+ *
+ * Authors: listed in file AUTHORS in main folder
+ *
+ * License: GNU General Public License v2.0 or later
+ * Full text of license available in license.txt file, in main folder
+ *
+ */
+ 
+#pragma once
+ 
+#include "../lib/mapping/CMap.h"
+
+struct MapComparer
+{
+	bool operator() (const std::unique_ptr<CMap>& lhs, const std::unique_ptr<CMap>& rhs);
+};
+
+