📄 interop.cpp
字号:
//pos = cimInstance.findProperty(CIMName ("PlannedValue")); //prop = (CIMProperty)cimInstance.getProperty(pos); //plannedValue = prop.getValue().toString(); if (verbose) { cout << " Config return: " << " Requested Name: " << propertyName.getString() << " Returned Name: " << propertyNameValue //<< " Default: " << defaultValue //<< " planned: " << plannedValue << " current: " << currentValue << endl; } } catch(const CIMException& e) { cout << "CIM Exception during get Config " << e.getMessage() << endl; return(String::EMPTY); } return (currentValue);}Boolean InteropTest::getCurrentBoolConfigProperty( const CIMName& propName) { return ConfigManager::parseBooleanValue(getCurrentConfigProperty(propName));}Uint32 InteropTest::getCurrentValueConfigProperty( const CIMName& propName) { String strValue = getCurrentConfigProperty(propName); long longValue; if (!sscanf(strValue.getCString(), "%ld", &longValue)) return 0; return (Uint32)longValue;}/** Test a single class to assure that the returned reference names from an enumerateInstanceNames and the paths in the instances match. Then get all classes and test against the returned instances to assure that they match. @parm - namespace - Namespace for this test. @param - className CIMName of class to test. @return returns true if tests pass. False if there is a difference. @any exceptions caught are displayed and the error return executed.*/Boolean InteropTest::testEnumAgainstEnumNames( const CIMNamespaceName& nameSpace, const CIMName& className){ try { Array<CIMObjectPath> paths; Array<CIMInstance> instances; paths = _client.enumerateInstanceNames(nameSpace, className); instances = _client.enumerateInstances(nameSpace, className, true, // deepinheritance false, // localonly true, //includeQualifiers true, //includeClassOrigin CIMPropertyList()); if(!(paths.size() == instances.size())) { cout << "Error: Class " << className.getString() << " referenceCount: " << paths.size() << " instanceCount: " << instances.size() << endl; return(false); } if( !matchPathsAndInstancePaths(paths, instances)) { /* Assumes that the match function will flag errors cout << "Error: Class " << className.getString() << " reference and Instance paths do not match " << endl; */ return(false); } for (Uint32 i = 0 ; i < instances.size() ; i++ ) { CIMInstance instance = _client.getInstance(nameSpace, instances[i].getPath(), false, //lo true, //includeQualifiers true, //includeClassOrigin CIMPropertyList()); instance.setPath(instances[i].getPath()); if (!(instances[i].getPath() == instance.getPath())) { cout << "Error: Class " << className.getString() << " Instance path does not match enumerate for same instance.\n\n" << instances[i].getPath().toString() << "\n\n" << instance.getPath().toString() << endl << endl; return(false); } // TODO DELETE CIMObjectPath temp = instances[i].getPath(); if (!instance.identical(instances[i])) { cout << "Error: Class " << className.getString() << " Instance identical test faild for instance " << instances[i].getPath().toString() << endl; return(false); } } } catch(CIMException& e) { cerr << "testEnumAgainstEnumNames CIMException: " << e.getMessage() << endl; } catch(Exception& e) { cerr << "testEnumAgainstEnumNames Pegasus Exception: " << e.getMessage() << endl; } catch(...) { cerr << "testEnumAgainstEnumNames Caught General Exception:" << endl; } return(false);}/* test getting instances from an enum list. The returned instances are compared to those in the corresponding instances list. We assume that the instance list was from an enum. This confirms that the instances returned from getInstance are the same as those from enumerateinstances. Note: Since this tests the instance for equality with the instance from the enumerate, the enumerate must have matching attributes AND must be deepInheritance to assure that all properties are returned. @param paths Array of CIMObjectPaths representing the enumerateinstanceNames result @param instances Array of CIMInstances representing the enumerateInstances result @return True if passes test. False if any of the tests fail @Exceptions Any number of uncaught exceptions from the calls.*/Boolean InteropTest::testGetInstancesForEnum(const Array<CIMObjectPath>& paths, const Array<CIMInstance>& instances, const Boolean localOnly, const Boolean includeQualifiers, const Boolean includeClassOrigin, const CIMPropertyList& propertyList){ // Get every instance to confirm that it is gettable for (Uint32 i = 0 ; i < paths.size() ; i++) { CIMInstance instance = _client.getInstance(PEGASUS_NAMESPACENAME_INTEROP, paths[i], localOnly, includeQualifiers, includeClassOrigin, propertyList); for (Uint32 j = 0; instances.size() ; j++) { if (instance.getPath() == instances[j].getPath()) { if (!instances[j].identical(instance)) { cout << " Instances not equal " << instances[j].getPath().toString() << endl; return (false); } else break; } } } return(true);}/* Validate the path definitions in results of enumerateInstances against that in enumerateinstance paths. Confirms that the same number of items is returned and that they have the same path definitions. Note that this comparison is independent of hostname and namespaces because they are not returned with instances. @param paths Array<CIMObjectPath> from an enumerateinstanceNames @param instances Array of CIMInstance from enumerateInstanceN.*/Boolean InteropTest::matchPathsAndInstancePaths(Array<CIMObjectPath>& paths, const Array<CIMInstance> instances){ PEGASUS_TEST_ASSERT(instances.size() == paths.size()); if (paths.size() == 0) return true; Array<CIMObjectPath> instancePaths; // create path list from instances for (Uint32 i = 0 ; i < instances.size() ; i++) { instancePaths.append(instances[i].getPath()); } String host = paths[0].getHost(); CIMNamespaceName ns = paths[0].getNameSpace(); for (Uint32 i = 0 ; i < instancePaths.size() ; i++) { if (instancePaths[i].getHost() == String::EMPTY) { instancePaths[i].setHost(host); } if (instancePaths[i].getNameSpace().isNull()) { instancePaths[i].setNameSpace(ns); } } for (Uint32 i = 0 ; i < paths.size() ; i++) { if (!_containsObjectPath(instancePaths[i], paths)) { // Failed test. Display error and rtn false. if (true) { cout << "matchPathsAndInstancePaths Error in path match. Path\n" << instances[i].getPath().toString() << "\nNot found in the following array of paths" << endl; for (Uint32 j = 0 ; j < paths.size() ; j++) { cout << paths[j].toString() << endl;; } } return (false); } } return (true);}Boolean InteropTest::matchPathsAndObjectPaths(Array<CIMObjectPath>& paths, const Array<CIMObject> ObjectInstances){ PEGASUS_TEST_ASSERT(ObjectInstances.size() == paths.size()); if (paths.size() == 0) return true; Array<CIMObjectPath> instancePaths; // create path list from instances for (Uint32 i = 0 ; i < ObjectInstances.size() ; i++) { instancePaths.append(ObjectInstances[i].getPath()); } String host = paths[0].getHost(); CIMNamespaceName ns = paths[0].getNameSpace(); for (Uint32 i = 0 ; i < instancePaths.size() ; i++) { if (instancePaths[i].getHost() == String::EMPTY) { instancePaths[i].setHost(host); } if (instancePaths[i].getNameSpace().isNull()) { instancePaths[i].setNameSpace(ns); } } for (Uint32 i = 0 ; i < paths.size() ; i++) { if (!_containsObjectPath(instancePaths[i], paths)) { // Failed test. Display error and rtn false. if (true) { cout << "matchPathsAndInstancePaths Error in path match. Path\n" << ObjectInstances[i].getPath().toString() << "\nNot found in the following array of paths" << endl; for (Uint32 j = 0 ; j < paths.size() ; j++) { cout << paths[j].toString() << endl;; } } return (false); } } return (true);}Boolean InteropTest::testEnumerateOptions( const CIMName& className, Boolean localOnly, Boolean deepInheritance, const CIMPropertyList propertyList, const Uint32 expectedPropertyCount){ CDEBUG("testEnumerations 0" ); Array<CIMInstance> instancesObjMgr = _client.enumerateInstances( PEGASUS_NAMESPACENAME_INTEROP, className, deepInheritance, localOnly, false, // include qualifiers = false false, propertyList); PEGASUS_TEST_ASSERT(instancesObjMgr.size() == 1); CIMInstance instance = instancesObjMgr[0]; CIMPropertyList rtnd; Array<CIMName> nameList; CDEBUG("testEnumerations 1" << " prpertycount= " << instance.getPropertyCount()); for (Uint32 i = 0 ; i < instance.getPropertyCount() ; i++) { CDEBUG("testEnumerations 1a" << " propertycount= " << instance.getProperty(i).getName().getString()); nameList.append(instance.getProperty(i).getName()); } CDEBUG("testEnumerations 2" ); rtnd.set(nameList); CDEBUG("testEnumerations 3" ); if (instance.getPropertyCount() != expectedPropertyCount) { cout << "Error in enumerate options. " << " Class " << className.getString() << " lo= " << _toString(localOnly) << " di= " << _toString(deepInheritance) << " Expected Property count " << expectedPropertyCount << " Received Property Count " << instance.getPropertyCount() << "\nPl Sent= " << _showPropertyList(propertyList) << "\nPl Rcvd= " << _showPropertyList(rtnd) << endl; PEGASUS_TEST_ASSERT(false); return(false); } CDEBUG("testEnumerations rtn" ); return(true);}InteropTest::InteropTest(){ try { _client.connectLocal(); } catch(Exception& e) { cerr <<" Error: " << e.getMessage() << " Conection terminate abnormal" << endl; exit(1); }}InteropTest::~InteropTest(){ _client.disconnect();}/* Get all namespaces and return as an array*/Array<CIMNamespaceName> InteropTest::_getNamespacesOld(){ CIMName className = "__NameSpace"; Array<CIMNamespaceName> namespaceNames; // Build the namespaces incrementally starting at the root // ATTN: 20030319 KS today we start with the "root" directory but this is wrong. We should be // starting with null (no directoyr) but today we get an xml error return in Pegasus // returned for this call. Note that the specification requires that the root namespace be used // when __namespace is defined but does not require that it be the root for allnamespaces. That // is a hole is the spec, not in our code. namespaceNames.append("root"); namespaceNames.append("test"); namespaceNames.append("SDKExamples"); Uint32 start = 0; Uint32 end = namespaceNames.size(); do { // for all new elements in the output array for (Uint32 range = start; range < end; range ++) { // Get the next increment in naming for all a name elements in the array CIMNamespaceName next; if (end != 0) { next = namespaceNames[range];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -