summaryrefslogtreecommitdiff
path: root/test/sockstreambuf_test.h
blob: b6efd05cb34f0fdd7a46f933fa1ff4cce4b02f36 (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
/*
*  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/>.
*
*/

#ifndef SOCKSTREAMBUF_TEST_H
#define SOCKSTREAMBUF_TEST_H

#include <cppunit/extensions/HelperMacros.h>
#include <psocksxx/sockaddr.h>

#define LOCAL_LISTENER_SOCK_PATH    "/tmp/psocksxx.listener.sock"
#define LOCAL_SOCK_PATH             "/tmp/psocksxx.sock"


class sockstreambuf_test : public CppUnit::TestFixture {

	// setup the test suite
	CPPUNIT_TEST_SUITE( sockstreambuf_test );
	CPPUNIT_TEST( test_constructors );
	CPPUNIT_TEST( test_open_close_local_ip );
	CPPUNIT_TEST( test_flush_empty );
	CPPUNIT_TEST( test_bad_flush );
	CPPUNIT_TEST( test_bad_connect_failure );
	CPPUNIT_TEST( test_bad_bind_failure );
	CPPUNIT_TEST( test_bad_listen_failure );
	CPPUNIT_TEST( test_bad_accept_failure );
	CPPUNIT_TEST( test_local_bind );
	CPPUNIT_TEST( test_local_listen );
	CPPUNIT_TEST( test_local_connect );
	CPPUNIT_TEST( test_local_connect_timeout );
	CPPUNIT_TEST( test_local_accept );
	CPPUNIT_TEST( test_local_flush );
	CPPUNIT_TEST( test_local_flush_read );
	CPPUNIT_TEST( test_local_ostream );
	CPPUNIT_TEST( test_local_istream );
	CPPUNIT_TEST( test_set_timeout );
	CPPUNIT_TEST( test_clear_timeout );
	CPPUNIT_TEST( test_local_read_timeout );
	CPPUNIT_TEST_SUITE_END();

public:
	sockstreambuf_test();
	~sockstreambuf_test();

	void setUp();
	void tearDown();

	void test_constructors();
	void test_open_close_local_ip();
	void test_flush_empty();
	void test_bad_flush();
	void test_bad_connect_failure();
	void test_bad_bind_failure();
	void test_bad_listen_failure();
	void test_bad_accept_failure();
	void test_local_bind();
	void test_local_listen();
	void test_local_connect();
	void test_local_connect_timeout();
	void test_local_accept();
	void test_local_flush();
	void test_local_flush_read();
	void test_local_ostream();
	void test_local_istream();
	void test_set_timeout();
	void test_clear_timeout();
	void test_local_read_timeout();


private:

	// base sockaddr class for negative testing purposes
	struct : public psocksxx::sockaddr, public sockaddr {
		socklen_t size() const throw() { return sizeof( ::sockaddr ); }
		::sockaddr * psockaddr() const throw() { return (::sockaddr *) this; }
	} _sockaddr;


	void connect_local() throw();

};


#endif /* !SOCKSTREAMBUF_TEST_H */