Mercurial > projects > mde
view mde/mergetag/mtunittest.d @ 26:611f7b9063c6
Changed the licensing and removed a few dead files.
Changed licensing to "GPL version 2 or later" to avoid future compatibility issues.
Also a unittest fix to the previous commit.
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 03 Apr 2008 18:15:02 +0100 |
parents | 5f90774ea1ef |
children | 467c74d4804d |
line wrap: on
line source
/* LICENSE BLOCK Part of mde: a Modular D game-oriented Engine Copyright © 2007-2008 Diggory Hardy This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ /// This module provides a unittest for mergetag. module mde.mergetag.mtunittest; import mde.mergetag.Reader; import mde.mergetag.Writer; import mde.mergetag.DataSet; import mde.mergetag.DefaultData; import tango.scrapple.text.convert.parseTo : parseTo; import tango.scrapple.text.convert.parseFrom : parseFrom; import tango.util.log.Log : Log, Logger; debug (mdeUnitTest) { private Logger logger; static this() { logger = Log.getLogger ("mde.mergetag.mtunittest"); } unittest { /* This does a basic write-out and read-in test for each type with its default value. * Thus it provides some basic testing for the whole mergetag package. */ const file = "unittest"; const ID UT_ID = cast (ID) "mdeUT"; const headInfo = "mde Unit Test"; DataSet dsW = new DataSet(); dsW.header = new DefaultData(); dsW.header._charA[UT_ID] = headInfo; DefaultData secW = new DefaultData(); dsW.sec[UT_ID] = secW; static char[] genUTCode () { char[] ret; foreach (type; DefaultData.dataTypes) { ret ~= `secW.`~DefaultData.varName(type)~`[UT_ID] = (`~type~`).init;`; } return ret; } mixin (genUTCode()); // Add an entry to dd for each type IWriter w = makeWriter (file, dsW, WriterMethod.Both); w.write(); // FIXME: when binary writing is supported, read both formats and check IReader r = makeReader (file~".mtt", null, true); r.read(); DataSet dsR = r.dataset; assert (dsR !is null); assert (dsR.header !is null); char[]* p = UT_ID in dsW.header._charA; assert (p); assert (*p == headInfo); IDataSection* sec_p = (UT_ID in dsR.sec); assert (sec_p); DefaultData secR = cast(DefaultData) *sec_p; assert (secR !is null); // FIXME: when comparing associative arrays works, use that. In the mean-time, format!() should work. static char[] genCheckCode (char[] dd1, char[] dd2) { const char[] failureMsg = "Assertion failed for type; values: "; char[] ret; foreach (type; DefaultData.dataTypes) { char[] tName = DefaultData.varName(type); ret ~= `char[] `~tName~`Val1 = parseFrom!(`~type~`[char[]]) (cast(`~type~`[char[]]) `~dd1~`.`~tName~`); char[] `~tName~`Val2 = parseFrom!(`~type~`[char[]]) (cast(`~type~`[char[]]) `~dd2~`.`~tName~`); assert (`~tName~`Val1 == `~tName~`Val2, "Assertion failed for type `~type~`; values: "~`~tName~`Val1~", "~`~tName~`Val2 ); `; } return ret; } mixin (genCheckCode (`secW`,`secR`)); logger.info ("Unittest complete (for DefaultData)."); } }