test_nua.c 19.2 KB
Newer Older
Pekka Pessi's avatar
Pekka Pessi committed
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 52 53 54 55
/*
 * 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.c
 * @brief High-level tester for Sofia SIP User Agent Engine
 *
 * @author Pekka Pessi <Pekka.Pessi@nokia.com>
 *
 * @date Created: Wed Aug 17 12:12:12 EEST 2005 ppessi
 * $Date: 2005/09/29 18:35:22 $
 */

#include "config.h"

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

#include <assert.h>

#if HAVE_ALARM
#include <unistd.h>
#include <signal.h>
#endif

struct context;
#define NUA_MAGIC_T struct context
struct call;
#define NUA_HMAGIC_T struct call

#include "nua.h"
#include "nua_tag.h"

#include <sdp.h>
56
#include <sip_header.h>
Pekka Pessi's avatar
Pekka Pessi committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77

#include <su_log.h>

extern su_log_t nua_log[];
extern su_log_t su_log_default[];

char const name[] = "test_nua";
int tstflags = 0;
#define TSTFLAGS tstflags

#include <tstdef.h>

#if HAVE_FUNC
#elif HAVE_FUNCTION
#define __func__ __FUNCTION__
#else
#define __func__ name
#endif

#define NONE ((void*)-1)

78 79 80
struct endpoint;

typedef
Pekka Pessi's avatar
Pekka Pessi committed
81 82 83
int condition_function(nua_event_t event,
		       int status, char const *phrase,
		       nua_t *nua, struct context *ctx,
84
		       struct endpoint *ep,
Pekka Pessi's avatar
Pekka Pessi committed
85 86 87 88
		       nua_handle_t *nh, struct call *call,
		       sip_t const *sip,
		       tagi_t tags[]);

89
struct context
Pekka Pessi's avatar
Pekka Pessi committed
90 91 92 93 94 95 96 97
{
  su_home_t home[1];
  su_root_t *root;

  int running;

  nua_t *next_stack, *last_stack;

98 99 100
  struct endpoint {
    condition_function *next_condition;
    nua_event_t next_event, last_event;
Pekka Pessi's avatar
Pekka Pessi committed
101
    nua_t *nua;
102 103
    nua_handle_t *nh;
    nua_saved_event_t saved_event[1];
Pekka Pessi's avatar
Pekka Pessi committed
104 105 106
  } a, b;
};

107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
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[])
{
  fprintf(stderr, "a.nua(%p): event %s status %u %s\n",
	  nh, nua_event_name(event), status, phrase);

  if ((ctx->a.next_event == -1 || ctx->a.next_event == event) &&
      (ctx->a.next_condition == NULL ||
       ctx->a.next_condition(event, status, phrase,
			     nua, ctx, &ctx->a, nh, call, sip, tags)))
    ctx->running = 0;

  ctx->a.last_event = event;
  ctx->b.last_event = -1;
}

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[])
Pekka Pessi's avatar
Pekka Pessi committed
133
{
134 135 136 137 138 139 140
  fprintf(stderr, "a.nua(%p): event %s status %u %s\n",
	  nh, nua_event_name(event), status, phrase);

  if ((ctx->b.next_event == -1 || ctx->b.next_event == event) &&
      (ctx->b.next_condition == NULL ||
       ctx->b.next_condition(event, status, phrase,
			     nua, ctx, &ctx->a, nh, call, sip, tags)))
Pekka Pessi's avatar
Pekka Pessi committed
141 142
    ctx->running = 0;

143 144 145

  ctx->a.last_event = -1;
  ctx->b.last_event = event;
Pekka Pessi's avatar
Pekka Pessi committed
146 147
}

148 149 150
void run_until(struct context *ctx,
	       nua_event_t a_event, condition_function *a_condition,
	       nua_event_t b_event, condition_function *b_condition)
