commit 82bbdd664ad78d36d1ece1badda6b37e04214133
parent 10c9fbd8143c13677c5f1c95db20d48aa758dbd1
Author: fundamental <mark.d.mccurry@gmail.com>
Date: Fri, 4 Sep 2009 18:34:01 -0400
Added in XMLwrapper tests
Diffstat:
5 files changed, 96 insertions(+), 23 deletions(-)
diff --git a/src/Misc/Microtonal.cpp b/src/Misc/Microtonal.cpp
@@ -171,13 +171,16 @@ bool Microtonal::operator==(const Microtonal µ) const
return(!(*this!=micro));
}
-/**\TODO remove printfs once testing is done*/
-//A simple macro to test equality MiCRotonal EQuals (not the perfect approach, but good enough for debug)
-#define MCREQ( x ) if(x!=micro.x){printf("%d\n",__LINE__);return true;}
-//for floats
-#define FMCREQ( x ) if(!((x<micro.x+0.0001)&&(x>micro.x-0.0001))){printf("%d\n",__LINE__);return true;}
bool Microtonal::operator!=(const Microtonal µ) const
{
+
+ //A simple macro to test equality MiCRotonal EQuals (not the perfect
+ //approach, but good enough)
+#define MCREQ( x ) if(x!=micro.x)return true;
+
+ //for floats
+#define FMCREQ( x ) if(!((x<micro.x+0.0001)&&(x>micro.x-0.0001)))return true;
+
MCREQ(Pinvertupdown);
MCREQ(Pinvertupdowncenter);
MCREQ(octavesize);
@@ -202,11 +205,16 @@ bool Microtonal::operator!=(const Microtonal µ) const
MCREQ(octave[i].x2);
}
if(strcmp((const char *)this->Pname,(const char *)micro.Pname))
- {printf("%d\n",__LINE__); return true;}
+ return true;
if(strcmp((const char *)this->Pcomment,(const char *)micro.Pcomment))
- {printf("%d\n",__LINE__);return true;}
+ return true;
MCREQ(Pglobalfinedetune);
return false;
+
+ //undefine macros, as they are no longer needed
+#undef MCREQ
+#undef FMCREQ
+
}
diff --git a/src/Tests/CMakeLists.txt b/src/Tests/CMakeLists.txt
@@ -2,3 +2,4 @@ unit_test(ControllerTest ControllerTest.h "")
unit_test(EchoTest EchoTest.h "")
unit_test(SampleTest SampleTest.h "")
unit_test(MicrotonalTest MicrotonalTest.h "")
+unit_test(XMLwrapperTest XMLwrapperTest.h "")
diff --git a/src/Tests/MicrotonalTest.h b/src/Tests/MicrotonalTest.h
@@ -24,6 +24,7 @@
#include "../Misc/Microtonal.h"
#include <cstring>
#include <string>
+#include <cstdio>
using namespace std;
@@ -76,6 +77,7 @@ public:
//Gah, the XMLwrapper is a twisted maze
testMicro->Penabled=1;
XMLwrapper xml;
+ XMLwrapper xml2;
xml.beginbranch("Dummy"); //this should not be needed, but odd behavior
//seems to exist from MICROTONAL being on the
//top of the stack
@@ -86,42 +88,56 @@ public:
//stack errors
char *tmp=xml.getXMLdata();
+ xml2.putXMLdata(tmp);
//printf("%s",tmp);
Microtonal other;
- cout << (char*)testMicro->Pname << " vs1 "
- << (char*)other.Pname << endl;
+ //cout << (char*)testMicro->Pname << " vs1 "
+ // << (char*)other.Pname << endl;
other.Penabled=1;
strcpy((char *)other.Pname,"Myname");//will be nicer with strings
- cout << (char*)testMicro->Pname << " vs1.5 "
- << (char*)other.Pname << endl;
+ //cout << (char*)testMicro->Pname << " vs1.5 "
+ // << (char*)other.Pname << endl;
TS_ASSERT(*testMicro!=other);//sanity check
- TS_ASSERT(xml.enterbranch("Dummy"));
- TS_ASSERT(xml.enterbranch("MICROTONAL"));
+ TS_ASSERT(xml2.enterbranch("Dummy"));
+ TS_ASSERT(xml2.enterbranch("MICROTONAL"));
//printf("%s",tmp);
- other.getfromXML(&xml); //failure here
- xml.exitbranch();
- xml.exitbranch();
- char *tmpo=xml.getXMLdata();
+ other.getfromXML(&xml2); //failure here
+ xml2.exitbranch();
+ xml2.exitbranch();
+ char *tmpo=xml2.getXMLdata();
- cout << (char*)testMicro->Pname << " vs2 "
- << (char*)other.Pname << endl; //shows error here
+ //cout << (char*)testMicro->Pname << " vs2 "
+ // << (char*)other.Pname << endl; //shows error here
//printf("%s",tmpo);
+
+ FILE *f=fopen("aaaa.xml","w");
+ fprintf(f,tmp);
+ fclose(f);
+ FILE *f2=fopen("aaaaoo.xml","w");
+ fprintf(f2,tmpo);
+ fclose(f2);
TS_ASSERT(!strcmp(tmp,tmpo)); //these should be equal, but there seems
//to be one line that is duplicated
//(I think in one of the reads)
free(tmp);
free(tmpo);
+ //testMicro->saveXML("0testMicro.xml");
+ //other.saveXML("0other.xml");
+
TS_ASSERT(*testMicro==other); //cxxTest sees error here
- cout << (char*)testMicro->Pname << " vs3 "
- << (char*)other.Pname << endl;
+ //cout << (char*)testMicro->Pname << " vs3 "
+ // << (char*)other.Pname << endl;
+ //remove unneeded files
+ remove("aaaa.xml");
+ remove("aaaaoo.xml");
}
diff --git a/src/Tests/XMLWrapperTest.h b/src/Tests/XMLWrapperTest.h
@@ -0,0 +1,48 @@
+/*
+ ZynAddSubFX - a software synthesizer
+
+ XMLwrapperTest.h - CxxTest for Misc/XMLwrapper
+ Copyright (C) 2009-2009 Mark McCurry
+ Author: Mark McCurry
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of version 2 of the GNU General Public License
+ as published by the Free Software Foundation.
+
+ 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 (version 2 or later) for more details.
+
+ You should have received a copy of the GNU General Public License (version 2)
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+*/
+#include <cxxtest/TestSuite.h>
+#include "../XMLwrapper.h"
+
+class XMLwrapperTest : pubilc CxxTest::TestSuite
+{
+pubilic:
+ void setUp() {
+ xmla = new XMLwrapper;
+ xmlb = new XMLwrapper;
+ }
+
+ void tearDown() {
+ delete xmla;
+ delete xmlb;
+ }
+
+ void testAddPar(){
+ xmla.addpar("my Pa*_ramet@er",75);
+ TS_ASSERT_EQUALS(xmla.getpar("my Pa*_ramet@er",0,-200,200),75);
+ }
+
+
+private:
+ XMLwrapper *xmla;
+ XMLwrapper *xmlb;
+}
+
diff --git a/src/Tests/make.sh b/src/Tests/make.sh
@@ -1,6 +1,6 @@
cd ../
make
cd Tests
-#cxxtestgen.py --error-printer -o runner.cpp SampleTest.h EchoTest.h ControllerTest.h MicrotonalTest.h
-cxxtestgen.py --error-printer -o runner.cpp MicrotonalTest.h
+cxxtestgen.py --error-printer -o runner.cpp SampleTest.h EchoTest.h \
+ControllerTest.h MicrotonalTest.h XMLwrapperTest.h
g++ -g -o runner runner.cpp ../Samples/AuSample.o ../Samples/Sample.o ../Effects/Echo.o ../Effects/Effect.o ../Controls/Control.o ../Controls/DelayCtl.o ../Params/Controller.o ../Misc/XMLwrapper.o ../Misc/Config.o ../Misc/Util.o ../Misc/Microtonal.o -lmxml -lm -lz -lpthread