Exemplo n.º 1
0
static void RegisterNewClass (IAAFDictionary * pDictionary)
{
  //
  // Create a new kind of filler with no new properties.
  //

  // Look up parent class
  IAAFClassDefSP pFillClass;
  CAAFBuiltinDefs defs (pDictionary);
  checkResult (pDictionary->LookupClassDef (AUID_AAFFiller, &pFillClass));
  assert (pFillClass);

  // Create a foward class reference to the new filler class (not really required).
  // This is just to test the methods on Dictionary that implement foward class
  // references.
  checkResult (pDictionary->CreateForwardClassReference(kClassAUID_NewFill));

  // Try a negative test: Attempt to create a forward class reference with the
  // same class id. This should fail.
  checkExpression(FAILED(pDictionary->CreateForwardClassReference(kClassAUID_NewFill)), AAFRESULT_TEST_FAILED);

  // Make sure that the new filler class is recognized as a foward class reference.
  aafBoolean_t isaFowardReference;
  checkResult (pDictionary->HasForwardClassReference(kClassAUID_NewFill, &isaFowardReference));
  checkExpression (kAAFTrue == isaFowardReference, AAFRESULT_TEST_FAILED);

  // Create new object for our new filler class, and initialize it.
  IAAFClassDefSP pNewFillClass;
  checkResult (pDictionary->CreateMetaInstance(AUID_AAFClassDef,
                                               IID_IAAFClassDef,
                                               (IUnknown **)&pNewFillClass));
  checkResult (pNewFillClass->Initialize (kClassAUID_NewFill,
										  pFillClass,
										  L"New Filler",
										  kAAFTrue));

  // Get type def for uint32
  IAAFTypeDefSP ptd;
  checkResult (pDictionary->LookupTypeDef (kAAFTypeID_UInt32,
										   &ptd));
  assert (ptd);

  // Initialize new property
  checkResult
	(pNewFillClass->RegisterNewPropertyDef (kPropAUID_NewFill_Odor,
											L"Odor",
											ptd,
											kAAFFalse,  // mandatory
											kAAFFalse,  // not a unique identifer
											0));

  // Register it in the dictionary.
  checkResult (pDictionary->RegisterClassDef (pNewFillClass));
 
  // If RegisterClassDef succeeds then there should be no foward reference
  // to kClassAUID_NewFill. Test: Make sure that the new filler class is no longer 
  // recognized as a foward class reference.
  checkResult (pDictionary->HasForwardClassReference(kClassAUID_NewFill, &isaFowardReference));
  checkExpression (kAAFFalse == isaFowardReference, AAFRESULT_TEST_FAILED);
}
Exemplo n.º 2
0
static void CheckWeakReference(
  IAAFFiller * pFiller,
  IAAFMob * pTargetMob)
{
  IAAFObjectSP pObject;
  checkResult(pFiller->QueryInterface(IID_IAAFObject, (void **)&pObject));

  IAAFClassDefSP pClassDef;
  checkResult(pObject->GetDefinition(&pClassDef));
  IAAFPropertyDefSP pWeakRefPropertyDef;
  checkResult(pClassDef->LookupPropertyDef(kAAFPropID_TestWeakReferenceToMob, &pWeakRefPropertyDef));
  
  // Get weak reference value from the filler object.
  IAAFPropertyValueSP pWeakReferenceValue;
  checkResult(pObject->GetPropertyValue(pWeakRefPropertyDef, &pWeakReferenceValue));

  // Make sure the value's type definition is in fact a weak reference.
  IAAFTypeDefSP pPropertyType;
  checkResult(pWeakReferenceValue->GetType(&pPropertyType));
  IAAFTypeDefWeakObjRefSP pWeakReferenceType;
  checkResult(pPropertyType->QueryInterface(IID_IAAFTypeDefWeakObjRef, (void **)&pWeakReferenceType));

  // Create the weak reference property value.  
  IAAFTypeDefObjectRefSP pObjectReferenceType;
  checkResult(pWeakReferenceType->QueryInterface(IID_IAAFTypeDefObjectRef, (void **)&pObjectReferenceType));
  
  // Make sure the target of the weak reference is a type definition.
  IAAFMobSP pFoundTargetMob;
  checkResult(pObjectReferenceType->GetObject(pWeakReferenceValue, IID_IAAFMob, (IUnknown **)&pFoundTargetMob));
  
  // Verify that the object that was the target of the weak reference was the
  // type that we were expecting.
  checkExpression(EqualObjects(pFoundTargetMob, pTargetMob), AAFRESULT_TEST_FAILED);
}
Exemplo n.º 3
0
static void CreateWeakReference(
  IAAFFiller * pFiller,
  IAAFMob * pTargetMob)
{
  IAAFObjectSP pObject;
  checkResult(pFiller->QueryInterface(IID_IAAFObject, (void **)&pObject));

  IAAFClassDefSP pClassDef;
  checkResult(pObject->GetDefinition(&pClassDef));
  IAAFPropertyDefSP pWeakRefPropertyDef;
  checkResult(pClassDef->LookupPropertyDef(kAAFPropID_TestWeakReferenceToMob, &pWeakRefPropertyDef));
  
  // Make sure the property's type definition is in fact a weak reference.
  IAAFTypeDefSP pPropertyType;
  checkResult(pWeakRefPropertyDef->GetTypeDef(&pPropertyType));
  IAAFTypeDefWeakObjRefSP pWeakReferenceType;
  checkResult(pPropertyType->QueryInterface(IID_IAAFTypeDefWeakObjRef, (void **)&pWeakReferenceType));

  // Create the weak reference property value.  
  IAAFTypeDefObjectRefSP pObjectReferenceType;
  checkResult(pWeakReferenceType->QueryInterface(IID_IAAFTypeDefObjectRef, (void **)&pObjectReferenceType));
  IAAFPropertyValueSP pWeakReferenceValue;
  checkResult(pObjectReferenceType->CreateValue(pTargetMob, &pWeakReferenceValue));
  
  // Install the new weak reference value into the filler object.
  checkResult(pObject->SetPropertyValue(pWeakRefPropertyDef, pWeakReferenceValue));
}
Exemplo n.º 4
0
static void ChangeWeakReference(
  IAAFFiller * pFiller,
  IAAFTypeDef * pTargetType)
{
  IAAFObjectSP pObject;
  checkResult(pFiller->QueryInterface(IID_IAAFObject, (void **)&pObject));

  IAAFClassDefSP pClassDef;
  checkResult(pObject->GetDefinition(&pClassDef));
  IAAFPropertyDefSP pWeakRefPropertyDef;
  checkResult(pClassDef->LookupPropertyDef(kAAFPropID_TestWeakReferenceToType, &pWeakRefPropertyDef));
  
  // Get weak reference value from the filler object.
  IAAFPropertyValueSP pWeakReferenceValue;
  checkResult(pObject->GetPropertyValue(pWeakRefPropertyDef, &pWeakReferenceValue));

  // Make sure the value's type definition is in fact a weak reference.
  IAAFTypeDefSP pPropertyType;
  checkResult(pWeakReferenceValue->GetType(&pPropertyType));
  IAAFTypeDefWeakObjRefSP pWeakReferenceType;
  checkResult(pPropertyType->QueryInterface(IID_IAAFTypeDefWeakObjRef, (void **)&pWeakReferenceType));

  // Create the weak reference property value.  
  IAAFTypeDefObjectRefSP pObjectReferenceType;
  checkResult(pWeakReferenceType->QueryInterface(IID_IAAFTypeDefObjectRef, (void **)&pObjectReferenceType));
  
  // Make sure the target of the weak reference is a type definition.
  checkResult(pObjectReferenceType->SetObject(pWeakReferenceValue, pTargetType));
}
Exemplo n.º 5
0
// Get the stream property values from the given essence data.
static void Test_LookupEssenceDataStreamPropertyDefinitions(
  IAAFDictionary *pDictionary,
  IAAFPropertyDef **ppDataPropertyDef,
  IAAFPropertyDef **ppSampleIndexPropertyDef)
{
 // Find the class definition for components class
  IAAFClassDefSP pEssenceDataClass;
  CheckResult (pDictionary->LookupClassDef (AUID_AAFEssenceData, 
                                            &pEssenceDataClass));

  // Find our property definition
  CheckResult (pEssenceDataClass->LookupPropertyDef (
                                      kAAFPropID_EssenceData_Data,
                                      ppDataPropertyDef));
  CheckResult (pEssenceDataClass->LookupPropertyDef (
                                      kAAFPropID_EssenceData_SampleIndex,
                                      ppSampleIndexPropertyDef));
}
Exemplo n.º 6
0
static HRESULT addCHARTypeToComponent(IAAFDictionary * const pDict)
{
	CAAFBuiltinDefs defs(pDict);
	
	///////////////////////////////////////////////////////////////////////
	//Look up a Class based on a component? or some meaningful class
	IAAFClassDefSP spSomeClass;
	checkResult(pDict->LookupClassDef (AUID_AAFComponent, &spSomeClass));	
	//OK, lets register (and get) a property def, give it a name + typedef, and
	
	//Lookup the TEST_CHAR_TYPE_ID (builtin)!
	IAAFTypeDefSP spTD;
	checkResult(pDict->LookupTypeDef (TEST_CHAR_TYPE_ID, &spTD));
	
	//	Register the Property
	IAAFPropertyDefSP spPropDef;
	checkResult(spSomeClass->RegisterOptionalPropertyDef (TEST_PROP_ID,
		TEST_PROP_NAME,
		spTD,
		&spPropDef));
	
	return S_OK;
}//addCHARTypeToComponent()
Exemplo n.º 7
0
static HRESULT ReadAAFFile(aafWChar* pFileName)
{
  IAAFFileSP           pFile;
  IAAFHeaderSP         pHeader;
  IEnumAAFMobsSP       pMobIter;
  IAAFMobSP            pMob;
  IEnumAAFMobSlotsSP   pSlotIter;
  IAAFMobSlotSP        pSlot;
  IAAFComponentSP      pComp;
  IAAFSegmentSP        pSegment;
  IAAFDataDefSP        pDataDef;
  IAAFSequenceSP       pSequence;
  IAAFDictionarySP     pDictionary;
  IEnumAAFComponentsSP pCompIter;
  aafNumSlots_t        numMobs;
  aafSearchCrit_t      criteria;
  HRESULT              hr = S_OK;
	
  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));
	  CAAFBuiltinDefs defs (pDictionary);

	  // Check a data definition from a composition MOB in order to test weak references
	  criteria.searchTag = kAAFByMobKind;
	  criteria.tags.mobKind = kAAFCompMob;
	  checkResult(pHeader->GetMobs(&criteria, &pMobIter));
	  while (pMobIter && pMobIter->NextOne(&pMob) == AAFRESULT_SUCCESS)
		{					
		  // Enumerate the first MOB slot for this MOB
		  checkResult(pMob->GetSlots(&pSlotIter));
		  checkResult(pSlotIter->NextOne(&pSlot));

		  checkResult(pSlot->GetSegment(&pSegment));
		  checkResult(pSegment->QueryInterface(IID_IAAFSequence, (void **) &pSequence));
		  checkResult(pSequence->GetComponents(&pCompIter));
		  checkResult(pCompIter->NextOne(&pComp));

		  aafBool  testBool;

		  checkResult(pComp->GetDataDef(&pDataDef));
		  checkResult(pDataDef->IsSoundKind(&testBool));
		  checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED);

		  checkResult(pDataDef->IsDataDefOf(defs.ddkAAFPictureWithMatte(), &testBool));
		  checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED);
		
		  // Make sure first component is a filler, and is our extended
		  // class.  To do that, we'll compare the class def we looked
		  // up in the dict, with the one we got from the new object.
		  //
		  // First get the class from the object.
		  IAAFFillerSP pFill;
		  checkResult(pComp->QueryInterface(IID_IAAFFiller,
											(void **) &pFill));
		  assert (pFill);

		  IAAFObjectSP pObj;
		  checkResult(pFill->QueryInterface(IID_IAAFObject,
											(void **) &pObj));
		  assert (pObj);
		  IAAFClassDefSP pClassFromObj;
		  checkResult (pObj->GetDefinition (&pClassFromObj));
		  assert (pClassFromObj);
		  IUnknownSP pUnkFromObj;
		  checkResult(pClassFromObj->QueryInterface(IID_IUnknown,
													(void **) &pUnkFromObj));

		  // Now get the class from the dict
		  IAAFClassDefSP pClassFromDict;
		  checkResult (pDictionary->LookupClassDef (kClassAUID_NewFill,
													&pClassFromDict));
		  assert (pClassFromDict);
		  IUnknownSP pUnkFromDict;
		  checkResult(pClassFromDict->QueryInterface(IID_IUnknown,
													 (void **) &pUnkFromDict));

		  // Compare class from object with class from dict.  Compare
		  // using IUnknown pointers.
		  assert (((IUnknown*)pUnkFromObj) ==
				  ((IUnknown*)pUnkFromDict));

		  // To test GetClassDefinitions(), try explicit lookup.
		  IEnumAAFClassDefsSP pClassDefEnum;
		  checkResult (pDictionary->GetClassDefs (&pClassDefEnum));
		  bool found = false;
		  IAAFClassDefSP cd;
		  while (SUCCEEDED (pClassDefEnum->NextOne (&cd)))
			{
			  IAAFMetaDefinitionSP def;
			  checkResult(cd->QueryInterface(IID_IAAFMetaDefinition,
											 (void **) &def));
			  aafUID_t classid;
			  checkResult (def->GetAUID (&classid));
			  if (EqualGUID (&classid, &kClassAUID_NewFill))
				{
				  // Found it the hard way.
				  found = true;
				  break;
				}
			}
		  // make sure we found it the hard way.
		  checkExpression(found == kAAFTrue, AAFRESULT_TEST_FAILED);

		  // Get the 'odor' property from our new fill clip.  Make
		  // sure it is set to the value we think it should be
		  // ('42').
		  //
		  // First get the property def from the class.
		  IAAFPropertyDefSP pPropDef;
		  checkResult (pClassFromObj->LookupPropertyDef
					   (kPropAUID_NewFill_Odor,
						&pPropDef));
		  //
		  // Get the property value from the object
		  IAAFPropertyValueSP pPropVal;
		  checkResult (pObj->GetPropertyValue (pPropDef, &pPropVal));
		  // 
		  // We know the property is int32; get the int32 type def
		  IAAFTypeDefSP ptd;
		  checkResult (pDictionary->LookupTypeDef
					   (kAAFTypeID_UInt32,
						&ptd));
		  IAAFTypeDefIntSP pTDUint32;
		  checkResult(ptd->QueryInterface(IID_IAAFTypeDefInt,
										  (void **) &pTDUint32));
		  assert (pTDUint32);
		  //
		  // Ask the typedef to interpret this property value for us.
		  aafUInt32 odorValue = 0;
		  checkResult (pTDUint32->GetInteger
					   (pPropVal,
						(aafMemPtr_t) &odorValue,
						sizeof (odorValue)));
		  //
		  // make sure it's what we expect.
		  assert (42 == odorValue);
		}

	  checkResult (LookupDefs (pDictionary));


	//Test the Lookup KLV and Tagged methods
	IAAFKLVDataDefinition *pKLVLook = NULL;
	IAAFTaggedValueDefinition *pTAGDefLook = NULL;
	IAAFDictionary2 *pDic2 = NULL;	
	IAAFDefObject *pKLVDataDefObj = NULL;
	IAAFDefObject *pTaggedValueDefObj = NULL;
	aafUID_t auid;

	checkResult( pDictionary->QueryInterface( IID_IAAFDictionary2, reinterpret_cast<void**>(&pDic2) ) );
	assert(pDic2);
	
	//test LookUpKLV()
	if(pDic2->LookupKLVDataDef(KLVDef_TestData, &pKLVLook) != AAFRESULT_SUCCESS)
		checkResult(AAFRESULT_TEST_FAILED);

	checkResult( pKLVLook->QueryInterface( IID_IAAFDefObject, reinterpret_cast<void**>(&pKLVDataDefObj) ) );
	assert(pKLVDataDefObj);
	
	//ensure the KLVLook auid is equal to KLVDef_TestData auid
	checkResult(pKLVDataDefObj->GetAUID(&auid));

	if(auid != KLVDef_TestData)
		checkResult(AAFRESULT_TEST_FAILED);

	//test LookUpTagged()
	if(pDic2->LookupTaggedValueDef(TAGDef_TestData, &pTAGDefLook) != AAFRESULT_SUCCESS)
		checkResult(AAFRESULT_TEST_FAILED);

	checkResult( pTAGDefLook->QueryInterface( IID_IAAFDefObject, reinterpret_cast<void**>(&pTaggedValueDefObj) ) );
	assert(pTaggedValueDefObj);
	
	//ensure the TAGDefLook auid is equal to TAGDef_TestData auid
	checkResult(pTaggedValueDefObj->GetAUID(&auid));

	if(auid != TAGDef_TestData)
		checkResult(AAFRESULT_TEST_FAILED);


	//cleanup	
	pDic2->Release();
	pDic2 = NULL;
	pKLVLook->Release();
	pKLVLook = NULL;
	pTAGDefLook->Release();
	pTAGDefLook = NULL;
	pKLVDataDefObj->Release();
	pKLVDataDefObj = NULL;
	pTaggedValueDefObj->Release();
	pTaggedValueDefObj = NULL;

	}

  catch (HRESULT& rResult)
	{
	  hr = rResult;
	}
	
  // Cleanup and return.
  if (pFile)
	{
	  pFile->Close();
	}
  return 	hr;
}
Exemplo n.º 8
0
static HRESULT CreateAAFFile(
    aafWChar * pFileName,
    aafUID_constref fileKind,
    testRawStorageType_t rawStorageType,
    aafProductIdentification_constref productID)
{
  IAAFFileSP       pFile;
  IAAFHeaderSP     pHeader;
  IAAFDictionarySP pDictionary;
  IAAFMobSP        pMob;
  IAAFTimelineMobSlotSP    pMobSlot;
  IAAFSequenceSP   pSequence;
  IAAFSegmentSP    pSegment;
  IAAFComponentSP  pComponent;
  int              i;
  HRESULT          hr = S_OK;
	
	
  try
	{  
	  // Remove the previous test file if any.
	  RemoveTestFile(pFileName);
		
	  // Create the AAF file
	  checkResult(CreateTestFile( pFileName, fileKind, rawStorageType, productID, &pFile ));

	  // Get the AAF file header.
	  checkResult(pFile->GetHeader(&pHeader));

	  // Get the AAF Dictionary so that we can create valid AAF objects.
	  checkResult(pHeader->GetDictionary(&pDictionary));
		
	  // Create a new class, and register it in the dictionary.
	  RegisterNewClass (pDictionary);
	  CAAFBuiltinDefs defs (pDictionary);

	  // Create a Composition Mob
	  checkResult(defs.cdCompositionMob()->
				  CreateInstance(IID_IAAFMob, 
								 (IUnknown **)&pMob));
		
	  checkResult(pMob->SetMobID(TEST_MobID));
	  checkResult(pMob->SetName(L"AAFDictionaryTest"));
		
	  // Add mob slot w/ Sequence
	  checkResult(defs.cdSequence()->
				  CreateInstance(IID_IAAFSequence, 
								 (IUnknown **)&pSequence));		

	  checkResult(pSequence->Initialize(defs.ddkAAFPicture()));
		
	  //
	  //	Add some segments.  Need to test failure conditions
	  //	(i.e. starting/ending w/ transition, two trans back
	  //	to back).
	  //
	  for(i = 0; i < kNumComponents; i++)
		{
		  aafLength_t		len = 10;
			
		  // For the first component, make it our extended filler.
		  if(i == 0)
			{
			  IAAFClassDefSP pNewFillClassDef;
			  checkResult(pDictionary->LookupClassDef(kClassAUID_NewFill,
													  &pNewFillClassDef));
			  checkResult
				(pNewFillClassDef->CreateInstance(IID_IAAFComponent, 
												  (IUnknown**)&pComponent));
			  checkResult(pComponent->SetDataDef(defs.ddkAAFPictureWithMatte()));
			}
		  else
			{
			  checkResult
				(defs.cdFiller()->CreateInstance(IID_IAAFComponent, 
												 (IUnknown**)&pComponent));

			  checkResult(pComponent->SetDataDef(defs.ddkAAFPicture()));
			}

		  checkResult(pComponent->SetLength(len));
		  checkResult(pSequence->AppendComponent(pComponent));
			
		  // For our first component, set the 'odor' value.  Must be
		  // done after the component has been inserted in sequence.
		  if (i == 0)
			{
			  // Set the odor value.
			  //
			  // 1) Get type def for uint32
			  IAAFTypeDefSP ptd;
			  checkResult (pDictionary->LookupTypeDef (kAAFTypeID_UInt32,
													   &ptd));
			  assert (ptd);
			  IAAFTypeDefIntSP pTDUint32;
			  checkResult(ptd->QueryInterface (IID_IAAFTypeDefInt,
											   (void **)&pTDUint32));
			  assert (pTDUint32);

			  // 2) Create a property value for the odor property, and
			  //    set it to 42.
			  IAAFPropertyValueSP pVal;
			  const aafUInt32 odorValue = 42;
			  checkResult (pTDUint32->CreateValue ((aafMemPtr_t) &odorValue,
												   sizeof (odorValue),
												   &pVal));

			  // 3) Look up the property def for the odor property in
			  //    the new fill class.
			  IAAFClassDefSP pNewFillClass;
			  checkResult (pDictionary->LookupClassDef (kClassAUID_NewFill,
														&pNewFillClass));
			  IAAFPropertyDefSP pPropDef;
			  checkResult (pNewFillClass->LookupPropertyDef (kPropAUID_NewFill_Odor,
															 &pPropDef));

			  // 4) Get IAAFObject interface for new fill object, and
			  //    set the odor property.
			  IAAFObjectSP pObj;
			  checkResult(pComponent->QueryInterface (IID_IAAFObject,
													  (void **)&pObj));
			  checkResult (pObj->SetPropertyValue (pPropDef, pVal));
			}
		}

	  checkResult(pSequence->QueryInterface (IID_IAAFSegment, (void **)&pSegment));
		
	  aafRational_t editRate = { 0, 1};
	  checkResult(pMob->AppendNewTimelineSlot(editRate,
											  pSegment,
											  1,
											  L"AAF Test Sequence",
											  0,
											  &pMobSlot));
		
	  // Add the master mob to the file and cleanup
	  pHeader->AddMob(pMob);

	  checkResult (RegisterDefs (pDictionary));

	  testKLVDataDefinitions(pDictionary, pMob);
	  testTaggedDefinitions(pDictionary, pMob);

	}
  catch (HRESULT& rResult)
	{
	  hr = rResult;
	}
	
  // Cleanup and return
  if (pFile)
	{
	  pFile->Save();
	  pFile->Close();
	}
  return hr;
}
Exemplo n.º 9
0
// Create the test file.
void CAAFTypeDefWeakObjRef_create (
    aafCharacter_constptr pFileName,
    aafUID_constref fileKind,
    testRawStorageType_t rawStorageType,
    aafProductIdentification_constref productID)
{
  // Remove the previous test file is one exists
  RemoveTestFile (pFileName);

  // Create the file.
  IAAFFileSP pFile;
  checkResult (CreateTestFile( pFileName, fileKind, rawStorageType, productID, &pFile ));
  
  try
  {
    IAAFHeaderSP pHeader;
    checkResult (pFile->GetHeader (&pHeader));
    
    aafProductVersion_t toolkitVersion;
    checkResult(GetAAFVersions(pHeader, &toolkitVersion, NULL));
    bool weakReferencesSupported = WeakReferencesSupported(toolkitVersion);
    
    IAAFDictionarySP pDictionary;
    checkResult (pHeader->GetDictionary (&pDictionary));
    
    CAAFBuiltinDefs defs (pDictionary);
   
    if (weakReferencesSupported)
    {
      // Create a Weak reference to a type definition.
      IAAFTypeDefWeakObjRefSP pWeakObjRef;
      checkResult(pDictionary->CreateMetaInstance(AUID_AAFTypeDefWeakObjRef,
                                                  IID_IAAFTypeDefWeakObjRef,
                                                  (IUnknown **)&pWeakObjRef));
      
      // Find the class definition for all type definitions.
      IAAFClassDefSP pClassDef;
      checkResult(pDictionary->LookupClassDef(AUID_AAFTypeDef, &pClassDef));
      

  	  aafUID_t targetSet[2];
      targetSet[0] = kAAFPropID_Root_MetaDictionary;
      targetSet[1] = kAAFPropID_MetaDictionary_TypeDefinitions;
      checkResult(pWeakObjRef->Initialize(kAAFTypeID_TestWeakReferenceToType,
                                          pClassDef,
                                          kMyWeakReferenceToTypeDefinitionName,
                                          sizeof(targetSet)/sizeof(aafUID_t),
                                          targetSet));

      // Validate that we make the correct "type" by inspecting the type category.
      IAAFTypeDefSP pTypeDef;
      checkResult(pWeakObjRef->QueryInterface(IID_IAAFTypeDef, (void **)&pTypeDef));

      eAAFTypeCategory_t category;
      checkResult(pTypeDef->GetTypeCategory(&category));
      checkExpression(kAAFTypeCatWeakObjRef == category, AAFRESULT_TEST_FAILED);


    	// Add the new type to the dictionary.
    	checkResult(pDictionary->RegisterTypeDef(pTypeDef));
    	
    	
    	// Now add a new optional weak reference property to an existing class.
    	IAAFClassDefSP pFillerClass;
      IAAFPropertyDefSP pWeakRefPropertyDef;  	
      checkResult(pDictionary->LookupClassDef(AUID_AAFComponent, &pFillerClass));   
      checkResult(pFillerClass->RegisterOptionalPropertyDef(
        kAAFPropID_TestWeakReferenceToType,
        kMyWeakReferenceToTypeDefinitionPropertyName,
        pTypeDef,
        &pWeakRefPropertyDef));      
    }
  

#ifndef NO_REFERENCE_TO_MOB_TEST
    if (weakReferencesSupported)
    {
      // Create a Weak reference to a mob.
      IAAFTypeDefWeakObjRefSP pWeakObjRef;
      checkResult(pDictionary->CreateMetaInstance(AUID_AAFTypeDefWeakObjRef,
                                                  IID_IAAFTypeDefWeakObjRef,
                                                  (IUnknown **)&pWeakObjRef));

      // Find the class definition for all mobs.
      IAAFClassDefSP pClassDef;
      checkResult(pDictionary->LookupClassDef(AUID_AAFMob, &pClassDef));


      aafUID_t targetSet[3];
      targetSet[0] = kAAFPropID_Root_Header;
      targetSet[1] = kAAFPropID_Header_Content;
      targetSet[2] = kAAFPropID_ContentStorage_Mobs;
      checkResult(pWeakObjRef->Initialize(kAAFTypeID_TestWeakReferenceToMob,
                                          pClassDef,
                                          kMyWeakReferenceToMobName,
                                          sizeof(targetSet)/sizeof(aafUID_t),
                                          targetSet));

      // Validate that we make the correct "type" by inspecting the type category.
      IAAFTypeDefSP pTypeDef;
      checkResult(pWeakObjRef->QueryInterface(IID_IAAFTypeDef, (void **)&pTypeDef));

      eAAFTypeCategory_t category;
      checkResult(pTypeDef->GetTypeCategory(&category));
      checkExpression(kAAFTypeCatWeakObjRef == category, AAFRESULT_TEST_FAILED);


      // Add the new type to the dictionary.
      checkResult(pDictionary->RegisterTypeDef(pTypeDef));


      // Now add a new optional weak reference property to an existing class.
      IAAFClassDefSP pFillerClass;
      IAAFPropertyDefSP pWeakRefPropertyDef;
      checkResult(pDictionary->LookupClassDef(AUID_AAFComponent, &pFillerClass));
      checkResult(pFillerClass->RegisterOptionalPropertyDef(
        kAAFPropID_TestWeakReferenceToMob,
        kMyWeakReferenceToMobPropertyName,
        pTypeDef,
        &pWeakRefPropertyDef));
    }
#endif
  


  
    //
	  // Create a Composition Mob
	  //
	  IAAFMobSP pMob;
	  checkResult(defs.cdCompositionMob()->CreateInstance(IID_IAAFMob, (IUnknown **)&pMob));
	  checkResult(pMob->SetMobID(TEST_MobID));
	  checkResult(pMob->SetName(L"TestCompMob"));
	  
	  //
	  // Create a sequence to hold our test fillers components.
	  //
	  IAAFSequenceSP pSequence;
	  checkResult (defs.cdSequence()->CreateInstance(IID_IAAFSequence, (IUnknown **)&pSequence));
	  checkResult (pSequence->Initialize (defs.ddkAAFPicture()));

	  
	  IAAFFillerSP pFiller1;
	  checkResult (defs.cdFiller()->CreateInstance(IID_IAAFFiller, (IUnknown **)&pFiller1));
	  checkResult (pFiller1->Initialize (defs.ddkAAFPicture(), 16));
	
		IAAFFillerSP pFiller2;
	  checkResult (defs.cdFiller()->CreateInstance(IID_IAAFFiller, (IUnknown **)&pFiller2));
	  checkResult (pFiller2->Initialize (defs.ddkAAFPicture(), 32));


    if (weakReferencesSupported)
    {
      // Try adding a weak reference before filler is attached to the file.
      CreateWeakReference(pFiller1, defs.tdInt64());
      CheckWeakReference(pFiller1, defs.tdInt64());
      
      ChangeWeakReference(pFiller1, defs.tdString());
      CreateWeakReference(pFiller2, defs.tdInt32()); 	
    }


    //
    // Add the initialized fillers to the sequence.
    //
    IAAFComponentSP pComp1;
  	checkResult(pFiller1->QueryInterface(IID_IAAFComponent, (void **)&pComp1));
  	checkResult(pSequence->AppendComponent(pComp1));

    IAAFComponentSP pComp2;
  	checkResult(pFiller2->QueryInterface(IID_IAAFComponent, (void **)&pComp2));	
  	checkResult(pSequence->AppendComponent(pComp2));
  	
  	//
  	// Append the sequence as the segment in a new timeline mob slot.
  	//
  	IAAFSegmentSP pSegment;
  	checkResult(pSequence->QueryInterface(IID_IAAFSegment, (void **)&pSegment));
   	aafRational_t  editRate = {30000, 1001};
   	aafCharacter_constptr pSlotName = L"Slot 1";
   	aafPosition_t  origin = 0;
   	IAAFTimelineMobSlotSP pNewSlot;
   	checkResult(pMob->AppendNewTimelineSlot(editRate, pSegment, TEST_SlotID, pSlotName, origin, &pNewSlot));

    //
    // Add to the set of mobs in the file.
    //
    checkResult(pHeader->AddMob(pMob));

#ifndef NO_REFERENCE_TO_MOB_TEST
    if (weakReferencesSupported)
    {
      // The referenced object needs to be attached to the file.
      CreateWeakReference(pFiller1, pMob);
      CheckWeakReference(pFiller1, pMob);
    }
#endif
//    if (weakReferencesSupported)
//    {
//      // Try adding a weak reference after filler is attached to the file.
//      CreateWeakReference(pFiller2, defs.tdInt32());  	
//    }

    // Verify the data before the save.
    CAAFTypeDefWeakObjRef_verify (pHeader);

    checkResult(pFile->Save());
    checkResult(pFile->Close());
  }
  catch (HRESULT& rhr)
  {
    if (pFile) // only save & close the file if it was actually opened
    {
      pFile->Save();  // This may not be safe???
      pFile->Close();
    }
    throw rhr;
  }
  catch (...)
  {
    if (pFile) // only close the file if it was actually opened
      pFile->Close();  
    throw;
  }
}