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.Enum;
8 
9 import orange.serialization.Serializer;
10 import orange.serialization.archives.XmlArchive;
11 import orange.test.UnitTester;
12 import tests.Util;
13 
14 Serializer serializer;
15 XmlArchive!(char) archive;
16 
17 enum Foo
18 {
19     a,
20     b,
21     c
22 }
23 
24 class G
25 {
26     Foo foo;
27 }
28 
29 G g;
30 
31 unittest
32 {
33     archive = new XmlArchive!(char);
34     serializer = new Serializer(archive);
35 
36     g = new G;
37     g.foo = Foo.b;
38 
39     describe("serialize enum") in {
40         it("should return a serialized enum") in {
41             auto expected = q"xml
42 <?xml version="1.0" encoding="UTF-8"?>
43 <archive version="1.0.0" type="org.dsource.orange.xml">
44     <data>
45         <object runtimeType="tests.Enum.G" type="tests.Enum.G" key="0" id="0">
46             <enum type="tests.Enum.Foo" baseType="int" key="foo" id="1">1</enum>
47         </object>
48     </data>
49 </archive>
50 xml";
51 
52             serializer.reset();
53             serializer.serialize(g);
54 
55             assert(expected.equalToXml(archive.data));
56         };
57     };
58 
59 
60     describe("deserialize enum") in {
61         it("should return an enum equal to the original enum") in {
62             auto gDeserialized = serializer.deserialize!(G)(archive.untypedData);
63             assert(g.foo == gDeserialized.foo);
64         };
65     };
66 }