comparison tests/Event.d @ 42:8b9409423740

Added unit tests for (de)serializing events.
author Jacob Carlborg <doob@me.com>
date Sun, 07 Aug 2011 17:53:50 +0200
parents
children
comparison
equal deleted inserted replaced
41:b538d02578cb 42:8b9409423740
1 /**
2 * Copyright: Copyright (c) 2011 Jacob Carlborg. All rights reserved.
3 * Authors: Jacob Carlborg
4 * Version: Initial created: Aug 6, 2011
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
6 */
7 module tests.Event;
8
9 import orange.core.string;
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[] arr;
20
21 class Foo
22 {
23
24 void serializing ()
25 {
26 arr ~= 1;
27 }
28
29 void serialized ()
30 {
31 arr ~= 2;
32 }
33
34 void deserializing ()
35 {
36 arr ~= 3;
37 }
38
39 void deserialized ()
40 {
41 arr ~= 4;
42 }
43
44 mixin OnSerializing!(serializing);
45 mixin OnSerialized!(serialized);
46 mixin OnDeserializing!(deserializing);
47 mixin OnDeserialized!(deserialized);
48 }
49
50 unittest
51 {
52 archive = new XMLArchive!(char);
53 serializer = new Serializer(archive);
54
55 describe("serialization events") in {
56 it("all four events should be triggered when serializing and deserializing") in {
57 serializer.serialize(new Foo);
58 serializer.deserialize!(Foo)(archive.untypedData);
59
60 assert(arr == [1, 2, 3, 4]);
61 };
62 };
63 }