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.Object; 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 class A 18 { 19 override equals_t opEquals (Object other) 20 { 21 if (auto o = cast(A) other) 22 return true; 23 24 return false; 25 } 26 } 27 28 A a; 29 30 unittest 31 { 32 archive = new XmlArchive!(char); 33 serializer = new Serializer(archive); 34 35 a = new A; 36 37 describe("serialize object") in { 38 it("should return a serialized object") in { 39 auto expected = q"xml 40 <?xml version="1.0" encoding="UTF-8"?> 41 <archive version="1.0.0" type="org.dsource.orange.xml"> 42 <data> 43 <object runtimeType="tests.Object.A" type="tests.Object.A" key="0" id="0"/> 44 </data> 45 </archive> 46 xml"; 47 serializer.reset; 48 serializer.serialize(a); 49 50 assert(expected.equalToXml(archive.data)); 51 }; 52 }; 53 54 describe("deserialize object") in { 55 it("should return a deserialized object equal to the original object") in { 56 auto aDeserialized = serializer.deserialize!(A)(archive.untypedData); 57 assert(a == aDeserialized); 58 }; 59 }; 60 }