43static int testBasicRaii(
void);
45static int testMateriaSourceLimits();
93 testCharacterInventoryLimits(&droppedManager);
94 testMateriaSourceLimits();
95 testCharacterDeepCopy(&droppedManager);
96 testCharacterDeepCopyAssignment(&droppedManager);
108static int testBasicRaii(
void) {
109 LOG_INFO(
"--- Test Basic with ScopedPointer ---");
121 src->learnMateria(
new Ice());
122 src->learnMateria(
new Cure());
144 if (src.
get() && me.
get()) {
147 tmp = src->createMateria(
"ice");
151 tmp = src->createMateria(
"cure");
160 if (me.
get() && bob.
get()) {
185 LOG_INFO(
"--- Program finished with ScopedPointer ---");
197 LOG_INFO(
"\n--- Testing Character Inventory Limits ---");
211 src->learnMateria(
new Ice());
212 src->learnMateria(
new Cure());
216 if (alice.
get() && src.
get()) {
219 tmp = src->createMateria(
"ice");
223 tmp = src->createMateria(
"cure");
227 tmp = src->createMateria(
"ice");
231 tmp = src->createMateria(
"cure");
240 alice->equip(
new Ice());
246 if (alice.
get() && bob.
get()) {
259 unequipped_raw_ptr = alice->getMateriaAtSlot(1);
265 if (droppedManager && unequipped_raw_ptr) {
266 droppedManager->
addMateria(unequipped_raw_ptr);
267 }
else if (unequipped_raw_ptr) {
269 LOG_WARNING(
"No droppedManager or null materia. Deleting unequipped materia directly.");
270 delete unequipped_raw_ptr;
280 LOG_ERROR(
"An unknown error occurred in testCharacterInventoryLimits.");
292static int testMateriaSourceLimits() {
293 LOG_INFO(
"\n--- Testing MateriaSource Learning Limits ---");
305 src->learnMateria(
new Ice());
306 src->learnMateria(
new Cure());
307 src->learnMateria(
new Ice());
308 src->learnMateria(
new Cure());
315 src->learnMateria(
new Ice());
322 if (src.
get() && me.
get()) {
325 tmp = src->createMateria(
"ice");
329 tmp = src->createMateria(
"cure");
336 if (src.
get() && me.
get()) {
339 tmp_unknown = src->createMateria(
"fire");
340 if (tmp_unknown == 0) {
341 LOG_INFO(
"Successfully tried to create unknown materia 'fire', returned NULL.");
343 LOG_ERROR(
"Creating unknown materia 'fire' returned non-NULL. Leaking materia.");
355 LOG_ERROR(
"An unknown error occurred in testMateriaSourceLimits.");
359 LOG_INFO(
"--- Testing MateriaSource Learning Limits finished ---");
377 charlie.equip(
new Ice());
378 charlie.equip(
new Cure());
383 std::cout <<
"Charlie's first materia type: " << charlie.getName() <<
" has "
384 << (charlie.isMateriaEquipped(0) ? charlie.getMateriaAtSlot(0)->getType() :
"nothing") <<
" at slot 0"
386 std::cout <<
"Charlie's copy's first materia type: " << charlie_copy.getName() <<
" has "
387 << (charlie_copy.isMateriaEquipped(0) ? charlie_copy.getMateriaAtSlot(0)->getType() :
"nothing")
390 AMateria *unequipped = charlie_copy.getMateriaAtSlot(0);
391 charlie_copy.unequip(0);
395 std::cout <<
"After unequipping copy, Charlie's first materia type: " << charlie.getName() <<
" has "
396 << (charlie.isMateriaEquipped(0) ? charlie.getMateriaAtSlot(0)->getType() :
"nothing") <<
" at slot 0"
398 std::cout <<
"Charlie's copy's first materia type: " << charlie_copy.getName() <<
" has "
399 << (charlie_copy.isMateriaEquipped(0) ? charlie_copy.getMateriaAtSlot(0)->getType() :
"nothing")
415 david.equip(
new Ice());
417 david_assigned = david;
420 std::cout <<
"David's first materia type: " << david.getName() <<
" has "
421 << (david.isMateriaEquipped(0) ? david.getMateriaAtSlot(0)->getType() :
"nothing") <<
" at slot 0"
423 std::cout <<
"David's assigned's first materia type: " << david_assigned.getName() <<
" has "
424 << (david_assigned.isMateriaEquipped(0) ? david_assigned.getMateriaAtSlot(0)->getType() :
"nothing")
427 AMateria *unequipped = david_assigned.getMateriaAtSlot(0);
428 david_assigned.unequip(0);
430 std::cout <<
"After unequipping assigned, David's first materia type: " << david.getName() <<
" has "
431 << (david.isMateriaEquipped(0) ? david.getMateriaAtSlot(0)->getType() :
"nothing") <<
" at slot 0"
433 std::cout <<
"David's assigned's first materia type: " << david_assigned.getName() <<
" has "
434 << (david_assigned.isMateriaEquipped(0) ? david_assigned.getMateriaAtSlot(0)->getType() :
"nothing")
Declares the AMateria abstract base class.
Declares the Character class.
Declares the Cure materia class.
Declares the DroppedMateriaManager class.
Declares the ICharacter interface.
Declares the IMateriaSource interface.
Declares the Ice materia class.
Defines the Logger class for console-based logging.
#define LOG_WARNING(msg)
Macro for logging warning messages.
#define LOG_INFO(msg)
Macro for logging informational messages.
Declares the MateriaSource class.
Represents an abstract base class for all magical materias.
Represents a character capable of equipping and using Materias.
Represents a healing magic materia.
Manages AMateria objects that are temporarily "dropped" in the game.
void displayDroppedMaterias() const
Displays the types and slots of all currently dropped materias for debugging.
void addMateria(AMateria *materia)
Adds a materia to the list of dropped materias. Takes ownership of the passed AMateria pointer....
An interface for any character that can interact with Materias.
virtual void use(int idx, ICharacter &target)=0
Uses the Materia at a specific inventory slot on a target character. This is a pure virtual function,...
virtual void equip(AMateria *m)=0
Equips a Materia to the character's inventory. This is a pure virtual function, requiring derived cla...
An interface for objects that can learn Materia templates and create new Materias.
virtual void learnMateria(AMateria *)=0
Learns a Materia template for later creation. This is a pure virtual function, requiring derived clas...
virtual AMateria * createMateria(std::string const &type) const =0
Creates a new Materia based on a learned type. This is a pure virtual function, requiring derived cla...
Represents an ice-based offensive magic materia.
Represents a source for learning and creating Materias.
int main()
Main function of the program.
ScopedPointer Class is Custom smart pointer with RAII pattern applied.