player-robot-test.cpp 1.93 KB
/*
 * File: player-robot-test.cpp
 * Description: .cpp which is a test for PlayerRobot component.
 * Date: 09 March 2012
 * Generated by coolbot-bundle version 1.0.0
 */

#include "coolbot_compiler_adjustments.h"

#include "coolbot.h"

#include "component/coolbot_componentprobe.h"

using namespace CoolBOT;

#include "player-robot.h"

using namespace PlayerRobotSpace;

int mainUser(int argc, char* argv[])
{
#ifndef COOLBOT_IN_LINUX
    char* pName="TestingCoolBOT";
#else // COOLBOT_IN_LINUX
     char* pName="player-robot-test";
#endif // COOLBOT_IN_LINUX

    PlayerRobot c_PlayerRobot;

#ifndef COOLBOT_IN_LINUX
    Thread::setProcessSchedulingPolicy(Thread::COOLBOT_REALTIME);
#endif // COOLBOT_IN_LINUX

    ComponentProbe probe;

    probe.attach(&c_PlayerRobot);
    c_PlayerRobot.run();
    int state;

    try
    {
        probe.waitForState(Component::READY,Component::STARTING_ERROR);
        probe.setState(Component::RUNNING);

        Time::sleep(1000);

        probe.setState(Component::SUSPENDED);
        probe.waitForState(Component::SUSPENDED,Component::RUNNING_ERROR);

        probe.setState(Component::DEAD);
        probe.waitForState(Component::DEAD);
    }
    catch(GenericError& rError)
    {
        cout<<"[CoolBOT] "<<rError<<endl;

        probe.driveToDead();
    }

    c_PlayerRobot.waitTermination();

    return 0;
}

int main(int argc, char* argv[])
try
{
    // Set the main function
    Libraries::setMainFunction(mainUser);

    // Run main function
    return Libraries::main(argc,argv);
}
catch(Error& rError)
{
    cout<<"[CoolBOT] Uncaugth exception:"
        <<rError
        <<endl;
}
catch(Error* pError)
{
    cout<<"[CoolBOT] Uncaugth exception:"
        <<pError
        <<endl;
}
catch(exception& rException)
{
    cout<<"[CoolBOT] Uncaugth exception:"
        <<rException.what()
        <<endl;
}
catch(exception* pException)
{
    cout<<"[CoolBOT] Uncaugth exception:"
        <<pException->what()
        <<endl;
}