diff options
author | Michele Calgaro <[email protected]> | 2021-05-29 19:05:31 +0900 |
---|---|---|
committer | Michele Calgaro <[email protected]> | 2021-05-29 19:31:17 +0900 |
commit | 66abbed5e08370412b81be1628590898ceeeb604 (patch) | |
tree | b31703c326b690ad90f926f97ce0e92e70bf7cdd /tests/testcategories.cc | |
parent | 51b78ed87ec5219dc0413aa86132f16cb0a8cab1 (diff) | |
download | kpilot-66abbed5e08370412b81be1628590898ceeeb604.tar.gz kpilot-66abbed5e08370412b81be1628590898ceeeb604.zip |
Renaming of files in preparation for code style tools.
Signed-off-by: Michele Calgaro <[email protected]>
Diffstat (limited to 'tests/testcategories.cc')
-rw-r--r-- | tests/testcategories.cc | 215 |
1 files changed, 0 insertions, 215 deletions
diff --git a/tests/testcategories.cc b/tests/testcategories.cc deleted file mode 100644 index 35d5cd3..0000000 --- a/tests/testcategories.cc +++ /dev/null @@ -1,215 +0,0 @@ -/* testcategories KPilot -** -** Copyright (C) 2005 by Adriaan de Groot <[email protected]) -** -** Test the functions related to category handling. -*/ - -/* -** This program is free software; you can redistribute it and/or modify -** it under the terms of the GNU Lesser General Public License as published by -** the Free Software Foundation; either version 2.1 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU Lesser General Public License for more details. -** -** You should have received a copy of the GNU Lesser General Public License -** along with this program in a file called COPYING; if not, write to -** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, -** MA 02110-1301, USA. -*/ - -/* -** Bug reports and questions can be sent to [email protected] -*/ - -#include "options.h" - -#include <tdeaboutdata.h> -#include <tdeapplication.h> -#include <kdebug.h> -#include <tdelocale.h> -#include <tdecmdlineargs.h> - -#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; i<Pilot::CATEGORY_COUNT; i++) - { - TQString cat = appinfo->categoryName(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; i<Pilot::CATEGORY_COUNT+2; i++) - { - TQString name = TQString::fromLatin1(funnyname+funnyname_length-i-3); - if (!appinfo->setCategoryName(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 <path>","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<sizeof(files)/sizeof(const char *) ; i++) - { - if (!files[i]) - { - break; - } - DEBUGKPILOT << "# Categories (" << files[i] << "): " << endl; - DEBUGKPILOT << "# " << listCategories( datadir, files[i] ).join("\n# ") << "\n#\n"; - } - // Should bail, not crash - DEBUGKPILOT << "# Categories (nonexistent): " << endl; - (void) listCategories( datadir, "nonexistent" ); - - DEBUGKPILOT << "# Categories (bogus): " << endl; - (void) listCategories( datadir, BOGUS_NAME ); - - DEBUGKPILOT << "#\n# Trying to pass broken pointers to category functions.\n# Four errors are expected.\n#" << endl; - badAppInfoCreation(); - - DEBUGKPILOT << "#\n# Checking category names." << endl; - categoryNames( datadir ); - - DEBUGKPILOT << "# OK.\n" << endl; - return 0; -} - |