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

📄 testoperationcontext.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: Chip Vincent (cvincent@us.ibm.com)//// Modified By://      Carol Ann Krug Graves, Hewlett-Packard Company(carolann_graves@hp.com)//      Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)////%/////////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/Config.h>#include <Pegasus/Common/Constants.h>#include <Pegasus/Common/CIMDateTime.h>#include <Pegasus/Common/CIMName.h>#include <Pegasus/Common/OperationContext.h>#include <Pegasus/Common/OperationContextInternal.h>#include <iostream>PEGASUS_USING_PEGASUS;PEGASUS_USING_STD;static char * verbose = 0;CIMInstance _createFilterInstance1(void){    CIMInstance filterInstance(PEGASUS_CLASSNAME_INDFILTER);    // add properties    filterInstance.addProperty(CIMProperty("SystemCreationClassName", String("CIM_UnitaryComputerSystem")));    filterInstance.addProperty(CIMProperty("SystemName", String("server001.acme.com")));    filterInstance.addProperty(CIMProperty("CreationClassName", PEGASUS_CLASSNAME_INDFILTER.getString()));    filterInstance.addProperty(CIMProperty("Name", String("Filter1")));    filterInstance.addProperty(CIMProperty("Query", String("SELECT * FROM CIM_AlertIndication WHERE AlertType = 5")));    filterInstance.addProperty(CIMProperty("QueryLanguage", String("WQL1")));    filterInstance.addProperty(CIMProperty("SourceNamespace", PEGASUS_NAMESPACENAME_INTEROP.getString()));    // create keys    Array<CIMKeyBinding> keys;    keys.append(CIMKeyBinding("SystemCreationClassName", "CIM_UnitaryComputerSystem", CIMKeyBinding::STRING));    keys.append(CIMKeyBinding("SystemName", "server001.acme.com", CIMKeyBinding::STRING));    keys.append(CIMKeyBinding("CreationClassName", PEGASUS_CLASSNAME_INDFILTER.getString(), CIMKeyBinding::STRING));    keys.append(CIMKeyBinding("Name", "Filter1", CIMKeyBinding::STRING));    // update object path    CIMObjectPath objectPath = filterInstance.getPath();    objectPath.setKeyBindings(keys);    filterInstance.setPath(objectPath);    return(filterInstance);}CIMInstance _createHandlerInstance1(void){    CIMInstance handlerInstance(PEGASUS_CLASSNAME_INDHANDLER_CIMXML);    // add properties    handlerInstance.addProperty(CIMProperty("SystemCreationClassName", String("CIM_UnitaryComputerSystem")));    handlerInstance.addProperty(CIMProperty("SystemName", String("server001.acme.com")));    handlerInstance.addProperty(CIMProperty("CreationClassName", PEGASUS_CLASSNAME_INDHANDLER_CIMXML.getString()));    handlerInstance.addProperty(CIMProperty("Name", String("Handler1")));    handlerInstance.addProperty(CIMProperty("Destination", String("localhost:5988/test1")));    // create keys    Array<CIMKeyBinding> keys;    keys.append(CIMKeyBinding("SystemCreationClassName", "CIM_UnitaryComputerSystem", CIMKeyBinding::STRING));    keys.append(CIMKeyBinding("SystemName", "server001.acme.com", CIMKeyBinding::STRING));    keys.append(CIMKeyBinding("CreationClassName", PEGASUS_CLASSNAME_INDHANDLER_CIMXML.getString(), CIMKeyBinding::STRING));    keys.append(CIMKeyBinding("Name", "Handler1", CIMKeyBinding::STRING));    // update object path    CIMObjectPath objectPath = handlerInstance.getPath();    objectPath.setKeyBindings(keys);    handlerInstance.setPath(objectPath);    return(handlerInstance);}CIMInstance _createFilterInstance2(void){    CIMInstance filterInstance(PEGASUS_CLASSNAME_INDFILTER);    // add properties    filterInstance.addProperty(CIMProperty("SystemCreationClassName", String("CIM_UnitaryComputerSystem")));    filterInstance.addProperty(CIMProperty("SystemName", String("server001.acme.com")));    filterInstance.addProperty(CIMProperty("CreationClassName", PEGASUS_CLASSNAME_INDFILTER.getString()));    filterInstance.addProperty(CIMProperty("Name", String("Filter2")));    filterInstance.addProperty(CIMProperty("Query", String("SELECT * FROM CIM_AlertIndication WHERE AlertType = 8")));    filterInstance.addProperty(CIMProperty("QueryLanguage", String("WQL1")));    filterInstance.addProperty(CIMProperty("SourceNamespace", PEGASUS_NAMESPACENAME_INTEROP.getString()));    // create keys    Array<CIMKeyBinding> keys;    keys.append(CIMKeyBinding("SystemCreationClassName", "CIM_UnitaryComputerSystem", CIMKeyBinding::STRING));    keys.append(CIMKeyBinding("SystemName", "server001.acme.com", CIMKeyBinding::STRING));    keys.append(CIMKeyBinding("CreationClassName", PEGASUS_CLASSNAME_INDFILTER.getString(), CIMKeyBinding::STRING));    keys.append(CIMKeyBinding("Name", "Filter2", CIMKeyBinding::STRING));    // update object path    CIMObjectPath objectPath = filterInstance.getPath();    objectPath.setKeyBindings(keys);    filterInstance.setPath(objectPath);    return(filterInstance);}CIMInstance _createHandlerInstance2(void){    CIMInstance handlerInstance(PEGASUS_CLASSNAME_INDHANDLER_CIMXML);    // add properties    handlerInstance.addProperty(CIMProperty("SystemCreationClassName", String("CIM_UnitaryComputerSystem")));    handlerInstance.addProperty(CIMProperty("SystemName", String("server001.acme.com")));    handlerInstance.addProperty(CIMProperty("CreationClassName", PEGASUS_CLASSNAME_INDHANDLER_CIMXML.getString()));    handlerInstance.addProperty(CIMProperty("Name", String("Handler2")));    handlerInstance.addProperty(CIMProperty("Destination", String("localhost:5988/test2")));    // create keys    Array<CIMKeyBinding> keys;    keys.append(CIMKeyBinding("SystemCreationClassName","CIM_UnitaryComputerSystem", CIMKeyBinding::STRING));    keys.append(CIMKeyBinding("SystemName", "server001.acme.com", CIMKeyBinding::STRING));    keys.append(CIMKeyBinding("CreationClassName", PEGASUS_CLASSNAME_INDHANDLER_CIMXML.getString(), CIMKeyBinding::STRING));    keys.append(CIMKeyBinding("Name", "Handler2", CIMKeyBinding::STRING));    // update object path    CIMObjectPath objectPath = handlerInstance.getPath();    objectPath.setKeyBindings(keys);    handlerInstance.setPath(objectPath);    return(handlerInstance);}CIMInstance _createSubscriptionInstance1(void){    CIMInstance filterInstance1 = _createFilterInstance1();    CIMInstance handlerInstance1 = _createHandlerInstance1();    CIMInstance subscriptionInstance(PEGASUS_CLASSNAME_INDSUBSCRIPTION);    // add properties    subscriptionInstance.addProperty(CIMProperty("Filter", filterInstance1.getPath(), 0, PEGASUS_CLASSNAME_INDFILTER));    subscriptionInstance.addProperty(CIMProperty("Handler", handlerInstance1.getPath(), 0, PEGASUS_CLASSNAME_INDHANDLER_CIMXML));    subscriptionInstance.addProperty(CIMProperty("OnFatalErrorPolicy", Uint16(4)));    subscriptionInstance.addProperty(CIMProperty("FailureTriggerTimeInterval", Uint64(60)));    subscriptionInstance.addProperty(CIMProperty("SubscriptionState", Uint16(2)));    subscriptionInstance.addProperty(CIMProperty("TimeOfLastStateChange", CIMDateTime::getCurrentDateTime()));    subscriptionInstance.addProperty(CIMProperty("SubscriptionDuration", Uint64(86400)));    subscriptionInstance.addProperty(CIMProperty("SubscriptionStartTime", CIMDateTime::getCurrentDateTime()));    subscriptionInstance.addProperty(CIMProperty("SubscriptionTimeRemaining", Uint64(86400)));    subscriptionInstance.addProperty(CIMProperty("RepeatNotificationPolicy", Uint16(1)));    subscriptionInstance.addProperty(CIMProperty("OtherRepeatNotificationPolicy", String("AnotherPolicy")));    subscriptionInstance.addProperty(CIMProperty("RepeatNotificationInterval", Uint64(60)));    subscriptionInstance.addProperty(CIMProperty("RepeatNotificationGap", Uint64(15)));    subscriptionInstance.addProperty(CIMProperty("RepeatNotificationCount", Uint16(3)));    // create keys    Array<CIMKeyBinding> keys;    keys.append(CIMKeyBinding("Filter", filterInstance1.getPath().toString(), CIMKeyBinding::REFERENCE));    keys.append(CIMKeyBinding("Handler", handlerInstance1.getPath().toString(), CIMKeyBinding::REFERENCE));    // update object path    CIMObjectPath objectPath = subscriptionInstance.getPath();    objectPath.setKeyBindings(keys);    subscriptionInstance.setPath(objectPath);    return(subscriptionInstance);}CIMInstance _createSubscriptionInstance2(void){    CIMInstance filterInstance2 = _createFilterInstance2();    CIMInstance handlerInstance2 = _createHandlerInstance2();    CIMInstance subscriptionInstance(PEGASUS_CLASSNAME_INDSUBSCRIPTION);    // add properties    subscriptionInstance.addProperty(CIMProperty("Filter", filterInstance2.getPath(), 0, PEGASUS_CLASSNAME_INDFILTER));    subscriptionInstance.addProperty(CIMProperty("Handler", handlerInstance2.getPath(), 0, PEGASUS_CLASSNAME_INDHANDLER_CIMXML));    subscriptionInstance.addProperty(CIMProperty("OnFatalErrorPolicy", Uint16(2)));    subscriptionInstance.addProperty(CIMProperty("FailureTriggerTimeInterval", Uint64(120)));    subscriptionInstance.addProperty(CIMProperty("SubscriptionState", Uint16(2)));    subscriptionInstance.addProperty(CIMProperty("TimeOfLastStateChange", CIMDateTime::getCurrentDateTime()));    subscriptionInstance.addProperty(CIMProperty("SubscriptionDuration", Uint64(172800)));    subscriptionInstance.addProperty(CIMProperty("SubscriptionStartTime", CIMDateTime::getCurrentDateTime()));    subscriptionInstance.addProperty(CIMProperty("SubscriptionTimeRemaining", Uint64(172800)));    subscriptionInstance.addProperty(CIMProperty("RepeatNotificationPolicy", Uint16(1)));    subscriptionInstance.addProperty(CIMProperty("OtherRepeatNotificationPolicy", String("AnotherPolicy2")));    subscriptionInstance.addProperty(CIMProperty("RepeatNotificationInterval", Uint64(120)));    subscriptionInstance.addProperty(CIMProperty("RepeatNotificationGap", Uint64(30)));    subscriptionInstance.addProperty(CIMProperty("RepeatNotificationCount", Uint16(6)));    // create keys    Array<CIMKeyBinding> keys;    keys.append(CIMKeyBinding("Filter", filterInstance2.getPath().toString(), CIMKeyBinding::REFERENCE));    keys.append(CIMKeyBinding("Handler", handlerInstance2.getPath().toString(), CIMKeyBinding::REFERENCE));    // update object path    CIMObjectPath objectPath = subscriptionInstance.getPath();    objectPath.setKeyBindings(keys);    subscriptionInstance.setPath(objectPath);    return(subscriptionInstance);}////  IdentityContainer//void Test1(void){    if(verbose)    {        cout << "Test1()" << endl;    }    OperationContext context;    {        String userName("Yoda");        context.insert(IdentityContainer(userName));        IdentityContainer container = context.get(IdentityContainer::NAME);        if(userName != container.getUserName())        {            cout << "----- Identity Container failed" << endl;            throw 0;        }    }    context.clear();    {        String userName("Yoda");        context.insert(IdentityContainer(userName));        //        //  This test exercises the IdentityContainer copy constructor        //        IdentityContainer container = context.get(IdentityContainer::NAME);        if(userName != container.getUserName())        {            cout << "----- Identity Container copy constructor failed" << endl;            throw 0;        }    }    context.clear();    {        String userName("Yoda");        context.insert(IdentityContainer(userName));        //        //  This test exercises the IdentityContainer assignment operator        //        IdentityContainer container = IdentityContainer(" ");        container = context.get(IdentityContainer::NAME);        if(userName != container.getUserName())        {            cout << "----- Identity Container assignment operator failed" << endl;            throw 0;        }    }}////  SubscriptionInstanceContainer//void Test2(void){    if(verbose)    {        cout << "Test2()" << endl;    }    OperationContext context;    CIMInstance subscriptionInstance = _createSubscriptionInstance1();    {        context.insert(SubscriptionInstanceContainer(subscriptionInstance));        SubscriptionInstanceContainer container =            context.get(SubscriptionInstanceContainer::NAME);        if(!subscriptionInstance.identical(container.getInstance()))        {            cout << "----- Subscription Instance Container failed" << endl;            throw 0;        }    }    context.clear();    {        context.insert(SubscriptionInstanceContainer(subscriptionInstance));        //        //  This test exercises the SubscriptionInstanceContainer copy        //  constructor        //        SubscriptionInstanceContainer container =            context.get(SubscriptionInstanceContainer::NAME);        if(!subscriptionInstance.identical(container.getInstance()))        {            cout << "----- Subscription Instance Container copy constructor failed" << endl;            throw 0;        }    }    context.clear();    {        context.insert(SubscriptionInstanceContainer(subscriptionInstance));        //        //  This test exercises the SubscriptionInstanceContainer assignment        //  operator        //        SubscriptionInstanceContainer container =            SubscriptionInstanceContainer(CIMInstance());        container = context.get(SubscriptionInstanceContainer::NAME);        if(!subscriptionInstance.identical(container.getInstance()))        {            cout << "----- Subscription Instance Container assignment operator failed" << endl;            throw 0;        }    }}////  SubscriptionFilterConditionContainer//void Test3(void){    if(verbose)    {        cout << "Test3()" << endl;    }    OperationContext context;    {        String filterCondition("AlertType = 5");        String queryLanguage("WQL1");        context.insert(SubscriptionFilterConditionContainer(filterCondition, queryLanguage));        SubscriptionFilterConditionContainer container =            context.get(SubscriptionFilterConditionContainer::NAME);        if((filterCondition != container.getFilterCondition()) ||           (queryLanguage != container.getQueryLanguage()))        {            cout << "----- Subscription Filter Condition Container failed" << endl;            throw 0;        }    }    context.clear();    {        String filterCondition("AlertType = 5");        String queryLanguage("WQL1");        context.insert(            SubscriptionFilterConditionContainer(filterCondition, queryLanguage));        //        //  This test exercises the SubscriptionFilterConditionContainer copy        //  constructor        //        SubscriptionFilterConditionContainer container =            context.get(SubscriptionFilterConditionContainer::NAME);

⌨️ 快捷键说明

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