[mapguide-commits] r6753 - in branches/2.4/MgDev: Common/MapGuideCommon/MapLayer Common/MapGuideCommon/Resources Server/src/UnitTesting

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Mon Jun 11 21:29:51 PDT 2012


Author: jng
Date: 2012-06-11 21:29:51 -0700 (Mon, 11 Jun 2012)
New Revision: 6753

Modified:
   branches/2.4/MgDev/Common/MapGuideCommon/MapLayer/Map.cpp
   branches/2.4/MgDev/Common/MapGuideCommon/Resources/mapguide_en.res
   branches/2.4/MgDev/Server/src/UnitTesting/TestMisc.cpp
   branches/2.4/MgDev/Server/src/UnitTesting/TestMisc.h
Log:
#611: Check for layers belonging to groups not belonging to the map as part of serialization. Reviewed by Walt Welton-Lair

Modified: branches/2.4/MgDev/Common/MapGuideCommon/MapLayer/Map.cpp
===================================================================
--- branches/2.4/MgDev/Common/MapGuideCommon/MapLayer/Map.cpp	2012-06-12 02:12:46 UTC (rev 6752)
+++ branches/2.4/MgDev/Common/MapGuideCommon/MapLayer/Map.cpp	2012-06-12 04:29:51 UTC (rev 6753)
@@ -799,6 +799,9 @@
     Ptr<MgMemoryStreamHelper> streamHelper = new MgMemoryStreamHelper();
     Ptr<MgStream> stream = new MgStream(streamHelper);
 
+    //This is to trap layers attached to groups not in this map
+    std::map<STRING, MgLayerGroup*> groups;
+
     //groups
     INT32 groupCount = m_groups->GetCount();
     stream->WriteInt32(groupCount);
@@ -806,6 +809,7 @@
     {
         Ptr<MgLayerGroup> group = m_groups->GetItem(groupIndex);
         Ptr<MgLayerGroup> parent = group->GetGroup();
+        groups[group->GetObjectId()] = group;
         stream->WriteString(parent != NULL? parent->GetName(): L"");
         stream->WriteObject(group);
     }
@@ -817,6 +821,13 @@
     {
         Ptr<MgLayerBase> layer = m_layers->GetItem(layerIndex);
         Ptr<MgLayerGroup> parent = layer->GetGroup();
+        if (NULL != parent.p && groups.find(parent->GetObjectId()) == groups.end())
+        {
+            MgStringCollection args;
+            args.Add(layer->GetName());
+            args.Add(parent->GetName());
+            throw new MgGroupNotFoundException(L"MgMap.PackLayersAndGroups", __LINE__, __WFILE__, NULL, L"MgLayerBelongsToGroupNotInMap", &args);
+        }
         stream->WriteString(parent != NULL? parent->GetName(): L"");
         stream->WriteObject(layer);
     }

Modified: branches/2.4/MgDev/Common/MapGuideCommon/Resources/mapguide_en.res
===================================================================
--- branches/2.4/MgDev/Common/MapGuideCommon/Resources/mapguide_en.res	2012-06-12 02:12:46 UTC (rev 6752)
+++ branches/2.4/MgDev/Common/MapGuideCommon/Resources/mapguide_en.res	2012-06-12 04:29:51 UTC (rev 6753)
@@ -288,6 +288,7 @@
 MgInvalidWebWidgetType                                = The web widget type is invalid because it is not recognized.
 MgInvalidXmlDateTime                                  = The Xml date time is invalid because not all of the fields were found.
 MgInvalidYear                                         = The year is invalid because it must be between 1 and 9999.
+MgLayerBelongsToGroupNotInMap                         = The layer (%1) belongs to a group (%2) which is not part of the map.
 MgMachineIpMustBeLocalHost                            = The machine IP address must be a local host.
 MgMapCacheCleared                                     = The Tile Service map cache has been cleared.  Please increase TiledMapCacheSize in serverconfig.ini.
 MgMapDisplayDpiCannotBeLessThanOrEqualToZero          = The map DPI cannot be less than or equal to zero.

Modified: branches/2.4/MgDev/Server/src/UnitTesting/TestMisc.cpp
===================================================================
--- branches/2.4/MgDev/Server/src/UnitTesting/TestMisc.cpp	2012-06-12 02:12:46 UTC (rev 6752)
+++ branches/2.4/MgDev/Server/src/UnitTesting/TestMisc.cpp	2012-06-12 04:29:51 UTC (rev 6753)
@@ -17,6 +17,9 @@
 
 #include "MapGuideCommon.h"
 #include "TestMisc.h"
+#include "ServiceManager.h"
+#include "ServerResourceService.h"
+#include "ServerSiteService.h"
 #include "../UnitTesting/CppUnitExtensions.h"
 #include "FoundationDefs.h"
 const STRING TEST_LOCALE = L"en";
