added tests

This commit is contained in:
James Turk 2005-05-15 02:50:07 +00:00
parent 30d54eb4f6
commit dcf68651ae
8 changed files with 334 additions and 0 deletions

31
test/AudioCore_test.cpp Normal file
View File

@ -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 <iostream>
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)

47
test/ConfigFile_test.cpp Normal file
View File

@ -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 <iostream>
#include <cassert>
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)

49
test/Log_test.cpp Normal file
View File

@ -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)

63
test/RandGen_test.cpp Normal file
View File

@ -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 <iostream>
#include <iomanip>
#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.
}

11
test/config1.ini Normal file
View File

@ -0,0 +1,11 @@
[]
#config1.ini
[sec2]
fancy = 0
fancy2 = "james"
[sec]
int=3
float=3
string=three

9
test/config2.ini Normal file
View File

@ -0,0 +1,9 @@
[]
#config2.ini
[sec]
var = 0
hex = 0xff
[sec2]
var = 2

27
test/exception_test.cpp Normal file
View File

@ -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)

97
test/filesys_test.cpp Normal file
View File

@ -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<string>::iterator i=list.begin(); i != list.end(); ++i)
{
cout << *i << " ";
}
cout << endl;
return 0;
}
};
ENTRYPOINT(FilesysTest)