418707b4884d0056c5c8f567e3e1bc4ff90f3380
[senf.git] / Socket / SocketPolicy.test.hh
1 // $Id$
2 //
3 // Copyright (C) 2006 
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 #ifndef HH_SocketPolicy_test_
24 #define HH_SocketPolicy_test_ 1
25
26 // Custom includes
27 #include "SocketPolicy.hh"
28 #include "FileHandle.hh"
29
30 //#include "SocketPolicy.test.mpp"
31 ///////////////////////////////hh.p////////////////////////////////////////
32
33 namespace senf {
34
35 namespace test {
36
37     struct SomeAddressingPolicy : public senf::AddressingPolicyBase
38     {
39         typedef unsigned Address;
40         
41         static void peer(FileHandle handle, unsigned & addr)
42             { addr=1; }
43         static void local(FileHandle, unsigned & addr)
44             { addr=2; }
45         static void connect(FileHandle, unsigned addr)
46             {}
47         static void bind(FileHandle, unsigned addr)
48             {}
49     };
50
51     struct SomeFramingPolicy : public senf::FramingPolicyBase
52     {};
53
54     struct SomeCommunicationPolicy : public senf::CommunicationPolicyBase
55     {
56         static int accept(FileHandle handle, unsigned & addr)
57             { addr = 3; return -1; }
58     };
59
60     struct SomeReadPolicy : public senf::ReadPolicyBase
61     {
62         static unsigned const TEST_SIZE = 9;
63
64         static unsigned read(FileHandle handle, char * buffer, unsigned size)
65             {
66                 int const n (size<TEST_SIZE?size:TEST_SIZE);
67                 ::memcpy(buffer,"TEST-READ",n);
68                 return n;
69             }
70
71         static unsigned readfrom(FileHandle handle, char * buffer, unsigned size,
72                                  unsigned & address)
73             {
74                 return read(handle,buffer,size);
75             }
76     };
77
78     struct SomeWritePolicy : public senf::WritePolicyBase
79     {
80         static unsigned write(FileHandle handle, char const * buffer, unsigned size)
81             {
82                 if (size == 10 && ::strncmp(buffer,"TEST-WRITE",10) == 0)
83                     return size;
84                 else
85                     return 0;
86             }
87
88         static unsigned writeto(FileHandle handle, unsigned address,
89                                 char const * buffer, unsigned size)
90             {
91                 return write(handle,buffer,size);
92             }
93     };
94     
95     struct SomeBufferingPolicy : public senf::BufferingPolicyBase
96     {
97         static unsigned rcvbuf(FileHandle handle)
98             { return 0; }
99         static unsigned rcvbuf(FileHandle handle, unsigned size)
100             { return 0; }
101
102         static unsigned sndbuf(FileHandle handle)
103             { return 0; }
104         static unsigned sndbuf(FileHandle handle, unsigned size)
105             { return 0; }
106     };
107
108     typedef senf::MakeSocketPolicy<
109         SomeAddressingPolicy,
110         SomeFramingPolicy,
111         SomeCommunicationPolicy,
112         SomeReadPolicy,
113         SomeWritePolicy,
114         SomeBufferingPolicy
115         >::policy SomeSocketPolicy;
116
117 }}
118
119 ///////////////////////////////hh.e////////////////////////////////////////
120 //#include "SocketPolicy.test.cci"
121 //#include "SocketPolicy.test.ct"
122 //#include "SocketPolicy.test.cti"
123 //#include "SocketPolicy.test.mpp"
124 #endif
125
126 \f
127 // Local Variables:
128 // mode: c++
129 // c-file-style: "senf"
130 // End: