- Timestamp:
- Jun 25, 2011, 6:42:19 AM (13 years ago)
- Branches:
- master, release-1.10, release-1.8, release-1.9
- Children:
- b2bfe1f, af562f5, b8a3e00, e1d3607, 16ce7a4
- Parents:
- 650fb2c
- git-author:
- David Benjamin <davidben@mit.edu> (06/25/11 04:32:18)
- git-committer:
- David Benjamin <davidben@mit.edu> (06/25/11 06:42:19)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tester.c
rce68f23 r25891a8 23 23 int owl_fmtext_regtest(void); 24 24 int owl_smartfilter_regtest(void); 25 int owl_history_regtest(void); 25 26 26 27 extern void owl_perl_xs_init(pTHX); … … 112 113 numfailures += owl_fmtext_regtest(); 113 114 numfailures += owl_smartfilter_regtest(); 115 numfailures += owl_history_regtest(); 114 116 if (numfailures) { 115 117 fprintf(stderr, "# *** WARNING: %d failures total\n", numfailures); … … 803 805 return numfailed; 804 806 } 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.