1 /** 2 * Copyright: Copyright (c) 2011 Jacob Carlborg. All rights reserved. 3 * Authors: Jacob Carlborg 4 * Version: Initial created: Aug 6, 2011 5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) 6 */ 7 module spec.serialization.Array; 8 9 import dspec.Dsl; 10 11 import mambo.core._; 12 import mambo.serialization.Serializer; 13 import mambo.serialization.archives.XmlArchive; 14 import spec.serialization.Util; 15 16 Serializer serializer; 17 XmlArchive!(char) archive; 18 19 class D 20 { 21 int[] arr; 22 } 23 24 struct ArrayOfObject 25 { 26 Object[] arr; 27 } 28 29 D d; 30 31 unittest 32 { 33 archive = new XmlArchive!(char); 34 serializer = new Serializer(archive); 35 36 d = new D; 37 d.arr = [27, 382, 283, 3820, 32, 832].dup; 38 39 describe! "serialize array" in { 40 it! "should return a serialized array" in { 41 serializer.reset; 42 serializer.serialize(d); 43 44 assert(archive.data().containsDefaultXmlContent()); 45 assert(archive.data().containsXmlTag("object", `runtimeType="spec.serialization.Array.D" type="spec.serialization.Array.D" key="0" id="0"`)); 46 assert(archive.data().containsXmlTag("array", `type="int" length="6" key="arr" id="1"`)); 47 assert(archive.data().containsXmlTag("int", `key="0" id="2"`, "27")); 48 assert(archive.data().containsXmlTag("int", `key="1" id="3"`, "382")); 49 assert(archive.data().containsXmlTag("int", `key="2" id="4"`, "283")); 50 assert(archive.data().containsXmlTag("int", `key="3" id="5"`, "3820")); 51 assert(archive.data().containsXmlTag("int", `key="4" id="6"`, "32")); 52 assert(archive.data().containsXmlTag("int", `key="5" id="7"`, "832")); 53 }; 54 }; 55 56 describe! "deserialize array" in { 57 it! "should return a deserialize array equal to the original array" in { 58 auto dDeserialized = serializer.deserialize!(D)(archive.untypedData); 59 assert(d.arr == dDeserialized.arr); 60 }; 61 }; 62 63 describe! "serialize array of objects" in { 64 it! "sucessfully compiles" in { 65 assert(__traits(compiles, { 66 serializer.serialize(ArrayOfObject()); 67 })); 68 }; 69 }; 70 71 describe! "deserialize array of objects" in { 72 it! "sucessfully compiles" in { 73 assert(__traits(compiles, { 74 serializer.deserialize!(ArrayOfObject)(""); 75 })); 76 }; 77 }; 78 }