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

📄 testobjectnormalizer.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: Chip Vincent (cvincent@us.ibm.com)//// Modified By:////%/////////////////////////////////////////////////////////////////////////////#include "LocalRepository.h"#include <Pegasus/Common/ObjectNormalizer.h>#include <Pegasus/Common/Stopwatch.h>#include <Pegasus/Common/XmlWriter.h>PEGASUS_USING_PEGASUS;PEGASUS_USING_STD;static char * verbose = 0;static LocalRepository * repository = 0;static Stopwatch _stopwatch;#define PRINT(x) if(verbose) cout << x << endl;//// Basic ObjectNormalizer tests//// test improper ObjectNormalizer seedingvoid Test001a(void){    PRINT("Test001a");    CIMClass cimClass;    AutoPtr<NormalizerContext> nullContext(0);    ObjectNormalizer normalizer(        cimClass,        false,        false,        CIMNamespaceName(String("root")),        nullContext);    normalizer.processClassObjectPath(CIMObjectPath());    normalizer.processInstanceObjectPath(CIMObjectPath());    normalizer.processInstance(CIMInstance());}// test bad argumentsvoid Test001b(void){    PRINT("Test001b");    PRINT("Explicity disabled.");    /*    // ATTN: the following test has been disabled because the initialized object    // check was moved to the response handlers.    ObjectNormalizer normalizer(        CIMClass("CIM_ManagedElement"),        false,        false);    try    {        normalizer.processClassObjectPath(CIMObjectPath());        throw Exception("Failed to detect null class object path.");    }    catch(CIMException & e)    {        PRINT("expected CIMException: " << e.getMessage());    }    try    {        normalizer.processInstanceObjectPath(CIMObjectPath());        throw Exception("Failed to detect null instance object path.");    }    catch(CIMException & e)    {        PRINT("expected CIMException: " << e.getMessage());    }    try    {        normalizer.processInstance(CIMInstance());        throw Exception("Failed to detect null instance.");    }    catch(CIMException & e)    {        PRINT("expected CIMException: " << e.getMessage());    }    */}//// object path failures//// class object path (null object path)void Test002a(void){    PRINT("Test002a");    _stopwatch.reset();    Boolean includeQualifiers = false;    Boolean includeClassOrigin = false;    CIMClass cimClass =        repository->getClass(            "test_namespace",            "ClassC",            true,            includeClassOrigin,            CIMPropertyList());    AutoPtr<NormalizerContext> nullContext(0);    ObjectNormalizer normalizer(        cimClass,        includeQualifiers,        includeClassOrigin,        CIMNamespaceName("test_namespace"),        nullContext);    CIMObjectPath cimObjectPath;    try    {        _stopwatch.start();        CIMObjectPath normalizedObjectPath = normalizer.processClassObjectPath(cimObjectPath);        _stopwatch.stop();        throw Exception("Failed to detect a null class object path.");    }    catch(CIMException & e)    {        _stopwatch.stop();        PRINT("expected CIMException: " << e.getMessage());    }    PRINT("*** " << _stopwatch.getElapsed() << " milliseconds.");}// class object path (incorrect class name)void Test002b(void){    PRINT("Test002b");    _stopwatch.reset();    Boolean includeQualifiers = false;    Boolean includeClassOrigin = false;    CIMClass cimClass =        repository->getClass(            "test_namespace",            "ClassC",            true,            includeClassOrigin,            CIMPropertyList());    AutoPtr<NormalizerContext> nullContext(0);    ObjectNormalizer normalizer(        cimClass,        includeQualifiers,        includeClassOrigin,        CIMNamespaceName("test_namespace"),        nullContext);    CIMObjectPath cimObjectPath;    cimObjectPath.setClassName("ClassBAD");  // use different case to test that too    try    {        _stopwatch.start();        CIMObjectPath normalizedObjectPath = normalizer.processClassObjectPath(cimObjectPath);        _stopwatch.stop();        throw Exception("Failed to detect class object path with incorrect class name.");    }    catch(CIMException & e)    {        _stopwatch.stop();        PRINT("expected CIMException: " << e.getMessage());    }    PRINT("*** " << _stopwatch.getElapsed() << " milliseconds.")}// instance object path (incorrect class name)void Test002c(void){    PRINT("Test002c");    _stopwatch.reset();    Boolean includeQualifiers = false;    Boolean includeClassOrigin = false;    CIMClass cimClass =        repository->getClass(            "test_namespace",            "ClassC",            true,            includeClassOrigin,            CIMPropertyList());    AutoPtr<NormalizerContext> nullContext(0);    ObjectNormalizer normalizer(        cimClass,        includeQualifiers,        includeClassOrigin,        CIMNamespaceName("test_namespace"),        nullContext);    CIMObjectPath cimObjectPath;    cimObjectPath.setClassName("ClassBAD");    // no keys    try    {        _stopwatch.start();        CIMObjectPath normalizedObjectPath = normalizer.processInstanceObjectPath(cimObjectPath);        _stopwatch.stop();        throw Exception("Failed to detect instance object path with incorrect class name.");    }    catch(CIMException & e)    {        _stopwatch.stop();        PRINT("expected CIMException: " << e.getMessage());    }    PRINT("*** " << _stopwatch.getElapsed() << " milliseconds.");}// instance object path (no key properties in instance, no keys in object path)void Test002d(void){    PRINT("Test002d");    _stopwatch.reset();    Boolean includeQualifiers = false;    Boolean includeClassOrigin = false;    CIMClass cimClass =        repository->getClass(            "test_namespace",            "ClassC",            true,            includeClassOrigin,            CIMPropertyList());    AutoPtr<NormalizerContext> nullContext(0);    ObjectNormalizer normalizer(        cimClass,        includeQualifiers,        includeClassOrigin,        CIMNamespaceName("test_namespace"),        nullContext);    CIMObjectPath cimObjectPath;    cimObjectPath.setClassName(cimClass.getClassName());    // no keys    try    {        _stopwatch.start();        CIMObjectPath normalizedObjectPath = normalizer.processInstanceObjectPath(cimObjectPath);        _stopwatch.stop();        throw Exception("Failed to detect instance object path with no key properties and no keys.");    }    catch(CIMException & e)    {        _stopwatch.stop();        PRINT("expected CIMException: " << e.getMessage());    }    PRINT("*** " << _stopwatch.getElapsed() << " milliseconds.");}//// object path successes//// class object path (normal)void Test003a(void){    PRINT("Test003a");    _stopwatch.reset();    Boolean includeQualifiers = false;    Boolean includeClassOrigin = false;    CIMClass cimClass =        repository->getClass(            "test_namespace",            "ClassC",            true,            includeClassOrigin,            CIMPropertyList());    AutoPtr<NormalizerContext> nullContext(0);    ObjectNormalizer normalizer(        cimClass,        includeQualifiers,        includeClassOrigin,        CIMNamespaceName("test_namespace"),        nullContext);    CIMObjectPath cimObjectPath;    cimObjectPath.setClassName(cimClass.getClassName());    _stopwatch.start();    CIMObjectPath normalizedObjectPath = normalizer.processClassObjectPath(cimObjectPath);    _stopwatch.stop();    if(verbose)    {        cout << normalizedObjectPath.toString() << endl;    }    PRINT("*** " << _stopwatch.getElapsed() << " milliseconds.");}// class object path (with erroneous and extra information)void Test003b(void){    PRINT("Test003b");    _stopwatch.reset();    Boolean includeQualifiers = false;    Boolean includeClassOrigin = false;    CIMClass cimClass =        repository->getClass(            "test_namespace",            "ClassC",            true,            includeClassOrigin,            CIMPropertyList());    AutoPtr<NormalizerContext> nullContext(0);    ObjectNormalizer normalizer(        cimClass,        includeQualifiers,        includeClassOrigin,        CIMNamespaceName("test_namespace"),        nullContext);    CIMObjectPath cimObjectPath;    cimObjectPath.setClassName("classc");  // use lowercase. normalization should fix case    // fake keys    Array<CIMKeyBinding> keys;    keys.append(CIMKeyBinding("FakeProperty1", CIMValue(String("junk"))));    keys.append(CIMKeyBinding("FakeProperty2", CIMValue(String("more junk"))));    cimObjectPath.setKeyBindings(keys);    _stopwatch.start();    CIMObjectPath normalizedObjectPath = normalizer.processClassObjectPath(cimObjectPath);    _stopwatch.stop();    PRINT(normalizedObjectPath.toString());    PRINT("*** " << _stopwatch.getElapsed() << " milliseconds.");}// instance object path (normal)void Test003c(void){    PRINT("Test003c");    _stopwatch.reset();    Boolean includeQualifiers = false;    Boolean includeClassOrigin = false;

⌨️ 快捷键说明

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