1 /* AbiWord
2  * Copyright (C) 1998 AbiSource, Inc.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301 USA.
18  */
19 
20 
21 #ifdef PT_TEST
22 #include <stdio.h>
23 #include "ut_types.h"
24 #include "ut_misc.h"
25 #include "ut_assert.h"
26 #include "ut_test.h"
27 #include "pt_PieceTable.h"
28 #include "pf_Frag.h"
29 #include "pf_Frag_Strux.h"
30 #include "pf_Frag_Strux_Block.h"
31 #include "pf_Frag_Strux_Section.h"
32 #include "pf_Frag_Text.h"
33 #include "pf_Fragments.h"
34 
35 /*****************************************************************/
36 /*****************************************************************/
37 
__test_VerifyCoalescedFrags(FILE * fp) const38 UT_TestStatus pt_PieceTable::__test_VerifyCoalescedFrags(FILE * fp) const
39 {
40 	// Test code to verify that all fragments are properly coalesced.
41 
42 	fprintf(fp,"__test_VerifyCoalescedFrags: beginning....\n");
43 
44 	UT_TestStatus status = UT_Test_Pass;
45 
46 	for (pf_Frag * pf=m_fragments.getFirst(); (pf); pf=pf->getNext())
47 	{
48 		if (   (pf->getType() == pf_Frag::PFT_Text)
49 			&& (pf->getNext())
50 			&& (pf->getNext()->getType() == pf_Frag::PFT_Text))
51 		{
52 			pf_Frag_Text * pft1 = static_cast<pf_Frag_Text *>(pf);
53 			pf_Frag_Text * pft2 = static_cast<pf_Frag_Text *>(pf->getNext());
54 			if (   (pft1->getIndexAP() == pft2->getIndexAP())
55 				&& (m_varset.isContiguous(pft1->getBufIndex(),
56 										  pft1->getLength(),
57 										  pft2->getBufIndex())))
58 			{
59 				fprintf(fp,"__test_VerifyCoalescedFrags: uncoalesced frags found: p1[%p] len[%ld] p2[%p]\n",
60 						(void*)pft1,(long)pft1->getLength(),(void*)pft2);
61 				pft1->__dump(fp);
62 				pft2->__dump(fp);
63 				status = UT_Test_Fail;
64 			}
65 		}
66 	}
67 
68 	fprintf(fp,"__test_VerifyCoalescedFrags: status[%s]\n",UT_TestStatus_GetMessage(status));
69 	return status;
70 }
71 
__dump(FILE * fp) const72 void pt_PieceTable::__dump(FILE * fp) const
73 {
74 	// dump the piece table.
75 
76 	fprintf(fp,"  PieceTable: State %d\n",(int)m_pts);
77 	fprintf(fp,"  PieceTable: Fragments:\n");
78 
79 	m_fragments.__dump(fp);
80 }
81 
82 #endif /* PT_TEST */
83