Changes in / [16ce7a4:650fb2c]
Legend:
- Unmodified
- Added
- Removed
-
history.c
r25891a8 r95b52d1 6 6 h->cur = h->hist.tail; /* current position in history */ 7 7 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);14 8 } 15 9 … … 46 40 47 41 /* 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) 49 43 g_free(g_queue_pop_head(&h->hist)); 50 44 -
tester.c
r25891a8 rce68f23 23 23 int owl_fmtext_regtest(void); 24 24 int owl_smartfilter_regtest(void); 25 int owl_history_regtest(void);26 25 27 26 extern void owl_perl_xs_init(pTHX); … … 113 112 numfailures += owl_fmtext_regtest(); 114 113 numfailures += owl_smartfilter_regtest(); 115 numfailures += owl_history_regtest();116 114 if (numfailures) { 117 115 fprintf(stderr, "# *** WARNING: %d failures total\n", numfailures); … … 805 803 return numfailed; 806 804 } 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.