Pekka Pessi's avatar
Pekka Pessi committed
151
{
152 153 154 155 156 157
  ctx->a.next_event = a_event;
  ctx->a.next_condition = a_condition;
  ctx->a.last_event = -1;
  ctx->b.next_event = b_event;
  ctx->b.next_condition = b_condition;
  ctx->b.last_event = -1;
Pekka Pessi's avatar
Pekka Pessi committed
158 159 160 161

  for (ctx->running = 1; ctx->running;) {
    su_root_step(ctx->root, 1000);
  }
162
}
Pekka Pessi's avatar
Pekka Pessi committed
163

164 165 166 167 168 169 170 171 172 173 174 175 176 177
int run_a_until(struct context *ctx,
		nua_event_t a_event,
		condition_function *a_condition)
{
  run_until(ctx, a_event, a_condition, -1, NULL);
  return ctx->a.last_event;
}

int run_b_until(struct context *ctx,
		nua_event_t b_event,
		condition_function *b_condition)
{
  run_until(ctx, -1, NULL, b_event, b_condition);
  return ctx->b.last_event;
Pekka Pessi's avatar
Pekka Pessi committed
178 179
}

180 181 182 183 184 185 186 187
#define CONDITION_FUNCTION(name)		\
  int name(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[])
Pekka Pessi's avatar
Pekka Pessi committed
188 189

CONDITION_FUNCTION(condition_final_response){ return status >= 200; }
190 191 192 193 194 195 196
CONDITION_FUNCTION(save_final_response)
{
  if (status < 200)
    return 0;
  nua_save_event(ep->nua, ep->saved_event);
  return 1;
}
Pekka Pessi's avatar
Pekka Pessi committed
197 198 199 200 201 202 203

void nolog(void *stream, char const *fmt, va_list ap) {}

int test_api_errors(struct context *ctx)
{
  BEGIN();

Pekka Pessi's avatar
Pekka Pessi committed
204
  /* Invoke every API function with invalid arguments */
Pekka Pessi's avatar
Pekka Pessi committed
205

Pekka Pessi's avatar
Pekka Pessi committed
206 207 208 209 210 211 212
  int level;

  su_log_init(nua_log);

  level = nua_log->log_level;
  if (!(tstflags & tst_verbatim))
    su_log_set_level(nua_log, 0);
Pekka Pessi's avatar
Pekka Pessi committed
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253

  TEST_1(!nua_create(NULL, NULL, NULL, TAG_END()));
  TEST_VOID(nua_shutdown(NULL));
  TEST_VOID(nua_destroy(NULL));
  TEST_VOID(nua_set_params(NULL, TAG_END()));
  TEST_VOID(nua_get_params(NULL, TAG_END()));
  TEST_1(!nua_default(NULL));
  TEST_1(!nua_handle(NULL, NULL, TAG_END()));
  TEST_VOID(nua_handle_destroy(NULL));
  TEST_VOID(nua_handle_bind(NULL, NULL));
  TEST_1(!nua_handle_has_invite(NULL));
  TEST_1(!nua_handle_has_subscribe(NULL));
  TEST_1(!nua_handle_has_register(NULL));
  TEST_1(!nua_handle_has_active_call(NULL));
  TEST_1(!nua_handle_has_call_on_hold(NULL));
  TEST_1(!nua_handle_has_events(NULL));
  TEST_1(!nua_handle_has_registrations(NULL));
  TEST_1(!nua_handle_remote(NULL));
  TEST_1(!nua_handle_local(NULL));
  TEST_S(nua_event_name(-1), "NUA_UNKNOWN");
  TEST_VOID(nua_register(NULL, TAG_END()));
  TEST_VOID(nua_unregister(NULL, TAG_END()));
  TEST_VOID(nua_invite(NULL, TAG_END()));
  TEST_VOID(nua_ack(NULL, TAG_END()));
  TEST_VOID(nua_options(NULL, TAG_END()));
  TEST_VOID(nua_publish(NULL, TAG_END()));
  TEST_VOID(nua_message(NULL, TAG_END()));
  TEST_VOID(nua_chat(NULL, TAG_END()));
  TEST_VOID(nua_info(NULL, TAG_END()));
  TEST_VOID(nua_subscribe(NULL, TAG_END()));
  TEST_VOID(nua_unsubscribe(NULL, TAG_END()));
  TEST_VOID(nua_notify(NULL, TAG_END()));
  TEST_VOID(nua_notifier(NULL, TAG_END()));
  TEST_VOID(nua_terminate(NULL, TAG_END()));
  TEST_VOID(nua_refer(NULL, TAG_END()));
  TEST_VOID(nua_update(NULL, TAG_END()));
  TEST_VOID(nua_bye(NULL, TAG_END()));
  TEST_VOID(nua_cancel(NULL, TAG_END()));
  TEST_VOID(nua_authenticate(NULL, TAG_END()));
  TEST_VOID(nua_redirect(NULL, TAG_END()));
  TEST_VOID(nua_respond(NULL, 0, "", TAG_END()));
Pekka Pessi's avatar
Pekka Pessi committed
254

Pekka Pessi's avatar
Pekka Pessi committed
255 256
  TEST_1(!nua_handle_home(NULL));
  TEST_1(!nua_save_event(NULL, NULL));
257
  TEST_1(!nua_info_event(NULL, NULL, NULL, NULL, NULL,
Pekka Pessi's avatar
Pekka Pessi committed
258 259
			 NULL, NULL, NULL, NULL));
  TEST_VOID(nua_destroy_event(NULL));
260

Pekka Pessi's avatar
Pekka Pessi committed
261 262 263 264
  {
    nua_saved_event_t event[1];

    memset(event, 0, sizeof event);
265

Pekka Pessi's avatar
Pekka Pessi committed
266
    TEST_1(!nua_save_event(NULL, event));
267
    TEST_1(!nua_info_event(event, NULL, NULL, NULL, NULL,
Pekka Pessi's avatar
Pekka Pessi committed
268 269 270 271
			   NULL, NULL, NULL, NULL));
    TEST_VOID(nua_destroy_event(event));
  }

Pekka Pessi's avatar
Pekka Pessi committed
272
  su_log_set_level(nua_log, level);
Pekka Pessi's avatar
Pekka Pessi committed
273 274 275 276 277 278 279 280 281 282 283

  END();
}

