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. --- test/test_amrwb.cc | 185 +++++++++++++++++++++++++++-------------------------- 1 file changed, 96 insertions(+), 89 deletions(-) (limited to 'test/test_amrwb.cc') 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); -- cgit v1.2.3