torture_su_tag.c 14.1 KB
Newer Older
Pekka Pessi's avatar
Pekka Pessi committed
1 2 3 4 5 6 7
/*
 * This file is part of the Sofia-SIP package
 *
 * Copyright (C) 2005 Nokia Corporation.
 *
 * Contact: Pekka Pessi <pekka.pessi@nokia.com>
 *
8
 * This library is free software; you can redistribute it and/or
Pekka Pessi's avatar
Pekka Pessi committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 * 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
 *
 */

/**@SU_TAG
 * 
27
 * @file torture_su_tag.c
Pekka Pessi's avatar
Pekka Pessi committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41
 *
 * Testing functions for su_tag module.
 *
 * @author Pekka Pessi <Pekka.Pessi@nokia.com>
 * 
 * @date Created: Tue Mar  6 18:33:42 2001 ppessi
 */

#include "config.h"

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

42 43 44 45
#include <sofia-sip/su_tag.h>
#include <sofia-sip/su_tag_io.h>
#include <sofia-sip/su_tag_class.h>
#include <sofia-sip/su_tagarg.h>
Pekka Pessi's avatar
Pekka Pessi committed
46 47 48 49 50 51 52 53 54 55 56

#ifndef WIN32
#define DEVNULL "/dev/null"
#else
#define DEVNULL "nul"
#endif 

int tstflags = 0;

#define TSTFLAGS tstflags

57
#include <sofia-sip/tstdef.h>
Pekka Pessi's avatar
Pekka Pessi committed
58 59 60 61 62 63 64 65 66 67 68 69 70

#define TAG_A(s)      tag_a, tag_str_v((s))
#define TAG_A_REF(s)  tag_a_ref, tag_str_vr(&(s))
#define TAG_B(s)      tag_b, tag_str_v((s))
#define TAG_B_REF(s)  tag_b_ref, tag_str_vr(&(s))

#define TAG_I(i)      tag_i, tag_int_v((i))
#define TAG_I_REF(i)  tag_i_ref, tag_int_vr(&(i))
#define TAG_J(i)      tag_j, tag_int_v((i))
#define TAG_J_REF(i)  tag_j_ref, tag_int_vr(&(i))
#define TAG_K(i)      tag_k, tag_int_v((i))
#define TAG_K_REF(i)  tag_k_ref, tag_int_vr(&(i))

71 72
#define TAG_ANY_PQ()  tag_any_pq, (tag_value_t)0

Pekka Pessi's avatar
Pekka Pessi committed
73 74 75 76 77 78 79 80 81 82 83 84 85
#define TAG_P(i)      tag_p, tag_bool_v((i))
#define TAG_P_REF(i)  tag_p_ref, tag_bool_vr(&(i))
#define TAG_Q(i)      tag_q, tag_bool_v((i))
#define TAG_Q_REF(i)  tag_q_ref, tag_bool_vr(&(i))

char const *name = "su_tag_test";

#if HAVE_WIN32
typedef struct tag_type_s tag_typedef_win_t[1];

tag_typedef_win_t tag_a, tag_a_ref, tag_b, tag_b_ref;
tag_typedef_win_t tag_i, tag_i_ref, tag_j, tag_j_ref;
tag_typedef_win_t tag_k, tag_k_ref, tag_n, tag_n_ref;
86
tag_typedef_win_t tag_any_pq;
Pekka Pessi's avatar
Pekka Pessi committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
tag_typedef_win_t tag_p, tag_p_ref, tag_q, tag_q_ref;

#else
tag_typedef_t tag_a = STRTAG_TYPEDEF(a);
tag_typedef_t tag_a_ref = REFTAG_TYPEDEF(tag_a);

tag_typedef_t tag_b = STRTAG_TYPEDEF(b);
tag_typedef_t tag_b_ref = REFTAG_TYPEDEF(tag_b);

tag_typedef_t tag_i = INTTAG_TYPEDEF(i);
tag_typedef_t tag_i_ref = REFTAG_TYPEDEF(tag_i);

tag_typedef_t tag_j = INTTAG_TYPEDEF(j);
tag_typedef_t tag_j_ref = REFTAG_TYPEDEF(tag_j);

tag_typedef_t tag_k = INTTAG_TYPEDEF(k);
tag_typedef_t tag_k_ref = REFTAG_TYPEDEF(tag_k);

