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

📄 interop.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    options for shareable, updatesAllowed, and parent.  This allows testing    of creation of shared namespaces*/Boolean InteropTest::_namespaceCreatePG_Namespace(const CIMNamespaceName& name,    const Boolean shareable, const Boolean updatesAllowed, const String& parent){    // Does this namespace exist.    if (_existsNew(name))    {        cout << "Namespace " << name.getString() <<             " already Exists in _namespacCreatePG_Namespace function." << endl;        return(false);    }    //Now build the new namespace name instance.  Note that we need to get the    // collection of keys that are required. Easy way was to simply    // use an existing instance and change the name field.    Array<CIMInstance> instances = _getPGNamespaceInstances();    if(instances.size() == 0)    {        return(false);    }    CIMClass thisClass = _client.getClass(PEGASUS_NAMESPACENAME_INTEROP,                                        PG_NAMESPACE_CLASSNAME,                                        false,true,true);    CIMInstance instance = thisClass.buildInstance(true, false, CIMPropertyList());    // Modify the name property value for new name    Uint32 pos = instance.findProperty(NAMESPACE_PROPERTYNAME);    if (pos == PEG_NOT_FOUND)    {            cerr << "Error in property on create. No "                <<  NAMESPACE_PROPERTYNAME << " property" << endl;            return(false);    }    // Modify the name field in the instance    String localName = name.getString();    CIMProperty p = instance.getProperty(pos);    p.setValue(localName);    instance.removeProperty(pos);    instance.addProperty(p);    // Set the sharable, updates allowed, parent properties.    pos = instance.findProperty("SchemaUpdatesAllowed");    if (pos == PEG_NOT_FOUND)    {         cerr << "Error in property on create. No "             <<  "SchemaUpdatesAllowed" << " property" << endl;         return(false);    }    // Modify the field in the instance    String localName1 = name.getString();    CIMProperty p1 = instance.getProperty(pos);    p1.setValue(updatesAllowed);    instance.removeProperty(pos);    instance.addProperty(p1);    // Set the sharable, updates allowed, parent properties.    pos = instance.findProperty("IsShareable");    if (pos == PEG_NOT_FOUND)    {         cerr << "Error in property on create. No "             <<  "IsShareable" << " property" << endl;         return(false);    }    // Modify the field in the instance    String localName2 = name.getString();    CIMProperty p2 = instance.getProperty(pos);    p1.setValue(shareable);    instance.removeProperty(pos);    instance.addProperty(p2);    CDEBUG("Creating instance for " << localName << " in namespace " << PEGASUS_NAMESPACENAME_INTEROP);    if (verbose)    {        cout << "Show instance used to do namespace create: " << endl;        XmlWriter::printInstanceElement(instance);    }    try    {           CIMObjectPath path;           path = _client.createInstance(PEGASUS_NAMESPACENAME_INTEROP, instance);    }    catch(Exception& e)    {        cerr << "Error during Creation of " << name.getString()             << ": " << e.getMessage()            << " Instance Creation error" << endl;        return(false);    }    return(true);}Boolean InteropTest::_namespaceDeleteCIM_Namespace(const CIMNamespaceName& name){    // If does not exist, don't try to delete    if (!_existsNew(name))        return(false);    // Get this instancepath from the whole set.    Array<CIMObjectPath> paths = _getCIMNamespaceInstanceNames();    // find the entry with the correct key    Boolean found = false;    Uint32 i;    for (i = 0; i < paths.size() ; i++)    {        String n = _getKeyValue(paths[i], NAMESPACE_PROPERTYNAME);        if (n == name.getString())        {            found = true;            break;        }    }    // This should not happen since we found it at top of this function    if (!found)    {        cerr << "Namespace " << name.getString() << " not found" << endl;        return(false);    }    // Delete the namespace    try    {        _client.deleteInstance(PEGASUS_NAMESPACENAME_INTEROP, paths[i]);    }    catch(Exception& e)    {        cerr << "Error: " << e.getMessage()            << " Instance deletion error  for " << name.getString() << endl;        // Instead of this returns emptyexit(1);        return(false);    }    return(true);}Boolean InteropTest::testClassExists(const CIMName & className){    try    {        CIMClass thisClass = _client.getClass(PEGASUS_NAMESPACENAME_INTEROP,                                            className,                                            false,true,true);        return(true);    }    catch(Exception& e)    {        cerr << "Error: " << e.getMessage() << " Class " << className.getString()            << " does not exist in Namespace " << PEGASUS_NAMESPACENAME_INTEROP.getString() << endl;    }    return(false);}/* Execute the tests to assure that the namespace manager works and   that the results match what is returned from the __Namespace manager*/void InteropTest::testNameSpacesManagement(){    // Test for required classes to assure that the interop provider and    // its corresponding classes exist.    PEGASUS_TEST_ASSERT(testClassExists(CIM_NAMESPACE_CLASSNAME));    PEGASUS_TEST_ASSERT(testClassExists(PG_NAMESPACE_CLASSNAME));    PEGASUS_TEST_ASSERT(testClassExists(CIM_OBJECTMANAGER_CLASSNAME));    PEGASUS_TEST_ASSERT(testClassExists(CIM_OBJECTMANAGERCOMMUNICATIONMECHANISM_CLASSNAME));    PEGASUS_TEST_ASSERT(testClassExists(PG_CIMXMLCOMMUNICATIONMECHANISM_CLASSNAME));    PEGASUS_TEST_ASSERT(testClassExists(CIM_COMMMECHANISMFORMANAGER_CLASSNAME));    // Test namespace usage with both __namespace and CIM_Namespace.    // __namespace is called old    // CIM_Namespace is called new for these tests.    Array<CIMNamespaceName> nameListOld = _getNamespacesOld();    CDEBUG("Got Namespaces with __Namespace. Now Validate");    if (!_validateNamespaces(nameListOld))    {        cout << "Error exit, Invalid namespace returned" << endl;    }    Array<CIMNamespaceName> nameListNew;    nameListNew = _getNamespacesNew();    CDEBUG("Got Namespaces with CIM_Namespace. Now Validate");    if (!_validateNamespaces(nameListNew))    {        cout << "Error exit, Invalid namespace returned" << endl;    }    BubbleSort(nameListNew);    BubbleSort(nameListOld);    if(verbose) {        _showNamespaceList(nameListNew, "Using CIM_Namespace");        _showNamespaceList(nameListOld, "Using __Namespace");    }    PEGASUS_TEST_ASSERT(nameListNew.size() == nameListOld.size());    // Add assertion that they have the same items in the list    for (Uint32 i = 0 ; i < nameListNew.size() ; i++)     {        PEGASUS_TEST_ASSERT(nameListNew[i] == nameListOld[i]);    }    // Create a new namespace with new functions    CIMNamespaceName testNameNew = CIMNamespaceName("root/junk/interoptest/newtype");    CIMNamespaceName testNameOldRoot = CIMNamespaceName("root");    CIMNamespaceName testNameOldTail = CIMNamespaceName("junk/interoptest/oldtype");    CIMNamespaceName testNameOldComplete = CIMNamespaceName("root/junk/interoptest/oldtype");    // Create the namespace with the PG_Namespace class    // Note that this is an assertion and, in fact, we should probably remove the names    // to clean up the repository after the test. If they do exist here. TODO    // Clean up the names we will use just to be sure.    if (_existsNew(testNameNew)) {        _namespaceDeleteCIM_Namespace(testNameNew);    }    if (_existsNew(testNameOldComplete)) {        _namespaceDeleteCIM_Namespace(testNameOldComplete);    }    PEGASUS_TEST_ASSERT( ! _existsNew(testNameNew));    PEGASUS_TEST_ASSERT( ! _existsNew(testNameOldComplete));    CDEBUG("Create New Namespace with PG_Namespace. Namespace name = " << testNameNew.getString() << ".");    _namespaceCreatePG_Namespace(CIMNamespaceName(testNameNew));    if (verbose)    {        _showNamespaceList(nameListNew, "CIM_Namespace response after add. with PG_Namespace");    }    CDEBUG("Test for namespace created. Name = " << testNameNew.getString());    PEGASUS_TEST_ASSERT(_existsNew(testNameNew));    PEGASUS_TEST_ASSERT(_namespaceDeleteCIM_Namespace(CIMNamespaceName(testNameNew)));    CDEBUG("Test for Namespace existing = " << testNameOldComplete.getString());    if(_existsNew(CIMNamespaceName(testNameOldComplete)))       _namespaceDeleteCIM_Namespace(CIMNamespaceName(testNameOldComplete));    CDEBUG("Test for Namespace NOT existing = " << testNameOldComplete.getString());    if(_existsNew(testNameOldComplete))        cerr << "Problem deleting namespace" << testNameOldComplete.getString() <<endl;    //    // Repeat the creation/deletion test with the CIM_Namespace class.    //    PEGASUS_TEST_ASSERT( ! _existsNew(testNameNew));    CDEBUG("Now Create New Namespace with CIM_Namespace. Namespace name = " << testNameNew.getString() << ".");    PEGASUS_TEST_ASSERT(_namespaceCreateCIM_Namespace(CIMNamespaceName(testNameNew), PEGASUS_NAMESPACENAME_INTEROP));    if (verbose)        _showNamespaceList(nameListNew, "CIM_Namespace response after add. with PG_Namespace");    CDEBUG("Test for namespace created. Name = " << testNameNew.getString());    PEGASUS_TEST_ASSERT(_existsNew(testNameNew));    PEGASUS_TEST_ASSERT(_namespaceDeleteCIM_Namespace(CIMNamespaceName(testNameNew)));    PEGASUS_TEST_ASSERT( ! _existsNew(testNameNew));    //    // Create namespace with __Namespace    //    CDEBUG("Creating with __Namespace appending " << testNameOldTail.getString() << " to " << testNameOldRoot.getString());    _namespaceCreate__Namespace(CIMNamespaceName(testNameOldRoot), String(testNameOldTail.getString()));    PEGASUS_TEST_ASSERT(_existsNew(testNameOldComplete));    PEGASUS_TEST_ASSERT(_namespaceDeleteCIM_Namespace(CIMNamespaceName(testNameOldComplete)));    PEGASUS_TEST_ASSERT(!_existsNew(testNameOldComplete));    if (verbose)    {        _showNamespaceList(nameListNew, "Namespaces From CIM_Namespace after add.");    }    _namespaceCreate__Namespace(CIMNamespaceName(testNameOldRoot), String(testNameOldTail.getString()));    // Note that this tries to delete the multiple levels all at the same time.    // ATTN: There is apparently a problem here with the following    // delete.  Fix this and retest.  For the moment, we substituted    // Deleting the new way.    //_deleteNamespaceOld(String(testNameOldComplete.getString()));    _namespaceDeleteCIM_Namespace(testNameOldComplete);    if (verbose)    {        _showNamespaceList(nameListNew, "CIM_Namespace response after add.");    }    PEGASUS_TEST_ASSERT(!_existsNew(testNameOldComplete));    if(_existsNew(CIMNamespaceName(testNameOldComplete)))       _namespaceDeleteCIM_Namespace(CIMNamespaceName(testNameOldComplete));    if(_existsNew(CIMNamespaceName(testNameOldComplete)))        cerr << "Problem deleting namespace" << endl;    //    // Test to be sure we cannot create new namespaces anywhere but in the    // Interop namespace    //    Array<CIMNamespaceName> namespaceList = _getNamespacesNew();    for (Uint32 i = 0 ; i < namespaceList.size() ; i++)    {        // The get class test is here simply as a means to assure that no         // instances exist in the any namespace except the interop namespace        if (!(namespaceList[i] == PEGASUS_NAMESPACENAME_INTEROP))         {            // Error if we can successfully create namespace.            if (_namespaceCreateCIM_Namespace(CIMNamespaceName(testNameNew), namespaceList[i]))            {                cout << "Error, Created new CIM_Namespace " << testNameNew.getString()                     << " instance in " << namespaceList[i].getString() << endl;                TERMINATE("Failed test by creating new namespace outside of Interop namespace");            }        }    }    // Test to be sure that we have the same count of namespaces    //as when we started.  Should also check to be sure it is exactly the    //same set of namespaces.    Array<CIMNamespaceName> finalNamespaceList = _getNamespacesNew();    if (finalNamespaceList.size() !=  nameListNew.size())    {        BubbleSort(finalNamespaceList);        BubbleSort(nameListNew);        _showNamespaceList(nameListNew, " Namespaces Before Namespace test");        _showNamespaceList(finalNamespaceList, " Namespaces After Namespace test");        TERMINATE("Error. Did not clean all namespaces");    }    if (verbose)        cout << "Basic Namespace Tests passed" << endl;}//****************************************************************// Test characteristics of shared namespaces.//***************************************************************void InteropTest::testSharedNameSpacesManagement(){    try    {        Array<CIMNamespaceName> nameListBefore = _getNamespacesNew();        // We will add the following new namespaces        CIMNamespaceName testNameSharable = CIMNamespaceName("root/junk/interoptest/sharable");        CIMNamespaceName testNameShared = CIMNamespaceName("root/junk/interoptest/shared");        CIMNamespaceName testNameNotShared = CIMNamespaceName("root/junk/interoptest/notshared");        // Create a sharable namespace        _namespaceCreatePG_Namespace(testNameSharable, true, false, String::EMPTY);        // create a namespace with the previous sharable as parent.        _namespaceCreatePG_Namespace(testNameShared,

⌨️ 快捷键说明

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