提交 dd9f6af7 authored 作者: Michael Jerris's avatar Michael Jerris

complete r8400 commit

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8406 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 deba14a3
/*
* This file is part of the Sofia-SIP package
*
* Copyright (C) 2007 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 check2_sofia.c
*
* @brief Check-driven tester for Sofia SIP User Agent library
*
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
*
* @copyright (C) 2007 Nokia Corporation.
*/
#include "config.h"
#include "check_nua.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#if HAVE_FNMATCH_H
#include <fnmatch.h>
#endif
static char const * const default_patterns[] = { "*", NULL };
static char const * const *test_patterns = default_patterns;
void check_nua_tcase_add_test(TCase *tc, TFun tf, char const *name)
{
char const * const *patterns;
#if HAVE_FNMATCH_H
for (patterns = test_patterns; *patterns; patterns++) {
if (!fnmatch(*patterns, name, 0)) {
if (strcmp(*patterns, "*")) {
printf("%s: match with %s\n", name, *patterns);
}
_tcase_add_test(tc, tf, name, 0, 0, 1);
return;
}
}
#else
for (patterns = test_patterns; *patterns; patterns++) {
if (!strcmp(*patterns, name) || !strcmp(*patterns, "*")) {
if (strcmp(*patterns, "*")) {
printf("%s: match with %s\n", name, *patterns);
}
_tcase_add_test(tc, tf, name, 0, 0, 1);
return;
}
}
#endif
printf("%s: no match\n", name);
}
int main(int argc, char *argv[])
{
int failed = 0;
Suite *suite = suite_create("Unit tests for Sofia-SIP UA Engine");
SRunner *runner;
if (getenv("CHECK_NUA_CASES")) {
size_t i;
char *s, **patterns;
char *cases = strdup(getenv("CHECK_NUA_CASES"));
/* Count commas */
for (i = 2, s = cases; (s = strchr(s, ',')); s++, i++);
patterns = calloc(i, sizeof *patterns);
for (i = 0, s = cases;; i++) {
patterns[i] = s;
if (s == NULL)
break;
s = strchr(s, ',');
if (s)
*s++ = '\0';
}
test_patterns = (char const * const *)patterns;
}
check_register_cases(suite);
check_session_cases(suite);
runner = srunner_create(suite);
if (argv[1]) {
srunner_set_xml(runner, argv[1]);
}
srunner_run_all(runner, CK_ENV);
failed = srunner_ntests_failed(runner);
srunner_free(runner);
exit(failed ? EXIT_FAILURE : EXIT_SUCCESS);
}
#ifndef CHECK_NUA_H
#include <check.h>
#undef tcase_add_test
#define tcase_add_test(tc, tf) \
check_nua_tcase_add_test(tc, tf, "" #tf "")
void check_nua_tcase_add_test(TCase *, TFun, char const *name);
void check_session_cases(Suite *suite);
void check_register_cases(Suite *suite);
#endif
差异被折叠。
/*
* This file is part of the Sofia-SIP package
*
* Copyright (C) 2008 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
*/
#ifndef S2TESTER_H
#define S2TESTER_H
#define TP_STACK_T struct tester
#define SU_ROOT_MAGIC_T struct tester
#include <sofia-sip/su_wait.h>
#include <sofia-sip/sip.h>
#include <sofia-sip/tport.h>
#include <sofia-sip/nua.h>
struct tester
{
su_home_t home[1];
su_root_t *root;
msg_mclass_t const *mclass;
int flags;
char const *hostname;
tport_t *master;
sip_to_t *local;
sip_contact_t *contact;
struct {
sip_contact_t *contact;
tport_t *tport;
} udp, tcp, tls;
struct message {
struct message *next, **prev;
msg_t *msg;
sip_t *sip;
tport_t *tport;
su_time_t when;
} *received;
struct {
su_socket_t socket;
su_wait_t wait[1];
int reg;
} dns;
nua_t *nua;
struct event {
struct event *next, **prev;
nua_saved_event_t event[1];
nua_handle_t *nh;
nua_event_data_t const *data;
su_time_t when;
} *events;
struct {
nua_handle_t *nh;
sip_to_t *aor;
sip_contact_t *contact;
tport_t *tport;
} registration[1];
unsigned long tid;
/* Settings */
int server_uses_rport;
};
struct dialog
{
su_home_t home[1];
sip_from_t *local;
sip_to_t *remote;
sip_call_id_t *call_id;
uint32_t lseq, rseq;
sip_contact_t *target;
sip_route_t *route;
sip_contact_t *contact;
tport_t *tport;
msg_t *invite; /* latest invite sent */
};
extern struct tester *s2;
extern tp_stack_class_t const s2_stack[1];
extern unsigned s2_default_registration_duration;
extern char const s2_auth_digest_str[];
extern char const s2_auth_credentials[];
extern char const s2_auth2_digest_str[];
extern char const s2_auth2_credentials[];
extern char const s2_auth3_digest_str[];
extern char const s2_auth3_credentials[];
void s2_fast_forward(unsigned long seconds);
void s2_case(char const *tag,
char const *title,
char const *description);
struct event *s2_remove_event(struct event *);
void s2_free_event(struct event *);
void s2_flush_events(void);
struct event *s2_next_event(void);
struct event *s2_wait_for_event(nua_event_t event, int status);
int s2_check_event(nua_event_t event, int status);
int s2_check_callstate(enum nua_callstate state);
struct message *s2_remove_message(struct message *m);
void s2_free_message(struct message *m);
void s2_flush_messages(void);
struct message *s2_next_response(void);
struct message *s2_wait_for_response(int status, sip_method_t , char const *);
int s2_check_response(int status, sip_method_t method, char const *name);
struct message *s2_next_request(void);
struct message *s2_wait_for_request(sip_method_t method, char const *name);
int s2_check_request(sip_method_t method, char const *name);
#define SIP_METHOD_UNKNOWN sip_method_unknown, NULL
struct message *s2_respond_to(struct message *m, struct dialog *d,
int status, char const *phrase,
tag_type_t tag, tag_value_t value, ...);
int s2_request_to(struct dialog *d,
sip_method_t method, char const *name,
tport_t *tport,
tag_type_t tag, tag_value_t value, ...);
int s2_update_dialog(struct dialog *d, struct message *response);
int s2_save_register(struct message *m);
void s2_flush_all(void);
void s2_setup_base(char const *hostname);
void s2_setup_logs(int level);
void s2_setup_tport(char const * const *protocols,
tag_type_t tag, tag_value_t value, ...);
void s2_teardown(void);
nua_t *s2_nua_setup(tag_type_t tag, tag_value_t value, ...);
void s2_nua_teardown(void);
void s2_register_setup(void);
void s2_register_teardown(void);
#endif
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论