Exemplo n.º 1
0
//***********************************************************
//
//	SetIntegerPropOnObject()
//
//	Set an integer property to the AAF object specified by pObj.
//	The value of the property is specified in value.
//
//	Returns:
//
//		On Success: AAFRESULT_SUCCESS
//		On Failure: An exception.
//
HRESULT AAFDomainUtils::SetIntegerPropOnObject(IAAFObject* pObj, aafUID_t* pClassID, aafUID_t* pPropID, const aafUID_t* pIntTypeID,
        aafMemPtr_t pValue, aafUInt32 ValueSize, IAAFDictionary *dict)
{
    AAFCheck			hr;

    // Create a property value from the supplied value (pValue)
    IAAFTypeDef*		pTD;
    hr = dict->LookupTypeDef(*pIntTypeID, &pTD);
    AutoRelease<IAAFTypeDef> r1( pTD );

    IAAFTypeDefInt*	pTDInt;
    hr = pTD->QueryInterface(IID_IAAFTypeDefInt, (void**)&pTDInt);
    AutoRelease<IAAFTypeDefInt> r2( pTDInt );

    // Now create a property value object with that value.
    IAAFPropertyValue*	pPV;
    hr = pTDInt->CreateValue(pValue, ValueSize, &pPV);
    AutoRelease<IAAFPropertyValue> r3( pPV );

    // Add the property to the target object.
    // Get the class def for the object
    IAAFClassDef*	pCD;
    hr = dict->LookupClassDef(*pClassID, &pCD);
    AutoRelease<IAAFClassDef> r4( pCD );

    IAAFPropertyDef*	pPD;
    hr = pCD->LookupPropertyDef(*pPropID, &pPD);
    AutoRelease<IAAFPropertyDef> r5( pPD );

    // Set the propeter value on the target object
    hr = pObj->SetPropertyValue(pPD, pPV);

    return AAFRESULT_SUCCESS;
}
Exemplo n.º 2
0
//***********************************************************
//
//	GetIntegerPropFromObject()
//
//	Get an integer property from the AAF object specified by pObj.
//	The value of the property is returned in pValue.
//
//	Returns:
//
//		On Success: AAFRESULT_SUCCESS
//		On Failure: An exception.
//
HRESULT AAFDomainUtils::GetIntegerPropFromObject(IAAFObject* pObj, const aafUID_t* pClassID, aafUID_t* pPropID, const aafUID_t* pIntTypeID, aafMemPtr_t pValue, aafUInt32 ValueSize, IAAFDictionary *dict)
{
    AAFCheck				hr;

    // Get the property value for the target property
    IAAFClassDef*		pCD;
    hr = dict->LookupClassDef(*pClassID, &pCD);
    AutoRelease<IAAFClassDef> r1(pCD);

    IAAFPropertyDef*	pPD;
    hr = pCD->LookupPropertyDef(*pPropID, &pPD);
    AutoRelease<IAAFPropertyDef> r2( pPD );

    aafBool	present = kAAFFalse;
    pObj->IsPropertyPresent(pPD, &present);
    IAAFPropertyValue*	pPV = NULL;
    AutoRelease<IAAFPropertyValue> r3;

    if (present == kAAFTrue)
    {
        hr = pObj->GetPropertyValue(pPD, &pPV);
        r3 = pPV;
    }
    else
    {
        hr = AAFRESULT_PROP_NOT_PRESENT;
    }

    // Get the type def from the dict with which to interpret this
    // property value.
    IAAFTypeDef* pTD;
    hr = dict->LookupTypeDef(*pIntTypeID, &pTD);
    AutoRelease< IAAFTypeDef > r4 (pTD);

    IAAFTypeDefInt* pTDInt;
    hr = pTD->QueryInterface(IID_IAAFTypeDefInt, (void**)&pTDInt);
    AutoRelease< IAAFTypeDefInt > r5( pTDInt );

    pTDInt->GetInteger(pPV, pValue, ValueSize);

    return AAFRESULT_SUCCESS;
}
Exemplo n.º 3
0
static HRESULT TestPropertyValue (
    testMode_t mode,
    aafUID_constref fileKind,
    testRawStorageType_t rawStorageType,
    aafProductIdentification_constref productID)
{
  // HRESULT hr = E_FAIL;
  long hr = E_FAIL;

  const size_t fileNameBufLen = 128;
  aafWChar testFileName[ fileNameBufLen ] = L"";
  GenerateTestFileName( productID.productName, fileKind, fileNameBufLen, testFileName );

  IAAFFile* pFile = NULL;
  if(mode == kAAFUnitTestReadWrite)
  {
  	RemoveTestFile (testFileName);
  	checkResult (CreateTestFile( testFileName, fileKind, rawStorageType, productID, &pFile ));
 	 assert (pFile);
 }
  else
  {
  	checkResult (AAFFileOpenExistingRead(testFileName, 0, &pFile));
 	 assert (pFile);
 }

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

  IAAFDictionary * pDict = NULL;
  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
  IAAFTypeDefInt * pTypeDef = NULL;
  hr = defs.tdInt32()->QueryInterface (IID_IAAFTypeDefInt, (void **) &pTypeDef);
  if (! SUCCEEDED (hr)) return hr;
  assert (pTypeDef);

  if(mode == kAAFUnitTestReadWrite)
	{
		  // Now attempt to create invalid property values; check for errors.
	  const aafInt32 forty_two = 42;
	  IAAFPropertyValue * pv = NULL;
	  // This is what a correct one would look like; we're not ready for that yet:
	  // hr = pTypeDef->CreateValue (&forty_two, 4, &pv);

	  // set this to -1 to see if it gets modified
	  pv = (IAAFPropertyValue *) (-1);

	  // Try null pVal
	  hr = pTypeDef->CreateValue (NULL, 4, &pv);
	  if (AAFRESULT_NULL_PARAM != hr)
		return AAFRESULT_TEST_FAILED;
	  if ((IAAFPropertyValue *)(-1) != pv)
		return AAFRESULT_TEST_FAILED;

	  // Try valSize too large
	  hr = pTypeDef->CreateValue ((aafMemPtr_t) &forty_two, 8, &pv);
	  if (AAFRESULT_BAD_SIZE != hr)
		return AAFRESULT_TEST_FAILED;
	  if ((IAAFPropertyValue *)(-1) != pv)
		return AAFRESULT_TEST_FAILED;

	  // Now try correct one
	  pv = NULL;
	  hr = pTypeDef->CreateValue ((aafMemPtr_t) &forty_two, 4, &pv);
	  if (! SUCCEEDED (hr)) return hr;
	  if (! pv)
		return AAFRESULT_TEST_FAILED;

	  // That one worked; let's try one with a smaller init size (should
	  // also work)
	  pv->Release();
	  pv = NULL;
	  const aafInt16 fifty_seven = 57;
	  hr = pTypeDef->CreateValue ((aafMemPtr_t) &fifty_seven, 2, &pv);
	  if (! SUCCEEDED (hr)) return hr;
	  if (! pv)
		return AAFRESULT_TEST_FAILED;

	  // cool.  Now we should have a good property value whose value is 57.
	  // check GetType() for error condition
	  hr = pv->GetType (NULL);
	  if (AAFRESULT_NULL_PARAM != hr)
		return AAFRESULT_TEST_FAILED;

	  // this GetType() call should work, and return the original type def.
	  IAAFTypeDef * propType = NULL;
	  hr = pv->GetType (&propType);
	  if (! SUCCEEDED (hr)) return hr;
	  if (! propType)
		return AAFRESULT_TEST_FAILED;

	  // Convert both to IUnknown for comparison
	  IUnknown * pPropUnknown = NULL;
	  IUnknown * pTypeDefUnknown = NULL;
	  hr = propType->QueryInterface(IID_IUnknown, (void **)&pPropUnknown);
	  if (! SUCCEEDED (hr)) return hr;
	  assert (pPropUnknown);
	  hr = pTypeDef->QueryInterface(IID_IUnknown, (void **)&pTypeDefUnknown);
	  if (! SUCCEEDED (hr)) return hr;
	  assert (pTypeDefUnknown);

	  if (pPropUnknown != pTypeDefUnknown)
		return AAFRESULT_TEST_FAILED;
	  // Test IsDefinedType ()
	  // (Currently only returns true.)
	  aafBool b = kAAFFalse;
	  hr = pv->IsDefinedType (&b);
		if (! SUCCEEDED (hr)) return hr;
	  if (kAAFTrue != b)
		return AAFRESULT_TEST_FAILED;

	  pTypeDefUnknown->Release();
	  pPropUnknown->Release();
	  pTypeDef->Release();
	  propType->Release();
	  pv->Release();
	  pDict->Release();
	  pHeader->Release();
	  hr = pFile->Save();
	}
  if (! SUCCEEDED (hr)) return hr;
  hr = pFile->Close();
  if (! SUCCEEDED (hr)) return hr;
  pFile->Release();

  return AAFRESULT_SUCCESS;
}
Exemplo n.º 4
0
static bool testRestore(const wchar_t* fileName)
{
    bool passed = true;

    IAAFFile* pFile = 0;
    IAAFHeader* pHeader = 0;
    IAAFDictionary* pDictionary = 0;
    IAAFContentStorage* pStorage = 0;
    IEnumAAFMobs* pMobs = 0;
    IAAFMob* pMob = 0;

    try
    {
        pFile = openFileForReading(fileName);
    }
    catch (...)
    {
        return false;
    }

    try
    {
        // get the Mob containing the test data
        checkResult(pFile->GetHeader(&pHeader));
        checkResult(pHeader->GetDictionary(&pDictionary));
        checkResult(pHeader->GetContentStorage(&pStorage));
        aafSearchCrit_t searchCrit;
        searchCrit.searchTag = kAAFByMobKind;
        searchCrit.tags.mobKind = kAAFAllMob;
        checkResult(pStorage->GetMobs(&searchCrit, &pMobs));
        checkResult(pMobs->NextOne(&pMob));

        IAAFObject* pObject = 0;
        IAAFClassDef* pClassDef = 0;
        IAAFPropertyDef* pPropertyDef = 0;
        IAAFPropertyValue* pPropertyValue = 0;
        IAAFTypeDef* pType = 0;
        IAAFTypeDefFixedArray* pFixedArrayType = 0;
        IAAFTypeDefInt* pIntType = 0;
        IAAFPropertyValue* pIntValue = 0;

        try
        {
            printf("    * Baseline element type: ");

            const aafUID_t propId =
            {0x00000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}};
            aafUInt8 testValue[2] = {0,255};

            checkResult(pMob->QueryInterface(IID_IAAFObject, (void **)&pObject));

            checkResult(pDictionary->LookupClassDef(kAAFClassID_Mob, &pClassDef));
            checkResult(pClassDef->LookupPropertyDef(propId, &pPropertyDef));

            checkResult(pObject->GetPropertyValue(pPropertyDef, &pPropertyValue));
            checkResult(pPropertyValue->GetType(&pType));
            checkResult(pType->QueryInterface(IID_IAAFTypeDefFixedArray, (void **)&pFixedArrayType));
            release(pType);

            checkResult(pFixedArrayType->GetType(&pType));
            checkResult(pType->QueryInterface(IID_IAAFTypeDefInt, (void **)&pIntType));

            aafUInt8 value[2];

            checkResult(pFixedArrayType->GetElementValue(pPropertyValue, 0, &pIntValue));
            checkResult(pIntType->GetInteger(pIntValue, &value[0], 1));

            release(pIntValue);
            checkResult(pFixedArrayType->GetElementValue(pPropertyValue, 1, &pIntValue));
            checkResult(pIntType->GetInteger(pIntValue, &value[1], 1));

            if (value[0] == testValue[0] && value[1] == testValue[1])
            {
                printf("passed\n");
            }
            else
            {
                printf("FAILED\n");
                passed = false;
            }
        }
        catch (...)
        {
            printf("FAILED\n");
            passed = false;
        }
        release(pIntValue);
        release(pIntType);
        release(pFixedArrayType);
        release(pType);
        release(pPropertyValue);
        release(pPropertyDef);
        release(pClassDef);
        release(pObject);

        try
        {
            printf("    * Non-Baseline element type: ");

            const aafUID_t propId =
            {0x10000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}};
            aafUInt8 testValue[2] = {1,2};

            checkResult(pMob->QueryInterface(IID_IAAFObject, (void **)&pObject));

            checkResult(pDictionary->LookupClassDef(kAAFClassID_Mob, &pClassDef));
            checkResult(pClassDef->LookupPropertyDef(propId, &pPropertyDef));

            checkResult(pObject->GetPropertyValue(pPropertyDef, &pPropertyValue));
            checkResult(pPropertyValue->GetType(&pType));
            checkResult(pType->QueryInterface(IID_IAAFTypeDefFixedArray, (void **)&pFixedArrayType));
            release(pType);

            checkResult(pFixedArrayType->GetType(&pType));
            checkResult(pType->QueryInterface(IID_IAAFTypeDefInt, (void **)&pIntType));

            aafUInt8 value[2];

            checkResult(pFixedArrayType->GetElementValue(pPropertyValue, 0, &pIntValue));
            checkResult(pIntType->GetInteger(pIntValue, &value[0], 1));

            release(pIntValue);
            checkResult(pFixedArrayType->GetElementValue(pPropertyValue, 1, &pIntValue));
            checkResult(pIntType->GetInteger(pIntValue, &value[1], 1));

            if (value[0] == testValue[0] && value[1] == testValue[1])
            {
                printf("passed\n");
            }
            else
            {
                printf("FAILED\n");
                passed = false;
            }
        }
        catch (...)
        {
            printf("FAILED\n");
            passed = false;
        }
        release(pIntValue);
        release(pIntType);
        release(pFixedArrayType);
        release(pType);
        release(pPropertyValue);
        release(pPropertyDef);
        release(pClassDef);
        release(pObject);

    }
    catch (...)
    {
        passed = false;
    }

    // cleanup
    release(pMob);
    release(pMobs);
    release(pStorage);
    release(pDictionary);
    release(pHeader);
    checkResult(pFile->Close());
    release(pFile);

    report(passed);

    return passed;
}
Exemplo n.º 5
0
static bool testRestore(const wchar_t* fileName)
{
    bool passed = true;
    
    IAAFFile* pFile = 0;
    IAAFHeader* pHeader = 0;
    IAAFDictionary* pDictionary = 0;
    IAAFContentStorage* pStorage = 0;
    IEnumAAFMobs* pMobs = 0;
    IAAFMob* pMob = 0;
    
    try
    {
        pFile = openFileForReading(fileName);
    }
    catch (...)
    {
        return false;
    }
    
    try
    {
        // get the Mob containing the test data
        checkResult(pFile->GetHeader(&pHeader));
        checkResult(pHeader->GetDictionary(&pDictionary));
        checkResult(pHeader->GetContentStorage(&pStorage));
        aafSearchCrit_t searchCrit;
        searchCrit.searchTag = kAAFByMobKind;
        searchCrit.tags.mobKind = kAAFAllMob;
        checkResult(pStorage->GetMobs(&searchCrit, &pMobs));
        checkResult(pMobs->NextOne(&pMob));
        
        IAAFObject* pObject = 0;
        IAAFClassDef* pClassDef = 0;
        IAAFPropertyDef* pPropertyDef = 0;
        IAAFPropertyValue* pPropertyValue = 0;
        IAAFTypeDef* pType = 0;
        IAAFTypeDefIndirect* pIndirectType = 0;
        IAAFPropertyValue* pActualPropertyValue = 0;
        IAAFTypeDef* pActualType = 0;
        IAAFTypeDefInt* pIntType = 0;
        IAAFTypeDefEnum* pEnumType = 0;
        IAAFTypeDefRecord* pRecordType = 0;

        try
        {
            printf("    * Baseline: ");

            const aafUID_t propId = 
                {0x00000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}};
            aafInt8 testValue = -128;
            
            checkResult(pMob->QueryInterface(IID_IAAFObject, (void **)&pObject));
            
            checkResult(pDictionary->LookupClassDef(kAAFClassID_Mob, &pClassDef));
            checkResult(pClassDef->LookupPropertyDef(propId, &pPropertyDef));
            
            checkResult(pObject->GetPropertyValue(pPropertyDef, &pPropertyValue));
            checkResult(pPropertyValue->GetType(&pType));
            checkResult(pType->QueryInterface(IID_IAAFTypeDefIndirect, (void **)&pIndirectType));
            
            checkResult(pIndirectType->GetActualValue(pPropertyValue, &pActualPropertyValue));
            checkResult(pActualPropertyValue->GetType(&pActualType));
            checkResult(pActualType->QueryInterface(IID_IAAFTypeDefInt, (void **)&pIntType));
            
            aafInt8 value;
            checkResult(pIntType->GetInteger(pActualPropertyValue, (aafUInt8*)&value, 1));

            if (value == testValue)
            {
                printf("passed\n");
            }
            else
            {
                printf("FAILED\n");
                passed = false;
            }
        }
        catch (...)
        {
            printf("FAILED\n");
            passed = false;
        }
        release(pRecordType);
        release(pEnumType);
        release(pIntType);
        release(pActualType);
        release(pActualPropertyValue);
        release(pIndirectType);
        release(pType);
        release(pPropertyValue);
        release(pPropertyDef);
        release(pClassDef);
        release(pObject);
        
        try
        {
            printf("    * Non-baseline: ");

            const aafUID_t propId = 
                {0x10000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}};
            aafUInt8 testValue = 1;
            const wchar_t* testName = L"AAA";
            
            checkResult(pMob->QueryInterface(IID_IAAFObject, (void **)&pObject));
            
            checkResult(pDictionary->LookupClassDef(kAAFClassID_Mob, &pClassDef));
            checkResult(pClassDef->LookupPropertyDef(propId, &pPropertyDef));
            
            checkResult(pObject->GetPropertyValue(pPropertyDef, &pPropertyValue));
            checkResult(pPropertyValue->GetType(&pType));
            checkResult(pType->QueryInterface(IID_IAAFTypeDefIndirect, (void **)&pIndirectType));
            
            checkResult(pIndirectType->GetActualValue(pPropertyValue, &pActualPropertyValue));
            checkResult(pActualPropertyValue->GetType(&pActualType));
            checkResult(pActualType->QueryInterface(IID_IAAFTypeDefEnum, (void **)&pEnumType));
            
            aafInt64 value;
            aafCharacter name[256];
            checkResult(pEnumType->GetIntegerValue(pActualPropertyValue, &value));
            checkResult(pEnumType->GetNameFromValue(pActualPropertyValue, name, 256));

            if (value == testValue && wcscmp(name, testName) == 0)
            {
                printf("passed\n");
            }
            else
            {
                printf("FAILED\n");
                passed = false;
            }
        }
        catch (...)
        {
            printf("FAILED\n");
            passed = false;
        }
        release(pRecordType);
        release(pEnumType);
        release(pIntType);
        release(pActualType);
        release(pActualPropertyValue);
        release(pIndirectType);
        release(pType);
        release(pPropertyValue);
        release(pPropertyDef);
        release(pClassDef);
        release(pObject);
        
        try
        {
            printf("    * Baseline record: ");

            const aafUID_t propId = 
                {0x20000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}};
            aafProductVersion_t testValue = {0,1,0,0,kAAFVersionUnknown};
            
            checkResult(pMob->QueryInterface(IID_IAAFObject, (void **)&pObject));
            
            checkResult(pDictionary->LookupClassDef(kAAFClassID_Mob, &pClassDef));
            checkResult(pClassDef->LookupPropertyDef(propId, &pPropertyDef));
            
            checkResult(pObject->GetPropertyValue(pPropertyDef, &pPropertyValue));
            checkResult(pPropertyValue->GetType(&pType));
            checkResult(pType->QueryInterface(IID_IAAFTypeDefIndirect, (void **)&pIndirectType));

            checkResult(pIndirectType->GetActualValue(pPropertyValue, &pActualPropertyValue));
            checkResult(pActualPropertyValue->GetType(&pActualType));
            checkResult(pActualType->QueryInterface(IID_IAAFTypeDefRecord, (void **)&pRecordType));
            
            aafProductVersion_t value;
            checkResult(pRecordType->GetStruct(pActualPropertyValue, (aafUInt8*)&value, sizeof(aafProductVersion_t)));

            if (memcmp(&testValue, &value, sizeof(aafProductVersion_t)) == 0)
            {
                printf("passed\n");
            }
            else
            {
                printf("FAILED\n");
                passed = false;
            }
        }
        catch (...)
        {
            printf("FAILED\n");
            passed = false;
        }
        release(pRecordType);
        release(pEnumType);
        release(pIntType);
        release(pActualType);
        release(pActualPropertyValue);
        release(pIndirectType);
        release(pType);
        release(pPropertyValue);
        release(pPropertyDef);
        release(pClassDef);
        release(pObject);
        
    }
    catch (...)
    {
        passed = false;
    }

    // cleanup    
    release(pMob);
    release(pMobs);
    release(pStorage);
    release(pDictionary);
    release(pHeader);
    checkResult(pFile->Close());
    release(pFile);

    report(passed);
    
    return passed;
}