Exemplo n.º 1
0
void TestDistrList::testInsertEntry()
{
    kDebug() ;
    KABC::AddressBook *ab = KABC::StdAddressBook::self();
    DistributionList dl = DistributionList::findByName( ab, "foo" );
    assert( !dl.isEmpty() );

#if 0 // the usual method
    KABC::Addressee addr1 = ab->findByName( "addr1" ).first();
    assert( !addr1.isEmpty() );
    dl.insertEntry( addr1 );
#else // the kolab-resource method
    dl.insertEntry( "addr1" );
#endif

    KABC::Addressee addr2 = ab->findByName( "addr2" ).first();
    assert( !addr2.isEmpty() );
    dl.insertEntry( addr2, "*****@*****.**" );

    // Try inserting it again, should do nothing
    dl.insertEntry( addr2, "*****@*****.**" );

    // And insert it with another email address
    dl.insertEntry( addr2, "*****@*****.**" );

    // Test entries()
    DistributionList::Entry::List entries = dl.entries( ab );
    check( "entries count", QString::number( entries.count() ), "3" );
    check( "first entry", entries[0].addressee.name(), "addr1" );
    check( "first entry", entries[0].email, QString() );
    check( "second entry", entries[1].addressee.name(), "addr2" );
    check( "second entry", entries[1].email, "*****@*****.**" );
    check( "third entry", entries[2].addressee.name(), "addr2" );
    check( "third entry", entries[2].email, "*****@*****.**" );

    // Test emails()
    QStringList emails = dl.emails( ab );
    kDebug() << emails;
    assert( emails.count() == 3 );
    check( "first email", emails[0], "addr1 <*****@*****.**>" );
    check( "second email", emails[1], "addr2 <*****@*****.**>" );
    check( "third email", emails[2], "addr2 <*****@*****.**>" );

    // Commit changes to the addressbook !!
    ab->insertAddressee( dl );
}
Exemplo n.º 2
0
void TestDistrList::testRemoveEntry()
{
    kDebug() ;
    KABC::AddressBook *ab = KABC::StdAddressBook::self();
    DistributionList dl = DistributionList::findByName( ab, "foo" );
    assert( !dl.isEmpty() );
    DistributionList::Entry::List entries = dl.entries( ab );
    check( "entries count before removeEntry", QString::number( entries.count() ), "3" );

    // Removing an empty entry shouldn't do anything
    dl.removeEntry( KABC::Addressee() );
    check( "entries count after removing empty entry", QString::number( dl.entries(ab).count() ), "3" );

    KABC::Addressee addr1 = ab->findByName( "addr1" ).first();
    assert( !addr1.isEmpty() );
    // Removing an entry with the wrong email passed, shouldn't do anything
    dl.removeEntry( addr1, "*****@*****.**" );
    check( "entries count after removing entry with invalid email", QString::number( dl.entries(ab).count() ), "3" );

    // Now remove entry correctly
    dl.removeEntry( addr1 );
    check( "removeEntry(addr1) worked", QString::number( dl.entries(ab).count() ), "2" );
    QStringList emails = dl.emails( ab );
    assert( emails.count() == 2 );
    check( "first email", emails[0], "addr2 <*****@*****.**>" );

    // Now move on to addr2. First remove with no or a wrong email (nothing should happen)
    KABC::Addressee addr2 = ab->findByName( "addr2" ).first();
    assert( !addr2.isEmpty() );
    dl.removeEntry( addr2 );
    check( "entries count after removing entry with no email", QString::number( dl.entries(ab).count() ), "2" );

    // Now remove addr2 correctly
    dl.removeEntry( addr2, "*****@*****.**" );
    check( "entries count after removing addr2", QString::number( dl.entries(ab).count() ), "1" );
    dl.removeEntry( addr2, "*****@*****.**" );
    check( "entries count after removing alternate addr2", QString::number( dl.entries(ab).count() ), "0" );
    assert( dl.entries(ab).isEmpty() );
    assert( dl.emails(ab).isEmpty() );
    assert( DistributionList::isDistributionList( dl ) );

    ab->insertAddressee( dl );
}