diff options
| author | Randy Morgan <[email protected]> | 2011-11-23 21:45:54 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2011-11-23 21:45:54 +0900 |
| commit | c8c63518b4d58ca8875f81602792050cbec318f2 (patch) | |
| tree | 14f6e2c5286e5509879b6b664205f3ea2f38180c /test/drawing/tc_pic.rb | |
| parent | 2dea87f6f601795e32c7c14fbba5717c4b04fc1e (diff) | |
| download | caxlsx-c8c63518b4d58ca8875f81602792050cbec318f2.tar.gz caxlsx-c8c63518b4d58ca8875f81602792050cbec318f2.zip | |
Adding image support and some document clean up for .8 release
Diffstat (limited to 'test/drawing/tc_pic.rb')
| -rw-r--r-- | test/drawing/tc_pic.rb | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/test/drawing/tc_pic.rb b/test/drawing/tc_pic.rb new file mode 100644 index 00000000..2d6c603d --- /dev/null +++ b/test/drawing/tc_pic.rb @@ -0,0 +1,71 @@ +require 'test/unit' +require 'axlsx.rb' + +class TestPic < Test::Unit::TestCase + + def setup + @p = Axlsx::Package.new + ws = @p.workbook.add_worksheet + @test_img = File.dirname(__FILE__) + "/../../examples/image1.jpeg" + @image = ws.add_image :image_src => @test_img + end + + def teardown + end + + def test_initialization + assert_equal(@p.workbook.images.first, @image) + assert_equal(@image.image_src, @test_img) + end + + def test_name + assert_raise(ArgumentError) { @image.name = 49 } + assert_nothing_raised { @image.name = "unknown" } + assert_equal(@image.name, "unknown") + end + + def test_start_at + assert_raise(ArgumentError) { @image.start_at "a", 1 } + assert_nothing_raised { @image.start_at 6, 7 } + assert_equal(@image.anchor.from.col, 6) + assert_equal(@image.anchor.from.row, 7) + end + + def test_width + assert_raise(ArgumentError) { @image.width = "a" } + assert_nothing_raised { @image.width = 600 } + assert_equal(@image.width, 600) + end + + def test_height + assert_raise(ArgumentError) { @image.height = "a" } + assert_nothing_raised { @image.height = 600 } + assert_equal(600, @image.height) + end + + def test_image_src + assert_raise(ArgumentError) { @image.image_src = 49 } + assert_raise(ArgumentError) { @image.image_src = 'Unknown' } + assert_raise(ArgumentError) { @image.image_src = __FILE__ } + assert_nothing_raised { @image.image_src = @test_img } + assert_equal(@image.image_src, @test_img) + end + + def test_descr + assert_raise(ArgumentError) { @image.descr = 49 } + assert_nothing_raised { @image.descr = "test" } + assert_equal(@image.descr, "test") + end + + def test_to_xml + schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD)) + doc = Nokogiri::XML(@image.anchor.drawing.to_xml) + errors = [] + schema.validate(doc).each do |error| + errors.push error + puts error.message + end + assert(errors.empty?, "error free validation") + end + +end |
