Commit cce04807 authored by Tristan Matthews's avatar Tristan Matthews

tests: cleanup

parent 850fd952
......@@ -36,9 +36,9 @@
#include "logger.h"
#include "validator.h"
void AccountTest::TestAddRemove(void)
void AccountTest::TestAddRemove()
{
DEBUG("-------------------- AccountTest::TestAddRemove --------------------\n");
DEBUG("-------------------- %s --------------------\n", __PRETTY_FUNCTION__);
std::map<std::string, std::string> details;
details[CONFIG_ACCOUNT_TYPE] = "SIP";
......
......@@ -41,7 +41,7 @@ class AccountTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE_END();
public:
void TestAddRemove(void);
void TestAddRemove();
};
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(AccountTest, "AccountTest");
CPPUNIT_TEST_SUITE_REGISTRATION(AccountTest);
......
......@@ -28,23 +28,20 @@
* as that of the covered work.
*/
#include <stdio.h>
#include <sstream>
#include "audiolayertest.h"
#include "audio/pulseaudio/audiostream.h"
#include "logger.h"
#include "manager.h"
#include "audio/alsa/alsalayer.h"
#include "audio/pulseaudio/pulselayer.h"
#include <unistd.h>
using std::cout;
using std::endl;
AudioLayerTest::AudioLayerTest() : manager_(0), pulselayer_(0), layer_(0)
{}
void AudioLayerTest::testAudioLayerConfig()
{
DEBUG("-------------------- AudioLayerTest::testAudioLayerConfig --------------------\n");
DEBUG("-------------------- %s --------------------\n", __PRETTY_FUNCTION__);
CPPUNIT_ASSERT(Manager::instance().audioPreference.getSmplrate() == 44100);
......@@ -68,12 +65,12 @@ void AudioLayerTest::testAudioLayerConfig()
void AudioLayerTest::testAudioLayerSwitch()
{
DEBUG("-------------------- AudioLayerTest::testAudioLayerSwitch --------------------\n");
DEBUG("-------------------- %s --------------------\n", __PRETTY_FUNCTION__);
bool wasAlsa = dynamic_cast<AlsaLayer*>(Manager::instance().getAudioDriver()) != 0;
for (int i = 0; i < 2; i++) {
DEBUG("iter - %i", i);
DEBUG("iter - %i", i);
Manager::instance().switchAudioManager();
if (wasAlsa)
......@@ -88,7 +85,7 @@ void AudioLayerTest::testAudioLayerSwitch()
void AudioLayerTest::testPulseConnect()
{
DEBUG("-------------------- AudioLayerTest::testPulseConnect --------------------\n");
DEBUG("-------------------- %s --------------------\n", __PRETTY_FUNCTION__);
if (dynamic_cast<AlsaLayer*>(Manager::instance().getAudioDriver())) {
Manager::instance().switchAudioManager();
......
......@@ -33,8 +33,8 @@
* @brief Regroups unitary tests related to the plugin manager.
*/
#ifndef _AUDIOLAYER_TEST_
#define _AUDIOLAYER_TEST_
#ifndef AUDIOLAYER_TEST_
#define AUDIOLAYER_TEST_
// Cppunit import
#include <cppunit/extensions/HelperMacros.h>
......@@ -42,18 +42,11 @@
#include <cppunit/TestCase.h>
#include <cppunit/TestSuite.h>
#include <cassert>
// Application import
#include "manager.h"
#include "config/config.h"
#include "audio/audiolayer.h"
#include "audio/alsa/alsalayer.h"
#include "audio/pulseaudio/pulselayer.h"
#include "noncopyable.h"
class ManagerImpl;
class PulseLayer;
class AudioLayerTest: public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(AudioLayerTest);
......@@ -79,4 +72,4 @@ class AudioLayerTest: public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(AudioLayerTest, "AudioLayerTest");
CPPUNIT_TEST_SUITE_REGISTRATION(AudioLayerTest);
#endif
#endif // AUDIOLAYER_TEST_
......@@ -31,6 +31,12 @@
#include "delaydetectiontest.h"
// Returns the number of elements in a, calculated at compile-time
#define ARRAYSIZE(a) \
((sizeof(a) / sizeof(*(a))) / \
static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
#endif
#include <iostream>
#include <math.h>
#include <string.h>
......@@ -54,7 +60,7 @@ void DelayDetectionTest::testCrossCorrelation()
float tmp;
for (int i = 0; i < 10; i++) {
for (int i = 0; i < ARRAYSIZE(result); i++) {
tmp = result[i] - expected[i];
if (tmp < 0.0)
......@@ -79,47 +85,41 @@ void DelayDetectionTest::testCrossCorrelationDelay()
void DelayDetectionTest::testFirFilter()
{
float decimationCoefs[] = {-0.09870257, 0.07473655, 0.05616626, 0.04448337, 0.03630817, 0.02944626,
0.02244098, 0.01463477, 0.00610982, -0.00266367, -0.01120109, -0.01873722,
-0.02373243, -0.02602213, -0.02437806, -0.01869834, -0.00875287, 0.00500204,
0.02183252, 0.04065763, 0.06015944, 0.0788299, 0.09518543, 0.10799179,
0.1160644, 0.12889288, 0.1160644, 0.10799179, 0.09518543, 0.0788299,
0.06015944, 0.04065763, 0.02183252, 0.00500204, -0.00875287, -0.01869834,
-0.02437806, -0.02602213, -0.02373243, -0.01873722, -0.01120109, -0.00266367,
0.00610982, 0.01463477, 0.02244098, 0.02944626, 0.03630817, 0.04448337,
0.05616626, 0.07473655, -0.09870257
};
std::vector<double> ird(decimationCoefs, decimationCoefs + sizeof(decimationCoefs) /sizeof(float));
float bandpassCoefs[] = {0.06278034, -0.0758545, -0.02274943, -0.0084497, 0.0702427, 0.05986113,
0.06436469, -0.02412049, -0.03433526, -0.07568665, -0.03214543, -0.07236507,
-0.06979052, -0.12446371, -0.05530828, 0.00947243, 0.15294699, 0.17735563,
0.15294699, 0.00947243, -0.05530828, -0.12446371, -0.06979052, -0.07236507,
-0.03214543, -0.07568665, -0.03433526, -0.02412049, 0.06436469, 0.05986113,
0.0702427, -0.0084497, -0.02274943, -0.0758545, 0.06278034
};
std::vector<double> irb(bandpassCoefs, bandpassCoefs + sizeof(bandpassCoefs) /sizeof(float));
const float decimationCoefs[] = {-0.09870257, 0.07473655, 0.05616626, 0.04448337, 0.03630817, 0.02944626,
0.02244098, 0.01463477, 0.00610982, -0.00266367, -0.01120109, -0.01873722,
-0.02373243, -0.02602213, -0.02437806, -0.01869834, -0.00875287, 0.00500204,
0.02183252, 0.04065763, 0.06015944, 0.0788299, 0.09518543, 0.10799179,
0.1160644, 0.12889288, 0.1160644, 0.10799179, 0.09518543, 0.0788299,
0.06015944, 0.04065763, 0.02183252, 0.00500204, -0.00875287, -0.01869834,
-0.02437806, -0.02602213, -0.02373243, -0.01873722, -0.01120109, -0.00266367,
0.00610982, 0.01463477, 0.02244098, 0.02944626, 0.03630817, 0.04448337,
0.05616626, 0.07473655, -0.09870257};
std::vector<double> ird(decimationCoefs, decimationCoefs + sizeof(decimationCoefs) / sizeof(float));
const float bandpassCoefs[] = {0.06278034, -0.0758545, -0.02274943, -0.0084497, 0.0702427, 0.05986113,
0.06436469, -0.02412049, -0.03433526, -0.07568665, -0.03214543, -0.07236507,
-0.06979052, -0.12446371, -0.05530828, 0.00947243, 0.15294699, 0.17735563,
0.15294699, 0.00947243, -0.05530828, -0.12446371, -0.06979052, -0.07236507,
-0.03214543, -0.07568665, -0.03433526, -0.02412049, 0.06436469, 0.05986113,
0.0702427, -0.0084497, -0.02274943, -0.0758545, 0.06278034};
std::vector<double> irb(bandpassCoefs, bandpassCoefs + sizeof(bandpassCoefs) / sizeof(float));
float impulse[100];
memset(impulse, 0, sizeof(float) *100);
memset(impulse, 0, sizeof(impulse))
impulse[0] = 1.0;
FirFilter decimationFilter_(ird);
FirFilter bandpassFilter_(irb);
float impulseresponse[100];
memset(impulseresponse, 0, sizeof(float) *100);
memset(impulseresponse, 0, sizeof impulseresponse);
// compute impulse response
for (int i = 0; i < 100; i++) {
for (int i = 0; i < ARRAYSIZE(impulse); i++)
impulseresponse[i] = decimationFilter_.getOutputSample(impulse[i]);
}
float tmp;
int size = sizeof(decimationCoefs) /sizeof(float);
for (int i = 0; i < size; i++) {
tmp = decimationCoefs[i] - impulseresponse[i];
for (int i = 0; i < ARRAYSIZE(decimationCoefs); ++i) {
float tmp = decimationCoefs[i] - impulseresponse[i];
if (tmp < 0.0)
CPPUNIT_ASSERT(tmp > -0.000001);
......@@ -128,13 +128,10 @@ void DelayDetectionTest::testFirFilter()
}
for (int i = 0; i < 100; i++) {
for (size_t i = 0; i < ARRAYSIZE(impulseresponse); ++i)
impulseresponse[i] = bandpassFilter_.getOutputSample(impulse[i]);
}
size = sizeof(bandpassCoefs) /sizeof(float);
for (int i = 0; i < size; i++) {
for (size_t i = 0; i < ARRAYSIZE(bandpassCoefs); ++i) {
tmp = bandpassCoefs[i] - impulseresponse[i];
if (tmp < 0.0)
......@@ -142,51 +139,48 @@ void DelayDetectionTest::testFirFilter()
else
CPPUNIT_ASSERT(tmp < 0.000001);
}
}
void DelayDetectionTest::testIntToFloatConversion()
{
SFLDataFormat data[32768*2];
float converted[32768*2];
SFLDataFormat data[32768 * 2];
float converted[ARRAYSIZE(data)];
for (int i = -32768; i < 32768; i++)
data[i+32768] = i;
data[i + 32768] = i;
delaydetect_.convertInt16ToFloat32(data, converted, 32768*2);
delaydetect_.convertInt16ToFloat32(data, converted, ARRAYSIZE(data));
for (int i = -32768; i < 0; i++) {
CPPUNIT_ASSERT(converted[i+32768] >= -1.0);
CPPUNIT_ASSERT(converted[i+32768] <= 0.0);
CPPUNIT_ASSERT(converted[i + 32768] >= -1.0);
CPPUNIT_ASSERT(converted[i + 32768] <= 0.0);
}
for (int i = 0; i < 32768; i++) {
CPPUNIT_ASSERT(converted[i+32768] >= 0.0);
CPPUNIT_ASSERT(converted[i+32768] <= 1.0);
CPPUNIT_ASSERT(converted[i + 32768] >= 0.0);
CPPUNIT_ASSERT(converted[i + 32768] <= 1.0);
}
}
void DelayDetectionTest::testDownSamplingData()
{
SFLDataFormat data[32768*2];
float converted[32768*2];
float resampled[32768*2];
SFLDataFormat data[32768 * 2];
float converted[ARRAYSIZE(data)];
float resampled[ARRAYSIZE(data)];
for (int i = -32768; i < 32768; i++)
data[i+32768] = i;
data[i + 32768] = i;
delaydetect_.convertInt16ToFloat32(data, converted, 32768*2);
delaydetect_.convertInt16ToFloat32(data, converted, 32768 * 2);
delaydetect_.downsampleData(converted, resampled, 32768*2, 8);
delaydetect_.downsampleData(converted, resampled, 32768 * 2, 8);
for (int i = 0; i < 32768/8; i++) {
for (size_t i = 0; i < 32768 / 8; ++i) {
CPPUNIT_ASSERT(resampled[i] >= -1.0);
CPPUNIT_ASSERT(resampled[i] <= 0.0);
}
for (int i = 32768/8+1; i < 32768/4; i++) {
for (size_t i = 32768 / 8 + 1; i < 32768 / 4; i++) {
CPPUNIT_ASSERT(resampled[i] >= 0.0);
CPPUNIT_ASSERT(resampled[i] <= 1.0);
}
......@@ -197,25 +191,16 @@ void DelayDetectionTest::testDownSamplingData()
void DelayDetectionTest::testDelayDetection()
{
int delay = 100;
SFLDataFormat spkr[WINDOW_SIZE];
memset(spkr, 0, sizeof(SFLDataFormat) *WINDOW_SIZE);
spkr[0] = 32000;
spkr[1] = 32000;
spkr[2] = 32000;
spkr[3] = 32000;
spkr[4] = 32000;
memset(spkr, 0, sizeof spkr);
for (size_t i = 0; i < 5; ++i)
spkr[i] = 32000;
SFLDataFormat mic[DELAY_BUFF_SIZE];
memset(mic, 0, sizeof(SFLDataFormat) *DELAY_BUFF_SIZE);
mic[delay] = 32000;
mic[delay+1] = 32000;
mic[delay+2] = 32000;
mic[delay+3] = 32000;
mic[delay+4] = 32000;
delaydetect_.putData(spkr, WINDOW_SIZE);
delaydetect_.process(mic, DELAY_BUFF_SIZE);
memset(mic, 0, sizeof mic);
for (size_t delay = 100; delay < 105; ++delay)
mic[delay] = 32000;
delaydetect_.putData(spkr, ARRAYSIZE(spkr));
delaydetect_.process(mic, ARRAYSIZE(mic));
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment