[cairo-commit] rcairo/test test_context.rb, 1.4, 1.5 test_font_face.rb, 1.2, 1.3

Kouhei Sutou commit at pdx.freedesktop.org
Sat Aug 16 20:00:44 PDT 2008


Committed by: kou

Update of /cvs/cairo/rcairo/test
In directory kemper:/tmp/cvs-serv14819/test

Modified Files:
	test_context.rb test_font_face.rb 
Log Message:
        * test/test_font_face.rb
        (FontFaceTest#test_toy_font_face_new_with_invalid_family_name):
        add a test for creating Cairo::ToyFontFace with invalid family
        name.
        (FontFaceTest#test_toy_font_face_new): add a test for creating
        Cairo::ToyFontFace with nil family name.

        * src/rb_cairo_font_face.c (cr_toy_font_face_initialize): accept nil.

        * src/rb_cairo_context.c (cr_select_font_face): make family optional.

        * test/test_context.rb
        (ContextTest#test_select_font_face),
        (ContextTest#test_select_font_face_with_invalid_family_name): add
        a test for Cairo::Context#select_font_face.


Index: test_context.rb
===================================================================
RCS file: /cvs/cairo/rcairo/test/test_context.rb,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- test_context.rb	16 Aug 2008 08:34:19 -0000	1.4
+++ test_context.rb	17 Aug 2008 03:00:41 -0000	1.5
@@ -59,7 +59,6 @@
     assert_false(context.have_show_text_glyphs?)
   end
 
-
   def test_text_to_glyphs
     only_cairo_version(1, 7, 2)
 
@@ -76,4 +75,39 @@
       context.show_text_glyphs(utf8, glyphs, clusters, backward)
     end
   end
+
+  def test_select_font_face
+    context = Cairo::Context.new(@surface)
+
+    face = context.font_face
+    default_font_family = ""
+    # default_font_family = "Helvetica" if quartz?
+    # default_font_family = "Arial" if win32?
+    assert_equal([default_font_family,
+                  Cairo::FONT_SLANT_NORMAL,
+                  Cairo::FONT_WEIGHT_NORMAL],
+                 [face.family, face.slant, face.weight])
+
+    context.select_font_face
+    face = context.font_face
+    assert_equal([default_font_family,
+                  Cairo::FONT_SLANT_NORMAL,
+                  Cairo::FONT_WEIGHT_NORMAL],
+                 [face.family, face.slant, face.weight])
+
+    context.select_font_face(:serif, :italic, :bold)
+    face = context.font_face
+    assert_equal(["serif", Cairo::FONT_SLANT_ITALIC, Cairo::FONT_WEIGHT_BOLD],
+                 [face.family, face.slant, face.weight])
+  end
+
+  def test_select_font_face_with_invalid_family_name
+    context = Cairo::Context.new(@surface)
+
+    exception = assert_raise(ArgumentError) do
+      context.select_font_face([999])
+    end
+    assert_equal("family name should be nil, String or Symbol: [999]",
+                 exception.message)
+  end
 end

Index: test_font_face.rb
===================================================================
RCS file: /cvs/cairo/rcairo/test/test_font_face.rb,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- test_font_face.rb	16 Aug 2008 12:52:17 -0000	1.2
+++ test_font_face.rb	17 Aug 2008 03:00:41 -0000	1.3
@@ -3,26 +3,49 @@
 class FontFaceTest < Test::Unit::TestCase
   include CairoTestUtils
 
-  def test_toy_font_face
+  def test_toy_font_face_new
     only_cairo_version(1, 7, 2)
 
-    face = Cairo::ToyFontFace.new("sans")
-    assert_equal(["sans", Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL],
+    face = Cairo::ToyFontFace.new
+    default_font_family = ""
+    # default_font_family = "Helvetica" if quartz?
+    # default_font_family = "Arial" if win32?
+    assert_equal([default_font_family,
+                  Cairo::FONT_SLANT_NORMAL,
+                  Cairo::FONT_WEIGHT_NORMAL],
                  [face.family, face.slant, face.weight])
 
-    face = Cairo::ToyFontFace.new("sans", :oblique)
-    assert_equal(["sans", Cairo::FONT_SLANT_OBLIQUE, Cairo::FONT_WEIGHT_NORMAL],
+    face = Cairo::ToyFontFace.new("serif")
+    assert_equal(["serif", Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL],
                  [face.family, face.slant, face.weight])
 
-    face = Cairo::ToyFontFace.new("sans", nil, :bold)
-    assert_equal(["sans", Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_BOLD],
+    face = Cairo::ToyFontFace.new(:serif)
+    assert_equal(["serif", Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_NORMAL],
                  [face.family, face.slant, face.weight])
 
-    face = Cairo::ToyFontFace.new("sans", :italic, :bold)
-    assert_equal(["sans", Cairo::FONT_SLANT_ITALIC, Cairo::FONT_WEIGHT_BOLD],
+    face = Cairo::ToyFontFace.new("serif", :oblique)
+    assert_equal(["serif", Cairo::FONT_SLANT_OBLIQUE, Cairo::FONT_WEIGHT_NORMAL],
+                 [face.family, face.slant, face.weight])
+
+    face = Cairo::ToyFontFace.new("serif", nil, :bold)
+    assert_equal(["serif", Cairo::FONT_SLANT_NORMAL, Cairo::FONT_WEIGHT_BOLD],
+                 [face.family, face.slant, face.weight])
+
+    face = Cairo::ToyFontFace.new("serif", :italic, :bold)
+    assert_equal(["serif", Cairo::FONT_SLANT_ITALIC, Cairo::FONT_WEIGHT_BOLD],
                  [face.family, face.slant, face.weight])
   end
 
+  def test_toy_font_face_new_with_invalid_family_name
+    only_cairo_version(1, 7, 2)
+
+    exception = assert_raise(ArgumentError) do
+      Cairo::ToyFontFace.new(999)
+    end
+    assert_equal("family name should be nil, String or Symbol: 999",
+                 exception.message)
+  end
+
   def test_user_font_face_empty
     only_cairo_version(1, 7, 2)
 



More information about the cairo-commit mailing list