tag_typedef_t tag_n = INTTAG_TYPEDEF(n);
tag_typedef_t tag_n_ref = REFTAG_TYPEDEF(tag_n);

108 109 110 111 112
#undef TAG_NAMESPACE
#define TAG_NAMESPACE "pq"

tag_typedef_t tag_any_pq = NSTAG_TYPEDEF(*);

Pekka Pessi's avatar
Pekka Pessi committed
113 114 115 116 117 118 119 120
tag_typedef_t tag_p = BOOLTAG_TYPEDEF(p);
tag_typedef_t tag_p_ref = REFTAG_TYPEDEF(tag_p);

tag_typedef_t tag_q = BOOLTAG_TYPEDEF(q);
tag_typedef_t tag_q_ref = REFTAG_TYPEDEF(tag_q);

#endif

121
static void init_tags(void)
Pekka Pessi's avatar
Pekka Pessi committed
122 123
{
#if HAVE_WIN32
124 125
  /* Automatic initialization with pointers from DLL does not work in WIN32 */

Pekka Pessi's avatar
Pekka Pessi committed
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
  tag_typedef_t _tag_a = STRTAG_TYPEDEF(a);
  tag_typedef_t _tag_a_ref = REFTAG_TYPEDEF(tag_a);

  tag_typedef_t _tag_b = STRTAG_TYPEDEF(b);
  tag_typedef_t _tag_b_ref = REFTAG_TYPEDEF(tag_b);
 
  tag_typedef_t _tag_i = INTTAG_TYPEDEF(i);
  tag_typedef_t _tag_i_ref = REFTAG_TYPEDEF(tag_i);
 
  tag_typedef_t _tag_j = INTTAG_TYPEDEF(j);
  tag_typedef_t _tag_j_ref = REFTAG_TYPEDEF(tag_j);
 
  tag_typedef_t _tag_k = INTTAG_TYPEDEF(k);
  tag_typedef_t _tag_k_ref = REFTAG_TYPEDEF(tag_k);
  
  tag_typedef_t _tag_n = INTTAG_TYPEDEF(n);
  tag_typedef_t _tag_n_ref = REFTAG_TYPEDEF(tag_n);
143 144 145

#undef TAG_NAMESPACE
#define TAG_NAMESPACE "pq"
Pekka Pessi's avatar
Pekka Pessi committed
146
  
147 148
  tag_typedef_t _tag_any_pq = NSTAG_TYPEDEF(*);

Pekka Pessi's avatar
Pekka Pessi committed
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
  tag_typedef_t _tag_p = BOOLTAG_TYPEDEF(p);
  tag_typedef_t _tag_p_ref = REFTAG_TYPEDEF(tag_p);
  
  tag_typedef_t _tag_q = BOOLTAG_TYPEDEF(q);
  tag_typedef_t _tag_q_ref = REFTAG_TYPEDEF(tag_q);

  *(struct tag_type_s *)tag_a = *_tag_a;
  *(struct tag_type_s *)tag_a_ref = *_tag_a_ref;
  *(struct tag_type_s *)tag_b = *_tag_b;
  *(struct tag_type_s *)tag_b_ref = *_tag_b_ref;
  *(struct tag_type_s *)tag_i = *_tag_i;
  *(struct tag_type_s *)tag_i_ref = *_tag_i_ref;
  *(struct tag_type_s *)tag_j = *_tag_j;
  *(struct tag_type_s *)tag_j_ref = *_tag_j_ref;
  *(struct tag_type_s *)tag_k = *_tag_k;
  *(struct tag_type_s *)tag_k_ref = *_tag_k_ref;
  *(struct tag_type_s *)tag_n = *_tag_n;
  *(struct tag_type_s *)tag_n_ref = *_tag_n_ref;
167
  *(struct tag_type_s *)tag_any_pq = *_tag_any_pq;
Pekka Pessi's avatar
Pekka Pessi committed
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
  *(struct tag_type_s *)tag_p = *_tag_p;
  *(struct tag_type_s *)tag_p_ref = *_tag_p_ref;
  *(struct tag_type_s *)tag_q = *_tag_q;
  *(struct tag_type_s *)tag_q_ref = *_tag_q_ref;
#endif
}

