[cairo-commit] rcairo/test run-test.rb, 1.1, 1.2 test_paper.rb, NONE, 1.1

Kouhei Sutou commit at pdx.freedesktop.org
Tue Apr 8 23:11:11 PDT 2008


Committed by: kou

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

Modified Files:
	run-test.rb 
Added Files:
	test_paper.rb 
Log Message:
* src/lib/cairo/paper.rb, src/lib/cairo/papers.rb, test/test_paper.rb: add.


Index: run-test.rb
===================================================================
RCS file: /cvs/cairo/rcairo/test/run-test.rb,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- run-test.rb	24 Feb 2008 07:42:58 -0000	1.1
+++ run-test.rb	9 Apr 2008 06:15:42 -0000	1.2
@@ -1,5 +1,13 @@
 #!/usr/bin/env ruby
 
+base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
+src_dir = File.join(base_dir, "src")
+lib_dir = File.join(src_dir, "lib")
+
+$LOAD_PATH.unshift(base_dir)
+$LOAD_PATH.unshift(src_dir)
+$LOAD_PATH.unshift(lib_dir)
+
 require 'test/unit'
 
 Dir.glob("test/**/test_*.rb") do |file|

--- NEW FILE: test_paper.rb ---
require 'cairo'

class PaperTest < Test::Unit::TestCase
  def test_parse_name
    assert_parse(:A4, "A4")
    assert_parse(:A4, "A4")
    assert_parse(:A4, :A4)
    assert_parse(:A4, :a4)

    assert_parse(:JAPANESE_POSTCARD, :japanese_postcard)
    assert_parse(:JAPANESE_POSTCARD, "japanese-postcard")
    assert_parse(:JAPANESE_POSTCARD, "Japanese postcard")

    exception = assert_raise(Cairo::Paper::UnknownPaperName) do
      Cairo::Paper.parse(:nonexistence)
    end
    assert_equal(:nonexistence, exception.name)
  end

  def test_parse_size
    assert_parse(paper(100, 200), "100x200")
    assert_parse(paper(100, 200), "100mmx200mm")
    assert_parse(paper(100.5, 200.9), "100.5mmx200.9")
    assert_parse(paper(100.5, 200.9), "100.5mmx200.9")
    assert_parse(paper(25.4, 215.9), "1inchx8.5inch")

    exception = assert_raise(Cairo::Paper::UnknownUnit) do
      Cairo::Paper.parse("100kmx100")
    end
    assert_equal("km", exception.unit)
  end

  private
  def paper(width, height)
    Cairo::Paper.new(width, height)
  end

  def assert_parse(expected, paper_description)
    expected = Cairo::Paper.const_get(expected) if expected.is_a?(Symbol)
    actual_paper = Cairo::Paper.parse(paper_description)
    assert_equal(expected.to_s, actual_paper.nil? ? nil : actual_paper.to_s)
  end
end



More information about the cairo-commit mailing list