summaryrefslogtreecommitdiff
path: root/sd/qa
diff options
context:
space:
mode:
authorMaxim Monastirsky <momonasmon@gmail.com>2022-12-07 15:51:01 +0200
committerMaxim Monastirsky <momonasmon@gmail.com>2022-12-09 00:13:30 +0000
commit8bd31225d79f10993d0e0727ee7d27c729874b51 (patch)
treedc811ae2899ae23945e071a1ac3dd8e60648e250 /sd/qa
parent15e94efb87118b0ceb4aa926181a8906259f369b (diff)
Fix sd encoded table style name handling
Found this while looking into improving insertion of pages with tables, as SdDrawDocument::InsertBookmarkAsPage uses "_" as the rename suffix for styles with identical names but a different content. This commit fixes two issues: - For import, cell styles with encoded names couldn't be found by table styles. The reason is that styles are referenced in ODF by encoded names, but at runtime by display names. Yet we were searching the cell style family by encoded names. This was already handled for sw in insertTabletemplate(), and now do the same for sd. - For export, table template names were encoded, but then referenced by tables using their non-encoded names. This is unlike the sw code that doesn't encode them, and therefore doesn't have this problem. Looking at the schema, both table:name attribute of a table template, and table:template-name attribute of a table are of type "string", which suggests that there is indeed no need to encode those names. This aligns with the fact that table templates don't have a display-name attribute. Change-Id: Ie61b6a1c95b033404ee98f3fc40d8e82434a6a6c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143839 Tested-by: Jenkins Reviewed-by: Maxim Monastirsky <momonasmon@gmail.com>
Diffstat (limited to 'sd/qa')
-rw-r--r--sd/qa/unit/misc-tests.cxx52
1 files changed, 52 insertions, 0 deletions
diff --git a/sd/qa/unit/misc-tests.cxx b/sd/qa/unit/misc-tests.cxx
index bc741c6ac2fe..ee03008dfb47 100644
--- a/sd/qa/unit/misc-tests.cxx
+++ b/sd/qa/unit/misc-tests.cxx
@@ -24,6 +24,7 @@
#include <com/sun/star/container/XIndexAccess.hpp>
#include <com/sun/star/table/XTable.hpp>
#include <com/sun/star/table/XMergeableCellRange.hpp>
+#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#include <DrawDocShell.hxx>
#include <drawdoc.hxx>
@@ -80,6 +81,7 @@ public:
void testTdf131033();
void testTdf129898LayerDrawnInSlideshow();
void testTdf136956();
+ void testEncodedTableStyles();
CPPUNIT_TEST_SUITE(SdMiscTest);
CPPUNIT_TEST(testTdf99396);
@@ -101,6 +103,7 @@ public:
CPPUNIT_TEST(testTdf131033);
CPPUNIT_TEST(testTdf129898LayerDrawnInSlideshow);
CPPUNIT_TEST(testTdf136956);
+ CPPUNIT_TEST(testEncodedTableStyles);
CPPUNIT_TEST_SUITE_END();
virtual void registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) override
@@ -891,6 +894,55 @@ void SdMiscTest::testTdf136956()
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTable->getRowCount());
}
+void SdMiscTest::testEncodedTableStyles()
+{
+ // Silence unrelated failure:
+ // Error: element "table:table-template" is missing "first-row-start-column" attribute
+ skipValidation();
+
+ createSdDrawDoc();
+
+ {
+ uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(mxComponent,
+ uno::UNO_QUERY_THROW);
+ uno::Reference<css::lang::XSingleServiceFactory> xTableStyleFamily(
+ xStyleFamiliesSupplier->getStyleFamilies()->getByName("table"), uno::UNO_QUERY_THROW);
+ uno::Reference<css::lang::XSingleServiceFactory> xCellStyleFamily(
+ xStyleFamiliesSupplier->getStyleFamilies()->getByName("cell"), uno::UNO_QUERY_THROW);
+
+ uno::Reference<style::XStyle> xTableStyle(xTableStyleFamily->createInstance(),
+ uno::UNO_QUERY_THROW);
+ uno::Reference<style::XStyle> xCellStyle(xCellStyleFamily->createInstance(),
+ uno::UNO_QUERY_THROW);
+
+ uno::Reference<container::XNameContainer>(xTableStyleFamily, uno::UNO_QUERY_THROW)
+ ->insertByName("table_1", uno::Any(xTableStyle));
+ uno::Reference<container::XNameContainer>(xCellStyleFamily, uno::UNO_QUERY_THROW)
+ ->insertByName("table-body_1", uno::Any(xCellStyle));
+ uno::Reference<container::XNameReplace>(xTableStyle, uno::UNO_QUERY_THROW)
+ ->replaceByName("body", uno::Any(xCellStyle));
+ }
+
+ saveAndReload("draw8");
+
+ {
+ uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(mxComponent,
+ uno::UNO_QUERY_THROW);
+ uno::Reference<container::XNameAccess> xTableStyleFamily(
+ xStyleFamiliesSupplier->getStyleFamilies()->getByName("table"), uno::UNO_QUERY_THROW);
+ // Such style used to be exported as "table_5f_1" instead.
+ CPPUNIT_ASSERT(xTableStyleFamily->hasByName("table_1"));
+
+ uno::Reference<container::XNameAccess> xTableStyle(xTableStyleFamily->getByName("table_1"),
+ uno::UNO_QUERY_THROW);
+ uno::Reference<style::XStyle> xCellStyle(xTableStyle->getByName("body"), uno::UNO_QUERY);
+ // Such style used to not be found by the table style, as it was
+ // searching for "table-body_5f_1" instead of "table-body_1".
+ CPPUNIT_ASSERT(xCellStyle.is());
+ CPPUNIT_ASSERT_EQUAL(OUString("table-body_1"), xCellStyle->getName());
+ }
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SdMiscTest);
CPPUNIT_PLUGIN_IMPLEMENT();