// Create a SourceMob with the specified ID and name, // then create an EssenceData object associating it // with the new SourceMob. static void Test_CreateEssenceData( CAAFBuiltinDefs& defs, IAAFHeader* pHeader, const aafMobID_t& mobID, aafCharacter_constptr mobName, IAAFEssenceData** pResult) { IAAFSourceMobSP pSourceMob; IAAFMobSP pMob; IAAFEssenceDescriptorSP pEssenceDesciptor; IAAFEssenceDataSP pEssenceData; // Create a Mob CheckResult(defs.cdSourceMob()->CreateInstance(IID_IAAFSourceMob, (IUnknown **)&pSourceMob)); CheckResult(pSourceMob->QueryInterface(IID_IAAFMob, (void **)&pMob)); CheckResult(pMob->SetMobID(mobID)); CheckResult(pMob->SetName(mobName)); // Create a concrete subclass of EssenceDescriptor CheckResult(defs.cdAIFCDescriptor()->CreateInstance(IID_IAAFEssenceDescriptor, (IUnknown **)&pEssenceDesciptor)); IAAFAIFCDescriptor* pAIFCDesc = NULL; CheckResult(pEssenceDesciptor->QueryInterface (IID_IAAFAIFCDescriptor, (void **)&pAIFCDesc)); CheckResult(pAIFCDesc->SetSummary (5, (unsigned char*)"TEST")); pAIFCDesc->Release(); pAIFCDesc = NULL; CheckResult(pSourceMob->SetEssenceDescriptor (pEssenceDesciptor)); CheckResult(pHeader->AddMob(pMob)); // Attempt to create an AAFEssenceData. CheckResult(defs.cdEssenceData()->CreateInstance(IID_IAAFEssenceData, (IUnknown **)&pEssenceData)); CheckResult(pEssenceData->SetFileMob(pSourceMob)); CheckResult(pHeader->AddEssenceData(pEssenceData)); *pResult = pEssenceData; (*pResult)->AddRef(); }
static HRESULT CreateAAFFile( aafWChar * pFileName, aafUID_constref fileKind, testRawStorageType_t rawStorageType, aafProductIdentification_constref productID) { HRESULT hr = AAFRESULT_SUCCESS; IAAFFile* pFile = NULL; IAAFHeader * pHeader = NULL; IAAFDictionary * pDict = NULL; try { //Do the usual ... RemoveTestFile (pFileName); checkResult (CreateTestFile( pFileName, fileKind, rawStorageType, productID, &pFile )); assert (pFile); checkResult (pFile->GetHeader (&pHeader)); assert (pHeader); checkResult (pHeader->GetDictionary (&pDict)); assert (pDict); CAAFBuiltinDefs defs (pDict); /////////////////////// //checkResult(createCHARType (pDict)); checkResult(addCHARTypeToComponent (pDict)); /////////// //Create a concrete subclass of mob IAAFMobSP spMob; checkResult(defs.cdMasterMob()-> CreateInstance(IID_IAAFMob, (IUnknown **)&spMob)); checkResult(spMob->SetMobID(TEST_MobID)); checkResult(spMob->SetName(L"Some Mob")); //Add a slot - make it our Filler /// first, create Filler IAAFFillerSP spFill; checkResult(defs.cdFiller()->CreateInstance(IID_IAAFFiller, (IUnknown**)&spFill)); checkResult(spFill->Initialize(defs.ddkAAFSound(), 10)); checkResult(createCHARFiller(pDict, spFill)); //seg //QI the filler for its segment IAAFSegmentSP spSeg; checkResult(spFill->QueryInterface (IID_IAAFSegment, (void **)&spSeg)); //Create a concrete subclass of mob slot IAAFMobSlotSP spMobSlot; checkResult(defs.cdStaticMobSlot()-> CreateInstance(IID_IAAFMobSlot, (IUnknown **)&spMobSlot)); //Add the segment to the mobslot checkResult(spMobSlot->SetSegment(spSeg)); checkResult(spMobSlot->SetSlotID(TEST_SLOT_ID)); checkResult(spMobSlot->SetName(TEST_SLOT_NAME)); //Append the slot to the Mob .... checkResult(spMob->AppendSlot (spMobSlot)); //FINALLY .... Add mob to header checkResult (pHeader->AddMob (spMob)); //////////////////// done /!!!!!!!!!!!!!!!!!!!!!! //Verify results right away (during this creation process) .... checkResult(verifyContents (pHeader, pDict, kAAFTrue)); //True => minimal testing } catch (HRESULT & rResult) { hr = rResult; } if (pDict) pDict->Release(); if (pHeader) pHeader->Release(); if (pFile) { stopGap(pFile->Save()); stopGap(pFile->Close()); pFile->Release(); } return hr; }//CreateAAFFile()
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; }
// 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; } }