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

📄 instancedecl.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//%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: Mike Brasher (mbrasher@bmc.com)//// Modified By: Sushma Fernandes (sushma_fernandes@hp.com)//              Carol Ann Krug Graves, Hewlett-Packard Company//                (carolann_graves@hp.com)//              Karl Schopmeyer//              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)////%//////////////////////////////////////////////////////////////////////////////* This program tests the generation and resolution of instances.  It creates   a set of qualifiers and a class and then creates instances of the class   and confirms both the creation characteristics and the resolution   characteristics.*/#include <Pegasus/Common/PegasusAssert.h>#include <Pegasus/Common/CIMInstance.h>#include <Pegasus/Common/CIMClass.h>#include <Pegasus/Common/CIMName.h>#include <Pegasus/Common/DeclContext.h>#include <Pegasus/Common/Resolver.h>#include <Pegasus/Common/XmlWriter.h>PEGASUS_USING_PEGASUS;PEGASUS_USING_STD;static char * verbose;void test01(){    const CIMNamespaceName NAMESPACE = CIMNamespaceName("/zzz");    // Create and populate a declaration context:    SimpleDeclContext* context = new SimpleDeclContext;    context->addQualifierDecl(        NAMESPACE, CIMQualifierDecl(CIMName("counter"), false,        CIMScope::PROPERTY));    context->addQualifierDecl(        NAMESPACE, CIMQualifierDecl(CIMName("classcounter"), false,        CIMScope::CLASS));    context->addQualifierDecl(        NAMESPACE, CIMQualifierDecl(CIMName("min"), String(),        CIMScope::PROPERTY));    context->addQualifierDecl(        NAMESPACE, CIMQualifierDecl(CIMName("max"), String(),        CIMScope::PROPERTY));    context->addQualifierDecl(NAMESPACE,        CIMQualifierDecl(CIMName("Description"), String(),        CIMScope::PROPERTY));    CIMClass class1(CIMName("MyClass"));    class1        .addProperty(CIMProperty(CIMName("count"), Uint32(55))            .addQualifier(CIMQualifier(CIMName("counter"), true))            .addQualifier(CIMQualifier(CIMName("min"), String("0")))            .addQualifier(CIMQualifier(CIMName("max"), String("1"))))        .addProperty(CIMProperty(CIMName("message"), String("Hello"))            .addQualifier(CIMQualifier(CIMName("description"),                String("My Message"))))        .addProperty(CIMProperty(CIMName("ratio"), Real32(1.5)));    // Test    PEGASUS_TEST_ASSERT(class1.findProperty(CIMName("count")) != PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(class1.findProperty(CIMName("message")) != PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(class1.findProperty(CIMName("ratio")) != PEG_NOT_FOUND);    Resolver::resolveClass(class1, context, NAMESPACE);    context->addClass(NAMESPACE, class1);    if (verbose)    {        XmlWriter::printClassElement(class1);    }    CIMInstance instance0(CIMName("MyClass"));    PEGASUS_TEST_ASSERT(instance0.getClassName().equal(CIMName("MyClass")));    instance0.setPath(CIMObjectPath("//localhost/root/cimv2:MyClass.Foo=1"));    PEGASUS_TEST_ASSERT(instance0.getPath() ==        CIMObjectPath("//localhost/root/cimv2:MyClass.Foo=1"));    CIMInstance instance1(CIMName("MyClass"));    instance1.addQualifier(CIMQualifier(CIMName("classcounter"), true));    instance1.addProperty(CIMProperty(CIMName("message"), String("Goodbye")));    PEGASUS_TEST_ASSERT(instance1.findProperty(CIMName("message")) != PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(instance1.findProperty(CIMName("count")) == PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(instance1.findProperty(CIMName("ratio")) == PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(instance1.findProperty(CIMName("nuts")) == PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(instance1.getPropertyCount() == 1);    if (verbose)    {        XmlWriter::printInstanceElement(instance1);    }    Resolver::resolveInstance(instance1, context, NAMESPACE, true);    if (verbose)    {        XmlWriter::printInstanceElement(instance1);    }    // Now test for properties after resolution.    PEGASUS_TEST_ASSERT(instance1.findProperty(CIMName("message")) != PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(instance1.findProperty(CIMName("count")) != PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(instance1.findProperty(CIMName("ratio")) != PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(instance1.findProperty(CIMName("nuts")) == PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(instance1.getPropertyCount() == 3);    // Now remove a property    Uint32 posProperty;    posProperty = instance1.findProperty(CIMName("count"));    instance1.removeProperty(posProperty);    PEGASUS_TEST_ASSERT(instance1.findProperty(CIMName("message")) != PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(instance1.findProperty(CIMName("count")) == PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(instance1.findProperty(CIMName("ratio")) != PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(instance1.findProperty(CIMName("nuts")) == PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(instance1.getPropertyCount() == 2);    // Instance qualifier tests    CIMQualifier cq=instance1.getQualifier(instance1.findQualifier(        CIMName("classcounter")));    const CIMInstance instance2 = instance1.clone();    PEGASUS_TEST_ASSERT(instance2.identical(instance1));    PEGASUS_TEST_ASSERT(instance1.findQualifier(CIMName("nuts")) == PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(instance2.findQualifier(CIMName("nuts")) == PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(instance1.getQualifierCount() != 4);    PEGASUS_TEST_ASSERT(instance1.getQualifierCount() == 1);    PEGASUS_TEST_ASSERT(instance2.getQualifierCount() == 1);    if (verbose)    {        XmlWriter::printInstanceElement(instance2);    }    // Tests for CIMConstInstance    CIMConstInstance cinstance1(CIMName("MyClass")), cinstance3;    CIMConstInstance ccopy(cinstance1);    cinstance1 = instance1;    PEGASUS_TEST_ASSERT(cinstance1.identical(instance1));    PEGASUS_TEST_ASSERT(cinstance1.getQualifierCount() == 1);    CIMConstQualifier ccq = cinstance1.getQualifier(cinstance1.findQualifier(        CIMName("classcounter")));    PEGASUS_TEST_ASSERT(cinstance1.findProperty(CIMName("message")) != PEG_NOT_FOUND);    CIMConstProperty ccp =        cinstance1.getProperty(cinstance1.findProperty(CIMName("message")));    cinstance3 = cinstance1;    PEGASUS_TEST_ASSERT(cinstance3.identical(cinstance1));    PEGASUS_TEST_ASSERT(cinstance1.getClassName() == CIMName("MyClass"));    PEGASUS_TEST_ASSERT(cinstance1.getClassName().equal(CIMName("MyClass")));    PEGASUS_TEST_ASSERT(cinstance1.getClassName().equal(CIMName("MYCLASS")));    PEGASUS_TEST_ASSERT(cinstance1.getClassName().equal(CIMName("myclass")));    PEGASUS_TEST_ASSERT(!cinstance1.getClassName().equal(CIMName("blob")));    PEGASUS_TEST_ASSERT(cinstance1.getQualifierCount() != 4);    PEGASUS_TEST_ASSERT(cinstance1.getPropertyCount() == 2);    CIMConstInstance cinstance2 = cinstance1.clone();    PEGASUS_TEST_ASSERT(cinstance2.identical(cinstance1));    if (verbose)    {        XmlWriter::printInstanceElement(cinstance1);    }    cinstance1.buildPath(class1);    PEGASUS_TEST_ASSERT( !cinstance1.isUninitialized() );    delete context;}void test02(){    const CIMNamespaceName NAMESPACE = CIMNamespaceName("/zzz");    CIMClass cimClass(CIMName("MyClass"));    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"), String())            .addQualifier(CIMQualifier(CIMName("key"), true)));    CIMInstance cimInstance(CIMName("MyClass"));    cimInstance.addProperty(CIMProperty(CIMName("first"), String("John")));    cimInstance.addProperty(CIMProperty(CIMName("last"), String("Smith")));    cimInstance.addProperty(CIMProperty(CIMName("age"), Uint8(101)));    PEGASUS_TEST_ASSERT(cimInstance.findProperty(CIMName("first")) != PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(cimInstance.findProperty(CIMName("last")) != PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(cimInstance.findProperty(CIMName("age")) != PEG_NOT_FOUND);    PEGASUS_TEST_ASSERT(cimInstance.getPropertyCount() == 3);    CIMObjectPath instanceName =        cimInstance.buildPath(CIMConstClass(cimClass));    CIMObjectPath tmp("myclass.age=101,first=\"John\",last=\"Smith\"");    PEGASUS_TEST_ASSERT(tmp.makeHashCode() == instanceName.makeHashCode());    // Test CIMInstance::buildPath with incomplete keys in the instance    Boolean caughtNoSuchPropertyException = false;    try    {        CIMInstance badInstance(CIMName("MyClass"));        badInstance.addProperty(CIMProperty(CIMName("first"), String("John")));        badInstance.addProperty(CIMProperty(CIMName("last"), String("Smith")));        CIMObjectPath instanceName =            badInstance.buildPath(CIMConstClass(cimClass));    }    catch (const NoSuchProperty&)    {        caughtNoSuchPropertyException = true;    }    PEGASUS_TEST_ASSERT(caughtNoSuchPropertyException);}// Build the instance of an association class and test the build path functions.void test03(){    const CIMNamespaceName NAMESPACE = CIMNamespaceName("/zzz");    CIMClass myPersonClass(CIMName("MY_PersonClass"));    myPersonClass        .addProperty(CIMProperty(CIMName("name"), String())            .addQualifier(CIMQualifier(CIMName("Key"), true)));    CIMClass myAssocClass(CIMName("MY_AssocClass"));    myAssocClass        .addQualifier(CIMQualifier(CIMName("association"), true))        .addProperty(CIMProperty(CIMName("parent"), CIMObjectPath(), 0,            CIMName("MY_PersonClass"))            .addQualifier(CIMQualifier(CIMName("key"), true)))        .addProperty(CIMProperty(CIMName("child"), CIMObjectPath(), 0,            CIMName("MY_PersonClass"))            .addQualifier(CIMQualifier(CIMName("key"), true)))        .addProperty(CIMProperty(CIMName("Age"), String()));    CIMInstance fatherInstance(CIMName("MY_PersonClass"));    fatherInstance        .addProperty(CIMProperty(CIMName("name"), String("father")));

⌨️ 快捷键说明

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