spec/amf/deserializer_spec.rb in RocketAMF-0.0.7 vs spec/amf/deserializer_spec.rb in RocketAMF-0.1.0
- old
+ new
@@ -1,5 +1,7 @@
+# encoding: UTF-8
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
describe "when deserializing" do
before :each do
RocketAMF::ClassMapper.reset
@@ -16,11 +18,11 @@
input = object_fixture('amf0-boolean.bin')
output = RocketAMF.deserialize(input, 0)
output.should === true
end
- it "should deserialize strings" do
+ it "should deserialize UTF8 strings" do
input = object_fixture('amf0-string.bin')
output = RocketAMF.deserialize(input, 0)
output.should == "this is a テスト"
end
@@ -72,24 +74,25 @@
input = object_fixture('amf0-date.bin')
output = RocketAMF.deserialize(input, 0)
output.should == Time.utc(2003, 2, 13, 5)
end
- it "should deserialize XML"
+ it "should deserialize an XML document" do
+ input = object_fixture('amf0-xmlDoc.bin')
+ output = RocketAMF.deserialize(input, 0)
+ output.should == '<parent><child prop="test" /></parent>'
+ end
it "should deserialize an unmapped object as a dynamic anonymous object" do
input = object_fixture("amf0-typed-object.bin")
output = RocketAMF.deserialize(input, 0)
output.type.should == 'org.rocketAMF.ASClass'
output.should == {:foo => 'bar', :baz => nil}
end
it "should deserialize a mapped object as a mapped ruby class instance" do
- class RubyClass
- attr_accessor :foo, :baz
- end
RocketAMF::ClassMapper.define {|m| m.map :as => 'org.rocketAMF.ASClass', :ruby => 'RubyClass'}
input = object_fixture("amf0-typed-object.bin")
output = RocketAMF.deserialize(input, 0)
@@ -165,12 +168,21 @@
input = object_fixture("amf3-date.bin")
output = RocketAMF.deserialize(input, 3)
output.should == Time.at(0)
end
- #BAH! Who sends XML over AMF?
- it "should deserialize XML"
+ it "should deserialize XML" do
+ # XMLDocument tag
+ input = object_fixture("amf3-xmlDoc.bin")
+ output = RocketAMF.deserialize(input, 3)
+ output.should == '<parent><child prop="test" /></parent>'
+
+ # XML tag
+ input = object_fixture("amf3-xml.bin")
+ output = RocketAMF.deserialize(input, 3)
+ output.should == '<parent><child prop="test"/></parent>'
+ end
end
describe "objects" do
it "should deserialize an unmapped object as a dynamic anonymous object" do
input = object_fixture("amf3-dynObject.bin")
@@ -184,13 +196,10 @@
}
output.should == expected
end
it "should deserialize a mapped object as a mapped ruby class instance" do
- class RubyClass
- attr_accessor :foo, :baz
- end
RocketAMF::ClassMapper.define {|m| m.map :as => 'org.rocketAMF.ASClass', :ruby => 'RubyClass'}
input = object_fixture("amf3-typedObject.bin")
output = RocketAMF.deserialize(input, 3)
@@ -229,13 +238,34 @@
it "should deserialize a byte array" do
input = object_fixture("amf3-byteArray.bin")
output = RocketAMF.deserialize(input, 3)
- output.should be_a StringIO
- output.string.should == "\000\003これtest\100"
+ output.should be_a(StringIO)
+ expected = "\000\003これtest\100"
+ expected.force_encoding("ASCII-8BIT") if expected.respond_to?(:force_encoding)
+ output.string.should == expected
end
+
+ it "should deserialize an empty dictionary" do
+ input = object_fixture("amf3-emptyDictionary.bin")
+ output = RocketAMF.deserialize(input, 3)
+ output.should == {}
+ end
+
+ it "should deserialize a dictionary" do
+ input = object_fixture("amf3-dictionary.bin")
+ output = RocketAMF.deserialize(input, 3)
+
+ keys = output.keys
+ keys.length.should == 2
+ obj_key, str_key = keys[0].is_a?(RocketAMF::Values::TypedHash) ? [keys[0], keys[1]] : [keys[1], keys[0]]
+ obj_key.type.should == 'org.rocketAMF.ASClass'
+ output[obj_key].should == "asdf2"
+ str_key.should == "bar"
+ output[str_key].should == "asdf1"
+ end
end
describe "and implementing the AMF Spec" do
it "should keep references of duplicate strings" do
input = object_fixture("amf3-stringRef.bin")
@@ -272,13 +302,10 @@
obj2 = {:foo => obj1[:foo]}
output.should == [[obj1, obj2], "bar", [obj1, obj2]]
end
it "should keep reference of duplicate object traits" do
- class RubyClass
- attr_accessor :foo, :baz
- end
RocketAMF::ClassMapper.define {|m| m.map :as => 'org.rocketAMF.ASClass', :ruby => 'RubyClass'}
input = object_fixture("amf3-traitRef.bin")
output = RocketAMF.deserialize(input, 3)
@@ -302,10 +329,14 @@
a = []
b = []
output.should == [a,b,a,b]
end
- it "should keep references of duplicate XML and XMLDocuments"
+ it "should keep references of duplicate XML and XMLDocuments" do
+ input = object_fixture("amf3-xmlRef.bin")
+ output = RocketAMF.deserialize(input, 3)
+ output.should == ['<parent><child prop="test"/></parent>', '<parent><child prop="test"/></parent>']
+ end
it "should keep references of duplicate byte arrays" do
input = object_fixture("amf3-byteArrayRef.bin")
output = RocketAMF.deserialize(input, 3)
output[0].object_id.should == output[1].object_id
\ No newline at end of file