📄 object.cpp
字号:
obj2.addQualifier(CIMQualifier(CIMName ("Key"), true)); obj2.addQualifier(CIMQualifier(CIMName ("Description"), String("Just a Test"))); obj2.addProperty(CIMProperty(CIMName ("message"), String("Hello There"))); obj2.addProperty(CIMProperty(CIMName ("count"), Uint32(77))); CIMConstInstance cinstance(CIMName ("MyClass")); CIMConstObject cobj4(instance); CIMConstObject cobj5(cinstance); CIMConstObject cobj6(obj2); CIMConstObject cobj7 = obj1; CIMConstObject cobj8 = cobj7; CIMConstObject cobj9 = class1; CIMConstObject cobj10 = cclass1; CIMConstObject cobj11 = instance; CIMConstObject cobj12 = cinstance; PEGASUS_TEST_ASSERT(cobj1.getClassName() == CIMName ("MyClass")); PEGASUS_TEST_ASSERT(cobj1.getPath() == CIMObjectPath("//localhost/root/cimv2:MyClass")); // clone the instance object CIMObject cloneObj = cobj4.clone(); CIMConstObject ccloneObj = cloneObj; PEGASUS_TEST_ASSERT(ccloneObj.identical(cobj4) == true); PEGASUS_TEST_ASSERT(ccloneObj.identical(cobj2) == false); if (verbose) { Buffer xmlOut; XmlWriter::appendObjectElement(xmlOut, ccloneObj); } // Test qualifiers PEGASUS_TEST_ASSERT(ccloneObj.getQualifierCount() == 2); PEGASUS_TEST_ASSERT(ccloneObj.findQualifier(CIMName ("Key")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(ccloneObj.findQualifier(CIMName ("Description")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(ccloneObj.findQualifier(CIMName ("q1")) == PEG_NOT_FOUND); Uint32 posQualifier; posQualifier = ccloneObj.findQualifier(CIMName ("Key")); PEGASUS_TEST_ASSERT(posQualifier != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(posQualifier < ccloneObj.getQualifierCount()); try { ccloneObj.getQualifier(posQualifier); } catch(IndexOutOfBoundsException& e) { if(verbose) cout << "Exception: " << e.getMessage() << endl; } // Test properties PEGASUS_TEST_ASSERT(ccloneObj.getPropertyCount() == 2); PEGASUS_TEST_ASSERT(ccloneObj.findProperty(CIMName ("count")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(ccloneObj.findProperty(CIMName ("message")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(ccloneObj.findProperty(CIMName ("ratio")) == PEG_NOT_FOUND); Uint32 posProperty; posProperty = ccloneObj.findProperty(CIMName ("message")); try { ccloneObj.getProperty(posProperty); } catch(IndexOutOfBoundsException& e) { if(verbose) cout << "Exception: " << e.getMessage() << endl; }}//*********************************************************************// CIMObject setPath tests////*********************************************************************void test03(){ CIMClass class1(CIMName ("MyClass")); CIMObjectPath ref1("//localhost/root/cimv2:MyClass"); class1.setPath(ref1); CIMObject obj1; CIMObject obj2 = CIMObject (class1); obj2.setPath (ref1); CIMObject obj3(obj2); CIMObject obj4 = obj3; CIMClass class2(CIMName ("YourClass")); CIMObjectPath ref2("//localhost/root/cimv2:YourClass"); class2.setPath(ref2); obj3 = CIMObject (class2); obj3.setPath (ref2); CIMObjectPath ref3 = obj3.getPath (); CIMObject myObj = obj3; if(verbose) { Buffer xmlOut; XmlWriter::appendObjectElement(xmlOut, myObj); }}//*********************************************************************// CIMObject, CIMClass, CIMInstance tests using setPath and getPath//*********************************************************************void test04(){ // Verify class name cannot be changed after creation. only a test for // CIMObject is needed because CIMClass and CIMInstance use // CIMClass::setPath() to perform this function. try { CIMObject cimObject(CIMInstance("MyClass")); cimObject.setPath(CIMObjectPath("//localhost/root/cimv2:YourClass")); throw Exception( "Failed to detect name change via CIMObject::setPath()."); } catch(Exception &) { // expected. do nothing. if(verbose) { cout << "Successfully prevented class name change via setPath()." << endl; } } // // Test CIMClass // CIMClass class1 (CIMName ("MyClass")); class1.setPath(CIMObjectPath ("//localhost/root/cimv2:MyClass")); CIMProperty prop1; prop1 = CIMProperty (CIMName ("message"), CIMValue (CIMTYPE_STRING)); prop1.addQualifier (CIMQualifier (CIMName ("Key"), true)); CIMProperty prop2; prop2 = CIMProperty (CIMName ("count"), CIMValue (CIMTYPE_UINT32)); prop2.addQualifier (CIMQualifier (CIMName ("Key"), true)); class1.addProperty (prop1); class1.addProperty (prop2); CIMObjectPath cpath = class1.getPath (); class1.setPath (CIMObjectPath (class1.getClassName ().getString())); CIMObjectPath cpath2 = class1.getPath (); class1.setPath (cpath); CIMObjectPath cpath3 = class1.getPath (); PEGASUS_TEST_ASSERT (cpath3 == cpath); if (verbose) { cout << "Class object path from getPath: " << cpath.toString() << endl; cout << "Class object path from getPath after setPath: " << cpath2.toString() << endl; cout << "Class object path from getPath after second setPath: " << cpath3.toString() << endl; } // // Test class CIMObject // CIMObject oclass1 = class1; CIMObjectPath ocpath = class1.getPath (); class1.setPath (CIMObjectPath (class1.getClassName ().getString())); CIMObjectPath ocpath2 = class1.getPath (); class1.setPath (ocpath); CIMObjectPath ocpath3 = class1.getPath (); PEGASUS_TEST_ASSERT (ocpath3 == ocpath); if (verbose) { cout << "Class object path from getPath: " << ocpath.toString() << endl; cout << "Class object path from getPath after setPath: " << ocpath2.toString() << endl; cout << "Class object path from getPath after second setPath: " << ocpath3.toString() << endl; } // // Test CIMInstance // CIMInstance instance1 (CIMName ("MyClass")); instance1.addProperty (CIMProperty (CIMName ("message"), String("Hello There"))); instance1.addProperty (CIMProperty (CIMName ("count"), Uint32 (77))); CIMObjectPath path = instance1.buildPath (class1); CIMObjectPath path2 = instance1.getPath (); instance1.setPath (path); CIMObjectPath path3 = instance1.getPath (); PEGASUS_TEST_ASSERT (path3 == path); if (verbose) { cout << "Instance object path from buildPath: " << path.toString() << endl; cout << "Instance object path from getPath: " << path2.toString() << endl; cout << "Instance object path from getPath after setPath: " << path3.toString() << endl; } // // Test instance CIMObject // CIMInstance instance2 (CIMName ("MyClass")); instance2.addProperty (CIMProperty (CIMName ("message"), String("Good-bye..."))); instance2.addProperty (CIMProperty (CIMName ("count"), Uint32 (88))); CIMObject oinstance1 = instance2; CIMObjectPath opath = instance2.buildPath (class1); CIMObjectPath opath1 = oinstance1.getPath (); oinstance1.setPath (opath); CIMObjectPath opath2 = oinstance1.getPath (); PEGASUS_TEST_ASSERT (opath2 == opath); if (verbose) { cout << "Instance object path from buildPath: " << opath.toString() << endl; cout << "Instance object path from getPath: " << opath1.toString() << endl; cout << "Instance object path from getPath after setPath: " << opath2.toString() << endl; }}int main(int argc, char** argv){ verbose = getenv("PEGASUS_TEST_VERBOSE"); try { test01(); test02(); test03(); test04(); } catch (Exception& e) { cout << "Exception: " << e.getMessage() << endl; } cout << argv[0] << " +++++ passed all tests" << endl; return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -