Mercurial > projects > orange
comparison 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 |
comparison
equal
deleted
inserted
replaced
42:8b9409423740 | 43:6f35fb47ca24 |
---|---|
1 /** | |
2 * Copyright: Copyright (c) 2011 Jacob Carlborg. All rights reserved. | |
3 * Authors: Jacob Carlborg | |
4 * Version: Initial created: Aug 7, 2011 | |
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | |
6 */ | |
7 module tests.Subclass; | |
8 | |
9 import orange.core.string; | |
10 import orange.serialization.Serializer; | |
11 import orange.serialization.archives.XMLArchive; | |
12 import orange.test.UnitTester; | |
13 import tests.Util; | |
14 | |
15 Serializer serializer; | |
16 XMLArchive!(char) archive; | |
17 | |
18 class Base | |
19 { | |
20 int a; | |
21 } | |
22 | |
23 class Sub : Base | |
24 { | |
25 int b; | |
26 } | |
27 | |
28 Sub sub; | |
29 | |
30 unittest | |
31 { | |
32 archive = new XMLArchive!(char); | |
33 serializer = new Serializer(archive); | |
34 | |
35 sub = new Sub; | |
36 sub.a = 3; | |
37 sub.b = 4; | |
38 | |
39 describe("serialize a subclass") in { | |
40 it("should return serialized subclass") in { | |
41 serializer.reset; | |
42 serializer.serialize(sub); | |
43 | |
44 assert(archive.data().containsDefaultXmlContent()); | |
45 assert(archive.data().containsXmlTag("object", `runtimeType="tests.Subclass.Sub" type="Sub" key="0" id="0"`)); | |
46 assert(archive.data().containsXmlTag("int", `key="b" id="1"`, "4")); | |
47 assert(archive.data().containsXmlTag("base", `type="Base" key="1" id="2"`)); | |
48 assert(archive.data().containsXmlTag("int", `key="a" id="3"`, "3")); | |
49 }; | |
50 }; | |
51 | |
52 // describe("deserialize class with a base class") in { | |
53 // it("should return a deserialized string equal to the original string") in { | |
54 // auto subDeserialized = serializer.deserialize!(Sub)(archive.untypedData); | |
55 // | |
56 // assert(sub.a == subDeserialized.a); | |
57 // assert(sub.b == subDeserialized.b); | |
58 // }; | |
59 // }; | |
60 } |