static int test_assumptions(void)
{
  tagi_t tags[2], *tagi;

  BEGIN();

  TEST_1(sizeof (tag_value_t) >= sizeof (void *));

  /* First some pointer arithmetics - this is always true, right? */
  tagi = tags;
185
  TEST_P(tagi + 1, tags + 1);
Pekka Pessi's avatar
Pekka Pessi committed
186
  tagi = (tagi_t *)(sizeof(tagi_t) + (char *)tagi);
187
  TEST_P(tagi, tags + 1);
Pekka Pessi's avatar
Pekka Pessi committed
188 189 190 191 192 193 194 195 196 197 198 199

  END();
}

#if SU_HAVE_TAGSTACK

/* Automake thing:

###
### Test if we have stack suitable for handling tags directly
###
AC_TRY_RUN( [
200 201 202 203 204 205
#if HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#if HAVE_STDINT_H
#include <stdint.h>
#endif
Pekka Pessi's avatar
Pekka Pessi committed
206 207
#include <stdarg.h>

208 209 210 211
typedef void *tp;
typedef intptr_t tv;

int test1(tv l, tv h, ...)
Pekka Pessi's avatar
Pekka Pessi committed
212 213
{
  va_list ap;
214
  tv i, *p = &l;
Pekka Pessi's avatar
Pekka Pessi committed
215 216 217 218 219 220 221 222 223 224 225

  va_start(ap, h);

  if (*p++ != l || *p++ != h) return 1;

  for (i = l; i <= h; i++) {
    if (*p++ != i)
      return 1;
  }

  for (i = l; i <= h; i++) {
226
    if (va_arg(ap, tv) != i)
Pekka Pessi's avatar
Pekka Pessi committed
227 228 229 230 231 232 233 234 235 236
      return 1;
  }

  va_end(ap);

  return 0;
}

int main(int avc, char *av[])
{
237 238 239
  return test1((tv)1, (tv)10,
	       (tv)1, (tv)2, (tv)3, (tv)4, (tv)5,
	       (tv)6, (tv)7, (tv)8, (tv)9, (tv)10);
Pekka Pessi's avatar
Pekka Pessi committed
240 241
}
], 
242
SAC_SU_DEFINE(SU_HAVE_TAGSTACK, 1, [
Pekka Pessi's avatar
Pekka Pessi committed
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
Define this as 1 if your compiler puts the variable argument list nicely in memory]), 
)

*/

static int test_stackargs(int l, ...)
{
  va_list ap;  
  int i, *p;

  BEGIN();

  va_start(ap, l);
  
  p = &l;

  for (i = l; i <= 10; i++) {
    TEST(*p++, i);
  }

  for (i = l + 1; i <= 10; i++) {
    TEST(va_arg(ap, int), i);
  }

  va_end(ap);

  END();
}
#else
static int test_stackargs(int l, ...) { return 0; }
#endif

275
/** Test tl_list, tl_llist and tl_dup */
Pekka Pessi's avatar
Pekka Pessi committed
276 277 278 279 280 281 282 283 284 285 286 287 288
static int test_dup(void)
{
  tagi_t const rest[] = {{ TAG_A("Foo") }, { TAG_NULL() }};
  tagi_t *lst, *dup;

  BEGIN();

  lst = tl_list(TAG_A("Moro"), 
		TAG_A("Vaan"), 
		TAG_I(1), 
		TAG_SKIP(2), 
		TAG_NEXT(rest));

289 290 291 292 293
  TEST_P(lst[0].t_tag, tag_a);
  TEST_P(lst[1].t_tag, tag_a);
  TEST_P(lst[2].t_tag, tag_i);
  TEST_P(lst[3].t_tag, tag_skip);
  TEST_P(lst[4].t_tag, tag_next);
Pekka Pessi's avatar
Pekka Pessi committed
294

295 296
  TEST_SIZE(tl_len(lst), 5 * sizeof(tagi_t));
  TEST_SIZE(tl_xtra(lst, 0), strlen("Moro" "Vaan" "Foo") + 3);
Pekka Pessi's avatar
Pekka Pessi committed
297 298 299

  dup = tl_adup(NULL, lst);

300 301 302
  TEST_1(dup != NULL);
  TEST_SIZE(tl_len(dup), 5 * sizeof(tagi_t));
  TEST_SIZE(tl_xtra(dup, 0), strlen("Moro" "Vaan" "Foo") + 3);
Pekka Pessi's avatar
Pekka Pessi committed
303 304

  su_free(NULL, dup);
305 306 307

  dup = tl_llist(TAG_B("Moi"), TAG_NEXT(lst));

308 309 310 311 312 313
  TEST_P(dup[0].t_tag, tag_b);
  TEST_P(dup[1].t_tag, tag_a);
  TEST_P(dup[2].t_tag, tag_a);
  TEST_P(dup[3].t_tag, tag_i);
  TEST_P(dup[4].t_tag, tag_a);
  TEST_P(dup[5].t_tag, NULL);
314 315 316 317

  su_free(NULL, dup);

  dup = tl_llist(TAG_NEXT(NULL));
318
  TEST_P(dup[0].t_tag, 0);
319 320 321
  su_free(NULL, dup);

  dup = tl_llist(TAG_END());
322
  TEST_P(dup[0].t_tag, 0);
323 324 325
  su_free(NULL, dup);

  dup = tl_llist(TAG_SKIP(1), TAG_NEXT(lst + 4));
326 327
  TEST_P(dup[0].t_tag, tag_a);
  TEST_P(dup[1].t_tag, 0);
328 329
  su_free(NULL, dup);

Pekka Pessi's avatar
Pekka Pessi committed
330 331 332 333 334
  tl_vfree(lst);

  END();
}

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
/* filtering function */
int filter(tagi_t const *filter, tagi_t const *t)
{
  if (!t)
    return 0;

  /* Accept even TAG_I() */
  if (t->t_tag == tag_i)
    return (t->t_value & 1) == 0;

  /* TAG_Q(true) */
  if (t->t_tag == tag_q)
    return t->t_value != 0;

  /* TAG_P(false) */
  if (t->t_tag == tag_p)
    return t->t_value == 0;

  if (t->t_tag == tag_a) {
    char const *s = (char *)t->t_value;
    if (s && 'A' <= *s && *s <= 'Z')
      return 1;
  }

  return 0;
}

