[patch 12/15] [freqspec.diff] Minor tweaks to FreqSpec

c.shoemaker at cox.net c.shoemaker at cox.net
Mon Oct 10 10:34:34 EDT 2005


       * src/engine/FreqSpec.c: line-wrap fixes

       * src/enging/test/test-freq-spec.c: 
         - add a failing test case for FreqSpec

 src/engine/FreqSpec.c            |   12 +++++++-----
 src/engine/test/test-freq-spec.c |   23 ++++++++++++++++++++++-
 2 files changed, 29 insertions(+), 6 deletions(-)

Index: gnucash/src/engine/FreqSpec.c
===================================================================
--- gnucash.orig/src/engine/FreqSpec.c
+++ gnucash/src/engine/FreqSpec.c
@@ -378,14 +378,15 @@ xaccFreqSpecGetNextInstance( FreqSpec *f
       wday_of_1st = g_date_get_weekday( &date1 );
       /* This calculates the day of the month in the month which forms
        * the next month in the cycle after the given input date.
-       * However, this day may be larger than the number of days in that month... */
+       * However, this day may be larger than the number of days in
+       * that month... */
       day_of_repeat = (fs->s.month_relative.occurrence-1)*7 +
          ((fs->s.month_relative.weekday + 7 - wday_of_1st)%7 + 1);
       while( day_of_repeat > g_date_days_in_month( month, year ) ) {
-         /* If the repeat occurs after the end of the month, then
-          * find the next month containing a day which satisfies the request.
-          * Each candiate month separated by interval_months is considered
-          * by this loop.*/
+         /* If the repeat occurs after the end of the month, then find
+          * the next month containing a day which satisfies the
+          * request.  Each candiate month separated by interval_months
+          * is considered by this loop.*/
          ++complete_intervals;
          next_repeat_months_from_epoch =
             fs->s.month_relative.offset_from_epoch +
@@ -434,6 +435,7 @@ xaccFreqSpecGetNextInstance( FreqSpec *f
    }
 }
 
+
 /*
 char*
 xaccFreqSpecIsValidDateRelaxed( FreqSpec *fs, time_t query )
Index: gnucash/src/engine/test/test-freq-spec.c
===================================================================
--- gnucash.orig/src/engine/test/test-freq-spec.c
+++ gnucash/src/engine/test/test-freq-spec.c
@@ -89,7 +89,7 @@ test_daily (void)
    g_date_set_dmy( &date1, 25, 3, 2001 );
    for( interval = 1; interval < 20; ++interval ) {
       xaccFreqSpecSetDaily( fs, &date1, interval );
-      for( j = 0; j < 20; ++j ) {
+      for( j = 0; j < 20; ++j ) { /* j=0 passes by luck, but it's not valid */
          date2 = date1;
          for( i = 0; i < j; ++i ) {
             xaccFreqSpecGetNextInstance( fs, &date2, &next_date );
@@ -357,6 +357,26 @@ test_month_relative (void)
    xaccFreqSpecFree(fs);
 }
 
+static void test_caseA()
+{
+   FreqSpec *fs;
+   GDate date0, date1, date2, date3;
+
+   fs = xaccFreqSpecMalloc(book);
+
+   g_date_set_dmy(&date0, 31, 12, 1); /* end of year */
+
+   xaccFreqSpecSetMonthly(fs, &date0, 3);  /* quarterly */
+
+   g_date_set_dmy(&date1, 13, 2, 1);  /* Feb 13th */
+   xaccFreqSpecGetNextInstance( fs, &date1, &date2 );
+
+   g_date_set_dmy( &date3, 31, 3, 1 ); /* Should get March 31st */
+   do_test( g_date_compare( &date2, &date3 ) == 0, "end of quarter" );
+
+   xaccFreqSpecFree(fs);
+}
+
 static void
 test_composite (void)
 {
@@ -549,6 +569,7 @@ main (int argc, char **argv)
 	session = qof_session_new ();
 	book = qof_session_get_book(session);
    test_once();
+   test_caseA();
    test_daily();
    test_weekly();
    test_monthly();

--


More information about the gnucash-devel mailing list