[cairo] Unit testing? (PDF)

Ian Britten britten at caris.com
Fri May 22 09:46:19 PDT 2009


Hi all,
I'm looking to write some unit tests for my Cairo code (Producing PDF)
and was wondering if anyone had any suggestions/input?

As is usual for testing, you generate your current output and compare
it against a known-correct master version, looking for differences.

- I'm assuming I can't just do a binary comparison of the two PDF
   files, eh?  I'm not familiar with the PDF file format, and a lot of
   it looks like it may be binary.  However, I suspect there's meta
   data in there (eg: creation date) that would interfere with a
   straight file comparison.
- Similarly, from looking at the PDFs generated from Cairo, I don't
   think any sort of selective line-by-line comparison would be
   appropriate, would it?
- One possible approach might be to rasterize the files (somehow) and
   compare the pixels (somehow).  This might get past the meta-data
   issue, but introduces a rasterization step that might trigger false
   differences.  Also, I don't know how fast that might be.
- I came across http://www.cairographics.org/renderpdf/, which seems
   interesting.  If I could load the PDF file back into a PDF Surface,
   is there anything in Cairo that I could use?  I didn't see a way
   to test if two Surfaces are "the same", but maybe there is something
   like that somewhere?
- Given that the Cairo unit tests basically just:
        printf("Please check %s to ensure it looks/prints correctly")
   I'm guessing there may not be an easy way to do this.  :(
   Is there a non-easy way?  :P

Many thanks for any input, pointers, suggestions, etc!
Ian


More information about the cairo mailing list