[2554] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[PATCH 2/4] Add a test case for owl_fmtext with two failures

daemon@ATHENA.MIT.EDU (David Benjamin)
Sun Jul 25 17:59:15 2010

From: David Benjamin <davidben@MIT.EDU>
To: barnowl-dev@mit.edu
Date: Sun, 25 Jul 2010 14:56:58 -0700
In-Reply-To: <1280095020-26263-1-git-send-email-davidben@mit.edu>

When appending text, we get the textlen wrong. We also fail to correctly
consider attributes in owl_fmtext_num_lines.
---
 fmtext.c |    5 +++++
 tester.c |   33 +++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/fmtext.c b/fmtext.c
index 67c0643..f811e9d 100644
--- a/fmtext.c
+++ b/fmtext.c
@@ -520,6 +520,11 @@ const char *owl_fmtext_get_text(const owl_fmtext *f)
   return(f->textbuff);
 }
 
+int owl_fmtext_get_num_bytes(const owl_fmtext *f)
+{
+  return(f->textlen);
+}
+
 /* set the charater at 'index' to be 'char'.  If index is out of
  * bounds don't do anything. If c or char at index is not ASCII, don't
  * do anything because it's not UTF-8 safe. */
diff --git a/tester.c b/tester.c
index bb6ee48..842fbcb 100644
--- a/tester.c
+++ b/tester.c
@@ -20,6 +20,7 @@ int owl_variable_regtest(void);
 int owl_filter_regtest(void);
 int owl_obarray_regtest(void);
 int owl_editwin_regtest(void);
+int owl_fmtext_regtest(void);
 
 extern void owl_perl_xs_init(pTHX);
 
@@ -105,6 +106,7 @@ int owl_regtest(void) {
   numfailures += owl_variable_regtest();
   numfailures += owl_filter_regtest();
   numfailures += owl_editwin_regtest();
+  numfailures += owl_fmtext_regtest();
   if (numfailures) {
       fprintf(stderr, "# *** WARNING: %d failures total\n", numfailures);
   }
@@ -406,3 +408,34 @@ int owl_editwin_regtest(void) {
 
   return numfailed;
 }
+
+int owl_fmtext_regtest(void) {
+  int numfailed = 0;
+  owl_fmtext fm1;
+  owl_fmtext fm2;
+
+  printf("# BEGIN testing owl_fmtext\n");
+
+  owl_fmtext_init_null(&fm1);
+  owl_fmtext_init_null(&fm2);
+
+  /* Verify text gets correctly appended. */
+  owl_fmtext_append_normal(&fm1, "1234567898");
+  owl_fmtext_append_fmtext(&fm2, &fm1);
+  FAIL_UNLESS("string lengths correct",
+              owl_fmtext_get_num_bytes(&fm2) == strlen(owl_fmtext_get_text(&fm2)));
+
+  /* Test owl_fmtext_num_lines */
+  owl_fmtext_clear(&fm1);
+  FAIL_UNLESS("empty line correct", owl_fmtext_num_lines(&fm1) == 0);
+  owl_fmtext_append_normal(&fm1, "12345\n67898");
+  FAIL_UNLESS("trailing chars correct", owl_fmtext_num_lines(&fm1) == 2);
+  owl_fmtext_append_normal(&fm1, "\n");
+  FAIL_UNLESS("trailing newline correct", owl_fmtext_num_lines(&fm1) == 2);
+  owl_fmtext_append_bold(&fm1, "");
+  FAIL_UNLESS("trailing attributes correct", owl_fmtext_num_lines(&fm1) == 2);
+
+  printf("# END testing owl_fmtext (%d failures)\n", numfailed);
+
+  return numfailed;
+}
-- 
1.7.2.rc2.1.gaace1


home help back first fref pref prev next nref lref last post