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; }