Pekka Pessi's avatar
Pekka Pessi committed
362 363 364
/* Test tl_afilter() */
static int test_filters(void)
{
365 366
  tagi_t *lst, *filter1, *filter2, *filter3, *filter4, *filter5, *filter6;
  tagi_t *b, *b1, *b2, *b3, *b4;
Pekka Pessi's avatar
Pekka Pessi committed
367

368
  tagi_t *nsfilter, *b5;
369
  su_home_t *home;
370

Pekka Pessi's avatar
Pekka Pessi committed
371 372
  BEGIN();

373 374
  home = su_home_new(sizeof *home); TEST_1(home);

Pekka Pessi's avatar
Pekka Pessi committed
375
  lst = tl_list(TAG_A("Moro"), 
376 377
		TAG_I(2),
		TAG_Q(3),
Pekka Pessi's avatar
Pekka Pessi committed
378
		TAG_SKIP(2), 
379
		TAG_A("vaan"), 
Pekka Pessi's avatar
Pekka Pessi committed
380
		TAG_I(1), 
381
		TAG_P(2),
Pekka Pessi's avatar
Pekka Pessi committed
382 383 384 385 386 387
		TAG_NULL());

  filter1 = tl_list(TAG_A(""), TAG_NULL());
  filter2 = tl_list(TAG_I(0), TAG_NULL());
  filter3 = tl_list(TAG_A(""), TAG_I(0), TAG_NULL());
  filter4 = tl_list(TAG_ANY(), TAG_NULL());
388
  filter5 = tl_list(TAG_FILTER(filter), TAG_NULL());
389
  filter6 = tl_list(TAG_NULL());
Pekka Pessi's avatar
Pekka Pessi committed
390

391
  TEST0(lst && filter1 && filter2 && filter3 && filter4 && filter5);
Pekka Pessi's avatar
Pekka Pessi committed
392 393 394

  b1 = tl_afilter(NULL, filter1, lst);

395 396
  TEST_SIZE(tl_len(b1), 3 * sizeof(tagi_t));
  TEST_SIZE(tl_xtra(b1, 0), strlen("Moro" "vaan") + 2);
Pekka Pessi's avatar
Pekka Pessi committed
397 398 399

  b2 = tl_afilter(NULL, filter2, lst);

400 401
  TEST_SIZE(tl_len(b2), 3 * sizeof(tagi_t));
  TEST_SIZE(tl_xtra(b2, 0), 0);
Pekka Pessi's avatar
Pekka Pessi committed
402 403 404

  b3 = tl_afilter(NULL, filter3, lst);

405 406
  TEST_SIZE(tl_len(b3), 5 * sizeof(tagi_t));
  TEST_SIZE(tl_xtra(b3, 0), strlen("Moro" "vaan") + 2);
Pekka Pessi's avatar
Pekka Pessi committed
407 408 409

  b4 = tl_afilter(NULL, filter4, lst);

410 411
  TEST_SIZE(tl_len(b4), 7 * sizeof(tagi_t));
  TEST_SIZE(tl_xtra(b4, 0), strlen("Moro" "vaan") + 2);
Pekka Pessi's avatar
Pekka Pessi committed
412 413

  su_free(NULL, b1); su_free(NULL, b2); su_free(NULL, b3); su_free(NULL, b4);
414 415

  nsfilter = tl_list(TAG_ANY_PQ(), TAG_END());
Pekka Pessi's avatar
Pekka Pessi committed
416
  
417
  b5 = tl_afilter(NULL, nsfilter, lst);
418 419
  TEST_SIZE(tl_len(b5), 3 * sizeof(tagi_t));
  TEST_SIZE(tl_xtra(b5, 0), 0);
420

421 422
  TEST_P(b5[0].t_tag, tag_q);
  TEST_P(b5[1].t_tag, tag_p);
423

424
  b = tl_afilter(home, filter5, lst); TEST_1(b);
425 426 427 428
  TEST_P(b[0].t_tag, tag_a);
  TEST_P(b[1].t_tag, tag_i);
  TEST_P(b[2].t_tag, tag_q);
  TEST_P(b[3].t_tag, 0);
429 430

  b = tl_afilter(home, filter6, lst); TEST_1(b);
431
  TEST_P(b[0].t_tag, 0);
432 433

  tl_vfree(filter1); tl_vfree(filter2); tl_vfree(filter3); 
434
  tl_vfree(filter4); tl_vfree(filter5); tl_vfree(filter6);
435

Pekka Pessi's avatar
Pekka Pessi committed
436 437
  tl_vfree(lst);

438 439
  su_home_unref(home);

Pekka Pessi's avatar
Pekka Pessi committed
440 441 442 443 444 445
  END();
}

