[mapguide-commits] r6756 - in branches/2.4/MgDev: Common/PlatformBase/MapLayer Server/src/UnitTesting

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Wed Jun 13 01:57:02 PDT 2012


Author: jng
Date: 2012-06-13 01:57:02 -0700 (Wed, 13 Jun 2012)
New Revision: 6756

Modified:
   branches/2.4/MgDev/Common/PlatformBase/MapLayer/SelectionBase.cpp
   branches/2.4/MgDev/Common/PlatformBase/MapLayer/SelectionBase.h
   branches/2.4/MgDev/Server/src/UnitTesting/TestMisc.cpp
   branches/2.4/MgDev/Server/src/UnitTesting/TestMisc.h
Log:
#1304: Fix MgSelection constructor bug when an empty XML selection string is passed. Reviewed by Walt Welton-Lair

Modified: branches/2.4/MgDev/Common/PlatformBase/MapLayer/SelectionBase.cpp
===================================================================
--- branches/2.4/MgDev/Common/PlatformBase/MapLayer/SelectionBase.cpp	2012-06-13 08:01:46 UTC (rev 6755)
+++ branches/2.4/MgDev/Common/PlatformBase/MapLayer/SelectionBase.cpp	2012-06-13 08:57:02 UTC (rev 6756)
@@ -51,6 +51,13 @@
 // Destructor
 MgSelectionBase::~MgSelectionBase()
 {
+    ClearSelections();
+    delete m_stream;
+    m_stream = NULL;
+}
+
+void MgSelectionBase::ClearSelections()
+{
     // Delete selection manually instead of relying on deep template deletion
     SelectionMap::iterator lIter;
     for (lIter = m_selections.begin(); lIter != m_selections.end(); ++lIter)
@@ -67,12 +74,8 @@
         delete clsmap;
     }
     m_selections.clear();
-
-    delete m_stream;
-    m_stream = NULL;
 }
 
-
 void MgSelectionBase::Dispose()
 {
     delete this;
@@ -100,6 +103,10 @@
 // Read selection from XML document.  Previous selection is cleared.
 void MgSelectionBase::FromXml(CREFSTRING xmlSelectionString)
 {
+    ClearSelections();
+    if (xmlSelectionString.empty())
+        return;
+
     // TODO: Validate that data is legal by parsing each selection
     //       string.  MgMap will be required to do this.
 

Modified: branches/2.4/MgDev/Common/PlatformBase/MapLayer/SelectionBase.h
===================================================================
--- branches/2.4/MgDev/Common/PlatformBase/MapLayer/SelectionBase.h	2012-06-13 08:01:46 UTC (rev 6755)
+++ branches/2.4/MgDev/Common/PlatformBase/MapLayer/SelectionBase.h	2012-06-13 08:57:02 UTC (rev 6756)
@@ -622,6 +622,9 @@
     SelectionMap m_selections;
     Ptr<MgMapBase> m_map;
     MgMemoryStreamHelper* m_stream;
+
+private:
+    void ClearSelections();
 };
 /// \}
 

Modified: branches/2.4/MgDev/Server/src/UnitTesting/TestMisc.cpp
===================================================================
--- branches/2.4/MgDev/Server/src/UnitTesting/TestMisc.cpp	2012-06-13 08:01:46 UTC (rev 6755)
+++ branches/2.4/MgDev/Server/src/UnitTesting/TestMisc.cpp	2012-06-13 08:57:02 UTC (rev 6756)
@@ -480,4 +480,31 @@
     {
         throw;
     }
+}
+
+void TestMisc::TestCase_1304()
+{
+    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<MgSelection> sel = new MgSelection(map1, L"");
+        Ptr<MgReadOnlyLayerCollection> selLayers = sel->GetLayers();
+        CPPUNIT_ASSERT_MESSAGE("Expected null MgReadOnlyLayerCollection", NULL == selLayers.p); 
+        sel->FromXml(L""); //Should be same result
+        selLayers = sel->GetLayers();
+        CPPUNIT_ASSERT_MESSAGE("Expected null MgReadOnlyLayerCollection", NULL == selLayers.p); 
+    }
+    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: branches/2.4/MgDev/Server/src/UnitTesting/TestMisc.h
===================================================================
--- branches/2.4/MgDev/Server/src/UnitTesting/TestMisc.h	2012-06-13 08:01:46 UTC (rev 6755)
+++ branches/2.4/MgDev/Server/src/UnitTesting/TestMisc.h	2012-06-13 08:57:02 UTC (rev 6756)
@@ -27,6 +27,7 @@
 
     CPPUNIT_TEST(TestCase_CommonExceptionMessages);
     CPPUNIT_TEST(TestCase_611);
+    CPPUNIT_TEST(TestCase_1304);
 
     CPPUNIT_TEST(TestEnd); // This must be the very last unit test
     CPPUNIT_TEST_SUITE_END();
@@ -42,6 +43,7 @@
 
     void TestCase_CommonExceptionMessages();
     void TestCase_611();
+    void TestCase_1304();
 
 private:
     Ptr<MgSiteConnection> m_siteConnection;



More information about the mapguide-commits mailing list