⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 interop.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//%2006//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation, The Open Group.// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; Symantec Corporation; The Open Group.//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions:// // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.////==============================================================================//// Author: Karl Schopmeyer (k.schopmeyer@opengroup.org)//// Modified By://      David Dillard, VERITAS Software Corp.(david.dillard@veritas.com)//      Chip Vincent (cvincent@us.ibm.com)//      Aruran, IBM(aruran.shanmug@in.ibm.com) for Bug# 4846////%/////////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/Config.h>#include <Pegasus/Common/Constants.h>#include <Pegasus/Common/PegasusVersion.h>#include <Pegasus/Common/PegasusAssert.h>#include <Pegasus/Common/TLS.h>#include <Pegasus/Client/CIMClient.h>#include <Pegasus/Common/CIMName.h>#include <Pegasus/Common/OptionManager.h>#include <Pegasus/Common/FileSystem.h>#include <Pegasus/Common/Exception.h>#include <Pegasus/Common/XmlWriter.h>#include <Pegasus/Config/ConfigManager.h>#include <Pegasus/Common/Tracer.h>/* This is a test program for the Interop Control Provider.  It provides tests for thefunctions in this provider including;    The CIM_ObjectManager Class and its single instance    The CIM_CommunicationsMechanism class and its PG subclass.    The CIM_Namespace Class*/PEGASUS_USING_PEGASUS;PEGASUS_USING_STD;// Macro puts out message and then does assert error out.#define TERMINATE(X) {PEGASUS_STD(cout) << "TestInterop " << X << PEGASUS_STD(endl); PEGASUS_TEST_ASSERT(false);}#define CDEBUG(X)//#define CDEBUG(X) PEGASUS_STD(cout) << "InteropTest(" << __LINE__ << ")" << X << PEGASUS_STD(endl)#include <cstring>#include <stdcxx/stream/strstream>/* Test the namespace manipulation functions.Creates, deletes, queries namespaces using both the__Namespace and CIM_Namespace functions*/char * pgmName;char * verbose;static const CIMNamespaceName __NAMESPACE_NAMESPACE = CIMNamespaceName ("root");static const char programVersion[] =  "1.0";// Property Names for __Namespace Classstatic const CIMName NAMESPACE_PROPERTYNAME  = CIMName ("Name");static const CIMNamespaceName ROOTNS  = CIMNamespaceName ("root");static const CIMName __NAMESPACE_CLASSNAME  = CIMName ("__Namespace");static const CIMName CIM_NAMESPACE_CLASSNAME  = CIMName ("CIM_Namespace");static const CIMName PG_NAMESPACE_CLASSNAME  = CIMName ("PG_Namespace");static const CIMName CIM_OBJECTMANAGER_CLASSNAME  = CIMName ("CIM_ObjectManager");static const CIMName CIM_WBEMSERVICE_CLASSNAME  = CIMName ("CIM_WBEMService");static const CIMName CIM_OBJECTMANAGERCOMMUNICATIONMECHANISM_CLASSNAME  =        CIMName ("CIM_ObjectManagerCommunicationMechanism");static const CIMName PG_CIMXMLCOMMUNICATIONMECHANISM_CLASSNAME  =        CIMName ("PG_CIMXMLCommunicationMechanism");static const CIMName CIM_CIMXMLCOMMUNICATIONMECHANISM_CLASSNAME  =        CIMName ("CIM_CIMXMLCommunicationMechanism");static const CIMName CIM_COMMMECHANISMFORMANAGER_CLASSNAME  =        CIMName ("CIM_CommMechanismForManager");static const CIMName CIM_NAMESPACEINMANAGER_CLASSNAME  =        CIMName ("CIM_NamespaceInManager");String _toString(Boolean x){    return(x ? "true" : "false");} /* local support for display of propertyLists. Converts a property list   to a String for display. This function is only for diagnostic support.   Assumes that there is a propertylist and it is not empty or null.   @param pl CIMPropertyList to convert.   @return String representation of property list for display.*/String _toStringPropertyList(const CIMPropertyList& pl){    String tmp;    for (Uint32 i = 0; i < pl.size() ; i++)    {        if (i > 0)            tmp.append(", ");        tmp.append(pl[i].getString());    }    return(tmp);}String _showPathArray(Array<CIMObjectPath>& p){    String rtn;    for (Uint32 i = 0 ; i < p.size() ; i++)    {        if (i > 0)            rtn.append("\n");        rtn.append(p[i].toString());    }    return(rtn);}/* _showPropertyList is local support for displaying the propertylist   For display only. Generates String with property list names   or "empty" or "NULL" if that is the case.   @param pl CIMPropertyList to convert   @return String containing the list of properties comma separated   or the keywords NULL or Empty. */String _showPropertyList(const CIMPropertyList& pl){    if (pl.isNull())        return("NULL");    return((pl.size() == 0) ? String("EMPTY") : _toStringPropertyList(pl));}/** Check to see if the specified path is in the path list    @param CIMObjectPath which is target for search    @param Array of CIMObjectPaths to be searched    @return true if the path is in the list otherwise false.*/Boolean _containsObjectPath(const CIMObjectPath& path,     const Array<CIMObjectPath>& pathList){    for (Uint32 p = 0; p < pathList.size(); p++)    {        if (pathList[p].identical(path))            return true;    }    return false;}Boolean _checkExceptionCode    (const CIMException & e,     const CIMStatusCode expectedCode){    if (verbose)    {        if (e.getCode () != expectedCode)        {            cerr << "CIMException comparison failed.  ";            cerr << "Expected " << cimStatusCodeToString (expectedCode) << "; ";            cerr << "Actual exception was " << e.getMessage () << "." << endl;        }    }    if (e.getCode () == expectedCode)        return(true);    else        return(false);}/* Class created to provide cover for all of the tests in this    test program.*/class InteropTest{public:    //InteropTest();    InteropTest();    ~InteropTest();    // Methods associated with Namespace testing    Array<CIMNamespaceName> _getNamespacesOld();    Boolean _deleteOneLevelOfNamespace(        const CIMNamespaceName& parent,        const String & child);    Boolean _deleteNamespaceOld(const String & name);    Boolean _validateNamespaces(        Array<CIMNamespaceName>& namespaceNames);    Array<CIMInstance> _getCIMNamespaceInstances();    Array<CIMInstance> _getPGNamespaceInstances();    Array<CIMObjectPath> _getCIMNamespaceInstanceNames();    Array<CIMObjectPath> _getPGNamespaceInstanceNames();    Array<CIMNamespaceName> _getNamespacesNew();    void _showNamespaceInfo(const String& title);    Boolean _existsNew(const CIMNamespaceName& name);    Boolean _namespaceCreate__Namespace(                            const CIMNamespaceName& parent,                            const String& child);    Boolean _namespaceCreatePG_Namespace(const CIMNamespaceName& name);    Boolean _namespaceCreateCIM_Namespace(const CIMNamespaceName& name,                            const CIMNamespaceName& targetNamespace);    Boolean _testPGNamespace(const CIMNamespaceName& name,                            Boolean shared,                            Boolean updatesAllowed,                            const String& parent);    Boolean _namespaceCreatePG_Namespace(const CIMNamespaceName& name,                            const Boolean shareable,                            const Boolean updatesAllowed,                            const String& parent);    Boolean _namespaceDeleteCIM_Namespace(const CIMNamespaceName& name);    Boolean testClassExists(const CIMName & className);    // Methods associated with overall testing    void testNameSpacesManagement();    void testSharedNameSpacesManagement();    CIMInstance getInstanceObjMgr();    CIMObjectPath getObjMgrPath();    void testObjectManagerClass();    void setStatisticsState(const Boolean flag);    Boolean testStatisticsSetOperationError(            const CIMInstance & instance,            const CIMPropertyList& list,            Boolean shouldRespondGood,            Boolean includeQualifiers,            const CIMStatusCode expectedCode);    Boolean getStatisticsPropertyState(            CIMInstance & objMgrInstance);    String getCurrentConfigProperty(            const CIMName& propName);    Boolean getCurrentBoolConfigProperty(            const CIMName& propName);    Uint32 getCurrentValueConfigProperty(           const CIMName& propName);    Boolean getStatisticsState();    void showStatisticsState();    void testStatisticsEnable();    void testCommunicationClass();    void testNameSpaceInObjectManagerAssocClass();    void testCommMechinManagerAssocClass();    Boolean testEnumerateOptions(        const CIMName& className,        Boolean localOnly,        Boolean deepInheritance,        const CIMPropertyList propertyList,        const Uint32 expectedPropertyCount);    // Methods associated with general instance testing    Boolean matchPathsAndInstancePaths(        Array<CIMObjectPath>& paths,         const Array<CIMInstance> instances);    // Methods associated with general instance testing    Boolean matchPathsAndObjectPaths(        Array<CIMObjectPath>& paths,         const Array<CIMObject> instanceObjectss);    Boolean testGetInstancesForEnum(        const Array<CIMObjectPath>& paths,         const Array<CIMInstance>& instances,        const Boolean localOnly,        const Boolean includeQualifiers,        const Boolean includeClassOrigin,        const CIMPropertyList& propertyList);    Boolean testEnumAgainstEnumNames(        const CIMNamespaceName& nameSpace,        const CIMName& className);private:CIMClient _client;CIMInstance objectManagerInstance;};/**    Get property values for the specified configuration property from    the CIM Server.*/static const CIMName PROPERTY_NAME  = CIMName ("PropertyName");String InteropTest::getCurrentConfigProperty(    const CIMName& propertyName) {    // The following assumes localconnect.    String _hostName;    _hostName.assign(System::getHostName());    CIMProperty prop;    Array<CIMKeyBinding> kbArray;    CIMKeyBinding kb;    kb.setName(PROPERTY_NAME);    kb.setValue(propertyName.getString());    kb.setType(CIMKeyBinding::STRING);    kbArray.append(kb);    String propertyNameValue;    String currentValue;    //String defaultValue;    //String plannedValue;    try    {        CIMObjectPath reference(            _hostName, PEGASUS_NAMESPACENAME_CONFIG,            PEGASUS_CLASSNAME_CONFIGSETTING, kbArray);        CIMInstance cimInstance =            _client.getInstance(PEGASUS_NAMESPACENAME_CONFIG, reference);        Uint32 pos = cimInstance.findProperty(PROPERTY_NAME);        prop = (CIMProperty)cimInstance.getProperty(pos);        propertyNameValue = prop.getValue().toString();        pos = cimInstance.findProperty(CIMName ("CurrentValue"));        prop = (CIMProperty)cimInstance.getProperty(pos);        currentValue = prop.getValue().toString();        //pos = cimInstance.findProperty(CIMName ("DefaultValue"));        //prop = (CIMProperty)cimInstance.getProperty(pos);        //defaultValue = prop.getValue().toString();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -