示例#1
0
static HRESULT CreateAAFFile(
    aafWChar * pFileName,
    aafUID_constref fileKind,
    testRawStorageType_t rawStorageType,
    aafProductIdentification_constref productID)
{
	// IAAFSession 				*pSession = NULL;
	IAAFFile 					*pFile = NULL;
	IAAFHeader 					*pHeader = NULL;
	IAAFDictionary				*pDictionary = NULL;
	IAAFLocator					*pLocator = NULL;
	IAAFLocator					*pLocator2 = NULL;
	IAAFSourceMob 				*pSourceMob = NULL;
	IAAFMob						*pMob = NULL;
	IAAFEssenceDescriptor 		*edesc = NULL;
	IEnumAAFLocators			*pEnumLocators = NULL;
	aafUInt32					numLocators, numLocators2;
	aafUInt32					i;
	HRESULT						hr = AAFRESULT_SUCCESS,
								localhr = AAFRESULT_SUCCESS;
	bool bFileOpen = false;
//	aafUID_t					ddef = kAAFDataDef_Sound;

	try 
	{
	    // Remove the previous test file if any.
	  RemoveTestFile(pFileName);

	  // Create the file.
	  checkResult(CreateTestFile( pFileName, fileKind, rawStorageType, productID, &pFile ));
	  bFileOpen = true;
 
	  // We can't really do anthing in AAF without the header.
	  checkResult(pFile->GetHeader(&pHeader));

	  // Get the AAF Dictionary so that we can create valid AAF objects.
	  checkResult(pHeader->GetDictionary(&pDictionary));
 		
	  CAAFBuiltinDefs defs (pDictionary);

		//Make the first mob
		// Create a Mob
		checkResult(defs.cdSourceMob()->
					CreateInstance(IID_IAAFSourceMob, 
								   (IUnknown **)&pSourceMob));
		
		// Initialize mob properties:
		checkResult(pSourceMob->QueryInterface (IID_IAAFMob, (void **)&pMob));
		checkResult(pMob->SetMobID(TEST_MobID));
		checkResult(pMob->SetName(L"EssenceDescriptorTest"));
		
		// Create the descriptor:
		// instantiate a concrete subclass of EssenceDescriptor
		checkResult(defs.cdAIFCDescriptor()->
					CreateInstance(IID_IAAFEssenceDescriptor, 
								   (IUnknown **)&edesc));		

		IAAFAIFCDescriptor*			pAIFCDesc = NULL;
		checkResult(edesc->QueryInterface (IID_IAAFAIFCDescriptor, (void **)&pAIFCDesc));
		checkResult(pAIFCDesc->SetSummary (5, (unsigned char*)"TEST"));
		pAIFCDesc->Release();
		pAIFCDesc = NULL;

		checkResult(pSourceMob->SetEssenceDescriptor (edesc));


/* CountLocators()	******************************************/
		localhr = AAFRESULT_SUCCESS;
		// Verify AAFRESULT_NULL_PARAM is returned
		if (edesc->CountLocators(NULL) != AAFRESULT_NULL_PARAM)
			localhr = AAFRESULT_TEST_FAILED;		
		
		// Verify that there are no locators
		if (edesc->CountLocators(&numLocators) != AAFRESULT_SUCCESS)
			localhr = AAFRESULT_TEST_FAILED;
		if (0 != numLocators)
			localhr = AAFRESULT_TEST_FAILED;
			
		if (localhr == AAFRESULT_SUCCESS)
			cout<< "	CountLocators() ...		Passed"<< endl;
		else
		{
			cout<< "	CountLocators() ...		FAILED"<< endl;
			hr = AAFRESULT_TEST_FAILED;
		}
		
/* AppendLocator()	******************************************/
		localhr = AAFRESULT_SUCCESS;
		// Verify AAFRESULT_NULL_PARAM is returned
		if (edesc->AppendLocator(NULL) != AAFRESULT_NULL_PARAM)
			localhr = AAFRESULT_TEST_FAILED;		

		// Append and Count a bunch of Locators
		for (i=1; i<=10; i++)
		{
			// Make a concrete subclass of locator, and attach it to
			// the EssenceDescriptor
			checkResult(defs.cdNetworkLocator()->
					CreateInstance(IID_IAAFLocator, 
								   (IUnknown **)&pLocator));	
								   	
			if (edesc->AppendLocator(pLocator) != AAFRESULT_SUCCESS)
				localhr = AAFRESULT_TEST_FAILED;

			// Verify the number of locators
			numLocators = 0;
			edesc->CountLocators(&numLocators);
			if (i != numLocators)
				localhr = AAFRESULT_TEST_FAILED;

			// Verify that locator was appended
			edesc->GetLocatorAt(i-1, &pLocator2);
			if (pLocator2 != pLocator)
				localhr = AAFRESULT_TEST_FAILED;

			pLocator->Release();
			pLocator = 0;
			pLocator2->Release();
			pLocator2 = 0;
		}

		// Make sure we can't add it again

//		if (edesc->AppendLocator(pLocator) != AAFRESULT_OBJECT_ALREADY_ATTACHED)

//			localhr = AAFRESULT_TEST_FAILED;


		if (localhr == AAFRESULT_SUCCESS)
			cout<< "	AppendLocator() ...		Passed"<< endl;
		else
		{
			cout<< "	AppendLocator() ...		FAILED"<< endl;
			hr = AAFRESULT_TEST_FAILED;
		}
			

/* PrependLocator()	******************************************/
		localhr = AAFRESULT_SUCCESS;
		// Verify AAFRESULT_NULL_PARAM is returned
		if (edesc->PrependLocator(NULL) != AAFRESULT_NULL_PARAM)
			localhr = AAFRESULT_TEST_FAILED;		

		for (; i<=20; i++)
		{
			// Make a concrete subclass of locator, and attach it to
			// the EssenceDescriptor
			checkResult(defs.cdNetworkLocator()->
					CreateInstance(IID_IAAFLocator, 
								   (IUnknown **)&pLocator));	
								   	
			if (edesc->PrependLocator(pLocator) != AAFRESULT_SUCCESS)
				localhr = AAFRESULT_TEST_FAILED;

			// Verify the number of locators
			numLocators = 0;
			edesc->CountLocators(&numLocators);
			if (i != numLocators)
				localhr = AAFRESULT_TEST_FAILED;
				
			// Verify that locator was prepended
			edesc->GetLocatorAt(0, &pLocator2);
			if (pLocator2 != pLocator)
				localhr = AAFRESULT_TEST_FAILED;

			pLocator->Release();
			pLocator = 0;
			pLocator2->Release();
			pLocator2 = 0;
		}

		if (localhr == AAFRESULT_SUCCESS)
			cout<< "	PrependLocator() ...	Passed"<< endl;
		else
		{
			cout<< "	PrependLocator() ...	FAILED"<< endl;
			hr = AAFRESULT_TEST_FAILED;
		}


/* InsertLocatorAt()	**************************************/
		localhr = AAFRESULT_SUCCESS;

		// Make a concrete subclass of locator to attach
		checkResult(defs.cdNetworkLocator()->
						CreateInstance(IID_IAAFLocator, 
				   			(IUnknown **)&pLocator));			

		// Verify that we can't remove an index value that is out of range
		if (edesc->InsertLocatorAt(numLocators+1, pLocator) != AAFRESULT_BADINDEX)
			localhr = AAFRESULT_TEST_FAILED;

		// Verify behavior when NULL is passed in
		if (edesc->InsertLocatorAt(1, NULL) != AAFRESULT_NULL_PARAM)
			localhr = AAFRESULT_TEST_FAILED;

		edesc->CountLocators(&numLocators);

		// Insert it
		if (edesc->InsertLocatorAt(0, pLocator) != AAFRESULT_SUCCESS)
			localhr = AAFRESULT_TEST_FAILED;
		// Check it
		edesc->GetLocatorAt(0, &pLocator2);
		if (pLocator2 != pLocator)
			localhr = AAFRESULT_TEST_FAILED;
		// Count it	
		edesc->CountLocators(&numLocators2);
		if (numLocators2 != numLocators+1)
			localhr = AAFRESULT_TEST_FAILED;

		pLocator->Release();
		pLocator = 0;
		pLocator2->Release();
		pLocator2 = 0;


		edesc->CountLocators(&numLocators);
		// Make a concrete subclass of locator to attach in the middle
		checkResult(defs.cdNetworkLocator()->
						CreateInstance(IID_IAAFLocator, 
				   			(IUnknown **)&pLocator));			
		// Insert it
		if (edesc->InsertLocatorAt(numLocators/2, pLocator) != AAFRESULT_SUCCESS)
			localhr = AAFRESULT_TEST_FAILED;
		// Check it
		edesc->GetLocatorAt(numLocators/2, &pLocator2);
		if (pLocator2 != pLocator)
			localhr = AAFRESULT_TEST_FAILED;
		// Count it	
		edesc->CountLocators(&numLocators2);
		if (numLocators2 != numLocators+1)
			localhr = AAFRESULT_TEST_FAILED;

		pLocator->Release();
		pLocator = 0;
		pLocator2->Release();
		pLocator2 = 0;


		edesc->CountLocators(&numLocators);
		// Make a concrete subclass of locator to attach to the end
		checkResult(defs.cdNetworkLocator()->
						CreateInstance(IID_IAAFLocator, 
				   			(IUnknown **)&pLocator));			
		// Insert it.  note: its 0 based so the end is numLocators - 1
		if (edesc->InsertLocatorAt(numLocators-1, pLocator) != AAFRESULT_SUCCESS)
			localhr = AAFRESULT_TEST_FAILED;
		// Check it
		edesc->GetLocatorAt(numLocators-1, &pLocator2);
		if (pLocator2 != pLocator)
			localhr = AAFRESULT_TEST_FAILED;
		// Count it	
		edesc->CountLocators(&numLocators2);
		if (numLocators2 != numLocators+1)
			localhr = AAFRESULT_TEST_FAILED;
			
		// Make sure we can't add it again
		if (edesc->InsertLocatorAt(numLocators+1, pLocator) != AAFRESULT_OBJECT_ALREADY_ATTACHED)
			localhr = AAFRESULT_TEST_FAILED;
		
		pLocator->Release();
		pLocator = 0;
		pLocator2->Release();
		pLocator2 = 0;


		if (localhr == AAFRESULT_SUCCESS)
			cout<< "	InsertLocatorAt() ...	Passed"<< endl;
		else
		{
			cout<< "	InsertLocatorAt() ...	FAILED"<< endl;
			hr = AAFRESULT_TEST_FAILED;
		}
			
			
/* GetLocatorAt()	******************************************/
		localhr = AAFRESULT_SUCCESS;
		edesc->CountLocators(&numLocators);
		// Verify that we can't remove an index value that is out of range
		// note: Locators index is 0 based so the index numLocators is out of range
		if (edesc->GetLocatorAt(numLocators, &pLocator) != AAFRESULT_BADINDEX)
			localhr = AAFRESULT_TEST_FAILED;

		// Verify behavior when NULL is passed in
		if (edesc->GetLocatorAt(1, NULL) != AAFRESULT_NULL_PARAM)
			localhr = AAFRESULT_TEST_FAILED;
			
		for (i=0; i<numLocators; i++)
		{
			pLocator = NULL;
			if (edesc->GetLocatorAt(i, &pLocator) != AAFRESULT_SUCCESS)
				localhr = AAFRESULT_TEST_FAILED;

			if (pLocator != NULL)
				pLocator->Release();
		}
			
		if (localhr == AAFRESULT_SUCCESS)
			cout<< "	GetLocatorAt() ...		Passed"<< endl;
		else
		{
			cout<< "	GetLocatorAt() ...		FAILED"<< endl;
			hr = AAFRESULT_TEST_FAILED;
		}


/* GetLocators()	******************************************/
		if (edesc->GetLocators(NULL) != AAFRESULT_NULL_PARAM)
			localhr = AAFRESULT_TEST_FAILED;	

		pEnumLocators = NULL;
		if (edesc->GetLocators(&pEnumLocators) == AAFRESULT_SUCCESS)
		{
			if (pEnumLocators != NULL)
			{	
				// Try a simple test to confirm
				if (pEnumLocators->NextOne(&pLocator) != AAFRESULT_SUCCESS)					
					localhr = AAFRESULT_TEST_FAILED;
				edesc->GetLocatorAt(0, &pLocator2);

				if (pLocator != pLocator2)
					localhr = AAFRESULT_TEST_FAILED;
				else
					pLocator2->Release();

				pLocator->Release();
				pLocator = 0;

				pEnumLocators->Release();
			}
			else
				localhr = AAFRESULT_TEST_FAILED;			
		}
		else	
			localhr = AAFRESULT_TEST_FAILED;

		if (localhr == AAFRESULT_SUCCESS)
			cout<< "	GetLocators() ...		Passed"<< endl;
		else
		{
			cout<< "	GetLocators() ...		FAILED"<< endl;
			hr = AAFRESULT_TEST_FAILED;
		}


		

/* RemoveLocatorAt()	******************************************/
		localhr = AAFRESULT_SUCCESS;

		// Verify that we can't remove an index value that is out of range
		// note: Locators index is 0 based so the index numLocators is out of range

		if (edesc->RemoveLocatorAt (numLocators) != AAFRESULT_BADINDEX)
			localhr = AAFRESULT_TEST_FAILED;
				
		// Remove locator at beginning, but Release it first
		edesc->CountLocators(&numLocators);

		edesc->GetLocatorAt(0, &pLocator);
		pLocator->Release();

		edesc->GetLocatorAt(1, &pLocator);
		if (edesc->RemoveLocatorAt (0) != AAFRESULT_SUCCESS)
			localhr = AAFRESULT_TEST_FAILED;

		// Verify the count
		edesc->CountLocators(&numLocators2);
		if (numLocators2 != (numLocators - 1))
			localhr = AAFRESULT_TEST_FAILED;

		edesc->GetLocatorAt(0, &pLocator2);
		// Verify that the locators shifted properly
		if (pLocator != pLocator2)
			localhr = AAFRESULT_TEST_FAILED;
		
		pLocator->Release();
		pLocator = 0;
		pLocator2->Release();
		pLocator2 = 0;

		// Remove locator in middle, but Release it first
		edesc->CountLocators(&numLocators);
		edesc->GetLocatorAt((numLocators/2), &pLocator);
		pLocator->Release();

		edesc->GetLocatorAt((numLocators/2 +1), &pLocator);
		if (edesc->RemoveLocatorAt (numLocators/2) != AAFRESULT_SUCCESS)
			localhr = AAFRESULT_TEST_FAILED;
		
		edesc->CountLocators(&numLocators2);
		if (numLocators2 != (numLocators - 1))
			localhr = AAFRESULT_TEST_FAILED;
		
		edesc->GetLocatorAt(numLocators/2, &pLocator2);
		// Verify that the locators shifted properly
		if (pLocator != pLocator2)
			localhr = AAFRESULT_TEST_FAILED;

		pLocator->Release();
		pLocator = 0;
		pLocator2->Release();
		pLocator2 = 0;


		// Remove locator at end, but Release it first
		edesc->CountLocators(&numLocators);
		edesc->GetLocatorAt(numLocators-1, &pLocator);
		pLocator->Release();

		edesc->GetLocatorAt(numLocators-2, &pLocator);
		if (edesc->RemoveLocatorAt (numLocators-1) != AAFRESULT_SUCCESS)
			localhr = AAFRESULT_TEST_FAILED;
		
		edesc->CountLocators(&numLocators2);
		if (numLocators2 != (numLocators - 1))
			localhr = AAFRESULT_TEST_FAILED;

		edesc->GetLocatorAt(numLocators2-1, &pLocator2);
		// Verify that the locators shifted properly
		if (pLocator != pLocator2)
			localhr = AAFRESULT_TEST_FAILED;

		pLocator->Release();
		pLocator = 0;
		pLocator2->Release();
		pLocator2 = 0;

		if (localhr == AAFRESULT_SUCCESS)
			cout<< "	RemoveLocatorAt() ...	Passed"<< endl;
		else
		{
			cout<< "	RemoveLocatorAt() ...	FAILED"<< endl;
			hr = AAFRESULT_TEST_FAILED;
		}

/*************************************************************/


	// Add the source mob into the tree
	checkResult(pHeader->AddMob(pMob));

	}
	catch (HRESULT& rResult)
	{
    hr = rResult;
	}


	// Cleanup object references
	if (edesc)
		edesc->Release();

	if (pMob)
		pMob->Release();

	if (pSourceMob)
		pSourceMob->Release();
	
	if (pDictionary)
		pDictionary->Release();

	if (pHeader)
		pHeader->Release();
			
	if (pFile)
	{	// Close file, clean-up and return
		if (bFileOpen)
		  {
			pFile->Save();
			pFile->Close();
		  }
 		pFile->Release();
	}

	return hr;
}
示例#2
0
static HRESULT ReadAAFFile(aafWChar * pFileName)
{
	// IAAFSession *				pSession = NULL;
	IAAFFile *					pFile = NULL;
	IAAFHeader *				pHeader = NULL;
	IEnumAAFMobs *mobIter = NULL;
	IAAFMob			*aMob = NULL;
	IAAFEssenceDescriptor		*pEdesc = NULL;
	IAAFSourceMob				*pSourceMob = NULL;
	IEnumAAFLocators *			pEnum = NULL;
	IAAFLocator	*				pLocator = NULL;
	aafUInt32					numLocators;
	aafNumSlots_t	numMobs, n;
	HRESULT						hr = AAFRESULT_SUCCESS;
	bool bFileOpen = false;


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

		checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs));
		checkExpression (1 == numMobs, AAFRESULT_TEST_FAILED);

		checkResult(pHeader->GetMobs (NULL, &mobIter));
		for(n = 0; n < numMobs; n++)
		{
			aafWChar		name[500];
			aafMobID_t		mobID;

			checkResult(mobIter->NextOne (&aMob));
			checkResult(aMob->GetName (name, sizeof(name)));
			checkResult(aMob->GetMobID (&mobID));

			checkResult(aMob->QueryInterface (IID_IAAFSourceMob, (void **)&pSourceMob));
			checkResult(pSourceMob->GetEssenceDescriptor (&pEdesc));

			// Verify that there is now one locator
			checkResult(pEdesc->CountLocators(&numLocators));
		 	checkExpression(20 == numLocators, AAFRESULT_TEST_FAILED);
		
			checkResult(pEdesc->GetLocators(&pEnum));

			// This should read the one real locator
			for ( n=0; n<numLocators; n++)
			{
				checkResult(pEnum->NextOne(&pLocator));

				pLocator->Release();
				pLocator = NULL;
			}

     		// We had better not succeed or get an unknown failure.
     		checkExpression(AAFRESULT_NO_MORE_OBJECTS == pEnum->NextOne(&pLocator),
                      AAFRESULT_TEST_FAILED);


			pEnum->Release();
			pEnum = NULL;
			
			pEdesc->Release();
			pEdesc = NULL;

			pSourceMob->Release();
			pSourceMob = NULL;

			aMob->Release();
			aMob = NULL;
		}
	}
	catch (HRESULT& rResult)
	{
    hr = rResult;
	}

	// Cleanup object references
	if (pLocator)
		pLocator->Release();
	
	if (pEnum)
		pEnum->Release();

	if (pEdesc)
		pEdesc->Release();

	if (pSourceMob)
		pSourceMob->Release();
	
	if (aMob)
		aMob->Release();

	if (mobIter)
		mobIter->Release();

	if (pHeader)
		pHeader->Release();
			
	if (pFile)
	{	// Close file, clean-up and return
		if (bFileOpen)
			pFile->Close();
 		pFile->Release();
	}

	/*
	hr = pSession->EndSession();
 	if (AAFRESULT_SUCCESS != hr)
		return hr;
	*/

	return hr;
}
示例#3
0
static HRESULT ReadAAFFile(aafWChar * pFileName)
{
	// IAAFSession *				pSession = NULL;
	IAAFFile *					pFile = NULL;
	IAAFHeader *				pHeader = NULL;
	IAAFEssenceDescriptor		*pEdesc = NULL;
	IAAFSourceMob				*pSourceMob = NULL;
	IEnumAAFLocators *			pEnum = NULL;
	IAAFLocator	*				pLocator = NULL;
	IEnumAAFMobs *mobIter = NULL;
	IAAFMob			*aMob = NULL;
	aafUInt32					numLocators;
	aafUInt32					readLen;
	aafNumSlots_t	numMobs, n;
	HRESULT						hr = AAFRESULT_SUCCESS;
	aafWChar					readBuf[1024];
	bool bFileOpen = false;


	try
	{	  
    // Open the file.
		checkResult(AAFFileOpenExistingRead(pFileName, 0, &pFile));
		bFileOpen = true;

  	checkResult(pFile->GetHeader(&pHeader));

		checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs));
		if (1 != numMobs )
			checkResult(AAFRESULT_TEST_FAILED);


	//!!!	aafSearchCrit_t		criteria;
	//!!!	criteria.searchTag = kAAFNoSearch;

		checkResult(pHeader->GetMobs (NULL, &mobIter));
		for(n = 0; n < numMobs; n++)
		{
			aafWChar		name[500];
			aafMobID_t		mobID;

			checkResult(mobIter->NextOne (&aMob));
			checkResult(aMob->GetName (name, sizeof(name)));
			checkResult(aMob->GetMobID (&mobID));

			checkResult(aMob->QueryInterface (IID_IAAFSourceMob, (void **)&pSourceMob));
			checkResult(pSourceMob->GetEssenceDescriptor (&pEdesc));

			// Verify that there is now one locator
			checkResult(pEdesc->CountLocators(&numLocators));
			if (1 != numLocators)
				checkResult(AAFRESULT_TEST_FAILED);
		
			checkResult(pEdesc->GetLocators(&pEnum));

			// This should read the one real locator
			checkResult(pEnum->NextOne(&pLocator));

			checkResult(pLocator->GetPathBufLen (&readLen));
	//		if(readLen != strlen(TEST_PATH))
				
			checkResult(pLocator->GetPath (readBuf, readLen));

		// This should run off the end
			pLocator->Release();
			pLocator = NULL;
			hr = pEnum->NextOne(&pLocator);
			if (AAFRESULT_NO_MORE_OBJECTS != hr)
				checkResult(hr);
			else
				hr = AAFRESULT_SUCCESS; // reset result
		}


	}
  catch (HRESULT& rResult)
  {
    hr = rResult;
  }

	
	// Cleanup...
	if (pLocator)
		pLocator->Release();

	if (pEnum)
		pEnum->Release();

	if (pEdesc)
		pEdesc->Release();

	if (pSourceMob)
		pSourceMob->Release();

	if (aMob)
		aMob->Release();

	if (mobIter)
		mobIter->Release();

	if (pHeader)
		pHeader->Release();

	if (pFile)
	{
		if (bFileOpen)
			pFile->Close();
		pFile->Release();
	}

	// hr = pSession->EndSession();
	// if (AAFRESULT_SUCCESS != hr)
	//	return hr;

	// if (pSession) pSession->Release();
	
	return 	hr;
}
示例#4
0
static HRESULT CreateAAFFile(
    aafWChar * pFileName,
    aafUID_constref fileKind,
    testRawStorageType_t rawStorageType,
    aafProductIdentification_constref productID)
{
	IAAFFile *					pFile = NULL;
  bool bFileOpen = false;
	IAAFHeader *				pHeader = NULL;
  IAAFDictionary*  pDictionary = NULL;
	IAAFLocator	*				pLocator = NULL;
	IAAFNetworkLocator *		pNetLocator = NULL;
	IAAFSourceMob	*pSourceMob = NULL;
	IAAFMob			*pMob = NULL;
	IAAFEssenceDescriptor *edesc = NULL;
	aafUInt32					numLocators;
	HRESULT						hr = AAFRESULT_SUCCESS;


	try
	{
	    // Remove the previous test file if any.
	    RemoveTestFile(pFileName);


		// Create the file.
		checkResult(CreateTestFile( pFileName, fileKind, rawStorageType, productID, &pFile ));
		bFileOpen = true;
 
		// We can't really do anthing in AAF without the header.
		checkResult(pFile->GetHeader(&pHeader));

		// Get the AAF Dictionary so that we can create valid AAF objects.
		checkResult(pHeader->GetDictionary(&pDictionary));
		CAAFBuiltinDefs defs (pDictionary);
 		
		//Make the first mob
		// Create a Mob
		checkResult(defs.cdSourceMob()->
					CreateInstance(IID_IAAFSourceMob, 
								   (IUnknown **)&pSourceMob));

		checkResult(pSourceMob->QueryInterface (IID_IAAFMob, (void **)&pMob));
		checkResult(pMob->SetMobID(TEST_MobID));
		checkResult(pMob->SetName(L"SourceMOBTest"));
		
		// Create a concrete subclass of EssenceDescriptor
		checkResult(defs.cdAIFCDescriptor()->
					CreateInstance(IID_IAAFEssenceDescriptor, 
								   (IUnknown **)&edesc));
										

		IAAFAIFCDescriptor*			pAIFCDesc = NULL;
		checkResult(edesc->QueryInterface (IID_IAAFAIFCDescriptor, (void **)&pAIFCDesc));
		checkResult(pAIFCDesc->SetSummary (5, (unsigned char*)"TEST"));
		pAIFCDesc->Release();
		pAIFCDesc = NULL;

			// Verify that there are no locators
		checkResult(edesc->CountLocators(&numLocators));
		checkExpression(0 == numLocators, AAFRESULT_TEST_FAILED);

  
		// Make a locator, and attach it to the EssenceDescriptor
		checkResult(defs.cdNetworkLocator()->
					CreateInstance(IID_IAAFNetworkLocator, 
								   (IUnknown **)&pNetLocator));		
		checkResult(pNetLocator->QueryInterface (IID_IAAFLocator, (void **)&pLocator));

		checkResult(pLocator->SetPath (TEST_PATH));
		
		checkResult(edesc->AppendLocator(pLocator));
 		checkResult(pSourceMob->SetEssenceDescriptor (edesc));

		// Verify that there is now one locator
		checkResult(edesc->CountLocators(&numLocators));
		checkExpression(1 == numLocators, AAFRESULT_TEST_FAILED);

		// Add the source mob into the tree
		checkResult(pHeader->AddMob(pMob));

	}
  catch (HRESULT& rResult)
  {
    hr = rResult;
  }

	// cleanup
	if (pLocator)
		pLocator->Release();

	if (pNetLocator)
		pNetLocator->Release();

	if (edesc)
		edesc->Release();

	if (pMob)
		pMob->Release();

	if (pSourceMob)
		pSourceMob->Release();

  if (pDictionary)
    pDictionary->Release();

	if (pHeader)
		pHeader->Release();

	if (pFile)
	{
		if (bFileOpen)
		  {
			pFile->Save();
			pFile->Close();
		  }
		pFile->Release();
	}
	// hr = pSession->EndSession();
 	// if (AAFRESULT_SUCCESS != hr)
	//	return hr;

	// if (pSession) pSession->Release();


	return hr;
}
示例#5
0
static HRESULT ReadAAFFile(aafWChar * pFileName)
{
	// IAAFSession *				pSession = NULL;
	IAAFFile *					pFile = NULL;
	IAAFHeader *				pHeader = NULL;
	IEnumAAFMobs *mobIter = NULL;
	IAAFMob			*aMob = NULL;
	IAAFEssenceDescriptor		*pEdesc = NULL;
	IAAFSourceMob				*pSourceMob = NULL;
	IEnumAAFLocators *			pEnum = NULL;
	IEnumAAFLocators *			pCloneEnum = NULL;
	IAAFLocator	*				pLocator = NULL;
	aafUInt32					numLocators;
	aafNumSlots_t	numMobs, n;
	HRESULT						hr = AAFRESULT_SUCCESS;
	bool bFileOpen = false;
	wchar_t						testname[256];
	IAAFLocator				*	pArray[2] = { NULL, NULL };
	IAAFLocator				**	pArrayPoint = pArray;
	aafUInt32			resultCount;


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

		checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs));
		checkExpression (1 == numMobs, AAFRESULT_TEST_FAILED);

		checkResult(pHeader->GetMobs (NULL, &mobIter));
		for(n = 0; n < numMobs; n++)
		{
			aafWChar		name[500];
			aafMobID_t		mobID;

			checkResult(mobIter->NextOne (&aMob));
			checkResult(aMob->GetName (name, sizeof(name)));
			checkResult(aMob->GetMobID (&mobID));

			checkResult(aMob->QueryInterface (IID_IAAFSourceMob, (void **)&pSourceMob));
			checkResult(pSourceMob->GetEssenceDescriptor (&pEdesc));

			// Verify that there is now two locators
			checkResult(pEdesc->CountLocators(&numLocators));
		  checkExpression(2 == numLocators, AAFRESULT_TEST_FAILED);
		
			checkResult(pEdesc->GetLocators(&pEnum));

			/* Read and check the first element */
			checkResult(pEnum->NextOne(&pLocator));
			checkResult(pLocator->GetPath (testname, sizeof(testname)));
			checkExpression(wcscmp(testname, locator1) == 0, AAFRESULT_TEST_FAILED);
			pLocator->Release();
			pLocator = NULL;

			/**/
			/* Read and check the second element */
			checkResult(pEnum->NextOne(&pLocator));
			checkResult(pLocator->GetPath (testname, sizeof(testname)));
			checkExpression(wcscmp(testname, locator2) == 0, AAFRESULT_TEST_FAILED);
			pLocator->Release();
			pLocator = NULL;
			/*****/
			
			/* Reset, and check the first element again*/
			checkResult(pEnum->Reset());
			checkResult(pEnum->NextOne(&pLocator));
			checkResult(pLocator->GetPath (testname, sizeof(testname)));
			checkExpression(wcscmp(testname, locator1) == 0, AAFRESULT_TEST_FAILED);
			pLocator->Release();
			pLocator = NULL;
			
			/* Reset, Skip, and check the second element again*/
			checkResult(pEnum->Reset());
			checkResult(pEnum->Skip(1));
			checkResult(pEnum->NextOne(&pLocator));
			checkResult(pLocator->GetPath (testname, sizeof(testname)));
			checkExpression(wcscmp(testname, locator2) == 0, AAFRESULT_TEST_FAILED);
			pLocator->Release();
			pLocator = NULL;

			/* Reset, and read both elements */
			checkResult(pEnum->Reset());
			checkResult(pEnum->Next (2, (IAAFLocator **)&pArray, &resultCount));
			checkExpression (resultCount == 2, AAFRESULT_TEST_FAILED);
			checkResult(pArrayPoint[0]->GetPath (testname, sizeof(testname)));
			checkExpression(wcscmp(testname, locator1) == 0, AAFRESULT_TEST_FAILED);
			pArrayPoint[0]->Release();
			pArrayPoint[0] = NULL;
			
			checkResult(pArrayPoint[1]->GetPath (testname, sizeof(testname)));
			checkExpression(wcscmp(testname, locator2) == 0, AAFRESULT_TEST_FAILED);
			pArrayPoint[1]->Release();
			pArrayPoint[1] = NULL;
			
			/* Read one past to make sure that it fails */
			checkExpression(pEnum->NextOne(&pLocator) != AAFRESULT_SUCCESS, AAFRESULT_TEST_FAILED);
			/* Clone the enumerator, and read one element */
			checkResult(pEnum->Clone(&pCloneEnum));
			checkResult(pCloneEnum->Reset());
			checkResult(pCloneEnum->NextOne(&pLocator));
			checkResult(pLocator->GetPath (testname, sizeof(testname)));
			checkExpression(wcscmp(testname, locator1) == 0, AAFRESULT_TEST_FAILED);
			pLocator->Release();
			pLocator = NULL;

			pEnum->Release();
			pEnum = NULL;

			pEdesc->Release();
			pEdesc = NULL;

			pSourceMob->Release();
			pSourceMob = NULL;

			aMob->Release();
			aMob = NULL;
			pCloneEnum->Release();
			pCloneEnum = NULL;

		}
	}
	catch (HRESULT& rResult)
	{
    hr = rResult;
	}

	// Cleanup object references
	if (pLocator)
		pLocator->Release();

	if (pEnum)
		pEnum->Release();

	if (pEdesc)
		pEdesc->Release();

	if (pSourceMob)
		pSourceMob->Release();
	
	if (aMob)
		aMob->Release();

	if (mobIter)
		mobIter->Release();

	if (pHeader)
		pHeader->Release();
			
	if (pFile)
	{	// Close file, clean-up and return
		if (bFileOpen)
			pFile->Close();
 		pFile->Release();
	}

	/*
	hr = pSession->EndSession();
 	if (AAFRESULT_SUCCESS != hr)
		return hr;
	*/

	return hr;
}