File indexing completed on 2024-11-24 04:53:36

0001 /* Copyright (C) 2016 Thomas Lübking <thomas.luebking@gmail.com>
0002 
0003    This file is part of the Trojita Qt IMAP e-mail client,
0004    http://trojita.flaska.net/
0005 
0006    This program is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU General Public License as
0008    published by the Free Software Foundation; either version 2 of
0009    the License or (at your option) version 3 or any later version
0010    accepted by the membership of KDE e.V. (or its successor approved
0011    by the membership of KDE e.V.), which shall act as a proxy
0012    defined in Section 14 of version 3 of the license.
0013 
0014    This program is distributed in the hope that it will be useful,
0015    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017    GNU General Public License for more details.
0018 
0019    You should have received a copy of the GNU General Public License
0020    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021 */
0022 
0023 #include <QTest>
0024 #include "test_Formatting.h"
0025 
0026 #include "UiUtils/Formatting.h"
0027 
0028 void TestFormatting::testAddressEliding()
0029 {
0030     QFETCH(QString, original);
0031     QFETCH(QString, expected);
0032     QFETCH(bool, wasElided);
0033 
0034     QCOMPARE(UiUtils::elideAddress(original), wasElided);
0035     QCOMPARE(original /* now elided */, expected);
0036 }
0037 
0038 void TestFormatting::testAddressEliding_data()
0039 {
0040     QTest::addColumn<QString>("original");
0041     QTest::addColumn<QString>("expected");
0042     QTest::addColumn<bool>("wasElided");
0043 
0044     QTest::newRow("normal-address")
0045         << QStringLiteral("homer@springfield.us")
0046         << QStringLiteral("homer@springfield.us")
0047         << false;
0048 
0049     // address is too long, but we don't want to touch the domain and the local part is too short
0050     QTest::newRow("long-domain")
0051         << QStringLiteral("homer@burns-nucular-plant-near-moes-tavern-in-springfield-usa.com")
0052         << QStringLiteral("homer@burns-nucular-plant-near-moes-tavern-in-springfield-usa.com")
0053         << false;
0054 
0055     // elide local part, but leave 4 heading and tailing chars intact
0056     QTest::newRow("eliding-local-preserve-head-tail")
0057         << QStringLiteral("homer.simpson@burns-nucular-plant-near-moes-tavern-in-springfield-usa.com")
0058         << QStringLiteral("home\u2026pson@burns-nucular-plant-near-moes-tavern-in-springfield-usa.com")
0059         << true;
0060 
0061     // elide overly long local part, leave domain intact, result shall have 60 chars (+ellipsis)
0062     QTest::newRow("eliding-in-local-part")
0063         << QStringLiteral("homer_marge_bart_lisa_and_margaret_who_is_margaret.simpson@springfield.us")
0064         << QStringLiteral("homer_marge_bart_lisa_\u2026ho_is_margaret.simpson@springfield.us")
0065         << true;
0066 
0067     // in random long strings, leave 30 leading and tailing chars
0068     QTest::newRow("elide-non-mail")
0069         << QStringLiteral("012345678901234567890123456789 0123456789 012345678901234567890123456789")
0070         << QStringLiteral("012345678901234567890123456789\u2026012345678901234567890123456789")
0071         << true;
0072 
0073 }
0074 
0075 QTEST_GUILESS_MAIN(TestFormatting)