void test02() { const CIMNamespaceName NAMESPACE = CIMNamespaceName("/zzz"); CIMClass cimClass(CIMName("MyClass")); cimClass .addProperty(CIMProperty(CIMName("Last"), String()) .addQualifier(CIMQualifier(CIMName("key"), true))) .addProperty(CIMProperty(CIMName("First"), String()) .addQualifier(CIMQualifier(CIMName("key"), true))) .addProperty(CIMProperty(CIMName("Age"), String()) .addQualifier(CIMQualifier(CIMName("key"), true))); CIMInstance cimInstance(CIMName("MyClass")); cimInstance.addProperty(CIMProperty(CIMName("first"), String("John"))); cimInstance.addProperty(CIMProperty(CIMName("last"), String("Smith"))); cimInstance.addProperty(CIMProperty(CIMName("age"), Uint8(101))); assert(cimInstance.findProperty(CIMName("first")) != PEG_NOT_FOUND); assert(cimInstance.findProperty(CIMName("last")) != PEG_NOT_FOUND); assert(cimInstance.findProperty(CIMName("age")) != PEG_NOT_FOUND); assert(cimInstance.getPropertyCount() == 3); CIMObjectPath instanceName = cimInstance.buildPath(CIMConstClass(cimClass)); CIMObjectPath tmp("myclass.age=101,first=\"John\",last=\"Smith\""); assert(tmp.makeHashCode() == instanceName.makeHashCode()); // Test CIMInstance::buildPath with incomplete keys in the instance Boolean caughtNoSuchPropertyException = false; try { CIMInstance badInstance(CIMName("MyClass")); badInstance.addProperty(CIMProperty(CIMName("first"), String("John"))); badInstance.addProperty(CIMProperty(CIMName("last"), String("Smith"))); CIMObjectPath instanceName = badInstance.buildPath(CIMConstClass(cimClass)); } catch (const NoSuchProperty&) { caughtNoSuchPropertyException = true; } assert(caughtNoSuchPropertyException); }
CIMClass buildClass() { CIMClass CIMclass1(CIMName("MyClass")); CIMclass1 .addProperty(CIMProperty(CIMName("id"), Uint32(1)) .addQualifier(CIMQualifier(CIMName("key"), true))) .addProperty(CIMProperty(CIMName("count"), Uint32(55)) .addQualifier(CIMQualifier(CIMName("counter"), true)) .addQualifier(CIMQualifier(CIMName("min"), String("0"))) .addQualifier(CIMQualifier(CIMName("max"), String("1")))) .addProperty(CIMProperty(CIMName("message"), String("Hello")) .addQualifier(CIMQualifier(CIMName("description"), String("My Message")))) .addProperty(CIMProperty(CIMName("ratio"), Real32(1.5))); return CIMclass1; }
CIMQualifier CIMMethod::getQualifier(const CIMName& name) const { int tsize = m_pdata->m_qualifiers.size(); for (int i = 0; i < tsize; i++) { CIMQualifier nq = m_pdata->m_qualifiers[i]; if (nq.getName() == name) { return nq; } } return CIMQualifier(CIMNULL); }
void TestCreateClass() { if (verbose) cout << ProgName << "-TestCreateClass()" << endl; CIMClass c1(CIMName ("SuperClass")); c1.addQualifier(d); c1.addProperty( CIMProperty(CIMName ("key"), Uint32(0)) .addQualifier(CIMQualifier(CIMName("key"), true, CIMFlavor::DEFAULTS))); c1.addProperty(CIMProperty(CIMName ("ratio"), Real32(1.5))); c1.addProperty(CIMProperty(CIMName ("message"), String("Hello World"))); // -- Create the class (get it back and compare): r->createClass(NS, c1); CIMConstClass cc1; cc1 = r->getClass(NS, CIMName("SuperClass"), true, true, false); PEGASUS_TEST_ASSERT(c1.identical(cc1)); PEGASUS_TEST_ASSERT(cc1.identical(c1)); // -- Now create a sub class (get it back and compare): // c22 has one additional property than c1 (junk) CIMClass c2(CIMName ("SubClass"), CIMName ("SuperClass")); // Add new qualifier that will be local CIMQualifier j( CIMName("junk"), String("TestQualifier"), CIMFlavor::DEFAULTS); c2.addQualifier(j); c2.addProperty(CIMProperty(CIMName ("junk"), Real32(66.66))); r->createClass(NS, c2); CIMConstClass cc2; cc2 = r->getClass(NS, CIMName("SubClass"), true, true, false); //XmlWriter::printClassElement(c2); //XmlWriter::printClassElement(cc2); PEGASUS_TEST_ASSERT(c2.identical(cc2)); PEGASUS_TEST_ASSERT(cc2.identical(c2)); // -- Modify "SubClass" (add new property) c2.addProperty(CIMProperty(CIMName ("newProperty"), Uint32(888))); r->modifyClass(NS, c2); cc2 = r->getClass(NS, CIMName ("SubClass"), true, true, false); PEGASUS_TEST_ASSERT(c2.identical(cc2)); PEGASUS_TEST_ASSERT(cc2.identical(c2)); // should test for this new property on "SubClass" also. }
// // Initialize the namespaces so that all namespaces with the // CIM_ElementConformsToProfile class also have the // PG_ElementConformsToProfile class. Needed in order to implement // the cross-namespace ElementConformsToProfile association in both // directions. // void InteropProvider::initializeNamespaces() { Array<CIMNamespaceName> namespaceNames = repository->enumerateNameSpaces(); // get the PG_ElementConformstoProfile class without the qualifiers // and then add just the required ASSOCIATION qualifier, so that // resolveclass doesn't fail for the test/EmbeddedInstance/Dynamic // namespace, which uses the CIM25 schema that doesn't include any // of the new qualifiers added to this class in later versions of // the CIMSchema. CIMClass conformsClass = repository->getClass( PEGASUS_NAMESPACENAME_INTEROP, PEGASUS_CLASSNAME_PG_ELEMENTCONFORMSTOPROFILE, true, false); conformsClass.addQualifier( CIMQualifier(CIMName("ASSOCIATION"), CIMValue(true))); CIMClass profileClass = repository->getClass( PEGASUS_NAMESPACENAME_INTEROP, PEGASUS_CLASSNAME_PG_REGISTEREDPROFILE, true, false); for(Uint32 i = 0, n = namespaceNames.size(); i < n; ++i) { // Check if the PG_ElementConformsToProfile class is present CIMNamespaceName & currentNamespace = namespaceNames[i]; CIMClass tmpCimClass; CIMClass tmpPgClass; CIMClass tmpPgProfileClass; try { // Look for these classes in the same try-block since the // second depends on the first tmpCimClass = repository->getClass( currentNamespace, PEGASUS_CLASSNAME_CIM_ELEMENTCONFORMSTOPROFILE); tmpPgClass = repository->getClass( currentNamespace, PEGASUS_CLASSNAME_PG_ELEMENTCONFORMSTOPROFILE); } catch(const Exception &) { } try { tmpPgProfileClass = repository->getClass( currentNamespace, PEGASUS_CLASSNAME_PG_REGISTEREDPROFILE); } catch(const Exception &) { // Note: if any of the above three classes aren't found, // an exception will be thrown, which we can ignore since it's // an expected case // TBD: Log trace message? } // If the CIM_ElementConformsToProfile class is present, but // the PG_ElementConformsToProfile or PG_RegisteredProfile // class is not, then add it to that namespace. // // Note that we don't have to check for the // CIM_RegisteredProfile class because if the // CIM_ElementConformsToProfile class is present, the // CIM_RegisteredProfile class must also be present. if(!tmpCimClass.isUninitialized()) { if(tmpPgClass.isUninitialized()) { CIMClass newclass = conformsClass.clone(); CIMObjectPath newPath = conformsClass.getPath(); newPath.setNameSpace(currentNamespace); newclass.setPath(newPath); repository->createClass( currentNamespace, newclass); } if(tmpPgProfileClass.isUninitialized()) { CIMClass newclass = profileClass.clone(); CIMObjectPath newPath = profileClass.getPath(); newPath.setNameSpace(currentNamespace); newclass.setPath(newPath); repository->createClass( currentNamespace, newclass); } } } }
static void CreateRepository(CIMRepository & repository) { repository.createNameSpace(NS); Array<String> qualifierValue; qualifierValue.append(""); CIMQualifierDecl q1(CIMName ("MappingStrings"), qualifierValue, CIMScope::PROPERTY + CIMScope::CLASS); // Qualifier name must be "MappingStrings", test the qualifier // name is not "MappingStrings" CIMQualifierDecl q2(CIMName ("NotMappingStrings"), qualifierValue, CIMScope::CLASS); repository.setQualifier(NS, q1); repository.setQualifier(NS, q2); Array<String> classMappingStr; classMappingStr.append("OID.IETF | SNMP.1.3.6.1.4.1.892.2.3.9000.8600"); CIMClass class1(testClass1); class1.addQualifier(CIMQualifier(CIMName ("MappingStrings"), CIMValue(classMappingStr))); Array<String> invalidFormatStr; invalidFormatStr.append( "Wrong format OID.IETF | SNMP.1.3.6.1.4.1.2.3.9000.8600"); invalidFormatStr.append("DataType.IETF | OctetString "); // create wrong format property mappingStrings value class1.addProperty( CIMProperty(CIMName("OidDataType"), String("OctetString")) .addQualifier(CIMQualifier(CIMName ("MappingStrings"), CIMValue(invalidFormatStr)))); repository.createClass(NS, class1); // create invalid mapping string value Array<String> class2MappingStr; Array<String> mappingStr2; class2MappingStr.append("OID.IETF |Invalid Mapping String Value"); mappingStr2.append("OID.IETF | SNMP.1.3.6.1.4.1.2.3.9000.8600"); mappingStr2.append("DataType.IETF OctetString "); CIMClass class2(testClass2); class2.addQualifier(CIMQualifier(CIMName ("MappingStrings"), CIMValue(class2MappingStr))); class2.addProperty(CIMProperty(CIMName ("OidDataType"), String()) .addQualifier(CIMQualifier(CIMName ("MappingStrings"), CIMValue(mappingStr2)))); repository.createClass(NS, class2); // create non MappingStrings qualifier CIMClass class3(testClass3); class3.addQualifier(CIMQualifier(CIMName ("NotMappingStrings"), CIMValue(classMappingStr))); repository.createClass(NS, class3); // error building ASN.1 representation Array<String> class4MappingStr; class4MappingStr.append("OID.IETF | SNMP.1.204.6.1.6.3.1.330.5.1.0 "); CIMClass class4(testClass4); class4.addQualifier(CIMQualifier(CIMName ("MappingStrings"), CIMValue(class4MappingStr))); repository.createClass(NS, class4); // create incorrect class mappingStrings value Array<String> class5MappingStr; class5MappingStr.append("OID.IETF | SNMP.1.3.6.1.6.test.1.1.5.1.3 "); CIMClass class5(testClass5); class5.addQualifier(CIMQualifier(CIMName ("MappingStrings"), CIMValue(class5MappingStr))); // create incorrect property name class5.addProperty( CIMProperty(CIMName ("WrongPropertyName"), String("OctetString")) .addQualifier(CIMQualifier(CIMName ("MappingStrings"), CIMValue(class5MappingStr)))); repository.createClass(NS, class5); // create incorrect property mappingStrings value Array<String> class6MappingStr; class6MappingStr.append("OID.IETF | SNMP.1.3.6.1.6.3.1.1.0.1 "); Array<String> mappingStr6; mappingStr6.append("OID.IETF | SNMP.1.3.6.1.6.test.1.1.5.1.3"); mappingStr6.append("DataType.IETF | OctetString"); CIMClass class6(testClass6); class6.addQualifier(CIMQualifier(CIMName ("MappingStrings"), CIMValue(class6MappingStr))); class6.addProperty( CIMProperty(CIMName ("OidDataType"), String("OctetString")) .addQualifier(CIMQualifier(CIMName ("MappingStrings"), CIMValue(mappingStr6)))); repository.createClass(NS, class6); // create unsupportted SNMP Data Type for the CIM property Array<String> class7MappingStr; class7MappingStr.append("OID.IETF | SNMP.1.3.6.1.6.3.1.1.5.1 "); Array<String> mappingStr7; mappingStr7.append("OID.IETF | SNMP.1.3.6.1.6.test.1.1.5.1.3"); mappingStr7.append("DataType.IETF | test "); CIMClass class7(testClass7); class7.addQualifier(CIMQualifier(CIMName ("MappingStrings"), CIMValue(class7MappingStr))); class7.addProperty( CIMProperty(CIMName ("OidDataType"), String("test")) .addQualifier(CIMQualifier(CIMName ("MappingStrings"), CIMValue(mappingStr7)))); repository.createClass(NS, class7); // create invalid syntax for MappingStrings qualifier Array<String> invalidSyntax; Array<String> class8MappingStr; class8MappingStr.append("OID.IETF Invalid Syntax for MappingStrings"); Array<String> mappingStr8; mappingStr8.append("OID.IETF | SNMP.1.3.6.1.4.1.2.3.9000.8600"); mappingStr8.append("DataType.IETF | OctetString "); CIMClass class8(testClass8); class8.addQualifier(CIMQualifier(CIMName ("MappingStrings"), CIMValue(class8MappingStr))); class8.addProperty(CIMProperty(CIMName ("OidDataType"), String()) .addQualifier(CIMQualifier(CIMName ("MappingStrings"), CIMValue(mappingStr8)))); repository.createClass(NS, class8); }
void test01() { CIMProperty pnull; PEGASUS_TEST_ASSERT(pnull.isUninitialized()); CIMProperty p1(CIMName ("message"), String("Hi There")); p1.addQualifier(CIMQualifier(CIMName ("Key"), true)); p1.addQualifier(CIMQualifier(CIMName ("stuff"), true)); p1.addQualifier(CIMQualifier(CIMName ("stuff2"), true)); p1.addQualifier(CIMQualifier(CIMName ("Description"), String("Blah Blah"))); CIMConstProperty p2 = p1; // Test clone CIMProperty p1clone = p1.clone(); CIMProperty p2clone = p2.clone(); // Test print if(verbose) { XmlWriter::printPropertyElement(p1, cout); XmlWriter::printPropertyElement(p2, cout); XmlWriter::printPropertyElement(p1clone, cout); XmlWriter::printPropertyElement(p2clone, cout); } // Test toMof Buffer mofOut; MofWriter::appendPropertyElement(true, mofOut, p1); MofWriter::appendPropertyElement(true, mofOut, p2); // Test toXml Buffer xmlOut; XmlWriter::appendPropertyElement(xmlOut, p1); XmlWriter::appendPropertyElement(xmlOut, p2); // Test name CIMName name; name = p1.getName(); PEGASUS_TEST_ASSERT(name == CIMName ("message")); name = p2.getName(); PEGASUS_TEST_ASSERT(name == CIMName ("message")); // Test type PEGASUS_TEST_ASSERT(p1.getType() == CIMTYPE_STRING); PEGASUS_TEST_ASSERT(p2.getType() == CIMTYPE_STRING); // Test for key qualifier Uint32 pos; Boolean isKey = false; if ((pos = p1.findQualifier (CIMName ("key"))) != PEG_NOT_FOUND) { CIMValue value; value = p1.getQualifier (pos).getValue (); if (!value.isNull ()) { value.get (isKey); } } PEGASUS_TEST_ASSERT (isKey); isKey = false; if ((pos = p2.findQualifier (CIMName ("key"))) != PEG_NOT_FOUND) { CIMValue value; value = p2.getQualifier (pos).getValue (); if (!value.isNull ()) { value.get (isKey); } } PEGASUS_TEST_ASSERT (isKey); // Test for key property using CIMPropertyInternal PEGASUS_TEST_ASSERT (CIMPropertyInternal::isKeyProperty(p1)); PEGASUS_TEST_ASSERT (CIMPropertyInternal::isKeyProperty(p2)); // Test getArraySize PEGASUS_TEST_ASSERT(p1.getArraySize() == 0); PEGASUS_TEST_ASSERT(p2.getArraySize() == 0); // Test getPropagated PEGASUS_TEST_ASSERT(p1.getPropagated() == false); PEGASUS_TEST_ASSERT(p2.getPropagated() == false); // Tests for Qualifiers PEGASUS_TEST_ASSERT(p1.findQualifier(CIMName ("stuff")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(p1.findQualifier(CIMName ("stuff2")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(p1.findQualifier(CIMName ("stuff21")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(p1.findQualifier(CIMName ("stuf")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(p1.getQualifierCount() == 4); PEGASUS_TEST_ASSERT(p2.findQualifier(CIMName ("stuff")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(p2.findQualifier(CIMName ("stuff2")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(p2.findQualifier(CIMName ("stuff21")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(p2.findQualifier(CIMName ("stuf")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(p2.getQualifierCount() == 4); PEGASUS_TEST_ASSERT(p1.findQualifier(CIMName ("stuff")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(p1.findQualifier(CIMName ("stuff2")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(p1.findQualifier(CIMName ("stuff21")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(p1.findQualifier(CIMName ("stuf")) == PEG_NOT_FOUND); Uint32 posQualifier; posQualifier = p1.findQualifier(CIMName ("stuff")); PEGASUS_TEST_ASSERT(posQualifier != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(posQualifier < p1.getQualifierCount()); p1.removeQualifier(posQualifier); PEGASUS_TEST_ASSERT(p1.getQualifierCount() == 3); PEGASUS_TEST_ASSERT(p1.findQualifier(CIMName ("stuff")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(p1.findQualifier(CIMName ("stuff2")) != PEG_NOT_FOUND); // Tests for value insertion. { CIMProperty px(CIMName ("p1"), String("Hi There")); // test for CIMValue and type CIMProperty py(CIMName ("p2"), Uint32(999)); // test for CIMValue and type //Test getName and setName PEGASUS_TEST_ASSERT(px.getName() == CIMName ("p1")); px.setName(CIMName ("px")); PEGASUS_TEST_ASSERT(px.getName() == CIMName ("px")); PEGASUS_TEST_ASSERT(py.getName() == CIMName ("p2")); py.setName(CIMName ("py")); PEGASUS_TEST_ASSERT(py.getName() == CIMName ("py")); // ATTN: Test setValue and getValue } }
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; } }
int main(int argc, char** argv) { #ifdef IO verbose = getenv("PEGASUS_TEST_VERBOSE") ? true : false; if (verbose) cout << "Test CIMValue. To turn off display, compile with IO undefined\n"; #endif // Test the primitive CIMValue types with test01 test01(Boolean(true)); test01(Boolean(false)); test01(Char16('Z')); test01(Uint8(77)); test01(Sint8(-77)); test01(Sint16(77)); test01(Uint16(-77)); test01(Sint32(77)); test01(Uint32(-77)); test01(Sint64(77)); test01(Uint64(-77)); test01(Real32(1.5)); test01(Real64(55.5)); test01(Uint64(123456789)); test01(Sint64(-123456789)); test01(String("Hello world")); test01(CIMDateTime("19991224120000.000000+360")); test01(CIMObjectPath( "//host1:77/root/test:Class1.key1=\"key1Value\",key2=\"key2Value\"")); // Create and populate a declaration context: const CIMNamespaceName NAMESPACE = CIMNamespaceName ("/zzz"); SimpleDeclContext* context = new SimpleDeclContext; context->addQualifierDecl( NAMESPACE, CIMQualifierDecl(CIMName ("counter"), false, CIMScope::PROPERTY)); context->addQualifierDecl( NAMESPACE, CIMQualifierDecl(CIMName ("classcounter"), false, CIMScope::CLASS)); context->addQualifierDecl( NAMESPACE, CIMQualifierDecl(CIMName ("min"), String(), CIMScope::PROPERTY)); context->addQualifierDecl( NAMESPACE, CIMQualifierDecl(CIMName ("max"), String(), CIMScope::PROPERTY)); context->addQualifierDecl(NAMESPACE, CIMQualifierDecl(CIMName ("Description"), String(), CIMScope::PROPERTY)); CIMClass class1(CIMName ("MyClass")); class1 .addProperty(CIMProperty(CIMName ("count"), Uint32(55)) .addQualifier(CIMQualifier(CIMName ("counter"), true)) .addQualifier(CIMQualifier(CIMName ("min"), String("0"))) .addQualifier(CIMQualifier(CIMName ("max"), String("1")))) .addProperty(CIMProperty(CIMName ("message"), String("Hello")) .addQualifier(CIMQualifier(CIMName ("description"), String("My Message")))) .addProperty(CIMProperty(CIMName ("ratio"), Real32(1.5))); Resolver::resolveClass (class1, context, NAMESPACE); context->addClass(NAMESPACE, class1); // Test a CIMObject that is a CIMClass test01(CIMObject(class1)); // Test a CIMObject that is a CIMInstance CIMInstance instance1(CIMName ("MyClass")); instance1.addQualifier(CIMQualifier(CIMName ("classcounter"), true)); instance1.addProperty(CIMProperty(CIMName ("message"), String("Goodbye"))); Resolver::resolveInstance (instance1, context, NAMESPACE, true); test01(CIMObject(instance1)); testEmbeddedValue<CIMObject>(instance1); testEmbeddedValue<CIMInstance>(instance1); // Test CIMValue arrays Array<Uint8> arr1; arr1.append(11); arr1.append(22); arr1.append(23); test02(arr1); Array<Uint16> arr2; arr2.append(333); arr2.append(444); arr2.append(445); test02(arr2); Array<Uint32> arr3; arr3.append(5555); arr3.append(6666); arr3.append(6667); test02(arr3); Array<Uint64> arr4; arr4.append(123456789); arr4.append(987654321); arr4.append(987654322); test02(arr4); Array<Sint8> arr5; arr5.append(-11); arr5.append(-22); arr5.append(-23); test02(arr5); Array<Sint16> arr6; arr6.append(333); arr6.append(444); arr6.append(555); test02(arr6); Array<Sint32> arr7; arr7.append(555); arr7.append(666); arr7.append(777); test02(arr7); Array<Sint64> arr8; arr8.append(-123456789); arr8.append(-987654321); arr8.append(-987654321); test02(arr8); Array<Boolean> arr9; arr9.append(true); arr9.append(false); arr9.append(false); test02(arr9); Array<Real32> arr10; arr10.append(1.55F); arr10.append(2.66F); arr10.append(3.77F); test02(arr10); Array<Real64> arr11; arr11.append(55.55); arr11.append(66.66); arr11.append(77.77); test02(arr11); Array<Char16> arr12; arr12.append('X'); arr12.append('Y'); arr12.append('Z'); test02(arr12); Array<String> arr13; arr13.append("One"); arr13.append("Two"); arr13.append("Three"); test02(arr13); Array<CIMDateTime> arr14; arr14.append(CIMDateTime ("20020130120000.000000+360")); arr14.append(CIMDateTime ("20020201120000.000000+360")); arr14.append(CIMDateTime ("20020202120000.000000+360")); test02(arr14); Array<CIMObjectPath> arr15; arr15.append(CIMObjectPath( "//host1:77/root/test:Class1.key1=\"key1Value\",key2=\"key2Value\"")); arr15.append(CIMObjectPath( "//host2:88/root/static:Class2.keyA=\"keyAValue\",keyB=" "\"keyBValue\"")); arr15.append(CIMObjectPath( "//host3:99/root/test/static:Class3.keyX=\"keyXValue\"," "keyY=\"keyYValue\"")); test02(arr15); testEmbeddedValueArray<CIMObject>(instance1, NAMESPACE, context); testEmbeddedValueArray<CIMInstance>(instance1, NAMESPACE, context); // Calling remaining Array tests.. CIMDateTime D1("19991224120000.000000+100"); Array<CIMDateTime> arrD1(10,D1); CIMDateTime *D2 = new CIMDateTime("19991224120000.000000+100"); Array<CIMDateTime> arrD2(D2,1); test03(arrD1, arrD2, D2, CIMDateTime("19991224120000.000000+100"), CIMDateTime("29991224120000.000000+100")); delete D2; CIMName cimname1("yourName"); Array<CIMName> arrcimname1(10,cimname1); CIMName *cimname2 = new CIMName("yourName"); Array<CIMName> arrcimname2(cimname2,1); test03(arrcimname1, arrcimname2, cimname2, CIMName("yourName"), CIMName("myName")); delete cimname2; CIMKeyBinding cimbind1(cimname1, "myKey", CIMKeyBinding::STRING); CIMKeyBinding cimbind2(cimname1, "yourKey", CIMKeyBinding::STRING); Array<CIMKeyBinding> arrcimbind1(10,cimbind1); CIMKeyBinding *cimbind3 = new CIMKeyBinding(cimname1, "myKey", CIMKeyBinding::STRING); Array<CIMKeyBinding> arrcimbind2(cimbind3,1); test03(arrcimbind1, arrcimbind2, cimbind3, cimbind1, cimbind2 ); delete cimbind3; CIMNamespaceName cimnamespace1("root/SampleProvider"); Array<CIMNamespaceName> arrcimnamespace1(10,cimnamespace1); CIMNamespaceName *cimnamespace2 = new CIMNamespaceName( "root/SampleProvider"); Array<CIMNamespaceName> arrcimnamespace2(cimnamespace2,1); test03(arrcimnamespace1, arrcimnamespace2, cimnamespace2, CIMNamespaceName("root/SampleProvider"), CIMNamespaceName("root/SampleProvider2")); delete cimnamespace2; Array<Boolean> arrB1(10,true); Boolean *b = new Boolean(true); Array<Boolean> arrB2(b,1); Array<Boolean> arrB3(2); Boolean b1 = true, b2=false; test03(arrB1, arrB2, b, Boolean(true),Boolean(false)); delete b; Array<Real32> arrreal321(10); Real32 creal321(2.5); Array<Real32> arrreal322(10, creal321); Real32 *creal322 = new Real32(2.5); Array<Real32> arrreal323(creal322,1); Array<Real32> arrreal324(arrreal321); test03(arrreal322, arrreal323, creal322,Real32(2.5),Real32(3.5)); delete creal322; Array<Real64> arrreal641(10); Real64 creal641(20000.54321); Array<Real64> arrreal642(10, creal641); Real64 *creal642 = new Real64(20000.54321); Array<Real64> arrreal643(creal642,1); Array<Real64> arrreal644(arrreal641); test03(arrreal642, arrreal643, creal642,Real64(20000.54321), Real64(30000.54321)); delete creal642; Array<Sint16> arrSint161(10); Sint16 cSint161(-2000); Array<Sint16> arrSint162(10, cSint161); Sint16 *cSint162 = new Sint16(-2000); Array<Sint16> arrSint163(cSint162,1); Array<Sint16> arrSint164(arrSint161); test03(arrSint162, arrSint163, cSint162, Sint16(-2000), Sint16(-3000)); delete cSint162; Array<Sint32> arrSint321(10); Sint32 cSint321(-200000000); Array<Sint32> arrSint322(10, cSint321); Sint32 *cSint322 = new Sint32(-200000000); Array<Sint32> arrSint323(cSint322,1); Array<Sint32> arrSint324(arrSint321); test03(arrSint322, arrSint323, cSint322, Sint32(-200000000), Sint32(-300000000)); delete cSint322; Array<Sint64> arrSint641(10); Sint64 cSint641(Sint64(-2000000)*Sint64(10000000) ); Array<Sint64> arrSint642(10, cSint641); Sint64 *cSint642 = new Sint64(Sint64(-2000000)*Sint64(10000000)); Array<Sint64> arrSint643(cSint642,1); Array<Sint64> arrSint644(arrSint641); test03(arrSint642, arrSint643, cSint642,Sint64(-2000000)*Sint64(10000000), Sint64(-3000000)*Sint64(10000000)); delete cSint642; Array<Sint8> arrSint81(10); Sint8 cSint81(-20); Array<Sint8> arrSint82(10, cSint81); Sint8 *cSint82 = new Sint8(-20); Array<Sint8> arrSint83(cSint82,1); Array<Sint8> arrSint84(arrSint81); test03(arrSint82, arrSint83, cSint82, Sint8(-20), Sint8(-22)); delete cSint82; Array<Uint16> arrUint161(10); Uint16 cUint161(200); Array<Uint16> arrUint162(10, cUint161); Uint16 *cUint162 = new Uint16(200); Array<Uint16> arrUint163(cUint162,1); Array<Uint16> arrUint164(arrUint161); test03(arrUint162, arrUint163, cUint162, Uint16(200), Uint16(255)); delete cUint162; Array<Uint32> arrUint321(10); Uint32 cUint321(2000); Array<Uint32> arrUint322(10, cUint321); Uint32 *cUint322 = new Uint32(2000); Array<Uint32> arrUint323(cUint322,1); Array<Uint32> arrUint324(arrUint321); test03(arrUint322, arrUint323, cUint322, Uint32(2000), Uint32(3000)); delete cUint322; Array<Uint64> arrUint641(10); Uint64 cUint641(Uint64(2000000)*Uint64(10000000)); Array<Uint64> arrUint642(10, cUint641); Uint64 *cUint642 = new Uint64(Uint64(2000000)*Uint64(10000000)); Array<Uint64> arrUint643(cUint642,1); Array<Uint64> arrUint644(arrUint641); test03(arrUint642, arrUint643, cUint642,Uint64(2000000)*Uint64(10000000), Uint64(255000)*Uint64(10000000)); delete cUint642; Array<Uint8> arrUint81(10); Uint8 cUint81(200); Array<Uint8> arrUint82(10, cUint81); Uint8 *cUint82 = new Uint8(200); Array<Uint8> arrUint83(cUint82,1); Array<Uint8> arrUint84(arrUint81); test03(arrUint82, arrUint83, cUint82, Uint8(200), Uint8(255)); delete cUint82; Array<Char16> arrChar161(10); Char16 cChar161('Z'); Array<Char16> arrChar162(10, cChar161); Char16 *cChar162 = new Char16('Z'); Array<Char16> arrChar163(cChar162,1); Array<Char16> arrChar164(arrChar161); test03(arrChar162, arrChar163, cChar162, Char16('Z'), Char16('z')); delete cChar162; delete context; cout << argv[0] << " +++++ passed all tests" << endl; return 0; }
// Build the instance of an association class and test the build path functions. void test03() { const CIMNamespaceName NAMESPACE = CIMNamespaceName("/zzz"); CIMClass myPersonClass(CIMName("MY_PersonClass")); myPersonClass .addProperty(CIMProperty(CIMName("name"), String()) .addQualifier(CIMQualifier(CIMName("Key"), true))); CIMClass myAssocClass(CIMName("MY_AssocClass")); myAssocClass .addQualifier(CIMQualifier(CIMName("association"), true)) .addProperty(CIMProperty(CIMName("parent"), CIMObjectPath(), 0, CIMName("MY_PersonClass")) .addQualifier(CIMQualifier(CIMName("key"), true))) .addProperty(CIMProperty(CIMName("child"), CIMObjectPath(), 0, CIMName("MY_PersonClass")) .addQualifier(CIMQualifier(CIMName("key"), true))) .addProperty(CIMProperty(CIMName("Age"), String())); CIMInstance fatherInstance(CIMName("MY_PersonClass")); fatherInstance .addProperty(CIMProperty(CIMName("name"), String("father"))); CIMInstance daughterInstance(CIMName("My_PersonClass")); daughterInstance .addProperty(CIMProperty(CIMName("name"), String("daughter"))); CIMObjectPath fatherInstancePath = fatherInstance.buildPath(CIMConstClass(myPersonClass)); CIMObjectPath daughterInstancePath = daughterInstance.buildPath(CIMConstClass(myPersonClass)); CIMInstance assocInstance(CIMName("MY_AssocClass")); assocInstance.addProperty(CIMProperty(CIMName("parent"), CIMObjectPath(fatherInstancePath),0,CIMName("MY_PersonClass"))); assocInstance.addProperty(CIMProperty(CIMName("child"), CIMObjectPath(daughterInstancePath),0, CIMName("MY_PersonClass"))); CIMObjectPath assocInstancePath = assocInstance.buildPath(CIMConstClass(myAssocClass)); // Now do the asserts, etc. // See if the pathing works on Associations and association instances if (verbose) { XmlWriter::printClassElement(myPersonClass); XmlWriter::printClassElement(myAssocClass); XmlWriter::printInstanceElement(fatherInstance); XmlWriter::printInstanceElement(daughterInstance); XmlWriter::printInstanceElement(assocInstance); } if (verbose) { cout << "Paths " << endl; cout << "FatherInstancePath = " << fatherInstancePath.toString() << endl; cout << "DaughterInstancePath = " << daughterInstancePath.toString() << endl; cout << "AssocInstancePath = " << assocInstancePath.toString() << endl; } String x ="MY_AssocClass.child=\"My_PersonClass.name=\\\"daughter\\\"\"," "parent=\"MY_PersonClass.name=\\\"father\\\"\""; assert(x == assocInstancePath.toString()); CIMObjectPath px = x; assert(px.identical(assocInstancePath)); }
LocalRepository::LocalRepository(void) : context(0) { // the SimpleDeclContext object does not handle inheritance so it is necessary to create super-class // qualifiers and properties in subclasses. context = new SimpleDeclContext; // create essential qualifiers CIMQualifierDecl abstractQualifier("Abstract", Boolean(true), CIMScope::CLASS, CIMFlavor::NONE); CIMQualifierDecl keyQualifier("Key", Boolean(true), (CIMScope::PROPERTY + CIMScope::REFERENCE), CIMFlavor::TOSUBCLASS); context->addQualifierDecl("test_namespace", abstractQualifier); context->addQualifierDecl("test_namespace", keyQualifier); // create base class { CIMClass classA("ClassA"); classA.addQualifier(CIMQualifier("Abstract", Boolean(true))); CIMProperty property1("Property1", CIMValue(CIMTYPE_UINT32, 0, 0), 0, CIMName(), "ClassA"); classA.addProperty(property1); CIMProperty property2("Property2", CIMValue(String("default_value")), 0, CIMName(), "ClassA"); classA.addProperty(property2); CIMProperty property3("Property3", CIMValue(CIMTYPE_DATETIME, 0, 0), 0, CIMName(), "ClassA"); classA.addProperty(property3); // add class to namespace context->addClass("test_namespace", classA); } // create sub-class { CIMClass classB("ClassB", "ClassA"); classB.addQualifier(CIMQualifier("Abstract", Boolean(true))); CIMProperty property1("Property1", CIMValue(CIMTYPE_UINT32, 0, 0), 0, CIMName(), "ClassA"); property1.addQualifier(CIMQualifier("Key", Boolean(true))); classB.addProperty(property1); CIMProperty property2("Property2", CIMValue(String("default_value")), 0, CIMName(), "ClassA"); property2.addQualifier(CIMQualifier("Key", Boolean(true))); classB.addProperty(property2); CIMProperty property3("Property3", CIMValue(CIMTYPE_DATETIME, 0, 0), 0, CIMName(), "ClassA"); property3.addQualifier(CIMQualifier("Key", Boolean(true))); classB.addProperty(property3); CIMProperty property4("Property4", CIMValue(String("default_value")), 0, CIMName(), "ClassB"); classB.addProperty(property4); // add class to namespace context->addClass("test_namespace", classB); } // create sub-class { CIMClass classC("ClassC", "ClassB"); classC.addQualifier(CIMQualifier("Description", String(""))); CIMProperty property1("Property1", CIMValue(CIMTYPE_UINT32, 0, 0), 0, CIMName(), "ClassA"); property1.addQualifier(CIMQualifier("Key", Boolean(true))); property1.addQualifier(CIMQualifier("Description", String(""))); classC.addProperty(property1); CIMProperty property2("Property2", CIMValue(String("default_value")), 0, CIMName(), "ClassA"); property2.addQualifier(CIMQualifier("Key", Boolean(true))); property2.addQualifier(CIMQualifier("Description", String(""))); classC.addProperty(property2); CIMProperty property3("Property3", CIMValue(CIMTYPE_DATETIME, 0, 0), 0, CIMName(), "ClassA"); property3.addQualifier(CIMQualifier("Key", Boolean(true))); property3.addQualifier(CIMQualifier("Description", String(""))); classC.addProperty(property3); CIMProperty property4("Property4", CIMValue(CIMTYPE_STRING, 0, 0), 0, CIMName(), "ClassB"); property4.addQualifier(CIMQualifier("Description", String(""))); classC.addProperty(property4); CIMProperty property5("Property5", CIMValue(CIMTYPE_REAL32, 0, 0), 0, CIMName(), "ClassC"); classC.addProperty(property5); CIMProperty property6("Property6", CIMValue(CIMTYPE_REAL64, 0, 0), 0, CIMName(), "ClassC"); classC.addProperty(property6); CIMProperty property7("Property7", CIMValue(CIMTYPE_STRING, 0, 0), 0, CIMName(), "ClassC"); classC.addProperty(property7); CIMProperty property8("Property8", CIMValue(CIMTYPE_STRING, 0, 0), 0, CIMName(), "ClassC"); classC.addProperty(property8); CIMProperty property9("Property9", CIMValue(CIMTYPE_STRING, 0, 0), 0, CIMName(), "ClassC"); classC.addProperty(property9); CIMProperty property10("Property10", CIMValue(CIMTYPE_STRING, 0, 0), 0, CIMName(), "ClassC"); classC.addProperty(property10); CIMProperty property11("Property11", CIMValue(CIMTYPE_STRING, 0, 0), 0, CIMName(), "ClassC"); classC.addProperty(property11); CIMProperty property12("Property12", CIMValue(CIMTYPE_STRING, 0, 0), 0, CIMName(), "ClassC"); classC.addProperty(property12); CIMProperty property13("Property13", CIMValue(CIMTYPE_STRING, 0, 0), 0, CIMName(), "ClassC"); classC.addProperty(property13); CIMProperty property14("Property14", CIMValue(CIMTYPE_STRING, 0, 0), 0, CIMName(), "ClassC"); classC.addProperty(property14); CIMProperty property15("Property15", CIMValue(CIMTYPE_STRING, 0, 0), 0, CIMName(), "ClassC"); classC.addProperty(property15); CIMProperty property16("Property16", CIMValue(CIMTYPE_STRING, 0, 0), 0, CIMName(), "ClassC"); classC.addProperty(property16); CIMProperty property17("Property17", CIMValue(CIMTYPE_STRING, 0, 0), 0, CIMName(), "ClassC"); classC.addProperty(property17); CIMProperty property18("Property18", CIMValue(CIMTYPE_STRING, 0, 0), 0, CIMName(), "ClassC"); classC.addProperty(property18); CIMProperty property19("Property19", CIMValue(CIMTYPE_STRING, 0, 0), 0, CIMName(), "ClassC"); classC.addProperty(property19); CIMProperty property20("Property20", CIMValue(CIMTYPE_STRING, 0, 0), 0, CIMName(), "ClassC"); classC.addProperty(property20); // add class to namespace context->addClass("test_namespace", classC); } // TODO: add association object // TODO: add indication object // TODO: add object with embedded object }
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(Uint32 mode) { String repositoryRoot; const char* tmpDir = getenv ("PEGASUS_TMP"); if (tmpDir == NULL) { repositoryRoot = "."; } else { repositoryRoot = tmpDir; } repositoryRoot.append("/repository"); FileSystem::removeDirectoryHier(repositoryRoot); CIMRepository r (repositoryRoot, mode); // Create a namespace: const CIMNamespaceName NAMESPACE = CIMNamespaceName ("zzz"); r.createNameSpace(NAMESPACE); // Create a qualifier (and read it back): CIMQualifierDecl q1(CIMName ("abstract"), false, CIMScope::CLASS); r.setQualifier(NAMESPACE, q1); CIMConstQualifierDecl q2 = r.getQualifier(NAMESPACE, CIMName ("abstract")); PEGASUS_TEST_ASSERT(q1.identical(q2)); // Create two simple classes: CIMClass class1(CIMName ("Class1")); class1.addQualifier( CIMQualifier(CIMName ("abstract"), true, CIMFlavor::DEFAULTS)); CIMClass class2(CIMName ("Class2"), CIMName ("Class1")); r.createClass(NAMESPACE, class1); r.createClass(NAMESPACE, class2); // Enumerate the class names: Array<CIMName> classNames = r.enumerateClassNames(NAMESPACE, CIMName(), true); BubbleSort(classNames); PEGASUS_TEST_ASSERT(classNames.size() == 2); PEGASUS_TEST_ASSERT(classNames[0] == "Class1"); PEGASUS_TEST_ASSERT(classNames[1] == "Class2"); // Get the classes and determine if they are identical with input CIMClass c1 = r.getClass(NAMESPACE, CIMName ("Class1"), true, true, false); CIMClass c2 = r.getClass(NAMESPACE, CIMName ("Class2"), true, true, false); PEGASUS_TEST_ASSERT(c1.identical(class1)); PEGASUS_TEST_ASSERT(c1.identical(class1)); Array<CIMClass> classes = r.enumerateClasses(NAMESPACE, CIMName (), true, true, true); // Attempt to delete Class1. It should fail since the class has // children. try { r.deleteClass(NAMESPACE, CIMName ("Class1")); } catch (CIMException& e) { PEGASUS_TEST_ASSERT(e.getCode() == CIM_ERR_CLASS_HAS_CHILDREN); } // Delete all classes created here: r.deleteClass(NAMESPACE, CIMName ("Class2")); r.deleteClass(NAMESPACE, CIMName ("Class1")); // Be sure the classes are really gone: try { CIMClass c1 = r.getClass( NAMESPACE, CIMName ("Class1"), true, true, true); PEGASUS_TEST_ASSERT(false); } catch (CIMException& e) { PEGASUS_TEST_ASSERT(e.getCode() == CIM_ERR_NOT_FOUND); } try { CIMClass c2 = r.getClass( NAMESPACE, CIMName ("Class2"), true, true, true); PEGASUS_TEST_ASSERT(false); } catch (CIMException& e) { PEGASUS_TEST_ASSERT(e.getCode() == CIM_ERR_NOT_FOUND); } FileSystem::removeDirectoryHier(repositoryRoot); }
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 testEmbeddedValue(const CIMInstance & instance) { CIMInstance instance1 = instance.clone(); // Specific test to verify the cloning of CIMObjects/CIMInstances when set // and gotten from a CIMValue. CIMValue v1; // Create CIMValue v1 of type CIMTYPE_OBJECT/CIMTYPE_INSTANCE v1.set(EmbeddedType(instance1)); // Change the "count" property of instance1, and then verify // that the CIMValue v1, that was set from instance1, is // not affected (ie. tests clone() on CIMValue::set() ). Uint32 propIx = instance1.findProperty(CIMName("count")); PEGASUS_TEST_ASSERT(propIx != PEG_NOT_FOUND); CIMValue v2 = instance1.getProperty(propIx).getValue(); Uint32 propCount; v2.get(propCount); PEGASUS_TEST_ASSERT(propCount == 55); instance1.removeProperty(propIx); instance1.addProperty(CIMProperty(CIMName ("count"), Uint32(65)) .addQualifier(CIMQualifier(CIMName ("counter"), true)) .addQualifier(CIMQualifier(CIMName ("min"), String("0"))) .addQualifier(CIMQualifier(CIMName ("max"), String("1")))); EmbeddedType object2; v1.get(object2); CIMInstance instance1a(object2); propIx = instance1a.findProperty(CIMName("count")); PEGASUS_TEST_ASSERT(propIx != PEG_NOT_FOUND); CIMValue v3 = instance1a.getProperty(propIx).getValue(); v3.get(propCount); PEGASUS_TEST_ASSERT(propCount == 55); // Now change the "count" property of instance1a, which was obtained // from a get of CIMValue v1. Again, the underlying CIMValue should // not be affected (ie. tests clone() on CIMValue::get() ). instance1a.removeProperty(propIx); instance1a.addProperty(CIMProperty(CIMName ("count"), Uint32(65)) .addQualifier(CIMQualifier(CIMName ("counter"), true)) .addQualifier(CIMQualifier(CIMName ("min"), String("0"))) .addQualifier(CIMQualifier(CIMName ("max"), String("1")))); EmbeddedType object3; v1.get(object3); CIMInstance instance1b(object3); propIx = instance1b.findProperty(CIMName("count")); PEGASUS_TEST_ASSERT(propIx != PEG_NOT_FOUND); CIMValue v4 = instance1b.getProperty(propIx).getValue(); v4.get(propCount); PEGASUS_TEST_ASSERT(propCount == 55); // Specific test for setting value as a null CIMObject/CIMInstance // (see bug 3373). // Confirm that CIMValue() with an uninitialized CIMObject/CIMInstance will // throw exception. Boolean caught_exception = false; try { EmbeddedType obj = EmbeddedType(); CIMValue y(obj); } catch(UninitializedObjectException&) { caught_exception = true; } PEGASUS_TEST_ASSERT (caught_exception == true); // Confirm that set() with an uninitialized CIMObject/CIMInstance will // throw exception. caught_exception = false; try { CIMValue y; y.set(EmbeddedType()); } catch(UninitializedObjectException&) { caught_exception = true; } PEGASUS_TEST_ASSERT (caught_exception == true); }
// // Test of the Instance creation and instance filtering // void test04() { if (verbose) { cout << "Test04 - Create instance from Class. " << endl; } const CIMNamespaceName NAMESPACE = CIMNamespaceName("/zzz"); // Create and populate a declaration context: SimpleDeclContext* context = new SimpleDeclContext; context->addQualifierDecl( NAMESPACE, CIMQualifierDecl(CIMName("counter"), false, CIMScope::PROPERTY)); context->addQualifierDecl( NAMESPACE, CIMQualifierDecl(CIMName("classcounter"), false, CIMScope::CLASS)); context->addQualifierDecl( NAMESPACE, CIMQualifierDecl(CIMName("min"), String(), CIMScope::PROPERTY)); context->addQualifierDecl( NAMESPACE, CIMQualifierDecl(CIMName("max"), String(), CIMScope::PROPERTY)); context->addQualifierDecl(NAMESPACE, CIMQualifierDecl(CIMName("Description"), String(), CIMScope::PROPERTY)); CIMClass class1(CIMName("MyClass")); class1 .addProperty(CIMProperty(CIMName("count"), Uint32(55)) .addQualifier(CIMQualifier(CIMName("counter"), true)) .addQualifier(CIMQualifier(CIMName("min"), String("0"))) .addQualifier(CIMQualifier(CIMName("max"), String("1")))) .addProperty(CIMProperty(CIMName("message"), String("Hello")) .addQualifier(CIMQualifier(CIMName("description"), String("My Message")))) .addProperty(CIMProperty(CIMName("ratio"), Real32(1.5))); Resolver::resolveClass(class1, context, NAMESPACE); context->addClass(NAMESPACE, class1); if (verbose) { XmlWriter::printClassElement(class1); } // // Create instance with qualifiers, classorigin, and Null propertyList // { CIMInstance newInstance; newInstance = class1.buildInstance(true, true, CIMPropertyList()); if (verbose) { XmlWriter::printInstanceElement(newInstance); } assert(newInstance.getPropertyCount() == class1.getPropertyCount()); assert(newInstance.getQualifierCount() == class1.getQualifierCount()); assert(newInstance.findProperty("ratio") != PEG_NOT_FOUND); assert(newInstance.findProperty("message") != PEG_NOT_FOUND); } // // Test with include qualifiers false. Should be no qualifiers in result // { CIMInstance newInstance = class1.buildInstance(false, true, CIMPropertyList()); assert(newInstance.getQualifierCount() == 0); assert(newInstance.getPropertyCount() == class1.getPropertyCount()); assert(newInstance.findProperty("ratio") != PEG_NOT_FOUND); assert(newInstance.findProperty("message") != PEG_NOT_FOUND); } // // Test with empty property list. Should have no properties. // { Array<CIMName> pl1Array; CIMPropertyList pl1(pl1Array); CIMInstance newInstance = class1.buildInstance(false, true, pl1); assert(newInstance.getQualifierCount() == 0); assert(newInstance.getPropertyCount() == 0); } // // Test with a property that exists in property list. // { Array<CIMName> pl1Array; pl1Array.append("ratio"); CIMPropertyList pl1(pl1Array); CIMInstance newInstance = class1.buildInstance(false, true, pl1); if (verbose) { cout << "Test with one property in new instance" << endl; XmlWriter::printInstanceElement(newInstance); } assert(newInstance.getPropertyCount() == 1); assert(newInstance.findProperty("ratio") != PEG_NOT_FOUND); assert(newInstance.findProperty("message") == PEG_NOT_FOUND); assert(newInstance.getQualifierCount() == 0); } // // Test with a property that does/does not exist in property list // { Array<CIMName> pl1Array; CIMPropertyList pl1(pl1Array); pl1.clear(); pl1Array.append("blob"); pl1Array.append("ratio"); pl1.set(pl1Array); CIMInstance newInstance = class1.buildInstance(false, true, pl1); assert(newInstance.getPropertyCount() == 1); assert(newInstance.findProperty("ratio") != PEG_NOT_FOUND); assert(newInstance.findProperty("blob") == PEG_NOT_FOUND); assert(newInstance.findProperty("message") == PEG_NOT_FOUND); assert(newInstance.getQualifierCount() == 0); } /////////////////////////////////////////////////////////////////////// // // Instance Filtering function tests // /////////////////////////////////////////////////////////////////////// // build instance as starting point for tests. CIMInstance tstInstance = class1.buildInstance(true, true, CIMPropertyList()); // // Test complete copy, no change // { if (verbose) { cout << "Test1" << endl; } CIMInstance filterInstance = tstInstance.clone(); filterInstance.filter(true, true, CIMPropertyList()); assert(tstInstance.identical(filterInstance)); assert(filterInstance.getPropertyCount() == 3); assert(filterInstance.getQualifierCount() == tstInstance.getQualifierCount()); } // // Filter to one property, ratio // { if (verbose) { cout << "Test2" << endl; } Array<CIMName> pl1Array; pl1Array.append("ratio"); CIMPropertyList pl1(pl1Array); CIMInstance filterInstance = tstInstance.clone(); filterInstance.filter(true, true, pl1); if (verbose) { XmlWriter::printInstanceElement(filterInstance); } assert(filterInstance.getPropertyCount() == 1); assert(filterInstance.findProperty("ratio") != PEG_NOT_FOUND); assert(_propertyIdentical("ratio", filterInstance, tstInstance)); assert(filterInstance.getQualifierCount() == tstInstance.getQualifierCount()); } // // Filter to one property, message // { if (verbose) { cout << "Test3" << endl; } Array<CIMName> pl1Array; pl1Array.append("message"); CIMPropertyList pl1(pl1Array); CIMInstance filterInstance = tstInstance.clone(); filterInstance.filter(true, true, pl1); if (verbose) { XmlWriter::printInstanceElement(filterInstance); } assert(filterInstance.getPropertyCount() == 1); assert(filterInstance.findProperty("message") != PEG_NOT_FOUND); assert(_propertyIdentical("message", filterInstance, tstInstance)); assert(filterInstance.getQualifierCount() == tstInstance.getQualifierCount()); } // // Filter to one property, count // { if (verbose) { cout << "Test4" << endl; } Array<CIMName> pl1Array; pl1Array.append("count"); CIMPropertyList pl1(pl1Array); CIMInstance filterInstance = tstInstance.clone(); filterInstance.filter(true, true, pl1); if (verbose) { XmlWriter::printInstanceElement(filterInstance); } assert(filterInstance.getPropertyCount() == 1); assert(filterInstance.findProperty("count") != PEG_NOT_FOUND); assert(filterInstance.getQualifierCount() == tstInstance.getQualifierCount()); } // // Filter to no properties // { if (verbose) { cout << "Test5a" << endl; } Array<CIMName> pl1Array; CIMPropertyList pl1(pl1Array); CIMInstance filterInstance = tstInstance.clone(); filterInstance.filter(true, true, pl1); assert(filterInstance.getPropertyCount() == 0); assert(filterInstance.findProperty("ratio") == PEG_NOT_FOUND); assert(filterInstance.getQualifierCount() == tstInstance.getQualifierCount()); } // // Filter to two properties // { if (verbose) { cout << "Test5b" << endl; } Array<CIMName> pl1Array; pl1Array.append("count"); pl1Array.append("message"); CIMPropertyList pl1(pl1Array); CIMInstance filterInstance = tstInstance.clone(); filterInstance.filter(true, true, pl1); assert(filterInstance.getPropertyCount() == 2); assert(filterInstance.findProperty("ratio") == PEG_NOT_FOUND); assert(filterInstance.findProperty("message") != PEG_NOT_FOUND); assert(_propertyIdentical("message", filterInstance, tstInstance)); assert(filterInstance.findProperty("count") != PEG_NOT_FOUND); assert(_propertyIdentical("count", filterInstance, tstInstance)); assert(filterInstance.getQualifierCount() == tstInstance.getQualifierCount()); } // // Filter to no qualifiers and all properties. // { if (verbose) { cout << "Test6" << endl; } CIMInstance filterInstance = tstInstance.clone(); filterInstance.filter(false, true, CIMPropertyList()); assert(filterInstance.getPropertyCount() == 3); assert(filterInstance.findProperty("ratio") != PEG_NOT_FOUND); assert(filterInstance.getQualifierCount() == 0); for (Uint32 i = 0; i < filterInstance.getPropertyCount() ; i++) { CIMConstProperty p = filterInstance.getProperty(i); assert(p.getQualifierCount() == 0); } } // // Filter to no qualifiers and no properties. // { if (verbose) { cout << "Test6a" << endl; } Array<CIMName> pl1Array; CIMPropertyList pl1(pl1Array); CIMInstance filterInstance = tstInstance.clone(); filterInstance.filter(false, true, pl1); assert(filterInstance.getPropertyCount() == 0); assert(filterInstance.findProperty("ratio") == PEG_NOT_FOUND); assert(filterInstance.getQualifierCount() == 0); } // // Test Class Origin Filter // { if (verbose) { cout << "Test7 Class Origin" << endl; } // Create a subclass to do classOrigin testing CIMClass mySubClass(CIMName("subclass")); mySubClass.setSuperClassName(CIMName("MyClass")); Resolver::resolveClass(mySubClass, context, NAMESPACE); context->addClass(NAMESPACE, mySubClass); // build instance CIMInstance filterInstance = mySubClass.buildInstance(true, true, CIMPropertyList()); filterInstance.filter(false, true, CIMPropertyList()); assert(filterInstance.getPropertyCount() == 3); assert(filterInstance.findProperty("ratio") != PEG_NOT_FOUND); assert(filterInstance.getQualifierCount() == 0); for (Uint32 i = 0 ; i < filterInstance.getPropertyCount() ; i++) { CIMProperty p = filterInstance.getProperty(i); assert(!(p.getClassOrigin() == CIMName())); } filterInstance.filter(false, false, CIMPropertyList()); for (Uint32 i = 0 ; i < filterInstance.getPropertyCount() ; i++) { CIMProperty p = filterInstance.getProperty(i); assert(p.getClassOrigin() == CIMName()); } CIMInstance filterInstance2 = mySubClass.buildInstance(true, false, CIMPropertyList()); for (Uint32 i = 0 ; i < filterInstance2.getPropertyCount() ; i++) { CIMProperty p = filterInstance2.getProperty(i); assert(p.getClassOrigin() == CIMName()); } } delete context; }
void testEmbeddedValueArray(const CIMInstance & startInstance, const CIMNamespaceName & NAMESPACE, SimpleDeclContext * context) { CIMInstance instance1(startInstance.clone()); // Test an array of CIMObjects that are CIMInstances CIMInstance instance2(CIMName ("MyClass")); instance2.addQualifier(CIMQualifier(CIMName ("classcounter"), true)); instance2.addProperty(CIMProperty(CIMName ("message"), String("Adios"))); Resolver::resolveInstance (instance2, context, NAMESPACE, true); CIMInstance instance3(CIMName ("MyClass")); instance3.addQualifier(CIMQualifier(CIMName ("classcounter"), false)); instance3.addProperty(CIMProperty(CIMName ("message"), String("Au Revoir"))); Resolver::resolveInstance (instance3, context, NAMESPACE, true); Array<EmbeddedType> arr16; arr16.append(EmbeddedType(instance1)); arr16.append(EmbeddedType(instance2)); arr16.append(EmbeddedType(instance3)); test02(arr16); // Specific test to verify the cloning of CIMObjects when set as and // gotten from a CIMValue. CIMValue v1array; // Create CIMValue v1 of type CIMTYPE_OBJECT (ie. CIMObject) v1array.set(arr16); // Change the "count" property of arr16[1], and then verify // that the CIMValue v1array, that was set from arr16, is // not affected (ie. tests clone() on CIMValue::set() ). Uint32 propIx = arr16[1].findProperty(CIMName("count")); PEGASUS_TEST_ASSERT(propIx != PEG_NOT_FOUND); CIMValue v2 = arr16[1].getProperty(propIx).getValue(); Uint32 propCount; v2.get(propCount); PEGASUS_TEST_ASSERT(propCount == 55); arr16[1].removeProperty(propIx); arr16[1].addProperty(CIMProperty(CIMName ("count"), Uint32(65)) .addQualifier(CIMQualifier(CIMName ("counter"), true)) .addQualifier(CIMQualifier(CIMName ("min"), String("0"))) .addQualifier(CIMQualifier(CIMName ("max"), String("1")))); Array<EmbeddedType> object2array; v1array.get(object2array); CIMInstance instance2a(object2array[1]); propIx = instance2a.findProperty(CIMName("count")); PEGASUS_TEST_ASSERT(propIx != PEG_NOT_FOUND); CIMValue v3 = instance2a.getProperty(propIx).getValue(); v3.get(propCount); PEGASUS_TEST_ASSERT(propCount == 55); // Now change the "count" property of instance2a, which was obtained // from a get of CIMValue v1array. Again, the underlying CIMValue should // not be affected (ie. tests clone() on CIMValue::get() ). instance2a.removeProperty(propIx); instance2a.addProperty(CIMProperty(CIMName ("count"), Uint32(65)) .addQualifier(CIMQualifier(CIMName ("counter"), true)) .addQualifier(CIMQualifier(CIMName ("min"), String("0"))) .addQualifier(CIMQualifier(CIMName ("max"), String("1")))); Array<EmbeddedType> object3array; v1array.get(object3array); CIMInstance instance2b(object3array[1]); propIx = instance2b.findProperty(CIMName("count")); PEGASUS_TEST_ASSERT(propIx != PEG_NOT_FOUND); CIMValue v4 = instance2b.getProperty(propIx).getValue(); v4.get(propCount); PEGASUS_TEST_ASSERT(propCount == 55); // Specific test for setting value as a null CIMObject() (see bug 3373). // Confirm that CIMValue() with an uninitialized CIMObject in the input // array will throw exception. arr16.append(EmbeddedType()); bool caught_exception = false; try { CIMValue y(arr16); } catch(UninitializedObjectException&) { caught_exception = true; } PEGASUS_TEST_ASSERT (caught_exception == true); // Confirm that set() with an uninitialized CIMObject in the input // array will throw exception. caught_exception = false; try { CIMValue y; y.set(arr16); } catch(UninitializedObjectException&) { caught_exception = true; } PEGASUS_TEST_ASSERT (caught_exception == true); }
void test01() { const CIMNamespaceName NAMESPACE = CIMNamespaceName("/zzz"); // Create and populate a declaration context: SimpleDeclContext* context = new SimpleDeclContext; context->addQualifierDecl( NAMESPACE, CIMQualifierDecl(CIMName("counter"), false, CIMScope::PROPERTY)); context->addQualifierDecl( NAMESPACE, CIMQualifierDecl(CIMName("classcounter"), false, CIMScope::CLASS)); context->addQualifierDecl( NAMESPACE, CIMQualifierDecl(CIMName("min"), String(), CIMScope::PROPERTY)); context->addQualifierDecl( NAMESPACE, CIMQualifierDecl(CIMName("max"), String(), CIMScope::PROPERTY)); context->addQualifierDecl(NAMESPACE, CIMQualifierDecl(CIMName("Description"), String(), CIMScope::PROPERTY)); CIMClass class1(CIMName("MyClass")); class1 .addProperty(CIMProperty(CIMName("count"), Uint32(55)) .addQualifier(CIMQualifier(CIMName("counter"), true)) .addQualifier(CIMQualifier(CIMName("min"), String("0"))) .addQualifier(CIMQualifier(CIMName("max"), String("1")))) .addProperty(CIMProperty(CIMName("message"), String("Hello")) .addQualifier(CIMQualifier(CIMName("description"), String("My Message")))) .addProperty(CIMProperty(CIMName("ratio"), Real32(1.5))); // Test assert(class1.findProperty(CIMName("count")) != PEG_NOT_FOUND); assert(class1.findProperty(CIMName("message")) != PEG_NOT_FOUND); assert(class1.findProperty(CIMName("ratio")) != PEG_NOT_FOUND); Resolver::resolveClass(class1, context, NAMESPACE); context->addClass(NAMESPACE, class1); if (verbose) { XmlWriter::printClassElement(class1); } CIMInstance instance0(CIMName("MyClass")); assert(instance0.getClassName().equal(CIMName("MyClass"))); instance0.setPath(CIMObjectPath("//localhost/root/cimv2:MyClass.Foo=1")); assert(instance0.getPath() == CIMObjectPath("//localhost/root/cimv2:MyClass.Foo=1")); CIMInstance instance1(CIMName("MyClass")); instance1.addQualifier(CIMQualifier(CIMName("classcounter"), true)); instance1.addProperty(CIMProperty(CIMName("message"), String("Goodbye"))); assert(instance1.findProperty(CIMName("message")) != PEG_NOT_FOUND); assert(instance1.findProperty(CIMName("count")) == PEG_NOT_FOUND); assert(instance1.findProperty(CIMName("ratio")) == PEG_NOT_FOUND); assert(instance1.findProperty(CIMName("nuts")) == PEG_NOT_FOUND); assert(instance1.getPropertyCount() == 1); if (verbose) { XmlWriter::printInstanceElement(instance1); } Resolver::resolveInstance(instance1, context, NAMESPACE, true); if (verbose) { XmlWriter::printInstanceElement(instance1); } // Now test for properties after resolution. assert(instance1.findProperty(CIMName("message")) != PEG_NOT_FOUND); assert(instance1.findProperty(CIMName("count")) != PEG_NOT_FOUND); assert(instance1.findProperty(CIMName("ratio")) != PEG_NOT_FOUND); assert(instance1.findProperty(CIMName("nuts")) == PEG_NOT_FOUND); assert(instance1.getPropertyCount() == 3); // Now remove a property Uint32 posProperty; posProperty = instance1.findProperty(CIMName("count")); instance1.removeProperty(posProperty); assert(instance1.findProperty(CIMName("message")) != PEG_NOT_FOUND); assert(instance1.findProperty(CIMName("count")) == PEG_NOT_FOUND); assert(instance1.findProperty(CIMName("ratio")) != PEG_NOT_FOUND); assert(instance1.findProperty(CIMName("nuts")) == PEG_NOT_FOUND); assert(instance1.getPropertyCount() == 2); // Instance qualifier tests CIMQualifier cq=instance1.getQualifier(instance1.findQualifier( CIMName("classcounter"))); const CIMInstance instance2 = instance1.clone(); assert(instance2.identical(instance1)); assert(instance1.findQualifier(CIMName("nuts")) == PEG_NOT_FOUND); assert(instance2.findQualifier(CIMName("nuts")) == PEG_NOT_FOUND); assert(instance1.getQualifierCount() != 4); assert(instance1.getQualifierCount() == 1); assert(instance2.getQualifierCount() == 1); if (verbose) { XmlWriter::printInstanceElement(instance2); } // Tests for CIMConstInstance CIMConstInstance cinstance1(CIMName("MyClass")), cinstance3; CIMConstInstance ccopy(cinstance1); cinstance1 = instance1; assert(cinstance1.identical(instance1)); assert(cinstance1.getQualifierCount() == 1); CIMConstQualifier ccq = cinstance1.getQualifier(cinstance1.findQualifier( CIMName("classcounter"))); assert(cinstance1.findProperty(CIMName("message")) != PEG_NOT_FOUND); CIMConstProperty ccp = cinstance1.getProperty(cinstance1.findProperty(CIMName("message"))); cinstance3 = cinstance1; assert(cinstance3.identical(cinstance1)); assert(cinstance1.getClassName() == CIMName("MyClass")); assert(cinstance1.getClassName().equal(CIMName("MyClass"))); assert(cinstance1.getClassName().equal(CIMName("MYCLASS"))); assert(cinstance1.getClassName().equal(CIMName("myclass"))); assert(!cinstance1.getClassName().equal(CIMName("blob"))); assert(cinstance1.getQualifierCount() != 4); assert(cinstance1.getPropertyCount() == 2); CIMConstInstance cinstance2 = cinstance1.clone(); assert(cinstance2.identical(cinstance1)); if (verbose) { XmlWriter::printInstanceElement(cinstance1); } cinstance1.buildPath(class1); assert( !cinstance1.isUninitialized() ); delete context; }
int main(int, char** argv) { Boolean verbose = (getenv("PEGASUS_TEST_VERBOSE")) ? true : false; try { const String NAMESPACE = "/zzz"; // Create and populate a declaration context: SimpleDeclContext context; context.addQualifierDecl(NAMESPACE, CIMQualifierDecl (CIMName ("abstract"), false, CIMScope::CLASS, CIMFlavor::OVERRIDABLE)); context.addQualifierDecl(NAMESPACE, CIMQualifierDecl (CIMName ("description"), String(), CIMScope::CLASS, CIMFlavor::OVERRIDABLE)); context.addQualifierDecl(NAMESPACE, CIMQualifierDecl(CIMName ("q1"), false, CIMScope::CLASS, CIMFlavor::OVERRIDABLE + CIMFlavor::TOSUBCLASS)); context.addQualifierDecl(NAMESPACE, CIMQualifierDecl(CIMName ("q2"), false, CIMScope::CLASS, CIMFlavor::TOSUBCLASS)); // ATTN: KS P1 29 Mar 2002 - Add Tests for Null Value // ATTN: KS P1 29 Mar 2002 - Add tests for array values in Qualifier. // Create qualifier list 1: CIMQualifierList qualifiers0; CIMQualifierList qualifiers1; qualifiers1 .add(CIMQualifier(CIMName ("Abstract"), true)) .add(CIMQualifier(CIMName ("Description"), String("CIMQualifier List 1"))) .add(CIMQualifier(CIMName ("q1"), false)) .add(CIMQualifier(CIMName ("q2"), false)); // Run the find, get, etc tests. PEGASUS_TEST_ASSERT(qualifiers1.getCount() == 4); PEGASUS_TEST_ASSERT(qualifiers1.find(CIMName ("Abstract")) == 0); PEGASUS_TEST_ASSERT(qualifiers1.exists(CIMName ("Abstract"))); PEGASUS_TEST_ASSERT(qualifiers1.isTrue(CIMName ("Abstract"))); PEGASUS_TEST_ASSERT(qualifiers1.exists(CIMName ("q1"))); PEGASUS_TEST_ASSERT(!qualifiers1.isTrue(CIMName ("q1"))); PEGASUS_TEST_ASSERT(qualifiers1.exists(CIMName ("q2"))); PEGASUS_TEST_ASSERT(!qualifiers1.isTrue(CIMName ("q2"))); PEGASUS_TEST_ASSERT(qualifiers1.find(CIMName ("QualifierDoesNotExist")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(!qualifiers1.exists(CIMName("QualifierDoesNotExist"))); qualifiers1.resolve( &context, NAMESPACE, CIMScope::CLASS, false, qualifiers0, true); // Qualifiers after the resolve. Should have resolved against the // declarations. PEGASUS_TEST_ASSERT(qualifiers1.getCount() == 4); PEGASUS_TEST_ASSERT(qualifiers1.find(CIMName ("Abstract")) == 0); PEGASUS_TEST_ASSERT(qualifiers1.exists(CIMName ("Abstract"))); PEGASUS_TEST_ASSERT(qualifiers1.isTrue(CIMName ("Abstract"))); PEGASUS_TEST_ASSERT(qualifiers1.exists(CIMName ("q1"))); PEGASUS_TEST_ASSERT(!qualifiers1.isTrue(CIMName ("q1"))); PEGASUS_TEST_ASSERT(qualifiers1.exists(CIMName ("q2"))); PEGASUS_TEST_ASSERT(!qualifiers1.isTrue(CIMName ("q2"))); PEGASUS_TEST_ASSERT(qualifiers1.find(CIMName ("QualifierDoesNotExist")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(!qualifiers1.exists(CIMName("QualifierDoesNotExist"))); if(verbose) qualifiers1.print(); // Add test for double add of a name Boolean exceptionCaught = false; try { qualifiers1.add(CIMQualifier(CIMName ("Abstract"), true)); } catch (Exception&) { exceptionCaught = true; } PEGASUS_TEST_ASSERT(exceptionCaught); // Test some of the basics again after the double insertion problem PEGASUS_TEST_ASSERT(qualifiers1.getCount() == 4); PEGASUS_TEST_ASSERT(qualifiers1.find(CIMName ("Abstract")) == 0); PEGASUS_TEST_ASSERT(qualifiers1.exists(CIMName ("Abstract"))); PEGASUS_TEST_ASSERT(qualifiers1.isTrue(CIMName ("Abstract"))); // Create qualifier list 2: Will be resolved against qualifiers1 CIMQualifierList qualifiers2; qualifiers2 .add(CIMQualifier(CIMName ("Description"), String("CIMQualifier List 1"))) .add(CIMQualifier(CIMName ("q1"), Boolean(true), CIMFlavor::OVERRIDABLE)); if(verbose) qualifiers2.print(); PEGASUS_TEST_ASSERT(qualifiers2.getCount() == 2); PEGASUS_TEST_ASSERT(qualifiers2.exists(CIMName ("Description"))); PEGASUS_TEST_ASSERT(qualifiers2.exists(CIMName ("q1"))); PEGASUS_TEST_ASSERT(qualifiers2.isTrue(CIMName ("q1"))); // Resolve the qualifiers against the previous list qualifiers1 qualifiers2.resolve( &context, NAMESPACE, CIMScope::CLASS, false, qualifiers1, true); if(verbose) qualifiers2.print(); // Post resolution PEGASUS_TEST_ASSERT(qualifiers2.getCount() == 4); PEGASUS_TEST_ASSERT(qualifiers2.exists(CIMName ("Description"))); PEGASUS_TEST_ASSERT(qualifiers2.exists(CIMName ("abstract"))); PEGASUS_TEST_ASSERT(qualifiers2.isTrue(CIMName ("abstract"))); PEGASUS_TEST_ASSERT(qualifiers2.exists(CIMName ("q1"))); PEGASUS_TEST_ASSERT(qualifiers2.isTrue(CIMName ("q1"))); PEGASUS_TEST_ASSERT(qualifiers2.exists(CIMName ("q2"))); // Should inherit the value from the superclass PEGASUS_TEST_ASSERT(!qualifiers2.isTrue(CIMName ("q2"))); } catch (Exception& e) { cerr << "Exception: " << e.getMessage() << endl; exit(1); } cout << argv[0] << " +++++ passed all tests" << endl; return 0; }
// // Test instance qualifier operations // void test05() { CIMInstance instance1(CIMName("MyClass")); instance1.addQualifier(CIMQualifier(CIMName("Qualifier1"), true)); instance1.addQualifier(CIMQualifier(CIMName("Qualifier2"), Uint32(1))); instance1.addQualifier(CIMQualifier(CIMName("Qualifier3"), String("a"))); Boolean caughtException = false; try { instance1.addQualifier(CIMQualifier(CIMName("Qualifier1"), true)); } catch (const AlreadyExistsException&) { caughtException = true; } assert(caughtException); assert(instance1.getQualifierCount() == 3); // Test that the correct qualifiers exist in the instance Uint32 qualifierIndex; qualifierIndex = instance1.findQualifier(CIMName("Qualifier1")); assert(qualifierIndex != PEG_NOT_FOUND); qualifierIndex = instance1.findQualifier(CIMName("Qualifier2")); assert(qualifierIndex != PEG_NOT_FOUND); qualifierIndex = instance1.findQualifier(CIMName("Qualifier3")); assert(qualifierIndex != PEG_NOT_FOUND); qualifierIndex = instance1.findQualifier(CIMName("Qualifier4")); assert(qualifierIndex == PEG_NOT_FOUND); // Clone the instance and test for the correct qualifiers CIMConstInstance instance2 = instance1.clone(); assert(instance2.getQualifierCount() == 3); qualifierIndex = instance2.findQualifier(CIMName("Qualifier1")); assert(qualifierIndex != PEG_NOT_FOUND); qualifierIndex = instance2.findQualifier(CIMName("Qualifier2")); assert(qualifierIndex != PEG_NOT_FOUND); qualifierIndex = instance2.findQualifier(CIMName("Qualifier3")); assert(qualifierIndex != PEG_NOT_FOUND); qualifierIndex = instance2.findQualifier(CIMName("Qualifier4")); assert(qualifierIndex == PEG_NOT_FOUND); // Remove Qualifier2 from instance1 qualifierIndex = instance1.findQualifier(CIMName("Qualifier2")); instance1.removeQualifier(qualifierIndex); assert(instance1.getQualifierCount() == 2); qualifierIndex = instance1.findQualifier(CIMName("Qualifier2")); assert(qualifierIndex == PEG_NOT_FOUND); qualifierIndex = instance1.findQualifier(CIMName("Qualifier1")); assert(qualifierIndex != PEG_NOT_FOUND); // Confirm that the qualifiers are still in instance2 assert(instance2.getQualifierCount() == 3); qualifierIndex = instance2.findQualifier(CIMName("Qualifier1")); assert(qualifierIndex != PEG_NOT_FOUND); qualifierIndex = instance2.findQualifier(CIMName("Qualifier2")); assert(qualifierIndex != PEG_NOT_FOUND); // Remove a non-existant qualifier caughtException = false; try { instance1.removeQualifier(10); } catch (const IndexOutOfBoundsException&) { caughtException = true; } assert(caughtException); // Remove Qualifier1 and Qualifier3 from instance1 qualifierIndex = instance1.findQualifier(CIMName("Qualifier1")); instance1.removeQualifier(qualifierIndex); assert(instance1.getQualifierCount() == 1); qualifierIndex = instance1.findQualifier(CIMName("Qualifier3")); instance1.removeQualifier(qualifierIndex); assert(instance1.getQualifierCount() == 0); qualifierIndex = instance1.findQualifier(CIMName("Qualifier1")); assert(qualifierIndex == PEG_NOT_FOUND); qualifierIndex = instance1.findQualifier(CIMName("Qualifier3")); assert(qualifierIndex == PEG_NOT_FOUND); // Confirm that the qualifiers are still in instance2 assert(instance2.getQualifierCount() == 3); qualifierIndex = instance2.findQualifier(CIMName("Qualifier1")); assert(qualifierIndex != PEG_NOT_FOUND); qualifierIndex = instance2.findQualifier(CIMName("Qualifier2")); assert(qualifierIndex != PEG_NOT_FOUND); qualifierIndex = instance2.findQualifier(CIMName("Qualifier3")); assert(qualifierIndex != PEG_NOT_FOUND); }
// // Test identical() function with keys that are references // void test04() { // // Create classes A and B referenced classes, C - Association // CIMClass classA (CIMName ("A"), CIMName ()); CIMProperty propertyX ("x", String ()); propertyX.addQualifier (CIMQualifier (CIMName ("Key"), true)); CIMProperty propertyY ("y", String ()); propertyY.addQualifier (CIMQualifier (CIMName ("Key"), true)); CIMProperty propertyZ ("z", String ()); propertyZ.addQualifier (CIMQualifier (CIMName ("Key"), true)); classA.addProperty (propertyX); classA.addProperty (propertyY); classA.addProperty (propertyZ); CIMClass classB ("B"); CIMProperty propertyQ ("q", String ()); propertyQ.addQualifier (CIMQualifier (CIMName ("Key"), true)); CIMProperty propertyR ("r", String ()); propertyR.addQualifier (CIMQualifier (CIMName ("Key"), true)); CIMProperty propertyS ("s", String ()); propertyS.addQualifier (CIMQualifier (CIMName ("Key"), true)); classB.addProperty (propertyQ); classB.addProperty (propertyR); classB.addProperty (propertyS); CIMClass classC ("C"); CIMProperty propertyA ("a", CIMValue ()); propertyA.addQualifier (CIMQualifier (CIMName ("Key"), true)); CIMProperty propertyB ("b", CIMValue ()); propertyB.addQualifier (CIMQualifier (CIMName ("Key"), true)); classC.addProperty (propertyA); classC.addProperty (propertyB); // // Create instances of each classa // CIMInstance instanceA (CIMName ("A")); instanceA.addProperty (CIMProperty (CIMName ("x"), String ("rose"))); instanceA.addProperty (CIMProperty (CIMName ("y"), String ("lavender"))); instanceA.addProperty (CIMProperty (CIMName ("z"), String ("rosemary"))); CIMObjectPath aPath = instanceA.buildPath (classA); CIMObjectPath aPath2 ("A.y=\"lavender\",x=\"rose\",z=\"rosemary\""); PEGASUS_TEST_ASSERT (aPath.identical (aPath2)); CIMInstance instanceB (CIMName ("B")); instanceB.addProperty (CIMProperty (CIMName ("q"), String ("pelargonium"))); instanceB.addProperty (CIMProperty (CIMName ("r"), String ("thyme"))); instanceB.addProperty (CIMProperty (CIMName ("s"), String ("sage"))); // Test to assure that the buildpath function works. CIMObjectPath bPath = instanceB.buildPath (classB); CIMObjectPath bPath2 ("B.s=\"sage\",q=\"pelargonium\",r=\"thyme\""); PEGASUS_TEST_ASSERT (bPath.identical (bPath2)); // Build instance of C and build path from buildPath function. CIMInstance instanceC (CIMName ("C")); instanceC.addProperty (CIMProperty (CIMName ("a"), aPath, 0, CIMName ("A"))); instanceC.addProperty (CIMProperty (CIMName ("b"), bPath, 0, CIMName ("B"))); CIMObjectPath cPath = instanceC.buildPath (classC); // Build CIMObjectPath from keybindings. Array <CIMKeyBinding> keyBindings; CIMKeyBinding aBinding ("a", "A.y=\"lavender\",x=\"rose\",z=\"rosemary\"", CIMKeyBinding::REFERENCE); CIMKeyBinding bBinding ("b", "B.s=\"sage\",q=\"pelargonium\",r=\"thyme\"", CIMKeyBinding::REFERENCE); keyBindings.append (aBinding); keyBindings.append (bBinding); CIMObjectPath cPath2 ("", CIMNamespaceName (), cPath.getClassName (), keyBindings); // Assert that the CIMObjectPaths for C from build path and direct // from keybindings are equal. PEGASUS_TEST_ASSERT (cPath.identical (cPath2)); // ATTN: KS 25 Feb 2003 P3 - Think we can extend these tests // since this is creation of classes and // instnaces for associations and referenced classes. }
void test02() { // Tests for CIMConstProperty methods CIMProperty p1(CIMName ("message"), String("Hi There")); p1.addQualifier(CIMQualifier(CIMName ("Key"), true)); p1.addQualifier(CIMQualifier(CIMName ("stuff"), true)); p1.addQualifier(CIMQualifier(CIMName ("stuff2"), true)); p1.addQualifier(CIMQualifier(CIMName ("Description"), String("Blah Blah"))); CIMConstProperty p2 = p1; CIMConstProperty cp1 = p1; CIMConstProperty cp2 = p2; CIMConstProperty cp3(CIMName ("message3"), String("hello")); CIMConstProperty cp1clone = cp1.clone(); if(verbose) XmlWriter::printPropertyElement(cp1, cout); Buffer mofOut; MofWriter::appendPropertyElement(true,mofOut, cp1); Buffer xmlOut; XmlWriter::appendPropertyElement(xmlOut, cp1); PEGASUS_TEST_ASSERT(cp1.getName() == CIMName ("message")); PEGASUS_TEST_ASSERT(cp1.getType() == CIMTYPE_STRING); Uint32 pos; Boolean isKey = false; if ((pos = cp1.findQualifier (CIMName ("key"))) != PEG_NOT_FOUND) { CIMValue value; value = cp1.getQualifier (pos).getValue (); if (!value.isNull ()) { value.get (isKey); } } PEGASUS_TEST_ASSERT (isKey); PEGASUS_TEST_ASSERT(cp1.getArraySize() == 0); PEGASUS_TEST_ASSERT(cp1.getPropagated() == false); PEGASUS_TEST_ASSERT(cp1.findQualifier( CIMName ("stuff")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(cp1.findQualifier( CIMName ("stuff2")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(cp1.findQualifier( CIMName ("stuff21")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(cp1.findQualifier( CIMName ("stuf")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(cp1.getQualifierCount() == 4); try { p1.getQualifier(0); } catch(IndexOutOfBoundsException& e) { if(verbose) cout << "Exception: " << e.getMessage() << endl; } }