From 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kpilot/tests/testcategories.cc | 215 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 215 insertions(+) create mode 100644 kpilot/tests/testcategories.cc (limited to 'kpilot/tests/testcategories.cc') diff --git a/kpilot/tests/testcategories.cc b/kpilot/tests/testcategories.cc new file mode 100644 index 000000000..1ecfebf66 --- /dev/null +++ b/kpilot/tests/testcategories.cc @@ -0,0 +1,215 @@ +/* testcategories KPilot +** +** Copyright (C) 2005 by Adriaan de Groot +#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" + +QStringList categories( const PilotAppInfoBase *appinfo ) +{ + QStringList cats; + + for (unsigned int i=0; icategoryName(i); + if (!cat.isEmpty()) + { + QString s = CSL1("(%1:%2)").arg(i).arg(cat); + cats.append(s); + } + } + + return cats; +} + +QStringList listCategories( const QString &dir, const char *dbname ) +{ + QStringList 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 QString &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 + { + QString 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 KCmdLineOptions options[] = +{ + {"verbose", "Verbose output", 0}, + {"data-dir ","Set data directory", "."}, + KCmdLineLastOption +}; + + +int main(int argc, char **argv) +{ + KApplication::disableAutoDcopRegistration(); + + KAboutData aboutData("testcategories","Test Categories","0.1"); + KCmdLineArgs::init(argc,argv,&aboutData); + KCmdLineArgs::addCmdLineOptions( options ); + + KApplication app( false, false ); + + KCmdLineArgs *args = KCmdLineArgs::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 + }; + + QString 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