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.bergmann@allotropia.de>
This commit is contained in:
Stephan Bergmann
2025-04-14 22:31:57 +02:00
parent f16f694168
commit 2adacda491

View File

@@ -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]\nkey=value1\n[section2]\nkey=value2\n";
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);
}