[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 03/03: Various fixes:
From: |
Bertrand Garrigues |
Subject: |
[groff] 03/03: Various fixes: |
Date: |
Sat, 8 Jul 2023 06:50:01 -0400 (EDT) |
bgarrigues pushed a commit to branch format_knuth_plass2
in repository groff.
commit 90d46d0a1b0b34c2894f93abdd2111edbe08e690
Author: Bertrand Garrigues <bertrand.garrigues@laposte.net>
AuthorDate: Sun Jul 2 19:51:35 2023 +0200
Various fixes:
* Fix conflicts after rebase
* Fix crashes seen on printing paragraph when the algorithm failed to
format the paragraph
Also remove trailing whitespaces
---
configure.ac | 22 +++++++-----
src/roff/troff/paragraph.cpp | 84 +++++++++++++++++++++++++-------------------
src/roff/troff/paragraph.h | 6 ++--
src/roff/troff/paragraph_l.h | 12 +++----
test/test.am | 5 +--
test/test_paragraph.cpp | 52 ++++++++++++++-------------
test/utest_list.cpp | 36 +++++++++----------
7 files changed, 117 insertions(+), 100 deletions(-)
diff --git a/configure.ac b/configure.ac
index a6ce41bbb..f4545f877 100644
--- a/configure.ac
+++ b/configure.ac
@@ -80,9 +80,6 @@ GROFF_PROG_XPMTOPPM
PKG_PROG_PKG_CONFIG
GROFF_UCHARDET
-# check for pkgconfig
-PKG_PROG_PKG_CONFIG
-
# use a dummy substitution if no csh hack is necessary to avoid errors
# with non-GNU sed programs
GROFF_CSH_HACK([SH_SCRIPT_SED_CMD='1s/.*/:/'],
@@ -181,10 +178,6 @@ GROFF_GHOSTSCRIPT_VERSION_CHECK
gl_GLIBC21
gl_LOCALCHARSET
-# checks for presence of URW fonts (requires ghostscript, which is
-# checked in GROFF_HTML_PROGRAMS
-GROFF_URW_FONTS
-
# Check for cppunit, unit test framework
PKG_CHECK_MODULES([CPPUNIT], [cppunit >= 1.9.6], have_cppunit=yes,
have_cppunit=no)
AM_CONDITIONAL([BUILD_UNIT_TESTS], [test "$have_cppunit" = "yes" ])
@@ -237,9 +230,20 @@ then
fi
fi
echo "\
- URW fonts for pdf : $groff_have_urw_fonts
- Use uchardet library for preconv: $groff_have_uchardet
+ C++ compiler and options : $CXX $CXXFLAGS $CPPFLAGS
+ use libgroff's memory allocator : $groff_use_own_allocator
+ C compiler and options : $CC $CFLAGS $CPPFLAGS
+ Perl interpreter version : $perl_version
Unit tests build : $have_cppunit"
+if test "$groff_no_x" = yes
+then
+ echo "\
+ X11 support : disabled"
+else
+ echo "\
+ X11 support : enabled
+ X11 app defaults directory : $appdefdir"
+fi
echo "\
'groff -l' uses print spooler : $groff_have_spooler
use URW fonts for PDF output : $groff_have_urw_fonts"
diff --git a/src/roff/troff/paragraph.cpp b/src/roff/troff/paragraph.cpp
index eeb5932f4..38da8ec7e 100644
--- a/src/roff/troff/paragraph.cpp
+++ b/src/roff/troff/paragraph.cpp
@@ -139,7 +139,7 @@ box_item::box_item(paragraph_word *word)
: item()
{
char sz[STRING_MAX_SIZE] = "";
-
+
word_ = word;
stretchability_ = 0;
shrinkability_ = 0;
@@ -257,19 +257,19 @@ int
glue_item::sprint_info(char *str)
{
char tmp[32];
-
+
if (stretchability_ >= PLUS_INFINITY)
sprintf(tmp, "infinity");
else
sprintf(tmp, "%u", stretchability_);
-
+
return sprintf(str, "glue width:%u strecth:%s shrink:%u",
width_, tmp, shrinkability_);
}
/**
* Class penalty
- *
+ *
*/
penalty_item::penalty_item(int penalty,
bool flag,
@@ -345,7 +345,7 @@ penalty_item::sprint_info(char *str)
sprintf(tmp, "-infinity");
else
sprintf(tmp, "%d", penalty_);
-
+
return sprintf(str,
"penalty width:%u value:%s flag:%d",
width_,
@@ -408,7 +408,7 @@ breakpoint::get_total_width_after()
* incorrect. */
if (break_item_ != NULL && break_item_->get_penalty() == 0)
total_width_after += break_item_->get_width();
-
+
return total_width_after;
}
@@ -419,7 +419,7 @@ breakpoint::get_total_stretch_after()
if (break_item_ != NULL)
total_stretch_after += break_item_->get_stretchability();
-
+
return total_stretch_after;
}
@@ -430,7 +430,7 @@ breakpoint::get_total_shrink_after()
if (break_item_ != NULL)
total_shrink_after += break_item_->get_shrinkability();
-
+
return total_shrink_after;
}
@@ -444,7 +444,7 @@ item *
breakpoint::get_previous_box()
{
item *i = break_item_;
-
+
while (i != NULL) {
if (i->is_box())
break;
@@ -531,7 +531,7 @@ breakpoint::compute_adjust_ratio(int desired_line_length,
breakpoint_error("candidate item null");
return -1;
}
-
+
line_length = total_width - get_total_width_after();
#if TRACE_BREAKPOINT >= LEVEL_DEBUG
char tmp[256];
@@ -552,7 +552,7 @@ breakpoint::compute_adjust_ratio(int desired_line_length,
if (candidate->get_penalty() > 0) {
line_length += candidate->get_width();
}
-
+
if (line_length < desired_line_length) {
line_stretch = total_stretch - get_total_stretch_after();
breakpoint_debug(" line_stretch %u", line_stretch);
@@ -570,7 +570,7 @@ breakpoint::compute_adjust_ratio(int desired_line_length,
else
ratio = FLT_MIN;
}
-
+
if (ratio >= PLUS_INFINITY)
breakpoint_debug(" ratio: infinity");
else
@@ -643,7 +643,7 @@ unsigned int
breakpoint::compute_adj_extra_demerits(fitness_class_t candidate_fitness)
{
unsigned int extra_demerits = 0;
-
+
switch (candidate_fitness) {
case FITNESS_CLASS_TIGHT:
if (fitness_class_ >= FITNESS_CLASS_LOOSE)
@@ -661,7 +661,7 @@ breakpoint::compute_adj_extra_demerits(fitness_class_t
candidate_fitness)
if (fitness_class_ <= FITNESS_CLASS_NORMAL)
extra_demerits = PARAGRAPH_DEFAULT_NON_ADJACENT_FITNESS_DEMERITS;
default:
- break; //NOTE: intial breakpoint has a FITNESS_CLASS of MAX,
+ break; //NOTE: intial breakpoint has a FITNESS_CLASS of MAX,
}
return extra_demerits;
@@ -672,7 +672,7 @@ fitness_class_t
breakpoint::compute_fitness_class(float adjust_ratio)
{
fitness_class_t fitness_class;
-
+
if (adjust_ratio < (float) -0.5)
fitness_class = FITNESS_CLASS_TIGHT;
else if (adjust_ratio <= (float) 0.5)
@@ -699,7 +699,7 @@ breakpoint::sprint(char *str)
char tmp[32];
sprintf(tmp, " (penalty: %d)", break_item_->get_penalty());
strcat(str, tmp);
- }
+ }
} else {
res = sprintf(str, "initial breakpoint");
}
@@ -718,7 +718,7 @@ breakpoint::print_breakpoint_info()
if (sz_print_ == NULL) {
sz_print_ = (char *)calloc(512, sizeof(char));
-
+
if (break_item_ != NULL)
{
box = get_previous_box();
@@ -726,7 +726,7 @@ breakpoint::print_breakpoint_info()
} else {
sprintf(tmp, "initial breakpoint");
}
-
+
if (previous_best_ != NULL) {
previous_breakpoint_box = previous_best_->get_previous_box();
if (previous_breakpoint_box != NULL)
@@ -747,7 +747,7 @@ breakpoint::print_breakpoint_info()
sprintf(sz_print_, "Initial breakpoint\n");
}
}
-
+
return sz_print_;
}
@@ -764,7 +764,7 @@ paragraph::paragraph()
use_old_demerits_formula_ = false;
use_fitness_class_ = true;
hyphenation_penalty_ = PARAGRAPH_DEFAULT_HYPHENATION_PENALTY;
- INIT_LIST_HEAD(&item_list_head_, NULL);
+ INIT_LIST_HEAD(&item_list_head_, NULL);
INIT_LIST_HEAD(&active_breaks_list_head_, NULL);
INIT_LIST_HEAD(&passive_breaks_list_head_, NULL);
array_best_breaks_ = NULL;
@@ -875,7 +875,7 @@ paragraph::finish()
penalty_item *disallowed_break_penalty = new penalty_item(PLUS_INFINITY,
false);
glue_item *finishing_glue = new glue_item(0, PLUS_INFINITY, 0);
penalty_item *forced_break_penalty = new penalty_item(MINUS_INFINITY, false);
-
+
/* FIXME we assume here that we always finish with glue so we always remove
* it. This should be more robust. */
last_glue = list_entry(item_list_head_.prev, glue_item);
@@ -898,7 +898,7 @@ paragraph::deactivate_breakpoint(breakpoint *active)
active->sprint(str);
paragraph_debug(" deactivating '%s'", str);
#endif
-
+
list_del_init(&active->list_);
list_add_tail(&active->list_, &passive_breaks_list_head_);
}
@@ -912,13 +912,13 @@ paragraph::record_feasible_break(breakpoint *active,
active->sprint(str);
paragraph_debug(" record feasible break '%s'", str);
#endif
-
+
candidate->set_previous_best(active);
if (list_empty(&candidate->list_))
list_add_tail(&candidate->list_, &active_breaks_list_head_);
}
-/*
+/*
* Format the paragraph with Knuth-Plass algorithm. Algorithm general outline:
for (all items 'b' of the paragraph) {
@@ -991,7 +991,7 @@ paragraph::format_knuth_plass(float tolerance,
tab_total_best_demerits[k] = PLUS_INFINITY;
tab_ajust_ratio[k] = PLUS_INFINITY;
}
-
+
/* Check the candidate breakpoint against each active breakpoint */
list_for_each_entry_safe(
active, n, &active_breaks_list_head_, list_, breakpoint) {
@@ -1016,7 +1016,7 @@ paragraph::format_knuth_plass(float tolerance,
demerits +=
active->compute_adj_extra_demerits(fitness_class);
}
-
+
#if TRACE_PARAGRAPH >= LEVEL_INFO
paragraph_info(" From %s to %s:", tmp1, tmp);
paragraph_info(" ratio : %.3f", adjust_ratio);
@@ -1041,7 +1041,7 @@ paragraph::format_knuth_plass(float tolerance,
tab_best_previous[fitness_class]);
}
}
-
+
if (min_total_best_demerits < PLUS_INFINITY) {
for (k = 0;
k < n_fitness_class;
@@ -1069,7 +1069,7 @@ paragraph::format_knuth_plass(float tolerance,
/* No more active breakpoint, leave with error */
if (list_empty(&active_breaks_list_head_)) {
- paragraph_error("Could nor format paragraph");
+ paragraph_error("Could not format paragraph");
error_item_ = k_item;
break;
}
@@ -1087,12 +1087,16 @@ paragraph::format_knuth_plass(float tolerance,
active, n, &active_breaks_list_head_, list_, breakpoint) {
deactivate_breakpoint(active);
}
-
+
/* Create the list of best breakpoints by starting by the end of the passive
* list */
initial_breakpoint = list_entry(passive_breaks_list_head_.next, breakpoint);
n = list_entry(passive_breaks_list_head_.prev, breakpoint);
number_lines_ = n->get_line_number();
+ if (number_lines_ == 0) {
+ paragraph_error("Could not format paragraph");
+ return -1;
+ }
array_best_breaks_ = (breakpoint **)calloc(number_lines_,
sizeof(breakpoint *));
k = 0;
@@ -1127,7 +1131,7 @@ paragraph::write_text(paragraph_writer_interface *pwi,
int *number_lines)
float ratio;
float space_width;
paragraph_word *word;
-
+
if (pwi == NULL) {
paragraph_error("Incorrect input");
res = -1;
@@ -1135,7 +1139,10 @@ paragraph::write_text(paragraph_writer_interface *pwi,
int *number_lines)
*number_lines = 0;
goto end;
}
-
+ if (array_best_breaks_ == NULL) {
+ res = -1;
+ goto end;
+ }
k = 0;
j_current_line = 1;
next_best_breakpoint = array_best_breaks_[k];
@@ -1147,7 +1154,7 @@ paragraph::write_text(paragraph_writer_interface *pwi,
int *number_lines)
if (next_best_breakpoint && pos == next_best_breakpoint->get_item()) {
word = pos->get_word();
if (word != NULL) // case of a hyphen
- pwi->write_word_cbk(word);
+ pwi->write_word_cbk(word);
pwi->break_here_cbk(j_current_line);
j_current_line++;
if (k < number_lines_ - 1) {
@@ -1236,7 +1243,7 @@ paragraph::get_total_demerits(int line_number)
void paragraph::print_breakpoints()
{
breakpoint *pos;
-
+
list_for_each_entry(pos, &passive_breaks_list_head_, list_, breakpoint) {
printf("%s", pos->print_breakpoint_info());
}
@@ -1317,7 +1324,7 @@ paragraph_printer::write_space_cbk(float space_width)
strcat(tab_lines_[current_index_], " ");
tab_marks_[current_index_][size_to_print_] = ' ';
size_to_print_++;
-
+
return 0;
}
@@ -1327,7 +1334,7 @@ paragraph_printer::break_here_cbk(int line_number)
if (size_to_print_ > max_line_length_)
max_line_length_ = size_to_print_;
new_line();
-
+
return 0;
}
@@ -1339,8 +1346,10 @@ paragraph_printer::print()
int k, res;
int column1, column2, column3;
int number_lines = 0;
-
+
res = par_->write_text(this, &number_lines);
+ if (res != 0)
+ return res;
first_column_width = printf("Number of lines: %d",
par_->get_number_of_lines());
first_column_width += printf("%*s",
@@ -1368,7 +1377,8 @@ paragraph_printer::print()
* the lines of formatted the paragraph */
if (res != 0) {
printf("\nCould not finish the formatting after line:\n\n");
- printf("%s\n", tab_lines_[number_lines]);
+ if (tab_lines_[number_lines] != NULL)
+ printf("%s\n", tab_lines_[number_lines]);
}
return 0;
}
diff --git a/src/roff/troff/paragraph.h b/src/roff/troff/paragraph.h
index ddf5f2fe7..9a105e2f0 100644
--- a/src/roff/troff/paragraph.h
+++ b/src/roff/troff/paragraph.h
@@ -56,7 +56,7 @@ class paragraph {
breakpoint **array_best_breaks_;
int number_lines_;
item *error_item_; // last item before exiting in error
-
+
public:
paragraph();
~paragraph();
@@ -64,7 +64,7 @@ public:
void config_use_old_demerits_formula();
void config_no_fitness_class();
void config_hyphenation_penalty(unsigned int value);
-
+
// To build the paragraph
// TODO: enable to add a custom item
void add_box(paragraph_word *word);
@@ -96,7 +96,7 @@ class paragraph_printer : public paragraph_writer_interface {
int current_index_;
breakpoint *next_feasible_breakpoint_;
void new_line(void);
-
+
public:
paragraph_printer(paragraph *par);
~paragraph_printer();
diff --git a/src/roff/troff/paragraph_l.h b/src/roff/troff/paragraph_l.h
index 5eb98b2ee..c988432c1 100644
--- a/src/roff/troff/paragraph_l.h
+++ b/src/roff/troff/paragraph_l.h
@@ -39,7 +39,7 @@ along with this program. If not, see
<http://www.gnu.org/licenses/>. */
* the paragraph).
*/
class item {
-
+
protected:
paragraph_word *word_;
unsigned int width_;
@@ -48,7 +48,7 @@ protected:
int penalty_;
bool flagged_penalty_;
bool is_breakpoint_;
-
+
public:
struct list_head list_;
item();
@@ -74,7 +74,7 @@ public:
* A box contains a word and is not a legal breakpoint.
*/
class box_item : public item {
-
+
public:
box_item(paragraph_word *word);
~box_item();
@@ -130,7 +130,7 @@ public:
/**
* Class breakpoint
- *
+ *
* A breakpoint:
* - points to an item (the place where to break)
* - points to the previous best breakpoint.
@@ -159,7 +159,7 @@ class breakpoint {
item *break_item_;
breakpoint *previous_best_;
char *sz_print_;
-
+
protected:
/* simple getters */
unsigned int get_total_width();
@@ -189,7 +189,7 @@ public:
void set_fitness_class(fitness_class_t fitness_class);
breakpoint *get_previous_best();
void set_previous_best(breakpoint *previous);
-
+
/* compute various values */
float compute_adjust_ratio(int desired_line_length,
unsigned int total_width,
diff --git a/test/test.am b/test/test.am
index 7fec26cd5..332ef1b26 100644
--- a/test/test.am
+++ b/test/test.am
@@ -20,7 +20,9 @@ if BUILD_UNIT_TESTS
TESTS += utest_list
check_PROGRAMS += utest_list
utest_list_SOURCES = test/utest_list.cpp
-utest_list_CXXFLAGS = $(CPPUNIT_CFLAGS) -I$(top_srcdir)/src/roff/troff
+# We leave the debugging flag and disable optimization as the code is
+# a bit experimental
+utest_list_CXXFLAGS = $(CPPUNIT_CFLAGS) -I$(top_srcdir)/src/roff/troff -ggdb
-O0
utest_list_LDFLAGS = $(CPPUNIT_LIBS)
endif
@@ -31,4 +33,3 @@ test_paragraph_SOURCES = \
test/test_paragraph.cpp
test_paragraph_CXXFLAGS = -I$(top_srcdir)/src/roff/troff
-
diff --git a/test/test_paragraph.cpp b/test/test_paragraph.cpp
index 2736c44fb..3467ae22e 100644
--- a/test/test_paragraph.cpp
+++ b/test/test_paragraph.cpp
@@ -153,7 +153,7 @@ ascii_paragraph_word::set_width(unsigned int width)
{
width_ = width;
}
-
+
unsigned int
ascii_paragraph_word::get_width()
{
@@ -167,7 +167,7 @@ ascii_paragraph_word::get_next_glue_values(unsigned int
*width,
{
size_t len;
char last_character;
-
+
if (sz_word_) {
len = strlen(sz_word_);
last_character = sz_word_[len - 1];
@@ -196,6 +196,8 @@ ascii_paragraph_word::get_next_glue_values(unsigned int
*width,
*shrinkability = 2;
break;
}
+
+ return 0;
}
int
@@ -239,7 +241,7 @@ text_loader::text_loader(char *text, const char *path)
char *c;
size_t text_size;
struct stat buf;
-
+
fp = fopen (path, "r");
if (fp == NULL) {
printf("Error:%s\n", strerror(errno));
@@ -267,16 +269,16 @@ hyphen_type_t
text_loader::simulate_hyphenate (const char *word, unsigned int
*first_part_len)
{
hyphen_type_t ret = OPTIONAL_HYPHEN;
-
+
if (word == NULL || first_part_len == NULL)
goto end;
-
+
if (strncmp(word, "lime-tree", 9) == 0) {
*first_part_len = 5;
ret = EXPLICIT_HYPHEN;
goto end;
}
-
+
if (strncmp(word, "wishing", 7) == 0)
*first_part_len = 4;
else if (strncmp(word, "daughters", 9) == 0)
@@ -330,7 +332,7 @@ text_loader::process_text(paragraph *par, bool
with_indentation)
indentation->set_width(18);
par->add_box(indentation);
}
-
+
/* Build the paragraph: for each word of 'text' we check if there is an
* explicit hyphen (here only the word "lime-tree"), otherwise we add an
* optional hyphen, and add the corresponding items. For example 'whenever'
@@ -389,7 +391,7 @@ struct expected_break_info {
} while(0)
class test_paragraph {
-
+
private:
text_loader *text_loader_;
int check_all_breakpoint(struct expected_break_info tab_expected[],
@@ -404,7 +406,7 @@ public:
int test11_original_example();
int test12_example_with_default_demerits_formula();
int test13_example_with_larger_tolerance();
-
+
void suite2_init();
int test21_hyphen_flagged_penalty();
@@ -515,7 +517,7 @@ test_paragraph::check_best_breakpoint(const
char*tab_expected[], paragraph *par)
}
}
- return res;
+ return res;
}
test_paragraph::~test_paragraph()
@@ -534,7 +536,7 @@ test_paragraph::~test_paragraph()
*/
void
test_paragraph::suite1_init()
-{
+{
text_loader *tl;
char text[] =
"In olden times when wishing still helped one, there lived a "
@@ -561,7 +563,7 @@ test_paragraph::test11_original_example()
int res = 0;
float expected_line_ratio[10] = {0.774, 0.179, 0.629, 0.545, 0.000,
0.079, 0.282, 0.294, 0.575, 0.000};
-
+
int n_lines;
int k;
float ratio;
@@ -650,7 +652,7 @@ test_paragraph::test11_original_example()
printf(" Checking all breakpoints demerits\n");
res += check_all_breakpoint(all_expected, par);
-
+
printf(" Checking the best breakpoints array\n");
res += check_best_breakpoint(best_expected, par);
printer = new paragraph_printer(par);
@@ -658,7 +660,7 @@ test_paragraph::test11_original_example()
delete printer;
PRINT_RESULT(res);
delete par;
-
+
return res;
}
@@ -692,16 +694,16 @@
test_paragraph::test12_example_with_default_demerits_formula()
FITNESS_CLASS_LOOSE,
FITNESS_CLASS_NORMAL
};
-
+
int k = 0;
-
+
printf("-- Test12...\n");
text_loader_->process_text(par, true);
par->format_knuth_plass();
-
+
printf(" Checking the best breakpoints array\n");
res += check_best_breakpoint(best_expected, par);
-
+
printf(" Checking the lines fitness class\n");
for (k = 0; k < 10; k++) {
fitness_class = par->get_fitness_class(k + 1);
@@ -737,14 +739,14 @@ test_paragraph::test13_example_with_larger_tolerance()
{ "her", 400, 3605 },
{ "thing.", 1, 3606 }
};
-
+
printf("-- Test13...\n");
text_loader_->process_text(par, true);
par->format_knuth_plass(10);
-
+
printf(" Checking the best breakpoints array\n");
res += check_best_breakpoint(best_expected, par);
-
+
PRINT_RESULT(res);
delete par;
@@ -764,7 +766,7 @@ test_paragraph::test13_example_with_larger_tolerance()
*/
void
test_paragraph::suite2_init()
-{
+{
text_loader *tl;
char text[] =
"AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAA hyphenationtest "
@@ -787,7 +789,7 @@ test_paragraph::test21_hyphen_flagged_penalty()
"test", //FIXME actually is should be hyphenationtest
"DDDDDDDDDD"
};
-
+
printf("-- Test21...\n");
text_loader_->process_text(par, false);
par->format_knuth_plass(2);
@@ -810,7 +812,7 @@ class 2; the class 2 is better but the class 1 should be
chosen because of the
first line. */
void
test_paragraph::suite3_init()
-{
+{
text_loader *tl;
char text[] =
"The first line's best break makes it very veryyyyyy tiiiiiiiiiiiiiight, "
@@ -837,7 +839,7 @@ test_paragraph::test31_fitness_class()
"0."
};
char word[256];
-
+
printf("-- Test31...\n");
text_loader_->process_text(par, false);
par->format_knuth_plass(2);
diff --git a/test/utest_list.cpp b/test/utest_list.cpp
index 20b5e33ff..5c89a9195 100644
--- a/test/utest_list.cpp
+++ b/test/utest_list.cpp
@@ -30,7 +30,7 @@ along with this program. If not, see
<http://www.gnu.org/licenses/>. */
class dummy {
public:
int data;
- struct list_head lh;
+ struct list_head lh;
dummy (int x)
{
data = x;
@@ -42,9 +42,9 @@ public:
return data;
}
};
-
+
class ListTest : public CppUnit::TestFixture {
-
+
CPPUNIT_TEST_SUITE(ListTest);
CPPUNIT_TEST(testAdd);
CPPUNIT_TEST(testAddTail);
@@ -53,7 +53,7 @@ class ListTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testForEachEntrySafe);
CPPUNIT_TEST(testForEachEntrySafe2);
CPPUNIT_TEST_SUITE_END();
-
+
private:
// Head of the list: we will add class dummy object to this list.
struct list_head head;
@@ -77,7 +77,7 @@ public:
a = new dummy(10);
b = new dummy(20);
c = new dummy(30);
-
+
list_add(&a->lh, &head);
CPPUNIT_ASSERT(head.next == &a->lh);
CPPUNIT_ASSERT(head.prev == &a->lh);
@@ -92,7 +92,7 @@ public:
list_del_init(&b->lh);
list_del_init(&c->lh);
CPPUNIT_ASSERT(list_empty(&head));
-
+
// Local teardown
INIT_LIST_HEAD(&head, NULL);
delete a;
@@ -106,7 +106,7 @@ public:
a = new dummy(10);
b = new dummy(20);
c = new dummy(30);
-
+
list_add_tail(&a->lh, &head);
CPPUNIT_ASSERT(head.next == &a->lh);
CPPUNIT_ASSERT(head.prev == &a->lh);
@@ -134,11 +134,11 @@ public:
{
dummy *pos;
int k = 10;
-
+
a = new dummy(10);
b = new dummy(20);
c = new dummy(30);
-
+
list_add_tail(&a->lh, &head);
list_add_tail(&b->lh, &head);
list_add_tail(&c->lh, &head);
@@ -146,9 +146,9 @@ public:
CPPUNIT_ASSERT(pos->data == k);
k+=10;
}
-
+
CPPUNIT_ASSERT(k == 40);
-
+
// Local teardown
INIT_LIST_HEAD(&head, NULL);
delete a;
@@ -161,24 +161,24 @@ public:
{
dummy *pos;
a = new dummy(10);
-
+
list_add_tail(&a->lh, &head);
list_for_each_entry(pos, &head, lh, dummy) {
CPPUNIT_ASSERT(pos->data == 10);
}
list_del_init(&a->lh);
-
+
list_for_each_entry(pos, &head, lh, dummy) {
// We should not enter this loop
CPPUNIT_ASSERT(false);
}
CPPUNIT_ASSERT(true);
-
+
// Local teardown
INIT_LIST_HEAD(&head, NULL);
delete a;
}
-
+
// Walk into the list, but this time we delete the dummy objects one by one,
// so we use list_for_each_entry_safe rather than list_for_each_entry
void testForEachEntrySafe()
@@ -199,7 +199,7 @@ public:
k+=10;
delete pos;
}
-
+
CPPUNIT_ASSERT(true);
// Local teardown
INIT_LIST_HEAD(&head, NULL);
@@ -238,9 +238,9 @@ int main(int argc, char **argv)
bool wasSuccessful;
CppUnit::TestFactoryRegistry ®istry =
CppUnit::TestFactoryRegistry::getRegistry();
-
+
runner.addTest(registry.makeTest());
wasSuccessful = runner.run("", false);
-
+
return !wasSuccessful;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 03/03: Various fixes:,
Bertrand Garrigues <=