#include "SimpleComponent.h"
#include "SimpleEvent.h"


int main()
{ 
    printf ("starting test.\n");
    
    SimpleComponent *a = new SimpleComponent ("Fabio");
    SimpleComponent *b = new SimpleComponent ("Paula");
    SimpleComponent *c = new SimpleComponent (0);
    printf ("created simple components.\n");

    // normal cases    
    ACE_ASSERT(a->configurator->addHook ("LeftHand")  == 0);
    ACE_ASSERT(a->configurator->addHook ("RightHand") == 0);
    ACE_ASSERT(b->configurator->addHook ("LeftHand")  == 0);
    ACE_ASSERT(b->configurator->addHook ("RightHand") == 0);
    
    // erroneous cases
    ACE_ASSERT(a->configurator->addHook ("LeftHand") == -1); // repeating same hook
    ACE_ASSERT(a->configurator->addHook (0) == -1);          // null hook

    // normal cases
    ACE_ASSERT(a->configurator->deleteHook("LeftHand") == 0);
    ACE_ASSERT(a->configurator->addHook ("LeftHand") == 0);

    printf ("added hooks.\n");
    
    ACE_ASSERT(a->configurator->hook ("LeftHand", b->configurator) == 0);
    ACE_ASSERT(b->configurator->registerClient (a->configurator, "LeftHand") == 0);
    
    ACE_ASSERT(b->configurator->hook ("RightHand", a->configurator) == 0);
    ACE_ASSERT(a->configurator->registerClient (b->configurator, "RightHand") == 0);

    // erroneous cases (repetition)
    ACE_ASSERT(a->configurator->hook ("LeftHand", b->configurator) == -1);
    ACE_ASSERT(b->configurator->registerClient (a->configurator, "LeftHand") == -1);


    a->configurator->
      eventOnHookedComponent(b->configurator, 
                             new SimpleEvent (ComponentEvent::FAILURE, "help"));
    b->configurator->
      eventOnHookedComponent(a->configurator, 
                             new SimpleEvent (ComponentEvent::RECONFIGURED));
        
    printf ("hooked components and registered clients.\n");
    
    printf ("done.\n");
    
}// main ()
