Mercurial > projects > orange
annotate tests/Object.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 |
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.Object; |
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 A |
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 equals_t opEquals (Object other) |
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 if (auto o = cast(A) other) |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
23 return true; |
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 return false; |
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 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
29 A a; |
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 unittest |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
32 { |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
33 archive = new XMLArchive!(char); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
34 serializer = new Serializer(archive); |
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 a = new A; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
37 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
38 describe("serialize object") in { |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
39 it("should return a serialized object") in { |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
40 serializer.reset; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
41 serializer.serialize(a); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
42 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
43 assert(archive.data().containsDefaultXmlContent()); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
44 assert(archive.data().contains(`<object runtimeType="tests.Object.A" type="A" key="0" id="0"/>`)); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
45 }; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
46 }; |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
47 |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
48 describe("deserialize object") in { |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
49 it("should return a deserialized object equal to the original object") in { |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
50 auto aDeserialized = serializer.deserialize!(A)(archive.untypedData); |
02dbd18b7fe9
Moved all tests into its own modules.
Jacob Carlborg <doob@me.com>
parents:
diff
changeset
|
51 assert(a == aDeserialized); |
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 } |