⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_soa.c

📁 this is simple sip stack.
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * 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_soa.c * @brief High-level tester for Sofia SDP Offer/Answer Engine * * @author Pekka Pessi <Pekka.Pessi@nokia.com> * * @date Created: Wed Aug 17 12:12:12 EEST 2005 ppessi */#include "config.h"#include <stddef.h>#include <stdlib.h>#include <string.h>#include <assert.h>#if HAVE_ALARM#include <unistd.h>#include <signal.h>#endifstruct context;#define SOA_MAGIC_T struct context#include "sofia-sip/soa.h"#include "sofia-sip/soa_tag.h"#include "sofia-sip/soa_add.h"#include <sofia-sip/sdp.h>#include <sofia-sip/su_log.h>extern su_log_t soa_log[];char const name[] = "test_soa";int tstflags = 0;#define TSTFLAGS tstflags#include <sofia-sip/tstdef.h>#if HAVE_FUNC#elif HAVE_FUNCTION#define __func__ __FUNCTION__#else#define __func__ name#endif#define NONE ((void*)-1)struct context {  su_home_t home[1];  su_root_t *root;  struct {    soa_session_t *a;    soa_session_t *b;  } asynch;  soa_session_t *a;  soa_session_t *b;  soa_session_t *completed;};int test_api_completed(struct context *arg, soa_session_t *session){  return 0;}int test_api_errors(struct context *ctx){  BEGIN();  char const *phrase = NULL;  char const *null = NULL;  TEST_1(!soa_create("default", NULL, NULL));  TEST_1(!soa_clone(NULL, NULL, NULL));  TEST_VOID(soa_destroy(NULL));  TEST_1(-1 == soa_set_params(NULL, TAG_END()));  TEST_1(-1 == soa_get_params(NULL, TAG_END()));  TEST_1(!soa_get_paramlist(NULL, TAG_END()));  TEST(soa_error_as_sip_response(NULL, &phrase), 500);  TEST_S(phrase, "Internal Server Error");  TEST_1(soa_error_as_sip_reason(NULL));  TEST_1(!soa_media_features(NULL, 0, NULL));  TEST_1(!soa_sip_require(NULL));  TEST_1(!soa_sip_supported(NULL));  TEST_1(-1 == soa_remote_sip_features(NULL, &null, &null));  TEST_1(soa_set_capability_sdp(NULL, NULL, NULL, -1) < 0);  TEST_1(soa_set_remote_sdp(NULL, NULL, NULL, -1) < 0);  TEST_1(soa_set_user_sdp(NULL, NULL, NULL, -1) < 0);  TEST_1(soa_get_capability_sdp(NULL, NULL, NULL, NULL) < 0);  TEST_1(soa_get_remote_sdp(NULL, NULL, NULL, NULL) < 0);  TEST_1(soa_get_user_sdp(NULL, NULL, NULL, NULL) < 0);  TEST_1(soa_get_local_sdp(NULL, NULL, NULL, NULL) < 0);  TEST_1(-1 == soa_generate_offer(NULL, 0, test_api_completed));   TEST_1(-1 == soa_generate_answer(NULL, test_api_completed));   TEST_1(-1 == soa_process_answer(NULL, test_api_completed));   TEST_1(-1 == soa_process_reject(NULL, test_api_completed));  TEST(soa_activate(NULL, "both"), -1);  TEST(soa_deactivate(NULL, "both"), -1);  TEST_VOID(soa_terminate(NULL, "both"));  TEST_1(!soa_is_complete(NULL));  TEST_1(!soa_init_offer_answer(NULL));  TEST(soa_is_audio_active(NULL), SOA_ACTIVE_DISABLED);  TEST(soa_is_video_active(NULL), SOA_ACTIVE_DISABLED);  TEST(soa_is_image_active(NULL), SOA_ACTIVE_DISABLED);  TEST(soa_is_chat_active(NULL), SOA_ACTIVE_DISABLED);  TEST(soa_is_remote_audio_active(NULL), SOA_ACTIVE_DISABLED);  TEST(soa_is_remote_video_active(NULL), SOA_ACTIVE_DISABLED);  TEST(soa_is_remote_image_active(NULL), SOA_ACTIVE_DISABLED);  TEST(soa_is_remote_chat_active(NULL), SOA_ACTIVE_DISABLED);  END();}int test_init(struct context *ctx, char *argv[]){  BEGIN();  int n;  ctx->root = su_root_create(ctx); TEST_1(ctx->root);  ctx->asynch.a = soa_create("asynch", ctx->root, ctx);   TEST_1(!ctx->asynch.a);#if 0  TEST_1(!soa_find("asynch"));  TEST_1(soa_find("default"));  n = soa_add("asynch", &soa_asynch_actions); TEST(n, 0);  TEST_1(soa_find("asynch"));  ctx->asynch.a = soa_create("asynch", ctx->root, ctx);   TEST_1(ctx->asynch.a);  ctx->asynch.b = soa_create("asynch", ctx->root, ctx);  TEST_1(ctx->asynch.b);#endif  /* Create asynchronous endpoints */  ctx->a = soa_create("static", ctx->root, ctx);   TEST_1(!ctx->a);  TEST_1(!soa_find("static"));  TEST_1(soa_find("default"));  n = soa_add("static", &soa_default_actions); TEST(n, 0);  TEST_1(soa_find("static"));  ctx->a = soa_create("static", ctx->root, ctx);  TEST_1(ctx->a);  ctx->b = soa_create("static", ctx->root, ctx);  TEST_1(ctx->b);  END();}int test_params(struct context *ctx){  BEGIN();  int n;  int af;  char const *address;  char const *hold;  unsigned rtp_select, rtp_sort;  int rtp_mismatch;  int srtp_enable, srtp_confidentiality, srtp_integrity;  soa_session_t *a = ctx->a, *b = ctx->b;  n = soa_set_params(a, TAG_END()); TEST(n, 0);  n = soa_set_params(b, TAG_END()); TEST(n, 0);  af = -42;  address = NONE;  hold = NONE;  rtp_select = -1, rtp_sort = -1, rtp_mismatch = -1;  srtp_enable = -1, srtp_confidentiality = -1, srtp_integrity = -1;  TEST(soa_get_params(a,		      SOATAG_AF_REF(af),		      SOATAG_ADDRESS_REF(address),		      SOATAG_HOLD_REF(hold),		      SOATAG_RTP_SELECT_REF(rtp_select),		      SOATAG_RTP_SORT_REF(rtp_sort),		      SOATAG_RTP_MISMATCH_REF(rtp_mismatch),		      SOATAG_SRTP_ENABLE_REF(srtp_enable),		      SOATAG_SRTP_CONFIDENTIALITY_REF(srtp_confidentiality),		      SOATAG_SRTP_INTEGRITY_REF(srtp_integrity),		      TAG_END()),       9);  TEST(af, SOA_AF_ANY);  TEST(address, 0);  TEST(hold, 0);  TEST(rtp_select, SOA_RTP_SELECT_SINGLE);  TEST(rtp_sort, SOA_RTP_SORT_DEFAULT);  TEST(rtp_mismatch, 0);  TEST(srtp_enable, 0);  TEST(srtp_confidentiality, 0);  TEST(srtp_integrity, 0);  TEST(soa_set_params(a,		      SOATAG_AF(SOA_AF_IP4_IP6),		      SOATAG_ADDRESS("127.0.0.1"),		      SOATAG_HOLD("audio"),		      SOATAG_RTP_SELECT(SOA_RTP_SELECT_ALL),		      SOATAG_RTP_SORT(SOA_RTP_SORT_LOCAL),		      SOATAG_RTP_MISMATCH(1),		      SOATAG_SRTP_ENABLE(1),		      SOATAG_SRTP_CONFIDENTIALITY(1),		      SOATAG_SRTP_INTEGRITY(1),		      TAG_END()),       9);  TEST(soa_get_params(a,		      SOATAG_AF_REF(af),		      SOATAG_ADDRESS_REF(address),		      SOATAG_HOLD_REF(hold),		      SOATAG_RTP_SELECT_REF(rtp_select),		      SOATAG_RTP_SORT_REF(rtp_sort),		      SOATAG_RTP_MISMATCH_REF(rtp_mismatch),		      SOATAG_SRTP_ENABLE_REF(srtp_enable),		      SOATAG_SRTP_CONFIDENTIALITY_REF(srtp_confidentiality),		      SOATAG_SRTP_INTEGRITY_REF(srtp_integrity),		      TAG_END()),       9);  TEST(af, SOA_AF_IP4_IP6);  TEST_S(address, "127.0.0.1");  TEST_S(hold, "audio");  TEST(rtp_select, SOA_RTP_SELECT_ALL);  TEST(rtp_sort, SOA_RTP_SORT_LOCAL);  TEST(rtp_mismatch, 1);  TEST(srtp_enable, 1);  TEST(srtp_confidentiality, 1);  TEST(srtp_integrity, 1);  /* Restore defaults */  TEST(soa_set_params(a,		      SOATAG_AF(SOA_AF_IP4_IP6),		      SOATAG_ADDRESS(NULL),		      SOATAG_HOLD(NULL),		      SOATAG_RTP_SELECT(SOA_RTP_SELECT_SINGLE),		      SOATAG_RTP_SORT(SOA_RTP_SORT_DEFAULT),		      SOATAG_RTP_MISMATCH(0),		      SOATAG_SRTP_ENABLE(0),		      SOATAG_SRTP_CONFIDENTIALITY(0),		      SOATAG_SRTP_INTEGRITY(0),		      TAG_END()),       9);  END();}int test_completed(struct context *ctx, soa_session_t *session){  ctx->completed = session;  su_root_break(ctx->root);  return 0;}int test_static_offer_answer(struct context *ctx){  BEGIN();  int n;    soa_session_t *a, *b;  char const *caps = NONE, *offer = NONE, *answer = NONE;  int capslen = -1, offerlen = -1, answerlen = -1;  su_home_t home[1] = { SU_HOME_INIT(home) };  char const a_caps[] =     "v=0\r\n"    "o=left 219498671 2 IN IP4 127.0.0.2\r\n"    "c=IN IP4 127.0.0.2\r\n"    "m=audio 0 RTP/AVP 0 8\r\n";  char const b_caps[] =     "m=audio 5004 RTP/AVP 96 8\n"    "m=rtpmap:96 GSM/8000\n";  TEST(soa_set_capability_sdp(ctx->a, 0, "m=audio 0 RTP/AVP 0 8", -1),        1);  TEST(soa_set_capability_sdp(ctx->a, 0, a_caps, strlen(a_caps)),        1);  TEST(soa_get_capability_sdp(ctx->a, NULL, &caps, &capslen), 1);  TEST_1(caps != NULL && caps != NONE);  TEST_1(capslen > 0);  TEST(soa_set_user_sdp(ctx->b, 0, b_caps, strlen(b_caps)), 1);  TEST(soa_get_capability_sdp(ctx->a, NULL, &caps, &capslen), 1);  TEST_1(a = soa_clone(ctx->a, ctx->root, ctx));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -