comparison tests/Struct.d @ 40:02dbd18b7fe9

Moved all tests into its own modules.
author Jacob Carlborg <doob@me.com>
date Sat, 06 Aug 2011 13:27:21 +0200
parents
children
comparison
equal deleted inserted replaced
39:301476d40518 40:02dbd18b7fe9
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.Struct;
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 struct B
19 {
20 version (Tango)
21 {
22 equals_t opEquals (B b)
23 {
24 return true;
25 }
26 }
27
28 else
29 {
30 mixin(`bool opEquals (ref const B) const
31 {
32 return true;
33 }`);
34 }
35 }
36
37 B b;
38
39 unittest
40 {
41 archive = new XMLArchive!(char);
42 serializer = new Serializer(archive);
43
44 describe("serialize struct") in {
45 it("should return a serialized struct") in {
46 serializer.reset;
47 serializer.serialize(B());
48
49 assert(archive.data().containsDefaultXmlContent());
50 assert(archive.data().contains(`<struct type="B" key="0" id="0"/>`));
51 };
52 };
53
54 describe("deserialize struct") in {
55 it("should return a deserialized struct equal to the original struct") in {
56 auto bDeserialized = serializer.deserialize!(B)(archive.untypedData);
57 assert(b == bDeserialized);
58 };
59 };
60 }