first batch of license fixes (boring)
[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 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 /**
16  * @file ats/test_ats_api.c
17  * @brief test ATS
18  * @author Christian Grothoff
19  */
20 #include "platform.h"
21 #include "test_ats_lib.h"
22
23 /**
24  * Global timeout for the testcase.
25  */
26 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
27
28 /**
29  * Definition of the test as a sequence of commands.
30  */
31 static struct Command test_commands[] = {
32   {
33     .code = CMD_ADD_ADDRESS,
34     .label = "add-address-0-0",
35     .details.add_address = {
36       .pid = 0,
37       .addr_num = 0,
38       .addr_flags = GNUNET_HELLO_ADDRESS_INFO_NONE,
39       .session = 0,
40       .properties = {
41         .scope = GNUNET_ATS_NET_LAN
42       }
43     }
44   },
45   /* 1: adding same address again should fail */
46   {
47     .code = CMD_ADD_ADDRESS,
48     .label = "add-address-0-0:FAIL",
49     .details.add_address = {
50       .pid = 0,
51       .addr_num = 0,
52       .addr_flags = GNUNET_HELLO_ADDRESS_INFO_NONE,
53       .session = 0,
54       .properties = {
55         .scope = GNUNET_ATS_NET_LAN
56       },
57       .expect_fail = 1
58     }
59   },
60   /* 2: some solver still require explicit start */
61   {
62     .code = CMD_REQUEST_CONNECTION_START,
63     .label = "request-0",
64     .details.request_connection_start = {
65       .pid = 0
66     }
67   },
68   /* 3: check we got an address */
69   {
70     .code = CMD_AWAIT_ADDRESS_SUGGESTION,
71     .details.await_address_suggestion = {
72       .add_label = "add-address-0-0"
73     }
74   },
75   /* 4: check monitor also got the address */
76   {
77     .code = CMD_AWAIT_ADDRESS_INFORMATION,
78     .details.await_address_information = {
79       .add_label = "add-address-0-0"
80     }
81   },
82   /* 5: test session API */
83   {
84     .code = CMD_ADD_SESSION,
85     .label = "add-session-0-0-1",
86     .details.add_session = {
87       .add_label ="add-address-0-0",
88       .session = 1
89     }
90   },
91   {
92     .code = CMD_DEL_SESSION,
93     .details.del_session = {
94       .add_session_label = "add-session-0-0-1",
95     }
96   },
97   /* 7: test preference API */
98   {
99     .code = CMD_CHANGE_PREFERENCE,
100     .details.change_preference = {
101       .pid = 0
102       /* FIXME: preference details */
103     }
104   },
105   {
106     .code = CMD_PROVIDE_FEEDBACK,
107     .details.provide_feedback = {
108       .pid = 0,
109       .scope = { 50LL }
110       /* FIXME: preference details */
111     }
112   },
113   /* 9: test sanity check address listing */
114   {
115     .code = CMD_LIST_ADDRESSES,
116     .details.list_addresses = {
117       .pid = 0,
118       .all = 1,
119       .min_calls = 2, // ?
120       .max_calls = 2,
121       .min_active_calls = 1,
122       .max_active_calls = 1
123     }
124   },
125   /* 10: remove address testing */
126   {
127     .code = CMD_DEL_ADDRESS,
128     .details.del_address = {
129       .add_label = "add-address-0-0"
130     }
131   },
132   /* 11: check we got disconnected */
133   {
134     .code = CMD_AWAIT_DISCONNECT_SUGGESTION,
135     .details.await_disconnect_suggestion = {
136       .pid = 0
137     }
138   },
139   /* 12: just for symmetry, also stop asking for the connection */
140   {
141     .code = CMD_REQUEST_CONNECTION_STOP,
142     .details.request_connection_stop = {
143       .connect_label = "request-0",
144     }
145   },
146   /* 13: add address again */
147   {
148     .code = CMD_ADD_ADDRESS,
149     .label = "add-address-0-0:1",
150     .details.add_address = {
151       .pid = 0,
152       .addr_num = 0,
153       .session = 0,
154       .properties = {
155         .scope = GNUNET_ATS_NET_LAN
156       }
157     }
158   },
159   /* 14: some solver still require explicit start */
160   {
161     .code = CMD_REQUEST_CONNECTION_START,
162     .label = "request-0",
163     .details.request_connection_start = {
164       .pid = 0
165     }
166   },
167   /* 15: check we got an address */
168   {
169     .code = CMD_AWAIT_ADDRESS_SUGGESTION,
170     .details.await_address_suggestion = {
171       .add_label = "add-address-0-0:1"
172     }
173   },
174   /* 16: add alternative address */
175   {
176     .code = CMD_ADD_ADDRESS,
177     .label = "add-address-0-1",
178     .details.add_address = {
179       .pid = 0,
180       .addr_num = 1,
181       .addr_flags = GNUNET_HELLO_ADDRESS_INFO_NONE,
182       .session = 0,
183       .properties = {
184         .scope = GNUNET_ATS_NET_LAN
185       }
186     }
187   },
188   /* 17: remove original address */
189   {
190     .code = CMD_DEL_ADDRESS,
191     .details.del_address = {
192       .add_label = "add-address-0-0:1"
193     }
194   },
195   /* 18: check we switched to alternative address */
196   {
197     .code = CMD_AWAIT_ADDRESS_SUGGESTION,
198     .details.await_address_suggestion = {
199       .add_label = "add-address-0-1"
200     }
201   },
202   /* 19: remove alternative address */
203   {
204     .code = CMD_DEL_ADDRESS,
205     .details.del_address = {
206       .add_label = "add-address-0-1"
207     }
208   },
209   /* 20: check we got disconnected */
210   {
211     .code = CMD_AWAIT_DISCONNECT_SUGGESTION,
212     .details.await_disconnect_suggestion = {
213       .pid = 0
214     }
215   },
216   /* 21: just for symmetry, also stop asking for the connection */
217   {
218     .code = CMD_REQUEST_CONNECTION_STOP,
219     .details.request_connection_stop = {
220       .connect_label = "request-0",
221     }
222   },
223   /* Test ends successfully */
224   {
225     .code = CMD_END_PASS
226   }
227 };
228
229
230 int
231 main (int argc,
232       char *argv[])
233 {
234   return TEST_ATS_run (argc,
235                        argv,
236                        test_commands,
237                        TIMEOUT);
238 }
239
240
241 /* end of file test_ats_api.c */