From be37eea41283e6362d4bc4ff1d58d6c692cc516b Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Tue, 26 Nov 2019 14:20:52 +0000 Subject: [PATCH] [unit-tests] add basic RTP unit-test --- tests/unit/Makefile.am | 2 +- tests/unit/switch_rtp.c | 59 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 tests/unit/switch_rtp.c diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index f3e9a7d234..2b5f953997 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -1,7 +1,7 @@ include $(top_srcdir)/build/modmake.rulesam noinst_PROGRAMS = switch_event switch_hash switch_ivr_originate switch_utils switch_core switch_console switch_vpx switch_core_file \ - switch_ivr_play_say switch_core_codec + switch_ivr_play_say switch_core_codec switch_rtp noinst_PROGRAMS+= switch_core_video AM_LDFLAGS = -avoid-version -no-undefined $(SWITCH_AM_LDFLAGS) $(openssl_LIBS) AM_LDFLAGS += $(FREESWITCH_LIBS) $(switch_builddir)/libfreeswitch.la $(CORE_LIBS) $(APR_LIBS) diff --git a/tests/unit/switch_rtp.c b/tests/unit/switch_rtp.c new file mode 100644 index 0000000000..8c41764eba --- /dev/null +++ b/tests/unit/switch_rtp.c @@ -0,0 +1,59 @@ + +#include +#include + +static const char *rx_host = "127.0.0.1"; +static switch_port_t rx_port = 12346; +static const char *tx_host = "127.0.0.1"; +static switch_port_t tx_port = 54320; +static switch_memory_pool_t *pool = NULL; +static switch_rtp_t *rtp_session = NULL; +static switch_rtp_flag_t flags[SWITCH_RTP_FLAG_INVALID] = {0}; +const char *err = NULL; +static const switch_payload_t TEST_PT = 8; +switch_rtp_packet_t rtp_packet; +switch_frame_flag_t *frame_flags; +switch_io_flag_t io_flags; +switch_payload_t read_pt; +uint datalen; + +FST_CORE_BEGIN("./conf") +{ +FST_SUITE_BEGIN(switch_rtp) +{ +FST_SETUP_BEGIN() +{ +} +FST_SETUP_END() + +FST_TEARDOWN_BEGIN() +{ +} +FST_TEARDOWN_END() + +FST_TEST_BEGIN(test_rtp) +{ + switch_core_new_memory_pool(&pool); + + rtp_session = switch_rtp_new(rx_host, rx_port, tx_host, tx_port, TEST_PT, 8000, 20 * 1000, flags, "soft", &err, pool, 0, 0); + fst_xcheck(rtp_session != NULL, "get RTP session"); + fst_requires(rtp_session); + fst_requires(switch_rtp_ready(rtp_session)); + switch_rtp_activate_rtcp(rtp_session, 5, rx_port + 1, 0); + switch_rtp_set_default_payload(rtp_session, TEST_PT); + fst_xcheck(switch_rtp_get_default_payload(rtp_session) == TEST_PT, "get Payload Type") + switch_rtp_set_ssrc(rtp_session, 0xabcd); + switch_rtp_set_remote_ssrc(rtp_session, 0xcdef); + fst_xcheck(switch_rtp_get_ssrc(rtp_session) == 0xabcd, "get SSRC"); + switch_rtp_stats_t *stats = switch_rtp_get_stats(rtp_session, pool); + fst_requires(stats); + switch_rtp_destroy(&rtp_session); + + switch_core_destroy_memory_pool(&pool); +} +FST_TEST_END() +} +FST_SUITE_END() +} +FST_CORE_END() +