diff --git a/test/AudioCore_test.cpp b/test/AudioCore_test.cpp new file mode 100644 index 0000000..5d58eb3 --- /dev/null +++ b/test/AudioCore_test.cpp @@ -0,0 +1,31 @@ +//This file is part of Photon (http://photon.sourceforge.net) +//Copyright (C) 2004-2005 James Turk +// +// Author: +// James Turk (jpt2433@rit.edu) +// +// Version: +// $Id: AudioCore_test.cpp,v 1.1 2005/05/15 02:50:07 cozman Exp $ + +#include "photon.hpp" +#include + +using namespace photon; +using namespace photon::audio; + +class AudioTest : public Application +{ +public: + + int main(const StrVec& args) + { + //throw Error("zing!"); + + AudioCore& audio(AudioCore::getInstance()); + std::cout << audio.getAudioDeviceName(); + + return 0; + } +}; + +ENTRYPOINT(AudioTest) diff --git a/test/ConfigFile_test.cpp b/test/ConfigFile_test.cpp new file mode 100644 index 0000000..07e75de --- /dev/null +++ b/test/ConfigFile_test.cpp @@ -0,0 +1,47 @@ +//This file is part of Photon (http://photon.sourceforge.net) +//Copyright (C) 2004-2005 James Turk +// +// Author: +// James Turk (jpt2433@rit.edu) +// +// Version: +// $Id: ConfigFile_test.cpp,v 1.1 2005/05/15 02:50:07 cozman Exp $ + +#include "photon.hpp" + +#include +#include + +using namespace photon; +using namespace photon::util; + + +class ConfigTest : public Application +{ +public: + + int main(const StrVec& args) + { + ConfigFile c1("config1.ini"),c2; + c2.open("config2.ini"); + + c1.setVariable("sec","int",3); + c1.setVariable("sec","float",3.0f); + c1.setVariable("sec","string","three"); + + assert(c1.getVariable("sec","int",0) == 3); + assert(c1.getVariable("sec","float",0.0f) == 3.0f); + assert(c1.getVariable("sec","string",std::string()) == "three"); + + assert(c2.getVariable("sec","var",-1) != -1); + assert(c2.getVariable("sec2","var",-1) != -1); + assert(c2.getVariable("sec2","hex",0) == 0); + + c1.close(); + c2.close(); + + return 0; + } +}; + +ENTRYPOINT(ConfigTest) diff --git a/test/Log_test.cpp b/test/Log_test.cpp new file mode 100644 index 0000000..c3d743b --- /dev/null +++ b/test/Log_test.cpp @@ -0,0 +1,49 @@ +//This file is part of Photon (http://photon.sourceforge.net) +//Copyright (C) 2004-2005 James Turk +// +// Author: +// James Turk (jpt2433@rit.edu) +// +// Version: +// $Id: Log_test.cpp,v 1.1 2005/05/15 02:50:07 cozman Exp $ + +#include "photon.hpp" +using namespace photon; + + +class LogTest : public Application +{ +public: + int main(const StrVec& args) + { + Log log; + LogSinkPtr a( new ConsoleSink("console") ); + LogSinkPtr b( new TextSink("text") ); + LogSinkPtr c( new HTMLSink("html") ); + + log.note() << "this isn't seen"; + + log.addSink(a); + log.addSink(b); + log.addSink(c); + + log.note() << "notice?"; + log.verbose() << "(insert verbosity here)"; + log.warning() << "consider yourself warned."; + log.error() << "erroneous!"; + log.critical() << "Al the critic?"; + + log.removeSink(b); + + log.note() << "only seen by a and c" ; + + log.removeSinks(); + + log.note() << "not seen at all!"; + + return 0; + } +}; + +ENTRYPOINT(LogTest) + diff --git a/test/RandGen_test.cpp b/test/RandGen_test.cpp new file mode 100644 index 0000000..c010f9b --- /dev/null +++ b/test/RandGen_test.cpp @@ -0,0 +1,63 @@ +//This file is part of Photon (http://photon.sourceforge.net) +//Copyright (C) 2004-2005 James Turk +// +// Author: +// James Turk (jpt2433@rit.edu) +// +// Version: +// $Id: RandGen_test.cpp,v 1.1 2005/05/15 02:50:07 cozman Exp $ + +#include +#include +#include "photon.hpp" +using namespace photon::util; +using namespace std; + +int main() +{ + RandGen g1; + RandGen g2(0); + RandGen g3(0); + const int N=100; + double v[6] = {0}; + double s[6] = {0}; + double approx[6] = {3.5, 3.5, 3.5, 50, 0, 0.5}; + + std::cout << "d6 |d6 |d6 | [1,100] | +/- | [0,1) \n"; + std::cout << "---------------------------------------------------------------\n"; + for(int i=0; i < N; ++i) + { + v[0] = g1.genRand(1,6); + v[1] = g2.genRand(1,6); + v[2] = g3.genRand(1,6); + v[3] = g1.genRand(0.0,100.0); + v[4] = g1.genRandSign(); + v[5] = g1.genRand01(); + for(int j=0; j < 6; ++j) + { + std::cout.setf(ios::left); + std::cout << std::setw(9) << v[j] << " "; + s[j] += v[j]; + } + std::cout << std::endl; + } + std::cout << "-average-------------------------------------------------------\n"; + for(int j=0; j < 6; ++j) + { + std::cout << std::setw(9) << s[j]/N << " "; + } + std::cout << "\n-should be near------------------------------------------------\n"; + for(int j=0; j < 6; ++j) + { + std::cout.setf(ios::left); + std::cout << std::setw(9) << approx[j] << " "; + } + std::cout << std::endl; + + //Yes I realize what is incorrect about this, "should be near" has no + // meaning since random data can disobey all reason and give you a string + // of 20 billion 6's when rolling a 6-sided die. Most of the time however + // the values will fall within a small deviation from the "expected" and + // they are there for reference when ensuring that the bounds are set + // properly on the generators. +} diff --git a/test/config1.ini b/test/config1.ini new file mode 100644 index 0000000..919ca2e --- /dev/null +++ b/test/config1.ini @@ -0,0 +1,11 @@ +[] +#config1.ini + +[sec2] + fancy = 0 + fancy2 = "james" + +[sec] +int=3 +float=3 +string=three diff --git a/test/config2.ini b/test/config2.ini new file mode 100644 index 0000000..37af61e --- /dev/null +++ b/test/config2.ini @@ -0,0 +1,9 @@ +[] +#config2.ini + +[sec] +var = 0 + hex = 0xff + +[sec2] + var = 2 diff --git a/test/exception_test.cpp b/test/exception_test.cpp new file mode 100644 index 0000000..1fdf0c9 --- /dev/null +++ b/test/exception_test.cpp @@ -0,0 +1,27 @@ +//This file is part of Photon (http://photon.sourceforge.net) +//Copyright (C) 2004-2005 James Turk +// +// Author: +// James Turk (jpt2433@rit.edu) +// +// Version: +// $Id: exception_test.cpp,v 1.1 2005/05/15 02:50:07 cozman Exp $ + +#include "photon.hpp" +using namespace photon; + + +class ExceptionTest : public Application +{ +public: + + int main(const StrVec& args) + { + throw Error("catch this!"); + + return 0; + } +}; + +ENTRYPOINT(ExceptionTest) + diff --git a/test/filesys_test.cpp b/test/filesys_test.cpp new file mode 100644 index 0000000..134ab4e --- /dev/null +++ b/test/filesys_test.cpp @@ -0,0 +1,97 @@ +//This file is part of Photon (http://photon.sourceforge.net) +//Copyright (C) 2004-2005 James Turk +// +// Author: +// James Turk (jpt2433@rit.edu) +// +// Version: +// $Id: filesys_test.cpp,v 1.1 2005/05/15 02:50:07 cozman Exp $ + +#include "photon.hpp" + +using namespace std; +using namespace photon; +using namespace photon::util; + +class FilesysTest : public Application +{ +public: + + int main(const StrVec& args) + { + StrVec list; + + //System Directories + + list = filesys::getCDDirs(); + cout << "CD directories: "; + for(StrVec::iterator i=list.begin(); i != list.end(); ++i) + { + cout << *i << " "; + } + cout << endl; + + cout << "Base Directory: " << filesys::getBaseDir() << endl; + cout << "User Directory: " << filesys::getUserDir() << endl; + + //Search Path + + cout << "adding base directory to search & write path" << endl; + filesys::addToSearchPath( filesys::getBaseDir(), false ); + filesys::setWriteDir( filesys::getBaseDir() ); + + list = filesys::getSearchPath(); + cout << "Search path: "; + for(StrVec::iterator i=list.begin(); i != list.end(); ++i) + { + cout << *i << " "; + } + cout << endl; + + // Searching & Manipulation + + list = filesys::listDir("/"); + cout << "base dir contents: "; + for(StrVec::iterator i=list.begin(); i != list.end(); ++i) + { + cout << *i << " "; + } + cout << endl; + + cout << "filesys_test.cpp" << (filesys::exists("filesys_test.cpp") ? " exists" : " not found") << endl; + cout << "wokka " << (filesys::exists("wokka") ? " exists" : " not found") << endl; + + cout << "making directory 'bam'" << endl; + filesys::mkdir("bam"); + + cout << "bam " << (filesys::isDir("bam") ? " is dir" : " not dir") << endl; + cout << "filesys_test.cpp" << (filesys::isDir("filesys_test.cpp") ? " is dir" : " not dir") << endl; + + filesys::remove("bam"); + cout << "removing directory 'bam'" << endl; + + //other + + cout << "Dir separator: " << filesys::getDirSeparator() << endl; + cout << "Mod time of filesys_test.cpp" ": " << filesys::getModTime("filesys_test.cpp") << endl; + + // search path redux + + cout << "removing base directory from search/write path" << endl; + filesys::removeFromSearchPath( filesys::getBaseDir() ); + filesys::setWriteDir( std::string() ); + + list = filesys::getSearchPath(); + cout << "Search path: "; + for(vector::iterator i=list.begin(); i != list.end(); ++i) + { + cout << *i << " "; + } + cout << endl; + + return 0; + } +}; + +ENTRYPOINT(FilesysTest) +