From 7ca5011a76c7e32e51b2d5bf8d69deca159e13d4 Mon Sep 17 00:00:00 2001 From: Jonathon Jongsma Date: Mon, 8 Jun 2009 22:03:16 -0500 Subject: [PATCH] Revert "Inherit Cairo::Matrix from cairo_matrix_t" This reverts commit c0fab1927cab33f35d43b421c3464351bb8d8072. Conflicts: cairomm/matrix.h cairomm/types.h tests/Makefile.am tests/test-font-face.cc tests/test-matrix.cc --- ChangeLog | 17 ---- cairomm/Makefile.am | 4 +- cairomm/cairomm.h | 1 - cairomm/context.h | 1 - cairomm/matrix.cc | 91 ------------------ cairomm/matrix.h | 73 -------------- cairomm/scaledfont.cc | 8 +- cairomm/scaledfont.h | 1 - cairomm/types.h | 2 + tests/Makefile.am | 3 +- tests/test-font-face.cc | 238 +++++++++++++++++++++++++++++++++++++++++++++++ tests/test-matrix.cc | 87 ----------------- 12 files changed, 247 insertions(+), 279 deletions(-) delete mode 100644 cairomm/matrix.cc delete mode 100644 cairomm/matrix.h delete mode 100644 tests/test-matrix.cc diff --git a/ChangeLog b/ChangeLog index 16361be..571e9ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -400,23 +400,6 @@ 2008-09-12 Jonathon Jongsma - * cairomm/Makefile.am: - * cairomm/cairomm.h: - * cairomm/context.h: - * cairomm/matrix.cc: Added. - * cairomm/matrix.h: Added. - * cairomm/scaledfont.cc: - * cairomm/scaledfont.h: - * cairomm/types.h: - * tests/Makefile.am: - * tests/test-font-face.cc: - * tests/test-matrix.cc: Added. - Inherit Cairo::Matrix from cairo_matrix_t instead of just using a typedef. - cairo_matrix_* functions are now member functions of Matrix. This should - retain ABI compatibility while adding a more convenient C++ API. - -2008-09-12 Jonathon Jongsma - * cairomm/win32_surface.cc: * cairomm/win32_surface.h: add the Win32PrintingSurface type diff --git a/cairomm/Makefile.am b/cairomm/Makefile.am index 8af1caa..f697f87 100644 --- a/cairomm/Makefile.am +++ b/cairomm/Makefile.am @@ -2,9 +2,9 @@ SUBDIRS = INCLUDES = -I$(top_srcdir) @CAIROMM_CFLAGS@ -h_sources_public = cairomm.h context.h enums.h fontface.h fontoptions.h matrix.h path.h pattern.h quartz_font.h quartz_surface.h surface.h xlib_surface.h win32_font.h win32_surface.h exception.h refptr.h scaledfont.h types.h cairommconfig.h +h_sources_public = cairomm.h context.h enums.h fontface.h fontoptions.h path.h pattern.h quartz_font.h quartz_surface.h surface.h xlib_surface.h win32_font.h win32_surface.h exception.h refptr.h scaledfont.h types.h cairommconfig.h h_sources_private = private.h context_private.h -cc_sources = context.cc fontface.cc fontoptions.cc matrix.cc path.cc pattern.cc quartz_font.cc quartz_surface.cc surface.cc xlib_surface.cc win32_font.cc win32_surface.cc exception.cc scaledfont.cc +cc_sources = context.cc fontface.cc fontoptions.cc path.cc pattern.cc quartz_font.cc quartz_surface.cc surface.cc xlib_surface.cc win32_font.cc win32_surface.cc exception.cc scaledfont.cc cc_sources_private = private.cc context_surface_quartz.cc context_surface_win32.cc context_surface_xlib.cc # Support for DLL on cygwin/mingw using libtool > 1.4 diff --git a/cairomm/cairomm.h b/cairomm/cairomm.h index f8eaa3c..f3a1ac5 100644 --- a/cairomm/cairomm.h +++ b/cairomm/cairomm.h @@ -37,7 +37,6 @@ #include #include #include -#include #include #include #include diff --git a/cairomm/context.h b/cairomm/context.h index 54b51d8..5d4e11c 100644 --- a/cairomm/context.h +++ b/cairomm/context.h @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include diff --git a/cairomm/matrix.cc b/cairomm/matrix.cc deleted file mode 100644 index db65ad3..0000000 --- a/cairomm/matrix.cc +++ /dev/null @@ -1,91 +0,0 @@ -/* Copyright (C) 2008 Jonathon Jongsma - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ -#include -#include - -namespace Cairo -{ - -Matrix::Matrix() -{ - init_identity(); -} - -Matrix::Matrix(double xx, double yx, double xy, double yy, double x0, double y0) -{ - cairo_matrix_init(this, xx, yx, xy, yy, x0, y0); -} - -void Matrix::init_identity() -{ - cairo_matrix_init_identity(this); -} - -void Matrix::init_translate(double tx, double ty) -{ - cairo_matrix_init_translate(this, tx, ty); -} - -void Matrix::init_scale(double sx, double sy) -{ - cairo_matrix_init_scale(this, sx, sy); -} - -void Matrix::init_rotate(double radians) -{ - cairo_matrix_init_rotate(this, radians); -} - -void Matrix::translate(double tx, double ty) -{ - cairo_matrix_translate(this, tx, ty); -} - -void Matrix::scale(double sx, double sy) -{ - cairo_matrix_scale(this, sx, sy); -} - -void Matrix::rotate(double radians) -{ - cairo_matrix_rotate(this, radians); -} - -void Matrix::invert() -{ - cairo_status_t status = cairo_matrix_invert(this); - check_status_and_throw_exception(status); -} - -// throws exception -void Matrix::muiltiply(Matrix& a, Matrix& b) -{ - cairo_matrix_multiply(this, &a, &b); -} - -void Matrix::transform_distance(double& dx, double& dy) const -{ - cairo_matrix_transform_distance(this, &dx, &dy); -} - -void Matrix::transform_point(double& x, double& y) const -{ - cairo_matrix_transform_point(this, &x, &y); -} - -} // namespace Cairo diff --git a/cairomm/matrix.h b/cairomm/matrix.h deleted file mode 100644 index 46a3429..0000000 --- a/cairomm/matrix.h +++ /dev/null @@ -1,73 +0,0 @@ -/* Copyright (C) 2008 Jonathon Jongsma - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ -#ifndef __CAIROMM_MATRIX_H -#define __CAIROMM_MATRIX_H - -#include - -namespace Cairo -{ - -/** @class cairo_matrix_t - * See the cairo_matrix_t - * reference in the cairo manual for more information - */ - -/** A Transformation matrix. - * - * Cairo::Matrix is used throughout cairomm to convert between different - * coordinate spaces. A Matrix holds an affine transformation, such as - * a scale, rotation, shear, or a combination of these. The transformation of - * a point (x,y) is given by: - * - * @code - * x_new = xx * x + xy * y + x0; - * y_new = yx * x + yy * y + y0; - * @endcode - * - * The current transformation matrix of a Context, represented as a - * Matrix, defines the transformation from user-space coordinates to - * device-space coordinates. - * @sa Context::get_matrix() - * @sa Context::set_matrix() - */ -class Matrix : public cairo_matrix_t -{ -public: - Matrix(); - Matrix(double xx, double yx, double xy, double yy, double x0, double y0); - - void init_identity(); - void init_translate(double tx, double ty); - void init_scale(double sx, double sy); - void init_rotate(double radians); - void translate(double tx, double ty); - void scale(double sx, double sy); - void rotate(double radians); - - void invert(); // throws exception - void muiltiply(Matrix& a, Matrix& b); // FIXME: operator*? - - void transform_distance(double& dx, double& dy) const; - void transform_point(double& x, double& y) const; -}; - -} // namespace Cairo - -#endif // __CAIROMM_MATRIX_H diff --git a/cairomm/scaledfont.cc b/cairomm/scaledfont.cc index 5663f36..d08e766 100644 --- a/cairomm/scaledfont.cc +++ b/cairomm/scaledfont.cc @@ -36,8 +36,8 @@ ScaledFont::ScaledFont(const RefPtr& font_face, const Matrix& font_mat { m_cobject = cairo_scaled_font_create(font_face->cobj(), - &font_matrix, - &ctm, + reinterpret_cast(&font_matrix), + reinterpret_cast(&ctm), options.cobj()); check_object_status_and_throw_exception(*this); } @@ -99,13 +99,13 @@ void ScaledFont::get_font_options(FontOptions& options) const void ScaledFont::get_font_matrix(Matrix& font_matrix) const { cairo_scaled_font_get_font_matrix(m_cobject, - &font_matrix); + reinterpret_cast(&font_matrix)); check_object_status_and_throw_exception(*this); } void ScaledFont::get_ctm(Matrix& ctm) const { - cairo_scaled_font_get_ctm(m_cobject, &ctm); + cairo_scaled_font_get_ctm(m_cobject, reinterpret_cast(&ctm)); check_object_status_and_throw_exception(*this); } diff --git a/cairomm/scaledfont.h b/cairomm/scaledfont.h index 9abe48f..873f9ba 100644 --- a/cairomm/scaledfont.h +++ b/cairomm/scaledfont.h @@ -22,7 +22,6 @@ #include #include #include -#include #include #include diff --git a/cairomm/types.h b/cairomm/types.h index 5d583cd..5240e99 100644 --- a/cairomm/types.h +++ b/cairomm/types.h @@ -23,6 +23,8 @@ namespace Cairo { +typedef cairo_matrix_t Matrix; //A simple struct. //TODO: Derive and add operator[] and operator. matrix multiplication? + /** See the cairo_rectangle_t * reference in the cairo manual for more information diff --git a/tests/Makefile.am b/tests/Makefile.am index c18d975..94130a4 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,7 +1,7 @@ if AUTOTESTS # build automated 'tests' -TESTS=test-context test-font-face test-surface test-scaled-font test-font-options test-matrix test-user-font +TESTS=test-context test-font-face test-surface test-scaled-font test-font-options test-user-font noinst_PROGRAMS = $(TESTS) test_context_SOURCES=test-context.cc test_font_face_SOURCES=test-font-face.cc @@ -9,7 +9,6 @@ test_user_font_SOURCES=test-user-font.cc test_surface_SOURCES=test-surface.cc test_scaled_font_SOURCES=test-scaled-font.cc test_font_options_SOURCES=test-font-options.cc -test_matrix_SOURCES=test-matrix.cc test_surface_CPPFLAGS=-DPNG_STREAM_FILE=\"$(srcdir)/png-stream-test.png\" diff --git a/tests/test-font-face.cc b/tests/test-font-face.cc index b054709..3282bdc 100644 --- a/tests/test-font-face.cc +++ b/tests/test-font-face.cc @@ -48,6 +48,241 @@ void test_toy_getters () BOOST_CHECK_EQUAL (Cairo::FONT_TYPE_TOY, toy->get_type()); } +void test_user_font_create() +{ + Cairo::RefPtr font = Cairo::UserFontFace::create(); + BOOST_CHECK_EQUAL (Cairo::FONT_TYPE_USER, font->get_type()); +} + +// create some dummy callbacks +static unsigned int init_call_count = 0; +Cairo::ErrorStatus my_init(const Cairo::RefPtr&, const Cairo::RefPtr&, Cairo::FontExtents&) +{ + init_call_count++; + return CAIRO_STATUS_SUCCESS; +} + +static unsigned int unicode_to_glyph_call_count = 0; +Cairo::ErrorStatus my_unicode_to_glyph(const Cairo::RefPtr&, unsigned long, unsigned long&) +{ + unicode_to_glyph_call_count++; + return CAIRO_STATUS_SUCCESS; +} + +static unsigned int render_glyph_call_count = 0; +Cairo::ErrorStatus my_render_glyph(const Cairo::RefPtr&, unsigned long, const Cairo::RefPtr&, Cairo::TextExtents&) +{ + render_glyph_call_count++; + return CAIRO_STATUS_SUCCESS; +} + +static unsigned int text_to_glyphs_call_count = 0; +Cairo::ErrorStatus my_text_to_glyphs(const Cairo::RefPtr&, const std::string& utf8, std::vector& glyphs, std::vector& /*clusters*/, bool& /*backward*/) +{ + text_to_glyphs_call_count++; + if (glyphs.size()) + glyphs.clear(); + // just fill in some bogus glyph indexes + std::string::const_iterator str_iter = utf8.begin(); + for (; str_iter != utf8.end(); ++str_iter) + { + Cairo::Glyph g; + g.index = (unsigned long) *str_iter; + glyphs.push_back(g); + } + return CAIRO_STATUS_SUCCESS; +} + +void test_user_font_callbacks_ptr() +{ + render_glyph_call_count = 0; + unicode_to_glyph_call_count = 0; + init_call_count = 0; + Cairo::RefPtr font = Cairo::UserFontFace::create(); + BOOST_CHECK(font); + font->set_init_func(sigc::ptr_fun(my_init)); + font->set_unicode_to_glyph_func(sigc::ptr_fun(my_unicode_to_glyph)); + font->set_render_glyph_func(sigc::ptr_fun(my_render_glyph)); + Cairo::RefPtr scaled_font = + Cairo::ScaledFont::create(font, identity_matrix, identity_matrix, + Cairo::FontOptions()); + BOOST_CHECK (init_call_count > 0); + Cairo::RefPtr surface = + Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 100, 100); + Cairo::RefPtr cr = Cairo::Context::create(surface); + cr->set_font_face(font); + cr->show_text("Hello, world"); + BOOST_CHECK (unicode_to_glyph_call_count > 0); + BOOST_CHECK (render_glyph_call_count > 0); +} + +// since unicode_to_glyph_func and text_to_glyphs_func are mutually exclusive, +// we must test them separately. This test tests the text_to_glyphs_func +void test_user_font_callbacks_ptr_text() +{ + render_glyph_call_count = 0; + text_to_glyphs_call_count = 0; + init_call_count = 0; + Cairo::RefPtr font = Cairo::UserFontFace::create(); + BOOST_CHECK(font); + font->set_init_func(sigc::ptr_fun(my_init)); + font->set_render_glyph_func(sigc::ptr_fun(my_render_glyph)); + font->set_text_to_glyphs_func(sigc::ptr_fun(my_text_to_glyphs)); + Cairo::RefPtr scaled_font = + Cairo::ScaledFont::create(font, identity_matrix, identity_matrix, + Cairo::FontOptions()); + BOOST_CHECK (init_call_count > 0); + Cairo::RefPtr surface = + Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 100, 100); + Cairo::RefPtr cr = Cairo::Context::create(surface); + cr->set_font_face(font); + cr->show_text("Hello, world"); + BOOST_CHECK (render_glyph_call_count > 0); + BOOST_CHECK (text_to_glyphs_call_count > 0); +} + +struct UserFontCallbacks +{ +Cairo::ErrorStatus init(const Cairo::RefPtr&, const Cairo::RefPtr&, Cairo::FontExtents&) +{ + init_call_count++; + return CAIRO_STATUS_SUCCESS; +} + +Cairo::ErrorStatus unicode_to_glyph(const Cairo::RefPtr&, unsigned long, unsigned long&) +{ + unicode_to_glyph_call_count++; + return CAIRO_STATUS_SUCCESS; +} + +Cairo::ErrorStatus render_glyph(const Cairo::RefPtr&, unsigned long, const Cairo::RefPtr&, Cairo::TextExtents&) +{ + render_glyph_call_count++; + return CAIRO_STATUS_SUCCESS; +} + +static unsigned int init_call_count; +static unsigned int unicode_to_glyph_call_count; +static unsigned int render_glyph_call_count; +}; + +unsigned int UserFontCallbacks::init_call_count = 0; +unsigned int UserFontCallbacks::unicode_to_glyph_call_count = 0; +unsigned int UserFontCallbacks::render_glyph_call_count = 0; + +void test_user_font_callbacks_mem() +{ + Cairo::RefPtr font = Cairo::UserFontFace::create(); + BOOST_CHECK(font); + UserFontCallbacks callbacks; + font->set_init_func(sigc::mem_fun(&callbacks, &UserFontCallbacks::init)); + font->set_unicode_to_glyph_func(sigc::mem_fun(&callbacks, + &UserFontCallbacks::unicode_to_glyph)); + font->set_render_glyph_func(sigc::mem_fun(&callbacks, + &UserFontCallbacks::render_glyph)); + Cairo::RefPtr scaled_font = + Cairo::ScaledFont::create(font, identity_matrix, identity_matrix, + Cairo::FontOptions()); + BOOST_CHECK (UserFontCallbacks::init_call_count > 0); + Cairo::RefPtr surface = + Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 100, 100); + Cairo::RefPtr cr = Cairo::Context::create(surface); + cr->set_font_face(font); + cr->show_text("Hello, world"); + BOOST_CHECK (UserFontCallbacks::unicode_to_glyph_call_count > 0); + BOOST_CHECK (UserFontCallbacks::render_glyph_call_count > 0); +} + +static unsigned int init_exception_call_count = 0; +Cairo::ErrorStatus my_init_exception(const Cairo::RefPtr&, const Cairo::RefPtr&, Cairo::FontExtents&) +{ + init_exception_call_count++; + throw std::logic_error("init exception"); +} + +static unsigned int unicode_to_glyph_exception_call_count = 0; +Cairo::ErrorStatus my_unicode_to_glyph_exception(const Cairo::RefPtr&, unsigned long, unsigned long&) +{ + unicode_to_glyph_exception_call_count++; + throw std::logic_error("unicode-to-glyph exception"); +} + +static unsigned int render_glyph_exception_call_count = 0; +Cairo::ErrorStatus my_render_glyph_exception(const Cairo::RefPtr&, unsigned long, const Cairo::RefPtr&, Cairo::TextExtents&) +{ + render_glyph_exception_call_count++; + throw std::logic_error("render-glyph exception"); +} + + +void test_user_font_callbacks_exception() +{ + Cairo::RefPtr font = Cairo::UserFontFace::create(); + BOOST_CHECK(font); + font->set_init_func(sigc::ptr_fun(my_init_exception)); + + // the init() callback will throw an exception, if this isn't handled in the + // callback wrapper, the program will abort since an exception can't unwind + // through C code. However, due to the exception being thrown, the create() + // function will fail and throw a new exception. So if the executable doesn't + // abort, we should get an exception here. + Cairo::RefPtr scaled_font; + BOOST_CHECK_THROW (scaled_font = Cairo::ScaledFont::create(font, + identity_matrix, + identity_matrix, + Cairo::FontOptions()), + Cairo::logic_error); + BOOST_CHECK (init_exception_call_count > 0); + + // now initialize a scaled font properly so we can test the other callbacks + font = Cairo::UserFontFace::create(); + font->set_init_func(sigc::ptr_fun(my_init)); + font->set_render_glyph_func(sigc::ptr_fun(my_render_glyph_exception)); + font->set_unicode_to_glyph_func(sigc::ptr_fun(my_unicode_to_glyph_exception)); + BOOST_CHECK_NO_THROW (scaled_font = Cairo::ScaledFont::create(font, + identity_matrix, + identity_matrix, + Cairo::FontOptions())) + Cairo::RefPtr surface = + Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 100, 100); + Cairo::RefPtr cr = Cairo::Context::create(surface); + cr->set_font_face(font); + // this call should throw an exception since the callback wrapper will return + // an error status (that will be translated into an exception) but the test + // shouldn't abort sindce the callback exceptions are handled by the callback + // wrapper + BOOST_REQUIRE_EQUAL (CAIRO_STATUS_SUCCESS, font->get_status()); + BOOST_CHECK_THROW(cr->show_text("Hello, world"), Cairo::logic_error); + BOOST_CHECK (UserFontCallbacks::unicode_to_glyph_call_count > 0); + BOOST_CHECK (UserFontCallbacks::render_glyph_call_count > 0); +} + +// create some dummy callbacks +static unsigned int init2_call_count = 0; +Cairo::ErrorStatus my_init2(const Cairo::RefPtr&, const Cairo::RefPtr&, Cairo::FontExtents&) +{ + init2_call_count++; + return CAIRO_STATUS_SUCCESS; +} + +void test_user_font_replace_callback() +{ + // reset + init_call_count = 0; + Cairo::RefPtr font = Cairo::UserFontFace::create(); + font->set_init_func(sigc::ptr_fun(my_init)); + // now replace the init function with my_init2 and make sure that the 2nd + // function is called, not the first + font->set_init_func(sigc::ptr_fun(my_init2)); + Cairo::RefPtr scaled_font; + BOOST_CHECK_NO_THROW (scaled_font = Cairo::ScaledFont::create(font, + identity_matrix, + identity_matrix, + Cairo::FontOptions())) + BOOST_CHECK (init2_call_count > 0); + BOOST_CHECK_EQUAL (init_call_count, 0); +} + #ifdef CAIRO_HAS_FT_FONT void test_ft_font_face() { @@ -107,6 +342,9 @@ init_unit_test_suite(int argc, char* argv[]) // compile even with -Werror if (argc && argv) {} + // setup + cairo_matrix_init_identity(&identity_matrix); + test_suite* test= BOOST_TEST_SUITE( "Cairo::FontFace Tests" ); test->add (BOOST_TEST_CASE (&test_create_toy)); diff --git a/tests/test-matrix.cc b/tests/test-matrix.cc deleted file mode 100644 index fe4492f..0000000 --- a/tests/test-matrix.cc +++ /dev/null @@ -1,87 +0,0 @@ -#include -#include -#include -using namespace boost::unit_test; - -#include - -void test_constructors() -{ - cairo_matrix_t c_identity; - cairo_matrix_init_identity(&c_identity); - Cairo::Matrix cpp_identity; - - BOOST_CHECK_EQUAL(c_identity.xx, cpp_identity.xx); - BOOST_CHECK_EQUAL(c_identity.yx, cpp_identity.yx); - BOOST_CHECK_EQUAL(c_identity.xy, cpp_identity.xy); - BOOST_CHECK_EQUAL(c_identity.yy, cpp_identity.yy); - BOOST_CHECK_EQUAL(c_identity.x0, cpp_identity.x0); - BOOST_CHECK_EQUAL(c_identity.y0, cpp_identity.y0); - - // nonsense values, just for testing - const double xx=1, yx=2, xy=3, yy=5, x0=6, y0=7; - cairo_matrix_t c_matrix; - cairo_matrix_init(&c_matrix, xx, yx, xy, yy, x0, y0); - Cairo::Matrix cpp_matrix(xx, yx, xy, yy, x0, y0); - - BOOST_CHECK_EQUAL(c_matrix.xx, cpp_matrix.xx); - BOOST_CHECK_EQUAL(c_matrix.xy, cpp_matrix.xy); - BOOST_CHECK_EQUAL(c_matrix.yx, cpp_matrix.yx); - BOOST_CHECK_EQUAL(c_matrix.yy, cpp_matrix.yy); - BOOST_CHECK_EQUAL(c_matrix.x0, cpp_matrix.x0); - BOOST_CHECK_EQUAL(c_matrix.y0, cpp_matrix.y0); -} - -void test_invert() -{ - // test a valid matrix - Cairo::Matrix identity; - BOOST_CHECK_NO_THROW(identity.invert()); - // check a degenerate matrix - Cairo::Matrix degenerate(0,0,0,0,0,0); - BOOST_CHECK_THROW(degenerate.invert(), std::logic_error); -} - -cairo_matrix_t* test_matrix = 0; -static void foo(cairo_matrix_t* matrix) -{ - test_matrix = matrix; -} - -void test_cast() -{ - // make sure that we can cast between C++ and C types without ill effect - Cairo::Matrix matrix; - cairo_matrix_t casted = (cairo_matrix_t) matrix; - // check that it's equal to the identity matrix - cairo_matrix_t identity; - cairo_matrix_init_identity(&identity); - - BOOST_CHECK_EQUAL(casted.xx, identity.xx); - BOOST_CHECK_EQUAL(casted.xy, identity.xy); - BOOST_CHECK_EQUAL(casted.yx, identity.yx); - BOOST_CHECK_EQUAL(casted.yy, identity.yy); - BOOST_CHECK_EQUAL(casted.x0, identity.x0); - BOOST_CHECK_EQUAL(casted.y0, identity.y0); - - // pass C++ type as an argument to C - foo(&matrix); - BOOST_CHECK_EQUAL(matrix.xx, test_matrix->xx); - BOOST_CHECK_EQUAL(matrix.yx, test_matrix->yx); - BOOST_CHECK_EQUAL(matrix.xy, test_matrix->xy); - BOOST_CHECK_EQUAL(matrix.yy, test_matrix->yy); - BOOST_CHECK_EQUAL(matrix.x0, test_matrix->x0); - BOOST_CHECK_EQUAL(matrix.y0, test_matrix->y0); -} - -test_suite* -init_unit_test_suite(int /*argc*/, char** /*argv*/) -{ - test_suite* test= BOOST_TEST_SUITE( "Cairo::Matrix Tests" ); - - test->add (BOOST_TEST_CASE (&test_constructors)); - test->add (BOOST_TEST_CASE (&test_invert)); - test->add (BOOST_TEST_CASE (&test_cast)); - - return test; -} -- 1.6.3.1