[mapguide-commits] r10236 - in branches/4.0/MgDev: Portable/UnitTest Server/src/UnitTesting

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Fri Oct 30 05:00:47 PDT 2026


Author: jng
Date: 2026-10-30 05:00:47 -0700 (Fri, 30 Oct 2026)
New Revision: 10236

Modified:
   branches/4.0/MgDev/Portable/UnitTest/TestLogManager.cpp
   branches/4.0/MgDev/Server/src/UnitTesting/TestLogManager.cpp
Log:
Look for log file names by value in the log manager tests

r10224 made MgNamedCollection::Contains() answer whether the collection holds
that element, rather than whether it holds an element with that name, so that a
stale name-map entry can no longer report an object the collection does not
contain (#1268).

Three log manager cases were relying on the old answer. EnumerateLogs and
RenameLog build a fresh MgStringProperty and ask the collection whether it
contains it, which is now false because that property was never added, and
DeleteLog passes the file name, which binds the string overload and asks
whether a property is *named* "junkfile.log" - never true, so its assertions
could not fail. EnumerateLogs stopped at its first REQUIRE, which also meant
that RenameLog's REQUIRE_THROWS_MG checks never ran.

Changes:

  * Server/src/UnitTesting/TestLogManager.cpp: add ContainsLogName(), which
    searches the collection for a LogNameProperty whose value is the file name
    - EnumerateLogs() describes each log with three properties, the name being
    the value of that one - and use it in EnumerateLogs, DeleteLog and
    RenameLog.

  * Portable/UnitTest/TestLogManager.cpp: the same change in the mg-portable
    copy of these tests. That copy is not built by the default configuration
    (WITH_PORTABLE is off), so it was compile-checked on its own rather than
    run.

The LogManager suite passes with the change - "All tests passed (94 assertions
in 43 test cases)", on two consecutive runs in the Debug build (ubuntu22, x64)
- where the same two cases failed before it. DeleteLog's assertions and
RenameLog's exception checks now execute, and pass.


Modified: branches/4.0/MgDev/Portable/UnitTest/TestLogManager.cpp
===================================================================
--- branches/4.0/MgDev/Portable/UnitTest/TestLogManager.cpp	2026-10-30 11:56:40 UTC (rev 10235)
+++ branches/4.0/MgDev/Portable/UnitTest/TestLogManager.cpp	2026-10-30 12:00:47 UTC (rev 10236)
@@ -68,6 +68,29 @@
     }
 }
 
+// MgPortableLogManager::EnumerateLogs() describes each log file with three properties,
+// the file name being the value of its LogNameProperty property.
+// MgPropertyCollection::Contains() looks for the property object itself and not for a
+// property with the same value, so the name has to be searched for here.
+static bool ContainsLogName(MgPropertyCollection* logs, CREFSTRING fileName)
+{
+    for (INT32 i = 0;  i < logs->GetCount();  i++)
+    {
+        Ptr<MgProperty> property = logs->GetItem(i);
+
+        if (property->GetName() == L"LogNameProperty")
+        {
+            MgStringProperty* nameProperty = dynamic_cast<MgStringProperty*>(property.p);
+            if (nameProperty != NULL && nameProperty->GetValue() == fileName)
+            {
+                return true;
+            }
+        }
+    }
+
+    return false;
+}
+
 ///----------------------------------------------------------------------------
 /// Test Case Description:
 ///
@@ -144,15 +167,10 @@
         Ptr<MgPropertyCollection> logs = pMgPortableLogManager->EnumerateLogs();
 
         // Make sure the files show up in the enumeration
-        Ptr<MgStringProperty> testNameProp = new MgStringProperty(L"LogNameProperty", TestName);
-        Ptr<MgStringProperty> junkNameProp = new MgStringProperty(L"LogNameProperty", JunkName);
-        Ptr<MgStringProperty> testName2Prop = new MgStringProperty(L"LogNameProperty", TestName2);
-        Ptr<MgStringProperty> junkName2Prop = new MgStringProperty(L"LogNameProperty", JunkName2);
-
-        REQUIRE(logs->Contains(junkNameProp));
-        REQUIRE(logs->Contains(testNameProp));
-        REQUIRE(logs->Contains(junkName2Prop));
-        REQUIRE(logs->Contains(testName2Prop));
+        REQUIRE(ContainsLogName(logs, JunkName));
+        REQUIRE(ContainsLogName(logs, TestName));
+        REQUIRE(ContainsLogName(logs, JunkName2));
+        REQUIRE(ContainsLogName(logs, TestName2));
     }
     catch (MgException* e)
     {
@@ -186,11 +204,11 @@
 
         Ptr<MgPropertyCollection> logs = pMgPortableLogManager->EnumerateLogs();
 
-        REQUIRE(!logs->Contains(TestName));
-        REQUIRE(!logs->Contains(NewTestName));
-        REQUIRE(!logs->Contains(JunkName));
-        REQUIRE(!logs->Contains(TestName2));
-        REQUIRE(!logs->Contains(JunkName2));
+        REQUIRE(!ContainsLogName(logs, TestName));
+        REQUIRE(!ContainsLogName(logs, NewTestName));
+        REQUIRE(!ContainsLogName(logs, JunkName));
+        REQUIRE(!ContainsLogName(logs, TestName2));
+        REQUIRE(!ContainsLogName(logs, JunkName2));
     }
     catch (MgException* e)
     {
@@ -224,8 +242,7 @@
 
         Ptr<MgPropertyCollection> logs = pMgPortableLogManager->EnumerateLogs();
 
-        Ptr<MgStringProperty> newTestNameProp = new MgStringProperty(L"LogNameProperty", NewTestName);
-        REQUIRE(logs->Contains(newTestNameProp));
+        REQUIRE(ContainsLogName(logs, NewTestName));
 
         REQUIRE_THROWS_MG(pMgPortableLogManager->RenameLog(L"", NewTestName), MgNullArgumentException);
         REQUIRE_THROWS_MG(pMgPortableLogManager->RenameLog(NewTestName, L""), MgNullArgumentException);

Modified: branches/4.0/MgDev/Server/src/UnitTesting/TestLogManager.cpp
===================================================================
--- branches/4.0/MgDev/Server/src/UnitTesting/TestLogManager.cpp	2026-10-30 11:56:40 UTC (rev 10235)
+++ branches/4.0/MgDev/Server/src/UnitTesting/TestLogManager.cpp	2026-10-30 12:00:47 UTC (rev 10236)
@@ -68,6 +68,29 @@
     }
 }
 
