コード例 #1
0
// Create the test file.
void CAAFTypeDefWeakObjRef_read (aafCharacter_constptr pFileName) // throw HRESULT
{
  IAAFFileSP pFile;
  IAAFHeaderSP pHeader;
  HRESULT result = S_OK;

  try
  {
    checkResult (AAFFileOpenExistingRead(pFileName, 0, &pFile));
    checkResult (pFile->GetHeader (&pHeader));
    
    CAAFTypeDefWeakObjRef_verify (pHeader);

    result = pFile->Close();
  }
  catch (...)
  {
    if (pFile) // only close the file if it was actually opened
      pFile->Close();  
    throw;
  }
  checkResult(result);
}
コード例 #2
0
// Create the test file.
void CAAFTypeDefStream_read (aafCharacter_constptr pFileName) // throw HRESULT
{
  IAAFFileSP pFile;

  try
  {
    IAAFHeaderSP pHeader;
    IAAFDictionarySP pDictionary;
    IAAFEssenceDataSP pEssenceData;
    IAAFPropertyValueSP pDataPropertyValue;
    IAAFPropertyValueSP pSampleIndexPropertyValue;

    aafUID_t  fileKind;
    aafBool isAAFFile = kAAFFalse;
    CheckResult (AAFFileIsAAFFile(pFileName, &fileKind, &isAAFFile));
    CheckExpression(isAAFFile == kAAFTrue, AAFRESULT_TEST_FAILED);

    CheckResult (AAFFileOpenExistingRead(pFileName, 0, &pFile));
    CheckResult (pFile->GetHeader (&pHeader));
    CheckResult (pHeader->GetDictionary (&pDictionary));

    CAAFBuiltinDefs defs (pDictionary);

#if 1
    // Missing api method!
    CheckResult (pHeader->LookupEssenceData(sMobID[0], &pEssenceData));
#else
    // For this version of the test assume that there is only a single
    // essence data...
    aafUInt32 count;
    CheckResult(pHeader->CountEssenceData(&count));
    CheckExpression(1 == count, AAFRESULT_TEST_FAILED);
    IEnumAAFEssenceDataSP pEnumEssenceData;
    CheckResult(pHeader->EnumEssenceData(&pEnumEssenceData));
    CheckResult(pEnumEssenceData->NextOne(&pEssenceData));
    aafMobID_t testMobID = {{0,0,0,0,0,0,0,0,0,0,0,0},0,0,0,0,
                            {0,0,0,{0,0,0,0,0,0,0,0}}};
    CheckResult(pEssenceData->GetFileMobID(&testMobID));
    CheckExpression(0 == memcmp(&testMobID, &sMobID[0], sizeof(aafMobID_t)),
                    AAFRESULT_TEST_FAILED);  
#endif


    Test_EssenceStreamPropertyValues(pDictionary,
                                     pEssenceData,
                                     &pDataPropertyValue,
                                     &pSampleIndexPropertyValue);

    // Test the required property
    Test_EssenceStreamRead(defs, pDataPropertyValue);

    if(pSampleIndexPropertyValue)
    {
      // Test the optional property
      Test_EssenceStreamRead(defs, pSampleIndexPropertyValue);
    }  


    // Test IAAFTypeDefStream2 methods
    IAAFEssenceDataSP pEssenceData2;

    // sMobID[3] may not be in the file, in the case
    // the file was created by an older test.
    if(pHeader->LookupEssenceData(sMobID[3], &pEssenceData2)==AAFRESULT_SUCCESS)
    {
      IAAFPropertyValueSP pDataPropertyValue2;
      IAAFPropertyValueSP pSampleIndexPropertyValue2;

      Test_EssenceStreamPropertyValues(pDictionary,
                                       pEssenceData2,
                                       &pDataPropertyValue2,
                                       &pSampleIndexPropertyValue2);

    }


    // Test IAAFTypeDefStream3 methods
    IAAFEssenceDataSP pEssenceData3;

    // sMobID[4] may not be in the file, in the case
    // the file was created by an older test.
    if(pHeader->LookupEssenceData(sMobID[4], &pEssenceData3)==AAFRESULT_SUCCESS)
    {
      IAAFPropertyValueSP pDataPropertyValue3;
      IAAFPropertyValueSP pSampleIndexPropertyValue3;

      Test_EssenceStreamPropertyValues(pDictionary,
                                       pEssenceData3,
                                       &pDataPropertyValue3,
                                       &pSampleIndexPropertyValue3);

      Test_KLVStreamParametersOnRead(defs, pDataPropertyValue3);
      Test_EssenceStreamRead(defs, pDataPropertyValue3);
    }


    // Test the case when the stream data size approaches the KLV
    // Alignment Grid (KAG) boundary and leaves some but not enough
    // space to pad to the end of the boundary.
    // (This is a test of edge conditions specific to KLV encoded files.)
    IAAFEssenceDataSP pEssenceData4;

    // sMobID[4] may not be in the file, in the case
    // the file was created by an older test.
    if(pHeader->LookupEssenceData(sMobID[5], &pEssenceData4)==AAFRESULT_SUCCESS)
    {
      IAAFPropertyValueSP pDataPropertyValue4;
      IAAFPropertyValueSP pSampleIndexPropertyValue4;

      Test_EssenceStreamPropertyValues(pDictionary,
                                       pEssenceData4,
                                       &pDataPropertyValue4,
                                       &pSampleIndexPropertyValue4);

      Test_NearKAGBoundaryRead(defs, pDataPropertyValue4);
    }


    CheckResult(pFile->Close());
  }
  catch(AAFRESULT& hr)
  {
    // Ignore failure if file not open
    pFile->Close();
    CheckResult(hr);
  }
}
コード例 #3
0
// Create the test file.
void CAAFTypeDefStream_create (
    aafCharacter_constptr pFileName,
    aafUID_constref fileKind,
    testRawStorageType_t rawStorageType,
    aafProductIdentification_constref productID)
{
  IAAFFileSP pFile;

  try
  {
    IAAFHeaderSP pHeader;
    IAAFDictionarySP pDictionary;
    IAAFSourceMobSP pSourceMob;
    IAAFMobSP pMob;
    IAAFEssenceDescriptorSP pEssenceDesciptor;
    IAAFEssenceDataSP pEssenceData;
    IAAFPropertyValueSP pDataPropertyValue;
    IAAFPropertyValueSP pSampleIndexPropertyValue;

    // Remove the previous test file is one exists
    ::RemoveTestFile (pFileName);

    // Create the file.
    CheckResult (CreateTestFile( pFileName, fileKind, rawStorageType, productID, &pFile ));
    CheckResult (pFile->GetHeader (&pHeader));
    CheckResult (pHeader->GetDictionary (&pDictionary));

    CAAFBuiltinDefs defs (pDictionary);

    // Create an EssenceData object and associated Mob
    Test_CreateEssenceData(defs, pHeader, sMobID[0], sMobName[0], &pEssenceData);

    Test_EssenceStreamPropertyValues(pDictionary,
                                     pEssenceData,
                                     &pDataPropertyValue,
                                     &pSampleIndexPropertyValue);

    // Test the required property
    Test_EssenceStreamWrite(defs, pDataPropertyValue);
    Test_EssenceStreamRead(defs, pDataPropertyValue);

    if (pSampleIndexPropertyValue)
    {
    // Test the optional property
      Test_EssenceStreamWrite(defs, pSampleIndexPropertyValue);
      Test_EssenceStreamRead(defs, pSampleIndexPropertyValue);
    }

    Test_EssenceStreamPullWrite(pFile, defs);

    // Test IAAFTypeDefStream2 methods
    IAAFEssenceDataSP pEssenceData2;
    IAAFPropertyValueSP pDataPropertyValue2;
    IAAFPropertyValueSP pSampleIndexPropertyValue2;

    Test_CreateEssenceData(defs, pHeader, sMobID[3], sMobName[3], &pEssenceData2);

    Test_EssenceStreamPropertyValues(pDictionary,
                                     pEssenceData2,
                                     &pDataPropertyValue2,
                                     &pSampleIndexPropertyValue2);


    // Test IAAFTypeDefStream3 methods
    IAAFEssenceDataSP pEssenceData3;
    IAAFPropertyValueSP pDataPropertyValue3;
    IAAFPropertyValueSP pSampleIndexPropertyValue3;

    Test_CreateEssenceData(defs, pHeader, sMobID[4], sMobName[4], &pEssenceData3);

    Test_EssenceStreamPropertyValues(pDictionary,
                                     pEssenceData3,
                                     &pDataPropertyValue3,
                                     &pSampleIndexPropertyValue3);

    Test_KLVStreamParametersOnWrite(defs, pDataPropertyValue3);
    Test_EssenceStreamWrite(defs, pDataPropertyValue3);
    Test_KLVStreamParametersOnRead(defs, pDataPropertyValue3);
    Test_EssenceStreamRead(defs, pDataPropertyValue3);


    // Test the case when the stream data size approaches the KLV
    // Alignment Grid (KAG) boundary and leaves some but not enough
    // space to pad to the end of the boundary.
    // (This is a test of edge conditions specific to KLV encoded files.)
    IAAFEssenceDataSP pEssenceData4;
    IAAFPropertyValueSP pDataPropertyValue4;
    IAAFPropertyValueSP pSampleIndexPropertyValue4;

    Test_CreateEssenceData(defs, pHeader, sMobID[5], sMobName[5], &pEssenceData4);

    Test_EssenceStreamPropertyValues(pDictionary,
                                     pEssenceData4,
                                     &pDataPropertyValue4,
                                     &pSampleIndexPropertyValue4);

    Test_NearKAGBoundaryWrite(defs, pDataPropertyValue4);
    Test_NearKAGBoundaryRead(defs, pDataPropertyValue4);


    CheckResult(pFile->Save());
    CheckResult(pFile->Close());
  }
  catch(AAFRESULT& hr)
  {
    // Ignore failure if file not open
    pFile->Close();
    CheckResult(hr);
  }
}
コード例 #4
0
ファイル: CAAFGetFileBitsTest.cpp プロジェクト: mcanthony/aaf
static HRESULT GetFileBitsTest (
    aafUID_constref fileKind,
    aafProductIdentification_constref productID)
{
  // Create a memory raw storage and a file on it, to be opened for
  // writing.  We'll use this to get the GetFileBits to be tested.
  IAAFRawStorageSP pWriteStg;
  checkResult
	(AAFCreateRawStorageMemory (kAAFFileAccess_modify,
								&pWriteStg));
  IAAFFileSP pWriteFile;
  checkResult
	(AAFCreateAAFFileOnRawStorage (pWriteStg,
								   kAAFFileExistence_new,
								   kAAFFileAccess_modify,
								   &kAAFFileKind_Aaf4KBinary,
								   0,
								   &productID,
								   &pWriteFile));
  assert (pWriteFile);
  checkExpression (0 != (IAAFFile*)pWriteFile,
				   AAFRESULT_TEST_FAILED);
  
  IAAFRandomFileSP pWriteRandFile;
  checkResult(pWriteFile->QueryInterface(IID_IAAFRandomFile,
										 (void **)&pWriteRandFile));

  checkResult (pWriteFile->Open());
  checkResult (pWriteFile->Save());
  checkResult (pWriteFile->Close());

  //
  // Cool.  Now we can get the GetFileBits interface to test.
  //

  IAAFGetFileBitsSP pgfb;
  checkResult (pWriteRandFile->GetFileBits (&pgfb));

  //
  // test GetSize
  //
  HRESULT hr;

  // null param
  hr = pgfb->GetSize (0);
  checkExpression (AAFRESULT_NULL_PARAM == hr, AAFRESULT_TEST_FAILED);

  // Get the size
  aafUInt64 size = 0;
  checkResult (pgfb->GetSize (&size));
  // we know the file is not empty
  checkExpression (0 != size);

  //
  // test ReadAt
  //

  // null param
  hr = pgfb->ReadAt (0, 1, 0);
  checkExpression (AAFRESULT_NULL_PARAM == hr, AAFRESULT_TEST_FAILED);

  // Offset too large
  aafUInt8 foo[100];
  fillJunk (foo, sizeof (foo));
  checkExpression (testJunk (foo, sizeof (foo)), AAFRESULT_TEST_FAILED);
  hr = pgfb->ReadAt (foo, sizeof (foo), size);
  checkExpression (AAFRESULT_OFFSET_SIZE == hr, AAFRESULT_TEST_FAILED);
  checkExpression (testJunk (foo, sizeof (foo)), AAFRESULT_TEST_FAILED);

  // Size too large
  hr = pgfb->ReadAt (foo, 0x7fffffff, size);
  checkExpression (AAFRESULT_OFFSET_SIZE == hr, AAFRESULT_TEST_FAILED);
  checkExpression (testJunk (foo, sizeof (foo)), AAFRESULT_TEST_FAILED);

  // Size/offset too large
  hr = pgfb->ReadAt (foo, sizeof (foo), size-(sizeof (foo)/2));
  checkExpression (AAFRESULT_OFFSET_SIZE == hr, AAFRESULT_TEST_FAILED);
  checkExpression (testJunk (foo, sizeof (foo)), AAFRESULT_TEST_FAILED);

  // See if we can read at start
  checkResult (pgfb->ReadAt (foo, sizeof (foo), 0));
  checkExpression (!testJunk (foo, sizeof (foo)), AAFRESULT_TEST_FAILED);

  // See if we can read at end
  fillJunk (foo, sizeof (foo));
  checkResult (pgfb->ReadAt (foo, sizeof (foo), size-sizeof(foo)));
  checkExpression (!testJunk (foo, sizeof (foo)), AAFRESULT_TEST_FAILED);

  return AAFRESULT_SUCCESS;
}
コード例 #5
0
static HRESULT ReadRecordNoStructs (const aafWChar * pFileName, int loadingMode)
{
  HRESULT hr = E_FAIL;
  HRESULT temphr;
  IAAFFileSP   pFile;

  try 
	{
	  // Open the file, and get the dictionary.
	  checkResult(AAFFileOpenExistingRead(pFileName, loadingMode, &pFile));
	  IAAFHeaderSP pHeader;
	  checkResult(pFile->GetHeader(&pHeader));
	  IAAFDictionarySP pDict;
	  checkResult (pHeader->GetDictionary(&pDict));
	  CAAFBuiltinDefs defs(pDict);

	  // get the SDK version against which we are testing
	  aafProductVersion_t			testVer;
	  checkResult(pHeader->GetRefImplVersion(&testVer));

	  // Get the type definitions for our new types.
	  IAAFTypeDefSP ptd;
	  checkResult (pDict->LookupTypeDef (sTypeId_Rational16,
										 &ptd));
	  IAAFTypeDefRecordSP ptdr16;
	  checkResult (ptd->QueryInterface (IID_IAAFTypeDefRecord,
										(void**) &ptdr16));

	  checkResult (pDict->LookupTypeDef (sTypeId_Rational16_pair,
										 &ptd));
	  IAAFTypeDefRecordSP ptdr16p;
	  checkResult (ptd->QueryInterface (IID_IAAFTypeDefRecord,
										(void**) &ptdr16p));

	  // Setup to read the Velocity property which is of typed Mixed_t
	  checkResult (pDict->LookupTypeDef (sTypeId_Mixed, &ptd));
	  IAAFTypeDefRecordSP ptdrmixed;
	  checkResult (ptd->QueryInterface (IID_IAAFTypeDefRecord, (void**) &ptdrmixed));

	  IAAFTypeDef * pTempTd = 0;
	  checkResult (ptdr16->QueryInterface (IID_IAAFTypeDef,
										(void**) &pTempTd));
	  CheckMemberTypeEqual (ptdr16p, 0, pTempTd);
          CheckMemberTypeEqual (ptdr16p, 1, pTempTd);
	  pTempTd->Release ();
	  pTempTd = 0;

	  temphr = ptdr16p->GetMemberType (2, &pTempTd);
	  checkExpression (temphr == AAFRESULT_ILLEGAL_VALUE,
					   AAFRESULT_TEST_FAILED);

	  // register variable array of Rational16Pair records
	  IAAFTypeDefVariableArraySP ptdvaarpr;
	  IAAFTypeDefSP ptdarpr;
	  // perform this part only for specified versions
	  if( versionUInt(testVer) >= versionUInt(1,1,1,0) )
	  {
		checkResult (pDict->LookupTypeDef (sTypeId_Rational16_array,&ptdarpr));
		checkResult (ptdarpr->QueryInterface (IID_IAAFTypeDefVariableArray,(void**) &ptdvaarpr));
	  }

	  // Now read the CompositionMob to which we added some optional
	  // properties.
	  IEnumAAFMobsSP pEnumMobs;
	  checkResult (pHeader->GetMobs (0, &pEnumMobs));

	  IAAFMobSP pMob;
	  checkResult (pEnumMobs->NextOne (&pMob));
	  IAAFObjectSP pObj;
	  checkResult (pMob->QueryInterface (IID_IAAFObject,
										 (void**) &pObj));

	  // get the property definitions for the added properties
	  IAAFPropertyDefSP pPdPosA;
	  checkResult (defs.cdCompositionMob()->
				   LookupPropertyDef (sPropertyId_positionA,
									  &pPdPosA));
	  IAAFPropertyDefSP pPdPosB;
	  checkResult (defs.cdCompositionMob()->
				   LookupPropertyDef (sPropertyId_positionB,
									  &pPdPosB));
	  IAAFPropertyDefSP pPdPosC;
	  checkResult (defs.cdCompositionMob()->
				   LookupPropertyDef (sPropertyId_positionC,
									  &pPdPosC));

	  IAAFPropertyValueSP pPVa;
	  checkResult (pObj->GetPropertyValue (pPdPosA, &pPVa));
	  IAAFPropertyValueSP pPVb;
	  checkResult (pObj->GetPropertyValue (pPdPosB, &pPVb));
	  IAAFPropertyValueSP pPVc;
	  checkResult (pObj->GetPropertyValue (pPdPosC, &pPVc));

	  // Read back the value of the Velocity property
	  IAAFPropertyDefSP pPdvelocity;
	  checkResult (defs.cdCompositionMob()->LookupPropertyDef(sPropertyId_velocity, &pPdvelocity));
	  IAAFPropertyValueSP pPVvelocity;
	  checkResult (pObj->GetPropertyValue (pPdvelocity, &pPVvelocity));

	  IAAFPropertyValueSP pPVvelocityAngle, pPVvelocitySpeed;
	  checkResult (ptdrmixed->GetValue (pPVvelocity, 0, &pPVvelocityAngle));
	  checkResult (ptdrmixed->GetValue (pPVvelocity, 1, &pPVvelocitySpeed));
      
	  Mixed_t velocity = {0, 0};
	  IAAFTypeDefSP pTDmem;
	  IAAFTypeDefIntSP pTDIntMem;
	  checkResult (ptdrmixed->GetMemberType (0, &pTDmem));
	  checkResult (pTDmem->QueryInterface (IID_IAAFTypeDefInt,
                                  (void **) &pTDIntMem));
	  checkResult (pTDIntMem->GetInteger (pPVvelocityAngle, 
                                   (aafMemPtr_t)(&velocity.angle), 
                                   sizeof(velocity.angle)));
	  checkResult (ptdrmixed->GetMemberType (1, &pTDmem));
	  checkResult (pTDmem->QueryInterface (IID_IAAFTypeDefInt,
                                      (void **) &pTDIntMem));
	  checkResult (pTDIntMem->GetInteger (pPVvelocitySpeed, 
	                           (aafMemPtr_t)(&velocity.speed),
	                           sizeof(velocity.speed)));

	  checkExpression (15 == velocity.angle, AAFRESULT_TEST_FAILED);
	  checkExpression (2001 == velocity.speed, AAFRESULT_TEST_FAILED);

	  // Try to read the first one
	  Rational16pair_t valA = { {1, 2}, {3, 4} };
	  CheckRational16PairByValues (ptdr16p, ptdr16, pPVa, valA);


	  // Try to read the second one
	  Rational16pair_t valB = { {5, 6}, {7, 8} };
	  CheckRational16PairByValues (ptdr16p, ptdr16, pPVb, valB);

          // Check misc. error return conditions for TypeDefRecord GetValue
          IAAFPropertyValueSP junkPv;
	  temphr = ptdr16->GetValue (0, 1, &junkPv);
	  checkExpression (AAFRESULT_NULL_PARAM == temphr,
					   AAFRESULT_TEST_FAILED);
	  temphr = ptdr16p->GetValue (pPVb, 1, 0);
	  checkExpression (AAFRESULT_NULL_PARAM == temphr,
					   AAFRESULT_TEST_FAILED);

	  // Read the last two with GetStruct just to get it over with. ;)
	  Rational16pair_t valC = { {9, 10}, {11, 12} };
	  CheckRational16PairByValues (ptdr16p, ptdr16, pPVc, valC);

	  // test variable array of records
	  // perform this part only for specified versions
	  if( versionUInt(testVer) >= versionUInt(1,1,1,0) )
	  {
		IAAFPropertyDefSP pPdPosN;
		checkResult (defs.cdCompositionMob()->LookupPropertyDef (sPropertyId_positionN,	&pPdPosN));
		IAAFPropertyValueSP pPVN;
		checkResult (pObj->GetPropertyValue (pPdPosN, &pPVN));

		// get the middle element of the array, 9abc
		IAAFPropertyValueSP pPVN1;
		checkResult (ptdvaarpr->GetElementValue (pPVN, 1, &pPVN1));

		// Read the value with GetStruct
		Rational16pair_t valN1 = { {9,10},{11,12} };
		CheckRational16PairByValues (ptdr16p, ptdr16, pPVN1, valN1);
	  }

	  // Attempt to close the file.
	  checkResult(pFile->Close());
	  IAAFFileSP nullFile;
	  pFile = nullFile;  // zeros the pFile, and releases it.

	  hr = AAFRESULT_SUCCESS;
	}
  catch (HRESULT& rResult)
	{
	  hr = rResult;
	}
	
  // cleanup
  if (pFile)
	{
	  pFile->Close();
	}
	
  return hr;
}
コード例 #6
0
static HRESULT ReadRecord (const aafWChar * pFileName, int loadingMode)
{
  HRESULT hr = E_FAIL;
  IAAFFileSP   pFile;

  try 
	{
	  // Open the file, and get the dictionary.
	  checkResult(AAFFileOpenExistingRead(pFileName, loadingMode, &pFile));
	  IAAFHeaderSP pHeader;
	  checkResult(pFile->GetHeader(&pHeader));
	  IAAFDictionarySP pDict;
	  checkResult (pHeader->GetDictionary(&pDict));
	  CAAFBuiltinDefs defs(pDict);

	  // get the SDK version against which we are testing
	  aafProductVersion_t			testVer;
	  checkResult(pHeader->GetRefImplVersion(&testVer));

	  // Get the type definitions for our new types.
	  IAAFTypeDefSP ptd;
	  checkResult (pDict->LookupTypeDef (sTypeId_Rational16,
										 &ptd));
	  IAAFTypeDefRecordSP ptdr16;
	  checkResult (ptd->QueryInterface (IID_IAAFTypeDefRecord,
										(void**) &ptdr16));

	  // check for duplicate initialization
	  aafUID_t nullUid = { 0 };
	  HRESULT temphr;
	  temphr = ptdr16->Initialize (nullUid,
								  0,
								  0,
								  1,
								  L"foo");
	  checkExpression (AAFRESULT_ALREADY_INITIALIZED == temphr,
					   AAFRESULT_TEST_FAILED);

	  aafUInt32 count = 0;
	  checkResult (ptdr16->GetCount (&count));
	  checkExpression (2 == count, AAFRESULT_TEST_FAILED);

	  aafUInt32  nameLen = 0;
	  aafCharacter nameBuf [100];
	  checkResult (ptdr16->GetMemberNameBufLen (0, &nameLen));
	  checkExpression (((wcslen(L"Numerator")+1)*sizeof(aafCharacter))
					   == nameLen,
					   AAFRESULT_TEST_FAILED);
	  checkExpression (nameLen < 100,
					   AAFRESULT_TEST_FAILED);
	  checkResult (ptdr16->GetMemberName (0,
										 nameBuf,
										 sizeof (nameBuf)));
	  checkExpression (0 == wcscmp (L"Numerator", nameBuf),
					   AAFRESULT_TEST_FAILED);

	  checkResult (ptdr16->GetMemberNameBufLen (1, &nameLen));
	  checkExpression (((wcslen(L"Denominator")+1)*sizeof (aafCharacter))
					   == nameLen,
					   AAFRESULT_TEST_FAILED);
	  checkExpression (nameLen < 100,
					   AAFRESULT_TEST_FAILED);
	  checkResult (ptdr16->GetMemberName (1,
										 nameBuf,
										 sizeof (nameBuf)));
	  checkExpression (0 == wcscmp (L"Denominator", nameBuf),
					   AAFRESULT_TEST_FAILED);

	  temphr = ptdr16->GetMemberNameBufLen (2, &nameLen);
	  checkExpression (AAFRESULT_ILLEGAL_VALUE == temphr,
					   AAFRESULT_TEST_FAILED);

	  temphr = ptdr16->GetMemberName (2,
									 nameBuf,
									 sizeof (nameBuf));
	  checkExpression (AAFRESULT_ILLEGAL_VALUE == temphr,
					   AAFRESULT_TEST_FAILED);

	  checkResult (pDict->LookupTypeDef (sTypeId_Rational16_pair,
										 &ptd));
	  IAAFTypeDefRecordSP ptdr16p;
	  checkResult (ptd->QueryInterface (IID_IAAFTypeDefRecord,
										(void**) &ptdr16p));

	  // check for duplicate initialization
	  temphr = ptdr16p->Initialize (nullUid,
								   0,
								   0,
								   1,
								   L"foo");
	  checkExpression (AAFRESULT_ALREADY_INITIALIZED == temphr,
					   AAFRESULT_TEST_FAILED);

	  count = 0;
	  checkResult (ptdr16p->GetCount (&count));
	  checkExpression (2 == count, AAFRESULT_TEST_FAILED);

	  // Now attempt to register offsets of Rational16_pair.  This
	  // should fail, because offsets of its members (of type
	  // Rational16) have not yet been registered.
	  temphr = RegisterRational16PairOffsets (ptdr16p);
	  checkExpression (temphr == AAFRESULT_NOT_REGISTERED,
					   AAFRESULT_TEST_FAILED);

	  // Now let's attempt registration the right way.
	  checkResult (RegisterRational16Offsets (ptdr16));
	  checkResult (RegisterRational16PairOffsets (ptdr16p));
		
	  // Setup to read the Velocity property which is of typed Mixed_t
	  checkResult (pDict->LookupTypeDef (sTypeId_Mixed, &ptd));
	  IAAFTypeDefRecordSP ptdrmixed;
	  checkResult (ptd->QueryInterface (IID_IAAFTypeDefRecord, (void**) &ptdrmixed));
	  temphr = RegisterMixedOffsets(ptdrmixed);
	  /* It is ok to return default already used due to current limitation
           * in implementation that default registration may occur and tie us
           * to a specific structural layout before we get the ability to
           * register own offsets/layout. This is slated for fixing in
           * future rev of the SDK.
           */
	  if (temphr == AAFRESULT_DEFAULT_ALREADY_USED) {
	      temphr = AAFRESULT_SUCCESS;
	      throw temphr;
	  }

	  checkResult (temphr);

	  IAAFTypeDef * pTempTd = 0;
	  checkResult (ptdr16->QueryInterface (IID_IAAFTypeDef,
										(void**) &pTempTd));
	  CheckMemberTypeEqual (ptdr16p, 0, pTempTd);
	  CheckMemberTypeEqual (ptdr16p, 1, pTempTd);
	  pTempTd->Release ();
	  pTempTd = 0;

	  temphr = ptdr16p->GetMemberType (2, &pTempTd);
	  checkExpression (temphr == AAFRESULT_ILLEGAL_VALUE,
					   AAFRESULT_TEST_FAILED);

	  // register variable array of Rational16Pair records
	  IAAFTypeDefVariableArraySP ptdvaarpr;
	  IAAFTypeDefSP ptdarpr;
	  // perform this part only for specified versions
	  if( versionUInt(testVer) >= versionUInt(1,1,1,0) )
	  {
		checkResult (pDict->LookupTypeDef (sTypeId_Rational16_array,&ptdarpr));
		checkResult (ptdarpr->QueryInterface (IID_IAAFTypeDefVariableArray,(void**) &ptdvaarpr));
	  }

	  // Now read the CompositionMob to which we added some optional
	  // properties.
	  IEnumAAFMobsSP pEnumMobs;
	  checkResult (pHeader->GetMobs (0, &pEnumMobs));

	  IAAFMobSP pMob;
	  checkResult (pEnumMobs->NextOne (&pMob));
	  IAAFObjectSP pObj;
	  checkResult (pMob->QueryInterface (IID_IAAFObject,
										 (void**) &pObj));

	  // get the property definitions for the added properties
	  IAAFPropertyDefSP pPdPosA;
	  checkResult (defs.cdCompositionMob()->
				   LookupPropertyDef (sPropertyId_positionA,
									  &pPdPosA));
	  IAAFPropertyDefSP pPdPosB;
	  checkResult (defs.cdCompositionMob()->
				   LookupPropertyDef (sPropertyId_positionB,
									  &pPdPosB));
	  IAAFPropertyDefSP pPdPosC;
	  checkResult (defs.cdCompositionMob()->
				   LookupPropertyDef (sPropertyId_positionC,
									  &pPdPosC));

	  IAAFPropertyValueSP pPVa;
	  checkResult (pObj->GetPropertyValue (pPdPosA, &pPVa));
	  IAAFPropertyValueSP pPVb;
	  checkResult (pObj->GetPropertyValue (pPdPosB, &pPVb));
	  IAAFPropertyValueSP pPVc;
	  checkResult (pObj->GetPropertyValue (pPdPosC, &pPVc));

	  // Read back the value of the Velocity property
	  IAAFPropertyDefSP pPdvelocity;
	  checkResult (defs.cdCompositionMob()->LookupPropertyDef(sPropertyId_velocity, &pPdvelocity));
	  IAAFPropertyValueSP pPVvelocity;
	  checkResult (pObj->GetPropertyValue (pPdvelocity, &pPVvelocity));
	  Mixed_t velocity = {0, 0};
	  checkResult (ptdrmixed->GetStruct (pPVvelocity, (aafMemPtr_t) &velocity, sizeof (velocity)));
	  checkExpression (15 == velocity.angle, AAFRESULT_TEST_FAILED);
	  checkExpression (2001 == velocity.speed, AAFRESULT_TEST_FAILED);

	  // Try to read the first one with GetStruct.
	  Rational16pair_t valA = { {0,0},{0,0} };
	  checkResult (ptdr16p->GetStruct (pPVa,
									  (aafMemPtr_t) &valA,
									  sizeof (valA)));
	  checkExpression (1 == valA.X_Position.Numerator,
					   AAFRESULT_TEST_FAILED);
	  checkExpression (2 == valA.X_Position.Denominator,
					   AAFRESULT_TEST_FAILED);
	  checkExpression (3 == valA.Y_Position.Numerator,
					   AAFRESULT_TEST_FAILED);
	  checkExpression (4 == valA.Y_Position.Denominator,
					   AAFRESULT_TEST_FAILED);

	  // Try to read the second one by decomposing with GetValue.
	  Rational16pair_t valB = { {5, 6}, {7, 8} };
	  CheckRational16PairByValues (ptdr16p, ptdr16, pPVb, valB);

	  // Read the last two with GetStruct just to get it over with. ;)
	  Rational16pair_t valC = { {0,0},{0,0} };
	  temphr = ptdr16p->GetStruct (pPVc,
								  (aafMemPtr_t) &valC,
								  sizeof (valC)-1);
	  checkExpression (AAFRESULT_ILLEGAL_VALUE == temphr,
					   AAFRESULT_TEST_FAILED);
	  temphr = ptdr16p->GetStruct (0,
								  (aafMemPtr_t) &valC,
								  sizeof (valC));
	  checkExpression (AAFRESULT_NULL_PARAM == temphr,
					   AAFRESULT_TEST_FAILED);
	  temphr = ptdr16p->GetStruct (pPVc,
								  0,
								  sizeof (valC));
	  checkExpression (AAFRESULT_NULL_PARAM == temphr,
					   AAFRESULT_TEST_FAILED);
	  checkResult (ptdr16p->GetStruct (pPVc,
									  (aafMemPtr_t) &valC,
									  sizeof (valC)));
	  checkExpression (9 == valC.X_Position.Numerator,
					   AAFRESULT_TEST_FAILED);
	  checkExpression (10 == valC.X_Position.Denominator,
					   AAFRESULT_TEST_FAILED);
	  checkExpression (11 == valC.Y_Position.Numerator,
					   AAFRESULT_TEST_FAILED);
	  checkExpression (12 == valC.Y_Position.Denominator,
					   AAFRESULT_TEST_FAILED);

	  // test variable array of records
	  // perform this part only for specified versions
	  if( versionUInt(testVer) >= versionUInt(1,1,1,0) )
	  {
		IAAFPropertyDefSP pPdPosN;
		checkResult (defs.cdCompositionMob()->LookupPropertyDef (sPropertyId_positionN,	&pPdPosN));
		IAAFPropertyValueSP pPVN;
		checkResult (pObj->GetPropertyValue (pPdPosN, &pPVN));

		// get the middle element of the array, 9abc
		IAAFPropertyValueSP pPVN1;
		checkResult (ptdvaarpr->GetElementValue (pPVN, 1, &pPVN1));

		// Read the value with GetStruct
		Rational16pair_t valN1 = { {0,0},{0,0} };
		checkResult (ptdr16p->GetStruct (pPVN1,
										(aafMemPtr_t) &valN1,
										sizeof (valN1)));
		checkExpression (9 == valN1.X_Position.Numerator,
						AAFRESULT_TEST_FAILED);
		checkExpression (10 == valN1.X_Position.Denominator,
						AAFRESULT_TEST_FAILED);
		checkExpression (11 == valN1.Y_Position.Numerator,
						AAFRESULT_TEST_FAILED);
		checkExpression (12 == valN1.Y_Position.Denominator,
						AAFRESULT_TEST_FAILED);
	  }

	  // Attempt to close the file.
	  checkResult(pFile->Close());
	  IAAFFileSP nullFile;
	  pFile = nullFile;  // zeros the pFile, and releases it.

	  hr = AAFRESULT_SUCCESS;
	}
  catch (HRESULT& rResult)
	{
	  hr = rResult;
	}
	
  // cleanup
  if (pFile)
	{
	  pFile->Close();
	}
	
  return hr;
}
コード例 #7
0
static HRESULT WriteRecord (
    const aafWChar * pFileName,
    aafUID_constref fileKind,
    testRawStorageType_t rawStorageType,
    aafProductIdentification_constref productID)
{
  HRESULT hr = E_FAIL;
  IAAFFileSP   pFile;

  try 
	{
	  HRESULT temphr;

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

	  // Create the file and get the new file's header.
	  checkResult(CreateTestFile( pFileName, fileKind, rawStorageType, productID, &pFile ));
	  IAAFHeaderSP pHeader;
  	  checkResult(pFile->GetHeader(&pHeader));
	  IAAFDictionarySP pDict;
	  checkResult (pHeader->GetDictionary(&pDict));
	  CAAFBuiltinDefs defs(pDict);

	  // get the SDK version against which we are testing
      aafProductVersion_t			testVer;
      checkResult(pHeader->GetRefImplVersion(&testVer));

	  // Create, initialize, and register the Rational16 type, to
	  // consist of an Int16 numerator and a UInt16 denominator.
	  IAAFTypeDef* tdr16MemberTypes[] =
	  {defs.tdInt16(),
	   defs.tdUInt16()};
	  aafWChar numerator[] = L"Numerator";
	  aafWChar denominator[] = L"Denominator";
	  aafString_t tdr16MemberNames[] =
	  {numerator,
	   denominator};
	  IAAFTypeDefRecordSP ptdr16;
	  checkResult (pDict->
				   CreateMetaInstance (kAAFClassID_TypeDefRecord,
									   IID_IAAFTypeDefRecord,
									   (IUnknown**) &ptdr16));

	  checkResult (ptdr16->Initialize (sTypeId_Rational16,
									  tdr16MemberTypes,
									  tdr16MemberNames,
									  2,
									  L"Rational16"));

	  // check for duplicate initialization
	  temphr = ptdr16->Initialize (sTypeId_Rational16,
								  tdr16MemberTypes,
								  tdr16MemberNames,
								  2,
								  L"Rational16");
	  checkExpression (AAFRESULT_ALREADY_INITIALIZED == temphr,
					   AAFRESULT_TEST_FAILED);

	  IAAFTypeDefSP ptd;
	  checkResult (ptdr16->QueryInterface (IID_IAAFTypeDef, (void**) &ptd));
	  checkResult (pDict->RegisterTypeDef (ptd));

	  // Create, initialize, and register the Rational16Position type,
	  // to consist of a Rational16 X and Rational16 Y coordinates.

	  IAAFTypeDefRecordSP ptdr16p;
	  //checkResult (defs.cdTypeDefRecord()->
	  // CreateInstance (IID_IAAFTypeDefRecord,
	  // (IUnknown**)&ptdr16p));
	  checkResult (pDict->
				   CreateMetaInstance (kAAFClassID_TypeDefRecord,
									   IID_IAAFTypeDefRecord,
									   (IUnknown**) &ptdr16p));

	  IAAFTypeDef * pTempTd = 0;
	  checkResult (ptdr16->QueryInterface (IID_IAAFTypeDef,
										  (void**) &pTempTd));	  
	  IAAFTypeDef* tdr16pMemberTypes[] =
	  {pTempTd,
	   pTempTd};
	  aafWChar xpos[] = L"X Position";
	  aafWChar ypos[] = L"Y Position";
	  aafString_t tdr16pMemberNames[] =
	  {xpos,
	   ypos};
	  checkResult (ptdr16p->Initialize (sTypeId_Rational16_pair,
									   tdr16pMemberTypes,
									   tdr16pMemberNames,
									   2,
									   L"Rational16Pair"));
	  // check for duplicate initialization
	  temphr = ptdr16p->Initialize (sTypeId_Rational16,
								   tdr16pMemberTypes,
								   tdr16pMemberNames,
								   2,
								   L"Rational16Pair");
	  checkExpression (AAFRESULT_ALREADY_INITIALIZED == temphr,
					   AAFRESULT_TEST_FAILED);

	  pTempTd->Release ();
	  pTempTd = 0;
	  checkResult (ptdr16p->QueryInterface (IID_IAAFTypeDef, (void**) &ptd));
	  checkResult (pDict->RegisterTypeDef (ptd));

	  // Now attempt to register offsets of Rational16_pair.  This
	  // should fail, because offsets of its members (of type
	  // Rational16) have not yet been registered.
	  temphr = RegisterRational16PairOffsets (ptdr16p);
	  checkExpression (temphr == AAFRESULT_NOT_REGISTERED,
					   AAFRESULT_TEST_FAILED);

	  // Now let's attempt registration the right way.
	  checkResult (RegisterRational16Offsets (ptdr16));
	  checkResult (RegisterRational16PairOffsets (ptdr16p));

	  // register variable array of Rational16Pair records
	  IAAFTypeDefVariableArraySP ptdvaarpr;
	  IAAFTypeDefSP ptdarpr;
	  // perform this part only for specified versions
	  if( versionUInt(testVer) >= versionUInt(1,1,1,0) )
	  {
		//Create a Variable Array
		checkResult(pDict->CreateMetaInstance (AUID_AAFTypeDefVariableArray, IID_IAAFTypeDefVariableArray, (IUnknown **) &ptdvaarpr));
		
		//IAAFTypeDefVariableArray::Initialize
		checkResult(ptdvaarpr->Initialize(sTypeId_Rational16_array, ptd, L"Rational16PairArray"));
		
		//  Register our new VA type def :
		checkResult(ptdvaarpr->QueryInterface(IID_IAAFTypeDef, (void**)&ptdarpr));
		checkResult(pDict->RegisterTypeDef(ptdarpr));
	  }

	  // Create a new property on Composition mob (called Position)
	  // whose type is Rational16_pair.
	  checkResult (ptdr16p->QueryInterface (IID_IAAFTypeDef,
										   (void**) &ptd));
	  IAAFPropertyDefSP pPropDefPosA;
	  IAAFPropertyDefSP pPropDefPosB;
	  IAAFPropertyDefSP pPropDefPosC;
	  checkResult (defs.cdCompositionMob()->RegisterOptionalPropertyDef
				   (sPropertyId_positionA,
					L"PositionA",
					ptd,
					&pPropDefPosA));
	  checkResult (defs.cdCompositionMob()->RegisterOptionalPropertyDef
				   (sPropertyId_positionB,
					L"PositionB",
					ptd,
					&pPropDefPosB));
	  checkResult (defs.cdCompositionMob()->RegisterOptionalPropertyDef
				   (sPropertyId_positionC,
					L"PositionC",
					ptd,
					&pPropDefPosC));

	  // register property of type variable array of Rational16Pair records
	  IAAFPropertyDefSP pPropDefPosN;
	  // perform this part only for specified versions
	  if( versionUInt(testVer) >= versionUInt(1,1,1,0) )
	  {
		checkResult (defs.cdCompositionMob()->RegisterOptionalPropertyDef
					(sPropertyId_positionN,
						L"PositionN",
						ptdarpr,
						&pPropDefPosN));
	  }


	  // Register the Mixed_t type
	  IAAFTypeDef* tdMixedMemberTypes[] = {defs.tdInt8(), defs.tdUInt32()};
	  aafWChar str_angle[] = L"Angle";
	  aafWChar str_speed[] = L"Speed";
	  aafString_t tdMixedMemberNames[] = {str_angle, str_speed};
	  IAAFTypeDefRecordSP ptdrmixed;
	  checkResult(pDict->CreateMetaInstance(kAAFClassID_TypeDefRecord, IID_IAAFTypeDefRecord, (IUnknown**) &ptdrmixed));
	  checkResult(ptdrmixed->Initialize(sTypeId_Mixed, tdMixedMemberTypes, tdMixedMemberNames, 2, L"Mixed"));
	  //  Register Mixed type def
	  IAAFTypeDefSP ptdmixed;
	  checkResult(ptdrmixed->QueryInterface(IID_IAAFTypeDef, (void**)&ptdmixed));
	  checkResult(pDict->RegisterTypeDef(ptdmixed));
	  checkResult(RegisterMixedOffsets(ptdrmixed));
	  // Added Velocity property to Composition Mob
	  IAAFPropertyDefSP pPropDefVelocity;
	  checkResult (defs.cdCompositionMob()->RegisterOptionalPropertyDef
				   (sPropertyId_velocity,
					L"Velocity",
					ptdmixed,
					&pPropDefVelocity));


	  // Create one of our new CompositionMobs, and add a values for
	  // the Position property.
	  IAAFCompositionMobSP pcm;
	  checkResult (defs.cdCompositionMob()->
				   CreateInstance (IID_IAAFCompositionMob,
								   (IUnknown**)&pcm));

	  // Add property value for PositionA using CreateValueFromValues
	  // methods.  The constituent property values will be created
	  // from CreateValueFromStruct, and from SetValueFromStruct.

	  const Rational16_t v_12 = {1, 2};
	  const Rational16_t v_34 = {3, 4};
	  IAAFPropertyValue * pValRat[2] = { 0 };

	  checkResult (ptdr16->
				   CreateValueFromStruct ((aafMemPtr_t) &v_12,
										  sizeof (v_12),
										  &pValRat[0]));
	  // create it with wrong data, and use SetStruct to give it right
	  // data
	  checkResult (ptdr16->
				   CreateValueFromStruct ((aafMemPtr_t) &v_12,
										  sizeof (v_12),
										  &pValRat[1]));
	  checkResult (ptdr16->
				   SetStruct (pValRat[1],
							  (aafMemPtr_t) &v_34,
							  sizeof (v_34)));

	  // Create the Rational16_pair property value from the
	  // Rational16 property values.
	  IAAFPropertyValueSP pRat16PairVal_1234;
	  temphr = ptdr16p->CreateValueFromValues (0,
											  2,
											  &pRat16PairVal_1234);
	  checkExpression (AAFRESULT_NULL_PARAM == temphr,
					   AAFRESULT_TEST_FAILED);
	  temphr = ptdr16p->CreateValueFromValues (pValRat,
											  1,
											  &pRat16PairVal_1234);
	  checkExpression (AAFRESULT_ILLEGAL_VALUE == temphr,
					   AAFRESULT_TEST_FAILED);
	  checkResult (ptdr16p->CreateValueFromValues (pValRat,
												  2,
												  &pRat16PairVal_1234));
	  pValRat[0]->Release ();
	  pValRat[0] = 0;
	  pValRat[1]->Release ();
	  pValRat[1] = 0;

	  IAAFObjectSP pObj;
	  checkResult (pcm->QueryInterface (IID_IAAFObject,
										(void**) &pObj));
	  checkResult (pObj->SetPropertyValue (pPropDefPosA,
										   pRat16PairVal_1234));


	  // Add property value for PositionB using CreateValueFromStruct
	  // methods.
	  const Rational16_t r16_56 = {5, 6};
	  const Rational16_t r16_78 = {7, 8};
	  Rational16pair_t r16p_5678;
	  r16p_5678.X_Position = r16_56;
	  r16p_5678.Y_Position = r16_78;
	  IAAFPropertyValueSP pRat16PairVal_5678;
	  temphr = ptdr16p->
		CreateValueFromStruct (0,
							   sizeof (r16p_5678),
							   &pRat16PairVal_5678);
	  checkExpression (AAFRESULT_NULL_PARAM == temphr,
					   AAFRESULT_TEST_FAILED);
	  temphr = ptdr16p->
		CreateValueFromStruct ((aafMemPtr_t) &r16p_5678,
							   sizeof (r16p_5678),
							   0);
	  checkExpression (AAFRESULT_NULL_PARAM == temphr,
					   AAFRESULT_TEST_FAILED);
	  temphr = ptdr16p->
		CreateValueFromStruct ((aafMemPtr_t) &r16p_5678,
							   sizeof (r16p_5678)+1,
							   &pRat16PairVal_5678);
	  checkExpression (AAFRESULT_ILLEGAL_VALUE == temphr,
					   AAFRESULT_TEST_FAILED);
	  checkResult (ptdr16p->
				   CreateValueFromStruct ((aafMemPtr_t) &r16p_5678,
										  sizeof (r16p_5678),
										  &pRat16PairVal_5678));
	  checkResult (pObj->SetPropertyValue (pPropDefPosB,
										   pRat16PairVal_5678));

	  // Add property value for PositionC using CreateValueFromStruct
	  // methods, and then use SetStruct to set the value.
	  const Rational16_t r16_9a = {9, 10};
	  const Rational16_t r16_bc = {11, 12};
	  Rational16pair_t r16p_9abc;
	  r16p_9abc.X_Position = r16_9a;
	  r16p_9abc.Y_Position = r16_bc;
	  IAAFPropertyValueSP pRat16PairVal_9abc;
	  checkResult (ptdr16p->
				   CreateValueFromStruct ((aafMemPtr_t) &r16p_5678,
										  sizeof (r16p_5678),
										  &pRat16PairVal_9abc));
	  temphr = ptdr16p->SetStruct (0,
								  (aafMemPtr_t) &r16p_9abc,
								  sizeof (r16p_9abc));
	  checkExpression (AAFRESULT_NULL_PARAM == temphr,
					   AAFRESULT_TEST_FAILED);
	  temphr = ptdr16p->SetStruct (pRat16PairVal_9abc,
								  0,
								  sizeof (r16p_9abc));
	  checkExpression (AAFRESULT_NULL_PARAM == temphr,
					   AAFRESULT_TEST_FAILED);
	  temphr = ptdr16p->SetStruct (pRat16PairVal_9abc,
								  (aafMemPtr_t) &r16p_9abc,
								  sizeof (r16p_9abc)-1);
	  checkExpression (AAFRESULT_ILLEGAL_VALUE == temphr,
					   AAFRESULT_TEST_FAILED);
	  checkResult (ptdr16p->SetStruct (pRat16PairVal_9abc,
									  (aafMemPtr_t) &r16p_9abc,
										  sizeof (r16p_9abc)));
	  checkResult (pObj->SetPropertyValue (pPropDefPosC,
										   pRat16PairVal_9abc));

	  // add a value of PropertyN
	  IAAFPropertyValueSP spArrayPropertyValue;
	  // perform this part only for specified versions
	  if( versionUInt(testVer) >= versionUInt(1,1,1,0) )
	  {
	    // Create an empty array and then fill it by appending elements...
  		checkResult( ptdvaarpr->CreateEmptyValue (&spArrayPropertyValue) );
		
	    // intentionally in permuted order
		checkResult( ptdvaarpr->AppendElement(spArrayPropertyValue, pRat16PairVal_5678) );

		checkResult( ptdvaarpr->AppendElement(spArrayPropertyValue, pRat16PairVal_9abc) );

		checkResult( ptdvaarpr->AppendElement(spArrayPropertyValue, pRat16PairVal_1234) );

		// set PropertyN
		checkResult ( pObj->SetPropertyValue( pPropDefPosN, spArrayPropertyValue ) );
	  }

	  // Set the value on the new Velocity property (of Mixed_t type)
	  const Mixed_t velocty = {15, 2001};
	  IAAFPropertyValueSP pVelocity;
	  checkResult (ptdrmixed->CreateValueFromStruct((aafMemPtr_t) &velocty, sizeof(velocty), &pVelocity));
	  checkResult (pObj->SetPropertyValue(pPropDefVelocity, pVelocity));


	  //Put the modified comp mob into the file.
	  IAAFMobSP pMob;
	  checkResult (pcm->QueryInterface (IID_IAAFMob,
										(void**) &pMob));
	  checkResult (pHeader->AddMob(pMob));

	  // Attempt to save the file.
	  checkResult(pFile->Save());
		
	  // Attempt to close the file.
	  checkResult(pFile->Close());
	  IAAFFileSP nullFile;
	  pFile = nullFile;  // zeros the pFile, and releases it.

	  hr = AAFRESULT_SUCCESS;
	}
  catch (HRESULT& rResult)
	{
	  hr = rResult;
	}
	
  // cleanup
  if (pFile)
	{
	  pFile->Save();
	  pFile->Close();
	}
	
  return hr;
}
コード例 #8
0
ファイル: CAAFDictionaryTest.cpp プロジェクト: mcanthony/aaf
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;
}
コード例 #9
0
ファイル: CAAFDictionaryTest.cpp プロジェクト: mcanthony/aaf
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;
}
コード例 #10
0
ファイル: CAAFTypeDefTest.cpp プロジェクト: UIKit0/aaf
static HRESULT TestTypeDef (
    testMode_t mode,
    aafUID_constref fileKind,
    testRawStorageType_t rawStorageType,
    aafProductIdentification_constref productID)
{
  HRESULT hr = E_FAIL;

  GenerateTestFileName( productID.productName, fileKind, fileNameBufLen, testFileName );

  IAAFFileSP pFile;
  if(mode == kAAFUnitTestReadWrite)
  {
 	 RemoveTestFile (testFileName);
  	hr = CreateTestFile( testFileName, fileKind, rawStorageType, productID, &pFile );
  }
  else
  {
  	hr = AAFFileOpenExistingRead(testFileName, 0, &pFile);
  }
  
  if (! SUCCEEDED (hr)) return hr;

  IAAFHeaderSP pHeader;
  hr = pFile->GetHeader (&pHeader);
  if (! SUCCEEDED (hr)) return hr;
  assert (pHeader);

  IAAFDictionarySP pDict;
  hr = pHeader->GetDictionary (&pDict);
  if (! SUCCEEDED (hr)) return hr;
  assert (pDict);

  CAAFBuiltinDefs defs (pDict);

  // Let's try to do something interesting with a type definition
  IAAFTypeDefIntSP pTypeDefInt;
  hr = defs.tdInt32()->QueryInterface (IID_IAAFTypeDefInt, (void **) &pTypeDefInt);
  if (! SUCCEEDED (hr)) return hr;
  assert (pTypeDefInt);

  IAAFTypeDefSP pTypeDef;
  hr = pTypeDefInt->QueryInterface(IID_IAAFTypeDef, (void **)&pTypeDef);
  if (! SUCCEEDED (hr)) return hr;
  assert (pTypeDef);

  //
  // Test GetTypeCategory() method
  //

  // first, test error conditions
  hr = pTypeDef->GetTypeCategory(NULL);
  if (AAFRESULT_NULL_PARAM != hr)
	return AAFRESULT_TEST_FAILED;

  // now, test for valid value.  Our type def is integral.
  eAAFTypeCategory_t typeCat = kAAFTypeCatUnknown;
  hr = pTypeDef->GetTypeCategory(&typeCat);
  if (! SUCCEEDED (hr)) return hr;
  if (kAAFTypeCatInt != typeCat)
	return AAFRESULT_TEST_FAILED;

  // Test for RawAccessType().  It should be array of unsigned chars.
  IAAFTypeDefSP pRawType;
  hr = pTypeDef->RawAccessType (&pRawType);
  if (! SUCCEEDED (hr)) return hr;

  IUnknownSP    pUnkRawType;
  hr = pRawType->QueryInterface(IID_IUnknown, (void **)&pUnkRawType);
  if (! SUCCEEDED (hr)) return hr;

  IAAFTypeDefSP pUInt8ArrayType;
  hr = pDict->LookupTypeDef (kAAFTypeID_UInt8Array, &pUInt8ArrayType);
  if (! SUCCEEDED (hr)) return hr;

  IUnknownSP    pUnkUInt8Array;
  hr = pUInt8ArrayType->QueryInterface(IID_IUnknown, (void **)&pUnkUInt8Array);
  if (! SUCCEEDED (hr)) return hr;

  if (pUnkUInt8Array != pUnkRawType)
	return AAFRESULT_TEST_FAILED;


  // that's all we can test for.  Clean up.
  if(mode == kAAFUnitTestReadWrite)
  {
  	hr = pFile->Save();
 	 if (! SUCCEEDED (hr)) return hr;
 }
  hr = pFile->Close();
  if (! SUCCEEDED (hr)) return hr;

  return AAFRESULT_SUCCESS;
}
コード例 #11
0
ファイル: CAAFMobTest.cpp プロジェクト: mcanthony/aaf
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;
  IAAFMob						*pMob = NULL;
  IAAFMob						*pMob2 = NULL;
  IAAFMob2                      *pMobInterface2 = NULL;
  IAAFTimelineMobSlot 			*newSlot = NULL;
  IAAFStaticMobSlot 			*newStaticSlot=NULL;
  IAAFEventMobSlot 				*newEventSlot=NULL;
  IAAFSegment					*seg = NULL;
  IAAFSourceClip				*sclp = NULL;
  IAAFEvent						*event=NULL;
  IAAFComponent*				pComponent = NULL;
  IAAFClassDef					*pcdEventMeta=NULL;
  IAAFClassDef					*pcdEvent=NULL;
  IAAFClassDef					*pcdEventConcrete=NULL;
  HRESULT						hr = S_OK;
  aafNumSlots_t					numMobs;
  aafUInt32 					bufLen = 0;
  aafUInt32 					bytesRead = 0;
  aafUInt32 					numComments = 0;
  aafUInt32						numFound = 0;
  aafWChar						name[500];
  aafWChar						value[500];
  IEnumAAFTaggedValues 			*enumTaggedVal = NULL;
  IAAFTaggedValue				*taggedVal = NULL;
  IAAFMobSlot 					*mSlot = NULL;
  IAAFFiller 					*filler = NULL;
  IAAFKLVData					*pKLVData = NULL;
  IAAFTypeDef*					pBaseType = NULL;
  IAAFSourceReference 			*pSourceRef = NULL;
  IAAFTimecode					*pTimecode = NULL;
  aafTimecode_t					timecode;
  int 							i;


  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
	  long	test;

	  // Create a concrete subclass of Mob
	  checkResult(defs.cdMasterMob()->
				  CreateInstance(IID_IAAFMob, 
								 (IUnknown **)&pMob));
	  checkResult( pMob->QueryInterface(IID_IAAFMob2,(void**)&pMobInterface2));

	  checkResult(pMob->SetMobID(MOBTestID));
      checkExpression(pMob->GetNameBufLen(&bufLen) == AAFRESULT_PROP_NOT_PRESENT, AAFRESULT_TEST_FAILED);
      checkExpression(pMob->GetName(name, 0) == AAFRESULT_PROP_NOT_PRESENT, AAFRESULT_TEST_FAILED);
	  checkExpression(pMob->SetName(NULL) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED);
	  checkResult(pMob->SetName(mobName));
	  
	  checkResult(pMob->SetCreateTime(creationTimeStamp));
	  checkResult(pMob->SetModTime(modificationTimeStamp));

	  // Add some slots
	  for(test = 1; test < 6; test++)
		{
		  checkResult(defs.cdSourceClip()->
					  CreateInstance(IID_IAAFSourceClip, 
									 (IUnknown **)&sclp));		
		  checkResult(sclp->QueryInterface(IID_IAAFSourceReference, (void **)&pSourceRef));
		  checkResult(pSourceRef->SetSourceID(MOBTestID3));

		  checkResult(sclp->QueryInterface(IID_IAAFComponent, (void **)&pComponent));
		  checkResult(pComponent->SetDataDef(defs.ddkAAFPicture()));

		  checkResult(sclp->QueryInterface (IID_IAAFSegment, (void **)&seg));

		  aafRational_t editRate = { 0, 1};
		  checkResult(pMob->AppendNewTimelineSlot (editRate,
												   seg,
												   test+1,
												   slotNames[test],
												   0,
												   &newSlot));

		

		  if(test == 5)
		  {
			  checkExpression(pMob->AppendNewTimelineSlot (editRate,
										   NULL,
										   test+1,
										   slotNames[test],
										   0,
										   &newSlot) == AAFRESULT_NULL_PARAM, 
										   AAFRESULT_TEST_FAILED);

			  checkExpression(pMob->AppendNewTimelineSlot (editRate,
										   seg,
										   test+1,
										   NULL,
										   0,
										   &newSlot) == AAFRESULT_NULL_PARAM, 
										   AAFRESULT_TEST_FAILED);

			  checkExpression(pMob->AppendNewTimelineSlot (editRate,
										   seg,
										   test+1,
										   slotNames[test],
										   0,
										   NULL) == AAFRESULT_NULL_PARAM, 
										   AAFRESULT_TEST_FAILED);

			  pMob->RemoveSlotAt(4);
			  checkExpression(pMob->RemoveSlotAt(test+1) == AAFRESULT_BADINDEX,
			  							   AAFRESULT_TEST_FAILED);
		  }

		  newSlot->Release();
		  newSlot = NULL;

		  if(newStaticSlot)
			newStaticSlot->Release();
		  newStaticSlot = NULL;

		  seg->Release();
		  seg = NULL;

		  sclp->Release();
		  sclp = NULL;
		  
		  pComponent->Release();
		  pComponent = NULL;
		  
		  pSourceRef->Release();
		  pSourceRef = NULL;
		}



		// PrependSlot
 		checkResult(defs.cdStaticMobSlot()->
					  CreateInstance(IID_IAAFMobSlot, 
									 (IUnknown **)&mSlot));		
 		checkResult(defs.cdFiller()->
					  CreateInstance(IID_IAAFFiller, 
									 (IUnknown **)&filler));		

		checkResult(filler->Initialize(defs.ddkAAFSound(), 10));
		checkResult(filler->QueryInterface (IID_IAAFSegment, (void **)&seg));

		checkResult(mSlot->SetName(slotNames[0]));
		checkResult(mSlot->SetPhysicalNum(1));
		checkResult(mSlot->SetSlotID(1));
		checkResult(mSlot->SetSegment(seg));

		checkResult(pMob->PrependSlot(mSlot));
		checkExpression(pMob->PrependSlot(mSlot) == AAFRESULT_OBJECT_ALREADY_ATTACHED,
															AAFRESULT_TEST_FAILED);			
		checkExpression(pMob->PrependSlot(NULL) == AAFRESULT_NULL_PARAM, 
												  AAFRESULT_TEST_FAILED);
		mSlot->Release();
		mSlot = NULL;
		
		seg->Release();
		seg = NULL;
		
		filler->Release();
		filler = NULL;

		// AppendSlot
 		checkResult(defs.cdStaticMobSlot()->
					  CreateInstance(IID_IAAFMobSlot, 
									 (IUnknown **)&mSlot));		
 		checkResult(defs.cdFiller()->
					  CreateInstance(IID_IAAFFiller, 
									 (IUnknown **)&filler));		

		checkResult(filler->Initialize(defs.ddkAAFSound(), 10));
		checkResult(filler->QueryInterface (IID_IAAFSegment, (void **)&seg));

		checkResult(mSlot->SetName(slotNames[6]));
		checkResult(mSlot->SetPhysicalNum(1));
		checkResult(mSlot->SetSlotID(7));
		checkResult(mSlot->SetSegment(seg));

		checkResult(pMob->AppendSlot(mSlot));
		checkExpression(pMob->AppendSlot(mSlot) == AAFRESULT_OBJECT_ALREADY_ATTACHED,
															AAFRESULT_TEST_FAILED);			
		checkExpression(pMob->AppendSlot(NULL) == AAFRESULT_NULL_PARAM, 
												  AAFRESULT_TEST_FAILED);
		mSlot->Release();
		mSlot = NULL;
		
		seg->Release();
		seg = NULL;

		filler->Release();
		filler = NULL;

 		// InsertSlotAt -- insert a timecode object for OffsetToMobTimecode() testing
		timecode.startFrame = TCstartFrame;	// One hour
		timecode.drop = TCdrop;
		timecode.fps = TCfps;

		checkResult(defs.cdTimecode()->
					  CreateInstance(IID_IAAFTimecode, 
									 (IUnknown **)&pTimecode));
		checkResult(pTimecode->Initialize(100, &timecode));		
		checkResult(pTimecode->QueryInterface (IID_IAAFSegment, (void **)&seg));
		
		assert(pComponent == NULL);
		checkResult(pTimecode->QueryInterface(IID_IAAFComponent,(void **)&pComponent));
		checkResult(pComponent->SetDataDef(defs.ddkAAFTimecode()));
		pComponent->Release();
		pComponent = NULL;

 		checkResult(defs.cdStaticMobSlot()->
					  CreateInstance(IID_IAAFMobSlot, 
									 (IUnknown **)&mSlot));		

		checkResult(mSlot->SetName(slotNames[5]));
		checkResult(mSlot->SetPhysicalNum(1));
		checkResult(mSlot->SetSlotID(6));
		checkResult(mSlot->SetSegment(seg));

		checkExpression(pMob->InsertSlotAt(8, mSlot) == AAFRESULT_BADINDEX, 
												  AAFRESULT_TEST_FAILED);
		checkResult(pMob->InsertSlotAt(5, mSlot));

		checkExpression(pMob->InsertSlotAt(4, mSlot) == AAFRESULT_OBJECT_ALREADY_ATTACHED,
															AAFRESULT_TEST_FAILED);			
		checkExpression(pMob->InsertSlotAt(1, NULL) == AAFRESULT_NULL_PARAM, 
												  AAFRESULT_TEST_FAILED);
		mSlot->Release();
		mSlot = NULL;

		seg->Release();
		seg = NULL;
		
		pTimecode->Release();
		pTimecode = NULL;


		//now test AppendNewStaticSlot
		checkResult(defs.cdSourceClip()->
			CreateInstance(IID_IAAFSourceClip, 
			(IUnknown **)&sclp));		
		checkResult(sclp->QueryInterface(IID_IAAFSourceReference, (void **)&pSourceRef));
		checkResult(pSourceRef->SetSourceID(MOBTestID_Static));

		checkResult(sclp->QueryInterface(IID_IAAFComponent, (void **)&pComponent));
		checkResult(pComponent->SetDataDef(defs.ddkAAFPicture()));

		checkResult(sclp->QueryInterface (IID_IAAFSegment, (void **)&seg));

		checkResult(pMobInterface2->AppendNewStaticSlot (  seg,
			8,
			slotNames[7],
			&newStaticSlot));

		if(newStaticSlot)
			newStaticSlot->Release();
		newStaticSlot = NULL;


		seg->Release();
		seg = NULL;

		pSourceRef->Release();
		pSourceRef = NULL;

		sclp->Release();
		sclp = NULL;

		pComponent->Release();
		pComponent = NULL;



		//now test AppendNewEventSlot

		//Create a concrete version of IAAFEvent
		checkResult (pDictionary->CreateMetaInstance (AUID_AAFClassDef, IID_IAAFClassDef, (IUnknown**) &pcdEventMeta));
		checkResult (pDictionary->LookupClassDef (AUID_AAFEvent, &pcdEvent));
		checkResult (pcdEventMeta->Initialize (kClassID_ConcreteEvent, pcdEvent, L"COncreteEvent", kAAFTrue));
		checkResult (pDictionary->RegisterClassDef (pcdEventMeta));

		//Now instantiate it
		checkResult(pDictionary->LookupClassDef(kClassID_ConcreteEvent, &pcdEventConcrete));
		checkResult(pcdEventConcrete->CreateInstance(IID_IAAFEvent, (IUnknown **)&event));
		
		//and initialize reqruied properties
		checkResult(event->QueryInterface(IID_IAAFComponent, (void **)&pComponent));
		checkResult(pComponent->SetDataDef(defs.ddkAAFPicture()));
		event->SetPosition(1);

		aafRational_t EventeditRate = { 0, 1};

		//get the segment
		checkResult(event->QueryInterface (IID_IAAFSegment, (void **)&seg));
		checkResult(pMobInterface2->AppendNewEventSlot (  EventeditRate,
															seg,
															9,
															slotNames[8],
															0,
															&newEventSlot));

		if(newEventSlot)
			newEventSlot->Release();
		newEventSlot = NULL;

		seg->Release();
		seg = NULL;

		pComponent->Release();
		pComponent = NULL;

		event->Release();
		event = NULL;

		pcdEventConcrete->Release();
		pcdEventConcrete = NULL;

		pcdEvent->Release();
		pcdEvent = NULL;

		pcdEventMeta->Release();
		pcdEventMeta = NULL;


		// Try CountKLVData before any have been attached
		numFound = 1;
		checkResult(pMob->CountKLVData(&numFound));
		checkExpression(numFound == 0, AAFRESULT_TEST_FAILED);
		checkExpression(pMob->CountKLVData(NULL) == AAFRESULT_NULL_PARAM,
			AAFRESULT_TEST_FAILED);		  
		// AppendKLVData - attach some objects
		checkResult(pDictionary->LookupTypeDef (kAAFTypeID_UInt8Array, &pBaseType));
		checkResult(pDictionary->RegisterKLVDataKey(TEST_KLV, pBaseType));
		pBaseType->Release();
		pBaseType = NULL;

		checkExpression(pMob->AppendKLVData(NULL) == AAFRESULT_NULL_PARAM,
		  												AAFRESULT_TEST_FAILED);	
 		checkResult(defs.cdKLVData()->
					  CreateInstance(IID_IAAFKLVData, 
									 (IUnknown **)&pKLVData));									 		
		checkResult(pKLVData->Initialize(TEST_KLV, sizeof(KLVfrowney), 
		  													(unsigned char *)KLVfrowney));
		checkResult(pMob->AppendKLVData(pKLVData));		  
		pKLVData->Release();
		pKLVData = NULL;
		  
 		checkResult(defs.cdKLVData()->
					  CreateInstance(IID_IAAFKLVData, 
									 (IUnknown **)&pKLVData));
		checkResult(pKLVData->Initialize(TEST_KLV, sizeof(KLVfrowney), 
		  													(unsigned char *)KLVfrowney));
		checkResult(pMob->AppendKLVData(pKLVData));		  
		checkExpression(pMob->AppendKLVData(pKLVData) == AAFRESULT_OBJECT_ALREADY_ATTACHED,
		  														AAFRESULT_TEST_FAILED);		  
		  												
		// RemoveKLVData - remove object #2
		checkExpression(pMob->RemoveKLVData(NULL) == AAFRESULT_NULL_PARAM,
		  												AAFRESULT_TEST_FAILED);		  
 		checkResult(pMob->CountKLVData(&numFound));
		checkExpression(numFound == 2, AAFRESULT_TEST_FAILED);
 		checkResult(pMob->RemoveKLVData(pKLVData));
 		checkResult(pMob->CountKLVData(&numFound));
		checkExpression(numFound == 1, AAFRESULT_TEST_FAILED);
		pKLVData->Release();
		pKLVData = NULL;
 		  
		// Try removing an object that is not attached
 		checkResult(defs.cdKLVData()->
					  CreateInstance(IID_IAAFKLVData, 
									 (IUnknown **)&pKLVData));
		checkResult(pKLVData->Initialize(TEST_KLV, sizeof(KLVsmiley), 
		  													(unsigned char *)KLVsmiley));
		checkExpression(pMob->RemoveKLVData(pKLVData) == AAFRESULT_OBJECT_NOT_ATTACHED, 
		  												AAFRESULT_TEST_FAILED);
		// Attach it to replace the one removed												
		checkResult(pMob->AppendKLVData(pKLVData));

		pKLVData->Release();
		pKLVData = NULL;

		// Comments
		checkExpression(pMob->GetComments(&enumTaggedVal) == AAFRESULT_PROP_NOT_PRESENT,
													AAFRESULT_TEST_FAILED);
		// Check CountComments()
		checkExpression(pMob->CountComments(NULL) == AAFRESULT_NULL_PARAM,
															AAFRESULT_TEST_FAILED);
		numComments = 1;
		checkResult(pMob->CountComments(&numComments));
		checkExpression(numComments == 0, AAFRESULT_TEST_FAILED);
		
		// Check AppendComments()
		checkExpression(pMob->AppendComment(NULL, pComment[0]) == AAFRESULT_NULL_PARAM,
																	AAFRESULT_TEST_FAILED);
		checkExpression(pMob->AppendComment(const_cast<aafWChar*>(pCategory[0]), NULL) == AAFRESULT_NULL_PARAM,
																	AAFRESULT_TEST_FAILED);
		for (i = 0; i < 5; ++i)
		{
		checkResult(pMob->AppendComment(const_cast<aafWChar*>(pCategory[i]), pComment[i]));
		}

		checkResult(pMob->CountComments(&numComments));
		checkExpression(numComments == 5, AAFRESULT_TEST_FAILED);

		// Check GetComments()
		checkExpression(pMob->GetComments(NULL) == AAFRESULT_NULL_PARAM,
													AAFRESULT_TEST_FAILED);
		checkResult(pMob->GetComments(&enumTaggedVal));
		for (i = 0; i < 5; ++i)
		{						
			checkResult(enumTaggedVal->NextOne(&taggedVal));
			
			checkResult(taggedVal->GetNameBufLen(&bufLen));
			checkResult(taggedVal->GetName(name, bufLen));
			checkExpression(wcscmp(name, pCategory[i]) == 0, AAFRESULT_TEST_FAILED);
			
			checkResult(taggedVal->GetValueBufLen(&bufLen));
			checkResult(taggedVal->GetValue(bufLen, (aafDataBuffer_t)value, &bytesRead));
			checkExpression(wcscmp(value, pComment[i]) == 0, AAFRESULT_TEST_FAILED);

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

		
 		checkResult(defs.cdTaggedValue()->
					  CreateInstance(IID_IAAFTaggedValue, 
									 (IUnknown **)&taggedVal));		
						
		checkExpression(pMob->RemoveComment(taggedVal) == AAFRESULT_OBJECT_NOT_ATTACHED, 
													AAFRESULT_TEST_FAILED);
		taggedVal->Release();
		taggedVal = NULL;

		enumTaggedVal->Reset();
		enumTaggedVal->Skip(2);
		checkResult(enumTaggedVal->NextOne(&taggedVal));
		checkExpression(pMob->RemoveComment(NULL) == AAFRESULT_NULL_PARAM, 
													AAFRESULT_TEST_FAILED);
		checkResult(pMob->RemoveComment(taggedVal));
		taggedVal->Release();
		taggedVal = NULL;
			
		enumTaggedVal->Reset();
		for (i = 0; i < 5; ++i)
		{
 			if (i==2)
 				continue;
 										
			checkResult(enumTaggedVal->NextOne(&taggedVal));
			
			checkResult(taggedVal->GetNameBufLen(&bufLen));
			checkResult(taggedVal->GetName(name, bufLen));
			checkExpression(wcscmp(name, pCategory[i]) == 0, AAFRESULT_TEST_FAILED);
			
			checkResult(taggedVal->GetValueBufLen(&bufLen));
			checkResult(taggedVal->GetValue(bufLen, (aafDataBuffer_t)value, &bytesRead));
			checkExpression(wcscmp(value, pComment[i]) == 0, AAFRESULT_TEST_FAILED);

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

		enumTaggedVal->Release();
		enumTaggedVal = NULL;
		

  	  // Check the Mob2 attribute and usage code implementations.
 	  // Need IAAFMob2 for that;
	 checkResult( pMobInterface2->AppendAttribute( AttributeNames[0], AttributeValues[0] ) );
	 checkResult( pMobInterface2->AppendAttribute( AttributeNames[1], AttributeValues[1] ) );
	 checkResult( pMobInterface2->SetUsageCode( kAAFUsage_SubClip ) );

	  // Add the mob to the file.
	  checkResult(pHeader->AddMob(pMob));

	  // Test changing the mob id after the mob is attached to the
	  // content store.  Change it, then reset to the original id.
	  checkResult(pMob->SetMobID(MOBTestID2));
	  checkResult(pMob->SetMobID(MOBTestID));
	  
	  // Create another Mob, check mob count, then delete and recheck count
	  checkResult(defs.cdMasterMob()->
				  CreateInstance(IID_IAAFMob, 
								 (IUnknown **)&pMob2));

	  checkResult(pMob2->SetMobID(MOBTestID2));
	  checkResult(pMob2->SetName(mobName));
	  
	  checkResult(pMob2->SetCreateTime(creationTimeStamp));
	  checkResult(pMob2->SetModTime(modificationTimeStamp));
	  // Add the mob to the file.
	  checkResult(pHeader->AddMob(pMob2));
	  checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs));
	  checkExpression(numMobs == 2, AAFRESULT_TEST_FAILED);
	  checkResult(pHeader->RemoveMob(pMob2));
	  checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs));
	  checkExpression(numMobs == 1, AAFRESULT_TEST_FAILED);

	  //try Copy()
	  const aafCharacter *copy_name = L"Name of Copied Mob";
	  IAAFMobSP spCopiedMob;
	  checkResult(pMob->Copy(copy_name, &spCopiedMob));
	  checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs));
	  checkExpression(numMobs == 2, AAFRESULT_TEST_FAILED);
	  checkResult(pHeader->RemoveMob(spCopiedMob));
	  checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs));
	  checkExpression(numMobs == 1, AAFRESULT_TEST_FAILED);

	  //try CloneExternal
	  IAAFMobSP spClonedMob;
	  IAAFFileSP spDestFile;
	  aafCharacter dest_filename[128];
	  wcscpy(dest_filename, pFileName);
	  wcscat(dest_filename, L"_clone");


	  // Remove the previous test file if any.
	  RemoveTestFile(dest_filename);
	  checkResult(CreateTestFile( dest_filename, fileKind, rawStorageType, productID, &spDestFile ));
	  checkResult(pMob->CloneExternal(kAAFNoFollowDepend, kAAFNoIncludeMedia, spDestFile, &spClonedMob));
	  checkResult(spDestFile->Save());	  	
	  checkResult(spDestFile->Close());	  	
	}
  catch (HRESULT& rResult)
	{
	  hr = rResult;
	}


  // Cleanup and return
  if (enumTaggedVal)
    enumTaggedVal->Release();

  if (newSlot)
    newSlot->Release();

  if (newStaticSlot)
	newStaticSlot->Release();
		 

  if (seg)
    seg->Release();

  if (pComponent)
    pComponent->Release();

  if (sclp)
    sclp->Release();

  if (pMob)
    pMob->Release();

  if (pMob2)
    pMob2->Release();

  if (pMobInterface2)
    pMobInterface2->Release();

  if (pDictionary)
    pDictionary->Release();

  if (pHeader)
    pHeader->Release();

 if(pcdEventMeta)
	  pcdEventMeta->Release();

 if(pcdEvent)
	  pcdEvent->Release();

  if(pcdEventConcrete)
	  pcdEventConcrete->Release();
 

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

  return hr;
}
コード例 #12
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;
  }
}