//===========================================================================// // File: receiver.tst // // Project: MUNGA Brick: Dynamic Dispatch // // Contents: Test routines for MessageHandlerSet, Derivation and Receiver // //---------------------------------------------------------------------------// // Date Who Modification // // -------- --- ---------------------------------------------------------- // // 10/19/94 JMA Initial coding. // // 11/02/94 JMA Made compatible with SGI CC // // 11/03/94 ECH Made compatible with BC4.0 // // 11/05/94 JMA Made compatible with GNU C++ // // 12/01/94 JMA Made compatible with SGI CC // // 12/04/94 JMA Moved Message under Receiver, merged in message.tst // //---------------------------------------------------------------------------// // Copyright (C) 1994, Virtual World Entertainment, Inc. All Rights reserved // // PROPRIETARY AND CONFIDENTIAL // //===========================================================================// #include "testclas.hpp" //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Alpha ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Alpha::Alpha( ClassID class_ID, SharedData &vdata ): Receiver(class_ID,vdata) { x = -1; } Alpha::~Alpha() { } void Alpha::Method0Handler(Message*) { x = 0; } void Alpha::Method1Handler(Message*) { x = 1; } Alpha::SharedData Alpha::DefaultData( Alpha::ClassDerivations, Alpha::handlerSet ); Derivation Alpha::ClassDerivations(Receiver::ClassDerivations,"Alpha"); const Receiver::HandlerEntry Set_1[]= { { Alpha::message0ID, "message0", (Receiver::Handler)&Alpha::Method0Handler }, { Alpha::message1ID, "message1", (Receiver::Handler)&Alpha::Method1Handler } }; Receiver::MessageHandlerSet Alpha::handlerSet( ELEMENTS(Set_1), Set_1, Receiver::MessageHandlers ); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Beta ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Beta::Beta( ClassID class_id, SharedData &vdata ): Alpha(class_id, vdata) { x = -2; } Beta::~Beta() { } void Beta::Method1aHandler(Message*) { x = 6; } void Beta::Method2Handler(Message*) { x = 2; } void Beta::Method3Handler(Message*) { x = 3; } Beta::SharedData Beta::DefaultData( Beta::ClassDerivations, Beta::handlerSet ); Derivation Beta::ClassDerivations(Alpha::ClassDerivations,"Beta"); const Receiver::HandlerEntry Set_2[]= { { Beta::message1ID, "message1", (Receiver::Handler)&Beta::Method1aHandler }, { Beta::message2ID, "message2", (Receiver::Handler)&Beta::Method2Handler }, { Beta::message3ID, "message3", (Receiver::Handler)&Beta::Method3Handler } }; Receiver::MessageHandlerSet Beta::handlerSet( ELEMENTS(Set_2), Set_2, Alpha::handlerSet ); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Gamma ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Gamma::Gamma(): Beta(TrivialReceiverClassID, DefaultData) { x = -3; } Gamma::~Gamma() { } void Gamma::Method4Handler(Message*) { x = 4; } Gamma::SharedData Gamma::DefaultData( Gamma::ClassDerivations, Gamma::handlerSet ); Derivation Gamma::ClassDerivations(Beta::ClassDerivations,"Gamma"); const Receiver::HandlerEntry Set_3[]= { { Gamma::message4ID, "message4", (Receiver::Handler)&Gamma::Method4Handler } }; Receiver::MessageHandlerSet Gamma::handlerSet( ELEMENTS(Set_3), Set_3, Beta::handlerSet ); //~~~~~~~~~~~~~~~~~~~~~~~~~~~ MessageHandlerSet ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // //############################################################################# //############################################################################# // Logical Receiver::MessageHandlerSet::TestClass() { DEBUG_STREAM << "Starting Receiver::MessageHandlerSet test...\n"; // //-------------------------------- // Test the inherited construction //-------------------------------- // Test(Alpha::handlerSet.entryCount == Alpha::message1ID); Test(Beta::handlerSet.entryCount == Beta::message3ID); Test(Gamma::handlerSet.entryCount == Gamma::message4ID); // //-------------------------- // Verify that Find() works //-------------------------- // Test( Alpha::handlerSet.Find(Alpha::message1ID) == (Receiver::Handler)&Alpha::Method1Handler ); Test(Alpha::handlerSet.Find(Gamma::message4ID) == Receiver::NullHandler); Test( Beta::handlerSet.Find(Alpha::message1ID) == (Receiver::Handler)&Beta::Method1aHandler ); Test( Beta::handlerSet.Find(Beta::message2ID) == (Receiver::Handler)&Beta::Method2Handler ); Test( Gamma::handlerSet.Find(Alpha::message1ID) == (Receiver::Handler)&Beta::Method1aHandler ); Test( Gamma::handlerSet.Find(Beta::message2ID) == (Receiver::Handler)&Beta::Method2Handler ); Test( Gamma::handlerSet.Find(Gamma::message4ID) == (Receiver::Handler)&Gamma::Method4Handler ); return True; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Derivation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // //############################################################################# //############################################################################# // Logical Derivation::TestClass() { DEBUG_STREAM << "Starting Derivation test...\n"; Tell(" Derivation::TestClass() is stubbed out...\n"); return False; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Receiver ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // //############################################################################# //############################################################################# // Logical Receiver::TestClass() { DEBUG_STREAM << "Starting Receiver test...\n"; Alpha a; Beta b; Gamma c; Message m(0, sizeof(Message)); // // Check construction stability // ChainIteratorOf i(Alpha::ClassDerivations.classDerivations); Test(i.ReadAndNext() == &Beta::ClassDerivations); Test(i.GetCurrent() == NULL); ChainIteratorOf j(Beta::ClassDerivations.classDerivations); Test(j.ReadAndNext() == &Gamma::ClassDerivations); Test(j.GetCurrent() == NULL); ChainIteratorOf k(Gamma::ClassDerivations.classDerivations); Test(k.GetCurrent() == NULL); Test(a.x == -1); Test(b.x == -2); Test(c.x == -3); // // Check basic method response // a.Method0(); b.Method0(); c.Method0(); Test(a.x == 0); Test(b.x == 0); Test(c.x == 0); a.Method1(); b.Method1(); c.Method1(); Test(a.x == 1); Test(b.x == 6); Test(c.x == 6); m.messageID = Beta::message2ID; a.Dispatch(&m); b.Method2(); c.Method2(); Test(a.x == 1); Test(b.x == 2); Test(c.x == 2); b.Method3(); c.Method3(); Test(b.x == 3); Test(c.x == 3); c.Method4(); Test(c.x == 4); // // Now test tapping. First, hierarchy... // #if 0 MessageTap *t = new MessageTap(a.GetDerivation(),f); Verify(t); x = -1; a.Method0(); Test(a.x == 0); Test(x == 1); x = -1; b.Method1(); Test(b.x == 6); Test(x == 1); x = -1; c.Method3(); Test(c.x == 3); Test(x == 1); // // Now test multiple tap operation // MessageTap *u = new MessageTap(b.GetDerivation(),g); x = -1; y = -1; a.Method0(); Test(a.x == 0); Test(x == 1); Test(y == -1); x = -1; b.Method1(); Test(b.x == 6); Test(x == 1); Test(y == 2); x = -1; y = -2; c.Method3(); Test(c.x == 3); Test(x == 1); Test(y == 2); delete t; delete u; #endif return True; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ MessageTap ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // //############################################################################# //############################################################################# // Logical MessageTap::TestClass() { DEBUG_STREAM << "Starting MessageTap test...\n"; #if 0 Alpha a; Receiver::Message m; // // Check universal tap // MessageTap *t = new MessageTap(a.GetDerivation(),f); Test(t); Test(t->scanCallback == f); Test(t->matchingReceiver == NULL); Test(t->matchingMessageID == Receiver::AnyMessageID); x = -1; m.messageID = Receiver::AnyMessageID; t->Scan(NULL,&m); Test(x == 1); x = -1; t->Scan(&a,&m); Test(x == 1); x = -1; m.messageID = Alpha::message1ID; t->Scan(NULL,&m); Test(x == 1); x = -1; t->Scan(&a,&m); Test(x == 1); delete t; // // Check message match tap // t = new MessageTap(a.GetDerivation(),f,2,NULL); Test(t); Test(t->scanCallback == f); Test(t->matchingReceiver == NULL); Test(t->matchingMessageID == 2); x = -1; m.messageID = Receiver::AnyMessageID; t->Scan(NULL,&m); Test(x == -1); t->Scan(&a,&m); Test(x == -1); m.messageID = 2; t->Scan(NULL,&m); Test(x == 1); x = -1; t->Scan(&a,&m); Test(x == 1); delete t; // // Check receiver match tap // t = new MessageTap(a.GetDerivation(),f,Receiver::AnyMessageID,&a); Test(t); Test(t->scanCallback == f); Test(t->matchingReceiver == &a); Test(t->matchingMessageID == Receiver::AnyMessageID); x = -1; m.messageID = Receiver::AnyMessageID; t->Scan(NULL,&m); Test(x == -1); t->Scan(&a,&m); Test(x == 1); x = -1; m.messageID = Beta::message2ID; t->Scan(NULL,&m); Test(x == -1); t->Scan(&a,&m); Test(x == 1); delete t; // // Check message&receiver match tap // t = new MessageTap(a.GetDerivation(),f,Beta::message2ID,&a); Test(t); Test(t->scanCallback == f); Test(t->matchingReceiver == &a); Test(t->matchingMessageID == Beta::message2ID); x = -1; m.messageID = Receiver::AnyMessageID; t->Scan(NULL,&m); Test(x == -1); t->Scan(&a,&m); Test(x == -1); m.messageID = Beta::message2ID; t->Scan(NULL,&m); Test(x == -1); t->Scan(&a,&m); Test(x == 1); delete t; #endif return True; }