@@ -25,6 +28,35 @@
 
 TestMisc::TestMisc()
 {
+    // Initialize service objects.
+    MgServiceManager* serviceManager = MgServiceManager::GetInstance();
+
+    m_svcResource = dynamic_cast<MgResourceService*>(
+        serviceManager->RequestService(MgServiceType::ResourceService));
+    assert(m_svcResource != NULL);
+
+    // Initialize a site connection.
+    Ptr<MgServerSiteService> svcSite = dynamic_cast<MgServerSiteService*>(
+        serviceManager->RequestService(MgServiceType::SiteService));
+    assert(svcSite != NULL);
+
+    Ptr<MgUserInformation> userInfo = new MgUserInformation(
+        L"Administrator", L"admin");
+    userInfo->SetLocale(TEST_LOCALE);
+
+    // Set the current MgUserInformation
+    // This must be done before calling CreateSession()
+    MgUserInformation::SetCurrentUserInfo(userInfo);
+
+    STRING session = svcSite->CreateSession();
+    assert(!session.empty());
+    userInfo->SetMgSessionId(session);
+
+    // Set the current MgUserInformation
+    MgUserInformation::SetCurrentUserInfo(userInfo);
+
+    m_siteConnection = new MgSiteConnection();
+    m_siteConnection->Open(userInfo);
 }
 
 
