diff tests/Subclass.d @ 43:6f35fb47ca24

Added test for serializing subclasses.
author Jacob Carlborg <doob@me.com>
date Tue, 09 Aug 2011 09:26:57 +0200
parents
children 9c9bbef6bf5e
line wrap: on
line diff
--- /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