int test_init(struct context *ctx, char *argv[])
{
  BEGIN();

  ctx->root = su_root_create(ctx); TEST_1(ctx->root);

  /* Disable threading by command line switch? */
284
  su_root_threading(ctx->root, 0);
Pekka Pessi's avatar
Pekka Pessi committed
285

286
  ctx->a.nua = nua_create(ctx->root, a_callback, ctx,
Pekka Pessi's avatar
Pekka Pessi committed
287 288 289 290
			  NUTAG_URL("sip:*:*"),
			  TAG_END());
  TEST_1(ctx->a.nua);

291
  ctx->b.nua = nua_create(ctx->root, b_callback, ctx,
Pekka Pessi's avatar
Pekka Pessi committed
292 293 294 295 296 297 298 299 300 301
			  NUTAG_URL("sip:*:*"),
			  TAG_END());
  TEST_1(ctx->b.nua);

  END();
}

int test_params(struct context *ctx)
{
  BEGIN();
302 303 304 305 306 307 308 309 310 311 312 313

  char const Alice[] = "Alice <sip:a@wonderland.org>";
  sip_from_t const *from;
  su_home_t tmphome[SU_HOME_AUTO_SIZE(16384)];
  nua_handle_t *nh;

  su_home_auto(tmphome, sizeof(tmphome));

  from = sip_from_make(tmphome, Alice);

  nh = nua_handle(ctx->a.nua, NULL, TAG_END());

314
  nua_set_hparams(nh, NUTAG_INVITE_TIMER(90), TAG_END());
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532

  /* Modify everything from their default value */
  nua_set_params(ctx->a.nua,
		 SIPTAG_FROM(from),
		 NUTAG_RETRY_COUNT(5),
		 NUTAG_MAX_SUBSCRIPTIONS(6),

		 NUTAG_ENABLEINVITE(0),
		 NUTAG_AUTOALERT(1),
		 NUTAG_EARLY_MEDIA(1),
		 NUTAG_AUTOANSWER(1),
		 NUTAG_AUTOACK(0),
		 NUTAG_INVITE_TIMER(60),

		 NUTAG_SESSION_TIMER(600),
		 NUTAG_MIN_SE(35),
		 NUTAG_SESSION_REFRESHER(nua_remote_refresher),
		 NUTAG_UPDATE_REFRESH(1),

		 NUTAG_ENABLEMESSAGE(0),
		 NUTAG_ENABLEMESSENGER(1),
		 /* NUTAG_MESSAGE_AUTOANSWER(0), */

		 NUTAG_CALLEE_CAPS(1),
		 NUTAG_MEDIA_FEATURES(1),
		 NUTAG_SERVICE_ROUTE_ENABLE(0),
		 NUTAG_PATH_ENABLE(0),

		 SIPTAG_SUPPORTED_STR("humppaa,kuole"),
		 SIPTAG_ALLOW_STR("OPTIONS, INFO"),
		 SIPTAG_USER_AGENT_STR("test_nua"),

		 SIPTAG_ORGANIZATION_STR("Pussy Galore's Flying Circus"),

		 NUTAG_MEDIA_ENABLE(0),
		 NUTAG_REGISTRAR("sip:sip.wonderland.org"),
		
		 TAG_END());

  nua_get_params(ctx->a.nua, TAG_ANY(), TAG_END());

  run_a_until(ctx, nua_r_get_params, save_final_response);

  {
    sip_from_t const *from = NONE;
    char const *from_str = "NONE";

    int retry_count = -1;
    int max_subscriptions = -1;
    
    int invite_enable = -1;
    int auto_alert = -1;
    int early_media = -1;
    int auto_answer = -1;
    int auto_ack = -1;
    int invite_timeout = -1;
    
    int session_timer = -1;
    int min_se = -1;
    int refresher = -1;
    int update_refresh = -1;
    
    int message_enable = -1;
    int win_messenger_enable = -1;
    int message_auto_respond = -1;
    
    int callee_caps = -1;
    int media_features = -1;
    int service_route_enable = -1;
    int path_enable = -1;

    sip_allow_t const *allow = NONE;
    char const   *allow_str = "NONE";
    sip_supported_t const *supported = NONE;
    char const *supported_str = "NONE";
    sip_user_agent_t const *user_agent = NONE;
    char const *user_agent_str = "NONE";
    sip_organization_t const *organization = NONE;
    char const *organization_str = "NONE";

    url_string_t const *registrar = NONE;

    int n;
    nua_event_t event = nua_i_error;
    tagi_t const *tags = NULL;

    TEST(nua_info_event(ctx->a.saved_event, 
			&event, NULL, NULL, NULL, NULL, NULL, NULL, &tags), 1);
    TEST(event, nua_r_get_params);

    n = tl_gets(tags,
	       	SIPTAG_FROM_REF(from),
	       	SIPTAG_FROM_STR_REF(from_str),

	       	NUTAG_RETRY_COUNT_REF(retry_count),
	       	NUTAG_MAX_SUBSCRIPTIONS_REF(max_subscriptions),

	       	NUTAG_ENABLEINVITE_REF(invite_enable),
	       	NUTAG_AUTOALERT_REF(auto_alert),
	       	NUTAG_EARLY_MEDIA_REF(early_media),
	       	NUTAG_AUTOANSWER_REF(auto_answer),
	       	NUTAG_AUTOACK_REF(auto_ack),
	       	NUTAG_INVITE_TIMER_REF(invite_timeout),

	       	NUTAG_SESSION_TIMER_REF(session_timer),
	       	NUTAG_MIN_SE_REF(min_se),
	       	NUTAG_SESSION_REFRESHER_REF(refresher),
	       	NUTAG_UPDATE_REFRESH_REF(update_refresh),

	       	NUTAG_ENABLEMESSAGE_REF(message_enable),
	       	NUTAG_ENABLEMESSENGER_REF(win_messenger_enable),
	       	/* NUTAG_MESSAGE_AUTOANSWER(message_auto_respond), */

	       	NUTAG_CALLEE_CAPS_REF(callee_caps),
	       	NUTAG_MEDIA_FEATURES_REF(media_features),
	       	NUTAG_SERVICE_ROUTE_ENABLE_REF(service_route_enable),
	       	NUTAG_PATH_ENABLE_REF(path_enable),

	       	SIPTAG_SUPPORTED_REF(supported),
	       	SIPTAG_SUPPORTED_STR_REF(supported_str),
	       	SIPTAG_ALLOW_REF(allow),
	       	SIPTAG_ALLOW_STR_REF(allow_str),
	       	SIPTAG_USER_AGENT_REF(user_agent),
	       	SIPTAG_USER_AGENT_STR_REF(user_agent_str),

	       	SIPTAG_ORGANIZATION_REF(organization),
	       	SIPTAG_ORGANIZATION_STR_REF(organization_str),

	       	NUTAG_REGISTRAR_REF(registrar),

		TAG_END());
    TEST(n, 29);

    TEST_S(sip_header_as_string(tmphome, (void *)from), Alice);
    TEST_S(from_str, Alice);

    TEST(retry_count, 5);
    TEST(max_subscriptions, 6);

    TEST(invite_enable, 0);
    TEST(auto_alert, 1);
    TEST(early_media, 1);
    TEST(auto_answer, 1);
    TEST(auto_ack, 0);
    TEST(invite_timeout, 60);

    TEST(session_timer, 600);
    TEST(min_se, 35);
    TEST(refresher, nua_remote_refresher);
    TEST(update_refresh, 1);

    TEST(message_enable, 0);
    TEST(win_messenger_enable, 1);
    TEST(message_auto_respond, -1); /* XXX */

    TEST(callee_caps, 1);
    TEST(media_features, 1);
    TEST(service_route_enable, 0);
    TEST(path_enable, 0);

    TEST_S(sip_header_as_string(tmphome, (void *)allow), "OPTIONS, INFO");
    TEST_S(allow_str, "OPTIONS, INFO");
    TEST_S(sip_header_as_string(tmphome, (void *)supported), "humppaa, kuole");
    TEST_S(supported_str, "humppaa, kuole");
    TEST_S(sip_header_as_string(tmphome, (void *)user_agent), "test_nua");
    TEST_S(user_agent_str, "test_nua");
    TEST_S(sip_header_as_string(tmphome, (void *)organization), 
	   "Pussy Galore's Flying Circus");
    TEST_S(organization_str, "Pussy Galore's Flying Circus");

    TEST_S(url_as_string(tmphome, registrar->us_url), 
	   "sip:sip.wonderland.org");
  }
  nua_destroy_event(ctx->a.saved_event);

  {
    sip_from_t const *from = NONE;
    char const *from_str = "NONE";

    int retry_count = -1;
    int max_subscriptions = -1;
    
    int invite_enable = -1;
    int auto_alert = -1;
    int early_media = -1;
    int auto_answer = -1;
    int auto_ack = -1;
    int invite_timeout = -1;
    
    int session_timer = -1;
    int min_se = -1;
    int refresher = -1;
    int update_refresh = -1;
    
    int message_enable = -1;
    int win_messenger_enable = -1;
    int message_auto_respond = -1;
    
    int callee_caps = -1;
    int media_features = -1;
    int service_route_enable = -1;
    int path_enable = -1;

    sip_allow_t const *allow = NONE;
    char const   *allow_str = "NONE";
    sip_supported_t const *supported = NONE;
    char const *supported_str = "NONE";
    sip_user_agent_t const *user_agent = NONE;
    char const *user_agent_str = "NONE";
    sip_organization_t const *organization = NONE;
    char const *organization_str = "NONE";

    url_string_t const *registrar = NONE;

    int n;
    nua_event_t event = nua_i_error;
    tagi_t const *tags = NULL;

533
    nua_get_hparams(nh, TAG_ANY(), TAG_END());
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580
    run_a_until(ctx, nua_r_get_params, save_final_response);

    TEST(nua_info_event(ctx->a.saved_event, 
			&event, NULL, NULL, NULL, NULL, NULL, NULL, &tags), 1);
    TEST(event, nua_r_get_params);

    n = tl_gets(tags,
	       	SIPTAG_FROM_REF(from),
	       	SIPTAG_FROM_STR_REF(from_str),

	       	NUTAG_RETRY_COUNT_REF(retry_count),
	       	NUTAG_MAX_SUBSCRIPTIONS_REF(max_subscriptions),

	       	NUTAG_ENABLEINVITE_REF(invite_enable),
	       	NUTAG_AUTOALERT_REF(auto_alert),
	       	NUTAG_EARLY_MEDIA_REF(early_media),
	       	NUTAG_AUTOANSWER_REF(auto_answer),
	       	NUTAG_AUTOACK_REF(auto_ack),
	       	NUTAG_INVITE_TIMER_REF(invite_timeout),

	       	NUTAG_SESSION_TIMER_REF(session_timer),
	       	NUTAG_MIN_SE_REF(min_se),
	       	NUTAG_SESSION_REFRESHER_REF(refresher),
	       	NUTAG_UPDATE_REFRESH_REF(update_refresh),

	       	NUTAG_ENABLEMESSAGE_REF(message_enable),
	       	NUTAG_ENABLEMESSENGER_REF(win_messenger_enable),
	       	/* NUTAG_MESSAGE_AUTOANSWER(message_auto_respond), */

	       	NUTAG_CALLEE_CAPS_REF(callee_caps),
	       	NUTAG_MEDIA_FEATURES_REF(media_features),
	       	NUTAG_SERVICE_ROUTE_ENABLE_REF(service_route_enable),
	       	NUTAG_PATH_ENABLE_REF(path_enable),

	       	SIPTAG_SUPPORTED_REF(supported),
	       	SIPTAG_SUPPORTED_STR_REF(supported_str),
	       	SIPTAG_ALLOW_REF(allow),
	       	SIPTAG_ALLOW_STR_REF(allow_str),
	       	SIPTAG_USER_AGENT_REF(user_agent),
	       	SIPTAG_USER_AGENT_STR_REF(user_agent_str),

	       	SIPTAG_ORGANIZATION_REF(organization),
	       	SIPTAG_ORGANIZATION_STR_REF(organization_str),

	       	NUTAG_REGISTRAR_REF(registrar),

		TAG_END());
581
    TEST(n, 3);
582 583 584

    TEST(invite_timeout, 90);

585 586 587 588
    TEST_1(from != NULL && from != NONE);
    TEST_1(strcmp(from_str, "NONE"));
    
    /* Nothing else should be set */
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625
    TEST(retry_count, -1);
    TEST(max_subscriptions, -1);

    TEST(invite_enable, -1);
    TEST(auto_alert, -1);
    TEST(early_media, -1);
    TEST(auto_answer, -1);
    TEST(auto_ack, -1);

    TEST(session_timer, -1);
    TEST(min_se, -1);
    TEST(refresher, -1);
    TEST(update_refresh, -1);

    TEST(message_enable, -1);
    TEST(win_messenger_enable, -1);
    TEST(message_auto_respond, -1); /* XXX */

    TEST(callee_caps, -1);
    TEST(media_features, -1);
    TEST(service_route_enable, -1);
    TEST(path_enable, -1);

    TEST(allow, NONE);
    TEST_S(allow_str, "NONE");
    TEST(supported, NONE);
    TEST_S(supported_str, "NONE");
    TEST(user_agent, NONE);
    TEST_S(user_agent_str, "NONE");
    TEST(organization, NONE);
    TEST_S(organization_str, "NONE");

    TEST(registrar->us_url, NONE);
  }

  nua_handle_destroy(nh);

Pekka Pessi's avatar
Pekka Pessi committed
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
  END();
}

