annotate tests/Pointer.d @ 51:70df72d2299a default tip

Added unit tests for events.
author Jacob Carlborg <doob@me.com>
date Sat, 13 Aug 2011 17:06:35 +0200
parents 02dbd18b7fe9
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.Pointer;
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 class F
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 int value;
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
21 int* ptr;
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
22 int* ptr2;
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
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
25 F f;
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
26 F fDeserialized;
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
27 int pointee;
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
28
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
29 unittest
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
30 {
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
31 archive = new XMLArchive!(char);
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
32 serializer = new Serializer(archive);
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 pointee = 3;
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
35 f = new F;
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
36 f.value = 9;
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
37 f.ptr = &f.value;
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
38 f.ptr2 = &pointee;
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
39
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
40 describe("serialize pointer") in {
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
41 it("should return a serialized pointer") in {
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
42 serializer.reset();
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
43 serializer.serialize(f);
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
44
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
45 assert(archive.data().containsDefaultXmlContent());
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
46 assert(archive.data().containsXmlTag("object", `runtimeType="tests.Pointer.F" type="F" key="0" id="0"`));
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
47 assert(archive.data().containsXmlTag("pointer", `key="ptr" id="2"`));
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
48 assert(archive.data().containsXmlTag("reference", `key="1"`, "1"));
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
49 assert(archive.data().containsXmlTag("int", `key="value" id="1"`, "9"));
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
50 };
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 describe("deserialize pointer") in {
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
54 fDeserialized = serializer.deserialize!(F)(archive.untypedData);
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
55
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
56 it("should return a deserialized pointer equal to the original pointer") in {
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
57 assert(*f.ptr == *fDeserialized.ptr);
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 it("the pointer should point to the deserialized value") in {
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
61 assert(fDeserialized.ptr == &fDeserialized.value);
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
62 };
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
63 };
02dbd18b7fe9 Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
64 }