sw/inc/fldbas.hxx | 3 +- sw/qa/uibase/fldui/fldui.cxx | 55 ++++++++++++++++++++------------------ sw/source/uibase/fldui/fldmgr.cxx | 3 +- 3 files changed, 34 insertions(+), 27 deletions(-)
New commits: commit 901f13195347b334319b87a7b7d4e9257f1c492c Author: Andreas Heinisch <[email protected]> AuthorDate: Tue Feb 10 10:15:16 2026 +0100 Commit: Andreas Heinisch <[email protected]> CommitDate: Tue Feb 10 16:42:36 2026 +0100 tdf#170392 - Align file name format constants FilenameDisplayFormat.idl Change-Id: If7679a2de049caf03865eef62ed5c4e8aa3b3aab Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199028 Reviewed-by: Andreas Heinisch <[email protected]> Tested-by: Jenkins diff --git a/sw/inc/fldbas.hxx b/sw/inc/fldbas.hxx index 1d29362b3caa..5756dccae44b 100644 --- a/sw/inc/fldbas.hxx +++ b/sw/inc/fldbas.hxx @@ -150,10 +150,11 @@ enum class SwFieldTypesEnum : sal_uInt16 { }; // tdf#170392 - this should be aligned with FMT_FF_ARY in sw/source/uibase/fldui/fldmgr.cxx +// including com::sun::star::text::FilenameDisplayFormat enum class SwFileNameFormat { // most of the constants are a regular enum - Path, PathName, + Path, NameNoExt, Name, UIName, diff --git a/sw/qa/uibase/fldui/fldui.cxx b/sw/qa/uibase/fldui/fldui.cxx index ea1168e89a36..7cad0330dccf 100644 --- a/sw/qa/uibase/fldui/fldui.cxx +++ b/sw/qa/uibase/fldui/fldui.cxx @@ -164,32 +164,37 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf68364InsertConditionalFieldWithTwoDots) CPPUNIT_ASSERT_EQUAL(u"19.12.2023"_ustr, pWrtShell->GetCurField()->ExpandField(true, nullptr)); } -CPPUNIT_TEST_FIXTURE(Test, testTdf170392FilenameFormatConstants) +CPPUNIT_TEST_FIXTURE(Test, testTdf170392FilenameFormatConstantsIdl) { - // Create an empty document - createSwDoc(); - SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); - - // Insert a filename field containing SwFileNameFormat::Path - SwFieldMgr aFieldMgr(pWrtShell); - SwInsertField_Data aFieldData(SwFieldTypesEnum::Filename, 0, u""_ustr, u""_ustr, 3); - CPPUNIT_ASSERT(aFieldMgr.InsertField(aFieldData)); - - // First reload in order to get a value for the filename field - saveAndReload(TestFilter::ODT); - pWrtShell = getSwDocShell()->GetWrtShell(); - pWrtShell->SttEndDoc(true); - const auto aExpandedField = pWrtShell->GetCurField()->ExpandField(true, nullptr); - - // Second reload in order to check consistency for the filename field - saveAndReload(TestFilter::ODT); - pWrtShell = getSwDocShell()->GetWrtShell(); - pWrtShell->SttEndDoc(true); - - // Without the accompanying fix in place, this test would have failed with: - // - Expected: filename field is the same - // - Actual : filename field differ since the filename format constants differ - CPPUNIT_ASSERT_EQUAL(aExpandedField, pWrtShell->GetCurField()->ExpandField(true, nullptr)); + SwFileNameFormat aFormats[] = { SwFileNameFormat::Name, SwFileNameFormat::Path }; + for (SwFileNameFormat eFormat : aFormats) + { + // Create an empty document + createSwDoc(); + SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); + + // Insert a filename field containing a specific format + SwFieldMgr aFieldMgr(pWrtShell); + SwInsertField_Data aFieldData(SwFieldTypesEnum::Filename, 0, u""_ustr, u""_ustr, + static_cast<sal_uInt32>(eFormat)); + CPPUNIT_ASSERT(aFieldMgr.InsertField(aFieldData)); + + // First reload in order to get a value for the filename field + saveAndReload(TestFilter::ODT); + pWrtShell = getSwDocShell()->GetWrtShell(); + pWrtShell->SttEndDoc(true); + const auto aExpandedField = pWrtShell->GetCurField()->ExpandField(true, nullptr); + + // Second reload in order to check consistency for the filename field + saveAndReload(TestFilter::ODT); + pWrtShell = getSwDocShell()->GetWrtShell(); + pWrtShell->SttEndDoc(true); + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: filename field is the same + // - Actual : filename field differ since the filename format constants differ + CPPUNIT_ASSERT_EQUAL(aExpandedField, pWrtShell->GetCurField()->ExpandField(true, nullptr)); + } } CPPUNIT_TEST_FIXTURE(Test, testInsertRefmarkSelection) diff --git a/sw/source/uibase/fldui/fldmgr.cxx b/sw/source/uibase/fldui/fldmgr.cxx index 802d7f37f219..c4601be97783 100644 --- a/sw/source/uibase/fldui/fldmgr.cxx +++ b/sw/source/uibase/fldui/fldmgr.cxx @@ -189,10 +189,11 @@ const TranslateId FMT_NUM_ARY[] = }; // tdf#170392 - this should be aligned with enum SwFileNameFormat in sw/inc/fldbas.hxx +// including com::sun::star::text::FilenameDisplayFormat const TranslateId FMT_FF_ARY[] = { - FMT_FF_PATH, FMT_FF_PATHNAME, + FMT_FF_PATH, FMT_FF_NAME_NOEXT, FMT_FF_NAME, FMT_FF_UI_NAME,
