mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-12 22:09:25 +08:00

Put(int), Get(int), Put(float), Get(float), using two pointer (which should be in AudioLayer and in AudioRtp)
152 lines
4.3 KiB
C++
152 lines
4.3 KiB
C++
/*
|
|
* Copyright (C) 2009 Savoir-Faire Linux inc.
|
|
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program 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 General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <sstream>
|
|
#include <ccrtp/rtp.h>
|
|
#include <assert.h>
|
|
#include <string>
|
|
#include <cstring>
|
|
#include <math.h>
|
|
#include <dlfcn.h>
|
|
#include <iostream>
|
|
#include <sstream>
|
|
|
|
|
|
#include "mainbufferTest.h"
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
using std::cout;
|
|
using std::endl;
|
|
|
|
|
|
void MainBufferTest::setUp()
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
void MainBufferTest::tearDown()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
void MainBufferTest::testRingBufferCreation()
|
|
{
|
|
CallID test_id = "1234";
|
|
RingBuffer* test_ring_buffer = _mainbuffer.createRingBuffer(test_id);
|
|
|
|
CPPUNIT_ASSERT(test_ring_buffer != NULL);
|
|
CPPUNIT_ASSERT(_mainbuffer.getRingBuffer("null id") == NULL);
|
|
CPPUNIT_ASSERT(_mainbuffer.getRingBuffer(test_id) == test_ring_buffer);
|
|
|
|
CPPUNIT_ASSERT(_mainbuffer.removeRingBuffer("null id") == false);
|
|
CPPUNIT_ASSERT(_mainbuffer.removeRingBuffer(test_id) == true);
|
|
|
|
}
|
|
|
|
|
|
void MainBufferTest::testRingbufferInt()
|
|
{
|
|
|
|
CallID test_id = "test_int";
|
|
RingBuffer* test_ring_buffer = _mainbuffer.createRingBuffer(test_id);
|
|
|
|
int testint1 = 12;
|
|
int testint2 = 13;
|
|
|
|
CPPUNIT_ASSERT(test_ring_buffer->Put(&testint1, sizeof(int)) == sizeof(int));
|
|
CPPUNIT_ASSERT(test_ring_buffer->Len() == sizeof(int));
|
|
|
|
CPPUNIT_ASSERT(test_ring_buffer->Put(&testint2, sizeof(int)) == sizeof(int));
|
|
CPPUNIT_ASSERT(test_ring_buffer->Len() == 2*sizeof(int));
|
|
|
|
int testget;
|
|
|
|
CPPUNIT_ASSERT(test_ring_buffer->Get(&testget, sizeof(int)) == sizeof(int));
|
|
CPPUNIT_ASSERT(test_ring_buffer->Len() == sizeof(int));
|
|
CPPUNIT_ASSERT(testget == testint1);
|
|
|
|
CPPUNIT_ASSERT(test_ring_buffer->Get(&testget, sizeof(int)) == sizeof(int));
|
|
CPPUNIT_ASSERT(testget == testint2);
|
|
CPPUNIT_ASSERT(test_ring_buffer->Len() == 0);
|
|
|
|
CPPUNIT_ASSERT(test_ring_buffer->Put(&testint1, sizeof(int)) == sizeof(int));
|
|
test_ring_buffer->flush();
|
|
CPPUNIT_ASSERT(test_ring_buffer->Len() == 0);
|
|
|
|
_mainbuffer.removeRingBuffer(test_id);
|
|
}
|
|
|
|
|
|
void MainBufferTest::testRingbufferFloat()
|
|
{
|
|
|
|
CallID test_id = "test_float";
|
|
RingBuffer* test_ring_buffer = _mainbuffer.createRingBuffer(test_id);
|
|
|
|
float testfloat1 = 12.5;
|
|
float testfloat2 = 13.4;
|
|
|
|
CPPUNIT_ASSERT(test_ring_buffer->Put(&testfloat1, sizeof(float)) == sizeof(float));
|
|
CPPUNIT_ASSERT(test_ring_buffer->Len() == sizeof(float));
|
|
|
|
CPPUNIT_ASSERT(test_ring_buffer->Put(&testfloat2, sizeof(float)) == sizeof(float));
|
|
CPPUNIT_ASSERT(test_ring_buffer->Len() == 2*sizeof(float));
|
|
|
|
float testget;
|
|
|
|
CPPUNIT_ASSERT(test_ring_buffer->Get(&testget, sizeof(float)) == sizeof(float));
|
|
CPPUNIT_ASSERT(test_ring_buffer->Len() == sizeof(float));
|
|
CPPUNIT_ASSERT(testget == testfloat1);
|
|
|
|
CPPUNIT_ASSERT(test_ring_buffer->Get(&testget, sizeof(float)) == sizeof(float));
|
|
CPPUNIT_ASSERT(testget == testfloat2);
|
|
CPPUNIT_ASSERT(test_ring_buffer->Len() == 0);
|
|
|
|
CPPUNIT_ASSERT(test_ring_buffer->Put(&testfloat1, sizeof(float)) == sizeof(float));
|
|
test_ring_buffer->flush();
|
|
CPPUNIT_ASSERT(test_ring_buffer->Len() == 0);
|
|
|
|
_mainbuffer.removeRingBuffer(test_id);
|
|
}
|
|
|
|
|
|
void MainBufferTest::testTwoPointer()
|
|
{
|
|
|
|
|
|
CallID test_id = "two pointer";
|
|
RingBuffer* input_buffer = _mainbuffer.createRingBuffer(test_id);
|
|
RingBuffer* output_buffer = _mainbuffer.getRingBuffer(test_id);
|
|
|
|
int test_input = 12;
|
|
int test_output;
|
|
|
|
CPPUNIT_ASSERT(input_buffer->Put(&test_input, sizeof(int)) == sizeof(int));
|
|
CPPUNIT_ASSERT(output_buffer->Get(&test_output, sizeof(float)) == sizeof(float));
|
|
CPPUNIT_ASSERT(test_input == test_output);
|
|
|
|
_mainbuffer.removeRingBuffer(test_id);
|
|
}
|