annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
40
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1 /**
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
2 * Copyright: Copyright (c) 2011 Jacob Carlborg. All rights reserved.
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
3 * Authors: Jacob Carlborg
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
4 * Version: Initial created: Aug 6, 2011
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
6 */
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
7 module tests.Struct;
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
8
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
9 import orange.core.string;
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
10 import orange.serialization.Serializer;
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
11 import orange.serialization.archives.XMLArchive;
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
12 import orange.test.UnitTester;
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
13 import tests.Util;
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
14
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
15 Serializer serializer;
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
16 XMLArchive!(char) archive;
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
17
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
18 struct B
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
19 {
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
20 version (Tango)
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
21 {
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
22 equals_t opEquals (B b)
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
23 {
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
24 return true;
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
25 }
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
26 }
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
27
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
28 else
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
29 {
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
30 mixin(`bool opEquals (ref const B) const
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
31 {
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
32 return true;
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
33 }`);
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
34 }
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
35 }
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
36
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
37 B b;
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
38
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
39 unittest
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
40 {
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
41 archive = new XMLArchive!(char);
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
42 serializer = new Serializer(archive);
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
43
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
44 describe("serialize struct") in {
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
45 it("should return a serialized struct") in {
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
46 serializer.reset;
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
47 serializer.serialize(B());
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
48
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
49 assert(archive.data().containsDefaultXmlContent());
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
50 assert(archive.data().contains(`<struct type="B" key="0" id="0"/>`));
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
51 };
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
52 };
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
53
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
54 describe("deserialize struct") in {
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
55 it("should return a deserialized struct equal to the original struct") in {
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
56 auto bDeserialized = serializer.deserialize!(B)(archive.untypedData);
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
57 assert(b == bDeserialized);
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
58 };
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
59 };
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
60 }