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

📄 object.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//%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.////==============================================================================////%/////////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/Config.h>#include <Pegasus/Common/CIMObject.h>#include <Pegasus/Common/CIMClass.h>#include <Pegasus/Common/CIMInstance.h>#include <Pegasus/Common/XmlWriter.h>#include <Pegasus/Common/PegasusAssert.h>PEGASUS_USING_PEGASUS;PEGASUS_USING_STD;static char * verbose = 0;//*********************************************************************//  CIMObject tests////  The CIMObject class refers either to a CIMInstance or a CIMClass.//*********************************************************************void test01(){    CIMObject obj;    //    // Construct from CIMClass    //    CIMClass cimClass1(CIMName ("MyClass"));    cimClass1.setPath(CIMObjectPath ("//localhost/root/cimv2:MyClass"));    CIMObject oclass1 = cimClass1;    CIMObject oclass2(cimClass1);    CIMObject oclass3(oclass2);    CIMObject oclass4 = oclass3;    CIMClass cimClass2 = cimClass1;    cimClass2 = cimClass1;    cimClass2 = CIMClass(oclass1);    CIMClass cimClass3 = CIMClass(oclass1);    PEGASUS_TEST_ASSERT(oclass1.getClassName() == CIMName ("MyClass"));    PEGASUS_TEST_ASSERT(oclass1.getPath() ==         CIMObjectPath("//localhost/root/cimv2:MyClass"));    PEGASUS_TEST_ASSERT (oclass1.isClass ());    PEGASUS_TEST_ASSERT (!oclass1.isInstance ());    PEGASUS_TEST_ASSERT (oclass2.isClass ());    PEGASUS_TEST_ASSERT (!oclass2.isInstance ());    PEGASUS_TEST_ASSERT (oclass3.isClass ());    PEGASUS_TEST_ASSERT (!oclass3.isInstance ());    PEGASUS_TEST_ASSERT (oclass4.isClass ());    PEGASUS_TEST_ASSERT (!oclass4.isInstance ());    //    // Construct from CIMInstance    //    CIMInstance cimInstance1(CIMName ("MyClass"));    CIMObject oinstance1 = cimInstance1;    CIMObject instance2(cimInstance1);    PEGASUS_TEST_ASSERT (oinstance1.isInstance ());    PEGASUS_TEST_ASSERT (!oinstance1.isClass ());    PEGASUS_TEST_ASSERT (instance2.isInstance ());    PEGASUS_TEST_ASSERT (!instance2.isClass ());    // Test qualifiers    oinstance1.addQualifier(CIMQualifier(CIMName ("Key"), true));    oinstance1.addQualifier(CIMQualifier(CIMName ("Description"),        String("Just a Test")));    oinstance1.addQualifier(CIMQualifier(CIMName ("q1"), true));    oinstance1.addQualifier(CIMQualifier(CIMName ("q2"), true));    PEGASUS_TEST_ASSERT(oinstance1.findQualifier(CIMName ("Key"))        != PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(oinstance1.findQualifier(CIMName ("Description"))        != PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(oinstance1.findQualifier(CIMName ("q1"))        != PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(oinstance1.findQualifier(CIMName ("q2"))        != PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(oinstance1.findQualifier(CIMName ("q3"))        == PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(oinstance1.getQualifierCount() == 4);    PEGASUS_TEST_ASSERT(oinstance1.findQualifier(CIMName ("q1"))        != PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(oinstance1.findQualifier(CIMName ("q2"))        != PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(oinstance1.findQualifier(CIMName ("q3"))        == PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(oinstance1.findQualifier(CIMName ("q4"))        == PEG_NOT_FOUND);    Uint32 posQualifier;    posQualifier = oinstance1.findQualifier(CIMName ("q1"));    PEGASUS_TEST_ASSERT(posQualifier != PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(posQualifier < oinstance1.getQualifierCount());    try    {        CIMQualifier q1 = oinstance1.getQualifier(posQualifier);        PEGASUS_TEST_ASSERT(!q1.isUninitialized());        CIMConstQualifier cq1 = oinstance1.getQualifier(posQualifier);        PEGASUS_TEST_ASSERT(!cq1.isUninitialized());                /**            Added to cover the function            CIMConstQualifier CIMObject::getQualifier(Uint32 index) const            in CIMObject.cpp        */        const CIMObject coinstance1 = cimInstance1;        CIMConstQualifier cq2 = coinstance1.getQualifier(0);        PEGASUS_TEST_ASSERT(!cq2.isUninitialized());        /**            Added to cover the function Added to cover the function            CIMConstProperty CIMObject::getProperty(Uint32 index) const            in CIMObject.cpp        */        CIMConstProperty cp1 =  coinstance1.getProperty(0);        PEGASUS_TEST_ASSERT(!cp1.isUninitialized());    }    catch(IndexOutOfBoundsException& e)    {        if(verbose)            cout << "Exception: " << e.getMessage() << endl;    }    oinstance1.removeQualifier(posQualifier);    PEGASUS_TEST_ASSERT(oinstance1.getQualifierCount() == 3);    PEGASUS_TEST_ASSERT(oinstance1.findQualifier(CIMName ("q1"))        == PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(oinstance1.findQualifier(CIMName ("q2"))        != PEG_NOT_FOUND);    // Test properties    oinstance1.addProperty(CIMProperty(CIMName ("message"),        String("Hello There")));    oinstance1.addProperty(CIMProperty(CIMName ("count"), Uint32(77)));    PEGASUS_TEST_ASSERT(oinstance1.findProperty(CIMName ("count"))        != PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(oinstance1.findProperty(CIMName ("message"))        != PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(oinstance1.findProperty(CIMName ("ratio"))        == PEG_NOT_FOUND);    CIMProperty cp =       oinstance1.getProperty(oinstance1.findProperty(CIMName ("message")));    Uint32 posProperty;    posProperty = oinstance1.findProperty(CIMName ("count"));    oinstance1.removeProperty(posProperty);    PEGASUS_TEST_ASSERT(oinstance1.findProperty(CIMName ("count"))        == PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(oinstance1.getPropertyCount() == 1);    const CIMObject oinstance2 = oinstance1.clone();    PEGASUS_TEST_ASSERT(oinstance2.identical(oinstance1));    if (verbose)    {        Buffer xmlOut;        XmlWriter::appendObjectElement(xmlOut, oinstance1);    }}//*********************************************************************//  CIMConstObject tests//*********************************************************************void test02(){    CIMConstObject obj;    //    // Construct from CIMClass    //    CIMClass class1(CIMName ("MyClass"));    class1.setPath(CIMObjectPath ("//localhost/root/cimv2:MyClass"));    //    // Construct from CIMClass    //    CIMObject obj1 = class1;    CIMConstClass cclass1(CIMName ("MyClass"));    CIMConstObject cobj1(class1);    CIMConstObject cobj2(cclass1);    CIMConstObject cobj3(obj1);    /**        Added to cover the constructor and getPath() in CIMClass.cpp    */    CIMConstClass cclass11(obj1);    PEGASUS_TEST_ASSERT( !cclass11.isUninitialized());     cclass11.getPath();    PEGASUS_TEST_ASSERT( cclass11.getPath().toString() ==        "//localhost/root/cimv2:MyClass" );        /**        Added to cover the function CIMConstObject& CIMConstObject::operator=(        const CIMConstObject& x) in CIMObject.cpp    */    const CIMConstObject cobj111(class1);    cobj1=cobj111;    PEGASUS_TEST_ASSERT( cobj1.toString() == cobj111.toString());    /**        Added to cover the function Boolean CIMConstObject::isUninitialized()        const in CIMObject.cpp    */    Boolean result=0;    PEGASUS_TEST_ASSERT( result == cobj1.isUninitialized());    /**        Added to cover the function String CIMConstObject::toString () const        in CIMObject.cpp    */    String result1;    result1 = cobj1.toString();    PEGASUS_TEST_ASSERT( result1 != "<CLASS  NAME=\"MyClass\" ></CLASS>" );        //    // Construct from CIMInstance    //    CIMInstance instance(CIMName ("MyClass"));    CIMObject obj2 = instance;

⌨️ 快捷键说明

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