changeset 43:6f35fb47ca24

Added test for serializing subclasses.
author Jacob Carlborg <doob@me.com>
date Tue, 09 Aug 2011 09:26:57 +0200
parents 8b9409423740
children 1fef41162966
files orange/serialization/archives/XMLArchive.d tests/Subclass.d unittest.sh
diffstat 3 files changed, 65 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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)
--- /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
--- 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