/* Test tl_print */
static int test_print(void)
{
446 447
  BEGIN();

Pekka Pessi's avatar
Pekka Pessi committed
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
  tagi_t *lst;
  FILE *out;

  lst = tl_list(TAG_A("Moro"), 
		TAG_I(2), 
		TAG_J(3),
		TAG_K(5),
		TAG_SKIP(2), 
		TAG_A("Vaan"), 
		TAG_B("b"),
		TAG_I(1), 
		TAG_NULL());

  if (tstflags & tst_verbatim)
    out = stdout;
  else
    out = fopen(DEVNULL, "w");

  if (out) {
    tl_print(out, "test_print: ", lst);

    if ((tstflags & tst_verbatim) == 0)
      fclose(out);
  }

  END();
}

static int test_tagargs2(tag_type_t tag, tag_value_t value, ...)
{
  ta_list ta;
  tagi_t const *t;

  BEGIN();

  ta_start(ta, tag, value);

  t = ta_args(ta);
486
  TEST_P(t->t_tag, tag_a);
Pekka Pessi's avatar
Pekka Pessi committed
487 488 489
  TEST_S((char *)t->t_value, "a");

  t = tl_next(t);
490
  TEST_P(t->t_tag, tag_b);
Pekka Pessi's avatar
Pekka Pessi committed
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
  TEST_S((char *)t->t_value, "b");

  ta_end(ta);

  END();
}

/* Test tagargs) */
static int test_tagargs(void)
{
  return test_tagargs2(TAG_A("a"),
		       TAG_B("b"),
		       TAG_I(1),
		       TAG_J(2),
		       TAG_K(3),
		       TAG_P(0),
		       TAG_Q(-1),
		       TAG_END());
}

