Changeset 119 for pjproject/trunk/pjsip/src/test-pjsip/txdata_test.c
- Timestamp:
- Jan 10, 2006 1:31:40 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/test-pjsip/txdata_test.c
r109 r119 30 30 * This tests various core message creation functions. 31 31 */ 32 inttxdata_test(void)32 static int core_txdata_test(void) 33 33 { 34 34 pj_status_t status; … … 36 36 pjsip_rx_data dummy_rdata; 37 37 pjsip_tx_data *invite, *invite2, *cancel, *response, *ack; 38 39 PJ_LOG(3,(THIS_FILE, " core transmit data test")); 38 40 39 41 /* Create INVITE request. */ … … 322 324 } 323 325 326 /* This tests the request creating functions against the following 327 * requirements: 328 * - header params in URI creates header in the request. 329 * - method and headers params are correctly shown or hidden in 330 * request URI, From, To, and Contact header. 331 */ 332 static int txdata_test_uri_params(void) 333 { 334 char msgbuf[512]; 335 pj_str_t target = pj_str("sip:alice@wonderland:5061;x-param=param%201" 336 "?X-Hdr-1=Header%201" 337 "&X-Empty-Hdr="); 338 pj_str_t pname = pj_str("x-param"); 339 pj_str_t hname = pj_str("X-Hdr-1"); 340 pj_str_t hemptyname = pj_str("X-Empty-Hdr"); 341 pjsip_from_hdr *from_hdr; 342 pjsip_to_hdr *to_hdr; 343 pjsip_contact_hdr *contact_hdr; 344 pjsip_generic_string_hdr *hdr; 345 pjsip_tx_data *tdata; 346 pjsip_sip_uri *uri; 347 pjsip_param *param; 348 pjsip_msg *msg; 349 int len; 350 pj_status_t status; 351 352 PJ_LOG(3,(THIS_FILE, " header param in URI to create request")); 353 354 /* Create request with header param in target URI. */ 355 status = pjsip_endpt_create_request(endpt, &pjsip_invite_method, &target, 356 &target, &target, &target, NULL, -1, 357 NULL, &tdata); 358 if (status != 0) { 359 app_perror(" error: Unable to create request", status); 360 return -200; 361 } 362 363 /* Print and parse the request. 364 * We'll check that header params are not present in 365 */ 366 len = pjsip_msg_print(tdata->msg, msgbuf, sizeof(msgbuf)); 367 if (len < 1) { 368 PJ_LOG(3,(THIS_FILE, " error: printing message")); 369 pjsip_tx_data_dec_ref(tdata); 370 return -250; 371 } 372 msgbuf[len] = '\0'; 373 374 PJ_LOG(5,(THIS_FILE, "%d bytes request created:--begin-msg--\n" 375 "%s\n" 376 "--end-msg--", len, msgbuf)); 377 378 /* Now parse the message. */ 379 msg = pjsip_parse_msg( tdata->pool, msgbuf, len, NULL); 380 if (msg == NULL) { 381 app_perror(" error: parsing message message", status); 382 pjsip_tx_data_dec_ref(tdata); 383 return -250; 384 } 385 386 /* Check the existence of port, other_param, and header param. 387 * Port is now allowed in To and From header. 388 */ 389 /* Port in request URI. */ 390 uri = (pjsip_sip_uri*) pjsip_uri_get_uri(msg->line.req.uri); 391 if (uri->port != 5061) { 392 PJ_LOG(3,(THIS_FILE, " error: port not present in request URI")); 393 pjsip_tx_data_dec_ref(tdata); 394 return -260; 395 } 396 /* other_param in request_uri */ 397 param = pjsip_param_find(&uri->other_param, &pname); 398 if (param == NULL || pj_strcmp2(¶m->value, "param 1") != 0) { 399 PJ_LOG(3,(THIS_FILE, " error: x-param not present in request URI")); 400 pjsip_tx_data_dec_ref(tdata); 401 return -261; 402 } 403 /* header param in request uri. */ 404 if (!pj_list_empty(&uri->header_param)) { 405 PJ_LOG(3,(THIS_FILE, " error: hparam in request URI")); 406 pjsip_tx_data_dec_ref(tdata); 407 return -262; 408 } 409 410 /* Port in From header. */ 411 from_hdr = (pjsip_from_hdr*) pjsip_msg_find_hdr(msg, PJSIP_H_FROM, NULL); 412 uri = (pjsip_sip_uri*) pjsip_uri_get_uri(from_hdr->uri); 413 if (uri->port != 0) { 414 PJ_LOG(3,(THIS_FILE, " error: port most not exist in From header")); 415 pjsip_tx_data_dec_ref(tdata); 416 return -270; 417 } 418 /* other_param in From header */ 419 param = pjsip_param_find(&uri->other_param, &pname); 420 if (param == NULL || pj_strcmp2(¶m->value, "param 1") != 0) { 421 PJ_LOG(3,(THIS_FILE, " error: x-param not present in From header")); 422 pjsip_tx_data_dec_ref(tdata); 423 return -271; 424 } 425 /* header param in From header. */ 426 if (!pj_list_empty(&uri->header_param)) { 427 PJ_LOG(3,(THIS_FILE, " error: hparam in From header")); 428 pjsip_tx_data_dec_ref(tdata); 429 return -272; 430 } 431 432 433 /* Port in To header. */ 434 to_hdr = (pjsip_to_hdr*) pjsip_msg_find_hdr(msg, PJSIP_H_TO, NULL); 435 uri = (pjsip_sip_uri*) pjsip_uri_get_uri(to_hdr->uri); 436 if (uri->port != 0) { 437 PJ_LOG(3,(THIS_FILE, " error: port most not exist in To header")); 438 pjsip_tx_data_dec_ref(tdata); 439 return -280; 440 } 441 /* other_param in To header */ 442 param = pjsip_param_find(&uri->other_param, &pname); 443 if (param == NULL || pj_strcmp2(¶m->value, "param 1") != 0) { 444 PJ_LOG(3,(THIS_FILE, " error: x-param not present in To header")); 445 pjsip_tx_data_dec_ref(tdata); 446 return -281; 447 } 448 /* header param in From header. */ 449 if (!pj_list_empty(&uri->header_param)) { 450 PJ_LOG(3,(THIS_FILE, " error: hparam in To header")); 451 pjsip_tx_data_dec_ref(tdata); 452 return -282; 453 } 454 455 456 457 /* Port in Contact header. */ 458 contact_hdr = (pjsip_contact_hdr*) pjsip_msg_find_hdr(msg, PJSIP_H_CONTACT, NULL); 459 uri = (pjsip_sip_uri*) pjsip_uri_get_uri(contact_hdr->uri); 460 if (uri->port != 5061) { 461 PJ_LOG(3,(THIS_FILE, " error: port not present in Contact header")); 462 pjsip_tx_data_dec_ref(tdata); 463 return -290; 464 } 465 /* other_param in Contact header */ 466 param = pjsip_param_find(&uri->other_param, &pname); 467 if (param == NULL || pj_strcmp2(¶m->value, "param 1") != 0) { 468 PJ_LOG(3,(THIS_FILE, " error: x-param not present in Contact header")); 469 pjsip_tx_data_dec_ref(tdata); 470 return -291; 471 } 472 /* header param in Contact header. */ 473 if (pj_list_empty(&uri->header_param)) { 474 PJ_LOG(3,(THIS_FILE, " error: hparam is missing in Contact header")); 475 pjsip_tx_data_dec_ref(tdata); 476 return -292; 477 } 478 /* Check for X-Hdr-1 */ 479 param = pjsip_param_find(&uri->header_param, &hname); 480 if (param == NULL || pj_strcmp2(¶m->value, "Header 1")!=0) { 481 PJ_LOG(3,(THIS_FILE, " error: hparam is missing in Contact header")); 482 pjsip_tx_data_dec_ref(tdata); 483 return -293; 484 } 485 /* Check for X-Empty-Hdr */ 486 param = pjsip_param_find(&uri->header_param, &hemptyname); 487 if (param == NULL || pj_strcmp2(¶m->value, "")!=0) { 488 PJ_LOG(3,(THIS_FILE, " error: hparam is missing in Contact header")); 489 pjsip_tx_data_dec_ref(tdata); 490 return -294; 491 } 492 493 494 /* Check that headers are present in the request. */ 495 hdr = (pjsip_generic_string_hdr*) 496 pjsip_msg_find_hdr_by_name(msg, &hname, NULL); 497 if (hdr == NULL || pj_strcmp2(&hdr->hvalue, "Header 1")!=0) { 498 PJ_LOG(3,(THIS_FILE, " error: header X-Hdr-1 not created")); 499 pjsip_tx_data_dec_ref(tdata); 500 return -300; 501 } 502 503 hdr = (pjsip_generic_string_hdr*) 504 pjsip_msg_find_hdr_by_name(msg, &hemptyname, NULL); 505 if (hdr == NULL || pj_strcmp2(¶m->value, "")!=0) { 506 PJ_LOG(3,(THIS_FILE, " error: header X-Empty-Hdr not created")); 507 pjsip_tx_data_dec_ref(tdata); 508 return -330; 509 } 510 511 pjsip_tx_data_dec_ref(tdata); 512 return 0; 513 } 514 515 int txdata_test(void) 516 { 517 int status; 518 519 status = core_txdata_test(); 520 if (status != 0) 521 return status; 522 523 524 status = txdata_test_uri_params(); 525 if (status != 0) 526 return status; 527 528 return 0; 529 }
Note: See TracChangeset
for help on using the changeset viewer.