Commit defeed7f authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

EmailValidator was moved in pimcommon directly

parent 2e6c721d
Pipeline #23830 passed with stage
in 13 minutes and 47 seconds
......@@ -7,7 +7,6 @@ ecm_setup_version(PROJECT VARIABLE_PREFIX LIBKDEPIM
if (BUILD_TESTING)
add_subdirectory(tests)
add_subdirectory(misc/autotests)
add_subdirectory(progresswidget/autotests/)
add_subdirectory(progresswidget/tests/)
endif()
......@@ -29,7 +28,6 @@ set(kdepim_widgets_LIB_SRCS
)
set(kdepim_misc_LIB_SRCS
misc/emailvalidator.cpp
misc/uistatesaver.cpp
misc/lineeditcatchreturnkey.cpp
)
......@@ -103,7 +101,6 @@ ecm_generate_headers(libkdepim_Camelcasewidgets_HEADERS
ecm_generate_headers(libkdepim_Camelcasemisc_HEADERS
HEADER_NAMES
EmailValidator
UiStateSaver
KCursorSaver
LineEditCatchReturnKey
......
macro(add_libkdepim_misc_unittest _name)
ecm_add_test(${ARGN}
TEST_NAME ${_name}
NAME_PREFIX "libkdepim-misc-"
LINK_LIBRARIES Qt5::Test
Qt5::Widgets
KF5::Libkdepim
)
endmacro()
add_libkdepim_misc_unittest(emailvalidatortest emailvalidatortest.cpp)
/*
Copyright (C) 2017-2020 Laurent Montel <montel@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "emailvalidatortest.h"
#include <Libkdepim/EmailValidator>
#include <QTest>
QTEST_MAIN(EmailValidatorTest)
Q_DECLARE_METATYPE(QValidator::State)
EmailValidatorTest::EmailValidatorTest(QObject *parent)
: QObject(parent)
{
}
void EmailValidatorTest::shouldValidateEmail_data()
{
QTest::addColumn<QString>("email");
QTest::addColumn<QValidator::State>("state");
QTest::newRow("empty") << QString() << QValidator::Intermediate;
QTest::newRow("email") << QStringLiteral("foo@kde.org") << QValidator::Acceptable;
QTest::newRow("notanemail") << QStringLiteral("foo") << QValidator::Intermediate;
QTest::newRow("space") << QStringLiteral("foo ") << QValidator::Invalid;
QTest::newRow("space1") << QStringLiteral(" foo") << QValidator::Invalid;
QTest::newRow("email2") << QStringLiteral("<foo@kde.org>") << QValidator::Intermediate;
QTest::newRow("email3") << QStringLiteral("\"bla\" <foo@kde.org>") << QValidator::Invalid;
}
void EmailValidatorTest::shouldValidateEmail()
{
QFETCH(QString, email);
QFETCH(QValidator::State, state);
KPIM::EmailValidator val(nullptr);
int pos;
QCOMPARE(val.validate(email, pos), state);
}
/*
Copyright (C) 2017-2020 Laurent Montel <montel@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef EMAILVALIDATORTEST_H
#define EMAILVALIDATORTEST_H
#include <QObject>
class EmailValidatorTest : public QObject
{
Q_OBJECT
public:
explicit EmailValidatorTest(QObject *parent = nullptr);
~EmailValidatorTest() = default;
private Q_SLOTS:
void shouldValidateEmail_data();
void shouldValidateEmail();
};
#endif // EMAILVALIDATORTEST_H
/*
Copyright (C) 2010 Casey Link <unnamedrambler@gmail.com>
Copyright (C) 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "emailvalidator.h"
#include <KEmailAddress>
#include <QRegularExpression>
using namespace KPIM;
EmailValidator::EmailValidator(QObject *parent) : QValidator(parent)
{
}
QValidator::State EmailValidator::validate(QString &str, int &pos) const
{
Q_UNUSED(pos);
if (KEmailAddress::isValidSimpleAddress(str)) {
return QValidator::Acceptable;
}
QRegularExpression re(QStringLiteral("\\s"));
QRegularExpressionMatch match = re.match(str);
if (match.hasMatch()) {
return QValidator::Invalid;
}
return QValidator::Intermediate;
}
void EmailValidator::fixup(QString &str) const
{
str = str.trimmed();
}
/*
Copyright (C) 2010 Casey Link <unnamedrambler@gmail.com>
Copyright (C) 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef EMAILVALIDATOR_H
#define EMAILVALIDATOR_H
#include "kdepim_export.h"
#include <QValidator>
namespace KPIM {
/**
A validator that enforces correct email addresses.
@see KEmailAddress::isValidSimpleAddress
*/
class KDEPIM_EXPORT EmailValidator : public QValidator //krazy:exclude=dpointer
{
Q_OBJECT
public:
explicit EmailValidator(QObject *parent);
State validate(QString &str, int &pos) const override;
void fixup(QString &str) const override;
};
}
#endif
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