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

📄 tomof.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.////==============================================================================//// Author: Karl Schopmeyer (k.schopmeyer@opengroup.org)//// Modified By: Carol Ann Krug Graves, Hewlett-Packard Company//                (carolann_graves@hp.com)////%/////////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/PegasusAssert.h>#include <Pegasus/Common/CIMValue.h>#include <Pegasus/Common/CIMProperty.h>#include <Pegasus/Common/CIMClass.h>#include <Pegasus/Common/CIMInstance.h>#include <Pegasus/Common/CIMName.h>#include <Pegasus/Common/CIMQualifierDecl.h>#include <Pegasus/Common/XmlWriter.h>#include <Pegasus/Common/MofWriter.h>PEGASUS_USING_PEGASUS;PEGASUS_USING_STD;char * verbose;// Local function to compare created buffer and a result char arraybool resultTest(Buffer& buffer, const char * result){    buffer.append('\0');    if (strcmp(buffer.getData(), result) == 0)    {        return true;    }    else    {        int maxLen = strlen(result);        if (strlen(buffer.getData()) != strlen(result))        {            cout << "Size diff error. str1 len = " << strlen(buffer.getData())                 << " str2 len = " << strlen(result) << endl;        }        cout << "Created Buffer\n<" << buffer.getData() << ">\nTest Result\n<" << result << ">" << endl;        return(false);    }}template<class T>void test01(const T& x, const char* result){    CIMValue v(x);    CIMValue v2(v);    CIMValue v3;    v3 = v2;    Buffer tmp1;    MofWriter::appendValueElement(tmp1, v3);    try    {        T t;        v3.get(t);        PEGASUS_TEST_ASSERT(t == x);    }    catch(Exception& e)    {        cerr << "Error: " << e.getMessage() << endl;        exit(1);    }    PEGASUS_TEST_ASSERT(resultTest(tmp1, result));}// test property generationvoid test03(){    // Test Property mof generation for string property.    {        CIMProperty p1(CIMName ("message"), String("Hi There"));        Buffer tmp;        // Test the mof creation for a class declaration        MofWriter::appendPropertyElement(true, tmp, p1);        const char * declCompare = "\nstring message = \"Hi There\";";        if (verbose)            cout << "Property MOF = " << tmp.getData() << "\n out \n" << declCompare << endl;        PEGASUS_TEST_ASSERT(resultTest(tmp,declCompare));        // Test the mof creation for instance definition        Buffer tmp1;        MofWriter::appendPropertyElement(false, tmp1, p1);        tmp1.append('\0');        const char * instanceCompare = "\nmessage = \"Hi There\";";        PEGASUS_TEST_ASSERT(resultTest(tmp1,instanceCompare));    }    // Test Property mof generation for boolean property.    {        CIMProperty p1(CIMName ("message"), Boolean(true));        Buffer tmp;        // Test the mof creation for a class declaration        MofWriter::appendPropertyElement(true, tmp, p1);        const char * declCompare = "\nboolean message = TRUE;";        PEGASUS_TEST_ASSERT(resultTest(tmp,declCompare));        // Test the mof creation for instance definition        Buffer tmp1;        MofWriter::appendPropertyElement(false, tmp1, p1);        const char * instanceCompare = "\nmessage = TRUE;";        PEGASUS_TEST_ASSERT(resultTest(tmp1,instanceCompare));    }    // Test Property mof generation for Uint32 property.    {        CIMProperty p1(CIMName ("message"), Uint32(9999));        Buffer tmp;        // Test the mof creation for a class declaration        MofWriter::appendPropertyElement(true, tmp, p1);        const char * declCompare = "\nuint32 message = 9999;";        PEGASUS_TEST_ASSERT(resultTest(tmp,declCompare));        // Test the mof creation for instance definition        Buffer tmp1;        MofWriter::appendPropertyElement(false, tmp1, p1);        const char * instanceCompare = "\nmessage = 9999;";        PEGASUS_TEST_ASSERT(resultTest(tmp1,instanceCompare));    }}// test mof generation for Qualifier declaration/*Qualifier flavors are indicated by an optional clause after the qualifierand preceded by a colon.They consist of some combination of the key words EnableOverride,DisableOverride,ToSubclass and Restricted, indicating the applicable propagationand override rules.Handle is designated as writable for the Process class and for every subclass ofthis class.class CIM_Process:CIM_LogicalElement{uint32 Priority;[Write(true):DisableOverride ToSubclass]string Handle;};*/void test04(){    //Qualifier declaration Test    try    {        CIMQualifierDecl qual1(            CIMName ("CIMTYPE"),             String(),            CIMScope::PROPERTY,            CIMFlavor::TOINSTANCE);        //Qualifier Abstract : boolean = false, Scope(class, association,         //indication), Flavor(DisableOverride, Restricted);        CIMQualifierDecl q2(            CIMName ("Abstract"),            true,             CIMScope::CLASS,            CIMFlavor::OVERRIDABLE);        ;        Buffer tmp;        MofWriter::appendQualifierDeclElement(tmp, qual1);        char cimTypeQualifierDecl[] = "\nQualifier CIMTYPE : string = \"\", Scope(property);\n";        PEGASUS_TEST_ASSERT(resultTest(tmp, cimTypeQualifierDecl));        Buffer tmp1;        MofWriter::appendQualifierDeclElement(tmp1, q2);        char cimAbstractQualDecl[] = "\nQualifier Abstract : boolean = TRUE, Scope(class);\n";        PEGASUS_TEST_ASSERT(resultTest(tmp1, cimAbstractQualDecl));    }    catch(Exception& e)    {        cerr << "Exception: " << e.getMessage() << endl;    }}// Test MOF generation of Classes and Instances.void test05(){    // Test CimClass not Association    {        if (verbose)           cout << "Class test\n";    CIMClass class1(CIMName ("MyClass"), CIMName ("YourClass"));    class1        .addQualifier(CIMQualifier(CIMName ("q1"), Uint32(55)))        .addQualifier(CIMQualifier(CIMName ("q2"), String("Hello")))        .addProperty(CIMProperty(CIMName ("message"), String("Hello")))        .addProperty(CIMProperty(CIMName ("count"), Uint32(77)))        .addMethod(CIMMethod(CIMName ("isActive"), CIMTYPE_BOOLEAN)            .addParameter(CIMParameter(CIMName ("hostname"),                     CIMTYPE_STRING))            .addParameter(CIMParameter(CIMName ("port"), CIMTYPE_UINT32)));    if (verbose)        XmlWriter::printClassElement(class1);    Buffer tmp;

⌨️ 快捷键说明

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