/*----< test Comm instance >-----------------------------------*/ /* * - Note: change every occurance of string "Odin" to your machine name * */ public static bool testComm() { TestUtilities.vbtitle("testing Comm"); var test = true; var comm = new Comm("http://localhost", 8081); var csndMsg = new CommMessage(CommMessage.MessageType.request); csndMsg.command = "show"; csndMsg.author = "Jim Fawcett"; var localEndPoint = "http://localhost:8081/IMessagePassingComm"; csndMsg.to = localEndPoint; csndMsg.from = localEndPoint; comm.postMessage(csndMsg); var crcvMsg = comm.getMessage(); if (ClientEnvironment.verbose) { crcvMsg.show(); } if (!compareMsgs(csndMsg, crcvMsg)) { test = false; } TestUtilities.checkResult(test, "csndMsg equals crcvMsg"); TestUtilities.putLine(comm.size() + " messages left in queue"); TestUtilities.putLine(); TestUtilities.vbtitle("testing connect to new EndPoint"); csndMsg.to = "http://Odin:8081/IMessagePassingComm"; comm.postMessage(csndMsg); crcvMsg = comm.getMessage(); if (ClientEnvironment.verbose) { crcvMsg.show(); } if (!compareMsgs(csndMsg, crcvMsg)) { test = false; } TestUtilities.checkResult(test, "csndMsg equals crcvMsg"); TestUtilities.putLine(comm.size() + " messages left in queue"); TestUtilities.putLine(); TestUtilities.vbtitle("testing file transfer"); var testFileTransfer = true; var names = getClientFileList(); foreach (var name in names) { TestUtilities.putLine(string.Format("transferring file \"{0}\"", name)); var transferSuccess = comm.postFile(name); TestUtilities.checkResult(transferSuccess, "transfer"); } foreach (var name in names) { if (!compareFileBytes(name)) { testFileTransfer = false; break; } } TestUtilities.checkResult(testFileTransfer, "file transfers"); TestUtilities.putLine(comm.size() + " messages left in queue"); TestUtilities.putLine(); TestUtilities.vbtitle("test closeConnection then postMessage"); comm.closeConnection(); var newMsg = new CommMessage(CommMessage.MessageType.request); newMsg.to = localEndPoint; newMsg.from = localEndPoint; comm.postMessage(newMsg); var reply = comm.getMessage(); reply.show(); // if we get here, test passed TestUtilities.checkResult(true, "closeSenderConnenction then PostMessage"); TestUtilities.putLine(comm.size() + " messages left in queue"); TestUtilities.putLine(); TestUtilities.vbtitle("test receiver close"); csndMsg.type = CommMessage.MessageType.closeReceiver; if (ClientEnvironment.verbose) { csndMsg.show(); } comm.postMessage(csndMsg); crcvMsg = comm.getMessage(); if (ClientEnvironment.verbose) { crcvMsg.show(); } if (!compareMsgs(csndMsg, crcvMsg)) { test = false; } TestUtilities.checkResult(test, "closeReceiver"); TestUtilities.putLine(comm.size() + " messages left in queue"); TestUtilities.putLine(); csndMsg.type = CommMessage.MessageType.closeSender; comm.postMessage(csndMsg); if (ClientEnvironment.verbose) { csndMsg.show(); } TestUtilities.putLine(comm.size() + " messages left in queue"); // comm.getMessage() would fail because server has shut down // no rcvMsg so no compare TestUtilities.putLine("last message received\n"); TestUtilities.putLine("Test comm.restart on same port - expected to fail"); if (comm.restart(8081)) { var newerMsg = new CommMessage(CommMessage.MessageType.request); newerMsg.to = ClientEnvironment.endPoint; newerMsg.from = ClientEnvironment.endPoint; comm.postMessage(newerMsg); var newReply = comm.getMessage(); newReply.show(); } else { Console.Write("\n can't restart but won't fail test"); } return(test && testFileTransfer); }