/** * Read a text string from a file. * @return true on success, false on error. */ bool FileUtil::readTextFromFile( const MAUtil::String& filePath, MAUtil::String& inText) { MAHandle file = openFileForReading(filePath); if (file < 0) { return false; } int size = maFileSize(file); if (size < 1) { return false; } // Allocate buffer with space for a null termination character. char* buffer = (char*) malloc(sizeof(char) * (size + 1)); int result = maFileRead(file, buffer, size); maFileClose(file); buffer[size] = 0; inText = buffer; return result == 0; }
/** * Read a data object from a file. * @param filePath Full path of file to read. * @param inPlaceholder Placeholder handle for data object. * @return true on success, false on error. */ bool FileUtil::readDataFromFile( const MAUtil::String& filePath, MAHandle inPlaceholder) { MAHandle file = openFileForReading(filePath); if (file < 0) { return false; } int size = maFileSize(file); if (size < 1) { return false; } int result = maCreateData(inPlaceholder, size); if (RES_OK != result) { return false; } result = maFileReadToData(file, inPlaceholder, 0, size); maFileClose(file); return result == 0; }
int readGPIO(int fileHandle,int gpio) { int value; //Reopening the file again in read mode, since data was not refreshing. fileHandle = openFileForReading(gpio); read(fileHandle, &value, 1); if('0' == value) { // Current GPIO status low value = 0; } else { // Current GPIO status high value = 1; } close(fileHandle); return value; }
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; IAAFTypeDefCharacter* pCharacterType = 0; // test simple try { printf(" * Simple: "); const aafUID_t propId = {0x00000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; wchar_t testCharacter = L'A'; 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_IAAFTypeDefCharacter, (void **)&pCharacterType)); aafCharacter value; checkResult(pCharacterType->GetCharacter(pPropertyValue, &value)); if (value == testCharacter) { printf("passed\n"); } else { printf("FAILED\n"); passed = false; } } catch (...) { printf("FAILED\n"); passed = false; } release(pCharacterType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); // test XML escaped try { printf(" * XML escaped: "); const aafUID_t propId = {0x10000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; wchar_t testCharacter = L'\r'; 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_IAAFTypeDefCharacter, (void **)&pCharacterType)); aafCharacter value; checkResult(pCharacterType->GetCharacter(pPropertyValue, &value)); if (value == testCharacter) { printf("passed\n"); } else { printf("FAILED\n"); passed = false; } } catch (...) { printf("FAILED\n"); passed = false; } release(pCharacterType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); // test AAF escaped try { printf(" * AAF escaped: "); const aafUID_t propId = {0x20000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; wchar_t testCharacter = 0x0; 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_IAAFTypeDefCharacter, (void **)&pCharacterType)); aafCharacter value; checkResult(pCharacterType->GetCharacter(pPropertyValue, &value)); if (value == testCharacter) { printf("passed\n"); } else { printf("FAILED\n"); passed = false; } } catch (...) { printf("FAILED\n"); passed = false; } release(pCharacterType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); // test AAF escaped of invalid UNICODE character try { printf(" * AAF escaped invalid Unicode character: "); const aafUID_t propId = {0x30000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; wchar_t testCharacter = 0xFFFF; 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_IAAFTypeDefCharacter, (void **)&pCharacterType)); aafCharacter value; checkResult(pCharacterType->GetCharacter(pPropertyValue, &value)); if (value == testCharacter) { printf("passed\n"); } else { printf("FAILED\n"); passed = false; } } catch (...) { printf("FAILED\n"); passed = false; } release(pCharacterType); 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; }
/*-------------------- readFile --------------------*/ File_t readFile ( ParameterSpecification_t fileSpecifier, /* in */ const char * filename /* in */ ) { File_t returnValue; FILE * filePointer; long fileLength; if( FileOpened == openFileForReading( filename, &filePointer ) ) { if( Success == getFileLength( filePointer, &fileLength ) ) { void * ptr; /* * Allocate one byte more if a newline must be added */ if( Success == allocateBuffer( fileLength + 1 , &ptr ) ) { char * buffer = ( char * )ptr; if( Success == readFileToBuffer( filePointer, fileLength, &buffer ) ) { if ( FALSE == queryParameter( IgnoreEOF ) ) { char * eof = (buffer + fileLength - 1); if ( *eof != '\n' ) { *( eof + 1 ) = '\n'; fileLength++; } } addToWatchdog( fileLength ); associateBuffer( fileSpecifier, fileLength, &buffer ); returnValue = FileOperationsSuccessful; } else { freeBuffer( &buffer ); returnValue = FileOperationsFailed; } } else { returnValue = FileOperationsFailed; } } else { returnValue = FileOperationsFailed; } closeFile( filePointer ); } else { returnValue = FileOperationsFailed; } return( returnValue ); }
bool TriMesh::readFromPly(const string &fileName, bool flipZ) { name = fileName; FILE *f = openFileForReading(fileName); if (f == NULL) return false; string token, t; int numVertices = 0; int numFaces = 0; int numTriangles = 0; vector<int> faceIndices; // get num vertices while (getToken(f, token, "")) { //cout << token << endl; if (token == "vertex") break; } getToken(f, token, ""); numVertices = atoi(token.c_str()); // get vertex attributes while (getToken(f, token, "")) { if (token == "property") { getToken(f, t, ""); // token should be "float" getToken(f, t, ""); // attribute name attributes.push_back(t); } else if (token == "face") { getToken(f, t, ""); numFaces = atoi(t.c_str()); break; } } // read to end of header while (getToken(f, token, "")) { if (token == "end_header") break; } // get vertices float val; for (int i = 0; i < (int)(numVertices*attributes.size()); i++) { //getToken(f, token, ""); //vertexData.push_back((float)atof(token.c_str())); fscanf(f, "%f", &val); vertexData.push_back(val); } // divide color values by 255, and flip normal directions if needed // This deals with issues related to exporting from Blender to ply // usin the y-axis as UP and the z-axis as FRONT. for (int i = 0; i < (int)attributes.size(); i++) { if (attributes[i] == "red" || attributes[i] == "green" || attributes[i] == "blue") { for (int j = 0; j < numVertices; j++) { vertexData[i + j*attributes.size()] /= 255.0f; } } else if (flipZ && (attributes[i] == "z" || attributes[i] == "nz")) { for (int j = 0; j < numVertices; j++) { vertexData[i + j*attributes.size()] *= -1.0f; } } } // get faces int idx; for (int i = 0; i < numFaces; i++) { faceIndices.clear(); getToken(f, token, ""); int numVerts = atoi(token.c_str()); for (int j = 0; j < numVerts; j++) { // get all vertices in face //getToken(f, t, ""); //faceIndices.push_back(atoi(t.c_str())); fscanf(f, "%d", &idx); faceIndices.push_back(idx); } for (int j = 2; j < numVerts; j++) { // make triangle fan indices.push_back(faceIndices[0]); indices.push_back(faceIndices[j-1]); indices.push_back(faceIndices[j]); numTriangles++; } } numIndices = (int)indices.size(); //printf("vertices:%d, triangles:%d, attributes:%d\n", // vertexData.size()/attributes.size(), // indices.size()/3, // attributes.size()); fclose(f); return true; }
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; IAAFTypeDefExtEnum* pExtEnumType = 0; // test baseline ext. enum try { printf(" * Baseline: "); const aafUID_t propId = {0x00000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; aafUID_t testValue = {0x0D010102,0x0101,0x0500,{0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01}}; const wchar_t* testName = L"Usage_SubClip"; 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_IAAFTypeDefExtEnum, (void **)&pExtEnumType)); aafUID_t value; aafCharacter name[256]; checkResult(pExtEnumType->GetAUIDValue(pPropertyValue, &value)); checkResult(pExtEnumType->GetNameFromValue(pPropertyValue, name, 256)); if (memcmp(&value, &testValue, sizeof(aafUID_t)) ==0 && wcscmp(name, testName) == 0) { printf("passed\n"); } else { printf("FAILED\n"); passed = false; } } catch (...) { printf("FAILED\n"); passed = false; } release(pExtEnumType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); // test Int8 enum try { printf(" * Non-baseline Ext Enum: "); const aafUID_t propId = {0x10000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; aafUID_t testValue = {0x6f9685a4,0x0a0d,0x447b,{0x89,0xf3,0x1b,0x75,0x0b,0xc5,0xc7,0xde}}; 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_IAAFTypeDefExtEnum, (void **)&pExtEnumType)); aafUID_t value; aafCharacter name[256]; checkResult(pExtEnumType->GetAUIDValue(pPropertyValue, &value)); checkResult(pExtEnumType->GetNameFromValue(pPropertyValue, name, 256)); if (memcmp(&value, &testValue, sizeof(aafUID_t)) ==0 && wcscmp(name, testName) == 0) { printf("passed\n"); } else { printf("FAILED\n"); passed = false; } } catch (...) { printf("FAILED\n"); passed = false; } release(pExtEnumType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); // test baseline extension try { printf(" * Baseline extension: "); const aafUID_t propId = {0x20000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; aafUID_t testValue = {0x197e78ac,0xb464,0x4bd1,{0x86,0x11,0xb6,0xf2,0xdf,0x0d,0x03,0xfe}}; const wchar_t* testName = L"MyUsage"; 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_IAAFTypeDefExtEnum, (void **)&pExtEnumType)); aafUID_t value; aafCharacter name[256]; checkResult(pExtEnumType->GetAUIDValue(pPropertyValue, &value)); checkResult(pExtEnumType->GetNameFromValue(pPropertyValue, name, 256)); if (memcmp(&value, &testValue, sizeof(aafUID_t)) ==0 && wcscmp(name, testName) == 0) { printf("passed\n"); } else { printf("FAILED\n"); passed = false; } } catch (...) { printf("FAILED\n"); passed = false; } release(pExtEnumType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); // test non-baseline extension try { printf(" * Non-baseline extension: "); const aafUID_t propId = {0x30000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; aafUID_t testValue = {0xe54f0efa,0x15c1,0x468f,{0xb7,0x43,0x9b,0xfd,0x12,0x94,0x04,0x49}}; const wchar_t* testName = L"CCC"; 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_IAAFTypeDefExtEnum, (void **)&pExtEnumType)); aafUID_t value; aafCharacter name[256]; checkResult(pExtEnumType->GetAUIDValue(pPropertyValue, &value)); checkResult(pExtEnumType->GetNameFromValue(pPropertyValue, name, 256)); if (memcmp(&value, &testValue, sizeof(aafUID_t)) ==0 && wcscmp(name, testName) == 0) { printf("passed\n"); } else { printf("FAILED\n"); passed = false; } } catch (...) { printf("FAILED\n"); passed = false; } release(pExtEnumType); 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; }
QStringList Helper::loadTextFile(QString file_name, bool trim_lines, QChar skip_header_char, bool skip_empty_lines) { return loadTextFile(openFileForReading(file_name), trim_lines, skip_header_char, skip_empty_lines); }
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; IAAFTypeDefEnum* pEnumType = 0; try { printf(" * Baseline: "); const aafUID_t propId = {0x00000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; aafUInt8 testValue = 5; const wchar_t* testName = L"VersionPrivateBuild"; 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_IAAFTypeDefEnum, (void **)&pEnumType)); aafInt64 value; aafCharacter name[256]; checkResult(pEnumType->GetIntegerValue(pPropertyValue, &value)); checkResult(pEnumType->GetNameFromValue(pPropertyValue, 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(pEnumType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); try { printf(" * Enum element size 1 : "); 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_IAAFTypeDefEnum, (void **)&pEnumType)); aafInt64 value; aafCharacter name[256]; checkResult(pEnumType->GetIntegerValue(pPropertyValue, &value)); checkResult(pEnumType->GetNameFromValue(pPropertyValue, 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(pEnumType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); try { printf(" * Enum element size 2 : "); const aafUID_t propId = {0x20000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; aafUInt8 testValue = 2; const wchar_t* testName = L"BBB"; 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_IAAFTypeDefEnum, (void **)&pEnumType)); aafInt64 value; aafCharacter name[256]; checkResult(pEnumType->GetIntegerValue(pPropertyValue, &value)); checkResult(pEnumType->GetNameFromValue(pPropertyValue, 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(pEnumType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); try { printf(" * Enum element size 4 : "); const aafUID_t propId = {0x30000000,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_IAAFTypeDefEnum, (void **)&pEnumType)); aafInt64 value; aafCharacter name[256]; checkResult(pEnumType->GetIntegerValue(pPropertyValue, &value)); checkResult(pEnumType->GetNameFromValue(pPropertyValue, 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(pEnumType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); try { printf(" * Enum element size 8 : "); const aafUID_t propId = {0x40000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; aafUInt8 testValue = 2; const wchar_t* testName = L"BBB"; 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_IAAFTypeDefEnum, (void **)&pEnumType)); aafInt64 value; aafCharacter name[256]; checkResult(pEnumType->GetIntegerValue(pPropertyValue, &value)); checkResult(pEnumType->GetNameFromValue(pPropertyValue, 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(pEnumType); 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; }
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; }
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; }