Changeset 6772d19


Ignore:
Timestamp:
Jul 31, 2010, 7:11:42 PM (14 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, release-1.7, release-1.8, release-1.9
Children:
e0e0e5a
Parents:
35a30f9
git-author:
David Benjamin <davidben@mit.edu> (07/25/10 17:28:27)
git-committer:
David Benjamin <davidben@mit.edu> (07/31/10 19:11:42)
Message:
Add a test case for owl_fmtext with two failures

When appending text, we get the textlen wrong. We also fail to correctly
consider attributes in owl_fmtext_num_lines. This also adds tests for
owl_fmtext_truncate_cols and owl_fmtext_truncate_lines as they are
finicky.
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • fmtext.c

    r423adcb r6772d19  
    521521}
    522522
     523int owl_fmtext_num_bytes(const owl_fmtext *f)
     524{
     525  return(f->textlen);
     526}
     527
    523528/* set the charater at 'index' to be 'char'.  If index is out of
    524529 * bounds don't do anything. If c or char at index is not ASCII, don't
  • tester.c

    r35a30f9 r6772d19  
    2121int owl_obarray_regtest(void);
    2222int owl_editwin_regtest(void);
     23int owl_fmtext_regtest(void);
    2324
    2425extern void owl_perl_xs_init(pTHX);
     
    106107  numfailures += owl_filter_regtest();
    107108  numfailures += owl_editwin_regtest();
     109  numfailures += owl_fmtext_regtest();
    108110  if (numfailures) {
    109111      fprintf(stderr, "# *** WARNING: %d failures total\n", numfailures);
     
    407409  return numfailed;
    408410}
     411
     412int owl_fmtext_regtest(void) {
     413  int numfailed = 0;
     414  owl_fmtext fm1;
     415  owl_fmtext fm2;
     416  char *str;
     417
     418  printf("# BEGIN testing owl_fmtext\n");
     419
     420  owl_fmtext_init_null(&fm1);
     421  owl_fmtext_init_null(&fm2);
     422
     423  /* Verify text gets correctly appended. */
     424  owl_fmtext_append_normal(&fm1, "1234567898");
     425  owl_fmtext_append_fmtext(&fm2, &fm1);
     426  FAIL_UNLESS("string lengths correct",
     427              owl_fmtext_num_bytes(&fm2) == strlen(owl_fmtext_get_text(&fm2)));
     428
     429  /* Test owl_fmtext_num_lines. */
     430  owl_fmtext_clear(&fm1);
     431  FAIL_UNLESS("empty line correct", owl_fmtext_num_lines(&fm1) == 0);
     432  owl_fmtext_append_normal(&fm1, "12345\n67898");
     433  FAIL_UNLESS("trailing chars correct", owl_fmtext_num_lines(&fm1) == 2);
     434  owl_fmtext_append_normal(&fm1, "\n");
     435  FAIL_UNLESS("trailing newline correct", owl_fmtext_num_lines(&fm1) == 2);
     436  owl_fmtext_append_bold(&fm1, "");
     437  FAIL_UNLESS("trailing attributes correct", owl_fmtext_num_lines(&fm1) == 2);
     438
     439  /* Test owl_fmtext_truncate_lines */
     440  owl_fmtext_clear(&fm1);
     441  owl_fmtext_append_normal(&fm1, "0\n1\n2\n3\n4\n");
     442
     443  owl_fmtext_clear(&fm2);
     444  owl_fmtext_truncate_lines(&fm1, 1, 3, &fm2);
     445  str = owl_fmtext_print_plain(&fm2);
     446  FAIL_UNLESS("lines corrected truncated",
     447              str && !strcmp(str, "1\n2\n3\n"));
     448  owl_free(str);
     449
     450  owl_fmtext_clear(&fm2);
     451  owl_fmtext_truncate_lines(&fm1, 1, 5, &fm2);
     452  str = owl_fmtext_print_plain(&fm2);
     453  FAIL_UNLESS("lines corrected truncated",
     454              str && !strcmp(str, "1\n2\n3\n4\n"));
     455  owl_free(str);
     456
     457  /* Test owl_fmtext_truncate_cols. */
     458  owl_fmtext_clear(&fm1);
     459  owl_fmtext_append_normal(&fm1, "123456789012345\n");
     460  owl_fmtext_append_normal(&fm1, "123456789\n");
     461  owl_fmtext_append_normal(&fm1, "1234567890\n");
     462
     463  owl_fmtext_clear(&fm2);
     464  owl_fmtext_truncate_cols(&fm1, 4, 9, &fm2);
     465  str = owl_fmtext_print_plain(&fm2);
     466  FAIL_UNLESS("columns correctly truncated",
     467              str && !strcmp(str, "567890"
     468                                  "56789\n"
     469                                  "567890"));
     470  owl_free(str);
     471
     472  owl_fmtext_cleanup(&fm1);
     473  owl_fmtext_cleanup(&fm2);
     474
     475  printf("# END testing owl_fmtext (%d failures)\n", numfailed);
     476
     477  return numfailed;
     478}
Note: See TracChangeset for help on using the changeset viewer.