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

📄 resolve.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: Mike Brasher (mbrasher@bmc.com)//// Modified By: Karl Schopmeyer (k.schopmeyer@opengroup.org)//			extend resolve tests for many error cases 22 March 2002//              Carol Ann Krug Graves, Hewlett-Packard Company//                (carolann_graves@hp.com)////%//////////////////////////////////////////////////////////////////////////////*	This module tests the resolve functions from the class objects.	Tests defined for valid resolution of classes. This test module sets	up multiple conditions of classes and subclasses and confirms that	the classes are resolved correctly for the superclasses and that	the proper information is propagated to subclasses as part of the	resolve.	We have tried to test all of the options of resolution including:	-resolution of properties and methods.	-resolution of class qualifiers	-resolution of property and method qualifiers.	-options of CIMScope and CIMFlavor	-resolution of propagation of qualifiers, properties, and methods to		a subclass.	-propagation of the values to subclasses.		All tests are confirmed with assertions so that the test should run	silently.	NOTE: Problems with the assertions are probably indications of problems	in the resolution of classes and either the test or the resolution	needs to be corrected.	Please, if there is a problem found, do not disable the tests.  We	prefer if you create a temporary display showing the problem	and disable the assertion itself so we are warned of the problem during	testing until the problem is corrected.*/#include <Pegasus/Common/PegasusAssert.h>#include <cstdlib>#include <Pegasus/Common/CIMClass.h>#include <Pegasus/Common/CIMQualifierDecl.h>#include <Pegasus/Common/DeclContext.h>#include <Pegasus/Common/CIMFlavor.h>#include <Pegasus/Common/CIMValue.h>#include <Pegasus/Common/CIMFlavor.h>#include <Pegasus/Common/Resolver.h>#include <Pegasus/Common/XmlWriter.h>PEGASUS_USING_PEGASUS;PEGASUS_USING_STD;#define TESTIOstatic char* verbose;/*  This is the original test written as a simple test of resolution.*/void test01(){    const CIMNamespaceName NAMESPACE = CIMNamespaceName ("/ttt");	if(verbose)		cout << "Test01 " << endl;	SimpleDeclContext* context = new SimpleDeclContext;    // Not sure about this one. How do I get NULL as CIMValue    // This generates an empty string, not NULL    CIMQualifierDecl q1(CIMName ("q1"),String(),CIMScope::CLASS);	// This qualifier is    CIMQualifierDecl q2(CIMName ("Abstract"), Boolean(true), CIMScope::CLASS,         CIMFlavor::NONE);	// flavors for this one should be enableoverride, and tosubclass 	CIMQualifierDecl key(CIMName ("key"),Boolean(true),            (CIMScope::PROPERTY + CIMScope::REFERENCE), CIMFlavor::TOSUBCLASS);	// Flavor is the defaults. overridable and tosubclass.    CIMValue v1(CIMTYPE_UINT32, false);    CIMQualifierDecl q3(CIMName ("q3"),v1,CIMScope::CLASS);	// Flavor should be tosubclass and overridable    CIMQualifierDecl q4(CIMName ("q4"),String(),CIMScope::CLASS, 		CIMFlavor::TOSUBCLASS + CIMFlavor::ENABLEOVERRIDE);	// Flavor should be tosubclass and overridable    CIMQualifierDecl q5(CIMName ("q5"),String("Declaration"),CIMScope::CLASS, 		CIMFlavor::TOSUBCLASS + CIMFlavor::ENABLEOVERRIDE);	if(verbose)	{		XmlWriter::printQualifierDeclElement(q1);		XmlWriter::printQualifierDeclElement(q2);		XmlWriter::printQualifierDeclElement(q3);		XmlWriter::printQualifierDeclElement(q4);		XmlWriter::printQualifierDeclElement(q5);		XmlWriter::printQualifierDeclElement(key);	}    context->addQualifierDecl(NAMESPACE, q1);    context->addQualifierDecl(NAMESPACE, q2);    context->addQualifierDecl(NAMESPACE, q3);    context->addQualifierDecl(NAMESPACE, q4);    context->addQualifierDecl(NAMESPACE, q5);    context->addQualifierDecl(NAMESPACE, key);	CIMProperty keyProperty(CIMName ("keyProperty"), Boolean(true));	keyProperty		.addQualifier(CIMQualifier(CIMName ("key"), Boolean(true)));    CIMClass class2(CIMName ("SuperClass"));	if(verbose)	cout << "Create Class2 " << endl;	class2        .addQualifier(CIMQualifier(CIMName ("Abstract"), Boolean(true)))		.addQualifier(CIMQualifier(CIMName ("q1"), String("Hello")))		.addQualifier(CIMQualifier(CIMName ("q4"), String("Goodbye")))		.addQualifier(CIMQualifier(CIMName ("q5"), String("Hello")))		.addProperty(CIMProperty(keyProperty))	;        context->addClass(NAMESPACE, class2);    Resolver::resolveClass (class2, context, NAMESPACE);    	if(verbose)	cout << "Create Class1 " << endl;    CIMClass class1(CIMName ("SubClass"), CIMName ("SuperClass"));    class1        .addQualifier(CIMQualifier(CIMName ("Abstract"), Boolean(true)))        .addQualifier(CIMQualifier(CIMName ("q1"), String("Hello")))		.addQualifier(CIMQualifier(CIMName ("q3"), Uint32(55)))		.addQualifier(CIMQualifier(CIMName ("q5"), String("Goodbye")))	// .addProperty(CIMProperty(keyProperty))	.addProperty(CIMProperty(CIMName ("count"), Uint32(77)))	// .addProperty(CIMProperty(CIMName ("ref1"), Reference("MyClass.key1=\"fred\"")))	.addMethod(CIMMethod(CIMName ("isActive"), CIMTYPE_BOOLEAN)	    .addParameter(CIMParameter(CIMName ("hostname"), CIMTYPE_STRING))	    .addParameter(CIMParameter(CIMName ("port"), CIMTYPE_UINT32)));    if(verbose)	{		XmlWriter::printClassElement(class1);		XmlWriter::printClassElement(class2);	}	if(verbose)	cout << "Resolve class 1 " << endl;    try{        Resolver::resolveClass (class1, context, NAMESPACE);		if(verbose)			cout << "Passed basic resolution test" << endl;        // Add assertions on the resolution.        // Abstract did not move to subclass        // 2. et.    if(verbose)	{		cout << "after resolve " << endl;		XmlWriter::printClassElement(class1);		XmlWriter::printClassElement(class2);	}    }    catch (Exception& e)    {        cerr << "Test01 - Resolution Error " << e.getMessage() << endl;    }	// Test results	in superclass	PEGASUS_TEST_ASSERT(class2.findQualifier(CIMName ("Abstract")) != PEG_NOT_FOUND);	// assert results in subclass	PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("Abstract")) != PEG_NOT_FOUND);	PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q1")) != PEG_NOT_FOUND);	PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q3")) != PEG_NOT_FOUND);	PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q4")) != PEG_NOT_FOUND);	PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q5")) != PEG_NOT_FOUND);    delete context;}/* Test for qualifier and properties resolved to subclass from superclass	This is a major test of resolution of attributes from a superclass to	a subclass.    This test confirms that:	-subclasses have the following moved correctly from superclasses:		-properties and the propagated flag set.		-Qualifiers with toSubclass set.		Confirms that the following is not done:		-qualifiers with !tosubclass are not propagated.		Confirms classOrigin set correctly for all properties and methods.	Confirms that the propagated flag set correctly on all propagated	properties and methods.		Tests to be added:		-Method propagation		-Array propagation		All tests are confirmed with assertions. Displays are optional except	for a few cases where the resolve itself is incorrect and we need reminders	to fix it.	*/void test02(){	if(verbose)		cout << "Test02 - Resolution of properties from super to subclass " << endl;    	const CIMNamespaceName NAMESPACE = CIMNamespaceName ("/ttt");    Boolean resolved = false;    SimpleDeclContext* context = new SimpleDeclContext;	  // flavors for this one should be disable override, restricted.      CIMQualifierDecl abstract(CIMName ("Abstract"), Boolean(true),           CIMScope::CLASS, CIMFlavor::RESTRICTED + CIMFlavor::DISABLEOVERRIDE);      // flavors for this one should be disableoverride, but tosubclass 	  CIMQualifierDecl key(CIMName ("key"),Boolean(true),		  (CIMScope::PROPERTY + CIMScope::REFERENCE),        CIMFlavor::TOSUBCLASS);	  // Flavors are not to subclass and not overridable	  CIMQualifierDecl notToSubclass(CIMName ("notToSubclass"), Boolean(),		  (CIMScope::PROPERTY + CIMScope::CLASS),		  CIMFlavor::RESTRICTED + CIMFlavor::DISABLEOVERRIDE);	  // same qualities as association qualifier. DisableOverride 	  CIMQualifierDecl association(CIMName ("associat"), Boolean(false),		  (CIMScope::ASSOCIATION + CIMScope::CLASS),		  CIMFlavor::DISABLEOVERRIDE);	  // Qualifier with TOSubclass set and a value and not overridable.	  CIMQualifierDecl toSubclass(CIMName ("toSubclass"), String("default"),		  (CIMScope::PROPERTY + CIMScope::CLASS),		  CIMFlavor::TOSUBCLASS);	  // Qualifier with TOSubclass set and a value.	  CIMQualifierDecl toSubclassOverridable              (CIMName ("toSubclassOverriddable"), String("default"),		  (CIMScope::PROPERTY + CIMScope::CLASS),		  CIMFlavor::TOSUBCLASS + CIMFlavor::OVERRIDABLE);	  // Qualifier with Null value. Use to demo value Nulls	  CIMQualifierDecl nullValue(CIMName ("nullValue"), String(),		  (CIMScope::PROPERTY + CIMScope::CLASS),		  CIMFlavor::TOSUBCLASS);	  // Flavors for this qualifier should be enableoverride, tosubclass	  // Value is empty      CIMQualifierDecl q1(CIMName ("q1"),String(),CIMScope::CLASS,        CIMFlavor::DEFAULTS);      CIMQualifierDecl q2(CIMName ("q2"),String(),CIMScope::CLASS,           CIMFlavor::DEFAULTS);	  // Qualifier q3 Boolean with value zero	  CIMValue v1(CIMTYPE_UINT32, false);      CIMQualifierDecl q3(CIMName ("q3"),v1,CIMScope::CLASS,           CIMFlavor::DEFAULTS);	  Array<String> stringArray;	  stringArray.append("One");	  stringArray.append("Two");	  stringArray.append("Three");      CIMQualifierDecl arrayValue(CIMName ("arrayValue"),stringArray,		  (CIMScope::CLASS + CIMScope::PROPERTY), CIMFlavor::DEFAULTS);      if(verbose)	  {		  XmlWriter::printQualifierDeclElement(q1);		  XmlWriter::printQualifierDeclElement(q2);		  XmlWriter::printQualifierDeclElement(q3);		  XmlWriter::printQualifierDeclElement(abstract);		  XmlWriter::printQualifierDeclElement(association);		  XmlWriter::printQualifierDeclElement(key);		  XmlWriter::printQualifierDeclElement(notToSubclass);		  XmlWriter::printQualifierDeclElement(toSubclass);		  XmlWriter::printQualifierDeclElement(toSubclassOverridable);		  XmlWriter::printQualifierDeclElement(nullValue);		  XmlWriter::printQualifierDeclElement(arrayValue);	  }	// add our test qualifiers to the namespace    context->addQualifierDecl(NAMESPACE, q1);    context->addQualifierDecl(NAMESPACE, q2);    context->addQualifierDecl(NAMESPACE, q3);    context->addQualifierDecl(NAMESPACE, abstract);    context->addQualifierDecl(NAMESPACE, association);    context->addQualifierDecl(NAMESPACE, key);    context->addQualifierDecl(NAMESPACE, notToSubclass);    context->addQualifierDecl(NAMESPACE, toSubclass);    context->addQualifierDecl(NAMESPACE, toSubclassOverridable);	// Create the superclass and add qualifier, properties and methods    CIMClass superClass(CIMName ("SuperClass"));	// Create property with qualifier that propagates.	CIMProperty propertyWithQualifier(CIMName ("withQualifier"),             Boolean(true));	propertyWithQualifier		.addQualifier(CIMQualifier(CIMName ("toSubclass"),                     String("default")));		// Create a key property with key qualifier	CIMProperty keyProperty(CIMName ("keyProperty"), Boolean(true));	keyProperty			.addQualifier(CIMQualifier(CIMName ("key"), Boolean(true)));

⌨️ 快捷键说明

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