sal/qa/rtl/bootstrap/expand.cxx |   50 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

New commits:
commit 2adacda491cf22f637e6419c4a735c0783e214e6
Author:     Stephan Bergmann <stephan.bergm...@allotropia.de>
AuthorDate: Mon Apr 14 22:31:57 2025 +0200
Commit:     Stephan Bergmann <stephan.bergm...@allotropia.de>
CommitDate: Tue Apr 15 08:01:29 2025 +0200

    Add a test for three-segment ${file:segment:key} bootstrap references
    
    Change-Id: I6d99cbdc5924b0afefaa1f5f7316824b81ccb474
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184179
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <stephan.bergm...@allotropia.de>

diff --git a/sal/qa/rtl/bootstrap/expand.cxx b/sal/qa/rtl/bootstrap/expand.cxx
index cb9acb3a200f..3d827cc2f63f 100644
--- a/sal/qa/rtl/bootstrap/expand.cxx
+++ b/sal/qa/rtl/bootstrap/expand.cxx
@@ -9,10 +9,14 @@
 
 #include <sal/config.h>
 
+#include <cstring>
+
 #include <cppunit/TestAssert.h>
 #include <cppunit/TestFixture.h>
 #include <cppunit/extensions/HelperMacros.h>
+#include <osl/file.hxx>
 #include <rtl/bootstrap.hxx>
+#include <rtl/ustrbuf.hxx>
 #include <rtl/ustring.hxx>
 
 namespace {
@@ -25,11 +29,14 @@ private:
     CPPUNIT_TEST_SUITE(Test);
     CPPUNIT_TEST(testDollar);
     CPPUNIT_TEST(testIndirectDollar);
+    CPPUNIT_TEST(testThreeSegments);
     CPPUNIT_TEST_SUITE_END();
 
     void testDollar();
 
     void testIndirectDollar();
+
+    void testThreeSegments();
 };
 
 void Test::setUp() {
@@ -50,6 +57,49 @@ void Test::testIndirectDollar() {
     CPPUNIT_ASSERT_EQUAL(u"foo$TEST"_ustr, s);
 }
 
+void Test::testThreeSegments() {
+    OUString url;
+    CPPUNIT_ASSERT(rtl::Bootstrap::get(u"UserInstallation"_ustr, url));
+    url += "/testThreeSegments.ini";
+    {
+        osl::File f(url);
+        CPPUNIT_ASSERT_EQUAL(
+            osl::FileBase::E_None, f.open(osl_File_OpenFlag_Write | 
osl_File_OpenFlag_Create));
+        char const data[] = "[section1]
key=value1
[section2]
key=value2
";
+        sal_uInt64 length = std::strlen(data);
+        sal_uInt64 written = 0;
+        CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, f.write(data, length, 
written));
+        CPPUNIT_ASSERT_EQUAL(length, written);
+        CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, f.close());
+    }
+    OUString esc;
+    {
+        OUStringBuffer buf;
+        for (sal_Int32 i = 0; i != url.getLength(); ++i) {
+            auto const c = url[i];
+            switch (c) {
+            case ':':
+            case '\':
+            case '{':
+            case '}':
+                buf.append('\');
+            }
+            buf.append(c);
+        }
+        esc = buf.makeStringAndClear();
+    }
+    {
+        OUString s("${" + esc + ":section1:key}");
+        rtl::Bootstrap::expandMacros(s);
+        CPPUNIT_ASSERT_EQUAL(u"value1"_ustr, s);
+    }
+    {
+        OUString s("${" + esc + ":section2:key}");
+        rtl::Bootstrap::expandMacros(s);
+        CPPUNIT_ASSERT_EQUAL(u"value2"_ustr, s);
+    }
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 
 }

Reply via email to