[ogs-changes] dist/c++/test MagicTest.cpp,NONE,1.1 Makefile.am,1.5,1.6
Status: Alpha
Brought to you by:
elemings
|
From: <ele...@us...> - 2003-05-02 19:06:42
|
Update of /cvsroot/ogs/dist/c++/test
In directory sc8-pr-cvs1:/tmp/cvs-serv32451/test
Modified Files:
Makefile.am
Added Files:
MagicTest.cpp
Log Message:
See C++ ChangeLog (May 2) for details.
--- NEW FILE: MagicTest.cpp ---
/*
* MagicTest.cpp -- test driver for magic system
* Copyright (C) 2003 Eric Lemings <ele...@us...>
*
* This software 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 software 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 software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA
*
* RCS: $Id: MagicTest.cpp,v 1.1 2003/05/02 19:06:38 elemings Exp $
*/
// Need to add configure checks before using <mcheck.h> and mtrace().
//#include <mcheck.h>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <exception>
#include <iostream>
#include <ogs/Support.h>
#include <ogs/Magic.h>
#include <ogs/Creatures.h>
#include <ogs/Spells.h>
using std::cout;
using std::endl;
using namespace ogs::support;
using namespace ogs::magic;
#define TEST_DRIVER "MagicTest"
/** Run various tests on schools and subschools. */
void testSchools () {
try {
School school (School::Type (382));
assert ("Should not be here." == NULL);
} catch (std::exception& exception) {
cout << "Exception caught: " << exception.what () << endl;
}
try {
Subschool school (Subschool::Type (841));
assert ("Should not be here." == NULL);
} catch (std::exception& exception) {
cout << "Exception caught: " << exception.what () << endl;
}
cout << "sizeof (School) = " << sizeof (School) << endl;
School illusion (School::ILLUSION);
cout << "&illusion = " << &illusion << endl;
cout << "sizeof (Subschool) = " << sizeof (Subschool) << endl;
Subschool phantasm (Subschool::PHANTASM);
cout << "&phantasm = " << &phantasm << endl;
const School& school = phantasm;
assert (school.getType () == School::ILLUSION);
cout << "school.getName () = \"" << school.getName () << "\"" << endl;
assert (school.getName () == "Illusion (Phantasm)");
const Subschool& subschool = dynamic_cast<const Subschool&> (school);
assert (subschool.getType () == Subschool::PHANTASM);
cout << endl;
}
#define printDescriptor(type) \
std::cout << "Descriptors::getName (Descriptors::" #type ") = \"" \
<< Descriptors::getName (Descriptors::type) \
<< "\"" << std::endl;
void testDescriptors () {
cout << "sizeof (Descriptors) = " << sizeof (Descriptors) << endl;
printDescriptor (ACID);
printDescriptor (TELEPORTATION);
cout << "Descriptors::getName (20) = \""
<< Descriptors::getName (20) << "\"" << endl;
// Do some tests on a brand new set of descriptors.
Descriptors d1;
cout << "&d1 = " << &d1 << endl;
assert (d1.none ());
assert (!d1.any ());
assert (d1.count () == 0);
cout << "d1 = " << d1 << endl;
// Phantasmal Killer spell...Fear and Mind-Affecting descriptors.
d1.set (Descriptors::FEAR);
assert (!d1.none ());
assert (d1.any ());
assert (d1.count () == 1);
cout << "d1 = " << d1 << endl;
d1.set (Descriptors::MIND_AFFECTING);
assert (!d1.none ());
assert (d1.any ());
assert (d1.count () == 2);
cout << "d1 = " << d1 << endl;
assert (!d1.test (Descriptors::ACID));
assert (!d1.test (Descriptors::CHAOTIC));
assert (!d1.test (Descriptors::COLD));
assert (!d1.test (Descriptors::DARKNESS));
assert (d1.test (Descriptors::FEAR));
assert (!d1.test (Descriptors::FIRE));
assert (d1.test (Descriptors::MIND_AFFECTING));
cout << endl;
}
void testCureWounds () {
// Do some checks on a cure wounds spell.
using ogs::spells::conjurations::CureWounds;
CureWounds* inflictLightWounds = CureWounds::createLight (4, true);
const School& school = inflictLightWounds->getSchool ();
assert (school.getType () == School::CONJURATION);
const Subschool* subschool = dynamic_cast<const Subschool*> (&school);
assert (subschool != NULL);
assert (subschool->getType () == Subschool::HEALING);
Descriptors descriptors = inflictLightWounds->getDescriptors ();
assert (descriptors.none ());
Components components = inflictLightWounds->getComponents ();
assert (components.size () == 2);
// TODO: Verify components are verbal and somantic.
const Range& range = inflictLightWounds->getRange ();
assert (range.getType () == Range::TOUCH);
assert (inflictLightWounds->getDegree () == CureWounds::LIGHT);
assert (inflictLightWounds->getTarget () == NULL);
assert (inflictLightWounds->inflictsWounds ());
inflictLightWounds->castSpell ();
// Cast a Inflict Light Wounds spell on a healthy human.
using ogs::creatures::humanoids::Human;
Human human;
using ogs::core::Entity;
Entity::Health health = human.getHealth ();
cout << "Human: hp " << health.first << "/"
<< health.second << "." << endl;
inflictLightWounds->setTarget (human);
cout << "Casting Inflict Light Wounds on human..." << endl;
inflictLightWounds->castSpell ();
health = human.getHealth ();
cout << "Human: hp " << health.first << "/"
<< health.second << "." << endl;
// Cast a Cure Light Wounds spell on a dying human.
CureWounds* cureLightWounds = CureWounds::createLight (8);
assert (! cureLightWounds->inflictsWounds ());
cureLightWounds->setTarget (human);
cout << "Casting Cure Light Wounds on human..." << endl;
cureLightWounds->castSpell ();
health = human.getHealth ();
cout << "Human: hp " << health.first << "/"
<< health.second << "." << endl;
// Cast a Cure Critical Wounds spell on a healthy wraith.
using ogs::creatures::undeads::Wraith;
Wraith wraith;
CureWounds* cureCriticalWounds = CureWounds::createCritical (8);
health = wraith.getHealth ();
cout << "Wraith: hp " << health.first << "/"
<< health.second << "." << endl;
cureCriticalWounds->setTarget (wraith);
cout << "Casting Cure Critical Wounds on wraith..." << endl;
cureCriticalWounds->castSpell ();
health = wraith.getHealth ();
cout << "Wraith: hp " << health.first << "/"
<< health.second << "." << endl;
delete cureLightWounds;
delete inflictLightWounds;
delete cureCriticalWounds;
cout << endl;
}
int main (void) {
//mtrace ();
cout << "BEGIN: " TEST_DRIVER "\n\n";
// Seed random number generator with current time.
std::srand (std::time (NULL));
testSchools ();
testDescriptors ();
testCureWounds ();
cout << "END: " TEST_DRIVER "\n";
//muntrace ();
return (0);
}
Index: Makefile.am
===================================================================
RCS file: /cvsroot/ogs/dist/c++/test/Makefile.am,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Makefile.am 15 Apr 2003 16:58:54 -0000 1.5
--- Makefile.am 2 May 2003 19:06:38 -0000 1.6
***************
*** 38,42 ****
AbilitiesTest \
CreatureTest \
! CombatTest01
SupportTest_SOURCES = \
--- 38,43 ----
AbilitiesTest \
CreatureTest \
! CombatTest01 \
! MagicTest
SupportTest_SOURCES = \
***************
*** 52,55 ****
--- 53,58 ----
CombatTest01_SOURCES = \
CombatTest01.cpp
+ MagicTest_SOURCES = \
+ MagicTest.cpp
# These programs are also executed when the check target is run.
|