[cairo] Unit testing? (PDF)

Chris Wilson chris at chris-wilson.co.uk
Fri May 22 11:42:38 PDT 2009


On Fri, 2009-05-22 at 15:07 -0300, Ian Britten wrote:
> Hun?  Not use cairo?  Maybe I wasn't clear (Or misunderstood you)...
> I already have a large suite of tests for our various parts, including
> the data retrieval, rendering engine, etc.  We render to various
> abstract outputs (Canvases), now including Cairo.  As such, it is the
> bridge code between our rendering code and Cairo that I'm looking to
> test:
>   - Did the transformations get set up in Cairo correctly?
>   - Did the cap style get correctly set in Cairo for the line?
>   - etc, etc.
> 
> Hmmm...  I was just thinking that maybe what I want for general testing
> of this code is some sort of mock/proxy/testing Surface - Is a Surface
> hard to make?

That is what I thought you would require as well. Your unit test should
be asking whether a cairo_set_line_cap(X) was emitted, rather than did
Cairo transform it into this pdf.

A raster backend is quite simple to write, but a vector surface is more
subtle. The difficultly here is that the internal API is significantly
different from the public API - which may or may not make the task
easier.

A true logging surface is another wishlist item. This use-case is
slightly different than the one I envisaged for the CairoScript backend,
but it may be close enough to be useful. [The goal of that backend is to
create a sequence of cairo user calls that recreates the input.]

> Or, is that what cairo-trace is about?  Are there any details around
> about it?  I'm not familiar with it... (And, is it in 1.8.x?)

cairo-trace is an LD_PRELOAD interception library that captures all
calls to cairo and generates a replayed CairoScript file. It is only
available in the development tree. It's format is a condense,
human-readable variant of PostScript. For your purposes, I think an even
more verbose log of cairo calls would be more useful. libcairowrap
[http://people.freedesktop.org/~jrmuizel/libcairowrap-0.1.tar.gz] is a
little old (it may be missing a few calls now) but it may be a suitable
starting point.
-ickle



More information about the cairo mailing list