[mapguide-commits] r7230 - in trunk/MgDev: Common/PlatformBase/MapLayer Server/src/UnitTesting

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Mon Nov 26 20:51:36 PST 2012


Author: jng
Date: 2012-11-26 20:51:35 -0800 (Mon, 26 Nov 2012)
New Revision: 7230

Modified:
   trunk/MgDev/Common/PlatformBase/MapLayer/LayerCollection.cpp
   trunk/MgDev/Common/PlatformBase/MapLayer/LayerGroupCollection.cpp
   trunk/MgDev/Server/src/UnitTesting/TestMisc.cpp
   trunk/MgDev/Server/src/UnitTesting/TestMisc.h
Log:
#2189, #2190: Fix Remove() behaviour in MgLayerCollection and MgLayerGroupCollection. Reviewed by Walt Welton-Lair. Includes unit test

Modified: trunk/MgDev/Common/PlatformBase/MapLayer/LayerCollection.cpp
===================================================================
--- trunk/MgDev/Common/PlatformBase/MapLayer/LayerCollection.cpp	2012-11-26 16:16:51 UTC (rev 7229)
+++ trunk/MgDev/Common/PlatformBase/MapLayer/LayerCollection.cpp	2012-11-27 04:51:35 UTC (rev 7230)
@@ -149,9 +149,9 @@
         Ptr<MgLayerBase> layer = SAFE_ADDREF(value);
 
         //value is released by m_layers base class
-        m_layers->Remove(value);
+        removed = m_layers->Remove(value);
 
-        if (m_owner)
+        if (m_owner && removed)
             m_owner->OnLayerRemoved(layer);
     }
     catch (MgException* e)

Modified: trunk/MgDev/Common/PlatformBase/MapLayer/LayerGroupCollection.cpp
===================================================================
--- trunk/MgDev/Common/PlatformBase/MapLayer/LayerGroupCollection.cpp	2012-11-26 16:16:51 UTC (rev 7229)
+++ trunk/MgDev/Common/PlatformBase/MapLayer/LayerGroupCollection.cpp	2012-11-27 04:51:35 UTC (rev 7230)
@@ -130,9 +130,9 @@
         Ptr<MgLayerGroup> group = SAFE_ADDREF(value);
 
         //value is released by m_groups base class
-        m_groups->Remove(value);
+        removed = m_groups->Remove(value);
 
-        if (m_owner)
+        if (m_owner && removed)
             m_owner->OnGroupRemoved(group);
     }
     catch (MgException* e)

Modified: trunk/MgDev/Server/src/UnitTesting/TestMisc.cpp
===================================================================
--- trunk/MgDev/Server/src/UnitTesting/TestMisc.cpp	2012-11-26 16:16:51 UTC (rev 7229)
+++ trunk/MgDev/Server/src/UnitTesting/TestMisc.cpp	2012-11-27 04:51:35 UTC (rev 7230)
@@ -509,4 +509,36 @@
     {
         throw;
     }
+}
+
+void TestMisc::TestCase_MapLayerCollections()
+{
+	try
+	{
+		Ptr<MgResourceIdentifier> mapRes1 = new MgResourceIdentifier(L"Library://UnitTests/Maps/Sheboygan.MapDefinition");
+        Ptr<MgMap> map1 = new MgMap(m_siteConnection);
+        map1->Create(mapRes1, L"UnitTestSheboygan1");
+
+		Ptr<MgLayerGroup> detachedGroup = new MgLayerGroup(L"DetachedGroup");
+        Ptr<MgResourceIdentifier> ldf = new MgResourceIdentifier(L"Library://UnitTests/Layers/Parcels.LayerDefinition");
+        Ptr<MgLayer> detachedLayer = new MgLayer(ldf, m_svcResource);
+		detachedLayer->SetName(L"DetachedLayer");
+
+		Ptr<MgLayerCollection> mapLayers = map1->GetLayers();
+		Ptr<MgLayerGroupCollection> mapGroups = map1->GetLayerGroups();
+
+		//Remove() should be returning false when passing in layers/groups that don't belong
+		CPPUNIT_ASSERT(!mapLayers->Remove(detachedLayer));
+		CPPUNIT_ASSERT(!mapGroups->Remove(detachedGroup));
+	}
+    catch (MgException* e)
+    {
+        STRING message = e->GetDetails(TEST_LOCALE);
+        SAFE_RELEASE(e);
+        CPPUNIT_FAIL(MG_WCHAR_TO_CHAR(message.c_str()));
+    }
+    catch (...)
+    {
+        throw;
+    }
 }
\ No newline at end of file

Modified: trunk/MgDev/Server/src/UnitTesting/TestMisc.h
===================================================================
--- trunk/MgDev/Server/src/UnitTesting/TestMisc.h	2012-11-26 16:16:51 UTC (rev 7229)
+++ trunk/MgDev/Server/src/UnitTesting/TestMisc.h	2012-11-27 04:51:35 UTC (rev 7230)
@@ -28,6 +28,7 @@
     CPPUNIT_TEST(TestCase_CommonExceptionMessages);
     CPPUNIT_TEST(TestCase_611);
     CPPUNIT_TEST(TestCase_1304);
+	CPPUNIT_TEST(TestCase_MapLayerCollections);
 
     CPPUNIT_TEST(TestEnd); // This must be the very last unit test
     CPPUNIT_TEST_SUITE_END();
@@ -44,6 +45,7 @@
     void TestCase_CommonExceptionMessages();
     void TestCase_611();
     void TestCase_1304();
+	void TestCase_MapLayerCollections();
 
 private:
     Ptr<MgSiteConnection> m_siteConnection;



More information about the mapguide-commits mailing list