Added a test to wxSocket sample (client side socket event test)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3557 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -48,6 +48,7 @@ class MyFrame: public wxFrame
|
|||||||
DECLARE_CLASS(MyFrame)
|
DECLARE_CLASS(MyFrame)
|
||||||
public:
|
public:
|
||||||
MyClient *sock;
|
MyClient *sock;
|
||||||
|
int m_good;
|
||||||
|
|
||||||
MyFrame(void);
|
MyFrame(void);
|
||||||
virtual ~MyFrame();
|
virtual ~MyFrame();
|
||||||
@@ -57,6 +58,7 @@ public:
|
|||||||
void OnQuitApp(wxCommandEvent& evt);
|
void OnQuitApp(wxCommandEvent& evt);
|
||||||
void OnExecOpenConnection(wxCommandEvent& evt);
|
void OnExecOpenConnection(wxCommandEvent& evt);
|
||||||
void OnExecCloseConnection(wxCommandEvent& evt);
|
void OnExecCloseConnection(wxCommandEvent& evt);
|
||||||
|
void OnSocketEvent(wxSocketEvent& evt);
|
||||||
void UpdateStatus();
|
void UpdateStatus();
|
||||||
|
|
||||||
void Download(wxInputStream *input);
|
void Download(wxInputStream *input);
|
||||||
@@ -86,6 +88,7 @@ const int SKDEMO_TEST2 = 104;
|
|||||||
const int SKDEMO_CLOSE = 105;
|
const int SKDEMO_CLOSE = 105;
|
||||||
const int SKDEMO_TEST3 = 106;
|
const int SKDEMO_TEST3 = 106;
|
||||||
const int ID_TEST_CLOSE = 107;
|
const int ID_TEST_CLOSE = 107;
|
||||||
|
const int SKDEMO_SCK = 108;
|
||||||
|
|
||||||
IMPLEMENT_APP(MyApp)
|
IMPLEMENT_APP(MyApp)
|
||||||
|
|
||||||
@@ -188,8 +191,23 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|||||||
EVT_MENU(SKDEMO_QUIT, MyFrame::OnQuitApp)
|
EVT_MENU(SKDEMO_QUIT, MyFrame::OnQuitApp)
|
||||||
EVT_MENU(SKDEMO_CONNECT, MyFrame::OnExecOpenConnection)
|
EVT_MENU(SKDEMO_CONNECT, MyFrame::OnExecOpenConnection)
|
||||||
EVT_MENU(SKDEMO_CLOSE, MyFrame::OnExecCloseConnection)
|
EVT_MENU(SKDEMO_CLOSE, MyFrame::OnExecCloseConnection)
|
||||||
|
EVT_SOCKET(SKDEMO_SCK, MyFrame::OnSocketEvent)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
class MyFrameSocketTimer: public wxTimer {
|
||||||
|
public:
|
||||||
|
void Notify() {
|
||||||
|
*m_var = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int *m_var;
|
||||||
|
};
|
||||||
|
|
||||||
|
void MyFrame::OnSocketEvent(wxSocketEvent& evt)
|
||||||
|
{
|
||||||
|
m_good = 1;
|
||||||
|
}
|
||||||
|
|
||||||
void MyFrame::OnCloseTest(wxCommandEvent& evt)
|
void MyFrame::OnCloseTest(wxCommandEvent& evt)
|
||||||
{
|
{
|
||||||
wxButton *button = (wxButton *)evt.GetEventObject();
|
wxButton *button = (wxButton *)evt.GetEventObject();
|
||||||
@@ -259,7 +277,37 @@ void MyFrame::OnExecTest1(wxCommandEvent& WXUNUSED(evt))
|
|||||||
sock->Close();
|
sock->Close();
|
||||||
UpdateStatus();
|
UpdateStatus();
|
||||||
} else
|
} else
|
||||||
text_win->WriteText("done\nTest 1 passed !\n");
|
text_win->WriteText("done\nTest 1A passed !\n");
|
||||||
|
|
||||||
|
/* No 2 */
|
||||||
|
sock->SetEventHandler(*this, SKDEMO_SCK);
|
||||||
|
sock->SetNotify(GSOCK_INPUT | GSOCK_LOST);
|
||||||
|
sock->Notify(TRUE);
|
||||||
|
|
||||||
|
text_win->WriteText("Test 1B: sending bytes to the server\n");
|
||||||
|
wxYield();
|
||||||
|
sock->Write((char *)buf, wxStrlen(buf)+1);
|
||||||
|
text_win->WriteText("Waiting for incoming bytes (timeout = 2 sec) ...");
|
||||||
|
wxYield();
|
||||||
|
|
||||||
|
m_good = 2;
|
||||||
|
|
||||||
|
MyFrameSocketTimer timer;
|
||||||
|
|
||||||
|
timer.m_var = &m_good;
|
||||||
|
timer.Start(2000, TRUE);
|
||||||
|
|
||||||
|
while (m_good == 2)
|
||||||
|
wxYield();
|
||||||
|
|
||||||
|
if (!m_good) {
|
||||||
|
text_win->WriteText("Timeout ! Failed.\n");
|
||||||
|
sock->Close();
|
||||||
|
UpdateStatus();
|
||||||
|
} else
|
||||||
|
text_win->WriteText("Success.");
|
||||||
|
|
||||||
|
sock->Read((char *)buf2, wxStrlen(buf)+1);
|
||||||
|
|
||||||
dlgbox->Layout();
|
dlgbox->Layout();
|
||||||
dlgbox->ShowModal();
|
dlgbox->ShowModal();
|
||||||
|
@@ -197,6 +197,10 @@ void MyFrame::ExecTest1(wxSocketBase *sock_o)
|
|||||||
|
|
||||||
l = sock_o->Read(buf, 50).LastCount();
|
l = sock_o->Read(buf, 50).LastCount();
|
||||||
sock_o->Write(buf, l);
|
sock_o->Write(buf, l);
|
||||||
|
l = sock_o->Read(buf, 50).LastCount();
|
||||||
|
sock_o->Write(buf, l);
|
||||||
|
|
||||||
|
delete[] buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyFrame::UpdateStatus(int incr)
|
void MyFrame::UpdateStatus(int incr)
|
||||||
|
Reference in New Issue
Block a user