Changes in / [16ce7a4:650fb2c]


Ignore:
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • history.c

    r25891a8 r95b52d1  
    66  h->cur = h->hist.tail;        /* current position in history */
    77  h->partial = false;           /* is the 0th element is partially composed? */
    8 }
    9 
    10 void owl_history_cleanup(owl_history *h)
    11 {
    12   g_queue_foreach(&h->hist, (GFunc)g_free, NULL);
    13   g_queue_clear(&h->hist);
    148}
    159
     
    4640
    4741  /* if we've reached the max history size, pop off the last element */
    48   if (g_queue_get_length(&h->hist) >= OWL_HISTORYSIZE)
     42  if (g_queue_get_length(&h->hist) > OWL_HISTORYSIZE)
    4943    g_free(g_queue_pop_head(&h->hist));
    5044
  • tester.c

    r25891a8 rce68f23  
    2323int owl_fmtext_regtest(void);
    2424int owl_smartfilter_regtest(void);
    25 int owl_history_regtest(void);
    2625
    2726extern void owl_perl_xs_init(pTHX);
     
    113112  numfailures += owl_fmtext_regtest();
    114113  numfailures += owl_smartfilter_regtest();
    115   numfailures += owl_history_regtest();
    116114  if (numfailures) {
    117115      fprintf(stderr, "# *** WARNING: %d failures total\n", numfailures);
     
    805803  return numfailed;
    806804}
    807 
    808 int owl_history_regtest(void)
    809 {
    810   int numfailed = 0;
    811   int i;
    812   owl_history h;
    813 
    814   printf("# BEGIN testing owl_history\n");
    815   owl_history_init(&h);
    816 
    817   /* Operations on empty history. */
    818   FAIL_UNLESS("prev NULL", owl_history_get_prev(&h) == NULL);
    819   FAIL_UNLESS("next NULL", owl_history_get_next(&h) == NULL);
    820   FAIL_UNLESS("untouched", !owl_history_is_touched(&h));
    821 
    822   /* Insert a few records. */
    823   owl_history_store(&h, "a", false);
    824   owl_history_store(&h, "b", false);
    825   owl_history_store(&h, "c", false);
    826   owl_history_store(&h, "d", true);
    827 
    828   /* Walk up and down the history a bit. */
    829   FAIL_UNLESS("untouched", !owl_history_is_touched(&h));
    830   FAIL_UNLESS("prev c", strcmp(owl_history_get_prev(&h), "c") == 0);
    831   FAIL_UNLESS("touched", owl_history_is_touched(&h));
    832   FAIL_UNLESS("next d", strcmp(owl_history_get_next(&h), "d") == 0);
    833   FAIL_UNLESS("untouched", !owl_history_is_touched(&h));
    834   FAIL_UNLESS("next NULL", owl_history_get_next(&h) == NULL);
    835   FAIL_UNLESS("prev c", strcmp(owl_history_get_prev(&h), "c") == 0);
    836   FAIL_UNLESS("prev b", strcmp(owl_history_get_prev(&h), "b") == 0);
    837   FAIL_UNLESS("prev a", strcmp(owl_history_get_prev(&h), "a") == 0);
    838   FAIL_UNLESS("prev NULL", owl_history_get_prev(&h) == NULL);
    839 
    840   /* Now insert something. It should reset and blow away 'd'. */
    841   owl_history_store(&h, "e", false);
    842   FAIL_UNLESS("untouched", !owl_history_is_touched(&h));
    843   FAIL_UNLESS("next NULL", owl_history_get_next(&h) == NULL);
    844   FAIL_UNLESS("prev c", strcmp(owl_history_get_prev(&h), "c") == 0);
    845   FAIL_UNLESS("touched", owl_history_is_touched(&h));
    846   FAIL_UNLESS("next e", strcmp(owl_history_get_next(&h), "e") == 0);
    847   FAIL_UNLESS("untouched", !owl_history_is_touched(&h));
    848 
    849   /* Lines get de-duplicated on insert. */
    850   owl_history_store(&h, "e", false);
    851   owl_history_store(&h, "e", false);
    852   owl_history_store(&h, "e", false);
    853   FAIL_UNLESS("prev c", strcmp(owl_history_get_prev(&h), "c") == 0);
    854   FAIL_UNLESS("next e", strcmp(owl_history_get_next(&h), "e") == 0);
    855 
    856   /* But a partial is not deduplicated, as it'll go away soon. */
    857   owl_history_store(&h, "e", true);
    858   FAIL_UNLESS("prev e", strcmp(owl_history_get_prev(&h), "e") == 0);
    859   FAIL_UNLESS("prev c", strcmp(owl_history_get_prev(&h), "c") == 0);
    860   FAIL_UNLESS("next e", strcmp(owl_history_get_next(&h), "e") == 0);
    861   FAIL_UNLESS("next e", strcmp(owl_history_get_next(&h), "e") == 0);
    862 
    863   /* Reset moves to the front... */
    864   owl_history_store(&h, "f", true);
    865   FAIL_UNLESS("prev e", strcmp(owl_history_get_prev(&h), "e") == 0);
    866   FAIL_UNLESS("prev c", strcmp(owl_history_get_prev(&h), "c") == 0);
    867   owl_history_reset(&h);
    868   FAIL_UNLESS("untouched", !owl_history_is_touched(&h));
    869   /* ...and destroys any pending partial entry... */
    870   FAIL_UNLESS("prev c", strcmp(owl_history_get_prev(&h), "c") == 0);
    871   FAIL_UNLESS("prev b", strcmp(owl_history_get_prev(&h), "b") == 0);
    872   /* ...but not non-partial ones. */
    873   owl_history_reset(&h);
    874   FAIL_UNLESS("untouched", !owl_history_is_touched(&h));
    875 
    876   /* Finally, check we are bounded by OWL_HISTORYSIZE. */
    877   for (i = 0; i < OWL_HISTORYSIZE; i++) {
    878     char *string = g_strdup_printf("mango%d", i);
    879     owl_history_store(&h, string, false);
    880     g_free(string);
    881   }
    882   /* The OWL_HISTORYSIZE'th prev gets NULL. */
    883   for (i = OWL_HISTORYSIZE - 2; i >= 0; i--) {
    884     char *string = g_strdup_printf("mango%d", i);
    885     FAIL_UNLESS("prev mango_N", strcmp(owl_history_get_prev(&h), string) == 0);
    886     g_free(string);
    887   }
    888   FAIL_UNLESS("prev NULL", owl_history_get_prev(&h) == NULL);
    889 
    890   owl_history_cleanup(&h);
    891 
    892   printf("# END testing owl_history (%d failures)\n", numfailed);
    893   return numfailed;
    894 }
Note: See TracChangeset for help on using the changeset viewer.