You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by Vincent Hennebert <vi...@anyware-tech.com> on 2007/02/12 18:00:33 UTC

FO snippets for unit testing

Hi All,

I think the codebase is seriously lacking of unit tests, which makes
refactoring a bit hazardous. Of course there is the wonderful
layoutengine testsuite that allows to check if a XSL-FO file is rendered
as expected (BTW, I don't remember who introduced this feature, but a
huge thanks to them, that's very useful!), but this is already at a too
high level in that it tests the code in a whole.

What I need is the possibility of unit testing one class at a time like,
say, TableRowIterator. The constructor of this class takes a Table and a
ColumnSetup as arguments, so I have to create ones if I want to unit
test it. But that would be a pity to create the whole structure by hand
whereas there is already code somewhere that does it.

So my question is: is there a possibility of creating a tree of FObj
instances from a corresponding FO fragment, and use it to feed objects
from the layout engine in order to unit test them? It doesn't seem to be
the case currently, but how difficult would it be to extract that from
the current codebase?
Or is this feature already available and I totally missed it?

Any ideas, opinions, hints are welcome.

Thanks,
Vincent

Re: FO snippets for unit testing

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
On 13.02.2007 21:52:01 Simon Pepping wrote:
> On Tue, Feb 13, 2007 at 08:04:00PM +0100, Vincent Hennebert wrote:
> > Many thanks Andreas, that was enough to get me started!
> > I've just committed a first test case for tables. This is still very
> > rough, there's no testsuite, that won't be called by ant, but as long as
> > I can run the tests from Eclipse from time to time I'm happy.
> > 
> > Of course I'm open to any comments or suggestions.
> 
> Very efficient, very nice.

I agree. Good stuff.

> I think that eventually you should move the expectations into the test
> files, similarly to the layoutengine test files.

If that's possible. I'm not sure it's possible in this case.


Jeremias Maerki


Re: FO snippets for unit testing

Posted by Simon Pepping <sp...@leverkruid.eu>.
On Tue, Feb 13, 2007 at 08:04:00PM +0100, Vincent Hennebert wrote:
> Many thanks Andreas, that was enough to get me started!
> I've just committed a first test case for tables. This is still very
> rough, there's no testsuite, that won't be called by ant, but as long as
> I can run the tests from Eclipse from time to time I'm happy.
> 
> Of course I'm open to any comments or suggestions.

Very efficient, very nice.

I think that eventually you should move the expectations into the test
files, similarly to the layoutengine test files.

Simon

-- 
Simon Pepping
home page: http://www.leverkruid.eu

Re: FO snippets for unit testing

Posted by Vincent Hennebert <vi...@anyware-tech.com>.
Andreas L Delmelle a écrit :
> On Feb 12, 2007, at 20:02, Andreas L Delmelle wrote:
> 
>> On Feb 12, 2007, at 18:00, Vincent Hennebert wrote:
>>> So my question is: is there a possibility of creating a tree of FObj
>>> instances from a corresponding FO fragment, and use it to feed objects
>>> from the layout engine in order to unit test them? It doesn't seem to be
>>> the case currently, but how difficult would it be to extract that from
>>> the current codebase?
>>
>> The code that constructs a tree of FObjs is located in
>> fop.fo.FOTreeBuilder: catching SAX startElement() events and
>> constructing FONodes + trigger the creation of PropertyLists from the
>> Attributes.
>> Unfortunately, FOTreeBuilder currently only accommodates construction
>> of a complete FOTree, starting with the root.
>>
>> Once a sufficient part of the FOTree is available, the LayoutManagers
>> are created from the FO subtrees in the main loops of the
>> getNextKnuthElements() methods (getChildLM() -> getNextChildLMs()),
>> ultimately triggered by AreaTreeHandler.endPageSequence().
> 
> To elaborate a bit on ideas on how to extract/implement it:
> If all you need is
> a) a way to test simple documents (build a complete FOTree of them), and
> b) only need to control the instantiation of the LMs
> 
> then I guess you could create your own subclass of FOEventHandler, and
> catch the FO events as they occur. You could write a FOEventHandler that
> only handles table-related FOs in a document, and ignores all the
> others. They will still be created, by the FOTreeBuilder, though...
> Advantage is that the default AreaTreeHandler can quite easily be
> overridden/replaced by a custom one. (The RTFHandler is an example)
> 
> If you also need control over the FOTree creation, then you'll need a
> special FOSubTreeBuilder as well.

