Пример #1
0
    // lookupResource(), numLinks(), numFramesProcessed() and numResources()
    void testAccessors()
    {
        MpFlowGraphBase*    pFlowGraph = 0;
        MpTestResource* pResource1 = 0;
        MpTestResource* pResource2 = 0;
        MpResource*     pLookupRes = 0;
        OsStatus        res;


        pFlowGraph = new MpFlowGraphBase(80, 8000);
        CPPUNIT_ASSERT(pFlowGraph->numResources() == 0);
        CPPUNIT_ASSERT(pFlowGraph->numLinks() == 0);
        CPPUNIT_ASSERT(pFlowGraph->numFramesProcessed() == 0);

        pResource1 = new MpTestResource("resource1", 4, 4, 4, 4);
        pResource2 = new MpTestResource("resource2", 4, 4, 4, 4);

        res = pFlowGraph->addResource(*pResource1);
        CPPUNIT_ASSERT((res == OS_SUCCESS) && (pFlowGraph->numResources() == 1));

        res = pFlowGraph->addResource(*pResource2);
        CPPUNIT_ASSERT((res == OS_SUCCESS) && (pFlowGraph->numResources() == 2));

        res = pFlowGraph->lookupResource("resource1", pLookupRes);
        CPPUNIT_ASSERT((res == OS_SUCCESS) && (pLookupRes == pResource1));

        res = pFlowGraph->lookupResource("resource2", pLookupRes);
        CPPUNIT_ASSERT((res == OS_SUCCESS) && (pLookupRes == pResource2));

        res = pFlowGraph->lookupResource("unknown", pLookupRes);
        CPPUNIT_ASSERT(res == OS_NOT_FOUND);

        res = pFlowGraph->addLink(*pResource1, 0, *pResource2, 0);
        CPPUNIT_ASSERT((res == OS_SUCCESS) && (pFlowGraph->numLinks() == 1));

        res = pFlowGraph->addLink(*pResource1, 1, *pResource2, 1);
        CPPUNIT_ASSERT((res == OS_SUCCESS) && (pFlowGraph->numLinks() == 2));

        res = pFlowGraph->processNextFrame();
        CPPUNIT_ASSERT((res == OS_SUCCESS) && (pFlowGraph->numFramesProcessed() == 1));

        res = pFlowGraph->processNextFrame();
        CPPUNIT_ASSERT((res == OS_SUCCESS) && (pFlowGraph->numFramesProcessed() == 2));

        res = pFlowGraph->removeLink(*pResource1, 0);
        CPPUNIT_ASSERT((res == OS_SUCCESS) && (pFlowGraph->numLinks() == 1));

        res = pFlowGraph->removeLink(*pResource1, 1);
        CPPUNIT_ASSERT((res == OS_SUCCESS) && (pFlowGraph->numLinks() == 0));

        res = pFlowGraph->removeResource(*pResource2);
        CPPUNIT_ASSERT((res == OS_SUCCESS) && (pFlowGraph->numResources() == 1));

        res = pFlowGraph->removeResource(*pResource1);
        CPPUNIT_ASSERT((res == OS_SUCCESS) && (pFlowGraph->numResources() == 0));

        delete pResource1;
        delete pResource2;
        delete pFlowGraph;
    }
Пример #2
0
    void testLinkAndResource()
    {
        MpFlowGraphBase*    pFlowGraph = 0;
        MpTestResource* pResource1 = 0;
        MpTestResource* pResource2 = 0;
        OsStatus        res;

        // ====== Test the addLink(), addResource(),
        //                 removeLink() and removeResource() methods ======
        pFlowGraph = new MpFlowGraphBase(80, 8000);
        pResource1 = new MpTestResource("test1", 2, 2, 2, 2);
        pResource2 = new MpTestResource("test2", 2, 2, 2, 2);

        res = pFlowGraph->addResource(*pResource1);
        CPPUNIT_ASSERT(res == OS_SUCCESS);

        res = pFlowGraph->addResource(*pResource2);
        CPPUNIT_ASSERT(res == OS_SUCCESS);

        // connect pResource1 output port 0 --> pResource2 input port 0
        res = pFlowGraph->addLink(*pResource1, 0, *pResource2, 0);
        CPPUNIT_ASSERT(res == OS_SUCCESS);

        // try connecting an invalid input port to a valid output port
        res = pFlowGraph->addLink(*pResource1, 2, *pResource2, 1);
        CPPUNIT_ASSERT(res == OS_INVALID_ARGUMENT);

        // try connecting a valid input port to an invalid output port
        res = pFlowGraph->addLink(*pResource1, 1, *pResource2, 2);
        CPPUNIT_ASSERT(res == OS_INVALID_ARGUMENT);

        // try removing a link on a port that doesn't exist
        res = pFlowGraph->removeLink(*pResource1, 2);
        CPPUNIT_ASSERT(res == OS_INVALID_ARGUMENT);

        // remove the link and resources
        res = pFlowGraph->removeLink(*pResource1, 0);
        CPPUNIT_ASSERT(res == OS_SUCCESS);

        res = pFlowGraph->removeResource(*pResource1);
        CPPUNIT_ASSERT(res == OS_SUCCESS);

        res = pFlowGraph->removeResource(*pResource2);
        CPPUNIT_ASSERT(res == OS_SUCCESS);

        delete pResource1;
        delete pResource2;
        delete pFlowGraph;
    }