00001
00002
00003
00004
00005
00006
00007
00008
00009
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
00090 IPP_UTEST_ASSERT_EQUALS(server.GetState(),ippSimpleServer::connected );
00091
00092
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
00122
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
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
00160 IPP_UTEST_ASSERT_EQUALS(server.GetState(),ippSimpleServer::connected );
00161
00162
00163 }
00164
00165