#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"); printf ("number of clients in %s: %d\n", a->configurator->name (), a->configurator->numberOfClients ()); printf ("number of clients in %s: %d\n", b->configurator->name (), a->configurator->numberOfClients ()); 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); printf ("added hooks, hooked components, and registered clients.\n"); printf ("number of clients in %s: %d\n", a->configurator->name (), a->configurator->numberOfClients ()); printf ("number of clients in %s: %d\n", b->configurator->name (), a->configurator->numberOfClients ()); a->configurator-> eventOnHookedComponent(b->configurator, new SimpleEvent (ComponentEvent::FAILURE, "help")); b->configurator-> eventOnHookedComponent(a->configurator, new SimpleEvent (ComponentEvent::RECONFIGURED)); ACE_ASSERT(b->configurator->unregisterClient (a->configurator, "LeftHand") == 0); ACE_ASSERT(a->configurator->unregisterClient (b->configurator, "RightHand") == 0); printf ("removed clients.\n"); printf ("number of clients in %s: %d\n", a->configurator->name (), a->configurator->numberOfClients ()); printf ("number of clients in %s: %d\n", b->configurator->name (), a->configurator->numberOfClients ()); printf ("done.\n"); }// main ()