/* Test tl_tgets() and tl_gets() */
static int test_gets(void)
{
514
  tagi_t *lst, *t;
Pekka Pessi's avatar
Pekka Pessi committed
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
  char const *a = "B", *b = "A";
  int i = 1, j = 0, k = 0, p = -1;

  BEGIN();

  lst = tl_list(TAG_A("Moro"), 
		TAG_I(2), 
		TAG_J(3),
		TAG_K(5),
		TAG_P(3),
		TAG_SKIP(2), 
		TAG_A("Vaan"), 
		TAG_B("b"),
		TAG_I(1), 
		TAG_NULL());

  TEST_1(lst);

533 534 535
  TEST_1(t = tl_find(lst, tag_i)); TEST(t->t_value, 2);
  TEST_1(t = tl_find_last(lst, tag_i)); TEST(t->t_value, 1);

Pekka Pessi's avatar
Pekka Pessi committed
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 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611
  TEST(tl_gets(lst, 
	       TAG_A_REF(a),
	       TAG_B_REF(b),
	       TAG_I_REF(i),
	       TAG_J_REF(j),
	       TAG_K_REF(k),
	       TAG_P_REF(p),
	       TAG_END()),
       6);

  /* tl_gets() semantics have changed */
#if 0
  TEST_S(a, "Moro");
  TEST(i, 2);
#else
  TEST_S(a, "Vaan");
  TEST(i, 1);
#endif
  TEST(j, 3);
  TEST(k, 5);
  TEST(p, 1);
  TEST_S(b, "b");

  lst = tl_list(TAG_A_REF(a),
		TAG_I_REF(i),
		TAG_NULL());
  
  TEST(tl_tgets(lst, TAG_A("Foo"), TAG_I(-1), TAG_END()), 2);

  TEST_S(a, "Foo");
  TEST(i, -1);

  END();
}

static int test_scan(void)
{
  tag_value_t v = 0;

  BEGIN();

  TEST(t_scan(tag_a, NULL, NULL, &v), -1); /* Invalid case */

  TEST(t_scan(tag_a, NULL, "foo", &v), 1);
  TEST_S((char *)v, "foo");
  su_free(NULL, (void *)v);

  TEST(t_scan(tag_i, NULL, "", &v), -1); /* Invalid case */
  TEST(t_scan(tag_i, NULL, "kukkuu-reset", &v), -1); /* Invalid case */

  TEST(t_scan(tag_i, NULL, "-1234", &v), 1);
  TEST(v, -1234);

  TEST(t_scan(tag_n, NULL, "", &v), -1); /* Invalid case */

  TEST(t_scan(tag_n, NULL, "3243432", &v), 1);
  TEST(v, 3243432);

  TEST(t_scan(tag_p, NULL, "kukkuu-reset", &v), -1); /* Invalid case */
  TEST(t_scan(tag_p, NULL, "", &v), -1); /* Invalid case */

  TEST(t_scan(tag_p, NULL, "true", &v), 1);
  TEST(v, 1);

  TEST(t_scan(tag_p, NULL, "true ", &v), 1);
  TEST(v, 1);

  TEST(t_scan(tag_p, NULL, "  134  ", &v), 1);
  TEST(v, 1);

  TEST(t_scan(tag_p, NULL, "false   \n\t", &v), 1);
  TEST(v, 0);

  TEST(t_scan(tag_p, NULL, "  000.000  ", &v), 1);
  TEST(v, 0);

612 613 614
  TEST(t_scan(tag_null, NULL, "NULL", &v), -2);
  TEST(t_scan(tag_skip, NULL, "SKIP", &v), -2);
  TEST(t_scan(tag_any, NULL, "any", &v), -2);
Pekka Pessi's avatar
Pekka Pessi committed
615 616 617 618 619 620 621 622

  TEST(t_scan(NULL, NULL, "-1234", &v), -1);
  TEST(t_scan(tag_a, NULL, NULL, &v), -1);
  TEST(t_scan(tag_a, NULL, "-1234", NULL), -1);

  END();
}

623
void usage(int exitcode)
624 625
{
  fprintf(stderr, 
626
	  "usage: %s [-v] [-a]\n", 
627
	  name);
628
  exit(exitcode);
629 630 631 632 633 634 635 636 637 638 639 640
}

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

  init_tags();

  for (i = 1; argv[i]; i++) {
    if (strcmp(argv[i], "-v") == 0)
      tstflags |= tst_verbatim;
641 642
    else if (strcmp(argv[i], "-a") == 0)
      tstflags |= tst_abort;
643
    else
644
      usage(1);
645 646
  }

647 648 649 650
#if HAVE_OPEN_C
  tstflags |= tst_verbatim;
#endif

651 652 653 654 655 656 657 658 659 660 661
  retval |= test_assumptions();
  retval |= test_stackargs(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
  retval |= test_dup();
  retval |= test_filters();
  retval |= test_print();
  retval |= test_tagargs();
  retval |= test_gets();
  retval |= test_scan();

  return retval;
}