blob: 30c4ead61233caa99ba2be3cccf059ca933c5836 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
/*
* psocksxx - A C++ wrapper for POSIX sockets
* Copyright (C) 2013 Uditha Atukorala
*
* This software library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This software library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software library. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "lsockstream_test.h"
#include "lecho.h"
#include <psocksxx/lsockstream.h>
// register the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION( lsockstream_test );
// use namespace psocksxx
using namespace psocksxx;
void lsockstream_test::test_constructors() {
// default constructor
CPPUNIT_ASSERT_NO_THROW( lsockstream l );
}
void lsockstream_test::test_connect_fail() {
// local socket stream
lsockstream l;
// this should throw a file not found error
CPPUNIT_ASSERT_THROW( l.connect( LOCAL_SOCK_PATH ), sockexception );
}
void lsockstream_test::test_connect_addr_fail() {
// local socket stream
lsockstream l;
// local (unix) socket address
lsockaddr saddr( LOCAL_SOCK_PATH );
// this should throw a file not found error
CPPUNIT_ASSERT_THROW( l.connect( &saddr ), sockexception );
}
void lsockstream_test::test_connect() {
// local socket stream
lsockstream l;
// local echo server
lecho echo( LOCAL_LISTENER_SOCK_PATH );
// connect
CPPUNIT_ASSERT_NO_THROW( l.connect( LOCAL_LISTENER_SOCK_PATH ) );
}
void lsockstream_test::test_connect_addr() {
// local socket stream
lsockstream l;
// local (unix) socket address
lsockaddr saddr( LOCAL_LISTENER_SOCK_PATH );
// local echo server
lecho echo( LOCAL_LISTENER_SOCK_PATH );
// connect
CPPUNIT_ASSERT_NO_THROW( l.connect( &saddr ) );
}
void lsockstream_test::test_read_timeout() {
// local socket stream
lsockstream l;
// local (unix) socket address
lsockaddr saddr( LOCAL_LISTENER_SOCK_PATH );
// local echo server
lecho echo( LOCAL_LISTENER_SOCK_PATH );
// connect
try {
l.connect( &saddr );
} catch( sockexception &e ) {
CPPUNIT_FAIL( e.what() );
return;
}
// set timeout
l.timeout( 0, 200 );
// read
char c = l.get();
// read - should timed out
CPPUNIT_ASSERT( true == l.timedout() );
}
|