comparison mde/file/mergetag/MTTagUnittest.d @ 136:4084f07f2c7a

Added simpler mergetag readers and writers, with unittest.
author Diggory Hardy <diggory.hardy@gmail.com>
date Sun, 01 Feb 2009 12:36:21 +0000
parents
children 9f035cd139c6
comparison
equal deleted inserted replaced
135:bc697a218716 136:4084f07f2c7a
1 /* LICENSE BLOCK
2 Part of mde: a Modular D game-oriented Engine
3 Copyright © 2007-2008 Diggory Hardy
4
5 This program is free software: you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free Software
7 Foundation, either version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11 PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
15
16 /******************************************************************************
17 * A unittest for the tag reader and writer.
18 *****************************************************************************/
19 module mde.file.mergetag.MTTagUnittest;
20
21 debug (mdeUnitTest) {
22 import mde.file.mergetag.MTTagReader;
23 import mde.file.mergetag.MTTagWriter;
24 import tango.io.FilePath;
25 import tango.util.log.Log : Log, Logger;
26
27 private Logger logger;
28 static this() {
29 logger = Log.getLogger ("mde.file.mergetag.MTTagUnittest");
30 }
31
32 unittest {
33 auto file = FilePath("unittest.mtt");
34 struct S {
35 char[] type, id, data;
36 }
37 static S tag1 = { type:"t1", id:"i1", data:"123"};
38 static S tag2 = { type:"t2", id:"i2", data:"abc"};
39 static S tag3 = { type:"t3", id:"i3", data:"\" a string \""};
40 static S tag4 = { type:"t1", id:"i1", data:"5.-98"};
41
42 MTTagWriter w = makeMTTagWriter (file.toString);
43 w.dataTag (tag2.type, tag2.id, tag2.data);
44 w.sectionTag ("one");
45 w.dataTag (tag1.type, tag1.id, tag1.data);
46 w.sectionTag ("three");
47 w.dataTag (tag3.type, tag3.id, tag3.data);
48 w.writeTag ("one", tag4.type, tag4.id, tag4.data);
49 w.close;
50
51 MTTagReader r = makeMTTagReader (file);
52 bool isSecTag;
53 while (r.readTag (isSecTag)) {
54 if (isSecTag) continue;
55 if (r.tagID == tag1.id) {
56 assert (r.tagType == tag1.type, r.tagID);
57 assert (r.tagData == tag1.data || r.tagData == tag4.data, r.tagID);
58 } else if (r.tagID == tag2.id) {
59 assert (r.tagType == tag2.type, r.tagID);
60 assert (r.tagData == tag2.data, r.tagID);
61 } else if (r.tagID == tag3.id) {
62 assert (r.tagType == tag3.type, r.tagID);
63 assert (r.tagData == tag3.data, r.tagID);
64 } else assert (false, "extra tag: "~r.tagID);
65 }
66
67 // Delete the unittest file now
68 file.remove;
69
70 logger.info ("Unittest complete.");
71 }
72 }
73