diff options
author | Jonathon Jongsma <jjongsma@gnome.org> | 2008-12-14 22:48:57 -0600 |
---|---|---|
committer | Jonathon Jongsma <jjongsma@gnome.org> | 2008-12-14 22:48:57 -0600 |
commit | 3a2c321730e583b6256e43cc91ee71c55b416ee4 (patch) | |
tree | f190983864506aedae2ebdd66e0861481baea075 | |
parent | 53ae1a41a5982f1e9740ecd94763e10c13b9749e (diff) |
Really fix ScaledFont::get_font_face() bug
* cairomm/scaledfont.cc: actually fix a reference-counting issue with
ScaledFont::get_font_face() that I thought I had fixed in b1d01ff7
* tests/test-scaled-font.cc: add a test for the get_font_face() bug
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | cairomm/scaledfont.cc | 2 | ||||
-rw-r--r-- | tests/test-scaled-font.cc | 21 |
3 files changed, 28 insertions, 1 deletions
@@ -1,3 +1,9 @@ +2008-12-14 Jonathon Jongsma <jonathon@quotidian.org> + + * cairomm/scaledfont.cc: actually fix a reference-counting issue with + ScaledFont::get_font_face() that I thought I had fixed in b1d01ff7 + * tests/test-scaled-font.cc: add a test for the get_font_face() bug + 2008-12-12 Jonathon Jongsma <jonathon@quotidian.org> * configure.in: bump version since we forgot to do it after release diff --git a/cairomm/scaledfont.cc b/cairomm/scaledfont.cc index 3d1a5d9..5663f36 100644 --- a/cairomm/scaledfont.cc +++ b/cairomm/scaledfont.cc @@ -87,7 +87,7 @@ RefPtr<FontFace> ScaledFont::get_font_face() const { cairo_font_face_t* face = cairo_scaled_font_get_font_face(m_cobject); check_object_status_and_throw_exception(*this); - return RefPtr<FontFace>(new FontFace(face, true /* returned face doesn't have a reference */)); + return RefPtr<FontFace>(new FontFace(face, false /* returned face doesn't have a reference */)); } void ScaledFont::get_font_options(FontOptions& options) const diff --git a/tests/test-scaled-font.cc b/tests/test-scaled-font.cc index 62bbd6e..73a4c59 100644 --- a/tests/test-scaled-font.cc +++ b/tests/test-scaled-font.cc @@ -3,6 +3,7 @@ #include <boost/test/floating_point_comparison.hpp> using namespace boost::unit_test; #include <cairomm/scaledfont.h> +#include <iostream> using namespace Cairo; @@ -49,6 +50,25 @@ void test_scale_matrix() // no real test, just excercising the functionality } +void test_get_font_face() +{ + // this is to test for a bug where we were accidentally freeing the resulting + // font face from a call to ScaledFont::get_font_face() when we didn't hold a + // reference to it + RefPtr<ToyFontFace> face = ToyFontFace::create("sans", FONT_SLANT_NORMAL, FONT_WEIGHT_NORMAL); + Matrix identity; + cairo_matrix_init_identity(&identity); + RefPtr<ScaledFont> font = ScaledFont::create(face, identity, identity, FontOptions()); + BOOST_REQUIRE(font); + const int refcount = cairo_font_face_get_reference_count(face->cobj()); + { + RefPtr<FontFace> got_face = font->get_font_face(); + } // scope ensure that the font face is destroyed + // after creating and destroying the FontFace in get_font_face, our reference + // count should be the same + BOOST_REQUIRE_EQUAL(cairo_font_face_get_reference_count(face->cobj()), refcount); +} + test_suite* init_unit_test_suite(int argc, char* argv[]) @@ -61,6 +81,7 @@ init_unit_test_suite(int argc, char* argv[]) test->add (BOOST_TEST_CASE (&test_construction)); test->add (BOOST_TEST_CASE (&test_text_to_glyphs)); test->add (BOOST_TEST_CASE (&test_scale_matrix)); + test->add (BOOST_TEST_CASE (&test_get_font_face)); return test; } |