51
|
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.Events;
|
|
8
|
|
9 import orange.core._;
|
|
10 import orange.serialization.Serializer;
|
|
11 import orange.serialization.Events;
|
|
12 import orange.serialization.archives.XMLArchive;
|
|
13 import orange.test.UnitTester;
|
|
14 import tests.Util;
|
|
15
|
|
16 Serializer serializer;
|
|
17 XMLArchive!(char) archive;
|
|
18
|
|
19 int b;
|
|
20 int c;
|
|
21
|
|
22 class Events
|
|
23 {
|
|
24 int a;
|
|
25 int d;
|
|
26
|
|
27 void serializing ()
|
|
28 {
|
|
29 a = 3;
|
|
30 }
|
|
31
|
|
32 mixin OnSerializing!(serializing);
|
|
33
|
|
34 void serialized ()
|
|
35 {
|
|
36 b = 4;
|
|
37 }
|
|
38
|
|
39 mixin OnSerialized!(serialized);
|
|
40
|
|
41 void deserializing ()
|
|
42 {
|
|
43 c = 5;
|
|
44 }
|
|
45
|
|
46 mixin OnDeserializing!(deserializing);
|
|
47
|
|
48 void deserialized ()
|
|
49 {
|
|
50 d = 6;
|
|
51 }
|
|
52
|
|
53 mixin OnDeserialized!(deserialized);
|
|
54 }
|
|
55
|
|
56 Events events;
|
|
57
|
|
58 unittest
|
|
59 {
|
|
60 archive = new XMLArchive!(char);
|
|
61 serializer = new Serializer(archive);
|
|
62
|
|
63 events = new Events;
|
|
64
|
|
65 describe("serialize a class with event handlers") in {
|
|
66 it("should return serialized class with the correct values set by the event handlers") in {
|
|
67 serializer.reset;
|
|
68 serializer.serialize(events);
|
|
69
|
|
70 assert(archive.data().containsDefaultXmlContent());
|
|
71 assert(archive.data().containsXmlTag("object", `runtimeType="tests.Events.Events" type="Events" key="0" id="0"`));
|
|
72 assert(archive.data().containsXmlTag("int", `key="a" id="1"`, "3"));
|
|
73 assert(archive.data().containsXmlTag("int", `key="d" id="2"`, "0"));
|
|
74
|
|
75 assert(b == 4);
|
|
76 };
|
|
77 };
|
|
78
|
|
79 describe("deserialize class with a base class") in {
|
|
80 it("should return a deserialized string equal to the original string") in {
|
|
81 auto eventsDeserialized = serializer.deserialize!(Events)(archive.untypedData);
|
|
82
|
|
83 assert(eventsDeserialized.a == 3);
|
|
84 assert(eventsDeserialized.d == 6);
|
|
85
|
|
86 assert(c == 5);
|
|
87 };
|
|
88 };
|
|
89 } |