[OpenDocString] kdeconnect-kde (cpp)
testsmshelper.cpp
void SmsHelperTest::testSimplePhoneMatch()
{
    const QString &phoneNumber = QLatin1String("+1 (222) 333-4444");

    QVERIFY2(SmsHelper::isPhoneNumberMatch(phoneNumber, phoneNumber), "Failed to match a phone number with itself");
}
This tests if the phone number is a simple number.
void SmsHelperTest::testMessyPhoneMatch()
{
    const QString &phoneNumber = QLatin1String("12223334444");
    const QString &messyPhoneNumber = QLatin1String("+1 (222) 333-4444");

    QVERIFY2(SmsHelper::isPhoneNumberMatch(phoneNumber, messyPhoneNumber), "Failed to match same number with different formatting characters");
}
This tests if the phone number is the same as the messy phone number.
void SmsHelperTest::testMissingCountryCode()
{
    const QString &shortForm = QLatin1String("(222) 333-4444");
    const QString &longForm = QLatin1String("+1 (222) 333-4444");

    QVERIFY2(SmsHelper::isPhoneNumberMatch(shortForm, longForm), "Failed to match two same numbers with missing country code");
}
This tests if the two numbers share a country code.
void SmsHelperTest::testLeadingZeros()
{
    const QString &shortForm = QLatin1String("+1 (222) 333-4444");
    const QString &zeroForm = QLatin1String("001 (222) 333-4444");

    QVERIFY2(SmsHelper::isPhoneNumberMatch(shortForm, zeroForm), "Failed to match two same numbers with padded zeros");
}
This tests that two numbers have padded zeros.
void SmsHelperTest::testLongDistancePhoneNumber()
{
    const QString &shortForm = QLatin1String("333-4444");
    const QString &longForm = QLatin1String("+1 (222) 333-4444");

    QVERIFY2(SmsHelper::isPhoneNumberMatch(shortForm, longForm), "Failed to suffix match two phone numbers");
}
This tests that the phone number is in the long form.
void SmsHelperTest::testShortCodePhoneNumberNonMatch()
{
    const QString &shortCode = QLatin1String("44455");
    const QString &normalNumber = QLatin1String("222-334-4455");

    QVERIFY2(!SmsHelper::isPhoneNumberMatch(shortCode, normalNumber), "Short code matched with normal number");
}
This tests that the short code and the phone number are not matching.
void SmsHelperTest::testShortCodeMatch()
{
    const QString &shortCode = QLatin1String("44455");
    QVERIFY2(SmsHelper::isPhoneNumberMatch(shortCode, shortCode), "Did not match two of the same short code");
}
This tests if the two short codes are identical.
void SmsHelperTest::testShortCodeNonMatch()
{
    const QString &shortCode1 = QLatin1String("44455");
    const QString &shortCode2 = QLatin1String("66677");
    QVERIFY2(!SmsHelper::isPhoneNumberMatch(shortCode1, shortCode2), "Incorrectly matched two different short codes");
}
This tests that the two short codes are not matching.
void SmsHelperTest::testAustralianShortCodeNumberNonMatch()
{
    const QString &australianShortCode = QLatin1String("19333444");
    // I'm not sure if this is even a valid Australian phone number, but whatever...
    const QString &australianPhoneNumber = QLatin1String("+41 02 1233 3444");

    QVERIFY2(!SmsHelper::isPhoneNumberMatch(australianShortCode, australianPhoneNumber), "Matched Australian short code with regular phone number");
}
This tests if the Australian short code has a phone number and isn't matching.
void SmsHelperTest::testAustralianShortCodeMatch()
{
    const QString &australianShortCode = QLatin1String("12333444");

    QVERIFY2(SmsHelper::isPhoneNumberMatch(australianShortCode, australianShortCode), "Failed to match Australian short code number");
}
This tests if the australian short code is match.
void SmsHelperTest::testAustralianShortCodeNonMatch()
{
    const QString &australianShortCode1 = QLatin1String("12333444");
    const QString &australianShortCode2 = QLatin1String("12555666");

    QVERIFY2(!SmsHelper::isPhoneNumberMatch(australianShortCode1, australianShortCode2), "Matched two different Australian short code numbers");
}
This tests if the two Australian short codes are not matching.
void SmsHelperTest::testCzechRepublicShortCodeNumberNonMatch()
{
    const QString &czechRepShortCode = QLatin1String("9090930");
    // I'm not sure if this is even a valid Czech Republic phone number, but whatever...
    const QString &czechRepPhoneNumber = QLatin1String("+420 809 090 930");

    QVERIFY2(!SmsHelper::isPhoneNumberMatch(czechRepShortCode, czechRepPhoneNumber), "Matched Czech Republic short code with regular phone number");
}
This tests if the Czech Republic short code number is not match.
void SmsHelperTest::testCzechRepublicShortCodeMatch()
{
    const QString &czechRepShortCode = QLatin1String("9090930");

    QVERIFY2(SmsHelper::isPhoneNumberMatch(czechRepShortCode, czechRepShortCode), "Failed to match Czech Republic short code number");
}
This tests if the Czech republic short code matches.
void SmsHelperTest::testCzechRepublicShortCodeNonMatch()
{
    const QString &czechRepShortCode1 = QLatin1String("9090930");
    const QString &czechRepShortCode2 = QLatin1String("9080990");

    QVERIFY2(!SmsHelper::isPhoneNumberMatch(czechRepShortCode1, czechRepShortCode2), "Matched two different Czech Republic short code numbers");
}
This tests if the two Czech Republic short codes are not matching.
void SmsHelperTest::testDifferentPhoneNumbers1()
{
    const QString &phone1 = QLatin1String("+1 (222) 333-4444");
    const QString &phone2 = QLatin1String("+1 (333) 222-4444");

    QVERIFY2(!SmsHelper::isPhoneNumberMatch(phone1, phone2), "Incorrectly marked two different numbers as same");
}
This tests the two phone numbers are not the same.
void SmsHelperTest::testDifferentPhoneNumbers2()
{
    const QString &phone1 = QLatin1String("+1 (222) 333-4444");
    const QString &phone2 = QLatin1String("122-2333");

    QVERIFY2(!SmsHelper::isPhoneNumberMatch(phone1, phone2), "Incorrectly *prefix* matched two phone numbers");
}
This tests the two phone numbers are not matched.
void SmsHelperTest::testAllZeros()
{
    const QString &zeros = QLatin1String("00000");
    const QString &canonicalized = SmsHelper::canonicalizePhoneNumber(zeros);

    QCOMPARE(canonicalized.length(), zeros.length());
}
This tests that the string contains all zeros.
void SmsHelperTest::testEmptyInput()
{
    const QString &empty = QLatin1String("");
    const QString &shortCode = QLatin1String("44455");
    const QString &realNumber = QLatin1String("12223334444");

    QVERIFY2(!SmsHelper::isPhoneNumberMatch(empty, shortCode), "The empty string matched a shortcode phone number");
    QVERIFY2(!SmsHelper::isPhoneNumberMatch(empty, realNumber), "The empty string matched a real phone number");
}
This tests that the string is empty, and checks that it matches a phone number.