Beispiel #1
0
        /*----< test Sender and Receiver classes >---------------------*/

        public static bool testSndrRcvr()
        {
            TestUtilities.vbtitle("testing Sender & Receiver");

            bool     test = true;
            Receiver rcvr = new Receiver();

            rcvr.start("http://localhost", 8080);
            Sender sndr = new Sender("http://localhost", 8080);

            CommMessage sndMsg = new CommMessage(CommMessage.MessageType.request);

            sndMsg.command = Msg.Command.show;
            sndMsg.author  = "Jim Fawcett";
            sndMsg.to      = "http://localhost:8080/IPluggableComm";
            sndMsg.from    = "http://localhost:8080/IPluggableComm";

            sndr.postMessage(sndMsg);
            CommMessage rcvMsg;

            // get connection message
            rcvMsg = rcvr.getMessage();
            if (ClientEnvironment.verbose)
            {
                rcvMsg.show();
            }
            // get first info message
            rcvMsg = rcvr.getMessage();
            if (ClientEnvironment.verbose)
            {
                rcvMsg.show();
            }
            if (!compareMsgs(sndMsg, rcvMsg))
            {
                test = false;
            }
            TestUtilities.checkResult(test, "sndMsg equals rcvMsg");
            TestUtilities.putLine();

            sndMsg.type = CommMessage.MessageType.closeReceiver;
            sndr.postMessage(sndMsg);
            rcvMsg = rcvr.getMessage();
            if (ClientEnvironment.verbose)
            {
                rcvMsg.show();
            }
            if (!compareMsgs(sndMsg, rcvMsg))
            {
                test = false;
            }
            TestUtilities.checkResult(test, "Close Receiver");
            TestUtilities.putLine();

            sndMsg.type = CommMessage.MessageType.closeSender;
            if (ClientEnvironment.verbose)
            {
                sndMsg.show();
            }
            sndr.postMessage(sndMsg);
            // rcvr.getMessage() would fail because server has shut down
            // no rcvMsg so no compare

            TestUtilities.putLine("last message received\n");
            return(test);
        }
Beispiel #2
0
        /*----< main thread enqueues message for sending >-------------*/

        public void postMessage(CommMessage msg)
        {
            sndQ.enQ(msg);
        }
Beispiel #3
0
        /*----< post message to remote Comm >--------------------------*/

        public void postMessage(CommMessage msg)
        {
            sndr.postMessage(msg);
            lastSndrError = sndr.lastError;
        }
Beispiel #4
0
        /*----< test Comm instance >-----------------------------------*/

        public static bool testComm()
        {
            TestUtilities.vbtitle("testing Comm");
            bool test = true;

            Comm        comm    = new Comm("http://localhost", 8081);
            CommMessage csndMsg = new CommMessage(CommMessage.MessageType.request);

            csndMsg.command = Msg.Command.show;
            csndMsg.author  = "Jim Fawcett";
            csndMsg.to      = "http://localhost:8081/IPluggableComm";
            csndMsg.from    = "http://localhost:8081/IPluggableComm";

            comm.postMessage(csndMsg);
            CommMessage crcvMsg = comm.getMessage();

            if (ClientEnvironment.verbose)
            {
                crcvMsg.show();
            }

            crcvMsg = comm.getMessage();
            if (ClientEnvironment.verbose)
            {
                crcvMsg.show();
            }
            if (!compareMsgs(csndMsg, crcvMsg))
            {
                test = false;
            }
            TestUtilities.checkResult(test, "csndMsg equals crcvMsg");
            TestUtilities.putLine();

            TestUtilities.vbtitle("testing file transfer");

            bool testFileTransfer = true;

            List <string> names = getClientFileList();

            foreach (string name in names)
            {
                TestUtilities.putLine(string.Format("transferring file \"{0}\"", name));
                bool transferSuccess = comm.postFile(name);
                TestUtilities.checkResult(transferSuccess, "transfer");
            }

            foreach (string name in names)
            {
                if (!compareFileBytes(name))
                {
                    testFileTransfer = false;
                    break;
                }
            }
            TestUtilities.checkResult(testFileTransfer, "file transfers");
            TestUtilities.putLine();

            TestUtilities.vbtitle("test receiver close");
            csndMsg.type = CommMessage.MessageType.closeReceiver;
            comm.postMessage(csndMsg);
            crcvMsg = comm.getMessage();
            if (ClientEnvironment.verbose)
            {
                crcvMsg.show();
            }
            if (!compareMsgs(csndMsg, crcvMsg))
            {
                test = false;
            }
            TestUtilities.checkResult(test, "closeReceiver");
            TestUtilities.putLine();

            csndMsg.type = CommMessage.MessageType.closeSender;
            comm.postMessage(csndMsg);
            if (ClientEnvironment.verbose)
            {
                csndMsg.show();
            }
            // comm.getMessage() would fail because server has shut down
            // no rcvMsg so no compare

            TestUtilities.putLine("last message received\n");

            return(test && testFileTransfer);
        }