[mapguide-commits] r5981 - in trunk/MgDev: Server/src/PostBuild Server/src/UnitTesting UnitTest/TestData/FeatureService UnitTest/TestData/FeatureService/SQLite

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Wed Jul 6 21:58:20 EDT 2011


Author: hubu
Date: 2011-07-06 18:58:20 -0700 (Wed, 06 Jul 2011)
New Revision: 5981

Added:
   trunk/MgDev/UnitTest/TestData/FeatureService/SQLite/
   trunk/MgDev/UnitTest/TestData/FeatureService/SQLite/SavePointTest.FeatureSource
Modified:
   trunk/MgDev/Server/src/PostBuild/PostBuild.mak
   trunk/MgDev/Server/src/UnitTesting/TestFeatureService.cpp
   trunk/MgDev/Server/src/UnitTesting/TestFeatureService.h
Log:
On behalf of Sam Wang
Ticket #1737: Add unit test for MapGuide RFC 114.

This submission add unit test for MapGuide RFC 114. A sqlite file and corresponding feature source configuration has been added to test data folder. The newly added test case can pass. 

Modified: trunk/MgDev/Server/src/PostBuild/PostBuild.mak
===================================================================
--- trunk/MgDev/Server/src/PostBuild/PostBuild.mak	2011-07-06 17:05:02 UTC (rev 5980)
+++ trunk/MgDev/Server/src/PostBuild/PostBuild.mak	2011-07-07 01:58:20 UTC (rev 5981)
@@ -1895,3 +1895,11 @@
 ..\..\bin\UnitTestFiles\UT_Annotation3.mdf : "..\..\..\UnitTest\TestData\Symbology\UT_Annotation3.mdf"
     if NOT EXIST ..\..\bin\UnitTestFiles\nul mkdir ..\..\bin\UnitTestFiles
     if EXIST "..\..\..\UnitTest\TestData\Symbology\UT_Annotation3.mdf" xcopy /r /d /y "..\..\..\UnitTest\TestData\Symbology\UT_Annotation3.mdf" ..\..\bin\UnitTestFiles\
+
+..\..\bin\UnitTestFiles\SavePointTest.sqlite : "..\..\..\UnitTest\TestData\FeatureService\SQLite\SavePointTest.sqlite"
+    if NOT EXIST ..\..\bin\UnitTestFiles\nul mkdir ..\..\bin\UnitTestFiles
+    if EXIST "..\..\..\UnitTest\TestData\FeatureService\SQLite\SavePointTest.sqlite" xcopy /r /d /y "..\..\..\UnitTest\TestData\FeatureService\SQLite\SavePointTest.sqlite" ..\..\bin\UnitTestFiles\
+
+..\..\bin\UnitTestFiles\SavePointTest.FeatureSource : "..\..\..\UnitTest\TestData\FeatureService\SQLite\SavePointTest.FeatureSource"
+    if NOT EXIST ..\..\bin\UnitTestFiles\nul mkdir ..\..\bin\UnitTestFiles
+    if EXIST "..\..\..\UnitTest\TestData\FeatureService\SQLite\SavePointTest.FeatureSource" xcopy /r /d /y "..\..\..\UnitTest\TestData\FeatureService\SQLite\SavePointTest.FeatureSource" ..\..\bin\UnitTestFiles\

Modified: trunk/MgDev/Server/src/UnitTesting/TestFeatureService.cpp
===================================================================
--- trunk/MgDev/Server/src/UnitTesting/TestFeatureService.cpp	2011-07-06 17:05:02 UTC (rev 5980)
+++ trunk/MgDev/Server/src/UnitTesting/TestFeatureService.cpp	2011-07-07 01:58:20 UTC (rev 5981)
@@ -81,6 +81,7 @@
             MgResourceIdentifier resourceIdentifier4(L"Library://UnitTests/Data/Sheboygan_VotingDistricts.FeatureSource");
             MgResourceIdentifier resourceIdentifier5(L"Library://UnitTests/Data/TestChainedInner1ToManyJoin.FeatureSource");
             MgResourceIdentifier resourceIdentifier6(L"Library://UnitTests/Data/Empty.FeatureSource");
+            MgResourceIdentifier resourceIdentifier7(L"Library://UnitTests/Data/SavePointTest.FeatureSource");
 #ifdef _WIN32
             STRING resourceContentFileName1 = L"..\\UnitTestFiles\\Sheboygan_Parcels.FeatureSource";
             STRING resourceContentFileName2 = L"..\\UnitTestFiles\\Redding_Parcels.FeatureSource";
@@ -88,6 +89,7 @@
             STRING resourceContentFileName4 = L"..\\UnitTestFiles\\Sheboygan_VotingDistricts.FeatureSource";
             STRING resourceContentFileName5=  L"..\\UnitTestFiles\\TESTChainedInner1ToManyJoin.FeatureSource";
             STRING resourceContentFileName6=  L"..\\UnitTestFiles\\Empty.FeatureSource";
+            STRING resourceContentFileName7=  L"..\\UnitTestFiles\\SavePointTest.FeatureSource";
             STRING dataFileName1 = L"..\\UnitTestFiles\\Sheboygan_Parcels.sdf";
             STRING dataFileName2 = L"..\\UnitTestFiles\\Redding_Parcels.shp";
             STRING dataFileName3 = L"..\\UnitTestFiles\\Redding_Parcels.dbf";
@@ -95,6 +97,7 @@
             STRING dataFileName5 = L"..\\UnitTestFiles\\Sheboygan_BuildingOutlines.sdf";
             STRING dataFileName6 = L"..\\UnitTestFiles\\Sheboygan_VotingDistricts.sdf";
             STRING dataFileName7 = L"..\\UnitTestFiles\\Empty.sdf";
+            STRING dataFileName8 = L"..\\UnitTestFiles\\SavePointTest.sqlite";
 #else
             STRING resourceContentFileName1 = L"../UnitTestFiles/Sheboygan_Parcels.FeatureSource";
             STRING resourceContentFileName2 = L"../UnitTestFiles/Redding_Parcels.FeatureSource";
@@ -109,6 +112,7 @@
             STRING dataFileName5 = L"../UnitTestFiles/Sheboygan_BuildingOutlines.sdf";
             STRING dataFileName6 = L"../UnitTestFiles/Sheboygan_VotingDistricts.sdf";
             STRING dataFileName7 = L"../UnitTestFiles/Empty.sdf";
+             STRING dataFileName8 = L"../UnitTestFiles/SavePointTest.sqlite";
 #endif
 
             //Add a new resource
@@ -136,6 +140,10 @@
             Ptr<MgByteReader> contentReader6 = contentSource6->GetReader();
             pService->SetResource(&resourceIdentifier6, contentReader6, NULL);
 
+            Ptr<MgByteSource> contentSource7 = new MgByteSource(resourceContentFileName7);
+            Ptr<MgByteReader> contentReader7 = contentSource7->GetReader();
+            pService->SetResource(&resourceIdentifier7, contentReader7, NULL);
+
             //Set the resource data
             Ptr<MgByteSource> dataSource1 = new MgByteSource(dataFileName1);
             Ptr<MgByteReader> dataReader1 = dataSource1->GetReader();
@@ -168,6 +176,10 @@
             Ptr<MgByteSource> dataSource8 = new MgByteSource(dataFileName7);
             Ptr<MgByteReader> dataReader8 = dataSource8->GetReader();
             pService->SetResourceData(&resourceIdentifier6, L"Empty.sdf", L"File", dataReader8);
+
+            Ptr<MgByteSource> dataSource9 = new MgByteSource(dataFileName8);
+            Ptr<MgByteReader> dataReader9 = dataSource9->GetReader();
+            pService->SetResourceData(&resourceIdentifier7, L"SavePointTest.sqlite", L"File", dataReader9);
         }
     }
     catch(MgException* e)
@@ -2243,3 +2255,101 @@
 
     featureReaders.clear();
 }
+
+void TestFeatureService::TestCase_SavePoint()
+{
+     try
+    {
+        MgServiceManager* serviceManager = MgServiceManager::GetInstance();
+        if(serviceManager == 0)
+        {
+            throw new MgNullReferenceException(L"TestFeatureService.TestCase_SavePoint", __LINE__, __WFILE__, NULL, L"", NULL);
+        }
+
+        Ptr<MgFeatureService> pService = dynamic_cast<MgFeatureService*>(serviceManager->RequestService(MgServiceType::FeatureService));
+        if (pService == 0)
+        {
+            throw new MgServiceNotAvailableException(L"TestFeatureService.TestCase_SavePoint", __LINE__, __WFILE__, NULL, L"", NULL);
+        }
+
+        Ptr<MgResourceIdentifier> featureSource = new MgResourceIdentifier(L"Library://UnitTests/Data/SavePointTest.FeatureSource");
+        Ptr<MgTransaction> pTransaction = pService->BeginTransaction(featureSource);
+        if(pTransaction != NULL)
+        {
+            Ptr<MgFeatureCommandCollection> commands = new MgFeatureCommandCollection();
+            Ptr<MgProperty> prop;
+            Ptr<MgPropertyCollection> properties1 = new MgPropertyCollection();
+            
+            prop = new MgInt32Property(L"ID", 1);
+            properties1->Add(prop);
+            prop = new MgStringProperty(L"Name", L"Sam");
+            properties1->Add(prop);
+            prop = new MgStringProperty(L"Key", L"Test1");
+            properties1->Add(prop);
+            
+            Ptr<MgPropertyCollection> properties2 = new MgPropertyCollection();
+
+            prop = new MgInt32Property(L"ID", 2);
+            properties2->Add(prop);
+            prop = new MgStringProperty(L"Name", L"Leaf");
+            properties2->Add(prop);
+            prop = new MgStringProperty(L"Key", L"Test2");
+            properties2->Add(prop);
+
+            Ptr<MgBatchPropertyCollection> propCollection = new MgBatchPropertyCollection();
+            propCollection->Add(properties1);
+            propCollection->Add(properties2);
+            Ptr<MgInsertFeatures> insertCommand1 = new MgInsertFeatures(L"DaKlass", propCollection);
+            
+            commands->Add(insertCommand1);
+            pService->UpdateFeatures(featureSource, commands, pTransaction);
+            
+            STRING sp = pTransaction->AddSavePoint(L"test");
+            STRING sp1 = pTransaction->AddSavePoint(L"test");
+
+            CPPUNIT_ASSERT(sp != sp1);
+
+            commands->Clear();
+            Ptr<MgPropertyCollection> properties3 = new MgPropertyCollection();
+            prop = new MgInt32Property(L"ID", 3);
+            properties3->Add(prop);
+            prop = new MgStringProperty(L"Name", L"Evan");
+            properties3->Add(prop);
+            prop = new MgStringProperty(L"Key", L"Test3");
+            properties3->Add(prop);
+            Ptr<MgInsertFeatures> insertCommand2 = new MgInsertFeatures(L"DaKlass", properties3);
+            commands->Add(insertCommand2);
+            pService->UpdateFeatures(featureSource, commands, pTransaction);
+
+            pTransaction->Rollback(sp);
+            pTransaction->Commit();
+
+            Ptr<MgFeatureQueryOptions> options = new MgFeatureQueryOptions();
+            options->AddFeatureProperty(L"ID");
+            options->AddFeatureProperty(L"Name");
+            options->AddFeatureProperty(L"Key");
+            Ptr<MgFeatureReader> reader = pService->SelectFeatures(featureSource, L"DaKlass", options);
+            int count = 0;
+            while(reader->ReadNext())
+            {
+                count++;
+            }
+            CPPUNIT_ASSERT(count == 2);
+        }
+    }
+    catch(MgException* e)
+    {
+        STRING message = e->GetDetails(TEST_LOCALE);
+        SAFE_RELEASE(e);
+        CPPUNIT_FAIL(MG_WCHAR_TO_CHAR(message.c_str()));
+    }
+    catch(FdoException* e)
+    {
+        FDO_SAFE_RELEASE(e);
+        CPPUNIT_FAIL("FdoException occurred");
+    }
+    catch(...)
+    {
+        throw;
+    }
+}

Modified: trunk/MgDev/Server/src/UnitTesting/TestFeatureService.h
===================================================================
--- trunk/MgDev/Server/src/UnitTesting/TestFeatureService.h	2011-07-06 17:05:02 UTC (rev 5980)
+++ trunk/MgDev/Server/src/UnitTesting/TestFeatureService.h	2011-07-07 01:58:20 UTC (rev 5981)
@@ -57,6 +57,7 @@
     CPPUNIT_TEST(TestCase_CreateFeatureSource);
     CPPUNIT_TEST(TestCase_BenchmarkSelectFeatures);
     CPPUNIT_TEST(TestCase_ConcurrentAccess);
+    CPPUNIT_TEST(TestCase_SavePoint);
 
     CPPUNIT_TEST(TestEnd); // This must be the very last unit test
     CPPUNIT_TEST_SUITE_END();
@@ -99,6 +100,7 @@
     void TestCase_CreateFeatureSource();
     void TestCase_BenchmarkSelectFeatures();
     void TestCase_ConcurrentAccess();
+    void TestCase_SavePoint();
 };
 
 #endif // _TESTFEATURESERVICE_H

Added: trunk/MgDev/UnitTest/TestData/FeatureService/SQLite/SavePointTest.FeatureSource
===================================================================
--- trunk/MgDev/UnitTest/TestData/FeatureService/SQLite/SavePointTest.FeatureSource	                        (rev 0)
+++ trunk/MgDev/UnitTest/TestData/FeatureService/SQLite/SavePointTest.FeatureSource	2011-07-07 01:58:20 UTC (rev 5981)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<FeatureSource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FeatureSource-1.0.0.xsd">
+  <Provider>OSGeo.SQLite</Provider>
+  <Parameter>
+    <Name>File</Name>
+    <Value>%MG_DATA_FILE_PATH%SavePointTest.sqlite</Value>
+  </Parameter>
+</FeatureSource>



More information about the mapguide-commits mailing list