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.Array;
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 class D
18 {
19     int[] arr;
20     int[2] arr2;
21 }
22 
23 D d;
24 
25 unittest
26 {
27     archive = new XmlArchive!(char);
28     serializer = new Serializer(archive);
29 
30     d = new D;
31     d.arr = [27, 382, 283, 3820, 32, 832].dup;
32     d.arr2 = [76, 34];
33 
34     describe("serialize array") in {
35         it("should return a serialized array") in {
36             auto expected = q"xml
37 <?xml version="1.0" encoding="UTF-8"?>
38 <archive version="1.0.0" type="org.dsource.orange.xml">
39     <data>
40         <object runtimeType="tests.Array.D" type="tests.Array.D" key="0" id="0">
41             <array type="int" length="2" key="arr2" id="8">
42                 <int key="0" id="9">76</int>
43                 <int key="1" id="10">34</int>
44             </array>
45             <array type="int" length="6" key="arr" id="1">
46                 <int key="0" id="2">27</int>
47                 <int key="1" id="3">382</int>
48                 <int key="2" id="4">283</int>
49                 <int key="3" id="5">3820</int>
50                 <int key="4" id="6">32</int>
51                 <int key="5" id="7">832</int>
52             </array>
53         </object>
54     </data>
55 </archive>
56 xml";
57 
58             serializer.reset;
59             serializer.serialize(d);
60 
61             assert(expected.equalToXml(archive.data));
62         };
63     };
64 
65     describe("deserialize array") in {
66         it("should return a deserialize array equal to the original array") in {
67             auto dDeserialized = serializer.deserialize!(D)(archive.untypedData);
68             assert(d.arr == dDeserialized.arr);
69             assert(d.arr2 == dDeserialized.arr2);
70         };
71     };
72 }