@@ -46,11 +78,170 @@
 void TestMisc::TestStart()
 {
     ACE_DEBUG((LM_INFO, ACE_TEXT("\nRunning Miscellaneous tests.\n")));
+
+    //Reusing Mapping Service test data
+    try
+    {
+        #ifdef _DEBUG
+        MgFdoConnectionManager* pFdoConnectionManager = MgFdoConnectionManager::GetInstance();
+        if(pFdoConnectionManager)
+        {
+            pFdoConnectionManager->ShowCache();
+        }
+        #endif
+
+        //set user info
+        Ptr<MgUserInformation> userInfo = new MgUserInformation(L"Administrator", L"admin");
+        userInfo->SetLocale(TEST_LOCALE);
+        MgUserInformation::SetCurrentUserInfo(userInfo);
+
+        //publish the map definition
+        Ptr<MgResourceIdentifier> mapres = new MgResourceIdentifier(L"Library://UnitTests/Maps/Sheboygan.MapDefinition");
+        Ptr<MgByteSource> mdfsrc = new MgByteSource(L"../UnitTestFiles/UT_Sheboygan.mdf", false);
+        Ptr<MgByteReader> mdfrdr = mdfsrc->GetReader();
+        m_svcResource->SetResource(mapres, mdfrdr, NULL);
+
+        //publish the layer definitions
+        Ptr<MgResourceIdentifier> ldfres1 = new MgResourceIdentifier(L"Library://UnitTests/Layers/HydrographicPolygons.LayerDefinition");
+        Ptr<MgByteSource> ldfsrc1 = new MgByteSource(L"../UnitTestFiles/UT_HydrographicPolygons.ldf", false);
+        Ptr<MgByteReader> ldfrdr1 = ldfsrc1->GetReader();
+        m_svcResource->SetResource(ldfres1, ldfrdr1, NULL);
+
+        Ptr<MgResourceIdentifier> ldfres2 = new MgResourceIdentifier(L"Library://UnitTests/Layers/Parcels.LayerDefinition");
+        Ptr<MgByteSource> ldfsrc2 = new MgByteSource(L"../UnitTestFiles/UT_Parcels.ldf", false);
+        Ptr<MgByteReader> ldfrdr2 = ldfsrc2->GetReader();
+        m_svcResource->SetResource(ldfres2, ldfrdr2, NULL);
+
+        Ptr<MgResourceIdentifier> ldfres3 = new MgResourceIdentifier(L"Library://UnitTests/Layers/Rail.LayerDefinition");
+        Ptr<MgByteSource> ldfsrc3 = new MgByteSource(L"../UnitTestFiles/UT_Rail.ldf", false);
+        Ptr<MgByteReader> ldfrdr3 = ldfsrc3->GetReader();
+        m_svcResource->SetResource(ldfres3, ldfrdr3, NULL);
+
+        //publish the feature sources
+        Ptr<MgResourceIdentifier> fsres1 = new MgResourceIdentifier(L"Library://UnitTests/Data/HydrographicPolygons.FeatureSource");
+        Ptr<MgByteSource> fssrc1 = new MgByteSource(L"../UnitTestFiles/UT_HydrographicPolygons.fs", false);
+        Ptr<MgByteReader> fsrdr1 = fssrc1->GetReader();
+        m_svcResource->SetResource(fsres1, fsrdr1, NULL);
+
+        Ptr<MgResourceIdentifier> fsres2 = new MgResourceIdentifier(L"Library://UnitTests/Data/Parcels.FeatureSource");
+        Ptr<MgByteSource> fssrc2 = new MgByteSource(L"../UnitTestFiles/UT_Parcels.fs", false);
+        Ptr<MgByteReader> fsrdr2 = fssrc2->GetReader();
+        m_svcResource->SetResource(fsres2, fsrdr2, NULL);
+
+        Ptr<MgResourceIdentifier> fsres3 = new MgResourceIdentifier(L"Library://UnitTests/Data/Rail.FeatureSource");
+        Ptr<MgByteSource> fssrc3 = new MgByteSource(L"../UnitTestFiles/UT_Rail.fs", false);
+        Ptr<MgByteReader> fsrdr3 = fssrc3->GetReader();
+        m_svcResource->SetResource(fsres3, fsrdr3, NULL);
+
+        // publish the resource data
+        Ptr<MgByteSource> dataSource1 = new MgByteSource(L"../UnitTestFiles/UT_HydrographicPolygons.sdf", false);
+        Ptr<MgByteReader> dataReader1 = dataSource1->GetReader();
+        m_svcResource->SetResourceData(fsres1, L"UT_HydrographicPolygons.sdf", L"File", dataReader1);
+
+        Ptr<MgByteSource> dataSource2 = new MgByteSource(L"../UnitTestFiles/UT_Parcels.sdf", false);
+        Ptr<MgByteReader> dataReader2 = dataSource2->GetReader();
+        m_svcResource->SetResourceData(fsres2, L"UT_Parcels.sdf", L"File", dataReader2);
+
+        Ptr<MgByteSource> dataSource3 = new MgByteSource(L"../UnitTestFiles/UT_Rail.sdf", false);
+        Ptr<MgByteReader> dataReader3 = dataSource3->GetReader();
+        m_svcResource->SetResourceData(fsres3, L"UT_Rail.sdf", L"File", dataReader3);
+
+        // publish the print layouts
+        Ptr<MgResourceIdentifier> plres1 = new MgResourceIdentifier(L"Library://UnitTests/PrintLayouts/AllElements.PrintLayout");
+        Ptr<MgByteSource> plsrc1 = new MgByteSource(L"../UnitTestFiles/UT_AllElements.pl", false);
+        Ptr<MgByteReader> plrdr1 = plsrc1->GetReader();
+        m_svcResource->SetResource(plres1, plrdr1, NULL);
+
+        Ptr<MgResourceIdentifier> plres2 = new MgResourceIdentifier(L"Library://UnitTests/PrintLayouts/NoLegend.PrintLayout");
+        Ptr<MgByteSource> plsrc2 = new MgByteSource(L"../UnitTestFiles/UT_NoLegend.pl", false);
+        Ptr<MgByteReader> plrdr2 = plsrc2->GetReader();
+        m_svcResource->SetResource(plres2, plrdr2, NULL);
+
+        // publish the symbol library
+        Ptr<MgResourceIdentifier> slres1 = new MgResourceIdentifier(L"Library://UnitTests/Symbols/SymbolMart.SymbolLibrary");
+        Ptr<MgByteSource> slsrc1 = new MgByteSource(L"../UnitTestFiles/UT_SymbolMart.sl", false);
+        Ptr<MgByteReader> slrdr1 = slsrc1->GetReader();
+        m_svcResource->SetResource(slres1, slrdr1, NULL);
+        Ptr<MgByteSource> datasrc = new MgByteSource(L"../UnitTestFiles/UT_Symbols.dwf", false);
+        Ptr<MgByteReader> datardr = datasrc->GetReader();
+        m_svcResource->SetResourceData(slres1, L"symbols.dwf", L"File", datardr);
+    }
+    catch (MgException* e)
+    {
+        STRING message = e->GetDetails(TEST_LOCALE);
+        SAFE_RELEASE(e);
+        CPPUNIT_FAIL(MG_WCHAR_TO_CHAR(message.c_str()));
+    }
+    catch (...)
+    {
+        throw;
+    }
 }
 
 
 void TestMisc::TestEnd()
 {
+    try
+    {
+        //set user info
+        Ptr<MgUserInformation> userInfo = new MgUserInformation(L"Administrator", L"admin");
+        userInfo->SetLocale(TEST_LOCALE);
+        MgUserInformation::SetCurrentUserInfo(userInfo);
+
+        //delete the map definition
+        Ptr<MgResourceIdentifier> mapres = new MgResourceIdentifier(L"Library://UnitTests/Maps/Sheboygan.MapDefinition");
+        m_svcResource->DeleteResource(mapres);
+
+        //delete the layer definitions
+        Ptr<MgResourceIdentifier> ldfres1 = new MgResourceIdentifier(L"Library://UnitTests/Layers/HydrographicPolygons.LayerDefinition");
+        m_svcResource->DeleteResource(ldfres1);
+
+        Ptr<MgResourceIdentifier> ldfres2 = new MgResourceIdentifier(L"Library://UnitTests/Layers/Parcels.LayerDefinition");
+        m_svcResource->DeleteResource(ldfres2);
+
+        Ptr<MgResourceIdentifier> ldfres3 = new MgResourceIdentifier(L"Library://UnitTests/Layers/Rail.LayerDefinition");
+        m_svcResource->DeleteResource(ldfres3);
+
+        //delete the feature sources
+        Ptr<MgResourceIdentifier> fsres1 = new MgResourceIdentifier(L"Library://UnitTests/Data/HydrographicPolygons.FeatureSource");
+        m_svcResource->DeleteResource(fsres1);
+
+        Ptr<MgResourceIdentifier> fsres2 = new MgResourceIdentifier(L"Library://UnitTests/Data/Parcels.FeatureSource");
+        m_svcResource->DeleteResource(fsres2);
+
+        Ptr<MgResourceIdentifier> fsres3 = new MgResourceIdentifier(L"Library://UnitTests/Data/Rail.FeatureSource");
+        m_svcResource->DeleteResource(fsres3);
+
+        // delete the print layouts
+        Ptr<MgResourceIdentifier> plres1 = new MgResourceIdentifier(L"Library://UnitTests/PrintLayouts/AllElements.PrintLayout");
+        m_svcResource->DeleteResource(plres1);
+
+        Ptr<MgResourceIdentifier> plres2 = new MgResourceIdentifier(L"Library://UnitTests/PrintLayouts/NoLegend.PrintLayout");
+        m_svcResource->DeleteResource(plres2);
+
+        // delete the symbol library
+        Ptr<MgResourceIdentifier> slres1 = new MgResourceIdentifier(L"Library://UnitTests/Symbols/SymbolMart.SymbolLibrary");
+        m_svcResource->DeleteResource(slres1);
+
+        #ifdef _DEBUG
+        MgFdoConnectionManager* pFdoConnectionManager = MgFdoConnectionManager::GetInstance();
+        if(pFdoConnectionManager)
+        {
+            pFdoConnectionManager->ShowCache();
+        }
+        #endif
+    }
+    catch (MgException* e)
+    {
+        STRING message = e->GetDetails(TEST_LOCALE);
+        SAFE_RELEASE(e);
+        CPPUNIT_FAIL(MG_WCHAR_TO_CHAR(message.c_str()));
+    }
+    catch (...)
+    {
+        throw;
+    }
+
     ACE_DEBUG((LM_INFO, ACE_TEXT("\nMiscellaneous tests completed.\n\n")));
 }
 
