1 /*
2 	liblinphone_tester - liblinphone test suite
3 	Copyright (C) 2013  Belledonne Communications SARL
4 
5 	This program is free software: you can redistribute it and/or modify
6 	it under the terms of the GNU General Public License as published by
7 	the Free Software Foundation, either version 2 of the License, or
8 	(at your option) any later version.
9 
10 	This program is distributed in the hope that it will be useful,
11 	but WITHOUT ANY WARRANTY; without even the implied warranty of
12 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 	GNU General Public License for more details.
14 
15 	You should have received a copy of the GNU General Public License
16 	along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 
20 #ifndef LIBLINPHONE_TESTER_H_
21 #define LIBLINPHONE_TESTER_H_
22 
23 
24 
25 #include <bctoolbox/tester.h>
26 #include "linphone/core.h"
27 #include <mediastreamer2/msutils.h>
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31 
32 
33 #ifdef _MSC_VER
34 #define popen _popen
35 #define pclose _pclose
36 #endif
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 extern test_suite_t setup_test_suite;
43 extern test_suite_t register_test_suite;
44 extern test_suite_t call_test_suite;
45 extern test_suite_t call_video_test_suite;
46 extern test_suite_t message_test_suite;
47 extern test_suite_t presence_test_suite;
48 extern test_suite_t presence_server_test_suite;
49 extern test_suite_t upnp_test_suite;
50 extern test_suite_t event_test_suite;
51 extern test_suite_t flexisip_test_suite;
52 extern test_suite_t stun_test_suite;
53 extern test_suite_t remote_provisioning_test_suite;
54 extern test_suite_t quality_reporting_test_suite;
55 extern test_suite_t log_collection_test_suite;
56 extern test_suite_t tunnel_test_suite;
57 extern test_suite_t player_test_suite;
58 extern test_suite_t dtmf_test_suite;
59 extern test_suite_t offeranswer_test_suite;
60 extern test_suite_t video_test_suite;
61 extern test_suite_t multicast_call_test_suite;
62 extern test_suite_t multi_call_test_suite;
63 extern test_suite_t proxy_config_test_suite;
64 extern test_suite_t account_creator_test_suite;
65 #ifdef VCARD_ENABLED
66 extern test_suite_t vcard_test_suite;
67 #endif
68 extern test_suite_t audio_bypass_suite;
69 #if HAVE_SIPP
70 extern test_suite_t complex_sip_call_test_suite;
71 #endif
72 extern int manager_count;
73 
74 extern int liblinphone_tester_ipv6_available(void);
75 extern int liblinphone_tester_ipv4_available(void);
76 
77 /**
78  * @brief Tells the tester whether or not to clean the accounts it has created between runs.
79  * @details Setting this to 1 will not clear the list of created accounts between successive
80  * calls to liblinphone_run_tests(). Some testing APIs call this function for *each* test,
81  * in which case we should keep the accounts that were created for further testing.
82  *
83  * You are supposed to manually call liblinphone_tester_clear_account when all the tests are
84  * finished.
85  *
86  * @param keep 1 to keep the accounts in-between runs, 0 to clear them after each run.
87  */
88 extern void liblinphone_tester_keep_accounts( int keep );
89 
90 /**
91  * @brief Tells the test whether to not remove recorded audio/video files after the tests.
92  * @details By default recorded files are erased after the test, unless the test is failed.
93 **/
94 void liblinphone_tester_keep_recorded_files(int keep);
95 
96 /**
97  * @brief Disable the automatic object leak detection. This is useful because the object leak detector prevents valgrind from seeing the leaks.
98  * @details By default object leak detector is enabled.
99 **/
100 void liblinphone_tester_disable_leak_detector(int disabled);
101 
102 /**
103  * @brief Clears the created accounts during the testing session.
104  */
105 extern void liblinphone_tester_clear_accounts(void);
106 
107 
108 extern const char* test_domain;
109 extern const char* auth_domain;
110 extern const char* test_username;
111 extern const char* test_password;
112 extern const char* test_route;
113 extern const char* userhostsfile;
114 extern bool_t liblinphone_tester_tls_support_disabled;
115 extern const MSAudioDiffParams audio_cmp_params;
116 extern const char *liblinphone_tester_mire_id;
117 extern bool_t liblinphonetester_ipv6;
118 extern bool_t liblinphonetester_show_account_manager_logs;
119 
120 typedef struct _stats {
121 	int number_of_LinphoneRegistrationNone;
122 	int number_of_LinphoneRegistrationProgress ;
123 	int number_of_LinphoneRegistrationOk ;
124 	int number_of_LinphoneRegistrationCleared ;
125 	int number_of_LinphoneRegistrationFailed ;
126 	int number_of_auth_info_requested ;
127 
128 
129 	int number_of_LinphoneCallIncomingReceived;
130 	int number_of_LinphoneCallOutgoingInit;
131 	int number_of_LinphoneCallOutgoingProgress;
132 	int number_of_LinphoneCallOutgoingRinging;
133 	int number_of_LinphoneCallOutgoingEarlyMedia;
134 	int number_of_LinphoneCallConnected;
135 	int number_of_LinphoneCallStreamsRunning;
136 	int number_of_LinphoneCallPausing;
137 	int number_of_LinphoneCallPaused;
138 	int number_of_LinphoneCallResuming;
139 	int number_of_LinphoneCallRefered;
140 	int number_of_LinphoneCallError;
141 	int number_of_LinphoneCallEnd;
142 	int number_of_LinphoneCallPausedByRemote;
143 	int number_of_LinphoneCallUpdatedByRemote;
144 	int number_of_LinphoneCallIncomingEarlyMedia;
145 	int number_of_LinphoneCallUpdating;
146 	int number_of_LinphoneCallReleased;
147 	int number_of_LinphoneCallEarlyUpdatedByRemote;
148 	int number_of_LinphoneCallEarlyUpdating;
149 
150 	int number_of_LinphoneTransferCallOutgoingInit;
151 	int number_of_LinphoneTransferCallOutgoingProgress;
152 	int number_of_LinphoneTransferCallOutgoingRinging;
153 	int number_of_LinphoneTransferCallOutgoingEarlyMedia;
154 	int number_of_LinphoneTransferCallConnected;
155 	int number_of_LinphoneTransferCallStreamsRunning;
156 	int number_of_LinphoneTransferCallError;
157 
158 	int number_of_LinphoneMessageReceived;
159 	int number_of_LinphoneMessageReceivedWithFile;
160 	int number_of_LinphoneMessageReceivedLegacy;
161 	int number_of_LinphoneMessageExtBodyReceived;
162 	int number_of_LinphoneMessageInProgress;
163 	int number_of_LinphoneMessageDelivered;
164 	int number_of_LinphoneMessageNotDelivered;
165 	int number_of_LinphoneMessageFileTransferDone;
166 	int number_of_LinphoneMessageDeliveredToUser;
167 	int number_of_LinphoneMessageDisplayed;
168 	int number_of_LinphoneIsComposingActiveReceived;
169 	int number_of_LinphoneIsComposingIdleReceived;
170 	int progress_of_LinphoneFileTransfer;
171 
172 	int number_of_IframeDecoded;
173 
174 	int number_of_NewSubscriptionRequest;
175 	int number_of_NotifyReceived;
176 	int number_of_NotifyPresenceReceived;
177 	int number_of_NotifyPresenceReceivedForUriOrTel;
178 	int number_of_LinphonePresenceActivityOffline;
179 	int number_of_LinphonePresenceActivityOnline;
180 	int number_of_LinphonePresenceActivityAppointment;
181 	int number_of_LinphonePresenceActivityAway;
182 	int number_of_LinphonePresenceActivityBreakfast;
183 	int number_of_LinphonePresenceActivityBusy;
184 	int number_of_LinphonePresenceActivityDinner;
185 	int number_of_LinphonePresenceActivityHoliday;
186 	int number_of_LinphonePresenceActivityInTransit;
187 	int number_of_LinphonePresenceActivityLookingForWork;
188 	int number_of_LinphonePresenceActivityLunch;
189 	int number_of_LinphonePresenceActivityMeal;
190 	int number_of_LinphonePresenceActivityMeeting;
191 	int number_of_LinphonePresenceActivityOnThePhone;
192 	int number_of_LinphonePresenceActivityOther;
193 	int number_of_LinphonePresenceActivityPerformance;
194 	int number_of_LinphonePresenceActivityPermanentAbsence;
195 	int number_of_LinphonePresenceActivityPlaying;
196 	int number_of_LinphonePresenceActivityPresentation;
197 	int number_of_LinphonePresenceActivityShopping;
198 	int number_of_LinphonePresenceActivitySleeping;
199 	int number_of_LinphonePresenceActivitySpectator;
200 	int number_of_LinphonePresenceActivitySteering;
201 	int number_of_LinphonePresenceActivityTravel;
202 	int number_of_LinphonePresenceActivityTV;
203 	int number_of_LinphonePresenceActivityUnknown;
204 	int number_of_LinphonePresenceActivityVacation;
205 	int number_of_LinphonePresenceActivityWorking;
206 	int number_of_LinphonePresenceActivityWorship;
207 	const LinphonePresenceModel *last_received_presence;
208 
209 	int number_of_LinphonePresenceBasicStatusOpen;
210 	int number_of_LinphonePresenceBasicStatusClosed;
211 
212 	int number_of_inforeceived;
213 	LinphoneInfoMessage* last_received_info_message;
214 
215 	int number_of_LinphoneSubscriptionIncomingReceived;
216 	int number_of_LinphoneSubscriptionOutgoingProgress;
217 	int number_of_LinphoneSubscriptionPending;
218 	int number_of_LinphoneSubscriptionActive;
219 	int number_of_LinphoneSubscriptionTerminated;
220 	int number_of_LinphoneSubscriptionError;
221 	int number_of_LinphoneSubscriptionExpiring;
222 
223 	int number_of_LinphonePublishProgress;
224 	int number_of_LinphonePublishOk;
225 	int number_of_LinphonePublishExpiring;
226 	int number_of_LinphonePublishError;
227 	int number_of_LinphonePublishCleared;
228 
229 	int number_of_LinphoneConfiguringSkipped;
230 	int number_of_LinphoneConfiguringFailed;
231 	int number_of_LinphoneConfiguringSuccessful;
232 
233 	int number_of_LinphoneCallEncryptedOn;
234 	int number_of_LinphoneCallEncryptedOff;
235 	int number_of_NetworkReachableTrue;
236 	int number_of_NetworkReachableFalse;
237 	int number_of_player_eof;
238 	LinphoneChatMessage* last_received_chat_message;
239 
240 	char * dtmf_list_received;
241 	int dtmf_count;
242 
243 	int number_of_LinphoneCallStatsUpdated;
244 	int number_of_rtcp_sent;
245 	int number_of_rtcp_received; /*total number of rtcp packet received */
246 	int number_of_rtcp_received_via_mux;/*number of rtcp packet received in rtcp-mux mode*/
247 
248 	int number_of_video_windows_created;
249 
250 	int number_of_LinphoneFileTransferDownloadSuccessful;
251 	int number_of_LinphoneCoreLogCollectionUploadStateDelivered;
252 	int number_of_LinphoneCoreLogCollectionUploadStateNotDelivered;
253 	int number_of_LinphoneCoreLogCollectionUploadStateInProgress;
254 	int audio_download_bandwidth[3];
255 	int audio_upload_bandwidth[3];
256 
257 	int video_download_bandwidth[3];
258 	int video_upload_bandwidth[3];
259 	int current_bandwidth_index[2] /*audio and video only*/;
260 
261 	int number_of_rtcp_generic_nack;
262 	int number_of_tmmbr_received;
263 	int last_tmmbr_value_received;
264 }stats;
265 
266 
267 typedef struct _LinphoneCoreManager {
268 	LinphoneCoreVTable v_table;
269 	LinphoneCore* lc;
270 	stats stat;
271 	LinphoneAddress* identity;
272 	LinphoneEvent *lev;
273 	bool_t decline_subscribe;
274 	int number_of_bcunit_error_at_creation;
275 	char* phone_alias;
276 } LinphoneCoreManager;
277 
278 typedef struct _LinphoneConferenceServer {
279 	LinphoneCoreManager base;
280 	LinphoneCall *first_call;
281 	LinphoneCoreCbs *cbs;
282 	LinphoneRegistrationState reg_state;
283 } LinphoneConferenceServer;
284 
285 typedef struct _LinphoneCallTestParams {
286 	LinphoneCallParams *base;
287 	bool_t sdp_removal;
288 	bool_t sdp_simulate_error;
289 } LinphoneCallTestParams;
290 
291 
292 void liblinphone_tester_add_suites(void);
293 
294 void linphone_core_manager_init(LinphoneCoreManager *mgr, const char* rc_file, const char* phone_alias);
295 void linphone_core_manager_start(LinphoneCoreManager *mgr, int check_for_proxies);
296 LinphoneCoreManager* linphone_core_manager_new3(const char* rc_file, int check_for_proxies, const char* phone_alias);
297 LinphoneCoreManager* linphone_core_manager_new2(const char* rc_file, int check_for_proxies);
298 LinphoneCoreManager* linphone_core_manager_new(const char* rc_file);
299 void linphone_core_manager_stop(LinphoneCoreManager *mgr);
300 void linphone_core_manager_uninit(LinphoneCoreManager *mgr);
301 void linphone_core_manager_wait_for_stun_resolution(LinphoneCoreManager *mgr);
302 void linphone_core_manager_destroy(LinphoneCoreManager* mgr);
303 
304 void reset_counters( stats* counters);
305 
306 void registration_state_changed(struct _LinphoneCore *lc, LinphoneProxyConfig *cfg, LinphoneRegistrationState cstate, const char *message);
307 void call_state_changed(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState cstate, const char *msg);
308 void linphone_transfer_state_changed(LinphoneCore *lc, LinphoneCall *transfered, LinphoneCallState new_call_state);
309 void notify_presence_received(LinphoneCore *lc, LinphoneFriend * lf);
310 void notify_presence_received_for_uri_or_tel(LinphoneCore *lc, LinphoneFriend *lf, const char *uri_or_tel, const LinphonePresenceModel *presence);
311 void text_message_received(LinphoneCore *lc, LinphoneChatRoom *room, const LinphoneAddress *from_address, const char *message);
312 void message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMessage* message);
313 void file_transfer_received(LinphoneChatMessage *message, const LinphoneContent* content, const LinphoneBuffer *buffer);
314 LinphoneBuffer * tester_file_transfer_send(LinphoneChatMessage *message, const LinphoneContent* content, size_t offset, size_t size);
315 LinphoneBuffer * tester_memory_file_transfer_send(LinphoneChatMessage *message, const LinphoneContent* content, size_t offset, size_t size);
316 void file_transfer_progress_indication(LinphoneChatMessage *message, const LinphoneContent* content, size_t offset, size_t total);
317 void is_composing_received(LinphoneCore *lc, LinphoneChatRoom *room);
318 void info_message_received(LinphoneCore *lc, LinphoneCall *call, const LinphoneInfoMessage *msg);
319 void new_subscription_requested(LinphoneCore *lc, LinphoneFriend *lf, const char *url);
320 void linphone_subscription_state_change(LinphoneCore *lc, LinphoneEvent *ev, LinphoneSubscriptionState state);
321 void linphone_publish_state_changed(LinphoneCore *lc, LinphoneEvent *ev, LinphonePublishState state);
322 void linphone_notify_received(LinphoneCore *lc, LinphoneEvent *lev, const char *eventname, const LinphoneContent *content);
323 void linphone_configuration_status(LinphoneCore *lc, LinphoneConfiguringState status, const char *message);
324 void linphone_call_encryption_changed(LinphoneCore *lc, LinphoneCall *call, bool_t on, const char *authentication_token);
325 void dtmf_received(LinphoneCore *lc, LinphoneCall *call, int dtmf);
326 void call_stats_updated(LinphoneCore *lc, LinphoneCall *call, const LinphoneCallStats *stats);
327 
328 LinphoneAddress * create_linphone_address(const char * domain);
329 bool_t wait_for(LinphoneCore* lc_1, LinphoneCore* lc_2,int* counter,int value);
330 bool_t wait_for_list(MSList* lcs,int* counter,int value,int timeout_ms);
331 bool_t wait_for_until(LinphoneCore* lc_1, LinphoneCore* lc_2,int* counter,int value,int timout_ms);
332 
333 bool_t call_with_params(LinphoneCoreManager* caller_mgr
334 						,LinphoneCoreManager* callee_mgr
335 						, const LinphoneCallParams *caller_params
336 						, const LinphoneCallParams *callee_params);
337 bool_t call_with_test_params(LinphoneCoreManager* caller_mgr
338 				,LinphoneCoreManager* callee_mgr
339 				,const LinphoneCallTestParams *caller_test_params
340 				,const LinphoneCallTestParams *callee_test_params);
341 bool_t call_with_params2(LinphoneCoreManager* caller_mgr
342 						,LinphoneCoreManager* callee_mgr
343 						, const LinphoneCallTestParams *caller_test_params
344 						, const LinphoneCallTestParams *callee_test_params
345 						, bool_t build_callee_params);
346 
347 bool_t call(LinphoneCoreManager* caller_mgr,LinphoneCoreManager* callee_mgr);
348 bool_t request_video(LinphoneCoreManager* caller,LinphoneCoreManager* callee, bool_t use_accept_call_update);
349 void end_call(LinphoneCoreManager *m1, LinphoneCoreManager *m2);
350 void disable_all_audio_codecs_except_one(LinphoneCore *lc, const char *mime, int rate);
351 void disable_all_video_codecs_except_one(LinphoneCore *lc, const char *mime);
352 void disable_all_codecs(const MSList* elem, LinphoneCoreManager* call);
353 stats * get_stats(LinphoneCore *lc);
354 bool_t transport_supported(LinphoneTransportType transport);
355 LinphoneCoreManager *get_manager(LinphoneCore *lc);
356 const char *liblinphone_tester_get_subscribe_content(void);
357 const char *liblinphone_tester_get_notify_content(void);
358 void liblinphone_tester_chat_message_state_change(LinphoneChatMessage* msg,LinphoneChatMessageState state,void* ud);
359 void liblinphone_tester_chat_message_msg_state_changed(LinphoneChatMessage *msg, LinphoneChatMessageState state);
360 void liblinphone_tester_check_rtcp(LinphoneCoreManager* caller, LinphoneCoreManager* callee);
361 void liblinphone_tester_clock_start(MSTimeSpec *start);
362 bool_t liblinphone_tester_clock_elapsed(const MSTimeSpec *start, int value_ms);
363 void linphone_core_manager_check_accounts(LinphoneCoreManager *m);
364 void account_manager_destroy(void);
365 LinphoneCore* configure_lc_from(LinphoneCoreVTable* v_table, const char* path, const char* file, void* user_data);
366 
367 void linphone_call_iframe_decoded_cb(LinphoneCall *call,void * user_data);
368 void call_paused_resumed_base(bool_t multicast,bool_t with_losses);
369 void simple_call_base(bool_t enable_multicast_recv_side);
370 void call_base_with_configfile(LinphoneMediaEncryption mode, bool_t enable_video,bool_t enable_relay,LinphoneFirewallPolicy policy,bool_t enable_tunnel, const char *marie_rc, const char *pauline_rc);
371 void call_base(LinphoneMediaEncryption mode, bool_t enable_video,bool_t enable_relay,LinphoneFirewallPolicy policy,bool_t enable_tunnel);
372 bool_t call_with_caller_params(LinphoneCoreManager* caller_mgr,LinphoneCoreManager* callee_mgr, const LinphoneCallParams *params);
373 bool_t pause_call_1(LinphoneCoreManager* mgr_1,LinphoneCall* call_1,LinphoneCoreManager* mgr_2,LinphoneCall* call_2);
374 void compare_files(const char *path1, const char *path2);
375 void check_media_direction(LinphoneCoreManager* mgr, LinphoneCall *call, MSList* lcs,LinphoneMediaDirection audio_dir, LinphoneMediaDirection video_dir);
376 void _call_with_ice_base(LinphoneCoreManager* pauline,LinphoneCoreManager* marie, bool_t caller_with_ice, bool_t callee_with_ice, bool_t random_ports, bool_t forced_relay);
377 int check_nb_media_starts(LinphoneCoreManager *caller, LinphoneCoreManager *callee, unsigned int caller_nb_media_starts, unsigned int callee_nb_media_starts);
378 void record_call(const char *filename, bool_t enableVideo, const char *video_codec);
379 
380 /*
381  * this function return max value in the last 3 seconds*/
382 int linphone_core_manager_get_max_audio_down_bw(const LinphoneCoreManager *mgr);
383 int linphone_core_manager_get_max_audio_up_bw(const LinphoneCoreManager *mgr);
384 int linphone_core_manager_get_mean_audio_down_bw(const LinphoneCoreManager *mgr);
385 int linphone_core_manager_get_mean_audio_up_bw(const LinphoneCoreManager *mgr);
386 
387 void video_call_base_2(LinphoneCoreManager* pauline,LinphoneCoreManager* marie, bool_t using_policy,LinphoneMediaEncryption mode, bool_t callee_video_enabled, bool_t caller_video_enabled);
388 
389 void liblinphone_tester_before_each(void);
390 void liblinphone_tester_after_each(void);
391 void liblinphone_tester_init(void(*ftester_printf)(int level, const char *fmt, va_list args));
392 void liblinphone_tester_uninit(void);
393 int liblinphone_tester_set_log_file(const char *filename);
394 bool_t check_ice(LinphoneCoreManager* caller, LinphoneCoreManager* callee, LinphoneIceState state);
395 
396 
397 LinphoneConferenceServer* linphone_conference_server_new(const char *rc_file, bool_t do_registration);
398 void linphone_conference_server_destroy(LinphoneConferenceServer *conf_srv);
399 
400 LinphoneAddress * linphone_core_manager_resolve(LinphoneCoreManager *mgr, const LinphoneAddress *source);
401 FILE *sip_start(const char *senario, const char* dest_username, const char *passwd, LinphoneAddress* dest_addres);
402 
403 void early_media_without_sdp_in_200_base( bool_t use_video, bool_t use_ice );
404 
405 
406 #ifdef __cplusplus
407 };
408 #endif
409 
410 #endif /* LIBLINPHONE_TESTER_H_ */
411