📄 resolve.cpp
字号:
PEGASUS_TEST_ASSERT(mp2.getType() == CIMTYPE_UINT32); } } delete context;}// Test to confirm that invalid qualifier is caught// Remove q3 from earlier test and confirm that caughtvoid test04(){ const CIMNamespaceName NAMESPACE = CIMNamespaceName ("/ttt"); Boolean resolved = false; 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); CIMQualifierDecl q2(CIMName ("Abstract"), Boolean(true), CIMScope::CLASS , CIMFlavor::NONE); CIMValue v1(CIMTYPE_UINT32, false); CIMQualifierDecl q3(CIMName ("q1"),v1,CIMScope::CLASS); // flavors for this one should be disableoverride, but tosubclass CIMQualifierDecl key(CIMName ("key"),Boolean(true),(CIMScope::PROPERTY + CIMScope::REFERENCE), CIMFlavor::TOSUBCLASS); context->addQualifierDecl(NAMESPACE, q1); context->addQualifierDecl(NAMESPACE, q2); context->addQualifierDecl(NAMESPACE, key); CIMProperty keyProperty(CIMName ("keyProperty"), Boolean(true)); keyProperty.addQualifier(CIMQualifier(CIMName ("key"), Boolean(true))); CIMClass class2(CIMName ("SuperClass")); class2.addProperty(CIMProperty(keyProperty)); context->addClass(NAMESPACE, class2); Resolver::resolveClass (class2, context, NAMESPACE); 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))) .addProperty(CIMProperty(CIMName ("message"), String("Hello"))) .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); } try{ Resolver::resolveClass (class1, context, NAMESPACE); resolved = true; 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) { // should catch error here, q3 invalid qualifier. if(verbose) cout << "Exception correctly detected missing qualifier declaration: " << e.getMessage() << endl; } PEGASUS_TEST_ASSERT(!resolved); delete context;}// Test05 - Determine if we correctly detect a property qualifier on a class and // rejectvoid test05(){ if(verbose) cout << "Test05-Detecting a CIMScope errors - exception" << endl; const CIMNamespaceName NAMESPACE = CIMNamespaceName ("/ttt"); Boolean resolved = false; SimpleDeclContext* context = new SimpleDeclContext; CIMQualifierDecl key(CIMName ("key"),Boolean(true), (CIMScope::PROPERTY + CIMScope::REFERENCE), CIMFlavor::TOSUBCLASS); //Qualifier Association : boolean = false, Scope(class, association), // Flavor(DisableOverride); CIMQualifierDecl association(CIMName ("association"),Boolean(true), (CIMScope::CLASS + CIMScope::ASSOCIATION), CIMFlavor::TOSUBCLASS); CIMQualifierDecl propertyQualifier(CIMName ("propertyQualifier"), Boolean(true), (CIMScope::PROPERTY + CIMScope::REFERENCE), CIMFlavor::TOSUBCLASS); CIMQualifierDecl classQualifier(CIMName ("classQualifier"), Boolean(true), (CIMScope::CLASS), CIMFlavor::TOSUBCLASS); if(verbose) { XmlWriter::printQualifierDeclElement(propertyQualifier); XmlWriter::printQualifierDeclElement(classQualifier); XmlWriter::printQualifierDeclElement(key); XmlWriter::printQualifierDeclElement(association); } context->addQualifierDecl(NAMESPACE, key); context->addQualifierDecl(NAMESPACE, association); context->addQualifierDecl(NAMESPACE, propertyQualifier); context->addQualifierDecl(NAMESPACE, classQualifier); CIMProperty keyProperty(CIMName ("keyProperty"), Boolean(true)); keyProperty.addQualifier(CIMQualifier(CIMName ("key"), Boolean(true))); // create class with property only qualifier and no superclass CIMClass classWithPropertyQualifier(CIMName ("classWithPropertyQualifier")); classWithPropertyQualifier .addQualifier(CIMQualifier(CIMName ("propertyQualifier"), Boolean(true))) .addProperty(CIMProperty(keyProperty)) .addProperty(CIMProperty(CIMName ("message"), String("Hello"))) .addMethod(CIMMethod(CIMName ("isActive"), CIMTYPE_BOOLEAN) .addParameter(CIMParameter(CIMName ("hostname"), CIMTYPE_STRING))); resolved = false; if(verbose) XmlWriter::printClassElement(classWithPropertyQualifier); try { Resolver::resolveClass (classWithPropertyQualifier, context, NAMESPACE); resolved = true; if(verbose) { cout << "Test05 Error - Should not have resolved class " << endl; XmlWriter::printClassElement(classWithPropertyQualifier); } } catch (Exception& e) { resolved = false; if(verbose) cout << " Exception is correct. Should not resolve: " << e.getMessage() << endl; } PEGASUS_TEST_ASSERT(!resolved); // Repeat the test with a class property attached to a property // Create a property with a qualifier that has scope class CIMProperty propertyWithClassQualifier (CIMName ("propertyWithClassQualifier"), Boolean(true)); propertyWithClassQualifier.addQualifier(CIMQualifier (CIMName ("classQualifier"), Boolean(true))); // Create the class with this bad property CIMClass classWithBadProperty(CIMName ("classWithBadProperty")); classWithBadProperty .addProperty(CIMProperty(keyProperty)) .addProperty(CIMProperty(propertyWithClassQualifier)) .addMethod(CIMMethod(CIMName ("isActive"), CIMTYPE_BOOLEAN) .addParameter(CIMParameter(CIMName ("hostname"), CIMTYPE_STRING))); if(verbose) XmlWriter::printClassElement(classWithBadProperty); try { Resolver::resolveClass (classWithBadProperty, context, NAMESPACE); resolved = true; } catch (Exception& e) { resolved = false; if(verbose) cout << " Exception is correct. Should not resolve: " << e.getMessage() << endl; } PEGASUS_TEST_ASSERT(!resolved); // Test that an association class passes the qualifier tests // Create Properties and references with Key qualifier CIMClass classAssoc(CIMName ("classAssoc")); try { classAssoc .addQualifier(CIMQualifier(CIMName ("Association"), Boolean(true))) .addProperty(CIMProperty(CIMName ("ref1"), CIMObjectPath("YourClass.key1=\"fred\""),0, CIMName ("refClassName"))) .addProperty(CIMProperty(CIMName ("ref2"), CIMObjectPath("MyClass.key1=\"fred\""), 0, CIMName ("refClassName"))) ; } catch (Exception& e) { cout << "Class Creation exception: " << e.getMessage() << endl; exit(1); } if(verbose) XmlWriter::printClassElement(classAssoc); try { Resolver::resolveClass (classAssoc, context, NAMESPACE); resolved = true; } catch (Exception& e) { resolved = false; if(verbose) cout << " Exception is Error: Should Resolve correctly: " << e.getMessage() << endl; } PEGASUS_TEST_ASSERT(resolved); delete context; if(verbose) cout << "End Test05" << endl;}// Test for create class with superclass defined but no superclassvoid test06(){ if(verbose) cout << "Test06-Creating class with no superclass - causes exception" << endl; const CIMNamespaceName NAMESPACE = CIMNamespaceName ("/ttt"); Boolean resolved = false; SimpleDeclContext* context = new SimpleDeclContext; CIMQualifierDecl key(CIMName ("key"),Boolean(true), (CIMScope::PROPERTY + CIMScope::REFERENCE), CIMFlavor::TOSUBCLASS); context->addQualifierDecl(NAMESPACE, key); CIMProperty keyProperty(CIMName ("keyProperty"), Boolean(true)); keyProperty.addQualifier(CIMQualifier(CIMName ("key"), Boolean(true))); CIMClass subClass(CIMName ("SubClass"), CIMName ("SuperClass")); subClass .addProperty(CIMProperty(keyProperty)) .addProperty(CIMProperty(CIMName ("message"), String("Hello"))) .addMethod(CIMMethod(CIMName ("isActive"), CIMTYPE_BOOLEAN) .addParameter(CIMParameter(CIMName ("hostname"), CIMTYPE_STRING))); try { Resolver::resolveClass (subClass, context, NAMESPACE); resolved = true; } catch (Exception& e) { resolved = false; if(verbose) cout << " Exception is correct. Should not resolve " << e.getMessage() << endl; // ATTN-KS-P3 - Could add test for correct exception message here. // should be INVALID_SUPERCLASS } PEGASUS_TEST_ASSERT(!resolved); delete context;}// Test to confirm that nonoverridable qualifiers cannot be propagated.void test07(){ if (verbose ) cout << "ATTN In process" << endl; if(verbose) cout << "Test07- Cannot put nonoverridable qualifiers in subclass" << endl; }//ATTN: KS P1 Mar 7 2002. Add tests propagation qual, method, propertys as follows:// Confirm that qualifiers are propagated correctly based on flavors// Confirm that properties and methods are propagated correctly based on flavors// int main(int argc, char** argv){ verbose = getenv("PEGASUS_TEST_VERBOSE"); try { test01(); test02(); //test03(); test04(); test05(); test06(); // Test for no superclass test07(); // Confirm noverridable qualifier cannot be in subclass } catch (Exception& e) { cout << "Exception: " << e.getMessage() << endl; exit(1); } cout << argv[0] << " +++++ passed all tests" << endl; return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -