[mapguide-commits] r9613 - sandbox/jng/mvt_alt/Server/src/UnitTesting

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Sat Sep 21 16:28:21 PDT 2019


Author: jng
Date: 2019-09-21 16:28:21 -0700 (Sat, 21 Sep 2019)
New Revision: 9613

Modified:
   sandbox/jng/mvt_alt/Server/src/UnitTesting/TestMisc.cpp
   sandbox/jng/mvt_alt/Server/src/UnitTesting/TestMisc.h
Log:
Add "unit test" for MgGeometry -> LineBuffer conversion. I say "unit test" as this is merely just verifying existing behavior and is more internal documentation as to the expected layout of a LineBuffer for the purposes of rendering.

Modified: sandbox/jng/mvt_alt/Server/src/UnitTesting/TestMisc.cpp
===================================================================
--- sandbox/jng/mvt_alt/Server/src/UnitTesting/TestMisc.cpp	2019-09-21 21:36:30 UTC (rev 9612)
+++ sandbox/jng/mvt_alt/Server/src/UnitTesting/TestMisc.cpp	2019-09-21 23:28:21 UTC (rev 9613)
@@ -23,6 +23,7 @@
 #include "../UnitTesting/CppUnitExtensions.h"
 #include "FoundationDefs.h"
 #include "FdoConnectionManager.h"
+#include "LineBuffer.h"
 
 const STRING TEST_LOCALE = L"en";
 static const INT32 MG_TEST_THREADS = 16;
@@ -794,7 +795,7 @@
     GetConfigValueThreadData* threadData = (GetConfigValueThreadData*)param;
     INT32 threadId = threadData->threadId;
 #ifdef _DEBUG
-    printf("> thread %d started, tile %d,%d\n", threadId, tileRow, tileCol);
+    printf("> thread %d started\n", threadId);
 #endif
 
     try
@@ -912,4 +913,489 @@
     {
         throw;
     }
+}
+
+void TestMisc::TestCase_LineBuffer_Conversion()
+{
+    //This isn't really a test, it's more verification and internal documentation
+    //of how LineBuffers are meant to be represented for various geometry types
+    try
+    {
+        MgWktReaderWriter wktRw;
+        MgAgfReaderWriter agfRw;
+        Ptr<MgGeometry> gPoint = wktRw.Read(L"POINT (30 10)");
+        Ptr<MgGeometry> gMultiPoint = wktRw.Read(L"MULTIPOINT (10 40, 40 30, 20 20, 30 10)");
+        Ptr<MgGeometry> gLineStr = wktRw.Read(L"LINESTRING (30 10, 10 30, 40 40)");
+        Ptr<MgGeometry> gMultiLineString = wktRw.Read(L"MULTILINESTRING ((10 10, 20 20, 10 40), (40 40, 30 30, 40 20, 30 10))");
+        Ptr<MgGeometry> gPolygon1 = wktRw.Read(L"POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))");
+        Ptr<MgGeometry> gPolygon2 = wktRw.Read(L"POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10), (20 30, 35 35, 30 20, 20 30))");
+        Ptr<MgGeometry> gMultiPolygon1 = wktRw.Read(L"MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)), ((15 5, 40 10, 10 20, 5 10, 15 5)))");
+        Ptr<MgGeometry> gMultiPolygon2 = wktRw.Read(L"MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), (30 20, 20 15, 20 25, 30 20)))");
+
+        //Point
+        {
+            LineBuffer lb(8);
+            Ptr<MgByteReader> agf = agfRw.Write(gPoint);
+            Ptr<MgByteSink> agfSink = new MgByteSink(agf);
+            Ptr<MgByte> bytes = agfSink->ToBuffer();
+            lb.LoadFromAgf(bytes->Bytes(), bytes->GetLength(), nullptr);
+
+            CPPUNIT_ASSERT(1 == lb.geom_count());
+            CPPUNIT_ASSERT(1 == lb.point_count());
+            CPPUNIT_ASSERT(30 == lb.x_coord(0));
+            CPPUNIT_ASSERT(10 == lb.y_coord(0));
+        }
+
+        //MultiPoint
+        {
+            LineBuffer lb(8);
+            Ptr<MgByteReader> agf = agfRw.Write(gMultiPoint);
+            Ptr<MgByteSink> agfSink = new MgByteSink(agf);
+            Ptr<MgByte> bytes = agfSink->ToBuffer();
+            lb.LoadFromAgf(bytes->Bytes(), bytes->GetLength(), nullptr);
+
+            CPPUNIT_ASSERT(1 == lb.geom_count()); //LineBuffer flattens this
+            CPPUNIT_ASSERT(4 == lb.point_count());
+            CPPUNIT_ASSERT(10 == lb.x_coord(0));
+            CPPUNIT_ASSERT(40 == lb.y_coord(0));
+            CPPUNIT_ASSERT(40 == lb.x_coord(1));
+            CPPUNIT_ASSERT(30 == lb.y_coord(1));
+            CPPUNIT_ASSERT(20 == lb.x_coord(2));
+            CPPUNIT_ASSERT(20 == lb.y_coord(2));
+            CPPUNIT_ASSERT(30 == lb.x_coord(3));
+            CPPUNIT_ASSERT(10 == lb.y_coord(3));
+        }
+
+        //LineString
+        {
+            LineBuffer lb(8);
+            Ptr<MgByteReader> agf = agfRw.Write(gLineStr);
+            Ptr<MgByteSink> agfSink = new MgByteSink(agf);
+            Ptr<MgByte> bytes = agfSink->ToBuffer();
+            lb.LoadFromAgf(bytes->Bytes(), bytes->GetLength(), nullptr);
+
+            int lineIdx = 0;
+            CPPUNIT_ASSERT(1 == lb.geom_count());
+            CPPUNIT_ASSERT(1 == lb.cntr_count());
+            CPPUNIT_ASSERT(3 == lb.cntr_size(lineIdx));
+
+            auto ptOffset = lb.contour_start_point(lineIdx);
+            for (int i = 0; i < lb.cntr_size(lineIdx); i++)
+            {
+                auto x = lb.x_coord(ptOffset + i);
+                auto y = lb.y_coord(ptOffset + i);
+                switch (i)
+                {
+                case 0:
+                    CPPUNIT_ASSERT(30 == x);
+                    CPPUNIT_ASSERT(10 == y);
+                    break;
+                case 1:
+                    CPPUNIT_ASSERT(10 == x);
+                    CPPUNIT_ASSERT(30 == y);
+                    break;
+                case 2:
+                    CPPUNIT_ASSERT(40 == x);
+                    CPPUNIT_ASSERT(40 == y);
+                    break;
+                }
+            }
+        }
+        
+        //MultiLineString
+        {
+            LineBuffer lb(8);
+            Ptr<MgByteReader> agf = agfRw.Write(gMultiLineString);
+            Ptr<MgByteSink> agfSink = new MgByteSink(agf);
+            Ptr<MgByte> bytes = agfSink->ToBuffer();
+            lb.LoadFromAgf(bytes->Bytes(), bytes->GetLength(), nullptr);
+
+            CPPUNIT_ASSERT(1 == lb.geom_count()); //LineBuffer flattens this
+            CPPUNIT_ASSERT(2 == lb.cntr_count());
+            CPPUNIT_ASSERT(3 == lb.cntr_size(0));
+            CPPUNIT_ASSERT(4 == lb.cntr_size(1));
+
+            //LineString 1
+            {
+                auto ptOffset = lb.contour_start_point(0);
+                for (int i = 0; i < lb.cntr_size(0); i++)
+                {
+                    auto x = lb.x_coord(ptOffset + i);
+                    auto y = lb.y_coord(ptOffset + i);
+                    switch (i)
+                    {
+                    case 0:
+                        CPPUNIT_ASSERT(10 == x);
+                        CPPUNIT_ASSERT(10 == y);
+                        break;
+                    case 1:
+                        CPPUNIT_ASSERT(20 == x);
+                        CPPUNIT_ASSERT(20 == y);
+                        break;
+                    case 2:
+                        CPPUNIT_ASSERT(10 == x);
+                        CPPUNIT_ASSERT(40 == y);
+                        break;
+                    }
+                }
+            }
+
+            //LineString 2
+            {
+                auto ptOffset = lb.contour_start_point(1);
+                for (int i = 0; i < lb.cntr_size(1); i++)
+                {
+                    auto x = lb.x_coord(ptOffset + i);
+                    auto y = lb.y_coord(ptOffset + i);
+                    switch (i)
+                    {
+                    case 0:
+                        CPPUNIT_ASSERT(40 == x);
+                        CPPUNIT_ASSERT(40 == y);
+                        break;
+                    case 1:
+                        CPPUNIT_ASSERT(30 == x);
+                        CPPUNIT_ASSERT(30 == y);
+                        break;
+                    case 2:
+                        CPPUNIT_ASSERT(40 == x);
+                        CPPUNIT_ASSERT(20 == y);
+                        break;
+                    case 3:
+                        CPPUNIT_ASSERT(30 == x);
+                        CPPUNIT_ASSERT(10 == y);
+                        break;
+                    }
+                }
+            }
+        }
+    
+        //Polygon 1 (1 outer, 0 inner)
+        {
+            LineBuffer lb(8);
+            Ptr<MgByteReader> agf = agfRw.Write(gPolygon1);
+            Ptr<MgByteSink> agfSink = new MgByteSink(agf);
+            Ptr<MgByte> bytes = agfSink->ToBuffer();
+            lb.LoadFromAgf(bytes->Bytes(), bytes->GetLength(), nullptr);
+
+            CPPUNIT_ASSERT(1 == lb.geom_count());
+            auto cc = lb.cntr_count();
+            CPPUNIT_ASSERT(1 == cc);
+
+            int lineIdx = 0;
+            CPPUNIT_ASSERT(5 == lb.cntr_size(lineIdx));
+
+            auto ptOffset = lb.contour_start_point(lineIdx);
+            for (int i = 0; i < lb.cntr_size(lineIdx); i++)
+            {
+                auto x = lb.x_coord(ptOffset + i);
+                auto y = lb.y_coord(ptOffset + i);
+                switch (i)
+                {
+                case 0:
+                    CPPUNIT_ASSERT(30 == x);
+                    CPPUNIT_ASSERT(10 == y);
+                    break;
+                case 1:
+                    CPPUNIT_ASSERT(40 == x);
+                    CPPUNIT_ASSERT(40 == y);
+                    break;
+                case 2:
+                    CPPUNIT_ASSERT(20 == x);
+                    CPPUNIT_ASSERT(40 == y);
+                    break;
+                case 3:
+                    CPPUNIT_ASSERT(10 == x);
+                    CPPUNIT_ASSERT(20 == y);
+                    break;
+                case 4:
+                    CPPUNIT_ASSERT(30 == x);
+                    CPPUNIT_ASSERT(10 == y);
+                    break;
+                }
+            }
+        }
+
+        //Polygon 2 (1 outer, 1 inner)
+        {
+            LineBuffer lb(8);
+            Ptr<MgByteReader> agf = agfRw.Write(gPolygon2);
+            Ptr<MgByteSink> agfSink = new MgByteSink(agf);
+            Ptr<MgByte> bytes = agfSink->ToBuffer();
+            lb.LoadFromAgf(bytes->Bytes(), bytes->GetLength(), nullptr);
+
+            CPPUNIT_ASSERT(1 == lb.geom_count());
+            auto cc = lb.cntr_count();
+            CPPUNIT_ASSERT(2 == cc);
+
+            //Outer Ring
+            {
+                CPPUNIT_ASSERT(5 == lb.cntr_size(0));
+                auto ptOffset = lb.contour_start_point(0);
+                for (int i = 0; i < lb.cntr_size(0); i++)
+                {
+                    auto x = lb.x_coord(ptOffset + i);
+                    auto y = lb.y_coord(ptOffset + i);
+                    switch (i)
+                    {
+                    case 0:
+                        CPPUNIT_ASSERT(35 == x);
+                        CPPUNIT_ASSERT(10 == y);
+                        break;
+                    case 1:
+                        CPPUNIT_ASSERT(45 == x);
+                        CPPUNIT_ASSERT(45 == y);
+                        break;
+                    case 2:
+                        CPPUNIT_ASSERT(15 == x);
+                        CPPUNIT_ASSERT(40 == y);
+                        break;
+                    case 3:
+                        CPPUNIT_ASSERT(10 == x);
+                        CPPUNIT_ASSERT(20 == y);
+                        break;
+                    case 4:
+                        CPPUNIT_ASSERT(35 == x);
+                        CPPUNIT_ASSERT(10 == y);
+                        break;
+                    }
+                }
+            }
+
+            //Inner Ring
+            {
+                CPPUNIT_ASSERT(4 == lb.cntr_size(1));
+                auto ptOffset = lb.contour_start_point(1);
+                for (int i = 0; i < lb.cntr_size(1); i++)
+                {
+                    auto x = lb.x_coord(ptOffset + i);
+                    auto y = lb.y_coord(ptOffset + i);
+                    switch (i)
+                    {
+                    case 0:
+                        CPPUNIT_ASSERT(20 == x);
+                        CPPUNIT_ASSERT(30 == y);
+                        break;
+                    case 1:
+                        CPPUNIT_ASSERT(35 == x);
+                        CPPUNIT_ASSERT(35 == y);
+                        break;
+                    case 2:
+                        CPPUNIT_ASSERT(30 == x);
+                        CPPUNIT_ASSERT(20 == y);
+                        break;
+                    case 3:
+                        CPPUNIT_ASSERT(20 == x);
+                        CPPUNIT_ASSERT(30 == y);
+                        break;
+                    }
+                }
+            }
+        }
+
+        //MultiPolygon 1
+        {
+            LineBuffer lb(8);
+            Ptr<MgByteReader> agf = agfRw.Write(gMultiPolygon1);
+            Ptr<MgByteSink> agfSink = new MgByteSink(agf);
+            Ptr<MgByte> bytes = agfSink->ToBuffer();
+            lb.LoadFromAgf(bytes->Bytes(), bytes->GetLength(), nullptr);
+
+            CPPUNIT_ASSERT(1 == lb.geom_count()); //LineBuffer flattens this
+            auto cc = lb.cntr_count();
+            CPPUNIT_ASSERT(2 == cc);
+            auto closed1 = lb.contour_closed(0);
+            auto closed2 = lb.contour_closed(1);
+
+            //Polygon 1
+            {
+                CPPUNIT_ASSERT(4 == lb.cntr_size(0));
+                auto ptOffset = lb.contour_start_point(0);
+                for (int i = 0; i < lb.cntr_size(0); i++)
+                {
+                    auto x = lb.x_coord(ptOffset + i);
+                    auto y = lb.y_coord(ptOffset + i);
+                    switch (i)
+                    {
+                    case 0:
+                        CPPUNIT_ASSERT(30 == x);
+                        CPPUNIT_ASSERT(20 == y);
+                        break;
+                    case 1:
+                        CPPUNIT_ASSERT(45 == x);
+                        CPPUNIT_ASSERT(40 == y);
+                        break;
+                    case 2:
+                        CPPUNIT_ASSERT(10 == x);
+                        CPPUNIT_ASSERT(40 == y);
+                        break;
+                    case 3:
+                        CPPUNIT_ASSERT(30 == x);
+                        CPPUNIT_ASSERT(20 == y);
+                        break;
+                    }
+                }
+            }
+
+            //Polygon 2
+            {
+                CPPUNIT_ASSERT(5 == lb.cntr_size(1));
+                auto ptOffset = lb.contour_start_point(1);
+                for (int i = 0; i < lb.cntr_size(1); i++)
+                {
+                    auto x = lb.x_coord(ptOffset + i);
+                    auto y = lb.y_coord(ptOffset + i);
+                    switch (i)
+                    {
+                    case 0:
+                        CPPUNIT_ASSERT(15 == x);
+                        CPPUNIT_ASSERT(5 == y);
+                        break;
+                    case 1:
+                        CPPUNIT_ASSERT(40 == x);
+                        CPPUNIT_ASSERT(10 == y);
+                        break;
+                    case 2:
+                        CPPUNIT_ASSERT(10 == x);
+                        CPPUNIT_ASSERT(20 == y);
+                        break;
+                    case 3:
+                        CPPUNIT_ASSERT(5 == x);
+                        CPPUNIT_ASSERT(10 == y);
+                        break;
+                    case 4:
+                        CPPUNIT_ASSERT(15 == x);
+                        CPPUNIT_ASSERT(5 == y);
+                        break;
+                    }
+                }
+            }
+        }
+
+        //MultiPolygon 2
+        {
+            LineBuffer lb(8);
+            Ptr<MgByteReader> agf = agfRw.Write(gMultiPolygon2);
+            Ptr<MgByteSink> agfSink = new MgByteSink(agf);
+            Ptr<MgByte> bytes = agfSink->ToBuffer();
+            lb.LoadFromAgf(bytes->Bytes(), bytes->GetLength(), nullptr);
+
+            CPPUNIT_ASSERT(1 == lb.geom_count()); //LineBuffer flattens this
+            auto cc = lb.cntr_count();
+            CPPUNIT_ASSERT(3 == cc);
+            auto closed1 = lb.contour_closed(0);
+            auto closed2 = lb.contour_closed(1);
+            auto closed3 = lb.contour_closed(2);
+
+            //Polygon 1
+            {
+                CPPUNIT_ASSERT(4 == lb.cntr_size(0));
+                auto ptOffset = lb.contour_start_point(0);
+                for (int i = 0; i < lb.cntr_size(0); i++)
+                {
+                    auto x = lb.x_coord(ptOffset + i);
+                    auto y = lb.y_coord(ptOffset + i);
+                    switch (i)
+                    {
+                    case 0:
+                        CPPUNIT_ASSERT(40 == x);
+                        CPPUNIT_ASSERT(40 == y);
+                        break;
+                    case 1:
+                        CPPUNIT_ASSERT(20 == x);
+                        CPPUNIT_ASSERT(45 == y);
+                        break;
+                    case 2:
+                        CPPUNIT_ASSERT(45 == x);
+                        CPPUNIT_ASSERT(30 == y);
+                        break;
+                    case 3:
+                        CPPUNIT_ASSERT(40 == x);
+                        CPPUNIT_ASSERT(40 == y);
+                        break;
+                    }
+                }
+            }
+
+            //How do we know from the LineBuffer that this is the 2nd polygon?
+
+            //Polygon 2 (inner ring)
+            {
+                CPPUNIT_ASSERT(6 == lb.cntr_size(1));
+                auto ptOffset = lb.contour_start_point(1);
+                for (int i = 0; i < lb.cntr_size(1); i++)
+                {
+                    auto x = lb.x_coord(ptOffset + i);
+                    auto y = lb.y_coord(ptOffset + i);
+                    switch (i)
+                    {
+                    case 0:
+                        CPPUNIT_ASSERT(20 == x);
+                        CPPUNIT_ASSERT(35 == y);
+                        break;
+                    case 1:
+                        CPPUNIT_ASSERT(10 == x);
+                        CPPUNIT_ASSERT(30 == y);
+                        break;
+                    case 2:
+                        CPPUNIT_ASSERT(10 == x);
+                        CPPUNIT_ASSERT(10 == y);
+                        break;
+                    case 3:
+                        CPPUNIT_ASSERT(30 == x);
+                        CPPUNIT_ASSERT(5 == y);
+                        break;
+                    case 4:
+                        CPPUNIT_ASSERT(45 == x);
+                        CPPUNIT_ASSERT(20 == y);
+                        break;
+                    case 5:
+                        CPPUNIT_ASSERT(20 == x);
+                        CPPUNIT_ASSERT(35 == y);
+                        break;
+                    }
+                }
+            }
+
+            //Polygon 2 (outer ring)
+            {
+                CPPUNIT_ASSERT(4 == lb.cntr_size(2));
+                auto ptOffset = lb.contour_start_point(2);
+                for (int i = 0; i < lb.cntr_size(2); i++)
+                {
+                    auto x = lb.x_coord(ptOffset + i);
+                    auto y = lb.y_coord(ptOffset + i);
+                    switch (i)
+                    {
+                    case 0:
+                        CPPUNIT_ASSERT(30 == x);
+                        CPPUNIT_ASSERT(20 == y);
+                        break;
+                    case 1:
+                        CPPUNIT_ASSERT(20 == x);
+                        CPPUNIT_ASSERT(15 == y);
+                        break;
+                    case 2:
+                        CPPUNIT_ASSERT(20 == x);
+                        CPPUNIT_ASSERT(25 == y);
+                        break;
+                    case 3:
+                        CPPUNIT_ASSERT(30 == x);
+                        CPPUNIT_ASSERT(20 == y);
+                        break;
+                    }
+                }
+            }
+        }
+    }
+    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: sandbox/jng/mvt_alt/Server/src/UnitTesting/TestMisc.h
===================================================================
--- sandbox/jng/mvt_alt/Server/src/UnitTesting/TestMisc.h	2019-09-21 21:36:30 UTC (rev 9612)
+++ sandbox/jng/mvt_alt/Server/src/UnitTesting/TestMisc.h	2019-09-21 23:28:21 UTC (rev 9613)
@@ -35,6 +35,7 @@
     CPPUNIT_TEST(TestCase_TryParseDouble);
     CPPUNIT_TEST(TestCase_BadResourceIdentifier);
     CPPUNIT_TEST(TestCase_ThreadSafeConfiguration);
+    CPPUNIT_TEST(TestCase_LineBuffer_Conversion);
 
     CPPUNIT_TEST(TestEnd); // This must be the very last unit test
     CPPUNIT_TEST_SUITE_END();
@@ -59,6 +60,7 @@
     void TestCase_TryParseDouble();
     void TestCase_BadResourceIdentifier();
     void TestCase_ThreadSafeConfiguration();
+    void TestCase_LineBuffer_Conversion();
 
 private:
     Ptr<MgSiteConnection> m_siteConnection;



More information about the mapguide-commits mailing list