From 774e2789774dcb35f7e9e4cfa41632e13e2ac09e Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Wed, 4 Dec 2013 14:04:33 +0100 Subject: Modernise autotools files. Convert all tests to cppunit. --- .gitignore | 8 -- autogen.sh | 73 +---------- configure.ac | 86 +++++++++++++ configure.in | 74 ----------- test/.gitignore | 8 ++ test/Makefile | 36 ------ test/Makefile.am | 34 +++++ test/test.cc | 15 ++- test/test_amrwb.cc | 185 ++++++++++++++------------- test/test_asc2bin.cc | 37 +++++- test/test_connectivity.cc | 122 ------------------ test/test_init.cc | 48 +++---- test/test_opus.cc | 309 +++++++++++++++++++++++----------------------- test/test_raw.cc | 138 +++++++++++++++++++++ test/test_rtp.cc | 121 +++++++++--------- test/test_srtp.cc | 83 +++++++------ 16 files changed, 696 insertions(+), 681 deletions(-) create mode 100644 configure.ac delete mode 100644 configure.in create mode 100644 test/.gitignore delete mode 100644 test/Makefile create mode 100644 test/Makefile.am delete mode 100644 test/test_connectivity.cc create mode 100644 test/test_raw.cc diff --git a/.gitignore b/.gitignore index b22fc36..cfcbe17 100644 --- a/.gitignore +++ b/.gitignore @@ -22,11 +22,3 @@ Makefile.in *.lo *.o lrtp.pc -test_amrwb -test_connectivity -test_init -test_opus -test_raw -test_rtp -test_srtp -test_asc2bin \ No newline at end of file diff --git a/autogen.sh b/autogen.sh index 3e7a88f..298a369 100755 --- a/autogen.sh +++ b/autogen.sh @@ -1,71 +1,2 @@ -#!/bin/sh -# Run this to generate all the initial makefiles, etc. -# This was lifted from the Gimp, and adapted slightly by -# Raph Levien, slightly hacked for xine by Daniel Caujolle-Bert. - -DIE=0 - -PROG=lrtp - -# Check how echo works in this /bin/sh -case `echo -n` in --n) _echo_n= _echo_c='\c';; -*) _echo_n=-n _echo_c=;; -esac - - -(autoconf --version) < /dev/null > /dev/null 2>&1 || { - echo - echo "You must have autoconf installed to compile $PROG." - echo "Download the appropriate package for your distribution," - echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/" - DIE=1 -} - -(libtool --version) < /dev/null > /dev/null 2>&1 || { - echo - echo "You must have libtool installed to compile $PROG." - echo "Get ftp://ftp.gnu.org/pub/gnu/libtool-1.4.tar.gz" - echo "(or a newer version if it is available)" - DIE=1 -} - -(automake --version) < /dev/null > /dev/null 2>&1 || { - echo - echo "You must have automake installed to compile $PROG." - echo "Get ftp://ftp.gnu.org/pub/gnu/automake-1.3.tar.gz" - echo "(or a newer version if it is available)" - DIE=1 -} - -(aclocal --version) < /dev/null > /dev/null 2>&1 || { - echo - echo "**Error**: Missing aclocal. The version of automake" - echo "installed doesn't appear recent enough." - echo "Get ftp://ftp.gnu.org/pub/gnu/automake-1.3.tar.gz" - echo "(or a newer version if it is available)" - DIE=1 -} - -if [ "$DIE" -eq 1 ]; then - exit 1 -fi - -aclocalinclude="$ACLOCAL_FLAGS"; \ -(echo $_echo_n " + Running aclocal: $_echo_c"; \ - aclocal $aclocalinclude; \ - echo "done.") && \ -(echo $_echo_n " + Running libtoolize: $_echo_c"; \ - libtoolize --force --copy >/dev/null 2>&1; \ - echo "done.") && \ -(echo $_echo_n " + Running autoheader: $_echo_c"; \ - autoheader; \ - echo "done.") && \ -(echo $_echo_n " + Running automake: $_echo_c"; \ - automake --gnu --add-missing --copy; \ - echo "done.") && \ -(echo $_echo_n " + Running autoconf: $_echo_c"; \ - autoconf; \ - echo "done.") - -rm -f config.cache +#!/bin/sh -e +${AUTORECONF:-autoreconf} -fiv diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..52c6481 --- /dev/null +++ b/configure.ac @@ -0,0 +1,86 @@ +# Filename: configure.in + +AC_INIT([lrtp], [0.0.1]) +AC_CONFIG_SRCDIR([src/lrtp.cc]) +AM_INIT_AUTOMAKE + +dnl ====================== +dnl Compile with debug options +dnl ====================== +AC_ARG_WITH(debug, + [ --with-debug build with debug support (default=no)], + [], + [with_debug=no]) +if test x$with_debug == xyes; then + AC_MSG_WARN([*** Building with debug support!]) + AC_DEFINE_UNQUOTED(WITH_DEBUG, , [The project is configured to use debug output]) + CXXFLAGS="$CXXFLAGS -D_FORTIFY_SOURCE=2 -fstack-protector -Wall -Werror -g -O0" +fi + +dnl ====================== +dnl Init pkg-config +dnl ====================== +PKG_PROG_PKG_CONFIG(0.23) + +dnl ====================== +dnl Compile with encryption +dnl ====================== +AC_ARG_WITH(crypto, + [ --with-crypto build with crypto support (default=yes)], + [], + [with_crypto=yes]) +if test x$with_crypto == xyes; then + AC_MSG_WARN([*** Building with crypto support!]) + CXXFLAGS="$CXXFLAGS -DUSE_CRYPTO" +fi + +dnl ====================== +dnl Check if tests should be built. +dnl ====================== +AC_ARG_WITH(test, + [ --with-test build tests (default=no)], + [], + [with_test=no]) +if test x$with_test == xyes; then + AM_PATH_CPPUNIT(1.9.6) +fi + +dnl ====================== +dnl Check for srtp library +dnl ====================== +tmp_CXXFLAGS="$CXXFLAGS" +tmp_CPPFLAGS="$CPPFLAGS" +tmp_CFLAGS="$CFLAGS" +tmp_LDFLAGS="$LDFLAGS" +tmp_LIBS="$LIBS" +CXXFLAGS="" +CPPFLAGS="" +CFLAGS="" +LDFLAGS="" +LIBS="" +AC_CHECK_HEADER(srtp/srtp.h, , AC_MSG_ERROR([*** srtp header file not found!])) +AC_CHECK_LIB(srtp, srtp_init, , AC_MSG_ERROR([*** srtp library not found!])) +SRTP_CFLAGS="$CXXFLAGS $CPPFLAGS $CFLAGS" +SRTP_LIBS="$LDFLAGS $LIBS" +CXXFLAGS="$tmp_CXXFLAGS" +CPPFLAGS="$tmp_CPPFLAGS" +CFLAGS="$tmp_CFLAGS" +LDFLAGS="$tmp_LDFLAGS" +LIBS="$tmp_LIBS" +AC_SUBST(SRTP_CFLAGS) +AC_SUBST(SRTP_LIBS) + +AC_PROG_CXX + +AC_PROG_LIBTOOL +AM_PROG_LIBTOOL + +AM_CONFIG_HEADER(config.h) +AC_STDC_HEADERS + +AC_OUTPUT( + Makefile + src/Makefile + test/Makefile + lrtp.pc) + diff --git a/configure.in b/configure.in deleted file mode 100644 index 537aa37..0000000 --- a/configure.in +++ /dev/null @@ -1,74 +0,0 @@ -# Filename: configure.in - -AC_INIT([lrtp], [0.0.1]) -AC_CONFIG_SRCDIR([src/lrtp.cc]) -AM_INIT_AUTOMAKE - -dnl ====================== -dnl Compile with debug options -dnl ====================== -AC_ARG_WITH(debug, - [ --with-debug build with debug support (default=no)], - [], - [with_debug=no]) -if test x$with_debug == xyes; then - AC_MSG_WARN([*** Building with debug support!]) - AC_DEFINE_UNQUOTED(WITH_DEBUG, , [The project is configured to use debug output]) - CXXFLAGS="$CXXFLAGS -D_FORTIFY_SOURCE=2 -fstack-protector -Wall -Werror -g -O0" -fi - -dnl ====================== -dnl Init pkg-config -dnl ====================== -PKG_PROG_PKG_CONFIG(0.23) - -dnl ====================== -dnl Compile with encryption -dnl ====================== -AC_ARG_WITH(crypto, - [ --with-crypto build with crypto support (default=yes)], - [], - [with_crypto=yes]) -if test x$with_crypto == xyes; then - AC_MSG_WARN([*** Building with crypto support!]) - CXXFLAGS="$CXXFLAGS -DUSE_CRYPTO" -fi - -dnl ====================== -dnl Check for srtp library -dnl ====================== -tmp_CXXFLAGS="$CXXFLAGS" -tmp_CPPFLAGS="$CPPFLAGS" -tmp_CFLAGS="$CFLAGS" -tmp_LDFLAGS="$LDFLAGS" -tmp_LIBS="$LIBS" -CXXFLAGS="" -CPPFLAGS="" -CFLAGS="" -LDFLAGS="" -LIBS="" -AC_CHECK_HEADER(srtp/srtp.h, , AC_MSG_ERROR([*** srtp header file not found!])) -AC_CHECK_LIB(srtp, srtp_init, , AC_MSG_ERROR([*** srtp library not found!])) -SRTP_CFLAGS="$CXXFLAGS $CPPFLAGS $CFLAGS" -SRTP_LIBS="$LDFLAGS $LIBS" -CXXFLAGS="$tmp_CXXFLAGS" -CPPFLAGS="$tmp_CPPFLAGS" -CFLAGS="$tmp_CFLAGS" -LDFLAGS="$tmp_LDFLAGS" -LIBS="$tmp_LIBS" -AC_SUBST(SRTP_CFLAGS) -AC_SUBST(SRTP_LIBS) - -AC_PROG_CXX - -AC_PROG_LIBTOOL -AM_PROG_LIBTOOL - -AM_CONFIG_HEADER(config.h) -AC_STDC_HEADERS - -AC_OUTPUT( - Makefile - src/Makefile - lrtp.pc) - diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 0000000..ee4d4d1 --- /dev/null +++ b/test/.gitignore @@ -0,0 +1,8 @@ +result_*.xml +amrwb +asc2bin +opus +raw +init +rtp +srtp \ No newline at end of file diff --git a/test/Makefile b/test/Makefile deleted file mode 100644 index 82fc79f..0000000 --- a/test/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -CFLAGS=`cppunit-config --cflags` -LIBS=`cppunit-config --libs` - -all: connectivity amrwb init rtp srtp opus raw - -connectivity: - g++ -g test_$@.cc -L../src/.libs -llrtp -I../src -o test_$@ - LD_LIBRARY_PATH=../src/.libs ./test_$@ - -amrwb: - g++ -g test_$@.cc -L../src/.libs -llrtp -lm -I../src -o test_$@ - LD_LIBRARY_PATH=../src/.libs ./test_$@ - -opus: - g++ -g test_$@.cc -L../src/.libs -llrtp -lm -I../src -lopus -lao -o test_$@ - LD_LIBRARY_PATH=../src/.libs ./test_$@ - -init: - g++ -g test_$@.cc -L../src/.libs -llrtp -I../src -o test_$@ - LD_LIBRARY_PATH=../src/.libs ./test_$@ - -raw: - g++ -g test_$@.cc -L../src/.libs -llrtp -I../src -o test_$@ - LD_LIBRARY_PATH=../src/.libs ./test_$@ - -rtp: - g++ -g test_$@.cc ../src/rtp.cc -o test_$@ - ./test_$@ - -srtp: - g++ -g -DUSE_CRYPTO test_$@.cc ../src/rtp.cc ../src/srtp.cc ../src/asc2bin.cc -lsrtp -o test_$@ - ./test_$@ - -asc2bin: - g++ ${CFLAGS} ${LIBS} -g test.cc test_$@.cc -o test_$@ - ./test_$@ diff --git a/test/Makefile.am b/test/Makefile.am new file mode 100644 index 0000000..e5c60bf --- /dev/null +++ b/test/Makefile.am @@ -0,0 +1,34 @@ +TESTS = amrwb opus init rtp srtp raw asc2bin + +check_PROGRAMS = $(TESTS) + +amrwb_CXXFLAGS = $(CPPUNIT_CFLAGS) -DOUTPUT=\"amrwb\" -I../src +amrwb_LDFLAGS = $(CPPUNIT_LIBS) -L../src/.libs/ -llrtp +amrwb_SOURCES = test.cc test_amrwb.cc + +opus_CXXFLAGS = $(CPPUNIT_CFLAGS) -DOUTPUT=\"opus\" -I../src +opus_LDFLAGS = $(CPPUNIT_LIBS) -L../src/.libs/ -llrtp -lopus -lao +opus_SOURCES = test.cc test_opus.cc + +init_CXXFLAGS = $(CPPUNIT_CFLAGS) -DOUTPUT=\"init\" -I../src +init_LDFLAGS = $(CPPUNIT_LIBS) -L../src/.libs/ -llrtp +init_SOURCES = test.cc test_init.cc + +rtp_CXXFLAGS = $(CPPUNIT_CFLAGS) -DOUTPUT=\"rtp\" -I../src +rtp_LDFLAGS = $(CPPUNIT_LIBS) -L../src/.libs/ -llrtp +rtp_SOURCES = test.cc test_rtp.cc + +srtp_CXXFLAGS = $(CPPUNIT_CFLAGS) -DOUTPUT=\"srtp\" -I../src +srtp_LDFLAGS = $(CPPUNIT_LIBS) -L../src/.libs/ -llrtp +srtp_SOURCES = test.cc test_srtp.cc + +raw_CXXFLAGS = $(CPPUNIT_CFLAGS) -DOUTPUT=\"raw\" -I../src +raw_LDFLAGS = $(CPPUNIT_LIBS) -L../src/.libs/ -llrtp +raw_SOURCES = test.cc test_raw.cc + +asc2bin_CXXFLAGS = $(CPPUNIT_CFLAGS) -DOUTPUT=\"asc2bin\" -I../src +asc2bin_LDFLAGS = $(CPPUNIT_LIBS) +asc2bin_SOURCES = test.cc test_asc2bin.cc + +clean-local: + -rm -f result_*.xml diff --git a/test/test.cc b/test/test.cc index 171a578..7830e2c 100644 --- a/test/test.cc +++ b/test/test.cc @@ -1,7 +1,11 @@ -#include +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +//#include +#include #include #include +#include + int main(int argc, char* argv[]) { // Get the top level suite from the registry @@ -11,12 +15,15 @@ int main(int argc, char* argv[]) CppUnit::TextUi::TestRunner runner; runner.addTest( suite ); - // Change the default outputter to a compiler error format outputter - runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), - std::cerr ) ); + std::ofstream myfile; + myfile.open("result_"OUTPUT".xml"); + runner.setOutputter(new CppUnit::XmlOutputter(&runner.result(), myfile)); + // Run the tests. bool wasSucessful = runner.run(); + myfile.close(); + // Return error code 1 if the one of test failed. return wasSucessful ? 0 : 1; } diff --git a/test/test_amrwb.cc b/test/test_amrwb.cc index cf5a5a6..adefda1 100644 --- a/test/test_amrwb.cc +++ b/test/test_amrwb.cc @@ -25,6 +25,8 @@ * License along with lrtp; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + #include #include @@ -32,31 +34,11 @@ #include #include -#include -#include -#include -#include - #define KEY "123456789012345678901234567890123456789012345678901234567890" #define SSRC 1234567890 -#define FS 8000 - -#define F1 440 -#define AF1 0.3 - -#define F2 500 -#define AF2 0.7 - -void dump(const char *title, const char *buf, size_t size) -{ - printf("%12s: ", title); - for(int i = 0; i < size; i++) { - if(i % 8 == 0) printf(" "); - printf("%02x ", (unsigned char)*buf++); - } - printf("\n"); -} +#define PKG_SIZE (16*1024) +#define NUM_PKGS 10 // Frame sizes based on frame type index: static const int wb_frame_size[16] = { @@ -64,92 +46,117 @@ static const int wb_frame_size[16] = { 60, 5, -1, -1, -1, -1, -1, 0 }; -int main() +class test_amrwb_class : public CppUnit::TestFixture { - std::vector packets; - unsigned int csrc = 42; + CPPUNIT_TEST_SUITE(test_amrwb_class); + CPPUNIT_TEST(test_amrwb_0); + CPPUNIT_TEST(test_amrwb_1); + CPPUNIT_TEST(test_amrwb_2); + CPPUNIT_TEST(test_amrwb_3); + CPPUNIT_TEST(test_amrwb_4); + CPPUNIT_TEST(test_amrwb_5); + CPPUNIT_TEST(test_amrwb_6); + CPPUNIT_TEST(test_amrwb_7); + CPPUNIT_TEST(test_amrwb_8); + CPPUNIT_TEST_SUITE_END(); + +public: + void setUp() {} + void tearDown() {} + + void test_amrwb(int frame_type_index) { + std::vector packets; + unsigned int csrc = 42; - int frame_type_index = 8; + int sent = 0; - printf("========== Encode ==========\n"); + size_t num_frames = NUM_PKGS; + size_t framesize = wb_frame_size[frame_type_index] * num_frames; - { // Encode - struct lrtp_t *lrtp = lrtp_init(KEY, SSRC); + { // Encode + struct lrtp_t *lrtp = lrtp_init(KEY, SSRC); - struct lrtp_profile_t *profile = - lrtp_create_profile(lrtp, PROFILE_AMRWB, csrc, - OPTION_AMRWB_FRAME_TYPE_INDEX, frame_type_index, - OPTION_END); + struct lrtp_profile_t *profile = + lrtp_create_profile(lrtp, PROFILE_AMRWB, csrc, + OPTION_AMRWB_FRAME_TYPE_INDEX, frame_type_index, + OPTION_END); - char packet[16*1024]; - size_t packetsize = sizeof(packet); + char packet[PKG_SIZE]; + size_t packetsize = sizeof(packet); - int cnt = 0; + char cnt = 0; - for(int i = 0; i < 10; i++) { + for(int i = 0; i < NUM_PKGS; i++) { + char frame[wb_frame_size[frame_type_index] * num_frames]; - size_t num_frames = 10; - char frame[wb_frame_size[frame_type_index] * num_frames]; - size_t framesize = wb_frame_size[frame_type_index] * num_frames; + for(int i = 0; i < framesize; i++) frame[i] = cnt++; - for(int i = 0; i < framesize; i++) frame[i] = cnt++; + int timestamp = 0; - int timestamp = 0; - - int ret = lrtp_enqueue_frame(profile, frame, framesize); - while( (ret = lrtp_pack(lrtp, packet, sizeof(packet))) != 0) { - std::string p; - p.append(packet, ret); - packets.push_back(p); + int ret = lrtp_enqueue_frame(profile, frame, framesize); + while( (ret = lrtp_pack(lrtp, packet, sizeof(packet))) != 0) { + std::string p; + p.append(packet, ret); + packets.push_back(p); + } } - } - - lrtp_destroy_profile(lrtp, csrc); - lrtp_close(lrtp); - } - printf("========== Decode ==========\n"); + lrtp_destroy_profile(lrtp, csrc); + lrtp_close(lrtp); + } - { // Decode - struct lrtp_t *lrtp = lrtp_init(KEY, SSRC); + { // Decode + struct lrtp_t *lrtp = lrtp_init(KEY, SSRC); - struct lrtp_profile_t *profile = - lrtp_create_profile(lrtp, PROFILE_AMRWB, csrc, - OPTION_AMRWB_FRAME_TYPE_INDEX, frame_type_index, - OPTION_END); + struct lrtp_profile_t *profile = + lrtp_create_profile(lrtp, PROFILE_AMRWB, csrc, + OPTION_AMRWB_FRAME_TYPE_INDEX, frame_type_index, + OPTION_END); - char frame[16*1024]; - size_t framesize = sizeof(frame); + char frame[16*1024]; - int cnt = 0; - - std::vector::iterator i = packets.begin(); - while(i != packets.end()) { - size_t packetsize = i->size(); - printf("unpack sz: %d\n", packetsize); - const char *packet = i->data(); - unsigned int ts; - - framesize = sizeof(frame); - - lrtp_unpack(lrtp, packet, packetsize); - int ret; - while((ret = lrtp_dequeue_frame(lrtp, frame, framesize, &csrc, &ts)) != 0) { - printf("Got %d bytes, csrc %d, ts: %d\n", ret, csrc, ts); - - printf("cnt:\n"); - for(int i = 0; i < ret; i++) { - printf("%02x ", (unsigned char)frame[i]); + char cnt = 0; + int total = 0; + + std::vector::iterator i = packets.begin(); + while(i != packets.end()) { + size_t packetsize = i->size(); + const char *packet = i->data(); + unsigned int ts; + + lrtp_unpack(lrtp, packet, packetsize); + int ret; + while((ret = lrtp_dequeue_frame(lrtp, frame, sizeof(frame), &csrc, &ts)) + != 0) { + int err = 0; + for(int i = 0; i < ret; i++) { + err += abs(frame[i] - cnt); + cnt++; + total++; + } + CPPUNIT_ASSERT_EQUAL(0, err); } - printf("\n"); + + i++; } - i++; - } + CPPUNIT_ASSERT_EQUAL((int)(framesize * NUM_PKGS), total); - lrtp_destroy_profile(lrtp, csrc); - lrtp_close(lrtp); - } + lrtp_destroy_profile(lrtp, csrc); + lrtp_close(lrtp); + } + } + + void test_amrwb_0() { test_amrwb(0); } + void test_amrwb_1() { test_amrwb(1); } + void test_amrwb_2() { test_amrwb(2); } + void test_amrwb_3() { test_amrwb(3); } + void test_amrwb_4() { test_amrwb(4); } + void test_amrwb_5() { test_amrwb(5); } + void test_amrwb_6() { test_amrwb(6); } + void test_amrwb_7() { test_amrwb(7); } + void test_amrwb_8() { test_amrwb(8); } +}; - return 0; -} +// Registers the fixture into the 'registry' +CPPUNIT_TEST_SUITE_REGISTRATION(test_amrwb_class); diff --git a/test/test_asc2bin.cc b/test/test_asc2bin.cc index 38010bf..1663c70 100644 --- a/test/test_asc2bin.cc +++ b/test/test_asc2bin.cc @@ -1,3 +1,30 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set et sw=2 ts=2: */ +/*************************************************************************** + * test_asc2bin.cc + * + * Mon Sep 2 14:02:16 CEST 2013 + * Copyright 2013 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of lrtp. + * + * lrtp 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. + * + * lrtp 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 lrtp; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ #include #include "../src/asc2bin.h" @@ -5,11 +32,11 @@ static int g_i = -1; -class test_asc2bin : public CppUnit::TestFixture +class test_asc2bin_class : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(test_asc2bin); + CPPUNIT_TEST_SUITE(test_asc2bin_class); CPPUNIT_TEST(test_asc2nibble); - CPPUNIT_TEST(test_asc2bin_); + CPPUNIT_TEST(test_asc2bin); CPPUNIT_TEST_SUITE_END(); public: @@ -42,7 +69,7 @@ public: CPPUNIT_ASSERT_EQUAL(asc2nibble('F'), 0xf); } - void test_asc2bin_() { + void test_asc2bin() { char val[32] = {}; const char h[] = "0123456789abcdefABCDEF0000000000"; char ref[] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, @@ -62,4 +89,4 @@ public: }; // Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION(test_asc2bin); +CPPUNIT_TEST_SUITE_REGISTRATION(test_asc2bin_class); diff --git a/test/test_connectivity.cc b/test/test_connectivity.cc deleted file mode 100644 index e115748..0000000 --- a/test/test_connectivity.cc +++ /dev/null @@ -1,122 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set et sw=2 ts=2: */ -/*************************************************************************** - * test_init.cc - * - * Mon Sep 2 14:02:16 CEST 2013 - * Copyright 2013 Bent Bisballe Nyeng - * deva@aasimon.org - ****************************************************************************/ - -/* - * This file is part of lrtp. - * - * lrtp 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. - * - * lrtp 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 lrtp; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -#include - -#include - -#include -#include - -#define KEY "123456789012345678901234567890123456789012345678901234567890" -#define SSRC 1234567890 - -void dump(const char *title, const char *buf, size_t size) -{ - printf("%12s: ", title); - for(int i = 0; i < size; i++) { - if(i % 8 == 0) printf(" "); - printf("%02x ", (unsigned char)*buf++); - } - printf("\n"); -} - -int main() -{ - char frame[5]; - int pkg_size = 4; - - std::vector packets; - unsigned int csrc = 42; - - { // Encode - struct lrtp_t *lrtp = lrtp_init(KEY, SSRC); - - struct lrtp_profile_t *profile = - lrtp_create_profile(lrtp, PROFILE_RAW, csrc, - OPTION_RAW_PKG_SIZE, pkg_size, - OPTION_END); - - char packet[16*1024]; - size_t size = sizeof(packet); - - for(unsigned int ts = 0; ts < 8; ts++) { - int ret = 0; - ret = lrtp_enqueue_frame(profile, frame, sizeof(frame)); - while( (ret = lrtp_pack(lrtp, packet, sizeof(packet))) != 0) { - std::string p; - p.append(packet, ret); - packets.push_back(p); - dump("pkg", packet, ret); - } - } - - lrtp_destroy_profile(lrtp, csrc); - - lrtp_close(lrtp); - } - - { // Decode - struct lrtp_t *lrtp = lrtp_init(KEY, SSRC); - - struct lrtp_profile_t *profile = - lrtp_create_profile(lrtp, PROFILE_RAW, csrc, - OPTION_RAW_PKG_SIZE, pkg_size, - OPTION_END); - - char frame[16*1024]; - size_t framesize = sizeof(frame); - - int cnt = 0; - - std::vector::iterator i = packets.begin(); - while(i != packets.end()) { - size_t packetsize = i->size(); - printf("unpack sz: %d\n", packetsize); - const char *packet = i->data(); - unsigned int ts; - - framesize = sizeof(frame); - - lrtp_unpack(lrtp, packet, packetsize); - int ret; - while((ret = lrtp_dequeue_frame(lrtp, frame, framesize, &csrc, &ts)) - != 0) { - printf("Got %d bytes, csrc %d, ts: %d\n", ret, csrc, ts); - dump("pkg", frame, ret); - } - - i++; - } - - lrtp_destroy_profile(lrtp, csrc); - lrtp_close(lrtp); - } - - return 0; -} - diff --git a/test/test_init.cc b/test/test_init.cc index 97ecd30..3281183 100644 --- a/test/test_init.cc +++ b/test/test_init.cc @@ -25,6 +25,8 @@ * License along with lrtp; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + #include #include @@ -32,32 +34,34 @@ #define KEY "123456789012345678901234567890123456789012345678901234567890" #define SSRC 1234567890 -void dump(const char *title, const char *buf, size_t size) -{ - printf("%12s: ", title); - for(int i = 0; i < size; i++) { - if(i % 8 == 0) printf(" "); - printf("%02x ", (unsigned char)*buf++); - } - printf("\n"); -} - -int main() +class test_init_class : public CppUnit::TestFixture { - char frame[] = "foo"; + CPPUNIT_TEST_SUITE(test_init_class); + CPPUNIT_TEST(test_init); + CPPUNIT_TEST_SUITE_END(); + +public: + void setUp() {} + void tearDown() {} + + void test_init() { + struct lrtp_t *lrtp = lrtp_init(KEY, SSRC); - struct lrtp_t *lrtp = lrtp_init(KEY, SSRC); + CPPUNIT_ASSERT(lrtp); - unsigned int csrc = 42; - struct lrtp_profile_t *profile = - lrtp_create_profile(lrtp, PROFILE_RAW, csrc, - OPTION_RAW_PKG_SIZE, sizeof(frame), - OPTION_END); + unsigned int csrc = 42; + struct lrtp_profile_t *profile = + lrtp_create_profile(lrtp, PROFILE_RAW, csrc, + OPTION_RAW_PKG_SIZE, 100, + OPTION_END); - lrtp_destroy_profile(lrtp, csrc); + CPPUNIT_ASSERT(profile); - lrtp_close(lrtp); + lrtp_destroy_profile(lrtp, csrc); - return 0; -} + lrtp_close(lrtp); + } +}; +// Registers the fixture into the 'registry' +CPPUNIT_TEST_SUITE_REGISTRATION(test_init_class); diff --git a/test/test_opus.cc b/test/test_opus.cc index 9e41a42..1d55d5a 100644 --- a/test/test_opus.cc +++ b/test/test_opus.cc @@ -25,6 +25,8 @@ * License along with lrtp; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + #include #include @@ -98,186 +100,189 @@ private: ao_device *device; }; -int main() +void get_samples(double x, short *r, short *l) { - size_t channels = 2; - size_t ms[] = { 120, 240, 480, 960, 1920, 2880 }; - - std::vector packets; - unsigned int csrc = 42; - - double sin_x = 0; - size_t ts = 0; - - printf("========== Encode ==========\n"); - - { // Encode - struct lrtp_t *lrtp = lrtp_init(KEY, SSRC); - - struct lrtp_profile_t *profile = - lrtp_create_profile(lrtp, PROFILE_OPUS, csrc, - //OPTION_RAW_PKG_SIZE, pkg_size, - OPTION_END); - - char packet[16*1024]; - size_t packetsize = sizeof(packet); - - int err; - OpusEncoder *opus = opus_encoder_create(FS, channels, - OPUS_APPLICATION_AUDIO, &err); - printf("Opus create err: %d\n", err); - - opus_encoder_ctl(opus, OPUS_SET_BITRATE(32000));// [500;512000] - opus_encoder_ctl(opus, OPUS_SET_COMPLEXITY(10)); // [0;10] - opus_encoder_ctl(opus, OPUS_SET_SIGNAL(OPUS_AUTO)); - //opus_encoder_ctl(opus, OPUS_SET_MAX_BANDWIDTH(OPUS_BANDWIDTH_NARROWBAND)); - - int cnt = 0; - size_t timestamp = 0; - size_t idx = 0; - for(unsigned int ts = 0; ts < FS / 10; ts++) { - printf("packet #%d\n", ts); - - printf("idx: %d\n", idx); - size_t pcmsize = ms[idx] / (48000.0 / FS); // Number of samples pr channel - short *pcm = new short[100000/*pcmsize * channels*/]; - for(int i = 0 ; i < pcmsize; i++) { - sin_x++; - - if((int)sin_x % FS == 0) { - idx++;// = rand() % (sizeof(ms)/sizeof(size_t)); - idx = idx % (sizeof(ms)/sizeof(size_t)); - } + double amp1 = sin((2 * M_PI / (double)FS)* x * AF1) * SHRT_MAX; + double amp2 = sin((2 * M_PI / (double)FS)* x * AF2) * SHRT_MAX; - double amp1 = sin((2*M_PI/(double)FS)*(double)sin_x * AF1) * SHRT_MAX; - double amp2 = sin((2*M_PI/(double)FS)*(double)sin_x * AF2) * SHRT_MAX; - - pcm[i*2] = (short)(sin(2*M_PI/FS*(double)sin_x * F1) * amp1); - pcm[i*2+1] = (short)(sin(2*M_PI/FS*(double)sin_x * F2) * amp2); - } - - // Master timestamp is sample number in 48kHz (Opus RFC states this) - timestamp += pcmsize * 48000 / FS; - - // size_t pcmsize = pcmsize * channels * sizeof(short); + *r = (short)(sin(2 * M_PI / FS * x * F1) * amp1); + *l = 0;//(short)(sin(2 * M_PI / FS * x * F2) * amp2); +} - char frame[pcmsize]; - int framesize = sizeof(frame); - framesize = opus_encode(opus, pcm, pcmsize, - (unsigned char*)frame, framesize); +class test_opus_class : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(test_opus_class); + CPPUNIT_TEST(test_opus); + CPPUNIT_TEST_SUITE_END(); - if(framesize < 0) { - printf("Opus error: %s\n", opus_strerror(framesize)); - } +public: + void setUp() {} + void tearDown() {} - printf("Opus Packet: %d bytes compressed to %d bytes\n", - channels * pcmsize * sizeof(short), framesize); + void test_opus() { + size_t channels = 2; + size_t ms[] = { 120, 240, 480, 960, 1920, 2880 }; - int ret = lrtp_enqueue_frame(profile, frame, framesize); - while( (ret = lrtp_pack(lrtp, packet, sizeof(packet))) != 0) { - std::string p; - p.append(packet, ret); - packets.push_back(p); - } + std::vector packets; + unsigned int csrc = 42; + + size_t ts = 0; - delete[] pcm; - } + int sent = 0; - opus_encoder_destroy(opus); - lrtp_destroy_profile(lrtp, csrc); - lrtp_close(lrtp); - } + { // Encode + struct lrtp_t *lrtp = lrtp_init(KEY, SSRC); - printf("========== Decode ==========\n"); + struct lrtp_profile_t *profile = + lrtp_create_profile(lrtp, PROFILE_OPUS, csrc, + //OPTION_RAW_PKG_SIZE, pkg_size, + OPTION_END); - { // Decode - struct lrtp_t *lrtp = lrtp_init(KEY, SSRC); - - struct lrtp_profile_t *profile = - lrtp_create_profile(lrtp, PROFILE_OPUS, csrc, - //OPTION_RAW_PKG_SIZE, pkg_size, - OPTION_END); + char packet[16*1024]; + size_t packetsize = sizeof(packet); + + int err; + OpusEncoder *opus = opus_encoder_create(FS, channels, + OPUS_APPLICATION_AUDIO, &err); + CPPUNIT_ASSERT_EQUAL(0, err); + + opus_encoder_ctl(opus, OPUS_SET_BITRATE(32000));// [500;512000] + opus_encoder_ctl(opus, OPUS_SET_COMPLEXITY(10)); // [0;10] + opus_encoder_ctl(opus, OPUS_SET_SIGNAL(OPUS_AUTO)); + //opus_encoder_ctl(opus, OPUS_SET_MAX_BANDWIDTH(OPUS_BANDWIDTH_NARROWBAND)); + + double sin_x = 0; + + int cnt = 0; + size_t timestamp = 0; + size_t idx = 0; + for(unsigned int ts = 0; ts < FS / 10; ts++) { + //printf("packet #%d\n", ts); + + //printf("idx: %d\n", idx); + size_t pcmsize = ms[idx] / (48000.0 / FS); // Number of samples pr channel + sent += pcmsize; + short *pcm = new short[100000/*pcmsize * channels*/]; + for(int i = 0 ; i < pcmsize; i++) { + sin_x++; + + if((int)sin_x % FS == 0) { + idx++;// = rand() % (sizeof(ms)/sizeof(size_t)); + idx = idx % (sizeof(ms)/sizeof(size_t)); + } + + get_samples(sin_x, &pcm[i*2], &pcm[i*2+1]); + } - int err; - OpusDecoder *opus = opus_decoder_create(FS, channels, &err); - printf("Opus create err: %d\n", err); + // Master timestamp is sample number in 48kHz (Opus RFC states this) + timestamp += pcmsize * 48000 / FS; - int idx = (sizeof(ms)/sizeof(size_t)) - 1; - printf("idx: %d\n", idx); + // size_t pcmsize = pcmsize * channels * sizeof(short); - Audio audio; + char frame[pcmsize]; + int framesize = sizeof(frame); + framesize = opus_encode(opus, pcm, pcmsize, + (unsigned char*)frame, framesize); - char frame[16*1024]; - - int cnt = 0; - std::vector::iterator i = packets.begin(); - while(i != packets.end()) { - size_t packetsize = i->size(); - const char *packet = i->data(); - unsigned int ts; - - // printf("unpack sz: %d - %p\n", packetsize, packet); - - lrtp_unpack(lrtp, packet, packetsize); - int n = 0; - int ret; - while((ret = lrtp_dequeue_frame(lrtp, frame, sizeof(frame), &csrc, &ts)) - != 0) { - size_t pcmsize = 16*1024;//ms[idx] / (48000 / FS); - short *pcm = new short[pcmsize * channels]; - //printf("pcmsize %d\n", pcmsize); fflush(stdout); - int res = opus_decode(opus, (const unsigned char*)frame, ret, - pcm, pcmsize, 0); - - // printf("Decompressed %d bytes\n", res); - n += res; - // pcmsize = res * channels * sizeof(short); - - audio.play((char *)pcm, res * channels * sizeof(short)); + if(framesize < 0) { + printf("Opus error: %s\n", opus_strerror(framesize)); + } + /* + printf("Opus Packet: %d bytes compressed to %d bytes\n", + channels * pcmsize * sizeof(short), framesize); + */ + int ret = lrtp_enqueue_frame(profile, frame, framesize); + while( (ret = lrtp_pack(lrtp, packet, sizeof(packet))) != 0) { + std::string p; + p.append(packet, ret); + packets.push_back(p); + } delete[] pcm; } - printf("ratio: %d => %d\n", packetsize, n * channels); - - i++; + opus_encoder_destroy(opus); + lrtp_destroy_profile(lrtp, csrc); + lrtp_close(lrtp); } + { // Decode + struct lrtp_t *lrtp = lrtp_init(KEY, SSRC); - /* + struct lrtp_profile_t *profile = + lrtp_create_profile(lrtp, PROFILE_OPUS, csrc, + //OPTION_RAW_PKG_SIZE, pkg_size, + OPTION_END); - std::vector::iterator i = packets.begin(); - while(i != packets.end()) { - size_t packetsize = i->size(); - printf("unpack sz: %d\n", packetsize); - const char *packet = i->data(); - unsigned int ts; + int err; + OpusDecoder *opus = opus_decoder_create(FS, channels, &err); + CPPUNIT_ASSERT_EQUAL(0, err); - framesize = sizeof(frame); + int idx = (sizeof(ms)/sizeof(size_t)) - 1; + //printf("idx: %d\n", idx); - lrtp_unpack(lrtp, packet, packetsize, frame, &framesize, &csrc, &ts); - printf("Got %d bytes, csrc %d, ts: %d\n", framesize, csrc, ts); + //Audio audio; - size_t pcmsize = 16*1024;//ms[idx] / (48000 / FS); - short *pcm = new short[pcmsize * channels]; - printf("pcmsize %d\n", pcmsize); fflush(stdout); - int res = opus_decode(opus, (const unsigned char*)frame, framesize, - pcm, pcmsize, 0); - framesize = sizeof(frame); + char frame[16*1024]; + + double sin_x = 0; + + int cnt = 0; + std::vector::iterator i = packets.begin(); + while(i != packets.end()) { + size_t packetsize = i->size(); + const char *packet = i->data(); + unsigned int ts; + + // printf("unpack sz: %d - %p\n", packetsize, packet); + + lrtp_unpack(lrtp, packet, packetsize); + int n = 0; + int ret; + while((ret = lrtp_dequeue_frame(lrtp, frame, sizeof(frame), &csrc, &ts)) + != 0) { + size_t pcmsize = 16*1024;//ms[idx] / (48000 / FS); + short *pcm = new short[pcmsize * channels]; + //printf("pcmsize %d\n", pcmsize); fflush(stdout); + int res = opus_decode(opus, (const unsigned char*)frame, ret, + pcm, pcmsize, 0); + + //printf("Decompressed %d samples\n", res); + n += res; + // pcmsize = res * channels * sizeof(short); + + int errl = 0; + int errr = 0; + for(int i = 0; i < res; i++) { + short left; + short right; + get_samples(sin_x, &left, &right); + //printf("%d\t%d\n", left, pcm[2 * i]); + //printf("%d\t%d\n", right, pcm[2 * i + 1]); + errl += abs(left - pcm[2 * i]); + errr += abs(right - pcm[2 * i + 1]); + sin_x++; + } + //printf("err: %d\t%d\n", errl, errr); + // CPPUNIT_ASSERT_EQUAL(0, errl / (res * 40000)); + // CPPUNIT_ASSERT_EQUAL(0, errr / (res * 40000)); + //audio.play((char *)pcm, res * channels * sizeof(short)); + + delete[] pcm; + } - printf("Decompressed %d bytes\n", res); - // pcmsize = res * channels * sizeof(short); + i++; + } - audio.play((char *)pcm, res * channels * sizeof(short)); + CPPUNIT_ASSERT(sent); // Fail if no data was sent. + CPPUNIT_ASSERT_EQUAL(sent, (int)sin_x); - delete[] pcm; - i++; + opus_decoder_destroy(opus); + lrtp_destroy_profile(lrtp, csrc); + lrtp_close(lrtp); } - */ - opus_decoder_destroy(opus); - lrtp_destroy_profile(lrtp, csrc); - lrtp_close(lrtp); } +}; - return 0; -} +// Registers the fixture into the 'registry' +CPPUNIT_TEST_SUITE_REGISTRATION(test_opus_class); diff --git a/test/test_raw.cc b/test/test_raw.cc new file mode 100644 index 0000000..d3910d3 --- /dev/null +++ b/test/test_raw.cc @@ -0,0 +1,138 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set et sw=2 ts=2: */ +/*************************************************************************** + * test_init.cc + * + * Mon Sep 2 14:02:16 CEST 2013 + * Copyright 2013 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of lrtp. + * + * lrtp 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. + * + * lrtp 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 lrtp; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include + +#include + +#include + +#include +#include + +#define KEY "123456789012345678901234567890123456789012345678901234567890" +#define SSRC 1234567890 + +class test_conn_class : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(test_conn_class); + CPPUNIT_TEST(test_raw); + CPPUNIT_TEST_SUITE_END(); + +public: + void setUp() {} + void tearDown() {} + + void test_raw() { + char frame[5]; + int pkg_size = 4; + + std::vector packets; + unsigned int csrc = 42; + + { // Encode + struct lrtp_t *lrtp = lrtp_init(KEY, SSRC); + + struct lrtp_profile_t *profile = + lrtp_create_profile(lrtp, PROFILE_RAW, csrc, + OPTION_RAW_PKG_SIZE, pkg_size, + OPTION_END); + + char num = 0; + + char packet[16*1024]; + size_t size = sizeof(packet); + + for(unsigned int ts = 0; ts < 8; ts++) { + + for(int i = 0; i < sizeof(frame); i++) frame[i] = num++; + + int ret = 0; + ret = lrtp_enqueue_frame(profile, frame, sizeof(frame)); + while( (ret = lrtp_pack(lrtp, packet, sizeof(packet))) != 0) { + std::string p; + p.append(packet, ret); + packets.push_back(p); + //dump("pkg", packet, ret); + } + } + + lrtp_destroy_profile(lrtp, csrc); + + lrtp_close(lrtp); + } + + { // Decode + struct lrtp_t *lrtp = lrtp_init(KEY, SSRC); + + struct lrtp_profile_t *profile = + lrtp_create_profile(lrtp, PROFILE_RAW, csrc, + OPTION_RAW_PKG_SIZE, pkg_size, + OPTION_END); + + char frame[16*1024]; + size_t framesize = sizeof(frame); + + int cnt = 0; + + char num = 0; + + std::vector::iterator i = packets.begin(); + while(i != packets.end()) { + size_t packetsize = i->size(); + // printf("unpack sz: %d\n", packetsize); + const char *packet = i->data(); + unsigned int ts; + + framesize = sizeof(frame); + + lrtp_unpack(lrtp, packet, packetsize); + int ret; + while((ret = lrtp_dequeue_frame(lrtp, frame, framesize, &csrc, &ts)) + != 0) { + //printf("Got %d bytes, csrc %d, ts: %d\n", ret, csrc, ts); + + int err = 0; + for(int i = 0; i < ret; i++) { + err += abs(frame[i] - num++); + } + CPPUNIT_ASSERT_EQUAL(0, err); + + //dump("pkg", frame, ret); + } + + i++; + } + + lrtp_destroy_profile(lrtp, csrc); + lrtp_close(lrtp); + } + } +}; + +// Registers the fixture into the 'registry' +CPPUNIT_TEST_SUITE_REGISTRATION(test_conn_class); diff --git a/test/test_rtp.cc b/test/test_rtp.cc index b3ef80d..489cd42 100644 --- a/test/test_rtp.cc +++ b/test/test_rtp.cc @@ -25,88 +25,93 @@ * License along with lrtp; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "../src/rtp.h" +#include -#include +#include "../src/rtp.h" -void dump(RTP &rtp, const char *title) +class test_rtp_class : public CppUnit::TestFixture { - char buf[16 * 1024]; + CPPUNIT_TEST_SUITE(test_rtp_class); + CPPUNIT_TEST(test_rtp); + CPPUNIT_TEST_SUITE_END(); - unsigned char *p = (unsigned char *)buf; - size_t s = rtp.packet(buf, sizeof(buf)); +public: + void setUp() {} + void tearDown() {} - printf("%12s: ", title); - for(int i = 0; i < s; i++) { - if(i % 8 == 0) printf(" "); - printf("%02x ", *p++); - } - printf("\n"); -} + void test_rtp() { + RTP rtp; + //dump(rtp, "Clean"); -int main() -{ - RTP rtp; - dump(rtp, "Clean"); + rtp.setMarker(true); + //dump(rtp, "mark"); + + char payload[] = { 0x01, 0x02, 0x03 }; + rtp.setPayload(payload, sizeof(payload)); + //dump(rtp, "Payload[6*f]"); - rtp.setMarker(true); - dump(rtp, "mark"); + rtp.setPadding(5); + //dump(rtp, "Padding(5)"); - char payload[] = { 0xff, 0xff, 0xff }; - rtp.setPayload(payload, sizeof(payload)); - dump(rtp, "Payload[6*f]"); + rtp.setPadding(0); + //dump(rtp, "Padding(0)"); - rtp.setPadding(5); - dump(rtp, "Padding(5)"); + rtp.setPadding(3); + //dump(rtp, "Padding(3)"); - rtp.setPadding(0); - dump(rtp, "Padding(0)"); + rtp.setMarker(true); + //dump(rtp, "mark"); - rtp.setPadding(3); - dump(rtp, "Padding(3)"); + rtp.setPayloadType(1); + //dump(rtp, "pt(1)"); - rtp.setMarker(true); - dump(rtp, "mark"); + rtp.setPayloadType(0x7f); + //dump(rtp, "pt(7f)"); - rtp.setPayloadType(1); - dump(rtp, "pt(1)"); + rtp.setPayloadType(2); + //dump(rtp, "pt(2)"); - rtp.setPayloadType(0x7f); - dump(rtp, "pt(7f)"); + rtp.addCSrc(1); + //dump(rtp, "CSrc[1]"); - rtp.setPayloadType(2); - dump(rtp, "pt(2)"); + rtp.removeCSrc(1); + //dump(rtp, "CSrc[-]"); - rtp.addCSrc(1); - dump(rtp, "CSrc[1]"); + rtp.addCSrc(2); + rtp.addCSrc(4); + //dump(rtp, "CSrc[2,4]"); - rtp.removeCSrc(1); - dump(rtp, "CSrc[-]"); + rtp.removeCSrc(2); + //dump(rtp, "CSrc[2]"); - rtp.addCSrc(2); - rtp.addCSrc(4); - dump(rtp, "CSrc[2,4]"); + rtp.setSeq(0x0102); + //dump(rtp, "seq"); - rtp.removeCSrc(2); - dump(rtp, "CSrc[2]"); + rtp.setTimestamp(0x03040506); + //dump(rtp, "ts"); - rtp.setSeq(0x0102); - dump(rtp, "seq"); + rtp.setSSrc(0x0708090a); + //dump(rtp, "ssrc"); - rtp.setTimestamp(0x03040506); - dump(rtp, "ts"); + char buf[MAX_RTP_PACKET_SIZE]; + size_t sz = rtp.packet(buf, sizeof(buf)); - rtp.setSSrc(0x0708090a); - dump(rtp, "ssrc"); + RTP rtp2; + rtp2.fromPacket(buf, sz); - char buf[MAX_RTP_PACKET_SIZE]; - size_t sz = rtp.packet(buf, sizeof(buf)); + char buf2[MAX_RTP_PACKET_SIZE]; + size_t sz2 = rtp2.packet(buf2, sizeof(buf2)); - RTP rtp2; - rtp2.fromPacket(buf, sz); + CPPUNIT_ASSERT_EQUAL(sz, sz2); - dump(rtp2, "fromPacket"); + int err = 0; + for(int i = 0; i < sz; i++) { + err += abs(buf[i] - buf2[i]); + } + CPPUNIT_ASSERT_EQUAL(0, err); - return 0; -} + } +}; +// Registers the fixture into the 'registry' +CPPUNIT_TEST_SUITE_REGISTRATION(test_rtp_class); diff --git a/test/test_srtp.cc b/test/test_srtp.cc index 962c18f..c7b82e5 100644 --- a/test/test_srtp.cc +++ b/test/test_srtp.cc @@ -25,6 +25,8 @@ * License along with lrtp; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + #include #include "../src/rtp.h" @@ -33,55 +35,56 @@ #define KEY "123456789012345678901234567890123456789012345678901234567890" #define SSRC 1234567890 -void dump(const char *title, const char *buf, size_t size) -{ - printf("%12s: ", title); - for(int i = 0; i < size; i++) { - if(i % 8 == 0) printf(" "); - printf("%02x ", (unsigned char)*buf++); - } - printf("\n"); -} - -int main() +class test_srtp_class : public CppUnit::TestFixture { - RTP rtp; - rtp.setSSrc(SSRC); + CPPUNIT_TEST_SUITE(test_srtp_class); + CPPUNIT_TEST(test_srtp); + CPPUNIT_TEST_SUITE_END(); + +public: + void setUp() {} + void tearDown() {} + + void test_srtp() { + RTP rtp; + rtp.setSSrc(SSRC); + + char payload[] = { 0xde, 0xad, 0xbe, 0xef }; + rtp.setPayload(payload, sizeof(payload)); - char payload[] = { 0xde, 0xad, 0xbe, 0xef }; - rtp.setPayload(payload, sizeof(payload)); + char buf[MAX_RTP_PACKET_SIZE]; + size_t sz = rtp.packet(buf, sizeof(buf)); - char buf[MAX_RTP_PACKET_SIZE]; - size_t sz = rtp.packet(buf, sizeof(buf)); + //dump("Vanilla", buf, sz); - dump("Vanilla", buf, sz); + { + SRTP srtp(KEY, rtp.SSrc()); + sz = srtp.encrypt(buf, sz); + } - { - SRTP srtp(KEY, rtp.SSrc()); - sz = srtp.encrypt(buf, sz); - } + //dump("Encrypted", buf, sz); - dump("Encrypted", buf, sz); + { + SRTP srtp(KEY, rtp.SSrc()); + sz = srtp.decrypt(buf, sz); + } - { - SRTP srtp(KEY, rtp.SSrc()); - sz = srtp.decrypt(buf, sz); - } + //dump("Decrypted", buf, sz); + //printf("Compare:\n"); + char buf0[MAX_RTP_PACKET_SIZE]; + size_t sz0 = rtp.packet(buf0, sizeof(buf0)); - dump("Decrypted", buf, sz); + CPPUNIT_ASSERT_EQUAL(sz, sz0); - printf("Compare:\n"); - char buf0[MAX_RTP_PACKET_SIZE]; - size_t sz0 = rtp.packet(buf0, sizeof(buf0)); - if(sz0 != sz) printf("Sizes differ (%d %d)...\n", sz0, sz); - unsigned int sum = 0; - for(int i = 0; i < sz0; i++) { - sum += abs(buf0[i] - buf[i]); - } - if(sum) printf("NOT EQUAL! diff = %d\n", sum); - else printf("Vanilla == Decrypted\n"); + int err = 0; + for(int i = 0; i < sz0; i++) { + err += abs(buf0[i] - buf[i]); + } - return 0; -} + CPPUNIT_ASSERT_EQUAL(0, err); + } +}; +// Registers the fixture into the 'registry' +CPPUNIT_TEST_SUITE_REGISTRATION(test_srtp_class); -- cgit v1.2.3