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

📄 g11ntest.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//%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: Chuck Carmack (carmack@us.ibm.com)//// Modified By: Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)////%/////////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/Config.h>#include <Pegasus/Common/Constants.h>#include <Pegasus/Common/PegasusVersion.h>#include <Pegasus/Common/PegasusAssert.h>#include <Pegasus/Common/TLS.h>#include <Pegasus/Client/CIMClient.h>#include <Pegasus/Common/CIMName.h>#include <Pegasus/Common/OptionManager.h>#include <Pegasus/Common/FileSystem.h>#include <Pegasus/Common/Stopwatch.h>#include <Pegasus/Common/System.h>#include <Pegasus/Common/Exception.h>#include <Pegasus/Common/XmlWriter.h>#include <Pegasus/Consumer/CIMIndicationConsumer.h>#include <Pegasus/Listener/CIMListener.h>#include <Pegasus/Common/AcceptLanguageList.h>#include <Pegasus/Common/ContentLanguageList.h>#include <Pegasus/Common/LanguageParser.h>#include <Pegasus/Common/IPCExceptions.h>PEGASUS_USING_PEGASUS;PEGASUS_USING_STD;#define TESTMACRO(EXCTYPE) throw new EXCTYPE;//#define MYASSERT ASSERTTEMP#define MYASSERT PEGASUS_TEST_ASSERTstatic const char* programVersion =  "1.0";Boolean skipICU = false;// Array of UTF-16 chars to be sent and received to the server.// Note: the dbc0/dc01 pair are surrogatesChar16 utf16Chars[] =        {        0x6A19, 0x6E96, 0x842C, 0x570B, 0x78BC,        0x042E, 0x043D, 0x0438, 0x043A, 0x043E, 0x0434,        0x110B, 0x1172, 0x1102, 0x1165, 0x110F, 0x1169, 0x11AE,        0x10E3, 0x10DC, 0x10D8, 0x10D9, 0x10DD, 0x10D3, 0x10D8,    0xdbc0, 0xdc01,        0x05D9, 0x05D5, 0x05E0, 0x05D9, 0x05E7, 0x05D0, 0x05B8, 0x05D3,        0x064A, 0x0648, 0x0646, 0x0650, 0x0643, 0x0648, 0x062F,        0x092F, 0x0942, 0x0928, 0x093F, 0x0915, 0x094B, 0x0921,        0x016A, 0x006E, 0x012D, 0x0063, 0x014D, 0x0064, 0x0065, 0x033D,        0x00E0, 0x248B, 0x0061, 0x2173, 0x0062, 0x1EA6, 0xFF21, 0x00AA, 0x0325, 0x2173, 0x249C, 0x0063,        0x02C8, 0x006A, 0x0075, 0x006E, 0x026A, 0x02CC, 0x006B, 0x006F, 0x02D0, 0x0064,        0x30E6, 0x30CB, 0x30B3, 0x30FC, 0x30C9,        0xFF95, 0xFF86, 0xFF7A, 0xFF70, 0xFF84, 0xFF9E,        0xC720, 0xB2C8, 0xCF5B, 0x7D71, 0x4E00, 0x78BC,    0xdbc0, 0xdc01,        0x00};// A shorter array of UTF-16 chars to be used in the repository tests for the names// of the repository files.// Longer strings are more likely to hit the filesystem maximum name length// if the repository is set up to escape these characters in its file names.// Mix in a utf-16 surrogate pair at the start (dbc0/dc01).Char16 utfRepChars[] =  {    0xdbc0, 0xdc01,    'a',    0xFF95,    'z',    0xFF86,    0x00  };//////////////////////////////////////////////////////////////////////////////////// Indication Related Stuff//////////////////////////////////////////////////////////////////////////////////Semaphore indicationReceived(0);OperationContext indicationContext;CIMInstance indication;class MyIndicationConsumer : public CIMIndicationConsumer{public:    MyIndicationConsumer(String name);    ~MyIndicationConsumer();    void consumeIndication(const OperationContext& context,        const String & url,        const CIMInstance& indicationInstance);private:    String name;};MyIndicationConsumer::MyIndicationConsumer(String name){    this->name = name;}MyIndicationConsumer::~MyIndicationConsumer(){}void MyIndicationConsumer::consumeIndication(                         const OperationContext & context,                         const String & url,                         const CIMInstance& indicationInstance){  // Save the objects for the main code to verify  indication = indicationInstance;  indicationContext = context;  // Signal the main code that the indication was received  indicationReceived.signal();}////////////////////////////////////////////////////////////////////////////** ErrorExit - Print out the error message as an    and get out.    @param - Text for error message    @return - None, Terminates the program    @execption - This function terminates the program    ATTN: Should write to stderr*/void ErrorExit(const String& message){    cout << message << endl;    exit(1);}/* Status display of the various steps.  Shows message of function andtime to execute.  Grow this to a class so we have start and stop and timedisplay with success/failure for each function.*/static void testStart(const String& message){    cout << "++++ " << message << " ++++" << endl;}static void testEnd(const double elapsedTime){    cout << "In " << elapsedTime << " Seconds\n\n";}/*   Tests the UTF support in the repository*/static void TestUTFRepository( CIMClient& client,                               Boolean utfRepNames,                               Boolean activeTest,                               Boolean verboseTest ){  if (!activeTest)  {     cout << "Active tests are disabled. Nothing to do for this set of tests." << endl;     return;  }  const CIMNamespaceName NAMESPACE = CIMNamespaceName ("root/SampleProvider");  const CIMNamespaceName ROOT_NAMESPACE = CIMNamespaceName ("root");  Boolean deepInheritance = true;  Boolean localOnly = true;  Boolean includeQualifiers = true;  Boolean includeClassOrigin = true;  try    {      // The repository does not support these headers and will throw errors      // if they are used.      client.setRequestAcceptLanguages(AcceptLanguageList());      client.setRequestContentLanguages(ContentLanguageList());        String utf16String(utf16Chars);    String utf16FileName(utfRepChars);    //    //  TEST 1 - Create qualifier    //  Create a qualifier with UTF-16 in the qualifier name,        //  and value    //  This will test UTF support in the repository.    //    cout << endl << "REPOSITORY TEST 1: Create Qualifier containing UTF-16 chars" << endl;    // Decide whether to use UTF-16 in the name of the qualifier        CIMName qualDeclName("UTFTestQualifier");        if (!utfRepNames)        {      cout << "Note: utfrep option was not set. Not using UTF-16 in the qualifier name" << endl;        }        else        {      if (verboseTest)        cout << "Using UTF-16 in the qualifier name" << endl;      // This will create a repository file with UTF-8 chars in the name      qualDeclName = utf16FileName;        }        //  First, delete the qualifier if it was there from before        if (verboseTest)        cout << "Deleting the qualifier in case it was there from before" << endl;        try        {            client.deleteQualifier(NAMESPACE, qualDeclName);        }        catch (CIMException & e)        {            if (e.getCode() != CIM_ERR_NOT_FOUND)                throw;        }        if (verboseTest)        cout << "Creating the qualifier" << endl;        CIMQualifierDecl qualDecl(qualDeclName,                     utf16String,                     CIMScope::PROPERTY + CIMScope::CLASS,             CIMFlavor::OVERRIDABLE);        client.setQualifier(NAMESPACE, qualDecl);        if (verboseTest)        cout << "Getting the qualifier that was just created" << endl;        CIMQualifierDecl rtnQualDecl = client.getQualifier(            NAMESPACE,            qualDeclName);        if (verboseTest)        cout << "Checking that UTF-16 was preserved" << endl;        MYASSERT(qualDecl.identical(rtnQualDecl));        if (verboseTest)        cout << "Enumerating the qualifiers, and looking for the UTF-16 one" << endl;    Array<CIMQualifierDecl> rtnQualDeclArray = client.enumerateQualifiers(              NAMESPACE );    Boolean foundQualDecl = false;    for (Uint32 i = 0; i < rtnQualDeclArray.size(); i++)        {      if (qualDecl.identical(rtnQualDeclArray[i]))          foundQualDecl = true;    }    MYASSERT(foundQualDecl == true);    //    //  TEST 2 - Create class    //  Create a class with UTF-16 in the class name,    //  property names, and qualifiers.    //    //  We will use the UTF16 qualifier created above    //  in this class.    //    //  This will test UTF support in the repository.    //    cout << endl << "REPOSITORY TEST 2: Create Class containing UTF-16 chars" << endl;    // Decide whether to use UTF-16 in the name of the class    CIMName className("UTFTestClass");    if (!utfRepNames)    {      cout << "Note: utfrep option was not set. Not using UTF-16 in the class name" << endl;    }    else    {      if (verboseTest)        cout << "Using UTF-16 in the class name" << endl;      // This will create a repository file with UTF-8 chars in the name      className = utf16FileName;    }        //  First, delete the class if it was there from before        if (verboseTest)        cout << "Deleting the class in case it was there from before" << endl;        try        {            client.deleteClass(NAMESPACE, className);        }        catch (CIMException & e)        {            if (e.getCode() != CIM_ERR_NOT_FOUND)                throw;        }        if (verboseTest)        cout << "Creating the class" << endl;        // How did this get so ugly?        CIMClass cimClass(className, CIMName ("CIM_ManagedElement"));        CIMName name1("fred");        CIMName name2(utf16String);        CIMValue fred("fred");        CIMName key("key");        CIMProperty prop1(name1, fred);        CIMQualifier qual1(key, true);        CIMProperty prop2 = prop1.addQualifier(qual1);        cimClass.addProperty(prop2);        CIMProperty prop3(name2, fred);             // UTF16 prop name        CIMQualifier qual2(qualDecl.getName(),      // UTF16 qualifier                           qualDecl.getValue(),                           qualDecl.getFlavor());        CIMProperty prop4 = prop3.addQualifier(qual2);        cimClass.addProperty(prop4);        client.createClass(NAMESPACE, cimClass);        if (verboseTest)        cout << "Getting the class that was just created" << endl;        CIMClass rtnClass = client.getClass(            NAMESPACE,            className,            true,            true);

⌨️ 快捷键说明

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