int test_basic_call(struct context *ctx)
{
  BEGIN();
  END();
}



int test_deinit(struct context *ctx)
{
  BEGIN();

  nua_shutdown(ctx->a.nua);
642
  run_a_until(ctx, nua_r_shutdown, condition_final_response);
Pekka Pessi's avatar
Pekka Pessi committed
643 644 645
  nua_destroy(ctx->a.nua), ctx->a.nua = NULL;

  nua_shutdown(ctx->b.nua);
646
  run_b_until(ctx, nua_r_shutdown, condition_final_response);
Pekka Pessi's avatar
Pekka Pessi committed
647 648 649
  nua_destroy(ctx->b.nua), ctx->b.nua = NULL;

  su_root_destroy(ctx->root);
650

Pekka Pessi's avatar
Pekka Pessi committed
651 652 653 654 655 656 657 658 659 660 661 662 663
  END();
}

#if HAVE_ALARM
static RETSIGTYPE sig_alarm(int s)
{
  fprintf(stderr, "%s: FAIL! test timeout!\n", name);
  exit(1);
}
#endif

void usage(void)
{
664 665
  fprintf(stderr,
	  "usage: %s [-v|-q] [-l level] [-p outbound-proxy-uri]\n",
Pekka Pessi's avatar
Pekka Pessi committed
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696
	  name);
  exit(1);
}

