📄 testclient.cpp
字号:
errorCount++; return; } //PEGASUS_TEST_ASSERT(c3.identical(c2)); // Determine if the new Class exists in Enumerate classNames = client->enumerateClassNames( globalNamespace, CIMName ("CIM_ManagedElement"), false); Boolean found = false; for (Uint32 i = 0; i < classNames.size(); i++) { if (classNames[i].equal(testClass)) found = true; } if (!found) { cout << "Test Class " << testClass << " Not found in enumeration " << endl; errorCount++; return; } //PEGASUS_TEST_ASSERT(found); // DeleteClass: try { client->deleteClass(globalNamespace, testClass); } catch (CIMException& e) { cout << "Testclass delete failed " << e.getMessage() << endl; errorCount++; return; } } // Get all the classes and compare enum names with enum classes from before classNames = client->enumerateClassNames(globalNamespace, CIMName(), false); Array<CIMClass> classDecls = client->enumerateClasses( globalNamespace, CIMName(), false, false, true, true); //PEGASUS_TEST_ASSERT(classDecls.size() == classNames.size()); if (classDecls.size() != classNames.size()) { cout << "Error: Class total count before and after test. Before = " << classNames.size() << ", after = " << classDecls.size() << endl; errorCount++; return; } for (Uint32 i = 0; i < classNames.size(); i++) { CIMClass tmp = client->getClass( globalNamespace, classNames[i], false, true, true); PEGASUS_TEST_ASSERT(classNames[i].equal(classDecls[i].getClassName())); PEGASUS_TEST_ASSERT(tmp.identical(classDecls[i])); }}static void TestQualifierOperations(CIMClient* client, Boolean activeTest, Boolean verboseTest, String uniqueID) { Array<CIMQualifierDecl> qualifierDecls = client->enumerateQualifiers(globalNamespace); if (verboseTest) { for (Uint32 i = 0; i < qualifierDecls.size(); i++) { cout << qualifierDecls[i].getName() << endl; } } cout << qualifierDecls.size() << " Qualifiers" <<endl; if (activeTest) { // create unique qualifiers String prefix = uniqueID; CIMName qd1_name = prefix.append("_Q1"); CIMName qd2_name = prefix.append("_Q2"); // Create two qualifier declarations: CIMQualifierDecl qd1(qd1_name, false, CIMScope::CLASS, CIMFlavor::TOSUBCLASS); client->setQualifier(globalNamespace, qd1); CIMQualifierDecl qd2(qd2_name, String("Hello"), CIMScope::PROPERTY + CIMScope::CLASS, CIMFlavor::OVERRIDABLE); client->setQualifier(globalNamespace, qd2); // Get them and compare: CIMQualifierDecl tmp1 = client->getQualifier(globalNamespace, qd1_name); PEGASUS_TEST_ASSERT(tmp1.identical(qd1)); CIMQualifierDecl tmp2 = client->getQualifier(globalNamespace, qd2_name); PEGASUS_TEST_ASSERT(tmp2.identical(qd2)); // Enumerate the qualifiers: Array<CIMQualifierDecl> qualifierDecls = client->enumerateQualifiers(globalNamespace); for (Uint32 i = 0; i < qualifierDecls.size(); i++) { CIMQualifierDecl tmp = qualifierDecls[i]; if (tmp.getName().equal(qd1_name)) PEGASUS_TEST_ASSERT(tmp1.identical(tmp)); if (tmp.getName().equal(qd2_name)) PEGASUS_TEST_ASSERT(tmp2.identical(tmp)); } // Delete the qualifiers: client->deleteQualifier(globalNamespace, qd1_name); client->deleteQualifier(globalNamespace, qd2_name); }}static void TestInstanceGetOperations(CIMClient* client, Boolean activeTest, Boolean verboseTest, String uniqueID){ // Get all instances // Get all classes //Array<CIMName> classNames = client.enumerateClassNames( // globalNamespace, "CIM_ManagedElement", false); Array<CIMName> classNames = client->enumerateClassNames( globalNamespace, CIMName(), true); cout << classNames.size() << " Classes found " << endl; Array<CIMObjectPath> instanceNames; Uint16 numberOfNotSupportedClassesFound = 0; for (Uint32 i = 0; i < classNames.size(); i++) { //if (classNames[i] == "PG_ShutdownService") //{ // // Skip the PG_ObjectManager class. It currently has no // // instance provider and no instances. //} //else //{ try { instanceNames = client->enumerateInstanceNames(globalNamespace,classNames[i]); if (instanceNames.size() > 0) cout << "Class " << classNames[i] << " " << instanceNames.size() << " Instances" << endl; } catch(CIMException& e) { if (e.getCode() == CIM_ERR_NOT_SUPPORTED) { numberOfNotSupportedClassesFound++; } else { cerr << "CIMException : " << classNames[i] << endl; cerr << e.getMessage() << endl; errorCount++; return; } } catch(ConnectionTimeoutException& e) { PEGASUS_STD(cerr) << "Warning: " << e.getMessage() << PEGASUS_STD(endl); exit(2); } catch(Exception& e) { PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl); exit(1); } //} } if (numberOfNotSupportedClassesFound > 0) { cout << "Number of Not Supported Classes Found = " << numberOfNotSupportedClassesFound << endl; } /* virtual Array<CIMObjectPath> enumerateInstanceNames( const CIMNamespaceName& nameSpace, const CIMName& className) = 0; virtual Array<CIMInstance> enumerateInstances( const CIMNamespaceName& nameSpace, const CIMName& className, Boolean deepInheritance = true, Boolean localOnly = true, Boolean includeQualifiers = false, Boolean includeClassOrigin = false, */}static void TestInstanceModifyOperations(CIMClient* client, Boolean activeTest, Boolean verboseTest, String uniqueID){ if (!activeTest) { cout << "InstanceModify bypassed because it modifies repository. Set active to execute." << endl; return; } // name of class to play with String classname = uniqueID.append("_").append("PEG_TEST_LocalCLASS"); CIMName className(classname); // Delete the class if it already exists: try { client->deleteClass(globalNamespace, className); } catch (Exception&) { // Ignore delete class! } // Create a new class: CIMClass cimClass(className); 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"), Uint32(0)) .addQualifier(CIMQualifier(CIMName ("key"), true))) .addProperty(CIMProperty(CIMName ("nick"), String()) .addQualifier(CIMQualifier(CIMName ("key"), false))); client->createClass(globalNamespace, cimClass); // Create an instance of that class: cout << "Create one Instance of class " << className << endl; CIMInstance cimInstance(className); cimInstance.addProperty(CIMProperty(CIMName ("last"), String("Smith"))); cimInstance.addProperty(CIMProperty(CIMName ("first"), String("John"))); cimInstance.addProperty(CIMProperty(CIMName ("age"), Uint32(1010))); cimInstance.addProperty(CIMProperty(CIMName ("nick"), String("Duke"))); CIMObjectPath instanceName = cimInstance.buildPath(cimClass); client->createInstance(globalNamespace, cimInstance); // Get the instance and compare with created one: //CIMObjectPath ref; //CIMObjectPath::instanceNameToReference(instanceName, ref); CIMInstance tmp = client->getInstance(globalNamespace, instanceName); // XmlWriter::printInstanceElement(cimInstance); // XmlWriter::printInstanceElement(tmp); // PEGASUS_TEST_ASSERT(cimInstance.identical(tmp)); // Test timeout methods const Uint32 TEST_TIMEOUT = 10000; Uint32 origTimeout = client->getTimeout(); client->setTimeout( TEST_TIMEOUT ); Uint32 newTimeout = client->getTimeout(); PEGASUS_TEST_ASSERT( newTimeout == TEST_TIMEOUT ); client->setTimeout( origTimeout ); // Test get/set property methods const String TESTPROPVAL = "JR"; const String TESTPROPVALNAME = "nick"; cout << "Set property " << endl; const CIMValue testPropVal = CIMValue( TESTPROPVAL ); client->setProperty( globalNamespace, instanceName, TESTPROPVALNAME, testPropVal ); cout << "Get property " << endl; CIMValue returnedPropVal = client->getProperty( globalNamespace, instanceName, TESTPROPVALNAME ); PEGASUS_TEST_ASSERT( returnedPropVal == testPropVal ); // Test modify instance client method // Change the "nick" property and compare. CIMInstance testInstance = client->getInstance(globalNamespace, instanceName); Uint32 propertyPos = testInstance.findProperty( TESTPROPVALNAME ); testInstance.removeProperty( propertyPos ); CIMProperty nickProperty = CIMProperty( TESTPROPVALNAME, String("Duke") ); nickProperty.setClassOrigin( className ); testInstance.addProperty( nickProperty ); testInstance.setPath (instanceName); client->modifyInstance( globalNamespace, testInstance ); CIMInstance currentInstance = client->getInstance( globalNamespace, instanceName ); currentInstance.setPath( instanceName ); //PEGASUS_TEST_ASSERT( currentInstance.identical( testInstance ) ); client->deleteInstance(globalNamespace, instanceName); // Repeat to create multiple instances Uint32 repeatCount = 30; Array<CIMObjectPath> instanceNames; cout << "Create " << repeatCount << " Instances" << endl; for (Uint32 i = 0; i < repeatCount; i++) { CIMInstance cimInstance(className); cimInstance.addProperty(CIMProperty(CIMName ("last"), String("Smith"))); cimInstance.addProperty(CIMProperty(CIMName ("first"), String("John"))); cimInstance.addProperty(CIMProperty(CIMName ("age"), Uint32(i))); instanceNames.append( cimInstance.buildPath(cimClass) ); client->createInstance(globalNamespace, cimInstance); } cout << "Delete the Instances " << endl; for (Uint32 i = 0; i < repeatCount; i++) { client->deleteInstance(globalNamespace,instanceNames[i]); } cout << "Delete the Class " << endl; client->deleteClass(globalNamespace,className);}/* testRefandAssoc - issues a set of reference and association calls for the input parameters. It does not capture exceptions*/static void testRefandAssoc(CIMClient* client, CIMNamespaceName& nameSpace, Boolean verboseTest, CIMObjectPath& objectName, CIMName assocClass, CIMName resultClass, String role = String::EMPTY, String resultRole = String::EMPTY){ Array<CIMObjectPath> result = client->referenceNames( nameSpace, objectName, resultClass, role); Array<CIMObject> resultObjects = client->references( nameSpace, objectName, resultClass, role); if (verboseTest) { cout << "Test references results for class: " << objectName.getClassName() << " returned " << result.size() << "reference names" << endl; } if (result.size() != resultObjects.size()) { cout << "ERROR, Reference and reference Name count difference" << endl; errorCount++; return; } for (Uint32 i = 0; i < resultObjects.size(); i++) { Uint32 matched=0; for (Uint32 j = 0; j < result.size(); j++) { if (resultObjects[i].getPath().toString() == result[j].toString()) { matched=1; result.remove(j); j--; break; } } if(matched) { resultObjects.remove(i); i--; } } for(Uint32 i=0;i<result.size(); i++) { cout << "ReferencesName response Error: " << resultObjects[i].getPath().toString() << " != " << result[i].toString() << endl; } if (result.size()) { errorCount++; return; } Array<CIMObjectPath> assocResult = client->associatorNames( nameSpace, objectName, assocClass, resultClass, role, resultRole); Array<CIMObject> assocResultObjects = client->associators( nameSpace, objectName, assocClass, resultClass, role, resultRole); if (verboseTest) { cout << "Test associations results for class: " << objectName.getClassName() << " returned " << result.size() << "associator names" << endl; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -