paragraph for gnunet devs that don't know how to use the web
[oweals/gnunet.git] / src / ats / test_ats_api.c
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2010-2015 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      Affero General Public License for more details.
14     
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 /**
19  * @file ats/test_ats_api.c
20  * @brief test ATS
21  * @author Christian Grothoff
22  */
23 #include "platform.h"
24 #include "test_ats_lib.h"
25
26 /**
27  * Global timeout for the testcase.
28  */
29 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
30
31 /**
32  * Definition of the test as a sequence of commands.
33  */
34 static struct Command test_commands[] = {
35   {
36     .code = CMD_ADD_ADDRESS,
37     .label = "add-address-0-0",
38     .details.add_address = {
39       .pid = 0,
40       .addr_num = 0,
41       .addr_flags = GNUNET_HELLO_ADDRESS_INFO_NONE,
42       .session = 0,
43       .properties = {
44         .scope = GNUNET_ATS_NET_LAN
45       }
46     }
47   },
48   /* 1: adding same address again should fail */
49   {
50     .code = CMD_ADD_ADDRESS,
51     .label = "add-address-0-0:FAIL",
52     .details.add_address = {
53       .pid = 0,
54       .addr_num = 0,
55       .addr_flags = GNUNET_HELLO_ADDRESS_INFO_NONE,
56       .session = 0,
57       .properties = {
58         .scope = GNUNET_ATS_NET_LAN
59       },
60       .expect_fail = 1
61     }
62   },
63   /* 2: some solver still require explicit start */
64   {
65     .code = CMD_REQUEST_CONNECTION_START,
66     .label = "request-0",
67     .details.request_connection_start = {
68       .pid = 0
69     }
70   },
71   /* 3: check we got an address */
72   {
73     .code = CMD_AWAIT_ADDRESS_SUGGESTION,
74     .details.await_address_suggestion = {
75       .add_label = "add-address-0-0"
76     }
77   },
78   /* 4: check monitor also got the address */
79   {
80     .code = CMD_AWAIT_ADDRESS_INFORMATION,
81     .details.await_address_information = {
82       .add_label = "add-address-0-0"
83     }
84   },
85   /* 5: test session API */
86   {
87     .code = CMD_ADD_SESSION,
88     .label = "add-session-0-0-1",
89     .details.add_session = {
90       .add_label ="add-address-0-0",
91       .session = 1
92     }
93   },
94   {
95     .code = CMD_DEL_SESSION,
96     .details.del_session = {
97       .add_session_label = "add-session-0-0-1",
98     }
99   },
100   /* 7: test preference API */
101   {
102     .code = CMD_CHANGE_PREFERENCE,
103     .details.change_preference = {
104       .pid = 0
105       /* FIXME: preference details */
106     }
107   },
108   {
109     .code = CMD_PROVIDE_FEEDBACK,
110     .details.provide_feedback = {
111       .pid = 0,
112       .scope = { 50LL }
113       /* FIXME: preference details */
114     }
115   },
116   /* 9: test sanity check address listing */
117   {
118     .code = CMD_LIST_ADDRESSES,
119     .details.list_addresses = {
120       .pid = 0,
121       .all = 1,
122       .min_calls = 2, // ?
123       .max_calls = 2,
124       .min_active_calls = 1,
125       .max_active_calls = 1
126     }
127   },
128   /* 10: remove address testing */
129   {
130     .code = CMD_DEL_ADDRESS,
131     .details.del_address = {
132       .add_label = "add-address-0-0"
133     }
134   },
135   /* 11: check we got disconnected */
136   {
137     .code = CMD_AWAIT_DISCONNECT_SUGGESTION,
138     .details.await_disconnect_suggestion = {
139       .pid = 0
140     }
141   },
142   /* 12: just for symmetry, also stop asking for the connection */
143   {
144     .code = CMD_REQUEST_CONNECTION_STOP,
145     .details.request_connection_stop = {
146       .connect_label = "request-0",
147     }
148   },
149   /* 13: add address again */
150   {
151     .code = CMD_ADD_ADDRESS,
152     .label = "add-address-0-0:1",
153     .details.add_address = {
154       .pid = 0,
155       .addr_num = 0,
156       .session = 0,
157       .properties = {
158         .scope = GNUNET_ATS_NET_LAN
159       }
160     }
161   },
162   /* 14: some solver still require explicit start */
163   {
164     .code = CMD_REQUEST_CONNECTION_START,
165     .label = "request-0",
166     .details.request_connection_start = {
167       .pid = 0
168     }
169   },
170   /* 15: check we got an address */
171   {
172     .code = CMD_AWAIT_ADDRESS_SUGGESTION,
173     .details.await_address_suggestion = {
174       .add_label = "add-address-0-0:1"
175     }
176   },
177   /* 16: add alternative address */
178   {
179     .code = CMD_ADD_ADDRESS,
180     .label = "add-address-0-1",
181     .details.add_address = {
182       .pid = 0,
183       .addr_num = 1,
184       .addr_flags = GNUNET_HELLO_ADDRESS_INFO_NONE,
185       .session = 0,
186       .properties = {
187         .scope = GNUNET_ATS_NET_LAN
188       }
189     }
190   },
191   /* 17: remove original address */
192   {
193     .code = CMD_DEL_ADDRESS,
194     .details.del_address = {
195       .add_label = "add-address-0-0:1"
196     }
197   },
198   /* 18: check we switched to alternative address */
199   {
200     .code = CMD_AWAIT_ADDRESS_SUGGESTION,
201     .details.await_address_suggestion = {
202       .add_label = "add-address-0-1"
203     }
204   },
205   /* 19: remove alternative address */
206   {
207     .code = CMD_DEL_ADDRESS,
208     .details.del_address = {
209       .add_label = "add-address-0-1"
210     }
211   },
212   /* 20: check we got disconnected */
213   {
214     .code = CMD_AWAIT_DISCONNECT_SUGGESTION,
215     .details.await_disconnect_suggestion = {
216       .pid = 0
217     }
218   },
219   /* 21: just for symmetry, also stop asking for the connection */
220   {
221     .code = CMD_REQUEST_CONNECTION_STOP,
222     .details.request_connection_stop = {
223       .connect_label = "request-0",
224     }
225   },
226   /* Test ends successfully */
227   {
228     .code = CMD_END_PASS
229   }
230 };
231
232
233 int
234 main (int argc,
235       char *argv[])
236 {
237   return TEST_ATS_run (argc,
238                        argv,
239                        test_commands,
240                        TIMEOUT);
241 }
242
243
244 /* end of file test_ats_api.c */