int main(int argc, char *argv[])
{
  int retval = 0, quit_on_single_failure = 0;
  int i, o_attach = 0, o_alarm = 1;

  struct context ctx[1] = {{{ SU_HOME_INIT(ctx) }}};

  for (i = 1; argv[i]; i++) {
    if (strcmp(argv[i], "-v") == 0)
      tstflags |= tst_verbatim;
    else if (strcmp(argv[i], "-q") == 0)
      tstflags &= ~tst_verbatim;
    else if (strcmp(argv[i], "-1") == 0)
      quit_on_single_failure = 1;
    else if (strncmp(argv[i], "-l", 2) == 0) {
      int level = 3;
      char *rest = NULL;

      if (argv[i][2])
	level = strtol(argv[i] + 2, &rest, 10);
      else if (argv[i + 1])
	level = strtol(argv[i + 1], &rest, 10), i++;
      else
	level = 3, rest = "";

      if (rest == NULL || *rest)
	usage();
697

Pekka Pessi's avatar
Pekka Pessi committed
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751
      su_log_set_level(nua_log, level);
    }
    else if (strcmp(argv[i], "--attach") == 0) {
      o_attach = 1;
    }
    else if (strcmp(argv[i], "--no-alarm") == 0) {
      o_alarm = 0;
    }
    else if (strcmp(argv[i], "-") == 0) {
      i++; break;
    }
    else if (argv[i][0] != '-') {
      break;
    }
    else
      usage();
  }

  if (o_attach) {
    char line[10];
    printf("%s: pid %u\n", name, getpid());
    printf("<Press RETURN to continue>\n");
    fgets(line, sizeof line, stdin);
  }
#if HAVE_ALARM
  else if (o_alarm) {
    alarm(60);
    signal(SIGALRM, sig_alarm);
  }
#endif

  su_init();

  if (!(TSTFLAGS & tst_verbatim)) {
    su_log_soft_set_level(nua_log, 0);
  }

#define SINGLE_FAILURE_CHECK()						\
  do { fflush(stdout);							\
    if (retval && quit_on_single_failure) { su_deinit(); return retval; } \
  } while(0)

  retval |= test_api_errors(ctx); SINGLE_FAILURE_CHECK();
  retval |= test_init(ctx, argv + i); SINGLE_FAILURE_CHECK();
  if (retval == 0) {
    retval |= test_params(ctx); SINGLE_FAILURE_CHECK();
    retval |= test_basic_call(ctx); SINGLE_FAILURE_CHECK();
  }
  retval |= test_deinit(ctx); SINGLE_FAILURE_CHECK();

  su_deinit();

  return retval;
}