summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJonathon Jongsma <jjongsma@gnome.org>2008-12-14 22:48:57 -0600
committerJonathon Jongsma <jjongsma@gnome.org>2008-12-14 22:48:57 -0600
commit3a2c321730e583b6256e43cc91ee71c55b416ee4 (patch)
treef190983864506aedae2ebdd66e0861481baea075 /tests
parent53ae1a41a5982f1e9740ecd94763e10c13b9749e (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
Diffstat (limited to 'tests')
-rw-r--r--tests/test-scaled-font.cc21
1 files changed, 21 insertions, 0 deletions
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;
}