diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile.am | 6 | ||||
-rw-r--r-- | test/test_amrwb.cc | 13 | ||||
-rw-r--r-- | test/test_framelist.cc | 113 | ||||
-rw-r--r-- | test/test_init.cc | 4 | ||||
-rw-r--r-- | test/test_instance.cc | 82 | ||||
-rw-r--r-- | test/test_jpeg.cc | 34 | ||||
-rw-r--r-- | test/test_l16.cc | 11 | ||||
-rw-r--r-- | test/test_opus.cc | 13 | ||||
-rw-r--r-- | test/test_raw.cc | 11 |
9 files changed, 222 insertions, 65 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index 00dc707..f5dfca8 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,7 +1,11 @@ -TESTS = jpeg amrwb opus init rtp srtp raw l16 asc2bin framelist +TESTS = instance jpeg amrwb opus init rtp srtp raw l16 asc2bin framelist check_PROGRAMS = $(TESTS) +instance_CXXFLAGS = $(CPPUNIT_CFLAGS) -DOUTPUT=\"instance\" -I../src +instance_LDFLAGS = $(CPPUNIT_LIBS) -L../src/.libs/ -llrtp +instance_SOURCES = test.cc test_instance.cc + jpeg_CXXFLAGS = $(CPPUNIT_CFLAGS) -DOUTPUT=\"jpeg\" -I../src jpeg_LDFLAGS = $(CPPUNIT_LIBS) -L../src/.libs/ -llrtp jpeg_SOURCES = test.cc test_jpeg.cc diff --git a/test/test_amrwb.cc b/test/test_amrwb.cc index d6a0731..cf82a6e 100644 --- a/test/test_amrwb.cc +++ b/test/test_amrwb.cc @@ -1,7 +1,7 @@ /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set et sw=2 ts=2: */ /*************************************************************************** - * test_init.cc + * test_amrwb.cc * * Mon Sep 2 14:02:16 CEST 2013 * Copyright 2013 Bent Bisballe Nyeng @@ -74,7 +74,9 @@ public: size_t framesize = wb_frame_size[frame_type_index] * num_frames; { // Encode - struct lrtp_t *lrtp = lrtp_init(KEY, SSRC); + lrtp_status_t status; + struct lrtp_t *lrtp = lrtp_init(&status, KEY, SSRC); + CPPUNIT_ASSERT_EQUAL(status, LRTP_OK); int x = lrtp_create_profile(lrtp, PROFILE_AMRWB, csrc, @@ -94,7 +96,8 @@ public: for(size_t j = 0; j < framesize; j++) frame[j] = cnt++; - int ret = lrtp_enqueue_frame(lrtp, csrc, frame, framesize, timestamp++); + int ret = lrtp_enqueue_frame(lrtp, csrc, frame, framesize, timestamp++, + LRTP_COPY); while( (ret = lrtp_pack(lrtp, packet, sizeof(packet))) != 0) { std::string p; p.append(packet, ret); @@ -107,7 +110,9 @@ public: } { // Decode - struct lrtp_t *lrtp = lrtp_init(KEY, SSRC); + lrtp_status_t status; + struct lrtp_t *lrtp = lrtp_init(&status, KEY, SSRC); + CPPUNIT_ASSERT_EQUAL(status, LRTP_OK); int x = lrtp_create_profile(lrtp, PROFILE_AMRWB, csrc, diff --git a/test/test_framelist.cc b/test/test_framelist.cc index 27b38f6..b3f8374 100644 --- a/test/test_framelist.cc +++ b/test/test_framelist.cc @@ -38,6 +38,11 @@ #define KEY "123456789012345678901234567890123456789012345678901234567890" #define SSRC 1234567890 +typedef union { + int n; + char c[sizeof(int)]; +} num_t; + class test_conn_class : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(test_conn_class); @@ -55,49 +60,59 @@ public: std::vector<std::string> packets; unsigned int csrc = 42; - union { - int n; - char c[sizeof(int)]; - } num[3]; + num_t num[3]; + + lrtp_status_t status; + struct lrtp_t *lrtp = lrtp_init(&status, KEY, SSRC); + CPPUNIT_ASSERT_EQUAL(LRTP_OK, status); - struct lrtp_t *lrtp = lrtp_init(KEY, SSRC); + struct lrtp_t *lrtp2 = lrtp_init(&status, KEY, SSRC); + CPPUNIT_ASSERT_EQUAL(LRTP_OK, status); ret = lrtp_create_profile(lrtp, PROFILE_RAW, csrc, - OPTION_RAW_PKG_SIZE, sizeof(num), + OPTION_RAW_PKG_SIZE, sizeof(num_t), + OPTION_END); + CPPUNIT_ASSERT_EQUAL(0, ret); + + ret = lrtp_create_profile(lrtp2, PROFILE_RAW, csrc, + OPTION_RAW_PKG_SIZE, sizeof(num_t), OPTION_END); CPPUNIT_ASSERT_EQUAL(0, ret); num[0].n = 0; - ret = lrtp_enqueue_frame(lrtp, csrc, num[0].c, sizeof(num), 0); + ret = lrtp_enqueue_frame(lrtp, csrc, num[0].c, sizeof(num_t), 0, LRTP_COPY); CPPUNIT_ASSERT_EQUAL(0, ret); num[1].n = 1; - ret = lrtp_enqueue_frame(lrtp, csrc, num[1].c, sizeof(num), 1); + ret = lrtp_enqueue_frame(lrtp, csrc, num[1].c, sizeof(num_t), 1, LRTP_COPY); CPPUNIT_ASSERT_EQUAL(0, ret); num[2].n = 2; - ret = lrtp_enqueue_frame(lrtp, csrc, num[2].c, sizeof(num), 2); + ret = lrtp_enqueue_frame(lrtp, csrc, num[2].c, sizeof(num_t), 2, LRTP_COPY); CPPUNIT_ASSERT_EQUAL(0, ret); for(int i = 0; i < 3; i++) { char packet[16*1024]; ret = lrtp_pack(lrtp, packet, sizeof(packet)); - CPPUNIT_ASSERT_EQUAL((int)(16 + sizeof(num)), ret); - - RTP rtp; - - ret = rtp.fromPacket(packet, ret); - CPPUNIT_ASSERT_EQUAL((int)(16 + sizeof(num)), ret); - - int n = *((int*)rtp.payloadData()); + CPPUNIT_ASSERT_EQUAL((int)(26 + sizeof(num_t)), ret); + ret = lrtp_unpack(lrtp2, packet, ret); + CPPUNIT_ASSERT_EQUAL(0, ret); + + char frame[16*1024]; + ret = lrtp_dequeue_frame(lrtp2, frame, sizeof(frame), NULL, NULL); + CPPUNIT_ASSERT_EQUAL((int)sizeof(num_t), ret); + int n = *((int*)frame); + CPPUNIT_ASSERT_EQUAL(i, n); } lrtp_destroy_profile(lrtp, csrc); + lrtp_destroy_profile(lrtp2, csrc); lrtp_close(lrtp); + lrtp_close(lrtp2); } void test_framelist() { @@ -106,57 +121,76 @@ public: std::vector<std::string> packets; unsigned int csrc = 42; - union { - int n; - char c[sizeof(int)]; - } num[4]; + num_t num[4]; - struct lrtp_t *lrtp = lrtp_init(KEY, SSRC); + lrtp_status_t status; + struct lrtp_t *lrtp = lrtp_init(&status, KEY, SSRC); + CPPUNIT_ASSERT_EQUAL(LRTP_OK, status); + struct lrtp_t *lrtp2 = lrtp_init(&status, KEY, SSRC); + CPPUNIT_ASSERT_EQUAL(LRTP_OK, status); + ret = lrtp_create_profile(lrtp, PROFILE_RAW, csrc + 2, - OPTION_RAW_PKG_SIZE, sizeof(num), + OPTION_RAW_PKG_SIZE, sizeof(num_t), OPTION_END); CPPUNIT_ASSERT_EQUAL(0, ret); ret = lrtp_create_profile(lrtp, PROFILE_RAW, csrc, - OPTION_RAW_PKG_SIZE, sizeof(num), + OPTION_RAW_PKG_SIZE, sizeof(num_t), OPTION_END); CPPUNIT_ASSERT_EQUAL(0, ret); ret = lrtp_create_profile(lrtp, PROFILE_RAW, csrc + 1, - OPTION_RAW_PKG_SIZE, sizeof(num), + OPTION_RAW_PKG_SIZE, sizeof(num_t), + OPTION_END); + CPPUNIT_ASSERT_EQUAL(0, ret); + + ret = lrtp_create_profile(lrtp2, PROFILE_RAW, csrc + 2, + OPTION_RAW_PKG_SIZE, sizeof(num_t), OPTION_END); CPPUNIT_ASSERT_EQUAL(0, ret); + ret = lrtp_create_profile(lrtp2, PROFILE_RAW, csrc, + OPTION_RAW_PKG_SIZE, sizeof(num_t), + OPTION_END); + CPPUNIT_ASSERT_EQUAL(0, ret); + + ret = lrtp_create_profile(lrtp2, PROFILE_RAW, csrc + 1, + OPTION_RAW_PKG_SIZE, sizeof(num_t), + OPTION_END); + CPPUNIT_ASSERT_EQUAL(0, ret); + + num[0].n = 0; - ret = lrtp_enqueue_frame(lrtp, csrc, num[0].c, sizeof(num), 0); + ret = lrtp_enqueue_frame(lrtp, csrc, num[0].c, sizeof(num_t), 0, LRTP_COPY); CPPUNIT_ASSERT_EQUAL(0, ret); num[1].n = 2; - ret = lrtp_enqueue_frame(lrtp, csrc + 2, num[1].c, sizeof(num), 1); + ret = lrtp_enqueue_frame(lrtp, csrc + 2, num[1].c, sizeof(num_t), 1, LRTP_COPY); CPPUNIT_ASSERT_EQUAL(0, ret); num[2].n = 1; - ret = lrtp_enqueue_frame(lrtp, csrc + 1, num[2].c, sizeof(num), 2); + ret = lrtp_enqueue_frame(lrtp, csrc + 1, num[2].c, sizeof(num_t), 2, LRTP_COPY); CPPUNIT_ASSERT_EQUAL(0, ret); num[3].n = 3; - ret = lrtp_enqueue_frame(lrtp, csrc + 1, num[3].c, sizeof(num), 3); + ret = lrtp_enqueue_frame(lrtp, csrc + 1, num[3].c, sizeof(num_t), 3, LRTP_COPY); CPPUNIT_ASSERT_EQUAL(0, ret); for(int i = 0; i < 4; i++) { char packet[16*1024]; ret = lrtp_pack(lrtp, packet, sizeof(packet)); - CPPUNIT_ASSERT_EQUAL((int)(16 + sizeof(num)), ret); - - RTP rtp; - - ret = rtp.fromPacket(packet, ret); - CPPUNIT_ASSERT_EQUAL((int)(16 + sizeof(num)), ret); - - int n = *((int*)rtp.payloadData()); + CPPUNIT_ASSERT_EQUAL((int)(26 + sizeof(num_t)), ret); + ret = lrtp_unpack(lrtp2, packet, ret); + CPPUNIT_ASSERT_EQUAL(0, ret); + + char frame[16*1024]; + ret = lrtp_dequeue_frame(lrtp2, frame, sizeof(frame), NULL, NULL); + CPPUNIT_ASSERT_EQUAL((int)sizeof(num_t), ret); + int n = *((int*)frame); + CPPUNIT_ASSERT_EQUAL(i, n); } @@ -164,7 +198,12 @@ public: lrtp_destroy_profile(lrtp, csrc + 1); lrtp_destroy_profile(lrtp, csrc + 2); + lrtp_destroy_profile(lrtp2, csrc); + lrtp_destroy_profile(lrtp2, csrc + 1); + lrtp_destroy_profile(lrtp2, csrc + 2); + lrtp_close(lrtp); + lrtp_close(lrtp2); } }; diff --git a/test/test_init.cc b/test/test_init.cc index 13ca874..d00033c 100644 --- a/test/test_init.cc +++ b/test/test_init.cc @@ -45,7 +45,9 @@ public: void tearDown() {} void test_init() { - struct lrtp_t *lrtp = lrtp_init(KEY, SSRC); + lrtp_status_t status; + struct lrtp_t *lrtp = lrtp_init(&status, KEY, SSRC); + CPPUNIT_ASSERT_EQUAL(status, LRTP_OK); CPPUNIT_ASSERT(lrtp); diff --git a/test/test_instance.cc b/test/test_instance.cc new file mode 100644 index 0000000..e8bee16 --- /dev/null +++ b/test/test_instance.cc @@ -0,0 +1,82 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set et sw=2 ts=2: */ +/*************************************************************************** + * test_instance.cc + * + * Fri May 30 08:37:33 CEST 2014 + * Copyright 2014 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 <cppunit/extensions/HelperMacros.h> + +#include <lrtp.h> + +#include <stdio.h> + +#include <string> +#include <vector> + +#define KEY "123456789012345678901234567890123456789012345678901234567890" +#define SSRC 1234567890 + +class test_instance_class : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(test_instance_class); + CPPUNIT_TEST(test_instance); + CPPUNIT_TEST_SUITE_END(); + +public: + void setUp() {} + void tearDown() {} + + void test_instance() { + lrtp_status_t status; + + struct lrtp_t *lrtp0 = lrtp_init(&status, KEY, SSRC); + CPPUNIT_ASSERT_EQUAL(status, LRTP_OK); + + struct lrtp_t *lrtp1 = lrtp_init(&status, KEY, SSRC); + CPPUNIT_ASSERT_EQUAL(status, LRTP_OK); + + struct lrtp_t *lrtp2 = lrtp_init(&status, KEY, SSRC); + CPPUNIT_ASSERT_EQUAL(status, LRTP_OK); + + status = lrtp_close(lrtp1); + CPPUNIT_ASSERT_EQUAL(status, LRTP_OK); + + status = lrtp_close(lrtp0); + CPPUNIT_ASSERT_EQUAL(status, LRTP_OK); + + status = lrtp_close(lrtp2); + CPPUNIT_ASSERT_EQUAL(status, LRTP_OK); + + // Expected shutdown here + + struct lrtp_t *lrtp3 = lrtp_init(&status, KEY, SSRC); + CPPUNIT_ASSERT_EQUAL(status, LRTP_OK); + + status = lrtp_close(lrtp3); + CPPUNIT_ASSERT_EQUAL(status, LRTP_OK); + } +}; + +// Registers the fixture into the 'registry' +CPPUNIT_TEST_SUITE_REGISTRATION(test_instance_class); diff --git a/test/test_jpeg.cc b/test/test_jpeg.cc index 894ae3a..ca6e80b 100644 --- a/test/test_jpeg.cc +++ b/test/test_jpeg.cc @@ -53,8 +53,10 @@ public: unsigned int csrc = 42; { // Encode - struct lrtp_t *lrtp = lrtp_init(KEY, SSRC); - + lrtp_status_t status; + struct lrtp_t *lrtp = lrtp_init(&status, KEY, SSRC); + CPPUNIT_ASSERT_EQUAL(status, LRTP_OK); + int x = lrtp_create_profile(lrtp, PROFILE_JPEG, csrc, OPTION_END); CPPUNIT_ASSERT_EQUAL(0, x); @@ -71,30 +73,33 @@ public: FILE *fp = fopen(filename, "r"); CPPUNIT_ASSERT(fp); - fseek(fp, 0, SEEK_END); + CPPUNIT_ASSERT(fseek(fp, 0, SEEK_END) != -1); int imagesize = ftell(fp); - fseek(fp, 0, SEEK_SET); + CPPUNIT_ASSERT(fseek(fp, 0, SEEK_SET) != -1); char *image = (char*)malloc(imagesize); - fread(image, imagesize, 1, fp); + CPPUNIT_ASSERT(fread(image, 1, imagesize, fp) == (size_t)imagesize); fclose(fp); int ret = 0; - ret = lrtp_enqueue_frame(lrtp, csrc, image, imagesize, n); + ret = lrtp_enqueue_frame(lrtp, csrc, image, imagesize, n, LRTP_COPY); CPPUNIT_ASSERT_EQUAL(0, ret); - while( (ret = lrtp_pack(lrtp, packet, sizeof(packet))) != 0) { + while( (ret = lrtp_pack(lrtp, packet, sizeof(packet))) > 0) { std::string p; p.append(packet, ret); packets.push_back(p); //dump("pkg", packet, ret); } + CPPUNIT_ASSERT_EQUAL(ret, 0); free(image); } - lrtp_destroy_profile(lrtp, csrc); + status = lrtp_destroy_profile(lrtp, csrc); + CPPUNIT_ASSERT_EQUAL(status, LRTP_OK); - lrtp_close(lrtp); + status = lrtp_close(lrtp); + CPPUNIT_ASSERT_EQUAL(status, LRTP_OK); } //printf("\nPackets: %d\n", packets.size()); @@ -105,7 +110,9 @@ public: // Write SIO and JFIF from original image: // fwrite(image, 2 + 16, 1, fp); - struct lrtp_t *lrtp = lrtp_init(KEY, SSRC); + lrtp_status_t status; + struct lrtp_t *lrtp = lrtp_init(&status, KEY, SSRC); + CPPUNIT_ASSERT_EQUAL(status, LRTP_OK); int x = lrtp_create_profile(lrtp, PROFILE_JPEG, csrc, OPTION_END); @@ -149,8 +156,11 @@ public: // CPPUNIT_ASSERT_EQUAL((int)imagesize, num); - lrtp_destroy_profile(lrtp, csrc); - lrtp_close(lrtp); + status = lrtp_destroy_profile(lrtp, csrc); + CPPUNIT_ASSERT_EQUAL(status, LRTP_OK); + + status = lrtp_close(lrtp); + CPPUNIT_ASSERT_EQUAL(status, LRTP_OK); //fclose(fp); } diff --git a/test/test_l16.cc b/test/test_l16.cc index 0cdb4b2..71e4562 100644 --- a/test/test_l16.cc +++ b/test/test_l16.cc @@ -57,7 +57,9 @@ public: CPPUNIT_ASSERT(false); // We need to actually test the profile options here... { // Encode - struct lrtp_t *lrtp = lrtp_init(KEY, SSRC); + lrtp_status_t status; + struct lrtp_t *lrtp = lrtp_init(&status, KEY, SSRC); + CPPUNIT_ASSERT_EQUAL(status, LRTP_OK); /* OPTION_L16_SAMPLES_PER_CHANNEL_PER_PACKET @@ -81,7 +83,8 @@ public: for(size_t i = 0; i < sizeof(frame); i++) frame[i] = num++; int ret = 0; - ret = lrtp_enqueue_frame(lrtp, csrc, frame, sizeof(frame), ts); + ret = lrtp_enqueue_frame(lrtp, csrc, frame, sizeof(frame), ts, + LRTP_COPY); while( (ret = lrtp_pack(lrtp, packet, sizeof(packet))) != 0) { std::string p; p.append(packet, ret); @@ -96,7 +99,9 @@ public: } { // Decode - struct lrtp_t *lrtp = lrtp_init(KEY, SSRC); + lrtp_status_t status; + struct lrtp_t *lrtp = lrtp_init(&status, KEY, SSRC); + CPPUNIT_ASSERT_EQUAL(status, LRTP_OK); int x = lrtp_create_profile(lrtp, PROFILE_L16, csrc, diff --git a/test/test_opus.cc b/test/test_opus.cc index 380e7b9..582ea02 100644 --- a/test/test_opus.cc +++ b/test/test_opus.cc @@ -1,7 +1,7 @@ /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set et sw=2 ts=2: */ /*************************************************************************** - * test_init.cc + * test_opus.cc * * Mon Sep 2 14:02:16 CEST 2013 * Copyright 2013 Bent Bisballe Nyeng @@ -86,7 +86,9 @@ public: int sent = 0; { // Encode - struct lrtp_t *lrtp = lrtp_init(KEY, SSRC); + lrtp_status_t status; + struct lrtp_t *lrtp = lrtp_init(&status, KEY, SSRC); + CPPUNIT_ASSERT_EQUAL(status, LRTP_OK); int x = lrtp_create_profile(lrtp, PROFILE_OPUS, csrc, OPTION_END); @@ -137,7 +139,8 @@ public: printf("Opus error: %s\n", opus_strerror(framesize)); } - int ret = lrtp_enqueue_frame(lrtp, csrc, frame, framesize, timestamp); + int ret = lrtp_enqueue_frame(lrtp, csrc, frame, framesize, timestamp, + LRTP_COPY); while( (ret = lrtp_pack(lrtp, packet, sizeof(packet))) != 0) { std::string p; p.append(packet, ret); @@ -153,7 +156,9 @@ public: } { // Decode - struct lrtp_t *lrtp = lrtp_init(KEY, SSRC); + lrtp_status_t status; + struct lrtp_t *lrtp = lrtp_init(&status, KEY, SSRC); + CPPUNIT_ASSERT_EQUAL(status, LRTP_OK); int x = lrtp_create_profile(lrtp, PROFILE_OPUS, csrc, OPTION_END); diff --git a/test/test_raw.cc b/test/test_raw.cc index e219ffa..ffadabb 100644 --- a/test/test_raw.cc +++ b/test/test_raw.cc @@ -55,7 +55,9 @@ public: unsigned int csrc = 42; { // Encode - struct lrtp_t *lrtp = lrtp_init(KEY, SSRC); + lrtp_status_t status; + struct lrtp_t *lrtp = lrtp_init(&status, KEY, SSRC); + CPPUNIT_ASSERT_EQUAL(status, LRTP_OK); int x = lrtp_create_profile(lrtp, PROFILE_RAW, csrc, OPTION_RAW_PKG_SIZE, pkg_size, @@ -72,7 +74,8 @@ public: for(size_t i = 0; i < sizeof(frame); i++) frame[i] = num++; int ret = 0; - ret = lrtp_enqueue_frame(lrtp, csrc, frame, sizeof(frame), ts); + ret = lrtp_enqueue_frame(lrtp, csrc, frame, sizeof(frame), ts, + LRTP_COPY); while( (ret = lrtp_pack(lrtp, packet, sizeof(packet))) != 0) { std::string p; p.append(packet, ret); @@ -87,7 +90,9 @@ public: } { // Decode - struct lrtp_t *lrtp = lrtp_init(KEY, SSRC); + lrtp_status_t status; + struct lrtp_t *lrtp = lrtp_init(&status, KEY, SSRC); + CPPUNIT_ASSERT_EQUAL(status, LRTP_OK); int x = lrtp_create_profile(lrtp, PROFILE_RAW, csrc, OPTION_RAW_PKG_SIZE, pkg_size, |