Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ippClientServerSpyTestCase.cpp

Go to the documentation of this file.
00001 // 
00002 // DISCLAIMER: 
00003 //  This software was produced by the National Institute of Standards 
00004 //  and Technology (NIST), an agency of the U.S. government, and by statute is 
00005 //  not subject to copyright in the United States.  Recipients of this 
00006 //  software assume all responsibility associated with its operation,
00007 //  modification,maintenance, and subsequent redistribution. 
00008 //
00009 //  See NIST Administration Manual 4.09.07 b and Appendix I. 
00010 //
00011 #define _CRT_SECURE_NO_DEPRECATE
00012 
00013 #include "ippdme/winsock.h"
00014 #include "ippClientServerSpyTestCase.h"
00015 #include "ippMemoryLeakDetector.h"
00016 
00017 #include "ippdme/Server/ippSimpleServer.h"
00018 #include "ippdme/Server/ippSimpleClient.h"
00019 #include "ippdme/Spy/ippClientServerSpy.h"
00020 #include "ippdme/Server/ippLogger.h"
00021 #include "ippdme/assert.h"
00022 
00023 
00024 
00025 
00026 
00027 
00028 CXXTEST_ENUM_TRAITS( ippSimpleServer::STATE,
00029                      CXXTEST_ENUM_MEMBER( ippSimpleServer::uninitialized )
00030                      CXXTEST_ENUM_MEMBER( ippSimpleServer::listening )
00031                      CXXTEST_ENUM_MEMBER( ippSimpleServer::connected ));
00032 
00033 
00034 
00035 CXXTEST_ENUM_TRAITS( ippSimpleClient::STATE,
00036                      CXXTEST_ENUM_MEMBER( ippSimpleClient::disconnected )
00037                      CXXTEST_ENUM_MEMBER( ippSimpleClient::trying_to_connect )
00038                      CXXTEST_ENUM_MEMBER( ippSimpleClient::connected ));
00039 
00040 
00041 class ippCommand;
00042 //-----------------------------------------------------------------------------
00043 #define HEARTBEAT server.HeartBeat();client.HeartBeat();spy.HeartBeat();server.HeartBeat();client.HeartBeat();
00044 
00045 void ippClientServerSpyTestCase::testSpy()
00046 {
00047    ippSimpleServer server;
00048    IPP_UTEST_ASSERT_EQUALS(server.GetState() , ippSimpleServer::uninitialized );
00049    server.PowerOn(33333);
00050    IPP_UTEST_ASSERT_EQUALS(server.GetState() , ippSimpleServer::listening );
00051   
00052    ippClientServerSpy spy;
00053    spy.Start(44444,"localhost",33333);
00054 
00055    ippSimpleClient client;
00056    IPP_UTEST_ASSERT_EQUALS(client.GetState(),ippSimpleClient::disconnected );
00057   
00058    client.Connect("localhost",44444);
00059    HEARTBEAT;   HEARTBEAT;   HEARTBEAT;
00060    IPP_UTEST_ASSERT_EQUALS(client.GetState() , ippSimpleClient::connected );
00061 
00062 
00063    client.SendCommand("00001 StartSession()");
00064    HEARTBEAT;   HEARTBEAT;   HEARTBEAT;
00065    IPP_UTEST_ASSERT(server.InSession());
00066    IPP_UTEST_ASSERT(!client.NeedToSendClearAllErrors());
00067    IPP_UTEST_ASSERT(client.ReadyToSend());
00068 
00069    client.SendCommand("00002 CRAPCRAP()");
00070    HEARTBEAT;   HEARTBEAT;   HEARTBEAT;
00071    IPP_UTEST_ASSERT(server.InSession());
00072    IPP_UTEST_ASSERT(client.NeedToSendClearAllErrors());
00073    IPP_UTEST_ASSERT(client.ReadyToSend());
00074    client.ClearAllErrors();
00075    HEARTBEAT;   HEARTBEAT;   HEARTBEAT;
00076    IPP_UTEST_ASSERT(!client.NeedToSendClearAllErrors());
00077    IPP_UTEST_ASSERT(client.ReadyToSend());
00078 
00079    client.SendCommand("00002 EndSession()");
00080    HEARTBEAT;   HEARTBEAT;   HEARTBEAT;
00081    IPP_UTEST_ASSERT(!server.InSession());
00082 
00083 
00084    client.Disconnect();
00085    HEARTBEAT;   HEARTBEAT;   HEARTBEAT;
00086    IPP_UTEST_ASSERT(!server.InSession());
00087    IPP_UTEST_ASSERT_EQUALS(client.GetState(),ippSimpleClient::disconnected );
00088 
00089    // the server , however stays connected as the spy is connected to it
00090    IPP_UTEST_ASSERT_EQUALS(server.GetState(),ippSimpleServer::connected );
00091 
00092    // verifies that reconnection can happen
00093    client.Connect("localhost",44444);
00094    HEARTBEAT;   HEARTBEAT;   HEARTBEAT;
00095    IPP_UTEST_ASSERT_EQUALS(client.GetState() , ippSimpleClient::connected );
00096 
00097    client.SendCommand("00001 StartSession()");
00098    HEARTBEAT;   HEARTBEAT;   HEARTBEAT;
00099    IPP_UTEST_ASSERT(server.InSession());
00100    IPP_UTEST_ASSERT(!client.NeedToSendClearAllErrors());
00101    IPP_UTEST_ASSERT(client.ReadyToSend());
00102 
00103    client.SendCommand("00002 EndSession()");
00104    HEARTBEAT;   HEARTBEAT;   HEARTBEAT;
00105    IPP_UTEST_ASSERT(!server.InSession());
00106 
00107 
00108    client.Disconnect();
00109    IPP_UTEST_ASSERT(!server.InSession());
00110    IPP_UTEST_ASSERT_EQUALS(client.GetState(),ippSimpleClient::disconnected );
00111 }
00112 
00113 #undef  HEARTBEAT
00114 #define HEARTBEAT server.HeartBeat();;spy.HeartBeat();server.HeartBeat();
00115 
00116 #include "ippMockExecutor.h"
00117 
00118 
00119 void ippClientServerSpyTestCase::testSpy_with_uncompliant_client1()
00120 {
00121   // special test that verifies that the spy is 
00122   // not getting upset by multiple commands being send and not acknowledged.
00123 
00124   ippMockExecutor executor;
00125   ippSimpleServer server(&executor);
00126   IPP_UTEST_ASSERT_EQUALS(server.GetState() , ippSimpleServer::uninitialized );
00127 
00128   server.PowerOn(33333);
00129   IPP_UTEST_ASSERT_EQUALS(server.GetState() , ippSimpleServer::listening );
00130 
00131   ippClientServerSpy spy;
00132   spy.Start(44444,"localhost",33333);
00133 
00134 
00135   ippSocket fautly_client;
00136   fautly_client.Create();
00137   fautly_client.Connect("localhost",44444);
00138   HEARTBEAT;   HEARTBEAT;   HEARTBEAT;
00139 
00140   // client send a few commands without waiting for acknowledgment
00141   fautly_client.Write("00001 StartSession()\r\n00002 GetDMEVersion()\r\n00003 GetDMEVersion()\r\n00004 GetDMEVersion()\r\n");
00142   HEARTBEAT;   HEARTBEAT;   HEARTBEAT;
00143   IPP_UTEST_ASSERT(server.InSession());
00144 
00145   fautly_client.Write("00100 IsHomed()\r\n");
00146 
00147   fautly_client.Write("99999 EndSession()\r\n");
00148   HEARTBEAT;   HEARTBEAT;   HEARTBEAT;
00149   IPP_UTEST_ASSERT(!server.InSession());
00150   
00151   IPP_UTEST_ASSERT_EQUALS(3,executor.GetDMEVersionCounter());
00152 
00153 
00154   fautly_client.Close();
00155   HEARTBEAT;   HEARTBEAT;   HEARTBEAT;
00156   IPP_UTEST_ASSERT(!server.InSession());
00157   IPP_UTEST_ASSERT(!fautly_client.IsValid() );
00158 
00159   // the server , however stays connected as the spy is connected to it
00160   IPP_UTEST_ASSERT_EQUALS(server.GetState(),ippSimpleServer::connected );
00161 
00162 
00163 }
00164 
00165 

Generated on Wed Nov 8 00:20:07 2006 for IPPDME by  doxygen 1.4.1