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 tests.Struct; 8 9 import orange.serialization.Serializer; 10 import orange.serialization.archives.XmlArchive; 11 import orange.test.UnitTester; 12 import tests.Util; 13 14 Serializer serializer; 15 XmlArchive!(char) archive; 16 17 struct B 18 { 19 bool opEquals (ref const B) const 20 { 21 return true; 22 } 23 } 24 25 B b; 26 27 unittest 28 { 29 archive = new XmlArchive!(char); 30 serializer = new Serializer(archive); 31 32 describe("serialize struct") in { 33 it("should return a serialized struct") in { 34 auto expected = q"xml 35 <?xml version="1.0" encoding="UTF-8"?> 36 <archive version="1.0.0" type="org.dsource.orange.xml"> 37 <data> 38 <struct type="tests.Struct.B" key="0" id="0"/> 39 </data> 40 </archive> 41 xml"; 42 serializer.reset; 43 serializer.serialize(B()); 44 45 assert(expected.equalToXml(archive.data)); 46 }; 47 }; 48 49 describe("deserialize struct") in { 50 it("should return a deserialized struct equal to the original struct") in { 51 auto bDeserialized = serializer.deserialize!(B)(archive.untypedData); 52 assert(b == bDeserialized); 53 }; 54 }; 55 }