Develop and Download Open Source Software

Browse Subversion Repository

Contents of /connection/TestUdpipCtrl.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 247 - (show annotations) (download) (as text)
Tue Feb 19 01:32:43 2008 UTC (16 years, 1 month ago) by satofumi
File MIME type: text/x-c++src
File size: 1760 byte(s)
adjuste unknown collision.
1 /*!
2 \file
3 \brief UdpipCtrl のテスト
4
5 \author Satofumi KAMIMURA
6
7 $Id$
8 */
9
10 #include "TestUdpipCtrl.h"
11 #include "UdpipCtrl.h"
12
13 CPPUNIT_TEST_SUITE_REGISTRATION(UdpipCtrlTest);
14 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(UdpipCtrlTest, "UdpipCtrlTest");
15
16 using namespace beego;
17
18
19 enum { Port = 9763 };
20
21
22 /*!
23 \brief 送受信テスト
24 */
25 void UdpipCtrlTest::readWriteTest(void) {
26
27 UdpipCtrl udp_send(UdpipCtrl::ClientMode);
28 UdpipCtrl udp_recv(Port);
29
30 // 接続
31 bool ret = udp_send.connect("localhost", Port);
32 CPPUNIT_ASSERT_EQUAL(true, ret);
33
34 // 1文字送信、受信
35 int n = udp_send.send("A", 1);
36 CPPUNIT_ASSERT_EQUAL(1, n);
37
38 char ch;
39 for (int i = 0; i < 10; ++i) {
40 n = udp_recv.recv(&ch, 1, 10);
41 if (n > 0) {
42 break;
43 }
44 }
45 CPPUNIT_ASSERT_EQUAL(1, n);
46 CPPUNIT_ASSERT_EQUAL('A', ch);
47 }
48
49
50 void UdpipCtrlTest::bindTest(void) {
51
52 // 2ポートを bind して、送受信できるかを試す
53
54 // 送信ポート
55 UdpipCtrl udp_send;
56
57 // 2つの送信ポートの割り当て
58 bool ret = udp_send.connect("localhost", Port);
59 CPPUNIT_ASSERT_EQUAL(true, ret);
60 ret = udp_send.connect("localhost", Port + 1);
61 CPPUNIT_ASSERT_EQUAL(true, ret);
62
63 // 受信ポート
64 UdpipCtrl udp_recv_1(Port);
65 UdpipCtrl udp_recv_2(Port + 1);
66
67 // 送信
68 int n = udp_send.send("B", 1);
69 CPPUNIT_ASSERT_EQUAL(2, n);
70
71 // 受信
72 char recv_ch;
73 n = udp_recv_1.recv(&recv_ch, 1, 10);
74 CPPUNIT_ASSERT_EQUAL(1, n);
75 CPPUNIT_ASSERT_EQUAL(recv_ch, 'B');
76
77 n = udp_recv_2.recv(&recv_ch, 1, 10);
78 CPPUNIT_ASSERT_EQUAL(1, n);
79 CPPUNIT_ASSERT_EQUAL(recv_ch, 'B');
80 }
81
82
83 #if 0
84 void UdpipCtrlTest::bufferTest(void) {
85
86 // 連続送信がバッファリングされるかのテスト
87 // !!!
88 // UdpipCtrl の受信周りをリングバッファ管理してから、テストを行う
89
90 CPPUNIT_FAIL("Not implemented.");
91 }
92 #endif

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26