//////////////////////////////////////////////////////////////// // // cimParamFromWMIParam // /////////////////////////////////////////////////////////////// CIMParameter cimParamFromWMIParam( const String& strParamName, CIMTYPE wmiType, const CComPtr<IWbemQualifierSet>& pQualifiers, Boolean includeQualifiers) { // Need to convert the qualifiers, even if includeQualifiers is FALSE // still need to get "in" and "out", as a min CIMQualifierList qualifierList; if (pQualifiers) { WMIQualifierSet(pQualifiers).cloneTo(qualifierList); } // Check for a reference type, and get the reference class if necessary: String referenceClass = String::EMPTY; if (CIM_REFERENCE == wmiType) { // strip "ref:" Uint32 pos = qualifierList.find(CIMName("CIMTYPE")); if (PEG_NOT_FOUND != pos) { qualifierList.getQualifier(pos).getValue().get(referenceClass); //strip off "ref:" or, if not found, erase the whole string if ((pos = referenceClass.find(qString(Q_COLON))) != PEG_NOT_FOUND) { referenceClass.remove(0, pos + 1); } } } CIMName refClassName; if (0 != referenceClass.size()) { refClassName = referenceClass; } // Check for Array type, and get the array size, if necessary: Boolean isArray = false; Uint32 arraySize = 0; if (wmiType & CIM_FLAG_ARRAY) { isArray = true; // If there is a MAX qualifier on this array, use it as the size: Uint32 pos = qualifierList.find(CIMName("MAX")); if (PEG_NOT_FOUND != pos) { qualifierList.getQualifier(pos).getValue().get(arraySize); } // remove the array flag from the type to get the base type: wmiType &= ~CIM_FLAG_ARRAY; } // NOTE: Currently no mapping of WMI "object" types, so this could // throw if the param is of type "object" or other un-supported // WMI type: CIMType cimType; try { cimType = WMITypeToCIMType(wmiType); } catch (TypeMismatchException tme) { // Don't want method enumeration to fail, just because // we don't handle the type, so making this type "reference" // for now and making the reference class name "UNKNOWN_TYPE": cimType = CIMTYPE_REFERENCE; refClassName = CIMName("UNKNOWN_TYPE"); } // Build the CIMParameter: CIMParameter cimParam = CIMParameter(strParamName, cimType, isArray, arraySize, refClassName); // Now, add the parameter's qualifiers ("in" and "out" as a minimum): addQualifiersToCIMParameter(qualifierList, cimParam, includeQualifiers); // Finally, return the newly created CIMParameter: return cimParam; }
int main(int, char** argv) { verbose = getenv("PEGASUS_TEST_VERBOSE") ? true : false; try { CIMMethod m1(CIMName ("getHostName"), CIMTYPE_STRING); m1.addQualifier(CIMQualifier(CIMName ("stuff"), true)); m1.addQualifier(CIMQualifier(CIMName ("stuff2"), true)); m1.addParameter(CIMParameter(CIMName ("ipaddress"), CIMTYPE_STRING)); // Tests for Qualifiers PEGASUS_TEST_ASSERT( m1.findQualifier(CIMName ("stuff")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT( m1.findQualifier(CIMName ("stuff2")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT( m1.findQualifier(CIMName ("stuff21")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT( m1.findQualifier(CIMName ("stuf")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(m1.getQualifierCount() == 2); PEGASUS_TEST_ASSERT( m1.findQualifier(CIMName ("stuff")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT( m1.findQualifier(CIMName ("stuff2")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT( m1.findQualifier(CIMName ("stuff21")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT( m1.findQualifier(CIMName ("stuf")) == PEG_NOT_FOUND); Uint32 posQualifier; posQualifier = m1.findQualifier(CIMName ("stuff")); PEGASUS_TEST_ASSERT(posQualifier != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(posQualifier < m1.getQualifierCount()); m1.removeQualifier(posQualifier); PEGASUS_TEST_ASSERT(m1.getQualifierCount() == 1); PEGASUS_TEST_ASSERT( m1.findQualifier(CIMName ("stuff")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT( m1.findQualifier(CIMName ("stuff2")) != PEG_NOT_FOUND); // Tests for Parameters PEGASUS_TEST_ASSERT(m1.findParameter( CIMName ("ipaddress")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(m1.findParameter( CIMName ("noparam")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(m1.getParameterCount() == 1); CIMParameter cp = m1.getParameter( m1.findParameter(CIMName ("ipaddress"))); PEGASUS_TEST_ASSERT(cp.getName() == CIMName ("ipaddress")); m1.removeParameter (m1.findParameter ( CIMName (CIMName ("ipaddress")))); PEGASUS_TEST_ASSERT (m1.getParameterCount () == 0); m1.addParameter (CIMParameter (CIMName ("ipaddress"), CIMTYPE_STRING)); PEGASUS_TEST_ASSERT (m1.getParameterCount () == 1); // throws OutOfBounds try { m1.removeParameter (1); } catch (IndexOutOfBoundsException & oob) { if (verbose) { PEGASUS_STD (cout) << "Caught expected exception: " << oob.getMessage () << PEGASUS_STD (endl); } } CIMMethod m2(CIMName ("test"), CIMTYPE_STRING); m2.setName(CIMName ("getVersion")); PEGASUS_TEST_ASSERT(m2.getName() == CIMName ("getVersion")); m2.setType(CIMTYPE_STRING); PEGASUS_TEST_ASSERT(m2.getType() == CIMTYPE_STRING); m2.setClassOrigin(CIMName ("test")); PEGASUS_TEST_ASSERT(m2.getClassOrigin() == CIMName ("test")); m2.setPropagated(true); PEGASUS_TEST_ASSERT(m2.getPropagated() == true); const CIMMethod cm1(m1); PEGASUS_TEST_ASSERT(cm1.findQualifier( CIMName ("stuff21")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(cm1.findQualifier( CIMName ("stuf")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT((cm1.getParameterCount() != 3)); PEGASUS_TEST_ASSERT(cm1.findParameter( CIMName ("ipaddress")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(cm1.findQualifier( CIMName ("stuff")) == PEG_NOT_FOUND); CIMQualifier q = m1.getQualifier(posQualifier); CIMConstParameter ccp = cm1.getParameter( cm1.findParameter(CIMName ("ipaddress"))); PEGASUS_TEST_ASSERT(cm1.getName() == CIMName ("getHostName")); PEGASUS_TEST_ASSERT(cm1.getType() == CIMTYPE_STRING); PEGASUS_TEST_ASSERT(!(cm1.getClassOrigin() == CIMName ("test"))); PEGASUS_TEST_ASSERT(!cm1.getPropagated() == true); PEGASUS_TEST_ASSERT(!m1.identical(m2)); // throws OutOfBounds try { CIMConstParameter p = cm1.getParameter(cm1.findParameter( CIMName ("ipaddress"))); } catch(IndexOutOfBoundsException&) { } // throws OutOfBounds try { CIMConstQualifier q1 = cm1.getQualifier(cm1.findQualifier( CIMName ("abstract"))); } catch(IndexOutOfBoundsException&) { } if (verbose) { XmlWriter::printMethodElement(m1); XmlWriter::printMethodElement(cm1); } Buffer out; XmlWriter::appendMethodElement(out, cm1); MofWriter::appendMethodElement(out, cm1); Boolean nullMethod = cm1.isUninitialized(); PEGASUS_TEST_ASSERT(!nullMethod); CIMMethod m3 = m2.clone(); m3 = cm1.clone(); CIMMethod m4; CIMMethod m5(m4); CIMConstMethod ccm1(CIMName ("getHostName"),CIMTYPE_STRING); PEGASUS_TEST_ASSERT(!(ccm1.getParameterCount() == 3)); PEGASUS_TEST_ASSERT(ccm1.getName() == CIMName ("getHostName")); PEGASUS_TEST_ASSERT(ccm1.getType() == CIMTYPE_STRING); PEGASUS_TEST_ASSERT(!(ccm1.getClassOrigin() == CIMName ("test"))); PEGASUS_TEST_ASSERT(!ccm1.getPropagated() == true); PEGASUS_TEST_ASSERT(!(ccm1.getParameterCount() == 3)); PEGASUS_TEST_ASSERT(ccm1.getQualifierCount() == 0); PEGASUS_TEST_ASSERT(ccm1.findQualifier( CIMName ("Stuff")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(ccm1.findParameter( CIMName ("ipaddress")) == PEG_NOT_FOUND); if (verbose) { XmlWriter::printMethodElement(m1); XmlWriter::printMethodElement(ccm1); } XmlWriter::appendMethodElement(out, ccm1); CIMConstMethod ccm2(ccm1); CIMConstMethod ccm3; ccm3 = ccm1.clone(); ccm1 = ccm3; PEGASUS_TEST_ASSERT(ccm1.identical(ccm3)); PEGASUS_TEST_ASSERT(ccm1.findQualifier( CIMName ("stuff")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(ccm1.findParameter( CIMName ("ipaddress")) == PEG_NOT_FOUND); nullMethod = ccm1.isUninitialized(); PEGASUS_TEST_ASSERT(!nullMethod); // throws OutOfBounds try { //CIMParameter p = m1.getParameter( // m1.findParameter(CIMName ("ipaddress"))); CIMConstParameter p = ccm1.getParameter(0); } catch(IndexOutOfBoundsException&) { } // throws OutOfBounds try { CIMConstQualifier q1 = ccm1.getQualifier(0); } catch(IndexOutOfBoundsException&) { } } catch(Exception& e) { cerr << "Exception: " << e.getMessage() << endl; } // Test for add second qualifier with same name. // Should do exception cout << argv[0] << " +++++ passed all tests" << endl; return 0; }
void test01() { // class MyClass : YourClass // { // string message = "Hello"; // } try { CIMName a = "A_class1"; CIMName b = "A_class2"; CIMClass c0(a, b); CIMClass c1(a, CIMName("A_class2")); CIMClass c2(CIMName("A_class1"), b); CIMClass c3(b, a); } catch (InvalidNameException & ine) { if (verbose) { cout << "Caught unexpected exception: " << ine.getMessage() << endl; } } try { // // Invalid class name // CIMClass class0(CIMName ("//localhost/root/cimv2:MyClass"), CIMName ("YourClass")); PEGASUS_TEST_ASSERT(class0.getPath() == CIMObjectPath("//localhost/root/cimv2:MyClass")); } catch (InvalidNameException & ine) { if (verbose) { cout << "Caught expected exception: " << ine.getMessage() << endl; } } CIMClass class1(CIMName ("MyClass"), CIMName ("YourClass")); class1 .addQualifier(CIMQualifier(CIMName ("association"), true)) .addQualifier(CIMQualifier(CIMName ("q1"), Uint32(55))) .addQualifier(CIMQualifier(CIMName ("q2"), String("Hello"))) .addProperty(CIMProperty(CIMName ("message"), String("Hello"))) .addProperty(CIMProperty(CIMName ("count"), Uint32(77), 0, CIMName(), CIMName("YourClass"), true)) .addMethod(CIMMethod(CIMName ("isActive"), CIMTYPE_BOOLEAN) .addParameter(CIMParameter(CIMName ("hostname"), CIMTYPE_STRING)) .addParameter(CIMParameter(CIMName ("port"), CIMTYPE_UINT32))); // Test the method count function PEGASUS_TEST_ASSERT(class1.getClassName().equal(CIMName ("myclass"))); PEGASUS_TEST_ASSERT(class1.getSuperClassName() == CIMName ("YourClass")); PEGASUS_TEST_ASSERT(class1.getMethodCount() ==1); // Test the findMethod and isMethod functions PEGASUS_TEST_ASSERT(class1.findMethod( CIMName ("isActive")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findMethod( CIMName ("DoesNotExist")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findMethod( CIMName ("isActive")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findMethod( CIMName ("DoesNotExist")) == PEG_NOT_FOUND); // Test the manipulation of an embeddedObjectProperty CIMClass embedClass(CIMName ("embedObj"), CIMName ()); class1.addProperty(CIMProperty(CIMName ("embedObj"), CIMObject(embedClass), 0, CIMName(), CIMName(), false)); PEGASUS_TEST_ASSERT(class1.findProperty( CIMName ("embedObj")) != PEG_NOT_FOUND); Uint32 posProp = class1.findProperty(CIMName ("embedObj")); CIMConstProperty constprop1 = class1.getProperty(posProp); PEGASUS_TEST_ASSERT(constprop1.getClassOrigin() == CIMName()); PEGASUS_TEST_ASSERT(constprop1.getType() == CIMTYPE_OBJECT); class1.removeProperty(posProp); // Now add another method and reconfirm. class1.addMethod(CIMMethod(CIMName ("makeActive"), CIMTYPE_BOOLEAN) .addParameter(CIMParameter(CIMName ("hostname"), CIMTYPE_STRING)) .addParameter(CIMParameter(CIMName ("port"), CIMTYPE_UINT32))); PEGASUS_TEST_ASSERT(class1.getMethodCount() == 2); // Test the findMethod and isMethod functions // with two methods defined PEGASUS_TEST_ASSERT(class1.findMethod( CIMName ("isActive")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findMethod( CIMName ("makeActive")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findMethod( CIMName ("DoesNotExist")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findMethod( CIMName ("isActive")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findMethod( CIMName ("makeActive")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findMethod( CIMName ("DoesNotExist")) == PEG_NOT_FOUND); // Test RemoveMethod function Uint32 posMethod; posMethod = class1.findMethod(CIMName ("isActive")); PEGASUS_TEST_ASSERT(posMethod != PEG_NOT_FOUND); class1.removeMethod(posMethod); PEGASUS_TEST_ASSERT(class1.findMethod( CIMName ("isActive")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.getMethodCount() == 1); //ATTN: P3 TODO add tests for different case names //Qualifier manipulation tests (find, remove) PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q1")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q2")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("qx")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q1")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q2")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findQualifier( CIMName ("association")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.isAssociation()); // Remove middle Qualifier "q2" Uint32 posQualifier; posQualifier = class1.findQualifier(CIMName ("q2")); CIMConstQualifier qconst = class1.getQualifier(posQualifier); PEGASUS_TEST_ASSERT(class1.getQualifierCount() == 3); PEGASUS_TEST_ASSERT(posQualifier <= class1.getQualifierCount()); class1.removeQualifier(posQualifier); PEGASUS_TEST_ASSERT(class1.getQualifierCount() == 2); PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q2")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q1")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.isAssociation()); // Remove the first parameter "q1" posQualifier = class1.findQualifier(CIMName ("q1")); PEGASUS_TEST_ASSERT(class1.getQualifierCount() == 2); CIMQualifier cq = class1.getQualifier( class1.findQualifier( CIMName ("q1"))); PEGASUS_TEST_ASSERT(posQualifier <= class1.getQualifierCount()); class1.removeQualifier(posQualifier); PEGASUS_TEST_ASSERT(class1.getQualifierCount() == 1); PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q1")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q2")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.isAssociation()); // ATTH: P3 Add tests for try block for outofbounds //The property manipulation tests. PEGASUS_TEST_ASSERT(class1.findProperty( CIMName ("count")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findProperty( CIMName ("message")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findProperty( CIMName ("isActive")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.getPropertyCount() == 2); Uint32 posProperty; posProperty = class1.findProperty(CIMName ("count")); CIMConstProperty constprop = class1.getProperty(posProperty); PEGASUS_TEST_ASSERT(constprop.getClassOrigin() == CIMName("YourClass")); PEGASUS_TEST_ASSERT(constprop.getPropagated()); class1.removeProperty(posProperty); PEGASUS_TEST_ASSERT(class1.findProperty( CIMName ("message")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findProperty( CIMName ("count")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.getPropertyCount() == 1); CIMProperty cp = class1.getProperty( class1.findProperty (CIMName ("message"))); PEGASUS_TEST_ASSERT(cp.getClassOrigin().isNull()); PEGASUS_TEST_ASSERT(!cp.getPropagated()); if(verbose) { XmlWriter::printClassElement(class1); MofWriter::printClassElement(class1); } Buffer out; MofWriter::appendClassElement(out, class1); out.clear(); XmlWriter::appendClassElement(out, class1); PEGASUS_TEST_ASSERT(!class1.isAbstract()); CIMName squal("q1"); PEGASUS_TEST_ASSERT(class1.findQualifier(squal) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(!class1.hasKeys()); Array<CIMName> keyNames; class1.getKeyNames(keyNames); CIMClass c2(CIMName ("MyClass")); PEGASUS_TEST_ASSERT(c2.getClassName().equal(CIMName ("myclass"))); // Error uninitialized handle c2.setSuperClassName(CIMName ("CIM_Element")); PEGASUS_TEST_ASSERT(c2.getSuperClassName() == CIMName ("CIM_Element")); CIMClass c3 = c2.clone(); c3 = c2; try { CIMMethod cm = c2.getMethod(0); } catch(IndexOutOfBoundsException& e) { if(verbose) cout << "Exception: " << e.getMessage() << endl; } const CIMClass c4(CIMName ("MyClass"), CIMName ("YourClass")); CIMConstClass c5(CIMName ("MyClass"), CIMName ("YourClass")); CIMConstClass c6(CIMName ("MyClass")); CIMConstClass cc7(c6); CIMClass c7 = c5.clone(); const CIMClass c8(class1); // Test the findMethod and isMethod functions PEGASUS_TEST_ASSERT(c7.findMethod( CIMName ("DoesNotExist")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(c7.findQualifier(CIMName ("dummy")) == PEG_NOT_FOUND); try { CIMConstMethod cm = c8.getMethod(0); } catch(IndexOutOfBoundsException& e) { if(verbose) cout << "Exception: " << e.getMessage() << endl; } try { CIMConstProperty ccp = c8.getProperty(c8.findProperty (CIMName ("count"))); } catch(IndexOutOfBoundsException& e) { if(verbose) cout << "Exception: " << e.getMessage() << endl; } if(verbose) { XmlWriter::printClassElement(c5); } try { CIMConstMethod cm = cc7.getMethod(0); } catch(IndexOutOfBoundsException& e) { if(verbose) cout << "Exception: " << e.getMessage() << endl; } // Test the findMethod and isMethod functions PEGASUS_TEST_ASSERT(c4.findMethod( CIMName ("DoesNotExist")) == PEG_NOT_FOUND); //Qualifier manipulation tests (find, remove) PEGASUS_TEST_ASSERT(c4.findQualifier(CIMName ("qx")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(c4.findQualifier(CIMName ("q1")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(c4.findQualifier(CIMName ("q2")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(c4.findQualifier( CIMName ("association")) == PEG_NOT_FOUND); posProperty = c4.findProperty(CIMName ("count")); try { CIMConstQualifier ccq = c4.getQualifier(c4.findQualifier (CIMName ("q1"))); } catch (IndexOutOfBoundsException& e) { if(verbose) cout << "Exception: " << e.getMessage() << endl; } PEGASUS_TEST_ASSERT(c4.findProperty(CIMName ("count")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(c4.getClassName() == CIMName ("MyClass")); PEGASUS_TEST_ASSERT(c4.getClassName().equal(CIMName ("MyClass"))); PEGASUS_TEST_ASSERT(c4.getClassName().equal(CIMName ("MYCLASS"))); PEGASUS_TEST_ASSERT(c4.getClassName().equal(CIMName ("myclass"))); PEGASUS_TEST_ASSERT(!c4.getClassName().equal(CIMName ("blob"))); PEGASUS_TEST_ASSERT(c4.getSuperClassName() == CIMName ("YourClass")); // test the setSuperClassName function /* ATTN KS 29 April. This test has problems. Relook later. Think test, not code. c4.setSuperClassName(CIMName ("JunkClass")); PEGASUS_TEST_ASSERT(c4.getSuperClassName() == CIMName ("JunkClass")); c4.setSuperClassName(CIMName ("YourClass")); */ PEGASUS_TEST_ASSERT(c5.getSuperClassName() == CIMName ("YourClass")); PEGASUS_TEST_ASSERT(c5.getQualifierCount() == 0); posQualifier = c5.findQualifier(CIMName ("q2")); // throws out of bounds try { CIMConstQualifier qconst1 = c5.getQualifier(posQualifier); } catch(IndexOutOfBoundsException& e) { if(verbose) cout << "Exception: " << e.getMessage() << endl; } if(verbose) { cout << "All tests" << endl; } }
CIMParameter CIMConstParameter::clone() const { return CIMParameter(_rep->clone()); }