@@ -258,4 +449,35 @@
         CPPUNIT_ASSERT_MESSAGE(assertMsg, msg.find(L"Foo") != STRING::npos);
         ex->Release();
     }
+}
+
+void TestMisc::TestCase_611()
+{
+    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"Detached");
+        Ptr<MgResourceIdentifier> ldf = new MgResourceIdentifier(L"Library://UnitTests/Layers/Parcels.LayerDefinition");
+        Ptr<MgLayer> layer = new MgLayer(ldf, m_svcResource);
+        layer->SetName(L"BelongsToDetachedGroup");
+        layer->SetLegendLabel(L"BelongsToDetachedGroup");
+        layer->SetGroup(detachedGroup);
+        Ptr<MgLayerCollection> mapLayers = map1->GetLayers();
+        mapLayers->Insert(0, layer);
+
+        CPPUNIT_ASSERT_THROW_MG(map1->Save(), MgGroupNotFoundException*);
+    }
+    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-12 02:12:46 UTC (rev 6752)
+++ branches/2.4/MgDev/Server/src/UnitTesting/TestMisc.h	2012-06-12 04:29:51 UTC (rev 6753)
@@ -26,6 +26,7 @@
     CPPUNIT_TEST(TestStart); // This must be the very first unit test
 
     CPPUNIT_TEST(TestCase_CommonExceptionMessages);
+    CPPUNIT_TEST(TestCase_611);
 
     CPPUNIT_TEST(TestEnd); // This must be the very last unit test
     CPPUNIT_TEST_SUITE_END();
@@ -40,6 +41,11 @@
     void TestEnd();
 
     void TestCase_CommonExceptionMessages();
+    void TestCase_611();
+
+private:
+    Ptr<MgSiteConnection> m_siteConnection;
+    Ptr<MgResourceService> m_svcResource;
 };
 
 #endif



More information about the mapguide-commits mailing list