# HG changeset patch # User Jacob Carlborg # Date 1312874817 -7200 # Node ID 6f35fb47ca242f3bdfcd8bd9c72132f5fca3d92c # Parent 8b940942374027a2eeec4161c3d89290d02035a6 Added test for serializing subclasses. diff -r 8b9409423740 -r 6f35fb47ca24 orange/serialization/archives/XMLArchive.d --- a/orange/serialization/archives/XMLArchive.d Sun Aug 07 17:53:50 2011 +0200 +++ b/orange/serialization/archives/XMLArchive.d Tue Aug 09 09:26:57 2011 +0200 @@ -280,12 +280,10 @@ void archiveBaseClass (string type, string key, Id id) { - restore(lastElement) in { - lastElement = lastElement.element(Tags.baseTag) - .attribute(Attributes.typeAttribute, toData(type)) - .attribute(Attributes.keyAttribute, toData(key)) - .attribute(Attributes.idAttribute, toData(id)); - }; + lastElement = lastElement.element(Tags.baseTag) + .attribute(Attributes.typeAttribute, toData(type)) + .attribute(Attributes.keyAttribute, toData(key)) + .attribute(Attributes.idAttribute, toData(id)); } void archiveNull (string type, string key) diff -r 8b9409423740 -r 6f35fb47ca24 tests/Subclass.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/Subclass.d Tue Aug 09 09:26:57 2011 +0200 @@ -0,0 +1,60 @@ +/** + * Copyright: Copyright (c) 2011 Jacob Carlborg. All rights reserved. + * Authors: Jacob Carlborg + * Version: Initial created: Aug 7, 2011 + * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) + */ +module tests.Subclass; + +import orange.core.string; +import orange.serialization.Serializer; +import orange.serialization.archives.XMLArchive; +import orange.test.UnitTester; +import tests.Util; + +Serializer serializer; +XMLArchive!(char) archive; + +class Base +{ + int a; +} + +class Sub : Base +{ + int b; +} + +Sub sub; + +unittest +{ + archive = new XMLArchive!(char); + serializer = new Serializer(archive); + + sub = new Sub; + sub.a = 3; + sub.b = 4; + + describe("serialize a subclass") in { + it("should return serialized subclass") in { + serializer.reset; + serializer.serialize(sub); + + assert(archive.data().containsDefaultXmlContent()); + assert(archive.data().containsXmlTag("object", `runtimeType="tests.Subclass.Sub" type="Sub" key="0" id="0"`)); + assert(archive.data().containsXmlTag("int", `key="b" id="1"`, "4")); + assert(archive.data().containsXmlTag("base", `type="Base" key="1" id="2"`)); + assert(archive.data().containsXmlTag("int", `key="a" id="3"`, "3")); + }; + }; + + // describe("deserialize class with a base class") in { + // it("should return a deserialized string equal to the original string") in { + // auto subDeserialized = serializer.deserialize!(Sub)(archive.untypedData); + // + // assert(sub.a == subDeserialized.a); + // assert(sub.b == subDeserialized.b); + // }; + // }; +} \ No newline at end of file diff -r 8b9409423740 -r 6f35fb47ca24 unittest.sh --- a/unittest.sh Sun Aug 07 17:53:50 2011 +0200 +++ b/unittest.sh Tue Aug 09 09:26:57 2011 +0200 @@ -37,6 +37,7 @@ tests/Slice.d \ tests/String.d \ tests/Struct.d \ +tests/Subclass.d \ tests/Typedef.d \ tests/Util.d \ tests/_.d