annotate tests/Serializer.d @ 27:fc315d786f24 experimental

Added unit testing.
author Jacob Carlborg <doob@me.com>
date Fri, 19 Nov 2010 11:14:55 +0100
parents
children bffcbc8c392b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
1
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
2 /**
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
3 * Copyright: Copyright (c) 2010 Jacob Carlborg. All rights reserved.
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
4 * Authors: Jacob Carlborg
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
5 * Version: Initial created: Nov 5, 2010
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
6 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
7 */
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
8 module tests.Serializer;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
9
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
10 private:
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
11
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
12 import orange.serialization.Serializer;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
13 import orange.serialization.archives.XMLArchive;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
14 import orange.core.io;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
15 import orange.core.string;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
16
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
17 bool containsDefaultXmlContent (string source)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
18 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
19 return source.containsXmlHeader() &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
20 source.containsArchive() &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
21 source.containsXmlTag("data");
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
22 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
23
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
24 bool containsXmlHeader (string source)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
25 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
26 return source.contains(`<?xml version="1.0" encoding="UTF-8"?>`);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
27 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
28
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
29 bool containsArchive (string source)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
30 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
31 return source.containsArchiveHeader() && source.contains("</archive>");
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
32 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
33
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
34 bool containsArchiveHeader (string source)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
35 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
36 return source.contains(`<archive type="org.dsource.orange.xml" version="1.0.0">`);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
37 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
38
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
39 bool containsXmlTag (string source, string tag, bool simple = false)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
40 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
41 return source.containsXmlTag(tag, null, null, simple);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
42 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
43
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
44 bool containsXmlTag (string source, string tag, string attributes, bool simple = false)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
45 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
46 return source.containsXmlTag(tag, attributes, null, simple);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
47 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
48
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
49 bool containsXmlTag (string source, string tag, string attributes, string content, bool simple = false)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
50 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
51 string pattern = '<' ~ tag;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
52
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
53 if (attributes.length > 0)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
54 pattern ~= ' ' ~ attributes;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
55
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
56 if (simple)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
57 return source.contains(pattern ~ "/>");
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
58
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
59 if (content.length > 0)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
60 return source.contains(pattern ~ '>' ~ content ~ "</" ~ tag ~ '>');
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
61
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
62 return source.contains(pattern ~ '>') && source.contains("</" ~ tag ~ '>');
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
63 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
64
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
65 enum Foo { a, b, c }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
66 typedef int Int;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
67
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
68 class A
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
69 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
70 equals_t opEquals (Object other)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
71 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
72 if (auto o = cast(A) other)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
73 return true;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
74
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
75 return false;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
76 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
77 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
78
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
79 struct B
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
80 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
81 equals_t opEquals (B b)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
82 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
83 return true;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
84 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
85 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
86
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
87 class C { string str; }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
88 class D { int[] arr; }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
89 class E { int[int] aa; }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
90 class F { int value; int* ptr; }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
91 class G { Foo foo; }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
92
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
93 class H
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
94 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
95 bool bool_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
96 byte byte_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
97 //cdouble cdouble_; // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
98 //cent cent_; // currently not implemented but a reserved keyword
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
99 //cfloat cfloat_; // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
100 char char_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
101 //creal creal_; // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
102 dchar dchar_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
103 double double_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
104 float float_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
105 //idouble idouble_; // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
106 //ifloat ifloat_; // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
107 int int_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
108 //ireal ireal_; // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
109 long long_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
110 real real_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
111 short short_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
112 ubyte ubyte_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
113 //ucent ucent_; // currently not implemented but a reserved keyword
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
114 uint uint_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
115 ulong ulong_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
116 ushort ushort_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
117 wchar wchar_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
118
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
119 equals_t opEquals (Object other)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
120 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
121 if (auto o = cast(H) other)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
122 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
123 return bool_ == o.bool_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
124 byte_ == o.byte_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
125 //cdouble_ == o.cdouble_ && // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
126 //cent_ == o.cent_ && // currently not implemented but a reserved keyword
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
127 //cfloat_ == o.cfloat_ && // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
128 char_ == o.char_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
129 //creal_ == o.creal_ && // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
130 dchar_ == o.dchar_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
131 double_ == o.double_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
132 float_ == o.float_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
133 //idouble_ == o.idouble_ && // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
134 //ifloat_ == o.ifloat_ && // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
135 int_ == o.int_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
136 //ireal_ == o.ireal_ && // currently not suppported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
137 long_ == o.long_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
138 real_ == o.real_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
139 short_ == o.short_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
140 ubyte_ == o.ubyte_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
141 //ucent_ == o.ucent_ && // currently not implemented but a reserved keyword
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
142 uint_ == o.uint_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
143 ulong_ == o.ulong_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
144 ushort_ == o.ushort_ &&
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
145 wchar_ == o.wchar_;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
146 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
147
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
148 return false;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
149 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
150 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
151
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
152 class I
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
153 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
154 Int a;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
155 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
156
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
157 class J
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
158 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
159 string firstSource;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
160 string firstSlice;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
161
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
162 string secondSlice;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
163 string secondSource;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
164 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
165
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
166 class K
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
167 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
168 int[int] a;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
169 int[int] b;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
170 }
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
171
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
172 import orange.test.UnitTester;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
173 Serializer serializer;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
174 XMLArchive!(char) archive;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
175
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
176 A a;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
177 B b;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
178 C c;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
179 D d;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
180 E e;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
181 F f;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
182 G g;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
183 H h;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
184 I i;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
185 J j;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
186 J jDeserialized;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
187 K k;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
188
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
189 string data;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
190
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
191 unittest
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
192 {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
193 archive = new XMLArchive!(char);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
194 serializer = new Serializer(archive);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
195
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
196 a = new A;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
197
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
198 c = new C;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
199 c.str = "foo";
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
200
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
201 d = new D;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
202 d.arr = [27, 382, 283, 3820, 32, 832].dup;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
203
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
204 e = new E;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
205 e.aa = [3 : 4, 1 : 2, 39 : 472, 6 : 7];
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
206
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
207 f = new F;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
208 f.value = 9;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
209 f.ptr = &f.value;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
210
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
211 g = new G;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
212 g.foo = Foo.b;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
213
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
214 h = new H;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
215 h.bool_ = true;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
216 h.byte_ = 1;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
217 h.char_ = 'a';
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
218 //h.cdouble_ = 0.0 + 0.0 * 1.0i; // currently not supported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
219 //h.cfloat_ = 0.0f + 0.0f * 1.0i; // currently not supported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
220 //h.creal_ = 0.0 + 0.0 * 1.0i; // currently not supported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
221 h.dchar_ = 'b';
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
222 h.double_ = 0.0;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
223 h.float_ = 0.0f;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
224 //h.idouble_ = 0.0 * 1.0i; // currently not supported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
225 //h.ifloat_ = 0.0f * 1.0i; // currently not supported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
226 h.int_ = 1;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
227 //h.ireal_ = 0.0 * 1.0i; // currently not supported by to!()
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
228 h.long_ = 1L;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
229 h.real_ = 0.0;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
230 h.short_ = 1;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
231 h.ubyte_ = 1U;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
232 h.uint_ = 1U;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
233 h.ulong_ = 1LU;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
234 h.ushort_ = 1U;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
235 h.wchar_ = 'c';
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
236
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
237 i = new I;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
238 i.a = 1;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
239
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
240 j = new J;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
241 j.firstSource = "0123456789";
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
242 j.firstSlice = j.firstSource[3 .. 7];
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
243 j.secondSource = "abcdefg";
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
244 j.secondSlice = j.secondSource[1 .. 4];
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
245
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
246 k = new K;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
247 k.a = [3 : 4, 1 : 2, 39 : 472, 6 : 7];
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
248 k.b = k.a;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
249
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
250 describe("Serializer") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
251 describe("serialize object") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
252 it("should return a serialized object") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
253 serializer.reset;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
254 serializer.serialize(a);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
255
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
256 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
257 assert(archive.data().contains(`<object runtimeType="tests.Serializer.A" type="A" key="0" id="0"/>`));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
258 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
259 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
260
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
261 describe("deserialize object") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
262 it("should return a deserialized object equal to the original object") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
263 auto aDeserialized = serializer.deserialize!(A)(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
264 assert(a == aDeserialized);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
265 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
266 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
267
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
268 describe("serialize struct") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
269 it("should return a serialized struct") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
270 serializer.reset;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
271 serializer.serialize(B());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
272
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
273 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
274 assert(archive.data().contains(`<struct type="B" key="0"/>`));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
275 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
276 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
277
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
278 describe("deserialize struct") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
279 it("should return a deserialized struct equal to the original struct") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
280 auto bDeserialized = serializer.deserialize!(B)(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
281 assert(b == bDeserialized);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
282 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
283 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
284
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
285 describe("serialize string") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
286 it("should return a serialized string") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
287 serializer.reset;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
288
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
289 serializer.serialize(c);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
290 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
291 assert(archive.data().containsXmlTag("object", `runtimeType="tests.Serializer.C" type="C" key="0" id="0"`));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
292 assert(archive.data().containsXmlTag("string", `type="char" length="3" key="str" id="1"`, "foo"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
293 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
294 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
295
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
296 describe("deserialize string") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
297 it("should return a deserialized string equal to the original string") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
298 auto cDeserialized = serializer.deserialize!(C)(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
299 assert(c.str == cDeserialized.str);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
300 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
301 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
302
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
303 describe("serialize array") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
304 it("should return a serialized array") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
305 serializer.reset;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
306 serializer.serialize(d);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
307
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
308 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
309 assert(archive.data().containsXmlTag("object", `runtimeType="tests.Serializer.D" type="D" key="0" id="0"`));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
310 assert(archive.data().containsXmlTag("int", `key="0"`, "27"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
311 assert(archive.data().containsXmlTag("int", `key="1"`, "382"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
312 assert(archive.data().containsXmlTag("int", `key="2"`, "283"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
313 assert(archive.data().containsXmlTag("int", `key="3"`, "3820"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
314 assert(archive.data().containsXmlTag("int", `key="4"`, "32"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
315 assert(archive.data().containsXmlTag("int", `key="5"`, "832"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
316 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
317 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
318
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
319 describe("deserialize array") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
320 it("should return a deserialize array equal to the original array") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
321 auto dDeserialized = serializer.deserialize!(D)(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
322 assert(d.arr == dDeserialized.arr);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
323 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
324 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
325
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
326 describe("serialize associative array") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
327 it("should return a serialized associative array") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
328 serializer.reset();
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
329 serializer.serialize(e);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
330
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
331 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
332 assert(archive.data().containsXmlTag("object", `runtimeType="tests.Serializer.E" type="E" key="0" id="0"`));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
333 assert(archive.data().containsXmlTag("associativeArray", `keyType="int" valueType="int" length="4" key="aa"`));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
334
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
335 assert(archive.data().containsXmlTag("key", `key="0"`));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
336 assert(archive.data().containsXmlTag("int", `key="0"`, "1"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
337 assert(archive.data().containsXmlTag("value", `key="0"`));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
338 assert(archive.data().containsXmlTag("int", `key="0"`, "2"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
339
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
340 assert(archive.data().containsXmlTag("key", `key="1"`));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
341 assert(archive.data().containsXmlTag("int", `key="1"`, "3"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
342 assert(archive.data().containsXmlTag("value", `key="1"`));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
343 assert(archive.data().containsXmlTag("int", `key="1"`, "4"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
344
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
345 assert(archive.data().containsXmlTag("key", `key="2"`));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
346 assert(archive.data().containsXmlTag("int", `key="2"`, "6"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
347 assert(archive.data().containsXmlTag("value", `key="2"`));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
348 assert(archive.data().containsXmlTag("int", `key="2"`, "7"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
349
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
350 assert(archive.data().containsXmlTag("key", `key="3"`));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
351 assert(archive.data().containsXmlTag("int", `key="3"`, "39"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
352 assert(archive.data().containsXmlTag("value", `key="3"`));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
353 assert(archive.data().containsXmlTag("int", `key="3"`, "472"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
354 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
355 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
356
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
357 describe("deserialize associative array") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
358 it("should return an associative array equal to the original associative array") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
359 auto eDeserialized = serializer.deserialize!(E)(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
360
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
361 foreach (k, v ; eDeserialized.aa)
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
362 assert(e.aa[k] == v);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
363
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
364 //assert(e.aa == eDeserialized.aa); // cannot compare associative array
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
365 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
366 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
367
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
368 describe("serialize pointer") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
369 it("should return a serialized pointer") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
370 serializer.reset();
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
371
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
372 serializer.serialize(f);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
373 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
374 assert(archive.data().containsXmlTag("object", `runtimeType="tests.Serializer.F" type="F" key="0" id="0"`));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
375 assert(archive.data().containsXmlTag("pointer", `key="ptr" id="2"`));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
376 assert(archive.data().containsXmlTag("int", `key="1"`, "9"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
377 assert(archive.data().containsXmlTag("int", `key="value"`, "9"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
378 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
379 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
380
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
381 describe("deserialize pointer") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
382 it("should return a deserialized pointer equal to the original pointer") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
383 auto fDeserialized = serializer.deserialize!(F)(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
384 assert(*f.ptr == *fDeserialized.ptr);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
385 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
386 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
387
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
388 describe("serialize enum") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
389 it("should return a serialized enum") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
390 serializer.reset();
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
391 serializer.serialize(g);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
392 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
393 assert(archive.data().containsXmlTag("object", `runtimeType="tests.Serializer.G" type="G" key="0" id="0"`));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
394 assert(archive.data().containsXmlTag("enum", `type="Foo" baseType="int" key="foo"`, "1"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
395 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
396 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
397
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
398
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
399 describe("deserialize enum") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
400 it("should return an enum equal to the original enum") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
401 auto gDeserialized = serializer.deserialize!(G)(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
402 assert(g.foo == gDeserialized.foo);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
403 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
404 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
405
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
406 describe("serialize primitives") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
407 it("should return serialized primitives") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
408 serializer.reset;
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
409
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
410 serializer.serialize(h);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
411 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
412 assert(archive.data().containsXmlTag("object", `runtimeType="tests.Serializer.H" type="H" key="0" id="0"`));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
413 assert(archive.data().containsXmlTag("byte", `key="byte_"`, "1"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
414 assert(archive.data().containsXmlTag("char", `key="char_"`, "a"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
415 assert(archive.data().containsXmlTag("dchar", `key="dchar_"`, "b"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
416 assert(archive.data().containsXmlTag("double", `key="double_"`, "0"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
417 assert(archive.data().containsXmlTag("float", `key="float_"`, "0"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
418 assert(archive.data().containsXmlTag("int", `key="int_"`, "1"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
419 assert(archive.data().containsXmlTag("long", `key="long_"`, "1"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
420 assert(archive.data().containsXmlTag("real", `key="real_"`, "0"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
421 assert(archive.data().containsXmlTag("short", `key="short_"`, "1"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
422 assert(archive.data().containsXmlTag("ubyte", `key="ubyte_"`, "1"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
423 assert(archive.data().containsXmlTag("uint", `key="uint_"`, "1"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
424 assert(archive.data().containsXmlTag("ulong", `key="ulong_"`, "1"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
425 assert(archive.data().containsXmlTag("ushort", `key="ushort_"`, "1"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
426 assert(archive.data().containsXmlTag("wchar", `key="wchar_"`, "c"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
427 assert(archive.data().containsXmlTag("bool", `key="bool_"`, "true"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
428 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
429 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
430
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
431 describe("deserialize primitives") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
432 it("should return deserialized primitives equal to the original primitives") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
433 auto hDeserialized = serializer.deserialize!(H)(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
434 assert(h == hDeserialized);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
435 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
436 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
437
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
438 describe("serialize typedef") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
439 it("should return a serialized typedef") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
440 serializer.reset();
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
441 serializer.serialize(i);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
442 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
443 assert(archive.data().containsXmlTag("object", `runtimeType="tests.Serializer.I" type="I" key="0" id="0"`));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
444 assert(archive.data().containsXmlTag("typedef", `type="Int" key="a"`));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
445 assert(archive.data().containsXmlTag("int", `key="1"`, "1"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
446 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
447 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
448
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
449 describe("deserialize typedef") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
450 it("should return a deserialized typedef equal to the original typedef") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
451 auto iDeserialized = serializer.deserialize!(I)(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
452 assert(i.a == iDeserialized.a);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
453 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
454 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
455
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
456 describe("serialize slices") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
457 it("should return serialized slices") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
458 serializer.reset();
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
459 serializer.serialize(j);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
460
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
461 assert(archive.data().containsDefaultXmlContent());
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
462 assert(archive.data().containsXmlTag("object", `runtimeType="tests.Serializer.J" type="J" key="0" id="0"`));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
463 assert(archive.data().containsXmlTag("string", `type="char" length="10" key="firstSource" id="1"`, "0123456789"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
464 assert(archive.data().containsXmlTag("slice", `key="firstSlice" offset="3" length="4"`, "1"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
465 assert(archive.data().containsXmlTag("slice", `key="secondSlice" offset="1" length="3"`, "4"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
466 assert(archive.data().containsXmlTag("string", `type="char" length="7" key="secondSource" id="4"`, "abcdefg"));
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
467 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
468 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
469
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
470 describe("deserialize slices") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
471 jDeserialized = serializer.deserialize!(J)(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
472
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
473 it("should return deserialized strings equal to the original strings") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
474 assert(j.firstSource == jDeserialized.firstSource);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
475 assert(j.secondSource == jDeserialized.secondSource);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
476 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
477
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
478 it("should return deserialized slices equal to the original slices") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
479 assert(j.firstSlice == jDeserialized.firstSlice);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
480 assert(j.secondSlice == jDeserialized.secondSlice);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
481 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
482
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
483 it("the slices should be equal to a slice of the original sources") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
484 assert(jDeserialized.firstSource[3 .. 7] == jDeserialized.firstSlice);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
485 assert(jDeserialized.secondSource[1 .. 4] == jDeserialized.secondSlice);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
486
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
487 assert(j.firstSource[3 .. 7] == jDeserialized.firstSlice);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
488 assert(j.secondSource[1 .. 4] == jDeserialized.secondSlice);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
489 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
490
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
491 it("the slices should be able to modify the sources") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
492 jDeserialized.firstSlice[0] = 'a';
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
493 jDeserialized.secondSlice[0] = '0';
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
494
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
495 assert(jDeserialized.firstSource == "012a456789");
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
496 assert(jDeserialized.secondSource == "a0cdefg");
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
497 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
498 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
499
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
500 describe("associative array references") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
501 it("should return ") in {
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
502 serializer.reset();
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
503 serializer.serialize(k);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
504 println(archive.data);
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
505 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
506 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
507 };
fc315d786f24 Added unit testing.
Jacob Carlborg <doob@me.com>
parents:
diff changeset
508 }