📄 resolve.cpp
字号:
/* ATTN: Add the following qualifier to the superclass. Needs value or Null indicator. Try for Null to see propagation of null .addQualifier(CIMQualifier(CIMName ("arrayValue"))) */ // Add our qualifiers and properties to superclass. superClass // This qualifier should not propagate. .addQualifier(CIMQualifier(CIMName ("Abstract"), Boolean(true))) .addQualifier(CIMQualifier(CIMName ("q1"), String("BonJour"))) .addQualifier(CIMQualifier(CIMName ("notToSubclass"), true)) .addQualifier(CIMQualifier(CIMName ("toSubclass"), String("default"))) .addQualifier(CIMQualifier(CIMName ("toSubclassOverriddable"), String("superClass"))) .addQualifier(CIMQualifier(CIMName ("associat"), Boolean(true))) .addProperty(CIMProperty(keyProperty)) .addProperty(CIMProperty(CIMName ("message"), String("Hello"))) .addProperty(CIMProperty(CIMName ("onlyInSuperClass"), String("Hello"))) .addProperty(CIMProperty(propertyWithQualifier)) // This method to demo propagation of method to subclass .addMethod(CIMMethod(CIMName ("methodinSuperclass"), CIMTYPE_BOOLEAN) .addParameter(CIMParameter(CIMName ("hostname"), CIMTYPE_STRING)) .addParameter(CIMParameter(CIMName ("port"), CIMTYPE_UINT32))); ; // ATTN: Add case where property in superclass has // more qualifiers than property in subclass. // add the superclass and resolve it. context->addClass(NAMESPACE, superClass); Resolver::resolveClass (superClass, context, NAMESPACE); // Create the subclass CIMClass subClass(CIMName ("SubClass"), CIMName ("SuperClass")); CIMProperty sndPropertyWithQualifier(CIMName ("sndWithQualifier"), Boolean(true)); sndPropertyWithQualifier .addQualifier(CIMQualifier(CIMName ("toSubclass"), String("default"))); subClass .addQualifier(CIMQualifier(CIMName ("q1"), String("Hello"))) .addQualifier(CIMQualifier(CIMName ("q3"), Uint32(99))) .addQualifier(CIMQualifier(CIMName ("toSubclassOverriddable"), String("subClass"))) // the key property should be propagated so do not put in subclass. .addProperty(CIMProperty(CIMName ("message"), String("Goodbye"))) .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) { cout << "Classes before resolution " << endl; XmlWriter::printClassElement(superClass); XmlWriter::printClassElement(subClass); } try{ Resolver::resolveClass (subClass, context, NAMESPACE); resolved = true; } catch (Exception& e) { resolved = false; cerr << " Test 02 Did not resolve " << e.getMessage() << endl; } if(verbose) { cout << "Classes after resolution " << endl; XmlWriter::printClassElement(superClass); XmlWriter::printClassElement(subClass); } // Resolved. Now thoroughly test the results PEGASUS_TEST_ASSERT(resolved); // Should have correctly resolved. // Test the results of the resolve of the subclass and superclass // **************************************************8 // Qualifier Tests on superClass and SubClass // ************************************************** if (verbose) cout << "Tst02 - Test Qualifiers" << endl; // Confirm that the qualifiers exist in the superclass that should PEGASUS_TEST_ASSERT(superClass.findQualifier(CIMName ("Abstract")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(superClass.findQualifier(CIMName ("ABSTRACT")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(superClass.findQualifier(CIMName ("Q3")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(superClass.findQualifier(CIMName ("Q1")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(superClass.findQualifier(CIMName ("notToSubclass")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(superClass.findQualifier(CIMName ("toSubClassOverriddable")) != PEG_NOT_FOUND); CIMQualifier qt = superClass.getQualifier(superClass.findQualifier (CIMName ("Abstract"))); // Determine that all required qualifiers exist in the subclass PEGASUS_TEST_ASSERT(subClass.findQualifier(CIMName ("q1")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(subClass.findQualifier(CIMName ("Q3")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(subClass.findQualifier(CIMName ("toSubClass")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(subClass.findQualifier(CIMName ("toSubClassOverriddable")) != PEG_NOT_FOUND); // Confirm that qualifiers that should not be propagated are not. PEGASUS_TEST_ASSERT(subClass.findQualifier(CIMName ("notToSubclass")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(subClass.findQualifier(CIMName ("Abstract")) == PEG_NOT_FOUND); // ATTN: Determine if correct value is in the qualifiers in subclass // Need to add a null value qualifier and test its propagation // Need to add an array qualifier and test its propagation. // Uint32 pos = subclass.findQualifier(CIMName ("Q1")); // Confirm that the value for tosubclass is still superclass and // the value for tosubclassoverride is now subclass // ************************************************** // Property Tests // ************************************************** if (verbose) cout << "Tst02 - Test Properties" << endl; // Confirm that correct properties exist in superclass PEGASUS_TEST_ASSERT (superClass.findProperty(CIMName ("message")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT (superClass.findProperty(CIMName ("onlyInSuperclass")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT (superClass.findProperty(CIMName ("withQualifier")) != PEG_NOT_FOUND); //Confirm that correct properties exist in subclass. PEGASUS_TEST_ASSERT (subClass.findProperty(CIMName ("message")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT (subClass.findProperty(CIMName ("count")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT (subClass.findProperty(CIMName ("onlyInSuperclass")) != PEG_NOT_FOUND); // Confirm that all properties in superclass have correct classorigin for(Uint32 i = 0; i < superClass.getPropertyCount(); i++) { CIMProperty p = superClass.getProperty(i); PEGASUS_TEST_ASSERT(p.getClassOrigin().equal (CIMName ("SuperClass"))); } if (verbose) cout << "Tst02 - Test Properties Move Value" << endl; // Determine if we moved the value in the property from superclass. { Uint32 pos = subClass.findProperty (CIMName ("onlyInSuperclass")); PEGASUS_TEST_ASSERT(pos != PEG_NOT_FOUND); // It was propagated to subclass. Now get property and test CIMProperty p = subClass.getProperty(pos); PEGASUS_TEST_ASSERT(p.getPropagated()); // Confirm classorigin OK and value not changed. PEGASUS_TEST_ASSERT(p.getClassOrigin() == CIMName ("SuperClass")); CIMValue v = p.getValue(); PEGASUS_TEST_ASSERT(v.getType() == CIMTYPE_STRING); String s; v.get(s); PEGASUS_TEST_ASSERT(s == "Hello"); // Assert correct value moved // test that value same in subclass and superclass. Uint32 possc = subClass.findProperty (CIMName ("onlyInSuperclass")); PEGASUS_TEST_ASSERT(possc != PEG_NOT_FOUND); CIMProperty psc = subClass.getProperty(pos); PEGASUS_TEST_ASSERT(psc.getPropagated()); PEGASUS_TEST_ASSERT(psc.getClassOrigin() == CIMName ("SuperClass")); CIMValue vsc = p.getValue(); PEGASUS_TEST_ASSERT(vsc.getType() == CIMTYPE_STRING); String ssc; vsc.get(ssc); PEGASUS_TEST_ASSERT(s == "Hello"); // Assert correct value moved PEGASUS_TEST_ASSERT (vsc == v); } // determine if we moved the property with ke qualifier from superclass if (verbose) cout << "Tst02 - Test Properties Move with key" << endl; { PEGASUS_TEST_ASSERT (subClass.findProperty(CIMName ("keyProperty")) != PEG_NOT_FOUND); Uint32 pos = subClass.findProperty(CIMName ("keyProperty")); PEGASUS_TEST_ASSERT(pos != PEG_NOT_FOUND); CIMProperty p = subClass.getProperty(pos); PEGASUS_TEST_ASSERT(p.getPropagated()); PEGASUS_TEST_ASSERT(p.getClassOrigin() == CIMName ("SuperClass")); CIMValue v = p.getValue(); PEGASUS_TEST_ASSERT(v.getType() == CIMTYPE_BOOLEAN); Boolean b; v.get(b); PEGASUS_TEST_ASSERT(b == true); } // Determine if we moved the qualifier to subclass with the property // Note that the identical test won't work since propagated set.. if (verbose) cout << "Tst02 - Test Properties with qualifier" << endl; { Uint32 pos = subClass.findProperty(CIMName ("withQualifier")); PEGASUS_TEST_ASSERT(pos != PEG_NOT_FOUND); CIMProperty p = subClass.getProperty(pos); PEGASUS_TEST_ASSERT(p.getClassOrigin() == CIMName ("SuperClass")); PEGASUS_TEST_ASSERT(p.getPropagated()); PEGASUS_TEST_ASSERT(p.getType() == CIMTYPE_BOOLEAN); CIMValue pv = p.getValue(); PEGASUS_TEST_ASSERT(pv.getType() == CIMTYPE_BOOLEAN); Boolean b; pv.get(b); PEGASUS_TEST_ASSERT(b == true); PEGASUS_TEST_ASSERT (p.findQualifier(CIMName ("toSubClass")) != PEG_NOT_FOUND); // Now determine if the value moved. PEGASUS_TEST_ASSERT(p.findQualifier(CIMName ("toSubClass")) != PEG_NOT_FOUND); Uint32 qpos = p.findQualifier(CIMName ("toSubClass")); CIMQualifier q = p.getQualifier(qpos); CIMValue v = q.getValue(); PEGASUS_TEST_ASSERT(v.getType() == CIMTYPE_STRING); String s; v.get(s); PEGASUS_TEST_ASSERT(s == "default"); // same as value in superclass } // ************************************************ // Test the methods propagation here // *********************************************** if (verbose) cout << "Tst02 - Test Methods" << endl; { { // Test method in superclass // doublecheck the type and that parameters are in place PEGASUS_TEST_ASSERT(superClass.findMethod(CIMName ("methodInSuperclass")) != PEG_NOT_FOUND); Uint32 mpos = superClass.findMethod (CIMName ("methodInSuperclass")); PEGASUS_TEST_ASSERT(mpos != PEG_NOT_FOUND); CIMMethod m = superClass.getMethod(mpos); PEGASUS_TEST_ASSERT(!m.getPropagated()); // should not be propagated PEGASUS_TEST_ASSERT(m.getType() == CIMTYPE_BOOLEAN); // Now confirm the parameters PEGASUS_TEST_ASSERT(m.findParameter(CIMName ("hostname")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(m.findParameter(CIMName ("port")) != PEG_NOT_FOUND); // Test characteristics of first parameter Uint32 ppos = m.findParameter(CIMName ("hostname")); PEGASUS_TEST_ASSERT(ppos != PEG_NOT_FOUND); CIMParameter mp1 = m.getParameter(m.findParameter (CIMName ("hostname"))); PEGASUS_TEST_ASSERT(mp1.getName() == CIMName ("hostname")); /* ATTN: KS P3 23 Mar 2002 Want to test values here CIMValue vmp1 = mp1.getValue(); PEGASUS_TEST_ASSERT(vmp1.getType() == CIMTYPE_Boolean); */ //PEGASUS_TEST_ASSERT(p1.getQualifierCount() == 0); // Test characteristics of second parameter Uint32 ppos2 = m.findParameter(CIMName ("port")); PEGASUS_TEST_ASSERT(ppos2 != PEG_NOT_FOUND); CIMParameter mp2 = m.getParameter(m.findParameter (CIMName ("port"))); PEGASUS_TEST_ASSERT(mp2.getName() == CIMName ("port")); PEGASUS_TEST_ASSERT(mp2.getType() == CIMTYPE_UINT32); // Test for second method PEGASUS_TEST_ASSERT(superClass.findMethod(CIMName ("methodInSuperclass")) != PEG_NOT_FOUND); } // Repeat the above for the subclass and test propagated. // ATTN: KS 22 March Complete this P2 - Testing of method propagation { PEGASUS_TEST_ASSERT(subClass.findMethod(CIMName ("isActive")) != PEG_NOT_FOUND); Uint32 mpos = subClass.findMethod(CIMName ("isActive")); CIMMethod m = subClass.getMethod(mpos); PEGASUS_TEST_ASSERT(!m.getPropagated()); // should not be propagated //ATTN: P3-KS-23March 2002 - Tests can be added for parms, etc. // Not absolutely necessary. } // Test for the method propagated from superclass to subclass // Confirm that propagated and marked propagated. { PEGASUS_TEST_ASSERT(subClass.findMethod (CIMName ("methodInSuperclass")) != PEG_NOT_FOUND); Uint32 mpos = subClass.findMethod (CIMName ("methodInSuperclass")); PEGASUS_TEST_ASSERT(mpos != PEG_NOT_FOUND); CIMMethod m = subClass.getMethod(mpos); PEGASUS_TEST_ASSERT(m.getPropagated()); // should not be propagated PEGASUS_TEST_ASSERT(m.getType() == CIMTYPE_BOOLEAN); // Now confirm the parameters PEGASUS_TEST_ASSERT(m.findParameter(CIMName ("hostname")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(m.findParameter(CIMName ("port")) != PEG_NOT_FOUND); // Test characteristics of first parameter Uint32 ppos = m.findParameter(CIMName ("hostname")); PEGASUS_TEST_ASSERT(ppos != PEG_NOT_FOUND); CIMParameter mp1 = m.getParameter(m.findParameter (CIMName ("hostname"))); PEGASUS_TEST_ASSERT(mp1.getName() == CIMName ("hostname")); /* ATTN: Want to test values here CIMValue vmp1 = mp1.getValue(); PEGASUS_TEST_ASSERT(vmp1.getType() == CIMTYPE_Boolean); */ //PEGASUS_TEST_ASSERT(p1.getQualifierCount() == 0); // Test characteristics of second parameter Uint32 ppos2 = m.findParameter(CIMName ("port")); PEGASUS_TEST_ASSERT(ppos2 != PEG_NOT_FOUND); CIMParameter mp2 = m.getParameter(m.findParameter (CIMName ("port"))); PEGASUS_TEST_ASSERT(mp2.getName() == CIMName ("port"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -