Skip to content

Commit a14f0b1

Browse files
author
Xisco Fauli
committed
CppunitTest_sw_autocorrect: move some tests here
and name them by language Change-Id: I634d31cd968ffdcbf2b92766980cae8bfb2afdb5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170506 Tested-by: Jenkins Reviewed-by: Xisco Fauli <[email protected]>
1 parent 5d0de0b commit a14f0b1

File tree

6 files changed

+85
-329
lines changed

6 files changed

+85
-329
lines changed

sw/qa/extras/autocorrect/autocorrect.cxx

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
#include <swmodeltestbase.hxx>
1111

12+
#include <comphelper/configuration.hxx>
1213
#include <docsh.hxx>
14+
#include <officecfg/Office/Common.hxx>
1315
#include <unotxdoc.hxx>
1416

1517
// If you want to add a test for a language that doesn't exists yet
@@ -38,6 +40,71 @@ CPPUNIT_TEST_FIXTURE(SwAutoCorrect, nl_BE)
3840
CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
3941
}
4042

43+
CPPUNIT_TEST_FIXTURE(SwAutoCorrect, fr_FR)
44+
{
45+
createSwDoc("fr-FR.fodt");
46+
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
47+
CPPUNIT_ASSERT(pTextDoc);
48+
49+
dispatchCommand(mxComponent, u".uno:GoToEndOfDoc"_ustr, {});
50+
51+
// tdf#158703: Typing ":" after the spaces should start auto-correction, which is expected to
52+
// remove the spaces, and insert an NBSP instead. It must not crash.
53+
emulateTyping(*pTextDoc, u"Foo :");
54+
CPPUNIT_ASSERT_EQUAL(u"Foo\u00A0:"_ustr, getParagraph(1)->getString());
55+
}
56+
57+
CPPUNIT_TEST_FIXTURE(SwAutoCorrect, pt_BR)
58+
{
59+
createSwDoc("pt-BR.fodt");
60+
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
61+
CPPUNIT_ASSERT(pTextDoc);
62+
63+
// tdf#44293
64+
emulateTyping(*pTextDoc, u"1a 1o ");
65+
CPPUNIT_ASSERT_EQUAL(u"1.a 1.o "_ustr, getParagraph(1)->getString());
66+
emulateTyping(*pTextDoc, u"1ra 1ro ");
67+
CPPUNIT_ASSERT_EQUAL(u"1.a 1.o 1.a 1.o "_ustr, getParagraph(1)->getString());
68+
emulateTyping(*pTextDoc, u"43as 43os 43ras 43ros ");
69+
CPPUNIT_ASSERT_EQUAL(u"1.a 1.o 1.a 1.o 43.as 43.os 43.as 43.os "_ustr,
70+
getParagraph(1)->getString());
71+
}
72+
73+
CPPUNIT_TEST_FIXTURE(SwAutoCorrect, de_DE)
74+
{
75+
Resetter resetter([]() {
76+
std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
77+
comphelper::ConfigurationChanges::create());
78+
officecfg::Office::Common::AutoCorrect::SingleQuoteAtStart::set(0, pBatch);
79+
officecfg::Office::Common::AutoCorrect::SingleQuoteAtEnd::set(0, pBatch);
80+
return pBatch->commit();
81+
});
82+
// Set Single Quotes › and ‹
83+
std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
84+
comphelper::ConfigurationChanges::create());
85+
officecfg::Office::Common::AutoCorrect::SingleQuoteAtStart::set(8250, pBatch);
86+
officecfg::Office::Common::AutoCorrect::SingleQuoteAtEnd::set(8249, pBatch);
87+
pBatch->commit();
88+
89+
createSwDoc("de-DE.fodt");
90+
SwDoc* pDoc = getSwDoc();
91+
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
92+
CPPUNIT_ASSERT(pWrtShell);
93+
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
94+
// tdf#151801: Single starting quote: 'word -> ›word
95+
emulateTyping(*pTextDoc, u"'word");
96+
OUString sReplaced(u"\u203Aword"_ustr);
97+
CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
98+
// tdf#151801: Single ending quote: ›word' -> ›word‹
99+
emulateTyping(*pTextDoc, u"'");
100+
sReplaced += u"\u2039";
101+
CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
102+
// tdf#151801: Use apostrophe without preceding starting quote: word' -> word’
103+
emulateTyping(*pTextDoc, u" word'");
104+
sReplaced += u" word\u2019";
105+
CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
106+
}
107+
41108
CPPUNIT_PLUGIN_IMPLEMENT();
42109

43110
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

sw/qa/extras/uiwriter/data/tdf158703.fodt renamed to sw/qa/extras/autocorrect/data/de-DE.fodt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
44
<office:automatic-styles>
55
<style:style style:name="P1" style:family="paragraph">
6-
<style:text-properties fo:language="fr" fo:country="FR"/>
6+
<style:text-properties fo:language="de" fo:country="DE"/>
77
</style:style>
88
</office:automatic-styles>
99
<office:body>
1010
<office:text>
11-
<text:p text:style-name="P1">Foo <text:s text:c="5"/></text:p>
11+
<text:p text:style-name="P1"></text:p>
1212
</office:text>
1313
</office:body>
14-
</office:document>
14+
</office:document>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
4+
<office:styles>
5+
<style:style style:name="Standard" style:family="paragraph" style:class="text"/>
6+
<style:default-style style:family="paragraph">
7+
<style:text-properties fo:language="fr" fo:country="FR"/>
8+
</style:default-style>
9+
</office:styles>
10+
<office:body>
11+
<office:text>
12+
<text:p text:style-name="Standard"></text:p>
13+
</office:text>
14+
</office:body>
15+
</office:document>

0 commit comments

Comments
 (0)