📄 mpresourcetest.cpp
字号:
//
//
// Copyright (C) 2004 SIPfoundry Inc.
// Licensed by SIPfoundry under the LGPL license.
//
// Copyright (C) 2004 Pingtel Corp.
// Licensed to SIPfoundry under a Contributor Agreement.
//
// $$
//////////////////////////////////////////////////////////////////////////////
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/TestCase.h>
#include <os/OsDefs.h>
#include <mp/MpResource.h>
#include <mp/MpFlowGraphBase.h>
#include <mp/MpTestResource.h>
/**
* Unittest for MpResource and MpResourceTest
*/
class MpResourceTest : public CppUnit::TestCase
{
CPPUNIT_TEST_SUITE(MpResourceTest);
CPPUNIT_TEST(testCreators);
CPPUNIT_TEST(testEnableAndDisable);
CPPUNIT_TEST(testDoProcessFrame);
CPPUNIT_TEST(testSamplesPerFrameAndSec);
CPPUNIT_TEST(testSetVisitState);
CPPUNIT_TEST(testMessageHandling);
CPPUNIT_TEST(testGetFlowGraph);
CPPUNIT_TEST(testInputOutputInfoAndCounts);
CPPUNIT_TEST(testIsEnabled);
CPPUNIT_TEST(testIsInputOutputConnectedDisconnected);
CPPUNIT_TEST_SUITE_END();
public:
void testCreators()
{
MpTestResource* pResource1 = 0;
MpTestResource* pResource2 = 0;
int portIdx = 0;
// test the constructor
pResource1 = new MpTestResource("Test", 0, 5, 1, 4);
// verify that the initial state of the object is sensible
CPPUNIT_ASSERT(pResource1->getName() == "Test");
CPPUNIT_ASSERT(pResource1->getFlowGraph() == NULL);
CPPUNIT_ASSERT_EQUAL(5, pResource1->maxInputs());
CPPUNIT_ASSERT_EQUAL(4, pResource1->maxOutputs());
CPPUNIT_ASSERT_EQUAL(0, pResource1->minInputs());
CPPUNIT_ASSERT_EQUAL(1, pResource1->minOutputs());
CPPUNIT_ASSERT_EQUAL(0, pResource1->numInputs());
CPPUNIT_ASSERT_EQUAL(0, pResource1->numOutputs());
CPPUNIT_ASSERT(pResource1->isEnabled() == FALSE);
CPPUNIT_ASSERT(pResource1->isInputConnected(0) == FALSE);
CPPUNIT_ASSERT(pResource1->isInputUnconnected(0) == TRUE);
CPPUNIT_ASSERT(pResource1->isOutputConnected(0) == FALSE);
CPPUNIT_ASSERT(pResource1->isOutputUnconnected(0) == TRUE);
// check for sensible initial info for input and output ports
pResource1->getInputInfo(0, (MpResource*&) pResource2, portIdx);
CPPUNIT_ASSERT(pResource2 == NULL);
pResource1->getOutputInfo(1, (MpResource*&) pResource2, portIdx);
CPPUNIT_ASSERT(pResource2 == NULL);
// test the destructor
delete pResource1;
}
void testEnableAndDisable()
{
MpTestResource* pResource = 0;
pResource = new MpTestResource("Test", 0, 5, 1, 4);
// verify that the resource starts out disabled
CPPUNIT_ASSERT(pResource->isEnabled() == FALSE);
// verify that the isEnabled flag is getting passed properly via
// doProcessFrame()
CPPUNIT_ASSERT_EQUAL(0, pResource->numFramesProcessed());
pResource->processFrame();
CPPUNIT_ASSERT_EQUAL(1, pResource->numFramesProcessed());
CPPUNIT_ASSERT(pResource->mLastDoProcessArgs.isEnabled == FALSE);
// now call the enable() method for the resource
pResource->enable();
CPPUNIT_ASSERT(pResource->isEnabled());
pResource->processFrame();
CPPUNIT_ASSERT_EQUAL(2, pResource->numFramesProcessed());
CPPUNIT_ASSERT(pResource->mLastDoProcessArgs.isEnabled);
// now call the disable() method for the resource
pResource->disable();
CPPUNIT_ASSERT(pResource->isEnabled() == FALSE);
pResource->processFrame();
CPPUNIT_ASSERT_EQUAL(3, pResource->numFramesProcessed());
CPPUNIT_ASSERT(pResource->mLastDoProcessArgs.isEnabled == FALSE);
delete pResource;
}
void testDoProcessFrame()
{
MpTestResource* pResource = 0;
pResource = new MpTestResource("Test", 0, 5, 1, 4);
// call processFrame() and then verify that doProcessFrame() is getting
// invoked with sensible arguments
pResource->processFrame();
CPPUNIT_ASSERT_EQUAL(1, pResource->numFramesProcessed());
CPPUNIT_ASSERT(pResource->mLastDoProcessArgs.inBufs != NULL);
CPPUNIT_ASSERT(pResource->mLastDoProcessArgs.outBufs != NULL);
CPPUNIT_ASSERT_EQUAL(pResource->mLastDoProcessArgs.inBufsSize,
pResource->maxInputs());
CPPUNIT_ASSERT_EQUAL(pResource->mLastDoProcessArgs.outBufsSize,
pResource->maxOutputs());
CPPUNIT_ASSERT(pResource->mLastDoProcessArgs.isEnabled == FALSE);
CPPUNIT_ASSERT_EQUAL(80,
pResource->mLastDoProcessArgs.samplesPerFrame);
CPPUNIT_ASSERT_EQUAL(8000,
pResource->mLastDoProcessArgs.samplesPerSecond);
delete pResource;
}
void testSamplesPerFrameAndSec()
{
MpTestResource* pResource = 0;
pResource = new MpTestResource("Test", 0, 5, 1, 4);
// check initial value of samples per frame
pResource->processFrame();
CPPUNIT_ASSERT_EQUAL(1, pResource->numFramesProcessed());
CPPUNIT_ASSERT_EQUAL(80, pResource->mLastDoProcessArgs.samplesPerFrame);
CPPUNIT_ASSERT_EQUAL(8000, pResource->mLastDoProcessArgs.samplesPerSecond);
// change the samples per frame and samples per second
pResource->setSamplesPerFrame(160);
pResource->setSamplesPerSec(32000);
// make sure that the changes have taken effect
pResource->processFrame();
CPPUNIT_ASSERT_EQUAL(2, pResource->numFramesProcessed());
CPPUNIT_ASSERT_EQUAL(160, pResource->mLastDoProcessArgs.samplesPerFrame);
CPPUNIT_ASSERT_EQUAL(32000, pResource->mLastDoProcessArgs.samplesPerSecond);
delete pResource;
}
void testSetVisitState()
{
MpTestResource* pResource = 0;
pResource = new MpTestResource("Test", 0, 5, 1, 4);
pResource->setVisitState(MpResource::NOT_VISITED);
CPPUNIT_ASSERT(MpResource::NOT_VISITED == pResource->getVisitState());
pResource->setVisitState(MpResource::IN_PROGRESS);
CPPUNIT_ASSERT(pResource->getVisitState() == MpResource::IN_PROGRESS);
pResource->setVisitState(MpResource::FINISHED);
CPPUNIT_ASSERT(pResource->getVisitState() == MpResource::FINISHED);
delete pResource;
}
void testMessageHandling()
{
MpTestResource* pResource = 0;
pResource = new MpTestResource("Test", 0, 5, 1, 4);
pResource->sendTestMessage((void*) 1, (void*) 2, 3, 4);
CPPUNIT_ASSERT(pResource->mLastMsg.getMsg() ==
MpFlowGraphMsg::RESOURCE_SPECIFIC_START);
CPPUNIT_ASSERT(pResource->mLastMsg.getMsgDest() == pResource);
CPPUNIT_ASSERT(pResource->mLastMsg.getPtr1() == (void*) 1);
CPPUNIT_ASSERT(pResource->mLastMsg.getPtr2() == (void*) 2);
CPPUNIT_ASSERT_EQUAL(3, pResource->mLastMsg.getInt1());
CPPUNIT_ASSERT_EQUAL(4, pResource->mLastMsg.getInt2());
delete pResource;
}
void testGetFlowGraph()
{
MpFlowGraphBase* pFlowGraph = 0;
MpTestResource* pResource1 = 0;
OsStatus res;
pFlowGraph = new MpFlowGraphBase(30, 30);
pResource1 = new MpTestResource("Test", 0, 5, 1, 4);
// verify that initially, the resource is not associated with a flow graph
CPPUNIT_ASSERT(pResource1->getFlowGraph() == NULL);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -