TDE personal information management applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
3.4 KiB

  1. /*
  2. This file is part of libkcal.
  3. Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
  4. Copyright (C) 2005 Reinhold Kainhofer <reinhold@kainhofe.com>
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public
  7. License as published by the Free Software Foundation; either
  8. version 2 of the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Library General Public License for more details.
  13. You should have received a copy of the GNU Library General Public License
  14. along with this library; see the file COPYING.LIB. If not, write to
  15. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16. Boston, MA 02110-1301, USA.
  17. */
  18. #include "calendarlocal.h"
  19. extern "C" {
  20. #include "libical/icaltimezone.h"
  21. }
  22. #include <tdeaboutdata.h>
  23. #include <tdeapplication.h>
  24. #include <kdebug.h>
  25. #include <tdecmdlineargs.h>
  26. #include <tqfile.h>
  27. using namespace KCal;
  28. static const TDECmdLineOptions options[] =
  29. {
  30. { "verbose", "Verbose output", 0 },
  31. { "+input", "Name of input file", 0 },
  32. { "[+output]", "optional name of output file for the recurrence dates", 0 },
  33. TDECmdLineLastOption
  34. };
  35. int main( int argc, char **argv )
  36. {
  37. TDEAboutData aboutData( "testrecurson", "Tests all dates from 2002 to 2010 to test if the event recurs on each individual date. This is meant to test the Recurrence::recursOn method for errors.", "0.1" );
  38. TDECmdLineArgs::init( argc, argv, &aboutData );
  39. TDECmdLineArgs::addCmdLineOptions( options );
  40. TDEApplication app( false, false );
  41. TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
  42. if ( args->count() < 1 ) {
  43. args->usage( "Wrong number of arguments." );
  44. }
  45. TQString input = TQFile::decodeName( args->arg( 0 ) );
  46. kdDebug(5800) << "Input file: " << input << endl;
  47. TQTextStream *outstream;
  48. outstream = 0;
  49. TQString fn("");
  50. if ( args->count() > 1 ) {
  51. fn = args->arg( 1 );
  52. kdDebug() << "We have a file name given: " << fn << endl;
  53. }
  54. TQFile outfile( fn );
  55. if ( !fn.isEmpty() && outfile.open( IO_WriteOnly ) ) {
  56. kdDebug() << "Opened output file!!!" << endl;
  57. outstream = new TQTextStream( &outfile );
  58. }
  59. CalendarLocal cal( TQString::fromLatin1("UTC") );
  60. if ( !cal.load( input ) ) return 1;
  61. TQString tz = cal.nonKDECustomProperty( "X-LibKCal-Testsuite-OutTZ" );
  62. if ( !tz.isEmpty() ) {
  63. cal.setTimeZoneIdViewOnly( tz );
  64. }
  65. Incidence::List inc = cal.incidences();
  66. for ( Incidence::List::Iterator it = inc.begin(); it != inc.end(); ++it ) {
  67. Incidence *incidence = *it;
  68. kdDebug(5800) << "*+*+*+*+*+*+*+*+*+*" << endl;
  69. kdDebug(5800) << " -> " << incidence->summary() << " <- " << endl;
  70. incidence->recurrence()->dump();
  71. TQDate dt( 1996, 7, 1 );
  72. if ( outstream ) {
  73. // Output to file for testing purposes
  74. while ( dt.year() <= 2010 ) {
  75. if ( incidence->recursOn( dt ) )
  76. (*outstream) << dt.toString( TQt::ISODate ) << endl;
  77. dt = dt.addDays( 1 );
  78. }
  79. } else {
  80. dt = TQDate( 2005, 1, 1 );
  81. while ( dt.year() < 2007 ) {
  82. if ( incidence->recursOn( dt ) )
  83. kdDebug(5800) << dt.toString( TQt::ISODate ) << endl;
  84. dt = dt.addDays( 1 );
  85. }
  86. }
  87. }
  88. delete outstream;
  89. outfile.close();
  90. return 0;
  91. }