Many thanks Andreas, that was enough to get me started!
I've just committed a first test case for tables. This is still very
rough, there's no testsuite, that won't be called by ant, but as long as
I can run the tests from Eclipse from time to time I'm happy.

Of course I'm open to any comments or suggestions.

Cheers,
Vincent


Re: FO snippets for unit testing

Posted by Andreas L Delmelle <a_...@pandora.be>.
On Feb 12, 2007, at 20:02, Andreas L Delmelle wrote:

> On Feb 12, 2007, at 18:00, Vincent Hennebert wrote:
>> So my question is: is there a possibility of creating a tree of FObj
>> instances from a corresponding FO fragment, and use it to feed  
>> objects
>> from the layout engine in order to unit test them? It doesn't seem  
>> to be
>> the case currently, but how difficult would it be to extract that  
>> from
>> the current codebase?
>
> The code that constructs a tree of FObjs is located in  
> fop.fo.FOTreeBuilder: catching SAX startElement() events and  
> constructing FONodes + trigger the creation of PropertyLists from  
> the Attributes.
> Unfortunately, FOTreeBuilder currently only accommodates  
> construction of a complete FOTree, starting with the root.
>
> Once a sufficient part of the FOTree is available, the  
> LayoutManagers are created from the FO subtrees in the main loops  
> of the getNextKnuthElements() methods (getChildLM() ->  
> getNextChildLMs()), ultimately triggered by  
> AreaTreeHandler.endPageSequence().

To elaborate a bit on ideas on how to extract/implement it:
If all you need is
a) a way to test simple documents (build a complete FOTree of them), and
b) only need to control the instantiation of the LMs

then I guess you could create your own subclass of FOEventHandler,  
and catch the FO events as they occur. You could write a  
FOEventHandler that only handles table-related FOs in a document, and  
ignores all the others. They will still be created, by the  
FOTreeBuilder, though...
Advantage is that the default AreaTreeHandler can quite easily be  
overridden/replaced by a custom one. (The RTFHandler is an example)

If you also need control over the FOTree creation, then you'll need a  
special FOSubTreeBuilder as well.

Cheers,

Andreas

Re: FO snippets for unit testing

Posted by Andreas L Delmelle <a_...@pandora.be>.
On Feb 12, 2007, at 18:00, Vincent Hennebert wrote:

Hi Vincent,

> I think the codebase is seriously lacking of unit tests, which makes
> refactoring a bit hazardous. Of course there is the wonderful
> layoutengine testsuite that allows to check if a XSL-FO file is  
> rendered
> as expected (BTW, I don't remember who introduced this feature, but a
> huge thanks to them, that's very useful!)

Virtually all thanks go to Jeremias here, if I remember correctly.

> , but this is already at a too
> high level in that it tests the code in a whole.
>
> What I need is the possibility of unit testing one class at a time  
> like,
> say, TableRowIterator. The constructor of this class takes a Table  
> and a
> ColumnSetup as arguments, so I have to create ones if I want to unit
> test it. But that would be a pity to create the whole structure by  
> hand
> whereas there is already code somewhere that does it.

> So my question is: is there a possibility of creating a tree of FObj
> instances from a corresponding FO fragment, and use it to feed objects
> from the layout engine in order to unit test them? It doesn't seem  
> to be
> the case currently, but how difficult would it be to extract that from
> the current codebase?

The code that constructs a tree of FObjs is located in  
fop.fo.FOTreeBuilder: catching SAX startElement() events and  
constructing FONodes + trigger the creation of PropertyLists from the  
Attributes.
Unfortunately, FOTreeBuilder currently only accommodates construction  
of a complete FOTree, starting with the root.

Once a sufficient part of the FOTree is available, the LayoutManagers  
are created from the FO subtrees in the main loops of the  
getNextKnuthElements() methods (getChildLM() -> getNextChildLMs()),  
ultimately triggered by AreaTreeHandler.endPageSequence().

> Or is this feature already available and I totally missed it?

Nope, it's not available, but it would be beneficial either way, I  
think, to teach FOP to render fragments instead of complete trees  
(using something as a default layout-master-set?)


Cheers,

Andreas