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

📄 value.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: Mike Brasher (mbrasher@bmc.com)//// Modified By: Jenny Yu, Hewlett-Packard Company (jenny_yu@hp.com)//              Karl Schopmeyer (k.schopmeyer@opengroup.org)//                  20 Feb 2002 - Add tests for new constructor and extend array tests//              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)//              Carol Ann Krug Graves, Hewlett-Packard Company//                  (carolann_graves@hp.com)//              Dave Sudlik, IBM (dsudlik@us.ibm.com)//              David Dillard, VERITAS Software Corp.//                  (david.dillard@veritas.com)//              Vijay Eli, IBM (vijayeli@in.ibm.com) for bug#3101//              Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) for bug#3290////%//////////////////////////////////////////////////////////////////////////////*    This test module tests the functions associated with CIMvalue.    Feb 2k - Expanded to include isNULL tests and tests of NULL CIMValues*//* ATTN: P3 KS feb 2002 tests to do    Test for array size    Test that a !isnull and an is null are not equal    Test that arrays of different size are not equal, etc.*/#include <Pegasus/Common/PegasusAssert.h>#include <Pegasus/Common/CIMValue.h>#include <Pegasus/Common/DeclContext.h>#include <Pegasus/Common/Resolver.h>#include <Pegasus/Common/XmlWriter.h>#include <Pegasus/Common/MofWriter.h>PEGASUS_USING_PEGASUS;PEGASUS_USING_STD;/* The following define is used to control displays of output from the    test.  Comment out the define to turn off the large quantity of prinout.    Added the verbose variable which comes from an environment variable.    IO occurs onlly when the environment variable is set.*/#define IO 1char * verbose;/* This template provides a complete set of tests of simple CIMValues for    the different possible data types.  It tests creating, assigning,    the equals, creating XML and MOF, and the functions associated with    clearing testing for the null attribute.*/template<class T>void test01(const T& x){    CIMValue v(x);    CIMValue v2(v);    CIMValue v3;    // Create a null constructor    CIMType type = v.getType();            // get the type of v    CIMValue v4(type,false);    v3 = v2;    CIMValue v5;    v5 = v4;#ifdef IO    if (verbose)    {	cout << "\n----------------------\n";	XmlWriter::printValueElement(v3, cout);    }#endif    try    {        T t;        v3.get(t);        PEGASUS_TEST_ASSERT (!v.isNull());        PEGASUS_TEST_ASSERT (!v.isArray());        PEGASUS_TEST_ASSERT (!v2.isNull());        PEGASUS_TEST_ASSERT(t == x);        PEGASUS_TEST_ASSERT (v3.typeCompatible(v2));        // Confirm that the constructor created Null, not array and correct type        PEGASUS_TEST_ASSERT (v4.isNull());        PEGASUS_TEST_ASSERT (!v4.isArray());        PEGASUS_TEST_ASSERT (v4.typeCompatible(v));        PEGASUS_TEST_ASSERT (v5.isNull());        PEGASUS_TEST_ASSERT (!v5.isArray());        PEGASUS_TEST_ASSERT (v5.typeCompatible(v));        // Test toMof        Buffer mofout;        mofout.clear();        MofWriter::appendValueElement(mofout, v);        mofout.append('\0');        // Test toXml        Buffer out;        XmlWriter::appendValueElement(out, v);        XmlWriter::appendValueElement(out, v);        // Test toString        String valueString = v.toString();#ifdef IO        if (verbose)        {            cout << "MOF = [" << mofout.getData() << "]" << endl;            cout << "toString Output [" << valueString << "]" << endl;        }#endif    // There should be no exceptions to this point in the test.    }    catch(Exception& e)    {        cerr << "Error: " << e.getMessage() << endl;        exit(1);    }    // From here forward, in the future we may have exceptions because    // of the isNull which should generate an exception on the getdata.    // ATTN: KS 12 Feb 2002 This is work in progress until we complete    // adding the exception return to the CIMValue get functions.    try    {        // Test for isNull and the setNullValue function        CIMType type = v.getType();        v.setNullValue(type, false);        PEGASUS_TEST_ASSERT(v.isNull());        // get the String and XML outputs for v        String valueString2 = v.toString();        Buffer xmlBuffer;        XmlWriter::appendValueElement(xmlBuffer, v);        xmlBuffer.append('\0');        Buffer mofOutput2;        MofWriter::appendValueElement(mofOutput2, v);        mofOutput2.append('\0');#ifdef IO        if (verbose)        {            cout << "MOF NULL = [" << mofOutput2.getData() << "]" << endl;            cout << "toString NULL Output [" << valueString2 << "]" << endl;            cout << " XML NULL = [" << xmlBuffer.getData() << "]" << endl;        }#endif        v.clear();        PEGASUS_TEST_ASSERT(v.isNull());        //v2.clear();        //PEGASUS_TEST_ASSERT(v2.isNull();    }    catch(Exception& e)    {        cerr << "Error: " << e.getMessage() << endl;        exit(1);    }}/* This template defines the set of tests used for arrays*/template<class T>void test02(const Array<T>& x){    CIMValue va(x);    CIMValue va2(va);    CIMValue va3;    va3 = va2;    // Create a null constructor    CIMType type = va.getType();            // get the type of v    CIMValue va4(type,true);    CIMValue va5;    va5 = va4;#ifdef IO    if (verbose)    {        cout << "\n----------------------\n";        XmlWriter::printValueElement(va3, cout);    }#endif        try    {        Array<T> t;        va3.get(t);        PEGASUS_TEST_ASSERT(t == x);        PEGASUS_TEST_ASSERT (va3.typeCompatible(va2));        PEGASUS_TEST_ASSERT (!va.isNull());        PEGASUS_TEST_ASSERT (va.isArray());        PEGASUS_TEST_ASSERT (!va2.isNull());        PEGASUS_TEST_ASSERT (va2.isArray());        PEGASUS_TEST_ASSERT (!va3.isNull());        PEGASUS_TEST_ASSERT (va3.isArray());        // Note that this test depends on what is built.  Everything has 2 entries.        PEGASUS_TEST_ASSERT (va.getArraySize() == 3);        // Confirm that va4 (and va5) is Null, and array and zero length        PEGASUS_TEST_ASSERT (va4.isNull());        PEGASUS_TEST_ASSERT (va4.isArray());        PEGASUS_TEST_ASSERT (va4.getArraySize() == 0);        PEGASUS_TEST_ASSERT (va4.typeCompatible(va));        PEGASUS_TEST_ASSERT (va5.isNull());        PEGASUS_TEST_ASSERT (va5.isArray());        PEGASUS_TEST_ASSERT (va5.getArraySize() == 0);        PEGASUS_TEST_ASSERT (va5.typeCompatible(va));        // Test toMof        Buffer mofOutput;        MofWriter::appendValueElement(mofOutput, va);        mofOutput.append('\0');        // Test toXml        Buffer out;        XmlWriter::appendValueElement(out, va);        XmlWriter::appendValueElement(out, va);        // Test toString        String valueString = va.toString();#ifdef IO        if (verbose)        {            cout << "MOF = [" << mofOutput.getData() << "]" << endl;            cout << "toString Output [" << valueString << "]" << endl;        }#endif        // There should be no exceptions to this point so the        // catch simply terminates.    }    catch(Exception& e)    {        cerr << "Error: " << e.getMessage() << endl;        exit(1);    }    // Test the Null Characteristics    try    {        // Set the initial one to Null        CIMType type = va.getType();        va.setNullValue(type, true, 0);        PEGASUS_TEST_ASSERT(va.isNull());        PEGASUS_TEST_ASSERT(va.isArray());        PEGASUS_TEST_ASSERT(va.getArraySize() == 0);        va.setNullValue(type, false);        PEGASUS_TEST_ASSERT(va.isNull());        PEGASUS_TEST_ASSERT(!va.isArray());        // get the String and XML outputs for v        String valueString2 = va.toString();        Buffer xmlBuffer;        XmlWriter::appendValueElement(xmlBuffer, va);        xmlBuffer.append('\0');        Buffer mofOutput2;        MofWriter::appendValueElement(mofOutput2, va);        mofOutput2.append('\0');#ifdef IO        if (verbose)        {            cout << "MOF NULL = [" << mofOutput2.getData() << "]" << endl;            cout << "toString NULL Output [" << valueString2 << "]" << endl;            cout << " XML NULL = [" << xmlBuffer.getData() << "]" << endl;        }#endif        va.clear();        PEGASUS_TEST_ASSERT(va.isNull());    }    catch(Exception& e)    {        cerr << "Error: " << e.getMessage() << endl;        exit(1);    }}template<class T1, class T2, class T3>void test03( Array<T1>& arrObj1, Array<T1>& arrObj2, T2 obj, T3 val1, T3 val2){    PEGASUS_TEST_ASSERT( 10 == arrObj1.size() && arrObj1[5] == val1);    PEGASUS_TEST_ASSERT( 1 == arrObj2.size() && arrObj2[0] == val1);    *obj = val2;    arrObj2.append(obj,1);    PEGASUS_TEST_ASSERT( 2 == arrObj2.size() && arrObj2[1] == val2 );    arrObj1.appendArray(arrObj2);    PEGASUS_TEST_ASSERT( 12 == arrObj1.size() && arrObj1[10] == val1 && arrObj1[11] == val2);    arrObj2.clear();    PEGASUS_TEST_ASSERT( 0 == arrObj2.size() );    PEGASUS_TEST_ASSERT( 16 == arrObj1.getCapacity() && 8 == arrObj2.getCapacity() );    arrObj2.grow(10,val1);    PEGASUS_TEST_ASSERT( 10 == arrObj2.size() && arrObj2[5] == val1);    arrObj2.insert(10,val2);    PEGASUS_TEST_ASSERT( 11 == arrObj2.size() && arrObj2[10] == val2);    arrObj2.insert(10, obj, 1);    PEGASUS_TEST_ASSERT( 12 == arrObj2.size() );    arrObj2.prepend(val2);    PEGASUS_TEST_ASSERT( 13 == arrObj2.size() && arrObj2[12] == val2);    *obj = val1;    arrObj2.prepend(obj,1);    PEGASUS_TEST_ASSERT( 14 == arrObj2.size() && arrObj2[0] == val1);    arrObj1.swap(arrObj2);    PEGASUS_TEST_ASSERT( 14 == arrObj1.size() && 12 == arrObj2.size() &&                        arrObj2[10] == val1 && arrObj1[12] == val2 );    arrObj1.remove(1);    PEGASUS_TEST_ASSERT( 13 == arrObj1.size() );    arrObj1.remove(1,1);    PEGASUS_TEST_ASSERT( 12 == arrObj1.size() );}template<class EmbeddedType>void testEmbeddedValue(const CIMInstance & instance){    CIMInstance instance1 = instance.clone();    // Specific test to verify the cloning of CIMObjects/CIMInstances when set    // and gotten from a CIMValue.    CIMValue v1;    // Create CIMValue v1 of type CIMTYPE_OBJECT/CIMTYPE_INSTANCE    v1.set(EmbeddedType(instance1));    // Change the "count" property of instance1, and then verify    // that the CIMValue v1, that was set from instance1, is    // not affected (ie. tests clone() on CIMValue::set() ).    Uint32 propIx = instance1.findProperty(CIMName("count"));    PEGASUS_TEST_ASSERT(propIx != PEG_NOT_FOUND);    CIMValue v2 = instance1.getProperty(propIx).getValue();    Uint32 propCount;    v2.get(propCount);    PEGASUS_TEST_ASSERT(propCount == 55);    instance1.removeProperty(propIx);    instance1.addProperty(CIMProperty(CIMName ("count"), Uint32(65))	    .addQualifier(CIMQualifier(CIMName ("counter"), true))	    .addQualifier(CIMQualifier(CIMName ("min"), String("0")))	    .addQualifier(CIMQualifier(CIMName ("max"), String("1"))));    EmbeddedType object2;    v1.get(object2);    CIMInstance instance1a(object2);    propIx = instance1a.findProperty(CIMName("count"));    PEGASUS_TEST_ASSERT(propIx != PEG_NOT_FOUND);    CIMValue v3 = instance1a.getProperty(propIx).getValue();    v3.get(propCount);    PEGASUS_TEST_ASSERT(propCount == 55);    // Now change the "count" property of instance1a, which was obtained    // from a get of CIMValue v1. Again, the underlying CIMValue should    // not be affected (ie. tests clone() on CIMValue::get() ).    instance1a.removeProperty(propIx);    instance1a.addProperty(CIMProperty(CIMName ("count"), Uint32(65))	    .addQualifier(CIMQualifier(CIMName ("counter"), true))	    .addQualifier(CIMQualifier(CIMName ("min"), String("0")))	    .addQualifier(CIMQualifier(CIMName ("max"), String("1"))));    EmbeddedType object3;    v1.get(object3);    CIMInstance instance1b(object3);    propIx = instance1b.findProperty(CIMName("count"));    PEGASUS_TEST_ASSERT(propIx != PEG_NOT_FOUND);    CIMValue v4 = instance1b.getProperty(propIx).getValue();    v4.get(propCount);    PEGASUS_TEST_ASSERT(propCount == 55);    // Specific test for setting value as a null CIMObject/CIMInstance    // (see bug 3373).    // Confirm that CIMValue() with an uninitialized CIMObject/CIMInstance will    // throw exception.    Boolean caught_exception = false;    try    {        EmbeddedType obj = EmbeddedType();        CIMValue y(obj);    }    catch(UninitializedObjectException&)    {        caught_exception = true;    }    PEGASUS_TEST_ASSERT (caught_exception == true);    // Confirm that set() with an uninitialized CIMObject/CIMInstance will    // throw exception.    caught_exception = false;    try    {        CIMValue y;        y.set(EmbeddedType());    }    catch(UninitializedObjectException&)    {        caught_exception = true;    }    PEGASUS_TEST_ASSERT (caught_exception == true);}template<class EmbeddedType>void testEmbeddedValueArray(const CIMInstance & startInstance,                            const CIMNamespaceName & NAMESPACE,                            SimpleDeclContext * context)

⌨️ 快捷键说明

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