kabc Library: testaddresseelist.cpp Source File (kabc Library)

| # kabc Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# testaddresseelist.cpp

    00001 #include <kaboutdata.h>
    00002 #include <kapplication.h>
    00003 #include <kdebug.h>
    00004 #include <klocale.h>
    00005 #include <kcmdlineargs.h>
    00006 #include <kstandarddirs.h>
    00007
    00008 #include "addressbook.h"
    00009 #include "addresseelist.h"
    00010
    00011 using namespace KABC;
    00012
    00013 static const KCmdLineOptions options[] =
    00014 {
    00015   { "save", "", 0 },
    00016   { "number", "", 0 },
    00017   KCmdLineLastOption
    00018 };
    00019
    00020 int main(int /*argc*/,char /* **argv*/)
    00021 {
    00022 /*  KAboutData aboutData("testaddresseelist","TestAddresseeList","0.1");
    00023   KCmdLineArgs::init(argc, argv, &aboutData);
    00024   KCmdLineArgs::addCmdLineOptions(options);
    00025
    00026   KApplication app;
    00027   KCmdLineArgs* args = KCmdLineArgs::parsedArgs(); */
    00028
    00029   kdDebug() << "Creating addressees" << endl;
    00030   Addressee a, b, c, d, e, f;
    00031   a.setGivenName ("Peter");
    00032   a.setFamilyName("Pan");
    00033   a.setFormattedName("Pan, Peter");
    00034   a.setUid("Asdf");
    00035   b.setGivenName ("Phileas");
    00036   b.setFamilyName("Fogg");
    00037   b.setFormattedName("Fogg, Phileas");
    00038   b.setUid("Rsdf");
    00039   c.setGivenName ("Jim");
    00040   c.setFamilyName("Hawkins");
    00041   c.setFormattedName("Hawkins, Jim");
    00042   c.setUid("Fhwn");
    00043   d.setGivenName ("John");
    00044   d.setFamilyName("Silver");
    00045   d.setPrefix    ("Long");
    00046   d.setFormattedName("Long John Silver");
    00047   d.setUid("Z2hk");
    00048   e.setGivenName ("Alice");
    00049   e.setFamilyName("Liddel");
    00050   e.setFormattedName("Liddel, Alice");
    00051   e.setUid("kk45");
    00052   f.setGivenName ("Edmond");
    00053   f.setFamilyName("Dantes");
    00054   f.setFormattedName("Dantes, Edmond");
    00055   f.setUid("78ze");
    00056
    00057   kdDebug() << "Adding to list" << endl;
    00058   AddresseeList list;
    00059   list.append(a);
    00060   list.append(b);
    00061   list.append(c);
    00062   list.append(d);
    00063   list.append(e);
    00064   list.append(f);
    00065
    00066   list.sortBy(FamilyName);
    00067   if ( !(   (*list.at(0)).uid()=="78ze"
    00068          && (*list.at(1)).uid()=="Rsdf"
    00069          && (*list.at(2)).uid()=="Fhwn"
    00070          && (*list.at(3)).uid()=="kk45"
    00071          && (*list.at(4)).uid()=="Asdf"
    00072          && (*list.at(5)).uid()=="Z2hk"
    00073         ) ) {
    00074       kdError() << "SORTING BY FAMILY NAME NOT CORRECT!" << endl;
    00075       kdDebug() << "list sorted by family name:" << endl;
    00076       list.dump();
    00077   } else {
    00078       kdDebug() << "Sorting by family name correct." << endl;
    00079   }
    00080   list.setReverseSorting(true);
    00081   list.sort();
    00082   if ( !(   (*list.at(5)).uid()=="78ze"
    00083          && (*list.at(4)).uid()=="Rsdf"
    00084          && (*list.at(3)).uid()=="Fhwn"
    00085          && (*list.at(2)).uid()=="kk45"
    00086          && (*list.at(1)).uid()=="Asdf"
    00087          && (*list.at(0)).uid()=="Z2hk"
    00088         ) ) {
    00089       kdError() << "REVERSE SORTING BY FAMILY NAME NOT CORRECT!" << endl;
    00090       kdDebug() << "list reverse sorted by family name:" << endl;
    00091       list.dump();
    00092   } else {
    00093       kdDebug() << "Reverse sorting by family name correct." << endl;
    00094   }
    00095
    00096   list.setReverseSorting(false);
    00097   list.sortBy(FormattedName);
    00098   if ( !(   (*list.at(0)).uid()=="78ze"
    00099          && (*list.at(1)).uid()=="Rsdf"
    00100          && (*list.at(2)).uid()=="Fhwn"
    00101          && (*list.at(3)).uid()=="kk45"
    00102          && (*list.at(4)).uid()=="Z2hk"
    00103          && (*list.at(5)).uid()=="Asdf"
    00104         ) ) {
    00105       kdError() << "SORTING BY FORMATTED NAME NOT CORRECT!" << endl;
    00106       kdDebug() << "list sorted by formatted name:" << endl;
    00107       list.dump();
    00108   } else {
    00109       kdDebug() << "Sorting by formatted name correct." << endl;
    00110   }
    00111   list.setReverseSorting(true);
    00112   list.sort();
    00113   if ( !(   (*list.at(5)).uid()=="78ze"
    00114          && (*list.at(4)).uid()=="Rsdf"
    00115          && (*list.at(3)).uid()=="Fhwn"
    00116          && (*list.at(2)).uid()=="kk45"
    00117          && (*list.at(1)).uid()=="Z2hk"
    00118          && (*list.at(0)).uid()=="Asdf"
    00119         ) ) {
    00120       kdError() << "REVERSE SORTING BY FORMATTED NAME NOT CORRECT!" << endl;
    00121       kdDebug() << "list reverse sorted by formatted name:" << endl;
    00122       list.dump();
    00123   } else {
    00124       kdDebug() << "Reverse sorting by formatted name correct." << endl;
    00125   }
    00126
    00127
    00128   list.setReverseSorting(false);
    00129   list.sortBy(Uid);
    00130   if ( !(   (*list.at(0)).uid()=="78ze"
    00131          && (*list.at(1)).uid()=="Asdf"
    00132          && (*list.at(2)).uid()=="Fhwn"
    00133          && (*list.at(3)).uid()=="Rsdf"
    00134          && (*list.at(4)).uid()=="Z2hk"
    00135          && (*list.at(5)).uid()=="kk45"
    00136         ) ) {
    00137       kdError() << "SORTING BY UID NOT CORRECT!" << endl;
    00138       kdDebug() << "list sorted by Uid:" << endl;
    00139       list.dump();
    00140   } else {
    00141       kdDebug() << "Sorting by Uid correct." << endl;
    00142   }
    00143   list.setReverseSorting(true);
    00144   list.sortBy(Uid);
    00145   if ( !(   (*list.at(5)).uid()=="78ze"
    00146          && (*list.at(4)).uid()=="Asdf"
    00147          && (*list.at(3)).uid()=="Fhwn"
    00148          && (*list.at(2)).uid()=="Rsdf"
    00149          && (*list.at(1)).uid()=="Z2hk"
    00150          && (*list.at(0)).uid()=="kk45"
    00151         ) ) {
    00152       kdError() << "REVERSE SORTING BY UID NOT CORRECT!" << endl;
    00153       kdDebug() << "list sorted by Uid:" << endl;
    00154       list.dump();
    00155   } else {
    00156       kdDebug() << "Reverse sorting by Uid correct." << endl;
    00157   }
    00158
    00159   // zero, one or two entries might give errors in a poor sorting
    00160   // implementation
    00161   kdDebug() << "sorting empty list" << endl;
    00162   AddresseeList list2;
    00163   list2.sort();
    00164
    00165   kdDebug() << "sorting one entry list" << endl;
    00166   list2.append(a);
    00167   list2.sort();
    00168
    00169   kdDebug() << "sorting two entry list" << endl;
    00170   list2.append(f);
    00171   list2.setReverseSorting(false);
    00172   list2.sort();
    00173   if ( !(   (*list2.at(0)).uid()=="78ze"
    00174          && (*list2.at(1)).uid()=="Asdf"
    00175         ) ) {
    00176       kdError() << "SORTING BY FORMATTED NAME IN A TWO ENTRY LIST NOT CORRECT!" << endl;
    00177       kdDebug() << "list sorted by formatted name, two entries:" << endl;
    00178       list2.dump();
    00179   } else {
    00180       kdDebug() << "Sorting by FormattedName in a two entry list correct." << endl;
    00181   }
    00182   list2.setReverseSorting(true);
    00183   list2.sort();
    00184   if ( !(   (*list2.at(1)).uid()=="78ze"
    00185          && (*list2.at(0)).uid()=="Asdf"
    00186         ) ) {
    00187       kdError() << "REVERSE SORTING BY FORMATTED NAME IN A TWO ENTRY LIST NOT CORRECT!" << endl;
    00188       kdDebug() << "list reverse sorted by formatted name, two entries:" << endl;
    00189       list2.dump();
    00190   } else {
    00191       kdDebug() << "Reverse sorting by FormattedName in a two entry list correct." << endl;
    00192   }
    00193
    00194 }
    00195
    00196

This file is part of the documentation for kabc Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:31:31 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003