TEST(DictionarySerializationTest, NumberAsStringsDoesntAffectObjects) { SerializationContext ctx; AmfDictionary d(true); d.insert(AmfArray(), AmfDictionary(false)); d.insert(AmfArray(std::vector<AmfInteger> { 1 }), AmfObject("", true, false)); consistsOf(std::vector<v8> { { // header 0x11, 0x05, // 2 elements 0x00 // no weak keys }, { // [] = {} 0x09, 0x01, 0x01, // empty array 0x11, 0x01, 0x00 // empty array }, { // [1] = {} 0x09, 0x03, 0x01, 0x04, 0x01, // AmfArray [1] 0x0a, 0x0b, 0x01, 0x01 // empty dynamic anonymous object } }, d.serialize(ctx)); AmfObject obj("foo", true, false); obj.addDynamicProperty("prop", AmfString("val")); AmfVector<int> vec { { 1, 2, 3 }, false }; d = AmfDictionary(true); d.insert(obj, vec); isEqual({ 0x11, 0x03, // 1 element 0x00, // no weak keys // key 0x0a, // AMF_OBJECT 0x0b, // U29O-traits | dynamic, 0 sealed properties 0x07, 0x66, 0x6f, 0x6f, // class-name "foo" // dynamic-member 0x09, 0x70, 0x72, 0x6f, 0x70, // UTF-8-vr "prop" 0x06, 0x07, 0x76, 0x61, 0x6c, // AmfString "val" 0x01, // end of object (UTF-8-empty) // value 0x0d, 0x07, 0x00, // AmfVector<int> with 3 elements 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03 }, d); }
TEST(DictionaryDeserialization, ObjectKeys) { AmfDictionary d(false, false); d.insert(AmfObject("", true, false), AmfString("foo")); v8 data { 0x11, 0x03, 0x00, 0x0a, 0x0b, 0x01, 0x01, 0x06, 0x07, 0x66, 0x6f, 0x6f }; deserialize(d, data, 0); d = AmfDictionary(false, false); AmfObject o("", true, false); o.addDynamicProperty("bar", AmfInteger(1)); d.insert(o, AmfString("foo")); data = { 0x11, 0x03, 0x00, 0x0a, 0x0b, 0x01, 0x07, 0x62, 0x61, 0x72, 0x04, 0x01, 0x01, 0x06, 0x07, 0x66, 0x6f, 0x6f }; deserialize(d, data, 0); }
TEST(ObjectSerializationTest, NonTraitCtor) { AmfObject obj; obj.addSealedProperty("sealedProp", AmfInteger(0x7b)); isEqual(v8 { 0x0a, // AMF_OBJECT 0x13, // U29O-traits, not dynamic, 1 sealed prop 0x01, // class-name "" // UTF-8-vr "sealedProp" 0x15, 0x73, 0x65, 0x61, 0x6c, 0x65, 0x64, 0x50, 0x72, 0x6f, 0x70, // sealed property value // AmfInteger 0x7b 0x04, 0x7b // no dynamic members }, obj); obj = AmfObject("foo", true, false); obj.addSealedProperty("sealedProp", AmfInteger(0x7b)); obj.addDynamicProperty("dynamicProp", AmfString("dyn")); isEqual(v8 { 0x0a, // AMF_OBJECT 0x1b, // U29O-traits, dynamic, 1 sealed prop // class-name UTF-8-vr "foo" 0x07, 0x66, 0x6f, 0x6f, // UTF-8-vr "sealedProp" 0x15, 0x73, 0x65, 0x61, 0x6c, 0x65, 0x64, 0x50, 0x72, 0x6f, 0x70, // sealed property value // AmfInteger 0x7b 0x04, 0x7b, // 1 dynamic member // UTF-8-vr "dynamicProp" 0x17, 0x64, 0x79, 0x6e, 0x61, 0x6d, 0x69, 0x63, 0x50, 0x72, 0x6f, 0x70, // AmfString "dyn" 0x06, 0x07, 0x64, 0x79, 0x6e, // end of dynamic members 0x01 }, obj); }
TEST(DeserializerTest, Object) { deserializesTo(AmfObject("", false, false), { 0x0a, 0x03, 0x01 }); deserializesTo(AmfObject("", true, false), { 0x0a, 0x0b, 0x01, 0x01, 0xff }, 1); }