+// MgLogManager::EnumerateLogs() describes each log file with three properties, the file
+// name being the value of its LogNameProperty property.  MgPropertyCollection::Contains()
+// looks for the property object itself and not for a property with the same value, so the
+// name has to be searched for here.
+static bool ContainsLogName(MgPropertyCollection* logs, CREFSTRING fileName)
+{
+    for (INT32 i = 0;  i < logs->GetCount();  i++)
+    {
+        Ptr<MgProperty> property = logs->GetItem(i);
+
+        if (property->GetName() == L"LogNameProperty")
+        {
+            MgStringProperty* nameProperty = dynamic_cast<MgStringProperty*>(property.p);
+            if (nameProperty != NULL && nameProperty->GetValue() == fileName)
+            {
+                return true;
+            }
+        }
+    }
+
+    return false;
+}
+
 ///----------------------------------------------------------------------------
 /// Test Case Description:
 ///
@@ -144,15 +167,10 @@
         Ptr<MgPropertyCollection> logs = pMgLogManager->EnumerateLogs();
 
         // Make sure the files show up in the enumeration
-        Ptr<MgStringProperty> testNameProp = new MgStringProperty(L"LogNameProperty", TestName);
-        Ptr<MgStringProperty> junkNameProp = new MgStringProperty(L"LogNameProperty", JunkName);
-        Ptr<MgStringProperty> testName2Prop = new MgStringProperty(L"LogNameProperty", TestName2);
-        Ptr<MgStringProperty> junkName2Prop = new MgStringProperty(L"LogNameProperty", JunkName2);
-
-        REQUIRE(logs->Contains(junkNameProp));
-        REQUIRE(logs->Contains(testNameProp));
-        REQUIRE(logs->Contains(junkName2Prop));
-        REQUIRE(logs->Contains(testName2Prop));
+        REQUIRE(ContainsLogName(logs, JunkName));
+        REQUIRE(ContainsLogName(logs, TestName));
+        REQUIRE(ContainsLogName(logs, JunkName2));
+        REQUIRE(ContainsLogName(logs, TestName2));
     }
     catch (MgException* e)
     {
@@ -186,11 +204,11 @@
 
         Ptr<MgPropertyCollection> logs = pMgLogManager->EnumerateLogs();
 
-        REQUIRE(!logs->Contains(TestName));
-        REQUIRE(!logs->Contains(NewTestName));
-        REQUIRE(!logs->Contains(JunkName));
-        REQUIRE(!logs->Contains(TestName2));
-        REQUIRE(!logs->Contains(JunkName2));
+        REQUIRE(!ContainsLogName(logs, TestName));
+        REQUIRE(!ContainsLogName(logs, NewTestName));
+        REQUIRE(!ContainsLogName(logs, JunkName));
+        REQUIRE(!ContainsLogName(logs, TestName2));
+        REQUIRE(!ContainsLogName(logs, JunkName2));
     }
     catch (MgException* e)
     {
@@ -224,8 +242,7 @@
 
         Ptr<MgPropertyCollection> logs = pMgLogManager->EnumerateLogs();
 
-        Ptr<MgStringProperty> newTestNameProp = new MgStringProperty(L"LogNameProperty", NewTestName);
-        REQUIRE(logs->Contains(newTestNameProp));
+        REQUIRE(ContainsLogName(logs, NewTestName));
 
         REQUIRE_THROWS_MG(pMgLogManager->RenameLog(L"", NewTestName), MgInvalidArgumentException);
         REQUIRE_THROWS_MG(pMgLogManager->RenameLog(NewTestName, L""), MgInvalidArgumentException);



More information about the mapguide-commits mailing list