void test04 (CIMClient & client) { CIMObjectPath instanceName; instanceName.setNameSpace (providerNamespace); instanceName.setClassName (CLASSNAME); Array < CIMParamValue > inParams; Array < CIMParamValue > outParams; /* [EmbeddedObject] String returnInstance(); */ CIMValue retValue = client.invokeMethod (providerNamespace, instanceName, "returnInstance", inParams, outParams); PEGASUS_TEST_ASSERT (retValue.getType () == CIMTYPE_OBJECT); PEGASUS_TEST_ASSERT (!retValue.isArray ()); PEGASUS_TEST_ASSERT (!retValue.isNull ()); CIMObject result; retValue.get (result); CIMObjectPath objPath = result.getPath(); PEGASUS_TEST_ASSERT (objPath.toString() == "TestCMPI_Instance"); }
void ReferencesResponseHandler::deliver(const CIMObject& cimObject) { if (cimObject.isUninitialized()) { MessageLoaderParms message( "Common.Exception.UNINITIALIZED_OBJECT_EXCEPTION", "The object is not initialized."); throw CIMException(CIM_ERR_FAILED, message); } SimpleObjectResponseHandler::deliver(cimObject); }
// Tests PROPERTY as an embedded object. static void testGetInstanceElement(const char* testDataFile) { //-------------------------------------------------------------------------- // Read in instance //-------------------------------------------------------------------------- CIMInstance cimInstance; Buffer text; FileSystem::loadFileToMemory(text, testDataFile); XmlParser parser((char*)text.getData()); XmlReader::getInstanceElement(parser, cimInstance); PEGASUS_TEST_ASSERT( cimInstance.getClassName() == CIMName("CIM_InstCreation")); Uint32 idx; CIMProperty cimProperty; CIMValue cimValue; CIMType cimType; PEGASUS_TEST_ASSERT(cimInstance.getPropertyCount() == 3); idx = cimInstance.findProperty(CIMName("IndicationIdentifier")); PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND); cimProperty = cimInstance.getProperty(idx); cimValue = cimProperty.getValue(); cimType = cimProperty.getType(); PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "string") == 0); String myString; cimValue.get(myString); PEGASUS_TEST_ASSERT(strcmp(myString.getCString(), "0") == 0); idx = cimInstance.findProperty(CIMName("IndicationTime")); PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND); cimProperty = cimInstance.getProperty(idx); cimValue = cimProperty.getValue(); cimType = cimProperty.getType(); PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "datetime") == 0); CIMDateTime myDateTime; cimValue.get(myDateTime); PEGASUS_TEST_ASSERT(myDateTime.equal( CIMDateTime("20050227225624.524000-300"))); idx = cimInstance.findProperty(CIMName("SourceInstance")); PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND); cimProperty = cimInstance.getProperty(idx); cimValue = cimProperty.getValue(); cimType = cimProperty.getType(); PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "object") == 0); CIMObject cimObject; cimValue.get(cimObject); PEGASUS_TEST_ASSERT( cimObject.getClassName() == CIMName("Sample_LifecycleIndicationProviderClass")); PEGASUS_TEST_ASSERT(cimObject.getPropertyCount() == 2); idx = cimObject.findProperty(CIMName("uniqueId")); PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND); cimProperty = cimObject.getProperty(idx); cimValue = cimProperty.getValue(); cimType = cimProperty.getType(); PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "uint32") == 0); Uint32 myUint32; cimValue.get(myUint32); PEGASUS_TEST_ASSERT(myUint32 == 1); idx = cimObject.findProperty(CIMName("lastOp")); PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND); cimProperty = cimObject.getProperty(idx); cimValue = cimProperty.getValue(); cimType = cimProperty.getType(); PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "string") == 0); cimValue.get(myString); PEGASUS_TEST_ASSERT(strcmp(myString.getCString(), "createInstance") == 0); }
void testInstanceClass(CIMClient & client, const CIMName & className) { cout << "Testing Instance Class " << (const char *)className.getString().getCString() << "..."; Array<CIMInstance> instances = testAnyClass(client, className); for(unsigned int i = 0, n = instances.size(); i < n; ++i) { CIMInstance currentInstance = instances[i]; CIMObjectPath currentPath = currentInstance.getPath(); if(currentPath.getNameSpace().isNull()) currentPath.setNameSpace(interopNamespace); // // Now test association traversal // Note that the "TestAssociationClass" method does a very good job // of testing association traversal between references contained in // instances of the supplied association class. Therefore, all we // really have to do here is make sure that the results of the // associators, associatorNames, references, and referenceNames // operations are consistent. // Boolean failure = false; try { Array<CIMObject> associatorsResults = client.associators( currentPath.getNameSpace(), currentPath); Array<CIMObjectPath> associatorNamesResults = client.associatorNames( currentPath.getNameSpace(), currentPath); Array<CIMObject> referencesResults = client.references( currentPath.getNameSpace(), currentPath); Array<CIMObjectPath> referenceNamesResults = client.referenceNames( currentPath.getNameSpace(), currentPath); Uint32 numResults = associatorsResults.size(); if(numResults != associatorNamesResults.size() || numResults != referencesResults.size() || numResults != referenceNamesResults.size()) { failure = true; } else { // Check that the results for the references and referenceNames // operations are consistent. unsigned int j = 0; for(j = 0; j < numResults; ++j) { CIMObjectPath currentReferenceName = referenceNamesResults[j]; Boolean found = false; for(unsigned int k = 0; k < numResults; ++k) { if(currentReferenceName == referencesResults[k].getPath()) { found = true; break; } } if(!found) { failure = true; break; } } // Check that that results for the associatorNames call is // consistent with the associators call and the references // call. for(j = 0; j < numResults; ++j) { CIMObjectPath currentAssociatorName = associatorNamesResults[j]; Boolean found = false; unsigned int k = 0; for(k = 0; k < numResults; ++k) { if(currentAssociatorName == associatorsResults[k].getPath()) { found = true; break; } } if(!found) { failure = true; break; } found = false; for(k = 0; k < numResults; ++k) { CIMObject referenceInstance = referencesResults[k]; for(unsigned int x = 0, m = referenceInstance.getPropertyCount(); x < m; ++x) { CIMProperty currentProp = referenceInstance.getProperty(x); if(currentProp.getType() == CIMTYPE_REFERENCE) { CIMObjectPath currentRef; currentProp.getValue().get(currentRef); currentRef.setHost( currentAssociatorName.getHost()); if(currentRef == currentAssociatorName) { found = true; break; } } } if(found) break; } if(!found) { failure = true; break; } } } if(failure) { exitFailure( String("Association Operations returned inconsistent ") + String("results for instance ") + currentPath.toString()); } } catch(CIMException & e) { exitFailure(String("Caught exception while performing ") + String("association operations on instance ") + currentPath.toString() + String(": ") + e.getMessage()); } } cout << "Test Complete" << endl; }
void CIMPropertyRep::toXml(Array<char>& out) const { if (_value.isArray()) { out << "<PROPERTY.ARRAY"; out << " NAME=\"" << _name << "\" "; // If the property array type is CIMObject, then // encode the property in CIM-XML as a string array with the EMBEDDEDOBJECT attribute // (there is not currently a CIM-XML "object" datatype) // else // output the real type if (_value.getType() == CIMTYPE_OBJECT) { Array<CIMObject> a; _value.get(a); out << " TYPE=\"string\""; // If the Embedded Object is an instance, always add the EMBEDDEDOBJECT attribute. if (a.size() > 0 && a[0].isInstance()) out << " EMBEDDEDOBJECT=\"object\""; // Else the Embedded Object is a class, always add the EmbeddedObject qualifier. // Note that if the macro PEGASUS_SNIA_INTEROP_COMPATIBILITY is defined, then // the EmbeddedObject qualifier will always be added, whether it's a class or // an instance. #ifndef PEGASUS_SNIA_INTEROP_COMPATIBILITY else { #endif if (_qualifiers.find(CIMName("EmbeddedObject")) == PEG_NOT_FOUND) { // Note that _qualifiers is not defined as const, and neither is add(), // but this method toXml() *is* const. However, in this case we really // do want to add the EmbeddedObject qualifier, so we cast away the // implied const-ness of _qualifiers. ((CIMQualifierList)_qualifiers).add(CIMQualifier(CIMName("EmbeddedObject"), true)); } #ifndef PEGASUS_SNIA_INTEROP_COMPATIBILITY } #endif } else { out << " TYPE=\"" << cimTypeToString (_value.getType ()) << "\""; } if (_arraySize) { char buffer[32]; sprintf(buffer, "%d", _arraySize); out << " ARRAYSIZE=\"" << buffer << "\""; } if (!_classOrigin.isNull()) out << " CLASSORIGIN=\"" << _classOrigin << "\""; if (_propagated != false) out << " PROPAGATED=\"" << _toString(_propagated) << "\""; out << ">\n"; _qualifiers.toXml(out); XmlWriter::appendValueElement(out, _value); out << "</PROPERTY.ARRAY>\n"; } else if (_value.getType() == CIMTYPE_REFERENCE) { out << "<PROPERTY.REFERENCE"; out << " NAME=\"" << _name << "\" "; if (!_referenceClassName.isNull()) { out << " REFERENCECLASS=\"" << _referenceClassName << "\""; } if (!_classOrigin.isNull()) out << " CLASSORIGIN=\"" << _classOrigin << "\""; if (_propagated != false) out << " PROPAGATED=\"" << _toString(_propagated) << "\""; out << ">\n"; _qualifiers.toXml(out); XmlWriter::appendValueElement(out, _value); out << "</PROPERTY.REFERENCE>\n"; } else { out << "<PROPERTY"; out << " NAME=\"" << _name << "\" "; if (!_classOrigin.isNull()) out << " CLASSORIGIN=\"" << _classOrigin << "\""; if (_propagated != false) out << " PROPAGATED=\"" << _toString(_propagated) << "\""; // If the property type is CIMObject, then // encode the property in CIM-XML as a string with the EMBEDDEDOBJECT attribute // (there is not currently a CIM-XML "object" datatype) // else // output the real type if (_value.getType() == CIMTYPE_OBJECT) { CIMObject a; _value.get(a); out << " TYPE=\"string\""; // If the Embedded Object is an instance, always add the EMBEDDEDOBJECT attribute. if (a.isInstance()) out << " EMBEDDEDOBJECT=\"object\""; // Else the Embedded Object is a class, always add the EmbeddedObject qualifier. // Note that if the macro PEGASUS_SNIA_INTEROP_COMPATIBILITY is defined, then // the EmbeddedObject qualifier will always be added, whether it's a class or // an instance. #ifndef PEGASUS_SNIA_INTEROP_COMPATIBILITY else { #endif if (_qualifiers.find(CIMName("EmbeddedObject")) == PEG_NOT_FOUND) { // Note that _qualifiers is not defined as const, and neither is add(), // but this method toXml() *is* const. However, in this case we really // do want to add the EmbeddedObject qualifier, so we cast away the // implied const-ness of _qualifiers. ((CIMQualifierList)_qualifiers).add(CIMQualifier(CIMName("EmbeddedObject"), true)); } #ifndef PEGASUS_SNIA_INTEROP_COMPATIBILITY } #endif } else { out << " TYPE=\"" << cimTypeToString (_value.getType ()) << "\""; } out << ">\n"; _qualifiers.toXml(out); XmlWriter::appendValueElement(out, _value); out << "</PROPERTY>\n"; } }
void test14 (CIMClient & client) { CIMObjectPath instanceName; instanceName.setNameSpace (providerNamespace); instanceName.setClassName (CLASSNAME); Array < CIMParamValue > inParams; Array < CIMInstance> eObjs; Array < CIMParamValue > outParams; CIMValue retValue = client.invokeMethod (providerNamespace, instanceName, "returnInstance", inParams, outParams); PEGASUS_TEST_ASSERT (retValue.getType () == CIMTYPE_OBJECT); PEGASUS_TEST_ASSERT (!retValue.isArray ()); PEGASUS_TEST_ASSERT (!retValue.isNull ()); CIMObject result; retValue.get (result); CIMObjectPath objPath = result.getPath(); CIMInstance inputInstance(result); CIMInstance outputInstance; eObjs.append(inputInstance); eObjs.append(inputInstance); eObjs.append(inputInstance); inParams.append ( CIMParamValue(String("inputInstances"), CIMValue(eObjs))); retValue = client.invokeMethod (providerNamespace, instanceName, "processArrayEmbeddedInstance", inParams, outParams); // First test the return value PEGASUS_TEST_ASSERT(retValue.getType() == CIMTYPE_INSTANCE); PEGASUS_TEST_ASSERT(!retValue.isArray()); PEGASUS_TEST_ASSERT(!retValue.isNull()); retValue.get(outputInstance); PEGASUS_TEST_ASSERT(objPath.toString() == outputInstance.getPath().toString()); PEGASUS_TEST_ASSERT(outputInstance.getPropertyCount() == inputInstance.getPropertyCount()); for(unsigned int i = 0, n = outputInstance.getPropertyCount(); i < n; ++i) { CIMProperty outputProp(outputInstance.getProperty(i)); CIMProperty inputProp(inputInstance.getProperty(i)); PEGASUS_TEST_ASSERT(outputProp.getName() == inputProp.getName()); PEGASUS_TEST_ASSERT(outputProp.getValue() == inputProp.getValue()); } // Now test the output parameters PEGASUS_TEST_ASSERT(outParams.size() == 3); CIMValue outParamValue = outParams[0].getValue(); PEGASUS_TEST_ASSERT(outParamValue.isArray()); PEGASUS_TEST_ASSERT(!outParamValue.isNull()); Array<CIMInstance> instances; outParamValue.get(instances); for (unsigned int j = 0; j < instances.size () ; ++j) { outputInstance = instances[j]; PEGASUS_TEST_ASSERT(objPath.toString() == outputInstance.getPath().toString()); PEGASUS_TEST_ASSERT(outputInstance.getPropertyCount() == eObjs[j].getPropertyCount()); for(unsigned int i = 0, n = outputInstance.getPropertyCount(); i < n; ++i) { CIMProperty outputProp(outputInstance.getProperty(i)); CIMProperty inputProp(eObjs[j].getProperty(i)); PEGASUS_TEST_ASSERT(outputProp.getName() == inputProp.getName()); PEGASUS_TEST_ASSERT(outputProp.getValue() == inputProp.getValue()); } } outParamValue = outParams[1].getValue(); PEGASUS_TEST_ASSERT(outParamValue.isArray()); PEGASUS_TEST_ASSERT(!outParamValue.isNull()); Array<CIMObject> objs; outParamValue.get(objs); for (unsigned int j = 0; j < objs.size () ; ++j) { outputInstance = CIMInstance(objs[j]); PEGASUS_TEST_ASSERT(objPath.toString() == outputInstance.getPath().toString()); PEGASUS_TEST_ASSERT(outputInstance.getPropertyCount() == eObjs[j].getPropertyCount()); for(unsigned int i = 0, n = outputInstance.getPropertyCount(); i < n; ++i) { CIMProperty outputProp(outputInstance.getProperty(i)); CIMProperty inputProp(eObjs[j].getProperty(i)); PEGASUS_TEST_ASSERT(outputProp.getName() == inputProp.getName()); PEGASUS_TEST_ASSERT(outputProp.getValue() == inputProp.getValue()); } } outParamValue = outParams[2].getValue(); PEGASUS_TEST_ASSERT(outParamValue.isArray()); PEGASUS_TEST_ASSERT(!outParamValue.isNull()); outParamValue.get(objs); for (Uint32 j = 0, m = objs.size(); j < m ; ++j) { outputInstance = CIMInstance(objs[j]); Uint32 id; CIMInstance emInstance; CIMObject emObject; outputInstance.getProperty( outputInstance.findProperty("id")).getValue().get(id); outputInstance.getProperty( outputInstance.findProperty("emInstance")). getValue().get(emInstance); outputInstance.getProperty( outputInstance.findProperty("emObject")).getValue().get(emObject); PEGASUS_TEST_ASSERT(eObjs[j].identical(emInstance)); PEGASUS_TEST_ASSERT(eObjs[j].identical(CIMInstance(emObject))); PEGASUS_TEST_ASSERT(id == j+1); } }
/** * This tests the embedded instance functionality through the CMPI Test * Method Provider. It first invokes the returnInstance() method to retrieve * an instance that can be used */ void test09 (CIMClient & client) { CIMObjectPath instanceName; instanceName.setNameSpace (providerNamespace); instanceName.setClassName (CLASSNAME); Array < CIMParamValue > inParams; Array < CIMParamValue > outParams; /* [EmbeddedObject] String returnInstance(); */ CIMValue retValue = client.invokeMethod (providerNamespace, instanceName, "returnInstance", inParams, outParams); PEGASUS_TEST_ASSERT (retValue.getType () == CIMTYPE_OBJECT); PEGASUS_TEST_ASSERT (!retValue.isArray ()); PEGASUS_TEST_ASSERT (!retValue.isNull ()); CIMObject result; retValue.get (result); CIMObjectPath objPath = result.getPath(); CIMInstance inputInstance(result); CIMInstance outputInstance; inParams.append( CIMParamValue(String("inputInstance"), CIMValue(inputInstance))); retValue = client.invokeMethod (providerNamespace, instanceName, "processEmbeddedInstance", inParams, outParams); // First test the return value PEGASUS_TEST_ASSERT(retValue.getType() == CIMTYPE_INSTANCE); PEGASUS_TEST_ASSERT(!retValue.isArray()); PEGASUS_TEST_ASSERT(!retValue.isNull()); retValue.get(outputInstance); PEGASUS_TEST_ASSERT(objPath.toString() == outputInstance.getPath().toString()); PEGASUS_TEST_ASSERT(outputInstance.getPropertyCount() == inputInstance.getPropertyCount()); for(unsigned int i = 0, n = outputInstance.getPropertyCount(); i < n; ++i) { CIMProperty outputProp(outputInstance.getProperty(i)); CIMProperty inputProp(inputInstance.getProperty(i)); PEGASUS_TEST_ASSERT(outputProp.getName() == inputProp.getName()); PEGASUS_TEST_ASSERT(outputProp.getValue() == inputProp.getValue()); } // Now test the output parameter PEGASUS_TEST_ASSERT(outParams.size() == 1); retValue = outParams[0].getValue(); PEGASUS_TEST_ASSERT(retValue.getType() == CIMTYPE_INSTANCE); PEGASUS_TEST_ASSERT(!retValue.isArray()); PEGASUS_TEST_ASSERT(!retValue.isNull()); retValue.get(outputInstance); PEGASUS_TEST_ASSERT(objPath.toString() == outputInstance.getPath().toString()); PEGASUS_TEST_ASSERT(outputInstance.getPropertyCount() == inputInstance.getPropertyCount()); for(unsigned int i = 0, n = outputInstance.getPropertyCount(); i < n; ++i) { CIMProperty outputProp(outputInstance.getProperty(i)); CIMProperty inputProp(inputInstance.getProperty(i)); PEGASUS_TEST_ASSERT(outputProp.getName() == inputProp.getName()); PEGASUS_TEST_ASSERT(outputProp.getValue() == inputProp.getValue()); } }