📄 instancedecl.cpp
字号:
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\\\"\""; PEGASUS_TEST_ASSERT(x == assocInstancePath.toString()); CIMObjectPath px = x; PEGASUS_TEST_ASSERT(px.identical(assocInstancePath));}Boolean _propertyIdentical( const char* propertyName, CIMInstance& instance1, CIMInstance& instance2){ Uint32 pos = instance1.findProperty(propertyName); CIMConstProperty p1 = instance1.getProperty(pos); pos = instance2.findProperty(propertyName); CIMConstProperty p2 = instance2.getProperty(pos); return (p1.identical(p2));}//// 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); } PEGASUS_TEST_ASSERT(newInstance.getPropertyCount() == class1.getPropertyCount()); PEGASUS_TEST_ASSERT(newInstance.getQualifierCount() == class1.getQualifierCount()); PEGASUS_TEST_ASSERT(newInstance.findProperty("ratio") != PEG_NOT_FOUND); PEGASUS_TEST_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()); PEGASUS_TEST_ASSERT(newInstance.getQualifierCount() == 0); PEGASUS_TEST_ASSERT(newInstance.getPropertyCount() == class1.getPropertyCount()); PEGASUS_TEST_ASSERT(newInstance.findProperty("ratio") != PEG_NOT_FOUND); PEGASUS_TEST_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); PEGASUS_TEST_ASSERT(newInstance.getQualifierCount() == 0); PEGASUS_TEST_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); } PEGASUS_TEST_ASSERT(newInstance.getPropertyCount() == 1); PEGASUS_TEST_ASSERT(newInstance.findProperty("ratio") != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(newInstance.findProperty("message") == PEG_NOT_FOUND); PEGASUS_TEST_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); PEGASUS_TEST_ASSERT(newInstance.getPropertyCount() == 1); PEGASUS_TEST_ASSERT(newInstance.findProperty("ratio") != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(newInstance.findProperty("blob") == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(newInstance.findProperty("message") == PEG_NOT_FOUND); PEGASUS_TEST_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()); PEGASUS_TEST_ASSERT(tstInstance.identical(filterInstance)); PEGASUS_TEST_ASSERT(filterInstance.getPropertyCount() == 3); PEGASUS_TEST_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); } PEGASUS_TEST_ASSERT(filterInstance.getPropertyCount() == 1); PEGASUS_TEST_ASSERT(filterInstance.findProperty("ratio") != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(_propertyIdentical("ratio", filterInstance, tstInstance)); PEGASUS_TEST_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); } PEGASUS_TEST_ASSERT(filterInstance.getPropertyCount() == 1); PEGASUS_TEST_ASSERT(filterInstance.findProperty("message") != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(_propertyIdentical("message", filterInstance, tstInstance)); PEGASUS_TEST_ASSERT(filterInstance.getQualifierCount() == tstInstance.getQualifierCount()); } // // Filter to one property, count // { if (verbose) { cout << "Test4" << endl; } Array<CIMName> pl1Array;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -