switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Socket / SocketPolicy.test.hh
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28
29 #ifndef HH_SENF_Socket_SocketPolicy_test_
30 #define HH_SENF_Socket_SocketPolicy_test_ 1
31
32 // Custom includes
33 #include "SocketPolicy.hh"
34 #include "FileHandle.hh"
35
36 //#include "SocketPolicy.test.mpp"
37 //-/////////////////////////////////////////////////////////////////////////////////////////////////
38
39 namespace senf {
40 namespace test {
41
42     struct SomeAddressingPolicy : public senf::AddressingPolicyBase
43     {
44         typedef unsigned Address;
45
46         static void peer(FileHandle handle, unsigned & addr)
47             { addr=1; }
48         static void local(FileHandle, unsigned & addr)
49             { addr=2; }
50         static void connect(FileHandle, unsigned addr)
51             {}
52         static void bind(FileHandle, unsigned addr)
53             {}
54     };
55
56     struct SomeFramingPolicy : public senf::FramingPolicyBase
57     {};
58
59     struct SomeCommunicationPolicy : public senf::CommunicationPolicyBase
60     {
61         static int accept(FileHandle handle, unsigned & addr)
62             { addr = 3; return -1; }
63         static int accept(FileHandle handle)
64             { return -1; }
65     };
66
67     struct SomeReadPolicy : public senf::ReadPolicyBase
68     {
69         static unsigned const TEST_SIZE = 9;
70
71         static unsigned read(FileHandle handle, char * buffer, unsigned size)
72             {
73                 int const n (size<TEST_SIZE?size:TEST_SIZE);
74                 ::memcpy(buffer,"TEST-READ",n);
75                 return n;
76             }
77
78         static unsigned readfrom(FileHandle handle, char * buffer, unsigned size,
79                                  unsigned & address)
80             {
81                 return read(handle,buffer,size);
82             }
83     };
84
85     struct SomeWritePolicy : public senf::WritePolicyBase
86     {
87         static unsigned write(FileHandle handle, char const * buffer, unsigned size)
88             {
89                 if (size == 10 && ::strncmp(buffer,"TEST-WRITE",10) == 0)
90                     return size;
91                 else
92                     return 0;
93             }
94
95         static unsigned writeto(FileHandle handle, unsigned address,
96                                 char const * buffer, unsigned size)
97             {
98                 return write(handle,buffer,size);
99             }
100     };
101
102     typedef senf::MakeSocketPolicy<
103         SomeAddressingPolicy,
104         SomeFramingPolicy,
105         SomeCommunicationPolicy,
106         SomeReadPolicy,
107         SomeWritePolicy
108         >::policy SomeSocketPolicy;
109
110 }}
111
112 //-/////////////////////////////////////////////////////////////////////////////////////////////////
113 //#include "SocketPolicy.test.cci"
114 //#include "SocketPolicy.test.ct"
115 //#include "SocketPolicy.test.cti"
116 //#include "SocketPolicy.test.mpp"
117 #endif
118
119 \f
120 // Local Variables:
121 // mode: c++
122 // fill-column: 100
123 // c-file-style: "senf"
124 // indent-tabs-mode: nil
125 // ispell-local-dictionary: "american"
126 // compile-command: "scons -u test"
127 // comment-column: 40
128 // End: