test/drawable_test.rb in ray-0.1.1 vs test/drawable_test.rb in ray-0.2.0

- old
+ new

@@ -7,11 +7,19 @@ asserts(:scale).equals Ray::Vector2[1, 1] asserts(:pos).equals Ray::Vector2[0, 0] asserts(:z).equals 0 asserts(:angle).equals 0 asserts(:shader).nil + asserts(:shader_attributes).nil + asserts(:matrix_proc).nil + asserts(:blend_mode).equals :alpha + context "after changing blend mode" do + hookup { topic.blend_mode = :add } + asserts(:blend_mode).equals :add + end + context "after changing origin" do hookup { topic.origin = Ray::Vector2[10, 20] } asserts(:origin).equals Ray::Vector2[10, 20] asserts(:scale).equals Ray::Vector2[1, 1] @@ -59,16 +67,20 @@ asserts(:z).equals 0 asserts(:angle).equals 60 end context "with several transformations" do + attr = {:foo => 3} + hookup do topic.origin = [30, 40] topic.pos = [10, 20] topic.angle = 90 topic.scale = [2, 0.5] topic.z = 9 + + topic.shader_attributes = attr end # (10, 30) => (-20, -10) (origin) # (-20, -10) => (-40, -5) (scale) # (-40, -5) => (5, -40) (rotate) @@ -86,10 +98,15 @@ asserts(:origin).equals Ray::Vector2[30, 40] asserts(:pos).equals Ray::Vector2[10, 20] asserts(:angle).equals 90 asserts(:scale).equals Ray::Vector2[2, 0.5] asserts(:z).equals 9 + + asserts(:shader_attributes).equals attr + asserts("shader_attributes are copied") do + !(topic.shader_attributes.equal? attr) + end end context "and a custom matrix" do hookup do topic.matrix = Ray::Matrix.new @@ -105,10 +122,39 @@ asserts(:transform, [10, 30]).almost_equals(Ray::Vector3[15, -20, 9], 1e-6) end end + + context "and a custom matrix proc" do + matrix_proc = proc { Ray::Matrix.identity } + + hookup do + proxy(matrix_proc).call + + topic.matrix_proc = matrix_proc + topic.matrix # calls proc + end + + asserts(:matrix).equals Ray::Matrix.new + asserts(:matrix_proc).equals matrix_proc + asserts(:matrix_proc).received(:call) { topic } + + context "when matrix is accessed twice" do + hookup { topic.matrix } + denies(:matrix_proc).received(:call => 2) { topic } + end + + context "when matrix is accessed after a change" do + hookup do + topic.matrix_changed! + topic.matrix + end + + asserts(:matrix_proc).received(:call => 2) { topic } + end + end end context "after changing shader" do hookup do topic.shader = @shader = Ray::Shader.new @@ -192,18 +238,41 @@ asserts_topic.received({:render => 2}, is_a(Integer), 0) end end end - context "with indices" do + context "drawn with indices" do hookup do proxy(topic).fill_indices + proxy(topic).render + topic.index_count = 3 target.draw topic end asserts_topic.received :fill_indices, is_a(Integer) + asserts_topic.received :render, is_a(Integer), is_a(Integer) + + context "but no vertices" do + hookup do + topic.vertex_count = 0 + target.draw topic + end + + asserts_topic.received({:render => 2}, is_a(Integer), is_a(Integer)) + end + end + + context "drawn without vertices" do + hookup do + topic.vertex_count = 0 + + proxy(topic).render + target.draw topic + end + + asserts_topic.received :render, 0, 0 end context "with more indices than it gives" do hookup { topic.index_count = 5 } asserts("drawing it") { target.draw topic }.raises_kind_of RuntimeError