Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit f48794ca authored by Laurent Montel's avatar Laurent Montel 😁

Start to create autotest for loading/saving autocorrection file

parent 488a5b20
......@@ -1112,45 +1112,55 @@ void AutoCorrection::readAutoCorrectionXmlFile(bool forceGlobal)
//qCDebug(PIMCOMMON_LOG)<<" LocalFile:"<<LocalFile;
if (localFileName.isEmpty()) {
if (fname.isEmpty()) {
mTypographicSingleQuotes = typographicDefaultSingleQuotes();
mTypographicDoubleQuotes = typographicDefaultDoubleQuotes();
} else {
ImportKMailAutocorrection import;
if (import.import(fname, ImportAbstractAutocorrection::All)) {
mUpperCaseExceptions = import.upperCaseExceptions();
mTwoUpperLetterExceptions = import.twoUpperLetterExceptions();
mAutocorrectEntries = import.autocorrectEntries();
mTypographicSingleQuotes = import.typographicSingleQuotes();
mTypographicDoubleQuotes = import.typographicDoubleQuotes();
mSuperScriptEntries = import.superScriptEntries();
if (forceGlobal) {
mTypographicSingleQuotes = typographicDefaultSingleQuotes();
mTypographicDoubleQuotes = typographicDefaultDoubleQuotes();
}
mMaxFindStringLenght = import.maxFindStringLenght();
mMinFindStringLenght = import.minFindStringLenght();
}
}
loadGlobalFileName(fname, forceGlobal);
} else {
loadLocalFileName(localFileName, fname);
}
}
void AutoCorrection::loadGlobalFileName(const QString &fname, bool forceGlobal)
{
if (fname.isEmpty()) {
mTypographicSingleQuotes = typographicDefaultSingleQuotes();
mTypographicDoubleQuotes = typographicDefaultDoubleQuotes();
} else {
ImportKMailAutocorrection import;
if (import.import(localFileName, ImportAbstractAutocorrection::All)) {
if (import.import(fname, ImportAbstractAutocorrection::All)) {
mUpperCaseExceptions = import.upperCaseExceptions();
mTwoUpperLetterExceptions = import.twoUpperLetterExceptions();
mAutocorrectEntries = import.autocorrectEntries();
mTypographicSingleQuotes = import.typographicSingleQuotes();
mTypographicDoubleQuotes = import.typographicDoubleQuotes();
//Don't import it in local
//mSuperScriptEntries = import.superScriptEntries();
}
if (!fname.isEmpty() && import.import(fname, ImportAbstractAutocorrection::SuperScript)) {
mSuperScriptEntries = import.superScriptEntries();
if (forceGlobal) {
mTypographicSingleQuotes = typographicDefaultSingleQuotes();
mTypographicDoubleQuotes = typographicDefaultDoubleQuotes();
}
mMaxFindStringLenght = import.maxFindStringLenght();
mMinFindStringLenght = import.minFindStringLenght();
}
mMaxFindStringLenght = import.maxFindStringLenght();
mMinFindStringLenght = import.minFindStringLenght();
}
}
void AutoCorrection::loadLocalFileName(const QString &localFileName, const QString &fname)
{
ImportKMailAutocorrection import;
if (import.import(localFileName, ImportAbstractAutocorrection::All)) {
mUpperCaseExceptions = import.upperCaseExceptions();
mTwoUpperLetterExceptions = import.twoUpperLetterExceptions();
mAutocorrectEntries = import.autocorrectEntries();
mTypographicSingleQuotes = import.typographicSingleQuotes();
mTypographicDoubleQuotes = import.typographicDoubleQuotes();
//Don't import it in local
//mSuperScriptEntries = import.superScriptEntries();
}
if (!fname.isEmpty() && import.import(fname, ImportAbstractAutocorrection::SuperScript)) {
mSuperScriptEntries = import.superScriptEntries();
}
mMaxFindStringLenght = import.maxFindStringLenght();
mMinFindStringLenght = import.minFindStringLenght();
}
void AutoCorrection::writeAutoCorrectionXmlFile(const QString &filename)
{
const QString fname = filename.isEmpty() ? QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/autocorrect/custom-") + (mAutoCorrectLang == QLatin1String("en_US") ? QStringLiteral("autocorrect") : mAutoCorrectLang) + QLatin1String(".xml") : filename;
......
......@@ -90,6 +90,8 @@ public:
void setNonBreakingSpace(const QChar &nonBreakingSpace);
void loadGlobalFileName(const QString &fname, bool forceGlobal);
void loadLocalFileName(const QString &localFileName, const QString &fname);
private:
bool isFrenchLanguage() const;
void readConfig();
......
add_definitions( -DAUTOCORRECTION_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data" )
macro(add_pimcommon_autocorrect_unittest _source)
ecm_add_test(${_source}
NAME_PREFIX "pimcommon-autocorrection-"
......
......@@ -668,4 +668,17 @@ void AutoCorrectionTest::shouldAddNonBreakingSpaceBeforeAfterQuote()
QCOMPARE(doc.toPlainText(), QString(doubleQuote.begin + nbsp + text + nbsp + doubleQuote.end));
}
void AutoCorrectionTest::shouldLoadSaveAutocorrection_data()
{
QTest::addColumn<QString>("filename");
QTest::newRow("empty") << QString();
}
void AutoCorrectionTest::shouldLoadSaveAutocorrection()
{
QFETCH(QString, filename);
PimCommon::AutoCorrection autocorrection;
//autocorrection.
}
QTEST_MAIN(AutoCorrectionTest)
......@@ -52,6 +52,9 @@ private Q_SLOTS:
void shouldAddNonBreakingSpaceBeforeAfterQuote();
void shouldLoadSaveAutocorrection_data();
void shouldLoadSaveAutocorrection();
private:
KSharedConfig::Ptr mConfig;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment