From 66abbed5e08370412b81be1628590898ceeeb604 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sat, 29 May 2021 19:05:31 +0900 Subject: Renaming of files in preparation for code style tools. Signed-off-by: Michele Calgaro --- tests/CMakeLists.txt | 16 +- tests/conduits/vcalconduit/exampletest.cc | 26 --- tests/conduits/vcalconduit/exampletest.cpp | 26 +++ tests/exportdatebook.cc | 136 ------------- tests/exportdatebook.cpp | 136 +++++++++++++ tests/importaddresses.cc | 127 ------------ tests/importaddresses.cpp | 127 ++++++++++++ tests/importdatebook.cc | 131 ------------ tests/importdatebook.cpp | 131 ++++++++++++ tests/main.cc | 17 -- tests/main.cpp | 17 ++ tests/mergecalendars.cc | 228 --------------------- tests/mergecalendars.cpp | 228 +++++++++++++++++++++ tests/testactions.cc | 92 --------- tests/testactions.cpp | 92 +++++++++ tests/testaddress.cc | 106 ---------- tests/testaddress.cpp | 106 ++++++++++ tests/testcategories.cc | 215 -------------------- tests/testcategories.cpp | 215 ++++++++++++++++++++ tests/testconstants.cc | 68 ------- tests/testconstants.cpp | 68 +++++++ tests/testdatabase.cc | 316 ----------------------------- tests/testdatabase.cpp | 316 +++++++++++++++++++++++++++++ tests/testdatebook.cc | 95 --------- tests/testdatebook.cpp | 95 +++++++++ tests/testidmapper.cc | 314 ---------------------------- tests/testidmapper.cpp | 314 ++++++++++++++++++++++++++++ 27 files changed, 1879 insertions(+), 1879 deletions(-) delete mode 100644 tests/conduits/vcalconduit/exampletest.cc create mode 100644 tests/conduits/vcalconduit/exampletest.cpp delete mode 100644 tests/exportdatebook.cc create mode 100644 tests/exportdatebook.cpp delete mode 100644 tests/importaddresses.cc create mode 100644 tests/importaddresses.cpp delete mode 100644 tests/importdatebook.cc create mode 100644 tests/importdatebook.cpp delete mode 100644 tests/main.cc create mode 100644 tests/main.cpp delete mode 100644 tests/mergecalendars.cc create mode 100644 tests/mergecalendars.cpp delete mode 100644 tests/testactions.cc create mode 100644 tests/testactions.cpp delete mode 100644 tests/testaddress.cc create mode 100644 tests/testaddress.cpp delete mode 100644 tests/testcategories.cc create mode 100644 tests/testcategories.cpp delete mode 100644 tests/testconstants.cc create mode 100644 tests/testconstants.cpp delete mode 100644 tests/testdatabase.cc create mode 100644 tests/testdatabase.cpp delete mode 100644 tests/testdatebook.cc create mode 100644 tests/testdatebook.cpp delete mode 100644 tests/testidmapper.cc create mode 100644 tests/testidmapper.cpp (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f27f41a..6dfe070 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -29,50 +29,50 @@ link_directories( set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} ) tde_add_check_executable( testconstants - SOURCES testconstants.cc + SOURCES testconstants.cpp LINK kpilot-shared ${TQT_LIBRARIES} TEST ) tde_add_check_executable( testcategories - SOURCES testcategories.cc + SOURCES testcategories.cpp LINK kpilot-shared ${TQT_LIBRARIES} TEST ) tde_add_check_executable( testaddresses - SOURCES testaddress.cc + SOURCES testaddress.cpp LINK kpilot-shared ${TQT_LIBRARIES} TEST ) tde_add_check_executable( testdatebook - SOURCES testdatebook.cc + SOURCES testdatebook.cpp LINK kpilot-shared ${TQT_LIBRARIES} TEST ) tde_add_check_executable( importaddresses - SOURCES importaddresses.cc + SOURCES importaddresses.cpp LINK kpilot-shared tdeabc-shared tdeabc_file-shared ${TQT_LIBRARIES} ) add_test(importaddresses ${EXECUTABLE_OUTPUT_PATH}/importaddresses --data-dir "${CMAKE_CURRENT_BINARY_DIR}" --address-file "${CMAKE_CURRENT_SOURCE_DIR}/data/AddressDB.pdb") if (HAVE_CALENDARLOCAL_H) tde_add_check_executable( importdatebook - SOURCES importdatebook.cc + SOURCES importdatebook.cpp LINK kpilot-shared kcal-shared ${TQT_LIBRARIES} TEST ) tde_add_check_executable( exportdatebook - SOURCES exportdatebook.cc + SOURCES exportdatebook.cpp LINK kpilot-shared kcal-shared ${TQT_LIBRARIES} TEST ) tde_add_check_executable( mergecalendars - SOURCES mergecalendars.cc + SOURCES mergecalendars.cpp LINK kpilot-shared kcal-shared ${TQT_LIBRARIES} TEST ) diff --git a/tests/conduits/vcalconduit/exampletest.cc b/tests/conduits/vcalconduit/exampletest.cc deleted file mode 100644 index b16a6c3..0000000 --- a/tests/conduits/vcalconduit/exampletest.cc +++ /dev/null @@ -1,26 +0,0 @@ -#include "options.h" -#include "config.h" - -#include "exampletest.h" - -CPPUNIT_TEST_SUITE_REGISTRATION( VCalConduitTest ); - - -void VCalConduitTest::setUp() -{ - device = TQString("testdevice"); - link = new KPilotLocalLink(0, "localLink"); - syncMode = SyncAction::SyncMode::eHotSync; -} - - -void VCalConduitTest::tearDown() -{ - delete link; -} - - -void VCalConduitTest::testConstructor() -{ - CPPUNIT_ASSERT( true == true ); -} diff --git a/tests/conduits/vcalconduit/exampletest.cpp b/tests/conduits/vcalconduit/exampletest.cpp new file mode 100644 index 0000000..b16a6c3 --- /dev/null +++ b/tests/conduits/vcalconduit/exampletest.cpp @@ -0,0 +1,26 @@ +#include "options.h" +#include "config.h" + +#include "exampletest.h" + +CPPUNIT_TEST_SUITE_REGISTRATION( VCalConduitTest ); + + +void VCalConduitTest::setUp() +{ + device = TQString("testdevice"); + link = new KPilotLocalLink(0, "localLink"); + syncMode = SyncAction::SyncMode::eHotSync; +} + + +void VCalConduitTest::tearDown() +{ + delete link; +} + + +void VCalConduitTest::testConstructor() +{ + CPPUNIT_ASSERT( true == true ); +} diff --git a/tests/exportdatebook.cc b/tests/exportdatebook.cc deleted file mode 100644 index 45cfa01..0000000 --- a/tests/exportdatebook.cc +++ /dev/null @@ -1,136 +0,0 @@ -/* testaddresses KPilot -** -** Copyright (C) 2007 by Jason 'vanRijn' Kasper -#include -#include -#include -#include -#include - -#include -#include - -#include "pilot.h" -#include "pilotDateEntry.h" -#include "pilotLocalDatabase.h" -#include "../conduits/vcalconduit/kcalRecord.cc" -#include "../conduits/vcalconduit/vcalRecord.cc" - -static const TDECmdLineOptions options[] = -{ - {"verbose", "Verbose output", 0}, - {"data-dir ","Set data directory", "."}, - {"vcal-file ","Set vcal file", 0}, - TDECmdLineLastOption -}; - - - -int main(int argc, char **argv) -{ - FUNCTIONSETUP; - - TDEApplication::disableAutoDcopRegistration(); - - TDEAboutData aboutData("exportdatebook","Emport Date Book","0.1"); - TDECmdLineArgs::init(argc,argv,&aboutData); - TDECmdLineArgs::addCmdLineOptions( options ); - - TDEApplication app( false, false ); - - TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); - - debug_level= (args->isSet("verbose")) ? 4 : 0; - - TQString datadir = args->getOption("data-dir"); - TQString vcalfile = args->getOption("vcal-file"); - - if (datadir.isEmpty()) - { - WARNINGKPILOT << "! Must provide a data-directory." << endl; - } - if (vcalfile.isEmpty()) - { - WARNINGKPILOT << "! Must provide a vcal-file to write to." << endl; - } - if (datadir.isEmpty() || vcalfile.isEmpty()) - { - return 1; - } - - /* - TDEConfig korgcfg( locate( "config", CSL1("korganizerrc") ) ); - - // this part taken from adcalendarbase.cpp: - korgcfg.setGroup( "Time & Date" ); - TQString tz(korgcfg.readEntry( "TimeZoneId" ) ); - - DEBUGKPILOT << fname << ": KOrganizer's time zone = " << tz << endl; - - KCal::CalendarLocal *calendar = new KCal::CalendarLocal( tz ); - */ - KCal::CalendarLocal *calendar = new KCal::CalendarLocal( TQString() ); - - if (!calendar) - { - WARNINGKPILOT << "! Can't create calendar object." << endl; - return 1; - } - - Pilot::setupPilotCodec( CSL1("Latin1") ); - - PilotLocalDatabase db( datadir, "DatebookDB" ); - - PilotDateInfo *fAppointmentAppInfo = new PilotDateInfo( &db ); - - int currentRecord = 0; - PilotRecord *pilotRec = 0; - PilotDateEntry *d = 0; - - while ((pilotRec = db.readRecordByIndex(currentRecord++)) != NULL) - { - d = new PilotDateEntry(pilotRec); - - KCal::Event*event = new KCal::Event; - - KCalSync::setEvent(event, d,*fAppointmentAppInfo->categoryInfo()); - - event->setSyncStatus( KCal::Incidence::SYNCNONE ); - - calendar->addEvent(event); - - } - - calendar->save(vcalfile); - - return 0; -} - diff --git a/tests/exportdatebook.cpp b/tests/exportdatebook.cpp new file mode 100644 index 0000000..3f8bcf2 --- /dev/null +++ b/tests/exportdatebook.cpp @@ -0,0 +1,136 @@ +/* testaddresses KPilot +** +** Copyright (C) 2007 by Jason 'vanRijn' Kasper +#include +#include +#include +#include +#include + +#include +#include + +#include "pilot.h" +#include "pilotDateEntry.h" +#include "pilotLocalDatabase.h" +#include "../conduits/vcalconduit/kcalRecord.cpp" +#include "../conduits/vcalconduit/vcalRecord.cpp" + +static const TDECmdLineOptions options[] = +{ + {"verbose", "Verbose output", 0}, + {"data-dir ","Set data directory", "."}, + {"vcal-file ","Set vcal file", 0}, + TDECmdLineLastOption +}; + + + +int main(int argc, char **argv) +{ + FUNCTIONSETUP; + + TDEApplication::disableAutoDcopRegistration(); + + TDEAboutData aboutData("exportdatebook","Emport Date Book","0.1"); + TDECmdLineArgs::init(argc,argv,&aboutData); + TDECmdLineArgs::addCmdLineOptions( options ); + + TDEApplication app( false, false ); + + TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); + + debug_level= (args->isSet("verbose")) ? 4 : 0; + + TQString datadir = args->getOption("data-dir"); + TQString vcalfile = args->getOption("vcal-file"); + + if (datadir.isEmpty()) + { + WARNINGKPILOT << "! Must provide a data-directory." << endl; + } + if (vcalfile.isEmpty()) + { + WARNINGKPILOT << "! Must provide a vcal-file to write to." << endl; + } + if (datadir.isEmpty() || vcalfile.isEmpty()) + { + return 1; + } + + /* + TDEConfig korgcfg( locate( "config", CSL1("korganizerrc") ) ); + + // this part taken from adcalendarbase.cpp: + korgcfg.setGroup( "Time & Date" ); + TQString tz(korgcfg.readEntry( "TimeZoneId" ) ); + + DEBUGKPILOT << fname << ": KOrganizer's time zone = " << tz << endl; + + KCal::CalendarLocal *calendar = new KCal::CalendarLocal( tz ); + */ + KCal::CalendarLocal *calendar = new KCal::CalendarLocal( TQString() ); + + if (!calendar) + { + WARNINGKPILOT << "! Can't create calendar object." << endl; + return 1; + } + + Pilot::setupPilotCodec( CSL1("Latin1") ); + + PilotLocalDatabase db( datadir, "DatebookDB" ); + + PilotDateInfo *fAppointmentAppInfo = new PilotDateInfo( &db ); + + int currentRecord = 0; + PilotRecord *pilotRec = 0; + PilotDateEntry *d = 0; + + while ((pilotRec = db.readRecordByIndex(currentRecord++)) != NULL) + { + d = new PilotDateEntry(pilotRec); + + KCal::Event*event = new KCal::Event; + + KCalSync::setEvent(event, d,*fAppointmentAppInfo->categoryInfo()); + + event->setSyncStatus( KCal::Incidence::SYNCNONE ); + + calendar->addEvent(event); + + } + + calendar->save(vcalfile); + + return 0; +} + diff --git a/tests/importaddresses.cc b/tests/importaddresses.cc deleted file mode 100644 index 032a14f..0000000 --- a/tests/importaddresses.cc +++ /dev/null @@ -1,127 +0,0 @@ -/* importaddresses KPilot -** -** Copyright (C) 2006 by Adriaan de Groot -#include -#include -#include -#include - -#include -#include - -#include "pilot.h" -#include "pilotLocalDatabase.h" -#include "pilotAddress.h" -#include "../conduits/abbrowserconduit/tdeabcRecord.h" -#include "../conduits/abbrowserconduit/tdeabcRecord.cc" - -static const TDECmdLineOptions options[] = -{ - {"verbose", "Verbose output", 0}, - {"data-dir ","Set data directory", "."}, - {"address-file ","Set addressbook file", 0}, - TDECmdLineLastOption -}; - - - -int main(int argc, char **argv) -{ - TDEAboutData aboutData("importaddresses","Import Address Book","0.1"); - TDECmdLineArgs::init(argc,argv,&aboutData); - TDECmdLineArgs::addCmdLineOptions( options ); - - TDEApplication app( false, false ); - - TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); - -#ifdef DEBUG - debug_level= (args->isSet("verbose")) ? 4 : 0; -#endif - TQString datadir = args->getOption("data-dir"); - TQString addressfile = args->getOption("address-file"); - - if (datadir.isEmpty()) - { - kdWarning() << "! Must provide a data-directory." << endl; - } - if (addressfile.isEmpty()) - { - kdWarning() << "! Must provide an address-file to read." << endl; - } - if (datadir.isEmpty() || addressfile.isEmpty()) - { - return 1; - } - - TDEABC::ResourceFile *file = new TDEABC::ResourceFile( addressfile ); - TDEABC::AddressBook book; - book.addResource( file ); - if (!book.load()) - { - kdWarning() << "! Failed to load the address-file <" << addressfile << ">" << endl; - return 1; - } - - Pilot::setupPilotCodec( CSL1("Latin1") ); - - PilotLocalDatabase db( datadir, "AddressDB" ); - db.createDatabase( 0xdead, 0xbeef ); - PilotAddressInfo info(0L); - info.resetToDefault(); - info.writeTo(&db); - - TDEABCSync::Settings settings; - - kdDebug() << "# Printing address book." << endl; - unsigned int count = 1; - TDEABC::AddressBook::ConstIterator it = book.begin(); - while (it != book.end()) - { - const TDEABC::Addressee &a = *it; - kdDebug() << "# Entry #" << count << endl; - kdDebug() << "# " << a.name() << endl; - kdDebug() << "# " << a.formattedName() << endl; - PilotAddress *p = new PilotAddress(); - TDEABCSync::copy(*p,a,info,settings); - PilotRecord *r = p->pack(); - if (r) - { - db.writeRecord(r); - delete r; - } - delete p; - ++it; - ++count; - } - - return 0; -} diff --git a/tests/importaddresses.cpp b/tests/importaddresses.cpp new file mode 100644 index 0000000..40973e3 --- /dev/null +++ b/tests/importaddresses.cpp @@ -0,0 +1,127 @@ +/* importaddresses KPilot +** +** Copyright (C) 2006 by Adriaan de Groot +#include +#include +#include +#include + +#include +#include + +#include "pilot.h" +#include "pilotLocalDatabase.h" +#include "pilotAddress.h" +#include "../conduits/abbrowserconduit/tdeabcRecord.h" +#include "../conduits/abbrowserconduit/tdeabcRecord.cpp" + +static const TDECmdLineOptions options[] = +{ + {"verbose", "Verbose output", 0}, + {"data-dir ","Set data directory", "."}, + {"address-file ","Set addressbook file", 0}, + TDECmdLineLastOption +}; + + + +int main(int argc, char **argv) +{ + TDEAboutData aboutData("importaddresses","Import Address Book","0.1"); + TDECmdLineArgs::init(argc,argv,&aboutData); + TDECmdLineArgs::addCmdLineOptions( options ); + + TDEApplication app( false, false ); + + TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); + +#ifdef DEBUG + debug_level= (args->isSet("verbose")) ? 4 : 0; +#endif + TQString datadir = args->getOption("data-dir"); + TQString addressfile = args->getOption("address-file"); + + if (datadir.isEmpty()) + { + kdWarning() << "! Must provide a data-directory." << endl; + } + if (addressfile.isEmpty()) + { + kdWarning() << "! Must provide an address-file to read." << endl; + } + if (datadir.isEmpty() || addressfile.isEmpty()) + { + return 1; + } + + TDEABC::ResourceFile *file = new TDEABC::ResourceFile( addressfile ); + TDEABC::AddressBook book; + book.addResource( file ); + if (!book.load()) + { + kdWarning() << "! Failed to load the address-file <" << addressfile << ">" << endl; + return 1; + } + + Pilot::setupPilotCodec( CSL1("Latin1") ); + + PilotLocalDatabase db( datadir, "AddressDB" ); + db.createDatabase( 0xdead, 0xbeef ); + PilotAddressInfo info(0L); + info.resetToDefault(); + info.writeTo(&db); + + TDEABCSync::Settings settings; + + kdDebug() << "# Printing address book." << endl; + unsigned int count = 1; + TDEABC::AddressBook::ConstIterator it = book.begin(); + while (it != book.end()) + { + const TDEABC::Addressee &a = *it; + kdDebug() << "# Entry #" << count << endl; + kdDebug() << "# " << a.name() << endl; + kdDebug() << "# " << a.formattedName() << endl; + PilotAddress *p = new PilotAddress(); + TDEABCSync::copy(*p,a,info,settings); + PilotRecord *r = p->pack(); + if (r) + { + db.writeRecord(r); + delete r; + } + delete p; + ++it; + ++count; + } + + return 0; +} diff --git a/tests/importdatebook.cc b/tests/importdatebook.cc deleted file mode 100644 index 99f81f2..0000000 --- a/tests/importdatebook.cc +++ /dev/null @@ -1,131 +0,0 @@ -/* testaddresses KPilot -** -** Copyright (C) 2006 by Adriaan de Groot -#include -#include -#include -#include - -#include -#include - -#include "pilot.h" -#include "pilotDateEntry.h" -#include "pilotLocalDatabase.h" -#include "../conduits/vcalconduit/kcalRecord.cc" -#include "../conduits/vcalconduit/vcalRecord.cc" - -static const TDECmdLineOptions options[] = -{ - {"verbose", "Verbose output", 0}, - {"data-dir ","Set data directory", "."}, - {"vcal-file ","Set vcal file", 0}, - TDECmdLineLastOption -}; - - - -int main(int argc, char **argv) -{ - TDEApplication::disableAutoDcopRegistration(); - - TDEAboutData aboutData("importdatebook","Import Date Book","0.1"); - TDECmdLineArgs::init(argc,argv,&aboutData); - TDECmdLineArgs::addCmdLineOptions( options ); - - TDEApplication app( false, false ); - - TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); - - debug_level= (args->isSet("verbose")) ? 4 : 0; - - TQString datadir = args->getOption("data-dir"); - TQString vcalfile = args->getOption("vcal-file"); - - if (datadir.isEmpty()) - { - WARNINGKPILOT << "! Must provide a data-directory." << endl; - } - if (vcalfile.isEmpty()) - { - WARNINGKPILOT << "! Must provide a vcal-file to read." << endl; - } - if (datadir.isEmpty() || vcalfile.isEmpty()) - { - return 1; - } - - DEBUGKPILOT << "Using vcal-file: [" << vcalfile - << "], creating DatebookDB in: [" << datadir - << "]" << endl; - - KCal::CalendarLocal *calendar = new KCal::CalendarLocal( TQString::fromLatin1("UTC") ); - if (!calendar || !calendar->load( vcalfile )) - { - return 1; - } - - DEBUGKPILOT << "Opened calendar with: [" - << calendar->incidences().count() << "] incidences." << endl; - - Pilot::setupPilotCodec( CSL1("Latin1") ); - - PilotLocalDatabase db( datadir, "DatebookDB" ); - db.createDatabase( 0xdead, 0xbeef ); - PilotDateInfo appInfo(0L); - appInfo.resetToDefault(); - appInfo.writeTo(&db); - - KCal::Event::List events = calendar->events(); - - for (KCal::Event::List::ConstIterator i = events.begin(); - i != events.end(); ++i) - { - PilotDateEntry * d = new PilotDateEntry(); - - const KCal::Event *e = *i; - DEBUGKPILOT << "event: [" << e->summary() << "]" << endl; - - if (KCalSync::setDateEntry(d,e,*appInfo.categoryInfo())) - { -DEBUGKPILOT << "got here." << endl; - PilotRecord *r = d->pack(); - if (r) - { - db.writeRecord(r); - delete r; - } - } - } - - return 0; -} - diff --git a/tests/importdatebook.cpp b/tests/importdatebook.cpp new file mode 100644 index 0000000..2e987d3 --- /dev/null +++ b/tests/importdatebook.cpp @@ -0,0 +1,131 @@ +/* testaddresses KPilot +** +** Copyright (C) 2006 by Adriaan de Groot +#include +#include +#include +#include + +#include +#include + +#include "pilot.h" +#include "pilotDateEntry.h" +#include "pilotLocalDatabase.h" +#include "../conduits/vcalconduit/kcalRecord.cpp" +#include "../conduits/vcalconduit/vcalRecord.cpp" + +static const TDECmdLineOptions options[] = +{ + {"verbose", "Verbose output", 0}, + {"data-dir ","Set data directory", "."}, + {"vcal-file ","Set vcal file", 0}, + TDECmdLineLastOption +}; + + + +int main(int argc, char **argv) +{ + TDEApplication::disableAutoDcopRegistration(); + + TDEAboutData aboutData("importdatebook","Import Date Book","0.1"); + TDECmdLineArgs::init(argc,argv,&aboutData); + TDECmdLineArgs::addCmdLineOptions( options ); + + TDEApplication app( false, false ); + + TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); + + debug_level= (args->isSet("verbose")) ? 4 : 0; + + TQString datadir = args->getOption("data-dir"); + TQString vcalfile = args->getOption("vcal-file"); + + if (datadir.isEmpty()) + { + WARNINGKPILOT << "! Must provide a data-directory." << endl; + } + if (vcalfile.isEmpty()) + { + WARNINGKPILOT << "! Must provide a vcal-file to read." << endl; + } + if (datadir.isEmpty() || vcalfile.isEmpty()) + { + return 1; + } + + DEBUGKPILOT << "Using vcal-file: [" << vcalfile + << "], creating DatebookDB in: [" << datadir + << "]" << endl; + + KCal::CalendarLocal *calendar = new KCal::CalendarLocal( TQString::fromLatin1("UTC") ); + if (!calendar || !calendar->load( vcalfile )) + { + return 1; + } + + DEBUGKPILOT << "Opened calendar with: [" + << calendar->incidences().count() << "] incidences." << endl; + + Pilot::setupPilotCodec( CSL1("Latin1") ); + + PilotLocalDatabase db( datadir, "DatebookDB" ); + db.createDatabase( 0xdead, 0xbeef ); + PilotDateInfo appInfo(0L); + appInfo.resetToDefault(); + appInfo.writeTo(&db); + + KCal::Event::List events = calendar->events(); + + for (KCal::Event::List::ConstIterator i = events.begin(); + i != events.end(); ++i) + { + PilotDateEntry * d = new PilotDateEntry(); + + const KCal::Event *e = *i; + DEBUGKPILOT << "event: [" << e->summary() << "]" << endl; + + if (KCalSync::setDateEntry(d,e,*appInfo.categoryInfo())) + { +DEBUGKPILOT << "got here." << endl; + PilotRecord *r = d->pack(); + if (r) + { + db.writeRecord(r); + delete r; + } + } + } + + return 0; +} + diff --git a/tests/main.cc b/tests/main.cc deleted file mode 100644 index c6ddd23..0000000 --- a/tests/main.cc +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -int main( int argc, char **argv) -{ - CppUnit::TestFactoryRegistry ®istry = - CppUnit::TestFactoryRegistry::getRegistry(); - - CppUnit::TextUi::TestRunner runner; - runner.addTest( registry.makeTest() ); - - // Run the tests. - bool wasSucessful = runner.run(); - - // Return error code 1 if the one of test failed. - return wasSucessful ? 0 : 1; -} diff --git a/tests/main.cpp b/tests/main.cpp new file mode 100644 index 0000000..c6ddd23 --- /dev/null +++ b/tests/main.cpp @@ -0,0 +1,17 @@ +#include +#include + +int main( int argc, char **argv) +{ + CppUnit::TestFactoryRegistry ®istry = + CppUnit::TestFactoryRegistry::getRegistry(); + + CppUnit::TextUi::TestRunner runner; + runner.addTest( registry.makeTest() ); + + // Run the tests. + bool wasSucessful = runner.run(); + + // Return error code 1 if the one of test failed. + return wasSucessful ? 0 : 1; +} diff --git a/tests/mergecalendars.cc b/tests/mergecalendars.cc deleted file mode 100644 index 010755d..0000000 --- a/tests/mergecalendars.cc +++ /dev/null @@ -1,228 +0,0 @@ -/* mergecalendars KPilot -** -** Copyright (C) 2007 by Jason 'vanRijn' Kasper -#include -#include -#include -#include -#include - -#include -#include - -#include "options.h" - -static const TDECmdLineOptions options[] = -{ - {"korgfile ","KOrganizer master file", 0}, - {"newfile ","Calendar file to merge into korganizer", 0}, - {"category ","Category to remove from 'korgfile' and to add to events in 'newfile' for synch purposes", 0}, - {"verbose", "Verbose debugging", 0}, - TDECmdLineLastOption -}; - - - -int main(int argc, char **argv) -{ - - TDEApplication::disableAutoDcopRegistration(); - - TDEAboutData aboutData("mergecalendars","Merge libkcal Calendars","0.1"); - TDECmdLineArgs::init(argc,argv,&aboutData); - TDECmdLineArgs::addCmdLineOptions( options ); - - TDEApplication app( false, false ); - - TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); - - int debug_level= (args->isSet("verbose")) ? 4 : 0; - - TQString korgfile = args->getOption("korgfile"); - TQString newfile = args->getOption("newfile"); - TQString category = args->getOption("category"); - - if (korgfile.isEmpty()) - { - WARNINGKPILOT << "! Must provide a korganizer file." << endl; - } - if (newfile.isEmpty()) - { - WARNINGKPILOT << "! Must provide a newfile file." << endl; - } - if (category.isEmpty()) - { - WARNINGKPILOT << "! Must provide a category to use." << endl; - } - if (korgfile.isEmpty() || newfile.isEmpty() || category.isEmpty()) - { - return 1; - } - - TQString korgsave = TQString("%1.updated").arg(korgfile); - TQString newfilesave = TQString("%1.updated").arg(newfile); - - DEBUGKPILOT << "Using korgfile: [" << korgfile - << "]" << endl; - DEBUGKPILOT << "Using newfile: [" << newfile - << "]" << endl; - DEBUGKPILOT << "Will save korgfile to: [" << korgsave - << "]" << endl; - DEBUGKPILOT << "Will save newfile to: [" << newfilesave - << "]" << endl << endl; - - KCal::CalendarLocal *calkorg = new KCal::CalendarLocal( TQString::fromLatin1("UTC") ); - KCal::CalendarLocal *calnew = new KCal::CalendarLocal( TQString::fromLatin1("UTC") ); - if (!calkorg || !calnew) - { - WARNINGKPILOT << "Unable to create base calendar objects." << endl; - return 1; - } - - if (!calkorg->load(korgfile) || !calnew->load(newfile)) - { - WARNINGKPILOT << "Unable to load calendar files." << endl; - return 1; - } - - int numkorgstart = calkorg->incidences().count(); - int numnewstart = calnew->incidences().count(); - - DEBUGKPILOT << " - Opened korganizer calendar with: [" - << numkorgstart << "] incidences." << endl; - DEBUGKPILOT << " - Opened newfile calendar with: [" - << numnewstart << "] incidences." << endl; - - KCal::Event::List korgEvents; - KCal::Event::List::ConstIterator korgIt; - korgEvents = calkorg->events(); - korgEvents.setAutoDelete(false); - - KCal::Event::List newEvents; - KCal::Event::List::ConstIterator newIt; - newEvents = calnew->events(); - newEvents.setAutoDelete(false); - - DEBUGKPILOT << "Looking for previous pilot ids for exchange events..." << endl; - - // iterate through all events and try to find a korganizer event - // that matches up with this external event's UID - unsigned int numkorgpilotids = 0; - KCal::Event *ev = 0; - for (newIt = newEvents.begin(); newIt != newEvents.end(); ++newIt ) - { - ev = *newIt; - TQString uid = ev->uid(); - if (debug_level) - DEBUGKPILOT << " - Looking at event: [" - << ev->summary() << "], uid: [" - << uid << "]" << endl; - - KCal::Event * evkorg = calkorg->event(uid); - if ( evkorg && (evkorg->pilotId() > 0) ) - { - unsigned long pilotId = evkorg->pilotId(); - - if (debug_level) - DEBUGKPILOT << "Found korg event for uid: [" - << uid << "], pilotId: [" - << pilotId << "]" << endl; - - ev->setPilotId(pilotId); - ev->setSyncStatus(KCal::Incidence::SYNCMOD); - - ++numkorgpilotids; - } - } - - DEBUGKPILOT << "Matched: [" << numkorgpilotids << "] events."<< endl; - - DEBUGKPILOT << "Now searching for previous events of category: [" << category << "] in korganizer's calendar." << endl; - - // iterate through all events and try to find a korganizer event - // that matches up with this external event's UID - unsigned int numkorgremoved = 0; - - TQString categoryToken = category; - - // careful iterating and removing... - KCal::Event *next = 0; - - korgIt = korgEvents.begin(); - for ( ev = *korgIt; ev != 0; ev = next ) - { - if (++korgIt == korgEvents.end()) - { - next = 0; - } - else - { - next = *korgIt; - } - - if (ev->categoriesStr().contains(categoryToken)) - { - if (debug_level) - DEBUGKPILOT << " - Found matching event: [" - << ev->summary() << "], uid: [" - << ev->uid() << "]. Removing." << endl; - - korgEvents.remove(ev); - calkorg->deleteEvent(ev); - - ++numkorgremoved; - } - } - - DEBUGKPILOT << " - Found: [" << numkorgremoved - << "] prior: [" << categoryToken - << "] category events." << endl; - - DEBUGKPILOT << "Merging new events into korganizer calendar..." - << endl; - - for (newIt = newEvents.begin(); newIt != newEvents.end(); ++newIt ) - { - ev = *newIt; - ev->setCategories(category); - korgEvents.append(ev); - calkorg->addEvent(ev); - } - - DEBUGKPILOT << "Ended up with: [" << korgEvents.count() - << "] events in korganizer calendar." << endl; - - DEBUGKPILOT << "Saving updated korganizer file..." << endl; - calkorg->save(korgsave); - - DEBUGKPILOT << "Saving updated newfile file..." << endl; - calnew->save(newfilesave); - - return 0; -} - diff --git a/tests/mergecalendars.cpp b/tests/mergecalendars.cpp new file mode 100644 index 0000000..010755d --- /dev/null +++ b/tests/mergecalendars.cpp @@ -0,0 +1,228 @@ +/* mergecalendars KPilot +** +** Copyright (C) 2007 by Jason 'vanRijn' Kasper +#include +#include +#include +#include +#include + +#include +#include + +#include "options.h" + +static const TDECmdLineOptions options[] = +{ + {"korgfile ","KOrganizer master file", 0}, + {"newfile ","Calendar file to merge into korganizer", 0}, + {"category ","Category to remove from 'korgfile' and to add to events in 'newfile' for synch purposes", 0}, + {"verbose", "Verbose debugging", 0}, + TDECmdLineLastOption +}; + + + +int main(int argc, char **argv) +{ + + TDEApplication::disableAutoDcopRegistration(); + + TDEAboutData aboutData("mergecalendars","Merge libkcal Calendars","0.1"); + TDECmdLineArgs::init(argc,argv,&aboutData); + TDECmdLineArgs::addCmdLineOptions( options ); + + TDEApplication app( false, false ); + + TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); + + int debug_level= (args->isSet("verbose")) ? 4 : 0; + + TQString korgfile = args->getOption("korgfile"); + TQString newfile = args->getOption("newfile"); + TQString category = args->getOption("category"); + + if (korgfile.isEmpty()) + { + WARNINGKPILOT << "! Must provide a korganizer file." << endl; + } + if (newfile.isEmpty()) + { + WARNINGKPILOT << "! Must provide a newfile file." << endl; + } + if (category.isEmpty()) + { + WARNINGKPILOT << "! Must provide a category to use." << endl; + } + if (korgfile.isEmpty() || newfile.isEmpty() || category.isEmpty()) + { + return 1; + } + + TQString korgsave = TQString("%1.updated").arg(korgfile); + TQString newfilesave = TQString("%1.updated").arg(newfile); + + DEBUGKPILOT << "Using korgfile: [" << korgfile + << "]" << endl; + DEBUGKPILOT << "Using newfile: [" << newfile + << "]" << endl; + DEBUGKPILOT << "Will save korgfile to: [" << korgsave + << "]" << endl; + DEBUGKPILOT << "Will save newfile to: [" << newfilesave + << "]" << endl << endl; + + KCal::CalendarLocal *calkorg = new KCal::CalendarLocal( TQString::fromLatin1("UTC") ); + KCal::CalendarLocal *calnew = new KCal::CalendarLocal( TQString::fromLatin1("UTC") ); + if (!calkorg || !calnew) + { + WARNINGKPILOT << "Unable to create base calendar objects." << endl; + return 1; + } + + if (!calkorg->load(korgfile) || !calnew->load(newfile)) + { + WARNINGKPILOT << "Unable to load calendar files." << endl; + return 1; + } + + int numkorgstart = calkorg->incidences().count(); + int numnewstart = calnew->incidences().count(); + + DEBUGKPILOT << " - Opened korganizer calendar with: [" + << numkorgstart << "] incidences." << endl; + DEBUGKPILOT << " - Opened newfile calendar with: [" + << numnewstart << "] incidences." << endl; + + KCal::Event::List korgEvents; + KCal::Event::List::ConstIterator korgIt; + korgEvents = calkorg->events(); + korgEvents.setAutoDelete(false); + + KCal::Event::List newEvents; + KCal::Event::List::ConstIterator newIt; + newEvents = calnew->events(); + newEvents.setAutoDelete(false); + + DEBUGKPILOT << "Looking for previous pilot ids for exchange events..." << endl; + + // iterate through all events and try to find a korganizer event + // that matches up with this external event's UID + unsigned int numkorgpilotids = 0; + KCal::Event *ev = 0; + for (newIt = newEvents.begin(); newIt != newEvents.end(); ++newIt ) + { + ev = *newIt; + TQString uid = ev->uid(); + if (debug_level) + DEBUGKPILOT << " - Looking at event: [" + << ev->summary() << "], uid: [" + << uid << "]" << endl; + + KCal::Event * evkorg = calkorg->event(uid); + if ( evkorg && (evkorg->pilotId() > 0) ) + { + unsigned long pilotId = evkorg->pilotId(); + + if (debug_level) + DEBUGKPILOT << "Found korg event for uid: [" + << uid << "], pilotId: [" + << pilotId << "]" << endl; + + ev->setPilotId(pilotId); + ev->setSyncStatus(KCal::Incidence::SYNCMOD); + + ++numkorgpilotids; + } + } + + DEBUGKPILOT << "Matched: [" << numkorgpilotids << "] events."<< endl; + + DEBUGKPILOT << "Now searching for previous events of category: [" << category << "] in korganizer's calendar." << endl; + + // iterate through all events and try to find a korganizer event + // that matches up with this external event's UID + unsigned int numkorgremoved = 0; + + TQString categoryToken = category; + + // careful iterating and removing... + KCal::Event *next = 0; + + korgIt = korgEvents.begin(); + for ( ev = *korgIt; ev != 0; ev = next ) + { + if (++korgIt == korgEvents.end()) + { + next = 0; + } + else + { + next = *korgIt; + } + + if (ev->categoriesStr().contains(categoryToken)) + { + if (debug_level) + DEBUGKPILOT << " - Found matching event: [" + << ev->summary() << "], uid: [" + << ev->uid() << "]. Removing." << endl; + + korgEvents.remove(ev); + calkorg->deleteEvent(ev); + + ++numkorgremoved; + } + } + + DEBUGKPILOT << " - Found: [" << numkorgremoved + << "] prior: [" << categoryToken + << "] category events." << endl; + + DEBUGKPILOT << "Merging new events into korganizer calendar..." + << endl; + + for (newIt = newEvents.begin(); newIt != newEvents.end(); ++newIt ) + { + ev = *newIt; + ev->setCategories(category); + korgEvents.append(ev); + calkorg->addEvent(ev); + } + + DEBUGKPILOT << "Ended up with: [" << korgEvents.count() + << "] events in korganizer calendar." << endl; + + DEBUGKPILOT << "Saving updated korganizer file..." << endl; + calkorg->save(korgsave); + + DEBUGKPILOT << "Saving updated newfile file..." << endl; + calnew->save(newfilesave); + + return 0; +} + diff --git a/tests/testactions.cc b/tests/testactions.cc deleted file mode 100644 index 51cb236..0000000 --- a/tests/testactions.cc +++ /dev/null @@ -1,92 +0,0 @@ -/* testactions KPilot -** -** Copyright (C) 2005 by Adriaan de Groot -#include -#include -#include -#include - -#include "pilot.h" -#include "pilotAddress.h" -#include "pilotLocalDatabase.h" - -static const TDECmdLineOptions options[] = -{ - {"verbose", "Verbose output", 0}, - {"data-dir ","Set data directory", "."}, - TDECmdLineLastOption -}; - - - -int main(int argc, char **argv) -{ - TDEApplication::disableAutoDcopRegistration(); - - TDEAboutData aboutData("testaddress","Test Addresses","0.1"); - TDECmdLineArgs::init(argc,argv,&aboutData); - TDECmdLineArgs::addCmdLineOptions( options ); - - TDEApplication app( false, false ); - - TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); - -#ifdef DEBUG - debug_level= (args->isSet("verbose")) ? 4 : 0; -#endif - TQString datadir = args->getOption("data-dir"); - - DEBUGKPILOT << "### testaddresses\n#\n#" << endl; - - Pilot::setupPilotCodec( CSL1("Latin1") ); - - PilotLocalDatabase db( datadir, "AddressDB" ); - PilotAddressInfo appinfo( &db ); - - appinfo.dump(); - - for (unsigned int i=0; i +#include +#include +#include +#include + +#include "pilot.h" +#include "pilotAddress.h" +#include "pilotLocalDatabase.h" + +static const TDECmdLineOptions options[] = +{ + {"verbose", "Verbose output", 0}, + {"data-dir ","Set data directory", "."}, + TDECmdLineLastOption +}; + + + +int main(int argc, char **argv) +{ + TDEApplication::disableAutoDcopRegistration(); + + TDEAboutData aboutData("testaddress","Test Addresses","0.1"); + TDECmdLineArgs::init(argc,argv,&aboutData); + TDECmdLineArgs::addCmdLineOptions( options ); + + TDEApplication app( false, false ); + + TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); + +#ifdef DEBUG + debug_level= (args->isSet("verbose")) ? 4 : 0; +#endif + TQString datadir = args->getOption("data-dir"); + + DEBUGKPILOT << "### testaddresses\n#\n#" << endl; + + Pilot::setupPilotCodec( CSL1("Latin1") ); + + PilotLocalDatabase db( datadir, "AddressDB" ); + PilotAddressInfo appinfo( &db ); + + appinfo.dump(); + + for (unsigned int i=0; i -#include -#include -#include -#include - -#include "pilotLocalDatabase.h" -#include "pilotRecord.h" -#include "pilotAppInfo.h" - -// Name of a bogus broken DB -#define BOGUS_NAME "bogus" - -// Name of an actual DB -#define MEMO_NAME "MemoDB" - -TQStringList categories( const PilotAppInfoBase *appinfo ) -{ - TQStringList cats; - - for (unsigned int i=0; icategoryName(i); - if (!cat.isEmpty()) - { - TQString s = CSL1("(%1:%2)").arg(i).arg(cat); - cats.append(s); - } - } - - return cats; -} - -TQStringList listCategories( const TQString &dir, const char *dbname ) -{ - TQStringList cats; - PilotLocalDatabase *database = new PilotLocalDatabase( dir, dbname ); - if (!database->isOpen()) return cats; - - PilotAppInfoBase *appinfo = new PilotAppInfoBase( database ); - appinfo->dump(); - - cats = categories( appinfo ); - - delete appinfo; - delete database; - return cats; -} - -void badAppInfoCreation() -{ - FUNCTIONSETUP; - PilotAppInfoBase *appinfo = new PilotAppInfoBase( 0L ); - appinfo->dump(); - KPILOT_DELETE( appinfo ) ; - - PilotLocalDatabase *database = new PilotLocalDatabase( BOGUS_NAME ); - appinfo = new PilotAppInfoBase( database ); - appinfo->dump(); - KPILOT_DELETE( appinfo ); -} - -void categoryNames( const TQString &dir ) -{ - PilotLocalDatabase *database = new PilotLocalDatabase( dir, MEMO_NAME ); - if (!database->isOpen()) - { - WARNINGKPILOT << "Can not open database '" << MEMO_NAME << "'" << endl; - return; - } - - PilotAppInfoBase *appinfo = new PilotAppInfoBase( database ); - appinfo->dump(); - - DEBUGKPILOT << "# Done dumping" << endl; - - if (!appinfo->categoryInfo()) - { - WARNINGKPILOT << "Could not read required database" << endl; - return; - } - - const char *funnyname = "OneTwoThreeFourFiveSixSevenEight"; - const int funnyname_length = strlen(funnyname); - - if (funnyname_length < 20) - { - WARNINGKPILOT << "String of example category names is too short." << endl; - return; - } - - DEBUGKPILOT << "# Updating category names with various lengths." << endl; - DEBUGKPILOT << "# Expect three truncation errors and two bad category numbers." << endl; - for (unsigned int i=0; isetCategoryName(i,name)) - { - WARNINGKPILOT << "Failed to set category " << i << " name to <" << name << ">" << endl; - } - else - { - TQString categoryname = appinfo->categoryName(i); - if (categoryname != name) - { - WARNINGKPILOT << "Category name " << i - << " set to <" << name - << "> and returns <" - << categoryname << ">" << endl; - } - } - } - - DEBUGKPILOT << "# Final categories\n# " << categories( appinfo ).join("\n# ") << endl; -} - -static const TDECmdLineOptions options[] = -{ - {"verbose", "Verbose output", 0}, - {"data-dir ","Set data directory", "."}, - TDECmdLineLastOption -}; - - -int main(int argc, char **argv) -{ - TDEApplication::disableAutoDcopRegistration(); - - TDEAboutData aboutData("testcategories","Test Categories","0.1"); - TDECmdLineArgs::init(argc,argv,&aboutData); - TDECmdLineArgs::addCmdLineOptions( options ); - - TDEApplication app( false, false ); - - TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); - -#ifdef DEBUG - debug_level= (args->isSet("verbose")) ? 4 : 0; -#endif - - Q_UNUSED(argc); - Q_UNUSED(argv); - - static const char *files[] = { - MEMO_NAME, - "AddressDB", - "MailDB", - "ToDoDB", - 0L - }; - - TQString datadir = args->getOption("data-dir"); - - DEBUGKPILOT << "### testcategories\n#\n#" << endl; - DEBUGKPILOT << "# Listing categories from database files.\n#" << endl; - - Pilot::setupPilotCodec( CSL1("Latin1") ); - - // Include arbitrary break-off point, in case - for (unsigned int i = 0; i +#include +#include +#include +#include + +#include "pilotLocalDatabase.h" +#include "pilotRecord.h" +#include "pilotAppInfo.h" + +// Name of a bogus broken DB +#define BOGUS_NAME "bogus" + +// Name of an actual DB +#define MEMO_NAME "MemoDB" + +TQStringList categories( const PilotAppInfoBase *appinfo ) +{ + TQStringList cats; + + for (unsigned int i=0; icategoryName(i); + if (!cat.isEmpty()) + { + TQString s = CSL1("(%1:%2)").arg(i).arg(cat); + cats.append(s); + } + } + + return cats; +} + +TQStringList listCategories( const TQString &dir, const char *dbname ) +{ + TQStringList cats; + PilotLocalDatabase *database = new PilotLocalDatabase( dir, dbname ); + if (!database->isOpen()) return cats; + + PilotAppInfoBase *appinfo = new PilotAppInfoBase( database ); + appinfo->dump(); + + cats = categories( appinfo ); + + delete appinfo; + delete database; + return cats; +} + +void badAppInfoCreation() +{ + FUNCTIONSETUP; + PilotAppInfoBase *appinfo = new PilotAppInfoBase( 0L ); + appinfo->dump(); + KPILOT_DELETE( appinfo ) ; + + PilotLocalDatabase *database = new PilotLocalDatabase( BOGUS_NAME ); + appinfo = new PilotAppInfoBase( database ); + appinfo->dump(); + KPILOT_DELETE( appinfo ); +} + +void categoryNames( const TQString &dir ) +{ + PilotLocalDatabase *database = new PilotLocalDatabase( dir, MEMO_NAME ); + if (!database->isOpen()) + { + WARNINGKPILOT << "Can not open database '" << MEMO_NAME << "'" << endl; + return; + } + + PilotAppInfoBase *appinfo = new PilotAppInfoBase( database ); + appinfo->dump(); + + DEBUGKPILOT << "# Done dumping" << endl; + + if (!appinfo->categoryInfo()) + { + WARNINGKPILOT << "Could not read required database" << endl; + return; + } + + const char *funnyname = "OneTwoThreeFourFiveSixSevenEight"; + const int funnyname_length = strlen(funnyname); + + if (funnyname_length < 20) + { + WARNINGKPILOT << "String of example category names is too short." << endl; + return; + } + + DEBUGKPILOT << "# Updating category names with various lengths." << endl; + DEBUGKPILOT << "# Expect three truncation errors and two bad category numbers." << endl; + for (unsigned int i=0; isetCategoryName(i,name)) + { + WARNINGKPILOT << "Failed to set category " << i << " name to <" << name << ">" << endl; + } + else + { + TQString categoryname = appinfo->categoryName(i); + if (categoryname != name) + { + WARNINGKPILOT << "Category name " << i + << " set to <" << name + << "> and returns <" + << categoryname << ">" << endl; + } + } + } + + DEBUGKPILOT << "# Final categories\n# " << categories( appinfo ).join("\n# ") << endl; +} + +static const TDECmdLineOptions options[] = +{ + {"verbose", "Verbose output", 0}, + {"data-dir ","Set data directory", "."}, + TDECmdLineLastOption +}; + + +int main(int argc, char **argv) +{ + TDEApplication::disableAutoDcopRegistration(); + + TDEAboutData aboutData("testcategories","Test Categories","0.1"); + TDECmdLineArgs::init(argc,argv,&aboutData); + TDECmdLineArgs::addCmdLineOptions( options ); + + TDEApplication app( false, false ); + + TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); + +#ifdef DEBUG + debug_level= (args->isSet("verbose")) ? 4 : 0; +#endif + + Q_UNUSED(argc); + Q_UNUSED(argv); + + static const char *files[] = { + MEMO_NAME, + "AddressDB", + "MailDB", + "ToDoDB", + 0L + }; + + TQString datadir = args->getOption("data-dir"); + + DEBUGKPILOT << "### testcategories\n#\n#" << endl; + DEBUGKPILOT << "# Listing categories from database files.\n#" << endl; + + Pilot::setupPilotCodec( CSL1("Latin1") ); + + // Include arbitrary break-off point, in case + for (unsigned int i = 0; i - -int main(int, char **) -{ -#ifdef DEBUG - debug_level = 1; -#endif - PilotAppInfoBase info; - - - DEBUGKPILOT << "### testconstants\n#" << endl; - DEBUGKPILOT << "# Sizes of structures\n#" << endl; - DEBUGKPILOT << "# AppInfoBase: " << sizeof(PilotAppInfoBase) << endl; - DEBUGKPILOT << "# CategoryInfo: " << sizeof(info.categoryInfo()) << endl; - DEBUGKPILOT << "# CategoryInfo: " << sizeof(*info.categoryInfo()) << endl; - DEBUGKPILOT << "# Category names: " << sizeof(info.categoryInfo()->name) << endl; - DEBUGKPILOT << "# Single category: " << sizeof(info.categoryInfo()->name[0]) << endl; - - DEBUGKPILOT << "#\n# Sanity checking structure sizes\n#" << endl; - if ( sizeof(info.categoryInfo()->name[0]) != Pilot::CATEGORY_SIZE ) - { - WARNINGKPILOT << "! Category names are not 16 bytes." << endl; - return 1; - } - if ( sizeof(info.categoryInfo()->name) / sizeof(info.categoryInfo()->name[0]) != Pilot::CATEGORY_COUNT ) - { - WARNINGKPILOT << "! There are not " << Pilot::CATEGORY_COUNT << " categories available." << endl; - return 1; - } - - DEBUGKPILOT << "# OK.\n" << endl; - return 0; -} - - diff --git a/tests/testconstants.cpp b/tests/testconstants.cpp new file mode 100644 index 0000000..06e9faf --- /dev/null +++ b/tests/testconstants.cpp @@ -0,0 +1,68 @@ +/* testconstants KPilot +** +** Copyright (C) 2005 by Adriaan de Groot + +int main(int, char **) +{ +#ifdef DEBUG + debug_level = 1; +#endif + PilotAppInfoBase info; + + + DEBUGKPILOT << "### testconstants\n#" << endl; + DEBUGKPILOT << "# Sizes of structures\n#" << endl; + DEBUGKPILOT << "# AppInfoBase: " << sizeof(PilotAppInfoBase) << endl; + DEBUGKPILOT << "# CategoryInfo: " << sizeof(info.categoryInfo()) << endl; + DEBUGKPILOT << "# CategoryInfo: " << sizeof(*info.categoryInfo()) << endl; + DEBUGKPILOT << "# Category names: " << sizeof(info.categoryInfo()->name) << endl; + DEBUGKPILOT << "# Single category: " << sizeof(info.categoryInfo()->name[0]) << endl; + + DEBUGKPILOT << "#\n# Sanity checking structure sizes\n#" << endl; + if ( sizeof(info.categoryInfo()->name[0]) != Pilot::CATEGORY_SIZE ) + { + WARNINGKPILOT << "! Category names are not 16 bytes." << endl; + return 1; + } + if ( sizeof(info.categoryInfo()->name) / sizeof(info.categoryInfo()->name[0]) != Pilot::CATEGORY_COUNT ) + { + WARNINGKPILOT << "! There are not " << Pilot::CATEGORY_COUNT << " categories available." << endl; + return 1; + } + + DEBUGKPILOT << "# OK.\n" << endl; + return 0; +} + + diff --git a/tests/testdatabase.cc b/tests/testdatabase.cc deleted file mode 100644 index 68b3965..0000000 --- a/tests/testdatabase.cc +++ /dev/null @@ -1,316 +0,0 @@ -/* testdatabase KPilot -** -** Copyright (C) 2005 by Adriaan de Groot -#include -#include -#include -#include - -#include "pilotLocalDatabase.h" -#include "pilotRecord.h" -#include "pilotMemo.h" - - -/* Return values for the various check* functions. They - return OK if all is OK; ERR is for generic errors. - ERR_NO_EXIST is returned if something (usually a database - or other file) doesn't exist that should. The latter - error might be ignored. -*/ -#define OK (0) -#define ERR (1) -#define ERR_NO_EXIST (2) - - -/* Data about the records in a database. The id field is - interpreted specially for the first and last entries. -*/ -typedef struct { int id,size; } recordInfo; - -/* Use END in the last recordInfo struct describing a database - to indicate you expect the database to end there. Use NO_EXIST - as the ID in the first struct to indicate that the database - is expected _not_ to exist. -*/ -#define NO_EXIST (-2) -#define END (-1) - -/* These tables of data are taken from various databases I have - (but which I cannot commit to SVN due to license issues). - The aesop listing is from an eBook of Aesop's fables. - The way to create these tables is to use a third-party - tool such as par to read the database: - - ./par l /tmp/Aesop.pdb | awk '{print "{",$3,",",$4,"},";}' - -*/ -recordInfo nonexistent[] = { - { NO_EXIST, 0 } -} ; - -recordInfo aesop[] = { -{ 7307264 , 214 }, -{ 7307265 , 1564 }, -{ 7307266 , 1575 }, -{ 7307267 , 2214 }, -{ 7307268 , 2276 }, -{ 7307269 , 2148 }, -{ 7307270 , 2194 }, -{ 7307271 , 2178 }, -{ 7307272 , 2220 }, -{ 7307273 , 2216 }, -{ 7307274 , 2181 }, -{ 7307275 , 2183 }, -{ 7307276 , 2197 }, -{ 7307277 , 2010 }, -{ 7307278 , 2198 }, -{ 7307279 , 2196 }, -{ 7307280 , 2243 }, -{ 7307281 , 2211 }, -{ 7307282 , 2274 }, -{ 7307283 , 364 }, -{ 7307284 , 49124 }, - { END, 0 } -} ; - -int checkDatabase(const char *path, recordInfo *info) -{ - FUNCTIONSETUP; - - PilotLocalDatabase db(TQString::fromLatin1(path)); - if (!db.isOpen()) - { - kdDebug() << "No database " << path << endl; - if ( info[0].id == NO_EXIST ) - { - kdDebug() << "This was expected" << endl; - return OK; - } - else - { - return ERR_NO_EXIST; - } - } - - if ( info[0].id == NO_EXIST ) - { - kdDebug() << "Database not expected" << endl; - return ERR; - } - - int fail = 0; - int index = 0; - PilotRecord *r; - while( (r = db.readRecordByIndex(index) ) ) - { - kdDebug() << "[" << index << "] id=" << r->id() << " size=" << r->size() << endl; - if ( ((recordid_t)info[index].id) != r->id() ) - { - kdDebug() << "* Bad ID (expected" << r->id() << ")" << endl; - fail++; - } - else if ( info[index].size != r->size() ) - { - kdDebug() << "* Bad size (expected " << info[index].size << ")" << endl; - fail++; - } - index++; - } - if ( info[index].id != END ) - { - kdDebug() << "* End wasn't expected yet." << endl; - r++; - } - - if (fail) - { - kdDebug() << "* " << fail << " failures." << endl; - return ERR; - } - return OK; -} - -const char *categoryNames[4] = -{ - "aardvarks", - "toolongToBeaCategoryName", - "personal", - "impersonal" -} ; - -TQStringList listCategories() -{ - TQStringList cats; - PilotLocalDatabase *l = new PilotLocalDatabase("./data/MemoDB"); - PilotMemoInfo *m = new PilotMemoInfo(l); - - if (!l->isOpen()) return cats; - - cats.append(CSL1("Unfiled")); - m->dump(); - - for (int i=0; i<20; i++) - { - PilotRecord *r = l->readRecordByIndex(i); - kdDebug() << "Read record " << (void *)r << " with id=" << r->id() << endl; - if (!r) break; - } - - for (int i=0; i<4; i++) - { - TQString s = m->category(i); - kdDebug() << "Category " << i << ": " << (s.isEmpty() ? CSL1("") : s) << endl; - cats.append(s); -/* - if (i<((sizeof(categoryNames) / sizeof(categoryNames[0])))) - m->setCategoryName(i,TQString::fromLatin1(categoryNames[i])); -*/ - } - - m->write(l); - - delete m; - delete l; - - return cats; -} - -int checkCategories() -{ - TQStringList l = listCategories(); - TQStringList m = listCategories(); - - if (l.isEmpty() || m.isEmpty()) return ERR; - if (l!=m) return ERR; - return OK; -} - -int checkMemo() -{ - PilotLocalDatabase *l = new PilotLocalDatabase("./data/MemoDB"); - if (!l->isOpen()) return ERR_NO_EXIST; - - PilotMemoInfo *m = new PilotMemoInfo(l); - m->dump(); - - TQString c = m->category(1); - if (c != CSL1("Business")) - { - kdDebug() << "* Category 1 is not 'Business' but " << c << endl; - return ERR; - } - - m->setCategoryName(2,CSL1("Aardvark")); - m->dump(); - - c = m->category(2); - if (c != CSL1("Aardvark")) - { - kdDebug() << "* Category 2 is not 'Aardvark' but " << c << endl; - return ERR; - } - - - delete m; - delete l; - return OK; -} - -static const TDECmdLineOptions options[] = -{ - {"verbose", "Verbose output", 0}, - TDECmdLineLastOption -}; - - -int main(int argc, char **argv) -{ - TDEApplication::disableAutoDcopRegistration(); - - TDEAboutData aboutData("testdatabase","Test Databases","0.1"); - TDECmdLineArgs::init(argc,argv,&aboutData); - TDECmdLineArgs::addCmdLineOptions( options ); - - TDEApplication app( false, false ); - - TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); - - Q_UNUSED(args) - - int r = 0; - int i = 0; -#ifdef DEBUG - debug_level=4; -#endif - - Q_UNUSED(argc); - Q_UNUSED(argv); - -#define ALLOW_NO_EXIST (1) - static struct { const char *path; recordInfo *info; int flags; } - tests[] = - { - { "/tmp/nonexistant/nonexistent", nonexistent,0 }, - { "/tmp/Aesop", aesop, ALLOW_NO_EXIST }, - { 0L, 0L, 0 } - } ; - - while ( tests[i].path ) - { - kdDebug() << "*** Test " << i << endl; - int ret = checkDatabase( tests[i].path, tests[i].info ); - if ( ret ) - { - if ( (ret==ERR_NO_EXIST) && - (tests[i].flags & ALLOW_NO_EXIST) ) - { - kdDebug() << "* Test database doesn't exist, ignored." << endl; - } - else - { - r++; - } - } - i++; - } - - kdDebug() << "*** Test " << i << endl; - if (checkMemo()) r++; - i++; - - if (r) - { - kdDebug() << "***\n*** Failed " << r << " tests." << endl; - return 1; - } - return 0; -} - diff --git a/tests/testdatabase.cpp b/tests/testdatabase.cpp new file mode 100644 index 0000000..68b3965 --- /dev/null +++ b/tests/testdatabase.cpp @@ -0,0 +1,316 @@ +/* testdatabase KPilot +** +** Copyright (C) 2005 by Adriaan de Groot +#include +#include +#include +#include + +#include "pilotLocalDatabase.h" +#include "pilotRecord.h" +#include "pilotMemo.h" + + +/* Return values for the various check* functions. They + return OK if all is OK; ERR is for generic errors. + ERR_NO_EXIST is returned if something (usually a database + or other file) doesn't exist that should. The latter + error might be ignored. +*/ +#define OK (0) +#define ERR (1) +#define ERR_NO_EXIST (2) + + +/* Data about the records in a database. The id field is + interpreted specially for the first and last entries. +*/ +typedef struct { int id,size; } recordInfo; + +/* Use END in the last recordInfo struct describing a database + to indicate you expect the database to end there. Use NO_EXIST + as the ID in the first struct to indicate that the database + is expected _not_ to exist. +*/ +#define NO_EXIST (-2) +#define END (-1) + +/* These tables of data are taken from various databases I have + (but which I cannot commit to SVN due to license issues). + The aesop listing is from an eBook of Aesop's fables. + The way to create these tables is to use a third-party + tool such as par to read the database: + + ./par l /tmp/Aesop.pdb | awk '{print "{",$3,",",$4,"},";}' + +*/ +recordInfo nonexistent[] = { + { NO_EXIST, 0 } +} ; + +recordInfo aesop[] = { +{ 7307264 , 214 }, +{ 7307265 , 1564 }, +{ 7307266 , 1575 }, +{ 7307267 , 2214 }, +{ 7307268 , 2276 }, +{ 7307269 , 2148 }, +{ 7307270 , 2194 }, +{ 7307271 , 2178 }, +{ 7307272 , 2220 }, +{ 7307273 , 2216 }, +{ 7307274 , 2181 }, +{ 7307275 , 2183 }, +{ 7307276 , 2197 }, +{ 7307277 , 2010 }, +{ 7307278 , 2198 }, +{ 7307279 , 2196 }, +{ 7307280 , 2243 }, +{ 7307281 , 2211 }, +{ 7307282 , 2274 }, +{ 7307283 , 364 }, +{ 7307284 , 49124 }, + { END, 0 } +} ; + +int checkDatabase(const char *path, recordInfo *info) +{ + FUNCTIONSETUP; + + PilotLocalDatabase db(TQString::fromLatin1(path)); + if (!db.isOpen()) + { + kdDebug() << "No database " << path << endl; + if ( info[0].id == NO_EXIST ) + { + kdDebug() << "This was expected" << endl; + return OK; + } + else + { + return ERR_NO_EXIST; + } + } + + if ( info[0].id == NO_EXIST ) + { + kdDebug() << "Database not expected" << endl; + return ERR; + } + + int fail = 0; + int index = 0; + PilotRecord *r; + while( (r = db.readRecordByIndex(index) ) ) + { + kdDebug() << "[" << index << "] id=" << r->id() << " size=" << r->size() << endl; + if ( ((recordid_t)info[index].id) != r->id() ) + { + kdDebug() << "* Bad ID (expected" << r->id() << ")" << endl; + fail++; + } + else if ( info[index].size != r->size() ) + { + kdDebug() << "* Bad size (expected " << info[index].size << ")" << endl; + fail++; + } + index++; + } + if ( info[index].id != END ) + { + kdDebug() << "* End wasn't expected yet." << endl; + r++; + } + + if (fail) + { + kdDebug() << "* " << fail << " failures." << endl; + return ERR; + } + return OK; +} + +const char *categoryNames[4] = +{ + "aardvarks", + "toolongToBeaCategoryName", + "personal", + "impersonal" +} ; + +TQStringList listCategories() +{ + TQStringList cats; + PilotLocalDatabase *l = new PilotLocalDatabase("./data/MemoDB"); + PilotMemoInfo *m = new PilotMemoInfo(l); + + if (!l->isOpen()) return cats; + + cats.append(CSL1("Unfiled")); + m->dump(); + + for (int i=0; i<20; i++) + { + PilotRecord *r = l->readRecordByIndex(i); + kdDebug() << "Read record " << (void *)r << " with id=" << r->id() << endl; + if (!r) break; + } + + for (int i=0; i<4; i++) + { + TQString s = m->category(i); + kdDebug() << "Category " << i << ": " << (s.isEmpty() ? CSL1("") : s) << endl; + cats.append(s); +/* + if (i<((sizeof(categoryNames) / sizeof(categoryNames[0])))) + m->setCategoryName(i,TQString::fromLatin1(categoryNames[i])); +*/ + } + + m->write(l); + + delete m; + delete l; + + return cats; +} + +int checkCategories() +{ + TQStringList l = listCategories(); + TQStringList m = listCategories(); + + if (l.isEmpty() || m.isEmpty()) return ERR; + if (l!=m) return ERR; + return OK; +} + +int checkMemo() +{ + PilotLocalDatabase *l = new PilotLocalDatabase("./data/MemoDB"); + if (!l->isOpen()) return ERR_NO_EXIST; + + PilotMemoInfo *m = new PilotMemoInfo(l); + m->dump(); + + TQString c = m->category(1); + if (c != CSL1("Business")) + { + kdDebug() << "* Category 1 is not 'Business' but " << c << endl; + return ERR; + } + + m->setCategoryName(2,CSL1("Aardvark")); + m->dump(); + + c = m->category(2); + if (c != CSL1("Aardvark")) + { + kdDebug() << "* Category 2 is not 'Aardvark' but " << c << endl; + return ERR; + } + + + delete m; + delete l; + return OK; +} + +static const TDECmdLineOptions options[] = +{ + {"verbose", "Verbose output", 0}, + TDECmdLineLastOption +}; + + +int main(int argc, char **argv) +{ + TDEApplication::disableAutoDcopRegistration(); + + TDEAboutData aboutData("testdatabase","Test Databases","0.1"); + TDECmdLineArgs::init(argc,argv,&aboutData); + TDECmdLineArgs::addCmdLineOptions( options ); + + TDEApplication app( false, false ); + + TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); + + Q_UNUSED(args) + + int r = 0; + int i = 0; +#ifdef DEBUG + debug_level=4; +#endif + + Q_UNUSED(argc); + Q_UNUSED(argv); + +#define ALLOW_NO_EXIST (1) + static struct { const char *path; recordInfo *info; int flags; } + tests[] = + { + { "/tmp/nonexistant/nonexistent", nonexistent,0 }, + { "/tmp/Aesop", aesop, ALLOW_NO_EXIST }, + { 0L, 0L, 0 } + } ; + + while ( tests[i].path ) + { + kdDebug() << "*** Test " << i << endl; + int ret = checkDatabase( tests[i].path, tests[i].info ); + if ( ret ) + { + if ( (ret==ERR_NO_EXIST) && + (tests[i].flags & ALLOW_NO_EXIST) ) + { + kdDebug() << "* Test database doesn't exist, ignored." << endl; + } + else + { + r++; + } + } + i++; + } + + kdDebug() << "*** Test " << i << endl; + if (checkMemo()) r++; + i++; + + if (r) + { + kdDebug() << "***\n*** Failed " << r << " tests." << endl; + return 1; + } + return 0; +} + diff --git a/tests/testdatebook.cc b/tests/testdatebook.cc deleted file mode 100644 index 82cc46a..0000000 --- a/tests/testdatebook.cc +++ /dev/null @@ -1,95 +0,0 @@ -/* testaddresses KPilot -** -** Copyright (C) 2006 by Adriaan de Groot -#include -#include -#include -#include - -#include "pilot.h" -#include "pilotDateEntry.h" -#include "pilotLocalDatabase.h" - -static const TDECmdLineOptions options[] = -{ - {"verbose", "Verbose output", 0}, - {"data-dir ","Set data directory", "."}, - TDECmdLineLastOption -}; - - - -int main(int argc, char **argv) -{ - TDEApplication::disableAutoDcopRegistration(); - - TDEAboutData aboutData("testdatebook","Test Date Book","0.1"); - TDECmdLineArgs::init(argc,argv,&aboutData); - TDECmdLineArgs::addCmdLineOptions( options ); - - TDEApplication app( false, false ); - - TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); - -#ifdef DEBUG - debug_level= (args->isSet("verbose")) ? 4 : 0; -#endif - TQString datadir = args->getOption("data-dir"); - - DEBUGKPILOT << "### testdatebook\n#\n#" << endl; - - Pilot::setupPilotCodec( CSL1("Latin1") ); - - PilotLocalDatabase db( datadir, "DatebookDB" ); - PilotDateInfo appinfo( &db ); - - for (unsigned int i=0; i +#include +#include +#include +#include + +#include "pilot.h" +#include "pilotDateEntry.h" +#include "pilotLocalDatabase.h" + +static const TDECmdLineOptions options[] = +{ + {"verbose", "Verbose output", 0}, + {"data-dir ","Set data directory", "."}, + TDECmdLineLastOption +}; + + + +int main(int argc, char **argv) +{ + TDEApplication::disableAutoDcopRegistration(); + + TDEAboutData aboutData("testdatebook","Test Date Book","0.1"); + TDECmdLineArgs::init(argc,argv,&aboutData); + TDECmdLineArgs::addCmdLineOptions( options ); + + TDEApplication app( false, false ); + + TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); + +#ifdef DEBUG + debug_level= (args->isSet("verbose")) ? 4 : 0; +#endif + TQString datadir = args->getOption("data-dir"); + + DEBUGKPILOT << "### testdatebook\n#\n#" << endl; + + Pilot::setupPilotCodec( CSL1("Latin1") ); + + PilotLocalDatabase db( datadir, "DatebookDB" ); + PilotDateInfo appinfo( &db ); + + for (unsigned int i=0; i -#include -#include - -#include -#include - -#define TESTFILE "Testing/mapping.xml" -#define CONDUIT CSL1("knotes") - -/** - * If the file does not exist it should be created by the idmapper. - */ -bool test1() -{ - FUNCTIONSETUP; - - IDMapper *mapper = new IDMapper( TESTFILE ); - - delete mapper; - mapper = 0l; - - TQFile f( TESTFILE ); - bool result = f.exists(); - - if( result ) - { - DEBUGKPILOT << fname << ": passed" << endl; - } - else - { - DEBUGKPILOT << fname << ": failed" << endl; - } - - return result; -} - -/** - * Test if a uid gets added when it's registered. - */ -bool test2() -{ - FUNCTIONSETUP; - - IDMapper *mapper = new IDMapper( TESTFILE ); - mapper->registerPCObjectId( CONDUIT, CSL1("testuid-1") ); - - delete mapper; - mapper = 0l; - - // Creating a new mapper ensures that the file is readed. So we know if this - // test passess that the data is saved and readed from the xml file correctly. - mapper = new IDMapper( TESTFILE ); - - bool result1 = ( mapper->getPCObjectIds( CONDUIT ).size() == 1 ); - bool result2 = false; - - if( result1 ) - result2 = ( mapper->getPCObjectIds( CONDUIT ).first() == "testuid-1" ); - - - if( result1 && result2 ) - { - DEBUGKPILOT << fname << ": passed" << endl; - } - else - { - DEBUGKPILOT << fname << ": " << result1 << " " << result2 << endl; - DEBUGKPILOT << fname << ": failed" << endl; - } - - delete mapper; - mapper = 0l; - - return (result1 && result2); -} - -/** - * Set the pid for uid "testuid-1". getHHObjectIds should return 1 item now and - * that should be the same as the one which is set. - */ -bool test3() -{ - FUNCTIONSETUP; - - IDMapper *mapper = new IDMapper( TESTFILE ); - mapper->setHHObjectId( CONDUIT, "testuid-1", 100 ); - - delete mapper; - mapper = 0l; - - // Creating a new mapper ensures that the file is readed. So we know if this - // test passess that the data is saved and readed from the xml file correctly. - mapper = new IDMapper( TESTFILE ); - - bool result1 = ( mapper->getHHObjectIds( CONDUIT ).size() == 1 ); - bool result2 = false; - - if( result1 ) - result2 = ( mapper->getHHObjectIds( CONDUIT ).first() == 100 ); - - - if( result1 && result2 ) - { - DEBUGKPILOT << fname << ": passed" << endl; - } - else - { - DEBUGKPILOT << fname << ": " << result1 << " " << result2 << endl; - DEBUGKPILOT << fname << ": failed" << endl; - } - - delete mapper; - mapper = 0l; - - return (result1 && result2); -} - -/** - * Test if a pid is stored correctly when it's registered. - */ -bool test4() -{ - FUNCTIONSETUP; - - IDMapper *mapper = new IDMapper( TESTFILE ); - mapper->registerHHObjectId( CONDUIT, 150 ); - - delete mapper; - mapper = 0l; - - // Creating a new mapper ensures that the file is readed. So we know if this - // test passess that the data is saved and readed from the xml file correctly. - mapper = new IDMapper( TESTFILE ); - - // We have two pids registered at this moment - bool result1 = ( mapper->getHHObjectIds( CONDUIT ).size() == 2 ); - bool result2 = false; - - // This prevents the test from chrashing when getHHObjectIds.size is 0. - if( result1 ) - result2 = ( mapper->getHHObjectIds( CONDUIT ).contains( 150 ) ); - - if( result1 && result2 ) - { - DEBUGKPILOT << fname << ": passed" << endl; - } - else - { - DEBUGKPILOT << fname << ": " << result1 << " " << result2 << endl; - DEBUGKPILOT << fname << ": failed" << endl; - } - - delete mapper; - mapper = 0l; - - return (result1 && result2); -} - -/** - * Set the uid for pid 150. getPcObjectIds should return 2 items now and - * it should contain the one which is just set. - */ -bool test5() -{ - FUNCTIONSETUP; - - IDMapper *mapper = new IDMapper( TESTFILE ); - mapper->setPCObjectId( CONDUIT, 150, "testuid-2" ); - - delete mapper; - mapper = 0l; - - // Creating a new mapper ensures that the file is readed. So we know if this - // test passess that the data is saved and readed from the xml file correctly. - mapper = new IDMapper( TESTFILE ); - - bool result1 = ( mapper->getPCObjectIds( CONDUIT ).size() == 2 ); - bool result2 = false; - - if( result1 ) - result2 = ( mapper->getPCObjectIds( CONDUIT ).contains( "testuid-2" ) ); - - - if( result1 && result2 ) - { - DEBUGKPILOT << fname << ": passed" << endl; - } - else - { - DEBUGKPILOT << fname << ": " << result1 << " " << result2 << endl; - DEBUGKPILOT << fname << ": failed" << endl; - } - - delete mapper; - mapper = 0l; - - return (result1 && result2); -} - - -/** - * Test for the hasPCId function. - */ -bool test6() -{ - FUNCTIONSETUP; - - IDMapper *mapper = new IDMapper( TESTFILE ); - - // Should be true (PCId is set to "testuid-2"). - bool result = mapper->hasPCId( CONDUIT, 150 ); - - delete mapper; - mapper = 0l; - - if( result ) - { - DEBUGKPILOT << fname << ": passed" << endl; - } - else - { - DEBUGKPILOT << fname << ": failed" << endl; - } - - return result; -} - -/** - * Test for the hasHHId function. - */ -bool test7() -{ - FUNCTIONSETUP; - - IDMapper *mapper = new IDMapper( TESTFILE ); - - // Should be true (HHId is set to "150"). - bool result = mapper->hasHHId( CONDUIT, "testuid-2" ); - - delete mapper; - mapper = 0l; - - if( result ) - { - DEBUGKPILOT << fname << ": passed" << endl; - } - else - { - DEBUGKPILOT << fname << ": failed" << endl; - } - - return result; -} - -int main(int argc, char **argv) -{ - TDEApplication::disableAutoDcopRegistration(); - TDEAboutData aboutData("testidmapper","Test IDMapper","0.1"); - TDECmdLineArgs::init(argc,argv,&aboutData); - - TDEApplication app( false, false ); - - // Remove file from previous test run - TQDir test( "Testing" ); - if( !test.exists() ) { - TQDir current; - current.mkdir( "Testing" ); - } - - TQFile f( TESTFILE ); - if( f.exists() ) - TQFile::remove( TESTFILE ); - - if( test1() && test2() && test3() && - test4() && test5() && test6() && - test7() ) - return 0; - else - return 1; -} - - diff --git a/tests/testidmapper.cpp b/tests/testidmapper.cpp new file mode 100644 index 0000000..8c9cccf --- /dev/null +++ b/tests/testidmapper.cpp @@ -0,0 +1,314 @@ +/* testactions KPilot +** +** Copyright (C) 2005 by Adriaan de Groot +#include +#include + +#include +#include + +#define TESTFILE "Testing/mapping.xml" +#define CONDUIT CSL1("knotes") + +/** + * If the file does not exist it should be created by the idmapper. + */ +bool test1() +{ + FUNCTIONSETUP; + + IDMapper *mapper = new IDMapper( TESTFILE ); + + delete mapper; + mapper = 0l; + + TQFile f( TESTFILE ); + bool result = f.exists(); + + if( result ) + { + DEBUGKPILOT << fname << ": passed" << endl; + } + else + { + DEBUGKPILOT << fname << ": failed" << endl; + } + + return result; +} + +/** + * Test if a uid gets added when it's registered. + */ +bool test2() +{ + FUNCTIONSETUP; + + IDMapper *mapper = new IDMapper( TESTFILE ); + mapper->registerPCObjectId( CONDUIT, CSL1("testuid-1") ); + + delete mapper; + mapper = 0l; + + // Creating a new mapper ensures that the file is readed. So we know if this + // test passess that the data is saved and readed from the xml file correctly. + mapper = new IDMapper( TESTFILE ); + + bool result1 = ( mapper->getPCObjectIds( CONDUIT ).size() == 1 ); + bool result2 = false; + + if( result1 ) + result2 = ( mapper->getPCObjectIds( CONDUIT ).first() == "testuid-1" ); + + + if( result1 && result2 ) + { + DEBUGKPILOT << fname << ": passed" << endl; + } + else + { + DEBUGKPILOT << fname << ": " << result1 << " " << result2 << endl; + DEBUGKPILOT << fname << ": failed" << endl; + } + + delete mapper; + mapper = 0l; + + return (result1 && result2); +} + +/** + * Set the pid for uid "testuid-1". getHHObjectIds should return 1 item now and + * that should be the same as the one which is set. + */ +bool test3() +{ + FUNCTIONSETUP; + + IDMapper *mapper = new IDMapper( TESTFILE ); + mapper->setHHObjectId( CONDUIT, "testuid-1", 100 ); + + delete mapper; + mapper = 0l; + + // Creating a new mapper ensures that the file is readed. So we know if this + // test passess that the data is saved and readed from the xml file correctly. + mapper = new IDMapper( TESTFILE ); + + bool result1 = ( mapper->getHHObjectIds( CONDUIT ).size() == 1 ); + bool result2 = false; + + if( result1 ) + result2 = ( mapper->getHHObjectIds( CONDUIT ).first() == 100 ); + + + if( result1 && result2 ) + { + DEBUGKPILOT << fname << ": passed" << endl; + } + else + { + DEBUGKPILOT << fname << ": " << result1 << " " << result2 << endl; + DEBUGKPILOT << fname << ": failed" << endl; + } + + delete mapper; + mapper = 0l; + + return (result1 && result2); +} + +/** + * Test if a pid is stored correctly when it's registered. + */ +bool test4() +{ + FUNCTIONSETUP; + + IDMapper *mapper = new IDMapper( TESTFILE ); + mapper->registerHHObjectId( CONDUIT, 150 ); + + delete mapper; + mapper = 0l; + + // Creating a new mapper ensures that the file is readed. So we know if this + // test passess that the data is saved and readed from the xml file correctly. + mapper = new IDMapper( TESTFILE ); + + // We have two pids registered at this moment + bool result1 = ( mapper->getHHObjectIds( CONDUIT ).size() == 2 ); + bool result2 = false; + + // This prevents the test from chrashing when getHHObjectIds.size is 0. + if( result1 ) + result2 = ( mapper->getHHObjectIds( CONDUIT ).contains( 150 ) ); + + if( result1 && result2 ) + { + DEBUGKPILOT << fname << ": passed" << endl; + } + else + { + DEBUGKPILOT << fname << ": " << result1 << " " << result2 << endl; + DEBUGKPILOT << fname << ": failed" << endl; + } + + delete mapper; + mapper = 0l; + + return (result1 && result2); +} + +/** + * Set the uid for pid 150. getPcObjectIds should return 2 items now and + * it should contain the one which is just set. + */ +bool test5() +{ + FUNCTIONSETUP; + + IDMapper *mapper = new IDMapper( TESTFILE ); + mapper->setPCObjectId( CONDUIT, 150, "testuid-2" ); + + delete mapper; + mapper = 0l; + + // Creating a new mapper ensures that the file is readed. So we know if this + // test passess that the data is saved and readed from the xml file correctly. + mapper = new IDMapper( TESTFILE ); + + bool result1 = ( mapper->getPCObjectIds( CONDUIT ).size() == 2 ); + bool result2 = false; + + if( result1 ) + result2 = ( mapper->getPCObjectIds( CONDUIT ).contains( "testuid-2" ) ); + + + if( result1 && result2 ) + { + DEBUGKPILOT << fname << ": passed" << endl; + } + else + { + DEBUGKPILOT << fname << ": " << result1 << " " << result2 << endl; + DEBUGKPILOT << fname << ": failed" << endl; + } + + delete mapper; + mapper = 0l; + + return (result1 && result2); +} + + +/** + * Test for the hasPCId function. + */ +bool test6() +{ + FUNCTIONSETUP; + + IDMapper *mapper = new IDMapper( TESTFILE ); + + // Should be true (PCId is set to "testuid-2"). + bool result = mapper->hasPCId( CONDUIT, 150 ); + + delete mapper; + mapper = 0l; + + if( result ) + { + DEBUGKPILOT << fname << ": passed" << endl; + } + else + { + DEBUGKPILOT << fname << ": failed" << endl; + } + + return result; +} + +/** + * Test for the hasHHId function. + */ +bool test7() +{ + FUNCTIONSETUP; + + IDMapper *mapper = new IDMapper( TESTFILE ); + + // Should be true (HHId is set to "150"). + bool result = mapper->hasHHId( CONDUIT, "testuid-2" ); + + delete mapper; + mapper = 0l; + + if( result ) + { + DEBUGKPILOT << fname << ": passed" << endl; + } + else + { + DEBUGKPILOT << fname << ": failed" << endl; + } + + return result; +} + +int main(int argc, char **argv) +{ + TDEApplication::disableAutoDcopRegistration(); + TDEAboutData aboutData("testidmapper","Test IDMapper","0.1"); + TDECmdLineArgs::init(argc,argv,&aboutData); + + TDEApplication app( false, false ); + + // Remove file from previous test run + TQDir test( "Testing" ); + if( !test.exists() ) { + TQDir current; + current.mkdir( "Testing" ); + } + + TQFile f( TESTFILE ); + if( f.exists() ) + TQFile::remove( TESTFILE ); + + if( test1() && test2() && test3() && + test4() && test5() && test6() && + test7() ) + return 0; + else + return 1; +} + + -- cgit v1.2.1