1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
/**
* Copyright (C) 2013 Canonical, Ltd.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 3, as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
* SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
*/
#include <QtCore/QObject>
#include <QtTest/QtTest>
#include "phoneutils_p.h"
class PhoneUtilsTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testIsPhoneNumber_data();
void testIsPhoneNumber();
void testComparePhoneNumbers_data();
void testComparePhoneNumbers();
};
void PhoneUtilsTest::testIsPhoneNumber_data()
{
QTest::addColumn<QString>("number");
QTest::addColumn<bool>("expectedResult");
QTest::newRow("simple number") << "12345678" << true;
QTest::newRow("number with dash") << "1234-5678" << true;
QTest::newRow("number with area code") << "(123)12345678" << true;
QTest::newRow("number with extension") << "12345678#123" << true;
QTest::newRow("number with comma") << "33333333,1,1" << false;
QTest::newRow("number with semicolon") << "33333333;1" << false;
QTest::newRow("short/emergency number") << "190" << true;
QTest::newRow("non phone numbers") << "abcdefg" << false;
QTest::newRow("phone number with dots") << "+31 (475) 12.34.56" << true;
QTest::newRow("number with slash") << "+421 2/123 456 78" << true;
}
void PhoneUtilsTest::testIsPhoneNumber()
{
QFETCH(QString, number);
QFETCH(bool, expectedResult);
bool result = PhoneUtils::isPhoneNumber(number);
QCOMPARE(result, expectedResult);
}
void PhoneUtilsTest::testComparePhoneNumbers_data()
{
QTest::addColumn<QString>("number1");
QTest::addColumn<QString>("number2");
QTest::addColumn<bool>("expectedResult");
QTest::newRow("string equal") << "12345678" << "12345678" << true;
QTest::newRow("number with dash") << "1234-5678" << "12345678" << true;
QTest::newRow("number with area code") << "12312345678" << "12345678" << true;
QTest::newRow("number with extension") << "12345678#123" << "12345678" << true;
QTest::newRow("both numbers with extension") << "(123)12345678#1" << "12345678#1" << true;
QTest::newRow("numbers with different extension") << "1234567#1" << "1234567#2" << false;
QTest::newRow("short/emergency numbers") << "190" << "190" << true;
QTest::newRow("different numbers") << "12345678" << "1234567" << false;
QTest::newRow("both non phone numbers") << "abcdefg" << "abcdefg" << true;
QTest::newRow("different non phone numbers") << "abcdefg" << "bcdefg" << false;
QTest::newRow("phone number and custom string") << "abc12345678" << "12345678" << true;
QTest::newRow("phone number with dots") << "+31 (475) 12.34.56" << "+31 (475) 12 34 56" << true;
QTest::newRow("phone number with slash") << "+421 2/123 456 78" << "212345678" << true;
// FIXME: check what other cases we need to test here"
}
void PhoneUtilsTest::testComparePhoneNumbers()
{
QFETCH(QString, number1);
QFETCH(QString, number2);
QFETCH(bool, expectedResult);
bool result = PhoneUtils::comparePhoneNumbers(number1, number2);
QCOMPARE(result, expectedResult);
}
QTEST_MAIN(PhoneUtilsTest)
#include "PhoneUtilsTest.moc"
|