Mercurial > projects > orange
comparison tests/Primitive.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 | 1fef41162966 |
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.Primitive; | |
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 class H | |
19 { | |
20 bool bool_; | |
21 byte byte_; | |
22 //cdouble cdouble_; // currently not suppported by to!() | |
23 //cent cent_; // currently not implemented but a reserved keyword | |
24 //cfloat cfloat_; // currently not suppported by to!() | |
25 char char_; | |
26 //creal creal_; // currently not suppported by to!() | |
27 dchar dchar_; | |
28 double double_; | |
29 float float_; | |
30 //idouble idouble_; // currently not suppported by to!() | |
31 //ifloat ifloat_; // currently not suppported by to!() | |
32 int int_; | |
33 //ireal ireal_; // currently not suppported by to!() | |
34 long long_; | |
35 real real_; | |
36 short short_; | |
37 ubyte ubyte_; | |
38 //ucent ucent_; // currently not implemented but a reserved keyword | |
39 uint uint_; | |
40 ulong ulong_; | |
41 ushort ushort_; | |
42 | |
43 version (Tango) | |
44 wchar wchar_; // Phobos to!() function can't handle string -> wchar | |
45 | |
46 equals_t opEquals (Object other) | |
47 { | |
48 if (auto o = cast(H) other) | |
49 { | |
50 auto result = bool_ == o.bool_ && | |
51 byte_ == o.byte_ && | |
52 //cdouble_ == o.cdouble_ && // currently not suppported by to!() | |
53 //cent_ == o.cent_ && // currently not implemented but a reserved keyword | |
54 //cfloat_ == o.cfloat_ && // currently not suppported by to!() | |
55 char_ == o.char_ && | |
56 //creal_ == o.creal_ && // currently not suppported by to!() | |
57 dchar_ == o.dchar_ && | |
58 double_ == o.double_ && | |
59 float_ == o.float_ && | |
60 //idouble_ == o.idouble_ && // currently not suppported by to!() | |
61 //ifloat_ == o.ifloat_ && // currently not suppported by to!() | |
62 int_ == o.int_ && | |
63 //ireal_ == o.ireal_ && // currently not suppported by to!() | |
64 long_ == o.long_ && | |
65 real_ == o.real_ && | |
66 short_ == o.short_ && | |
67 ubyte_ == o.ubyte_ && | |
68 //ucent_ == o.ucent_ && // currently not implemented but a reserved keyword | |
69 uint_ == o.uint_ && | |
70 ulong_ == o.ulong_ && | |
71 ushort_ == o.ushort_; | |
72 | |
73 version (Tango) | |
74 return result && wchar_ == o.wchar_; | |
75 | |
76 else | |
77 return result; | |
78 } | |
79 | |
80 return false; | |
81 } | |
82 } | |
83 | |
84 H h; | |
85 | |
86 unittest | |
87 { | |
88 archive = new XMLArchive!(char); | |
89 serializer = new Serializer(archive); | |
90 | |
91 h = new H; | |
92 h.bool_ = true; | |
93 h.byte_ = 1; | |
94 h.char_ = 'a'; | |
95 //h.cdouble_ = 0.0 + 0.0 * 1.0i; // currently not supported by to!() | |
96 //h.cfloat_ = 0.0f + 0.0f * 1.0i; // currently not supported by to!() | |
97 //h.creal_ = 0.0 + 0.0 * 1.0i; // currently not supported by to!() | |
98 h.dchar_ = 'b'; | |
99 h.double_ = 0.0; | |
100 h.float_ = 0.0f; | |
101 //h.idouble_ = 0.0 * 1.0i; // currently not supported by to!() | |
102 //h.ifloat_ = 0.0f * 1.0i; // currently not supported by to!() | |
103 h.int_ = 1; | |
104 //h.ireal_ = 0.0 * 1.0i; // currently not supported by to!() | |
105 h.long_ = 1L; | |
106 h.real_ = 0.0; | |
107 h.short_ = 1; | |
108 h.ubyte_ = 1U; | |
109 h.uint_ = 1U; | |
110 h.ulong_ = 1LU; | |
111 h.ushort_ = 1U; | |
112 | |
113 version (Tango) | |
114 h.wchar_ = 'c'; | |
115 | |
116 describe("serialize primitives") in { | |
117 it("should return serialized primitives") in { | |
118 serializer.reset; | |
119 serializer.serialize(h); | |
120 | |
121 assert(archive.data().containsDefaultXmlContent()); | |
122 assert(archive.data().containsXmlTag("object", `runtimeType="tests.Primitive.H" type="H" key="0" id="0"`)); | |
123 assert(archive.data().containsXmlTag("bool", `key="bool_" id="1"`, "true")); | |
124 assert(archive.data().containsXmlTag("byte", `key="byte_" id="2"`, "1")); | |
125 assert(archive.data().containsXmlTag("char", `key="char_" id="3"`, "a")); | |
126 assert(archive.data().containsXmlTag("dchar", `key="dchar_" id="4"`, "b")); | |
127 assert(archive.data().containsXmlTag("double", `key="double_" id="5"`, "0")); | |
128 assert(archive.data().containsXmlTag("float", `key="float_" id="6"`, "0")); | |
129 assert(archive.data().containsXmlTag("int", `key="int_" id="7"`, "1")); | |
130 assert(archive.data().containsXmlTag("long", `key="long_" id="8"`, "1")); | |
131 assert(archive.data().containsXmlTag("real", `key="real_" id="9"`, "0")); | |
132 assert(archive.data().containsXmlTag("short", `key="short_" id="10"`, "1")); | |
133 assert(archive.data().containsXmlTag("ubyte", `key="ubyte_" id="11"`, "1")); | |
134 assert(archive.data().containsXmlTag("uint", `key="uint_" id="12"`, "1")); | |
135 assert(archive.data().containsXmlTag("ulong", `key="ulong_" id="13"`, "1")); | |
136 assert(archive.data().containsXmlTag("ushort", `key="ushort_" id="14"`, "1")); | |
137 | |
138 version (Tango) | |
139 assert(archive.data().containsXmlTag("wchar", `key="wchar_" id="15"`, "c")); | |
140 }; | |
141 }; | |
142 | |
143 describe("deserialize primitives") in { | |
144 it("should return deserialized primitives equal to the original primitives") in { | |
145 auto hDeserialized = serializer.deserialize!(H)(archive.untypedData); | |
146 assert(h == hDeserialized); | |
147 }; | |
148 }; | |
149 } |