static HRESULT TestEnumerator(IAAFSequence* pSequence) { IEnumAAFComponents* pCompIter = NULL; IEnumAAFComponents* pCompCloneIter = NULL; IAAFComponent* pComp = NULL; IAAFComponent* pCompArray[kNumComponents] = {0}; aafUInt32 numFetched, i, j; HRESULT hr = S_OK, localhr = S_OK; aafUInt32 numCpnts; pSequence->CountComponents(&numCpnts); if (numCpnts != kNumComponents) return AAFRESULT_TEST_FAILED; hr = pSequence->GetComponents(&pCompIter); if (FAILED(hr)) return AAFRESULT_TEST_FAILED; /* Test the Reset method *******************************/ if (pCompIter->Reset() == AAFRESULT_SUCCESS) cout<< " Reset() ... Passed" << endl; else { cout<< " Reset() ... Failed!!!" << endl; hr = AAFRESULT_TEST_FAILED; } /* Test the NextOne method ******************************/ // Call NextOne once for each mob for a total of numCpnts times for (i=0; i<numCpnts; i++) { if (pCompIter->NextOne(&pComp) == AAFRESULT_SUCCESS) { pComp->Release(); pComp = NULL; } else { localhr = AAFRESULT_TEST_FAILED; } } // Make sure we are at the end if (pCompIter->NextOne(&pComp) != AAFRESULT_NO_MORE_OBJECTS) localhr = AAFRESULT_TEST_FAILED; pCompIter->Reset(); // this should return AAFRESULT_NULL_PARAM if (pCompIter->NextOne(NULL) != AAFRESULT_NULL_PARAM) localhr = AAFRESULT_TEST_FAILED; if (SUCCEEDED(localhr)) cout<< " NextOne() ... Passed" << endl; else { cout<< " NextOne() ... Failed!!!" << endl; hr = AAFRESULT_TEST_FAILED; } /* Test the Skip method ******************************/ localhr = S_OK; pCompIter->Reset(); // skip over each Component one at a time. for (i=0; i<numCpnts; i++) if (pCompIter->Skip(1) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; // Make sure we are at the end. if (pCompIter->Skip(1) != AAFRESULT_NO_MORE_OBJECTS) localhr = AAFRESULT_TEST_FAILED; pCompIter->Reset(); // Skip over multiple Components at a time. for (i=2; i<=numCpnts; i++) { if (pCompIter->Skip(i) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; pCompIter->Reset(); } // Make sure we can't skip past the end. if (pCompIter->Skip(i+1) != AAFRESULT_NO_MORE_OBJECTS) localhr = AAFRESULT_TEST_FAILED; if (SUCCEEDED(localhr)) cout<< " Skip() ... Passed" << endl; else { cout<< " Skip() ... Failed!!!" << endl; hr = AAFRESULT_TEST_FAILED; } /* Next() ******************************************/ localhr = S_OK; pCompIter->Reset(); numFetched = 1; // Iterate thru the Components using Next doing 1 at a time pCompIter->Reset(); for ( i=0; i<numCpnts ;i++) { if (pCompIter->Next(1, &pComp, &numFetched) == AAFRESULT_SUCCESS) { pComp->Release(); pComp = NULL; if (1 != numFetched) localhr = AAFRESULT_TEST_FAILED; } else localhr = AAFRESULT_TEST_FAILED; } // Make sure we are at the end if (pCompIter->Next(1, &pComp, &numFetched) != AAFRESULT_NO_MORE_OBJECTS) localhr = AAFRESULT_TEST_FAILED; // Test the Next method filling out an array of Components numFetched = 0; pCompIter->Reset(); for ( i=2; i<=numCpnts ;i++) { if (pCompIter->Next(i, pCompArray, &numFetched) == AAFRESULT_SUCCESS) { if (i != numFetched) localhr = AAFRESULT_TEST_FAILED; for (j = 0; j < numFetched; j++) { if (pCompArray[j] != NULL) // should have been set { pCompArray[j]->Release(); pCompArray[j] = NULL; } else { localhr = AAFRESULT_TEST_FAILED; } } } else { localhr = AAFRESULT_TEST_FAILED; } pCompIter->Reset(); } // Make sure we can't get more Mobs than numCpnts if (pCompIter->Next(i+1, pCompArray, &numFetched) != AAFRESULT_NO_MORE_OBJECTS) localhr = AAFRESULT_TEST_FAILED; if (numCpnts != numFetched) localhr = AAFRESULT_TEST_FAILED; for (i = 0; i < numCpnts; i++) if (pCompArray[i] != NULL) { pCompArray[i]->Release(); pCompArray[i] = NULL; } else localhr = AAFRESULT_TEST_FAILED; pCompIter->Reset(); pCompIter->Skip(2); // Make sure we can't go past the end to fill the array if (pCompIter->Next(numCpnts, pCompArray, &numFetched) != AAFRESULT_NO_MORE_OBJECTS) localhr = AAFRESULT_TEST_FAILED; if ((numCpnts-2) != numFetched) localhr = AAFRESULT_TEST_FAILED; for (i = 0; i < numCpnts-2; i++) if (pCompArray[i] != NULL) { pCompArray[i]->Release(); pCompArray[i] = NULL; } else localhr = AAFRESULT_TEST_FAILED; pCompIter->Reset(); // Make sure it returns AAFRESULT_NULL_PARAM if (pCompIter->Next(1, NULL, &numFetched) != AAFRESULT_NULL_PARAM) localhr = AAFRESULT_TEST_FAILED; // Make sure it returns AAFRESULT_NULL_PARAM if (pCompIter->Next(1, pCompArray, NULL) != AAFRESULT_NULL_PARAM) localhr = AAFRESULT_TEST_FAILED; if (SUCCEEDED(localhr)) cout<< " Next() ... Passed" << endl; else { cout<< " Next() ... Failed!!!" << endl; hr = AAFRESULT_TEST_FAILED; } /* Clone() ************************************/ // Test the Clone method with with enumerator at begining localhr = S_OK; pCompIter->Reset(); if (pCompIter->Clone(&pCompCloneIter) == AAFRESULT_SUCCESS) { for (i=0; i < numCpnts; i++) { if (pCompCloneIter->NextOne(&pComp) == AAFRESULT_SUCCESS) { pComp->Release(); pComp = NULL; } else localhr = AAFRESULT_TEST_FAILED; } if (pCompCloneIter->NextOne(&pComp) != AAFRESULT_NO_MORE_OBJECTS) localhr = AAFRESULT_TEST_FAILED; pCompCloneIter->Reset(); if (pCompCloneIter->Next(numCpnts, pCompArray, &numFetched) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; if (numCpnts != numFetched) localhr = AAFRESULT_TEST_FAILED; for (i = 0; i < numCpnts; i++) { if (pCompArray[i] != NULL) { pCompArray[i]->Release(); pCompArray[i] = NULL; } else localhr = AAFRESULT_TEST_FAILED; } pCompCloneIter->Reset(); if (pCompCloneIter->Next(numCpnts+1, pCompArray, &numFetched) != AAFRESULT_NO_MORE_OBJECTS) localhr = AAFRESULT_TEST_FAILED; if (numCpnts != numFetched) localhr = AAFRESULT_TEST_FAILED; for (i = 0; i < numCpnts; i++) { if (pCompArray[i] != NULL) { pCompArray[i]->Release(); pCompArray[i] = NULL; } else localhr = AAFRESULT_TEST_FAILED; } pCompCloneIter->Reset(); pCompCloneIter->Skip(1); if (pCompCloneIter->Next(numCpnts, pCompArray, &numFetched) != AAFRESULT_NO_MORE_OBJECTS) localhr = AAFRESULT_TEST_FAILED; if ((numCpnts-1) != numFetched) localhr = AAFRESULT_TEST_FAILED; for (i = 0; i < numCpnts-1; i++) { if (pCompArray[i] != NULL) { pCompArray[i]->Release(); pCompArray[i] = NULL; } else localhr = AAFRESULT_TEST_FAILED; } pCompCloneIter->Release(); pCompCloneIter = NULL; } else localhr = AAFRESULT_TEST_FAILED; // Test the Clone method with with enumerator at end. // Indirectly tests the Skip and Reset methods. pCompIter->Reset(); pCompIter->Skip(numCpnts-1); if (pCompIter->Clone(&pCompCloneIter) == AAFRESULT_SUCCESS) { if (pCompCloneIter->NextOne(&pComp) == AAFRESULT_SUCCESS) { pComp->Release(); pComp = NULL; } if (pCompCloneIter->NextOne(&pComp) != AAFRESULT_NO_MORE_OBJECTS) localhr = AAFRESULT_TEST_FAILED; pCompCloneIter->Release(); pCompCloneIter = NULL; } else localhr = AAFRESULT_TEST_FAILED; // Test the Clone method with with enumerator in the middle. // Indirectly tests the Skip and Reset methods. pCompIter->Reset(); pCompIter->Skip(numCpnts-2); if (pCompIter->Clone(&pCompCloneIter) == AAFRESULT_SUCCESS) { pCompCloneIter->Skip(1); if (pCompCloneIter->NextOne(&pComp) == AAFRESULT_SUCCESS) { pComp->Release(); pComp = NULL; } else localhr = AAFRESULT_TEST_FAILED; if (pCompCloneIter->NextOne(&pComp) != AAFRESULT_NO_MORE_OBJECTS) localhr = AAFRESULT_TEST_FAILED; pCompCloneIter->Release(); pCompCloneIter = NULL; } else localhr = AAFRESULT_TEST_FAILED; pCompIter->Reset(); if (pCompIter->Clone(&pCompCloneIter) == AAFRESULT_SUCCESS) { if (pCompCloneIter->Next(1, NULL, &numFetched) != AAFRESULT_NULL_PARAM) localhr = AAFRESULT_TEST_FAILED; if (pCompCloneIter->Next(1, pCompArray, NULL) != AAFRESULT_NULL_PARAM) localhr = AAFRESULT_TEST_FAILED; pCompCloneIter->Release(); pCompCloneIter = NULL; } else localhr = AAFRESULT_TEST_FAILED; if (SUCCEEDED(localhr)) cout<< " Clone() ... Passed" << endl; else { cout<< " Clone() ... Failed!!!" << endl; hr = AAFRESULT_TEST_FAILED; } if (pComp) pComp->Release(); if (pCompIter) pCompIter->Release(); if (pCompCloneIter) pCompCloneIter->Release(); for (numCpnts=0; numCpnts < kNumComponents; ++numCpnts) if (pCompArray[numCpnts]) pCompArray[numCpnts]->Release(); return hr; }
static HRESULT ReadAAFFile(aafWChar * pFileName) { // IAAFSession * pSession = NULL; IAAFFile * pFile = NULL; bool bFileOpen = false; IAAFHeader * pHeader = NULL; IAAFDictionary* pDictionary = NULL; IEnumAAFMobs* pMobIter = NULL; IEnumAAFMobSlots* pEnum = NULL; IAAFMob* pMob = NULL; IAAFMobSlot* pMobSlot = NULL; IAAFSegment* pSegment = NULL; IAAFSequence* pSequence = NULL; IAAFTransition* pTransition = NULL; IAAFComponent* pComponent = NULL; IAAFFiller* pFiller = NULL; IAAFOperationGroup* pOperationGroup = NULL; IEnumAAFComponents* pCompIter = NULL; aafLength_t transitionLength; aafPosition_t cutPoint; aafNumSlots_t numMobs; aafUInt32 numComponents = 0; HRESULT hr = S_OK; try { // Open the file checkResult(AAFFileOpenExistingRead(pFileName, 0, &pFile)); bFileOpen = true; // We can't really do anthing in AAF without the header. checkResult(pFile->GetHeader(&pHeader)); // Get the number of mobs in the file (should be one) checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs)); checkExpression(1 == numMobs, AAFRESULT_TEST_FAILED); checkResult(pHeader->GetMobs( NULL, &pMobIter)); while (AAFRESULT_SUCCESS == pMobIter->NextOne(&pMob)) { checkResult(pMob->GetSlots (&pEnum)); while (AAFRESULT_SUCCESS == pEnum->NextOne (&pMobSlot)) { checkResult(pMobSlot->GetSegment (&pSegment)); // Check to see if Segment is a Sequence checkResult(pSegment->QueryInterface(IID_IAAFSequence, (void **) &pSequence)); // It is, so get a Component Iterator checkResult(pSequence->CountComponents(&numComponents)); // Verify that all 3 components(Filler, Transition, Filler) are present checkExpression(numComponents == 3, AAFRESULT_TEST_FAILED); checkResult(pSequence->GetComponents(&pCompIter)); // Now visit each and every one of the components. while(AAFRESULT_SUCCESS == pCompIter->NextOne(&pComponent)) { // Find out what kind of segment we have if ((pComponent->QueryInterface(IID_IAAFTransition, (void **)&pTransition)) == AAFRESULT_SUCCESS) { // This is the transition checkResult(pTransition->GetCutPoint (&cutPoint)); checkResult(pComponent->GetLength(&transitionLength)); checkResult(pTransition->GetOperationGroup(&pOperationGroup)); // Check results !! checkExpression(cutPoint == 0, AAFRESULT_TEST_FAILED); checkExpression(transitionLength == 100, AAFRESULT_TEST_FAILED); pTransition->Release(); pTransition = NULL; } else { // validate that the other segments are Fillers checkResult(pComponent->QueryInterface(IID_IAAFFiller, (void **)&pFiller)); pFiller->Release(); pFiller = NULL; } pComponent->Release(); pComponent = NULL; } pSegment->Release(); pSegment = NULL; pSequence->Release(); pSequence = NULL; pCompIter->Release(); pCompIter = NULL; } pMob->Release(); pMob = NULL; } } catch (HRESULT& rResult) { hr = rResult; } // Cleanup and return if (pTransition) pTransition->Release(); if (pOperationGroup) pOperationGroup->Release(); if (pComponent) pComponent->Release(); if (pSegment) pSegment->Release(); if (pMobSlot) pMobSlot->Release(); if (pSequence) pSequence->Release(); if (pCompIter) pCompIter->Release(); if (pEnum) pEnum->Release(); if (pFiller) pFiller->Release(); if (pMob) pMob->Release(); if (pMobIter) pMobIter->Release(); if (pDictionary) pDictionary->Release(); if (pHeader) pHeader->Release(); if (pFile) { if (bFileOpen) pFile->Close(); pFile->Release(); } return hr; }
static HRESULT ReadAAFFile(aafWChar* pFileName) { IAAFFile* pFile = NULL; IAAFHeader* pHeader = NULL; IEnumAAFMobs* pMobIter = NULL; IAAFMob* pMob; IEnumAAFMobSlots* pSlotIter = NULL; IAAFMobSlot* pSlot = NULL; IAAFComponent* pComp = NULL; IAAFSegment* pSegment = NULL; IAAFDataDef* pDataDef = NULL; IAAFSequence* pSequence = NULL; IAAFDictionary* pDictionary = NULL; IEnumAAFDataDefs* pEnumDataDef = NULL; IEnumAAFDataDefs* pCloneEnum = NULL; IEnumAAFComponents* pCompIter = NULL; IAAFDataDef* pArray[2] = { NULL, NULL }; aafNumSlots_t numMobs; aafInt32 index; aafSearchCrit_t criteria; HRESULT hr = S_OK; aafBool testBool; aafUInt32 resultCount; try { // Open the AAF file checkResult(AAFFileOpenExistingRead(pFileName, 0, &pFile)); // Get the AAF file header. checkResult(pFile->GetHeader(&pHeader)); // Validate that there is only one composition mob. checkResult(pHeader->CountMobs(kAAFCompMob, &numMobs)); checkExpression(1 == numMobs, AAFRESULT_TEST_FAILED); // Get the AAF Dictionary so that we can create valid AAF objects. checkResult(pHeader->GetDictionary(&pDictionary)); // The test can't check the types on these because the order of adding data definitions // is defined by the toolkit, and not the test. !!!Change this to determine the order on // the first two tests, and then use to test the other functions. checkResult(pDictionary->GetDataDefs(&pEnumDataDef)); /* Read and check the first element */ checkResult(pEnumDataDef->NextOne(&pDataDef)); checkResult(pDataDef->IsPictureKind(&testBool)); // checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); checkResult(pDataDef->IsSoundKind(&testBool)); // checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED); pDataDef->Release(); pDataDef = NULL; /**/ /* Read and check the second element */ checkResult(pEnumDataDef->NextOne(&pDataDef)); checkResult(pDataDef->IsSoundKind(&testBool)); // checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); checkResult(pDataDef->IsPictureKind(&testBool)); // checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED); pDataDef->Release(); pDataDef = NULL; /*****/ /* Reset, and check the first element again*/ checkResult(pEnumDataDef->Reset()); checkResult(pEnumDataDef->NextOne(&pDataDef)); checkResult(pDataDef->IsPictureKind(&testBool)); // checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); checkResult(pDataDef->IsSoundKind(&testBool)); // checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED); pDataDef->Release(); pDataDef = NULL; /* Reset, Skip, and check the second element again*/ checkResult(pEnumDataDef->Reset()); checkResult(pEnumDataDef->Skip(1)); checkResult(pEnumDataDef->NextOne(&pDataDef)); checkResult(pDataDef->IsSoundKind(&testBool)); // checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); checkResult(pDataDef->IsPictureKind(&testBool)); // checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED); pDataDef->Release(); pDataDef = NULL; /* Reset, and read both elements */ checkResult(pEnumDataDef->Reset()); checkResult(pEnumDataDef->Next (2, (IAAFDataDef **)&pArray, &resultCount)); checkExpression (resultCount == 2, AAFRESULT_TEST_FAILED); checkResult(pArray[0]->IsPictureKind(&testBool)); // checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); checkResult(pArray[0]->IsSoundKind(&testBool)); // checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED); pArray[0]->Release(); pArray[0] = NULL; checkResult(pArray[1]->IsSoundKind(&testBool)); // checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); checkResult(pArray[1]->IsPictureKind(&testBool)); // checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED); pArray[1]->Release(); pArray[1] = NULL; // /* Read one past to make sure that it fails */ // checkExpression(pEnumDataDef->NextOne(&pDataDef) != AAFRESULT_SUCCESS, AAFRESULT_TEST_FAILED); /* Clone the enumerator, and read one element */ checkResult(pEnumDataDef->Clone(&pCloneEnum)); checkResult(pCloneEnum->Reset()); checkResult(pCloneEnum->NextOne(&pDataDef)); checkResult(pDataDef->IsPictureKind(&testBool)); // checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); checkResult(pDataDef->IsSoundKind(&testBool)); // checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED); pDataDef->Release(); pDataDef = NULL; pCloneEnum->Release(); pCloneEnum = NULL; // Enumerate over Composition MOBs criteria.searchTag = kAAFByMobKind; criteria.tags.mobKind = kAAFCompMob; checkResult(pHeader->GetMobs(&criteria, &pMobIter)); CAAFBuiltinDefs defs (pDictionary); while (pMobIter && pMobIter->NextOne(&pMob) == AAFRESULT_SUCCESS) { aafNumSlots_t numSlots = 0; checkResult(pMob->CountSlots(&numSlots)); checkExpression(1 == numSlots, AAFRESULT_TEST_FAILED); // Enumerate over all MOB slots for this MOB checkResult(pMob->GetSlots(&pSlotIter)); while (pSlotIter && pSlotIter->NextOne(&pSlot) == AAFRESULT_SUCCESS) { aafUInt32 numCpnts; checkResult(pSlot->GetSegment(&pSegment)); checkResult(pSegment->QueryInterface(IID_IAAFSequence, (void **) &pSequence)); checkResult(pSequence->CountComponents(&numCpnts)); checkExpression(numCpnts == kNumComponents, AAFRESULT_TEST_FAILED); checkResult(pSequence->GetComponents(&pCompIter)); numCpnts = 0; index = 0; while (pCompIter && pCompIter->NextOne(&pComp) == AAFRESULT_SUCCESS) { aafBool testBool; numCpnts++; checkResult(pComp->GetDataDef(&pDataDef)); checkResult(pDataDef->IsSoundKind(&testBool)); checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED); checkResult(pDataDef->IsMatteKind(&testBool)); checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED); if(index == 0) // First segment is Picture with Matte, converts to picture { checkResult(pDataDef->IsDataDefOf(defs.ddkAAFPictureWithMatte(), &testBool)); checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); checkResult(pDataDef->IsPictureKind(&testBool)); checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED); checkResult(pDataDef->IsPictureWithMatteKind(&testBool)); checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); checkResult(pDataDef->DoesDataDefConvertTo (defs.ddkAAFPicture(), &testBool)); checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); } else // First segment is Picture, converts from picture with Matte { checkResult(pDataDef->IsDataDefOf(defs.ddkAAFPicture(), &testBool)); checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); checkResult(pDataDef->IsPictureKind(&testBool)); checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); checkResult(pDataDef->IsPictureWithMatteKind(&testBool)); checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED); checkResult(pDataDef->DoesDataDefConvertFrom (defs.ddkAAFPictureWithMatte(), &testBool)); checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); } checkResult(pDataDef->DoesDataDefConvertTo (defs.ddkAAFSound(), &testBool)); checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED); checkResult(pDataDef->DoesDataDefConvertFrom (defs.ddkAAFSound(), &testBool)); checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED); pComp->Release(); pComp = NULL; pDataDef->Release(); pDataDef = NULL; index++; } pCompIter->Release(); pCompIter = NULL; pSequence->Release(); pSequence = NULL; pSegment->Release(); pSegment = NULL; pSlot->Release(); pSlot = NULL; } pSlotIter->Release(); pSlotIter = NULL; pMob->Release(); pMob = NULL; } } catch (HRESULT& rResult) { hr = rResult; } // Cleanup object references if (pComp) pComp->Release(); if (pEnumDataDef) pEnumDataDef->Release(); if (pCloneEnum) pCloneEnum->Release(); if (pCompIter) pCompIter->Release(); if (pArray[0]) pArray[0]->Release(); if (pArray[1]) pArray[1]->Release(); if (pDataDef) pDataDef->Release(); if (pSequence) pSequence->Release(); if (pSegment) pSegment->Release(); if (pSlot) pSlot->Release(); if (pDictionary) pDictionary->Release(); if (pSlotIter) pSlotIter->Release(); if (pMob) pMob->Release(); if (pMobIter) pMobIter->Release(); if (pHeader) pHeader->Release(); if (pFile) { pFile->Close(); pFile->Release(); } return hr; }