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