summaryrefslogtreecommitdiffhomepage
path: root/test/drawing
diff options
context:
space:
mode:
authorrandym <[email protected]>2018-02-06 22:11:32 +0900
committerrandym <[email protected]>2018-02-06 22:11:32 +0900
commit486fe82cdf4053e48e7a8357f4da32ae3d365433 (patch)
treedf9f9a254ac88a0993def27011408f3256b4e1f1 /test/drawing
parenta981ae5afffb6b0dfe411820e3df1a44f5cbd63f (diff)
parenta5a3e049a77a5553c2fba4fae809e3e242c51dbb (diff)
downloadcaxlsx-486fe82cdf4053e48e7a8357f4da32ae3d365433.tar.gz
caxlsx-486fe82cdf4053e48e7a8357f4da32ae3d365433.zip
Merge branch 'master' into release-3.0.0
Diffstat (limited to 'test/drawing')
-rw-r--r--test/drawing/tc_area_chart.rb39
-rw-r--r--test/drawing/tc_area_series.rb71
-rw-r--r--test/drawing/tc_bar_chart.rb71
3 files changed, 181 insertions, 0 deletions
diff --git a/test/drawing/tc_area_chart.rb b/test/drawing/tc_area_chart.rb
new file mode 100644
index 00000000..b3013c12
--- /dev/null
+++ b/test/drawing/tc_area_chart.rb
@@ -0,0 +1,39 @@
+require 'tc_helper.rb'
+
+class TestAreaChart < Test::Unit::TestCase
+
+ def setup
+ @p = Axlsx::Package.new
+ ws = @p.workbook.add_worksheet
+ @row = ws.add_row ["one", 1, Time.now]
+ @chart = ws.add_chart Axlsx::AreaChart, :title => "fishery"
+ end
+
+ def teardown
+ end
+
+ def test_initialization
+ assert_equal(@chart.grouping, :standard, "grouping defualt incorrect")
+ assert_equal(@chart.series_type, Axlsx::AreaSeries, "series type incorrect")
+ assert(@chart.cat_axis.is_a?(Axlsx::CatAxis), "category axis not created")
+ assert(@chart.val_axis.is_a?(Axlsx::ValAxis), "value access not created")
+ end
+
+ def test_grouping
+ assert_raise(ArgumentError, "require valid grouping") { @chart.grouping = :inverted }
+ assert_nothing_raised("allow valid grouping") { @chart.grouping = :stacked }
+ assert(@chart.grouping == :stacked)
+ end
+
+ def test_to_xml
+ schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
+ doc = Nokogiri::XML(@chart.to_xml_string)
+ errors = []
+ schema.validate(doc).each do |error|
+ errors.push error
+ puts error.message
+ end
+ assert(errors.empty?, "error free validation")
+ end
+
+end
diff --git a/test/drawing/tc_area_series.rb b/test/drawing/tc_area_series.rb
new file mode 100644
index 00000000..00229a39
--- /dev/null
+++ b/test/drawing/tc_area_series.rb
@@ -0,0 +1,71 @@
+require 'tc_helper.rb'
+
+class TestAreaSeries < Test::Unit::TestCase
+
+ def setup
+ p = Axlsx::Package.new
+ @ws = p.workbook.add_worksheet :name=>"hmmm"
+ chart = @ws.add_chart Axlsx::AreaChart, :title => "fishery"
+ @series = chart.add_series(
+ :data => [0,1,2],
+ :labels => ["zero", "one", "two"],
+ :title => "bob",
+ :color => "#FF0000",
+ :show_marker => true,
+ :smooth => true
+ )
+ end
+
+ def test_initialize
+ assert_equal(@series.title.text, "bob", "series title has been applied")
+ assert_equal(@series.labels.class, Axlsx::AxDataSource)
+ assert_equal(@series.data.class, Axlsx::NumDataSource)
+ end
+
+ def test_show_marker
+ assert_equal(true, @series.show_marker)
+ @series.show_marker = false
+ assert_equal(false, @series.show_marker)
+ end
+
+ def test_smooth
+ assert_equal(true, @series.smooth)
+ @series.smooth = false
+ assert_equal(false, @series.smooth)
+ end
+
+ def test_marker_symbol
+ assert_equal(:default, @series.marker_symbol)
+ @series.marker_symbol = :circle
+ assert_equal(:circle, @series.marker_symbol)
+ end
+
+ def test_to_xml_string
+ doc = Nokogiri::XML(wrap_with_namespaces(@series))
+ assert(doc.xpath("//srgbClr[@val='#{@series.color}']"))
+ assert_equal(xpath_with_namespaces(doc, "//c:marker").size, 0)
+ assert(doc.xpath("//smooth"))
+
+ @series.marker_symbol = :diamond
+ doc = Nokogiri::XML(wrap_with_namespaces(@series))
+ assert_equal(xpath_with_namespaces(doc, "//c:marker/c:symbol[@val='diamond']").size, 1)
+
+ @series.show_marker = false
+ doc = Nokogiri::XML(wrap_with_namespaces(@series))
+ assert_equal(xpath_with_namespaces(doc, "//c:marker/c:symbol[@val='none']").size, 1)
+ end
+
+ def wrap_with_namespaces(series)
+ '<c:chartSpace xmlns:c="' <<
+ Axlsx::XML_NS_C <<
+ '" xmlns:a="' <<
+ Axlsx::XML_NS_A <<
+ '">' <<
+ series.to_xml_string <<
+ '</c:chartSpace>'
+ end
+
+ def xpath_with_namespaces(doc, xpath)
+ doc.xpath(xpath, "a" => Axlsx::XML_NS_A, "c" => Axlsx::XML_NS_C)
+ end
+end
diff --git a/test/drawing/tc_bar_chart.rb b/test/drawing/tc_bar_chart.rb
new file mode 100644
index 00000000..ca1ca016
--- /dev/null
+++ b/test/drawing/tc_bar_chart.rb
@@ -0,0 +1,71 @@
+require 'tc_helper.rb'
+
+class TestBarChart < Test::Unit::TestCase
+
+ def setup
+ @p = Axlsx::Package.new
+ ws = @p.workbook.add_worksheet
+ @row = ws.add_row ["one", 1, Time.now]
+ @chart = ws.add_chart Axlsx::BarChart, :title => "fishery"
+ end
+
+ def teardown
+ end
+
+ def test_initialization
+ assert_equal(@chart.grouping, :clustered, "grouping defualt incorrect")
+ assert_equal(@chart.series_type, Axlsx::BarSeries, "series type incorrect")
+ assert_equal(@chart.bar_dir, :bar, " bar direction incorrect")
+ assert(@chart.cat_axis.is_a?(Axlsx::CatAxis), "category axis not created")
+ assert(@chart.val_axis.is_a?(Axlsx::ValAxis), "value access not created")
+ end
+
+ def test_bar_direction
+ assert_raise(ArgumentError, "require valid bar direction") { @chart.bar_dir = :left }
+ assert_nothing_raised("allow valid bar direction") { @chart.bar_dir = :col }
+ assert(@chart.bar_dir == :col)
+ end
+
+ def test_grouping
+ assert_raise(ArgumentError, "require valid grouping") { @chart.grouping = :inverted }
+ assert_nothing_raised("allow valid grouping") { @chart.grouping = :standard }
+ assert(@chart.grouping == :standard)
+ end
+
+
+ def test_gapWidth
+ assert_raise(ArgumentError, "require valid gap width") { @chart.gap_width = 200 }
+ assert_nothing_raised("allow valid gapWidth") { @chart.gap_width = "200%" }
+ assert(@chart.gap_width == "200%")
+ end
+
+ def test_gapDepth
+ assert_raise(ArgumentError, "require valid gap_depth") { @chart.gap_depth = 200 }
+ assert_nothing_raised("allow valid gap_depth") { @chart.gap_depth = "200%" }
+ assert(@chart.gap_depth == "200%")
+ end
+
+ def test_shape
+ assert_raise(ArgumentError, "require valid shape") { @chart.shape = :star }
+ assert_nothing_raised("allow valid shape") { @chart.shape = :cone }
+ assert(@chart.shape == :cone)
+ end
+
+ def test_to_xml_string
+ schema = Nokogiri::XML::Schema(File.open(Axlsx::DRAWING_XSD))
+ doc = Nokogiri::XML(@chart.to_xml_string)
+ errors = []
+ schema.validate(doc).each do |error|
+ errors.push error
+ puts error.message
+ end
+ assert(errors.empty?, "error free validation")
+ end
+
+ def test_to_xml_string_has_axes_in_correct_order
+ str = @chart.to_xml_string
+ cat_axis_position = str.index(@chart.axes[:cat_axis].id.to_s)
+ val_axis_position = str.index(@chart.axes[:val_axis].id.to_s)
+ assert(cat_axis_position < val_axis_position, "cat_axis must occur earlier than val_axis in the XML")
+ end
+end