test_nua.h 9.29 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
/*
 * This file is part of the Sofia-SIP package
 *
 * Copyright (C) 2005 Nokia Corporation.
 *
 * Contact: Pekka Pessi <pekka.pessi@nokia.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

/**@CFILE test_nua.h
 * @brief High-level tester framework for Sofia SIP User Agent Engine
 *
 * @author Pekka Pessi <Pekka.Pessi@nokia.com>
 * @author Martti Mela <Martti Mela@nokia.com>
 *
 * @date Created: Wed Aug 17 12:12:12 EEST 2005 ppessi
 */

#ifndef TEST_NUA_H
#define TEST_NUA_H

struct context;
#define NUA_MAGIC_T struct context

struct call;
#define NUA_HMAGIC_T struct call

#include "sofia-sip/nua.h"
#include "sofia-sip/sip_status.h"

#include <sofia-sip/sdp.h>
#include <sofia-sip/sip_header.h>

#include <sofia-sip/su_log.h>
#include <sofia-sip/su_tagarg.h>
#include <sofia-sip/su_tag_io.h>
52
#include <sofia-sip/nua_tag.h>
53

54 55 56 57
#if __APPLE_CC__
#include <sofia-sip/su_osx_runloop.h>
#endif

58 59
#include "test_proxy.h"
#include "test_nat.h"
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
#include <sofia-sip/auth_module.h>

#include <stddef.h>
#include <stdlib.h>
#include <string.h>

#include <assert.h>
#include <unistd.h>

extern char const name[];

extern int print_headings;
extern int tstflags;
#define TSTFLAGS tstflags

#include <sofia-sip/tstdef.h>

#define TEST_E(a, b) TEST_S(nua_event_name(a), nua_event_name(b))

#define NONE ((void*)-1)

struct endpoint;

typedef
int condition_function(nua_event_t event,
		       int status, char const *phrase,
		       nua_t *nua, struct context *ctx,
		       struct endpoint *ep,
		       nua_handle_t *nh, struct call *call,
		       sip_t const *sip,
		       tagi_t tags[]);

typedef
void printer_function(nua_event_t event,
		      char const *operation,
		      int status, char const *phrase,
		      nua_t *nua, struct context *ctx,
		      struct endpoint *ep,
		      nua_handle_t *nh, struct call *call,
		      sip_t const *sip,
		      tagi_t tags[]);

struct proxy_transaction;
struct registration_entry;

enum { event_is_extra, event_is_normal, event_is_special };

struct eventlist
{
  nua_event_t kind;
  struct event *head, **tail;
};

struct event 
{
  struct event *next, **prev;
  struct call *call;
  nua_saved_event_t saved_event[1];
  nua_event_data_t const *data;
};


struct context
{
  su_home_t home[1];
  su_root_t *root;

127
  int threading, proxy_tests, expensive, quit_on_single_failure, osx_runloop;
128
  int print_tags;
129 130

  url_t *external_proxy;
131

132 133
  int proxy_logging;

134 135 136 137
  struct endpoint {
    char name[4];
    struct context *ctx;	/* Backpointer */

138
    int logging;
139
    int print_tags;
140

141 142
    int running;

143
    struct domain *domain;
144 145 146 147 148 149
    condition_function *next_condition;
    nua_event_t next_event, last_event;
    nua_t *nua;
    sip_contact_t *contact;
    sip_from_t *to;

150 151 152 153
    sip_allow_t *allow;
    char const *appl_method;
    sip_supported_t *supported;

154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
    printer_function *printer;

    char const *instance;

    /* Per-call stuff */
    struct call {
      struct call *next;
      nua_handle_t *nh;
      char const *sdp;
      struct eventlist *events;
    } call[1], reg[1];

    int (*is_special)(nua_event_t e);

    /* Normal events are saved here */
    struct eventlist events[1];
    /* Special events are saved here */
    struct eventlist specials[1];

    /* State flags for complex scenarios */
174
    struct {
175
      unsigned n;
176 177 178
      unsigned bit0:1, bit1:1, bit2:1, bit3:1;
      unsigned bit4:1, bit5:1, bit6:1, bit7:1;
      unsigned :0;
179 180 181 182 183
    } flags;

  } a, b, c;

  struct proxy *p;
184
  sip_route_t const *lr;
185 186 187
  struct nat *nat;
};

188 189 190 191 192 193 194
#define RETURN_ON_SINGLE_FAILURE(retval)			  \
  do {								  \
    fflush(stdout);						  \
    if (retval && ctx->quit_on_single_failure) { return retval; } \
  } while(0)


195 196 197 198 199 200
int save_event_in_list(struct context *,
		       nua_event_t nevent,
		       struct endpoint *,
		       struct call *);
void free_events_in_list(struct context *,
			 struct eventlist *);
201 202 203
void free_event_in_list(struct context *ctx,
			struct eventlist *list,
			struct event *e);
204

205 206 207
struct event *event_by_type(struct event *e, nua_event_t);
size_t count_events(struct event const *e);

208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
#define CONDITION_PARAMS			\
  nua_event_t event,				\
  int status, char const *phrase,		\
  nua_t *nua, struct context *ctx,		\
  struct endpoint *ep,				\
  nua_handle_t *nh, struct call *call,		\
  sip_t const *sip,				\
  tagi_t tags[]

int save_events(CONDITION_PARAMS);
int until_final_response(CONDITION_PARAMS);
int save_until_final_response(CONDITION_PARAMS);
int save_until_received(CONDITION_PARAMS);
int save_until_special(CONDITION_PARAMS);

int until_terminated(CONDITION_PARAMS);
int until_ready(CONDITION_PARAMS);
int accept_call(CONDITION_PARAMS);
226
int cancel_when_ringing(CONDITION_PARAMS);
227

228 229
int accept_notify(CONDITION_PARAMS);

230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
void a_callback(nua_event_t event,
		int status, char const *phrase,
		nua_t *nua, struct context *ctx,
		nua_handle_t *nh, struct call *call,
		sip_t const *sip,
		tagi_t tags[]);
void b_callback(nua_event_t event,
		int status, char const *phrase,
		nua_t *nua, struct context *ctx,
		nua_handle_t *nh, struct call *call,
		sip_t const *sip,
		tagi_t tags[]);
void c_callback(nua_event_t event,
		int status, char const *phrase,
		nua_t *nua, struct context *ctx,
		nua_handle_t *nh, struct call *call,
		sip_t const *sip,
		tagi_t tags[]);

void run_abc_until(struct context *ctx,
		   nua_event_t a_event, condition_function *a_condition,
		   nua_event_t b_event, condition_function *b_condition,
		   nua_event_t c_event, condition_function *c_condition);

void run_ab_until(struct context *ctx,
		  nua_event_t a_event, condition_function *a_condition,
		  nua_event_t b_event, condition_function *b_condition);
257 258 259 260 261

void run_bc_until(struct context *ctx,
		  nua_event_t b_event, condition_function *b_condition,
		  nua_event_t c_event, condition_function *c_condition);

262 263 264 265 266 267 268 269 270
int run_a_until(struct context *, nua_event_t, condition_function *);
int run_b_until(struct context *, nua_event_t, condition_function *);
int run_c_until(struct context *, nua_event_t, condition_function *);

typedef int operation_f(struct endpoint *ep, struct call *call, 
			nua_handle_t *nh, tag_type_t tag, tag_value_t value,
			...);

operation_f INVITE, ACK, BYE, CANCEL, AUTHENTICATE, UPDATE, INFO, PRACK,
271
  REFER, MESSAGE, METHOD, OPTIONS, PUBLISH, UNPUBLISH, REGISTER, UNREGISTER,
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
  SUBSCRIBE, UNSUBSCRIBE, NOTIFY, NOTIFIER, TERMINATE, AUTHORIZE;

int RESPOND(struct endpoint *ep,
	    struct call *call,
	    nua_handle_t *nh,
	    int status, char const *phrase,
	    tag_type_t tag, tag_value_t value,
	    ...);

int DESTROY(struct endpoint *ep,
	    struct call *call,
	    nua_handle_t *nh);

struct call *check_handle(struct endpoint *ep,
			  struct call *call,
			  nua_handle_t *nh,
			  int status, char const *phrase);

int is_special(nua_event_t e);
int callstate(tagi_t const *tags);
int is_offer_sent(tagi_t const *tags);
int is_answer_sent(tagi_t const *tags);
int is_offer_recv(tagi_t const *tags);
int is_answer_recv(tagi_t const *tags);
int is_offer_answer_done(tagi_t const *tags);
int audio_activity(tagi_t const *tags);
int video_activity(tagi_t const *tags);

300 301 302 303 304 305 306 307 308
void print_event(nua_event_t event,
		 char const *operation,
		 int status, char const *phrase,
		 nua_t *nua, struct context *ctx,
		 struct endpoint *ep,
		 nua_handle_t *nh, struct call *call,
		 sip_t const *sip,
		 tagi_t tags[]);

309
su_inline
310 311 312 313 314
void eventlist_init(struct eventlist *list)
{
  list->tail = &list->head;
}

315
su_inline
316 317 318 319 320 321
void call_init(struct call *call)
{
}

void endpoint_init(struct context *ctx, struct endpoint *e, char id);

322 323 324 325 326 327 328 329
int test_nua_init(struct context *ctx,
		  int start_proxy,
		  url_t const *o_proxy,
		  int start_nat,
		  tag_type_t tag, tag_value_t value, ...);

int test_deinit(struct context *ctx);

330
int test_nua_api_errors(struct context *ctx);
331
int test_nua_destroy(struct context *ctx);
332 333 334 335 336 337 338 339 340 341
int test_stack_errors(struct context *ctx);
int test_tag_filter(void);
int test_nua_params(struct context *ctx);

int test_register(struct context *ctx);
int test_connectivity(struct context *ctx);
int test_nat_timeout(struct context *ctx);
int test_unregister(struct context *ctx);

int test_basic_call(struct context *ctx);
342
int test_offer_answer(struct context *ctx);
343
int test_rejects(struct context *ctx);
344
int test_mime_negotiation(struct context *ctx);
345
int test_call_timeouts(struct context *ctx);
346 347 348 349 350
int test_reject_401_aka(struct context *ctx);
int test_call_cancel(struct context *ctx);
int test_call_destroy(struct context *ctx);
int test_early_bye(struct context *ctx);
int test_call_hold(struct context *ctx);
351
int test_reinvites(struct context *ctx);
352 353 354 355 356 357
int test_session_timer(struct context *ctx);
int test_refer(struct context *ctx);
int test_100rel(struct context *ctx);
int test_simple(struct context *ctx);
int test_events(struct context *ctx);

358 359
int test_extension(struct context *ctx);

360
#endif