📄 repository2.cpp
字号:
PEGASUS_TEST_ASSERT(namedInstances.size() == 1); PEGASUS_TEST_ASSERT(namedInstances[0].identical(inst1)); #ifndef PEGASUS_DISABLE_REPOSITORY_INSTANCE_FILTER // // Test enumerating with classOrigin false // namedInstances = r.enumerateInstancesForSubtree(NS, CIMName ("SuperClass"),true, false, true, false); PEGASUS_TEST_ASSERT(namedInstances.size() == 2); for (Uint32 i = 0 ; i < namedInstances.size() ; i++) { // Check all properties for classorigin for (Uint32 j = 0 ; j < namedInstances[i].getPropertyCount() ; j++) { CIMProperty p = namedInstances[i].getProperty(j); } } // // Repeat the above for enumerateinstancesForClass // namedInstances = r.enumerateInstancesForClass(NS, CIMName("SuperClass"), false, true, false); PEGASUS_TEST_ASSERT(namedInstances.size() == 1); for (Uint32 i = 0 ; i < namedInstances.size() ; i++) { // Check all properties for classorigin for (Uint32 j = 0 ; j < namedInstances[i].getPropertyCount() ; j++) { CIMProperty p = namedInstances[i].getProperty(j); } } // // Test for qualifier removal from enumerateinstances // namedInstances = r.enumerateInstancesForSubtree(NS, CIMName ("SuperClass"),true, false, false, false); PEGASUS_TEST_ASSERT(namedInstances.size() == 2); for (Uint32 i = 0 ; i < namedInstances.size() ; i++) { PEGASUS_TEST_ASSERT(namedInstances[i].getQualifierCount() == 0); // Check all properties for qualifiers for (Uint32 j = 0 ; j < namedInstances[i].getPropertyCount() ; j++) { CIMProperty p = namedInstances[i].getProperty(j); PEGASUS_TEST_ASSERT(p.getQualifierCount() == 0); } } // // Repeat the above for the enumerateinstancesFor Class // namedInstances = r.enumerateInstancesForClass(NS, CIMName("SuperClass"), false, false, false); PEGASUS_TEST_ASSERT(namedInstances.size() == 1); for (Uint32 i = 0 ; i < namedInstances.size() ; i++) { PEGASUS_TEST_ASSERT(namedInstances[i].getQualifierCount() == 0); // Check all properties for qualifiers for (Uint32 j = 0 ; j < namedInstances[i].getPropertyCount() ; j++) { CIMProperty p = namedInstances[i].getProperty(j); PEGASUS_TEST_ASSERT(p.getQualifierCount() == 0); } } // ******************************************************************* // // Test for property filtering // // ******************************************************************* // // test with empty property list // CIMPropertyList pl1(pls_empty); // deepInheritance=true,localOnly=false, // includeQualifiers=false,includeClassOrigin=false, namedInstances = r.enumerateInstancesForSubtree(NS, CIMName ("SuperClass"),true, false, false, false, pl1); PEGASUS_TEST_ASSERT(namedInstances.size() == 2); for (Uint32 i = 0 ; i < namedInstances.size() ; i++) { // Check all properties for qualifiers for (Uint32 j = 0 ; j < namedInstances[i].getPropertyCount() ; j++) { PEGASUS_TEST_ASSERT(namedInstances[i].findProperty("key") == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(namedInstances[i].findProperty("ratio") == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(namedInstances[i].findProperty("message") == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(namedInstances[i].getPropertyCount() == 0); } } // // test with property list with property "ratio" // Array<CIMName> pls1; pls1.append(CIMName("ratio")); pl1.clear(); pl1.set(pls1); namedInstances = r.enumerateInstancesForSubtree(NS, CIMName ("SuperClass"),true, false, false, false, pl1); PEGASUS_TEST_ASSERT(namedInstances.size() == 2); for (Uint32 i = 0 ; i < namedInstances.size() ; i++) { // Check all properties for qualifiers for (Uint32 j = 0 ; j < namedInstances[i].getPropertyCount() ; j++) { PEGASUS_TEST_ASSERT(namedInstances[i].findProperty("key") == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(namedInstances[i].findProperty("ratio") != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(namedInstances[i].findProperty("message") == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(namedInstances[i].getPropertyCount() == 1); } } // // retest with two entries in the list. // pls1.append(CIMName("message")); pl1.clear(); pl1.set(pls1); // deepInheritance=true,localOnly=false, // includeQualifiers=false,includeClassOrigin=false, namedInstances = r.enumerateInstancesForSubtree(NS, CIMName ("SuperClass"),true, false, false, false, pl1); PEGASUS_TEST_ASSERT(namedInstances.size() == 2); for (Uint32 i = 0 ; i < namedInstances.size() ; i++) { // Check all properties for qualifiers for (Uint32 j = 0 ; j < namedInstances[i].getPropertyCount() ; j++) { PEGASUS_TEST_ASSERT(namedInstances[i].findProperty("key") == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(namedInstances[i].findProperty("ratio") != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(namedInstances[i].findProperty("message") != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(namedInstances[i].getPropertyCount() == 2); } } // // retest with two entries in the list and localOnly=true. // results should be same as with LocalOnly=false since it // has been deprecated. // pls1.append(CIMName("message")); pl1.clear(); pl1.set(pls1); // deepInheritance=true,localOnly=true, // includeQualifiers=false,includeClassOrigin=false, namedInstances = r.enumerateInstancesForSubtree(NS, CIMName ("SuperClass"),true, true, false, false, pl1); PEGASUS_TEST_ASSERT(namedInstances.size() == 2); for (Uint32 i = 0 ; i < namedInstances.size() ; i++) { // Check all properties for qualifiers for (Uint32 j = 0 ; j < namedInstances[i].getPropertyCount() ; j++) { PEGASUS_TEST_ASSERT(namedInstances[i].findProperty("key") == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(namedInstances[i].findProperty("ratio") != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(namedInstances[i].findProperty("message") != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(namedInstances[i].getPropertyCount() == 2); } } // // Test with an invalid property in the list. It should be ignored // and the results should be identical to the previous. // pls1.append(CIMName("herroyalhighnessofyork")); pl1.clear(); pl1.set(pls1); namedInstances = r.enumerateInstancesForSubtree(NS, CIMName ("SuperClass"),true, false, false, false, pl1); PEGASUS_TEST_ASSERT(namedInstances.size() == 2); for (Uint32 i = 0 ; i < namedInstances.size() ; i++) { // Check all properties for qualifiers for (Uint32 j = 0 ; j < namedInstances[i].getPropertyCount() ; j++) { PEGASUS_TEST_ASSERT(namedInstances[i].findProperty("key") == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(namedInstances[i].findProperty("ratio") != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(namedInstances[i].findProperty("message") != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(namedInstances[i].getPropertyCount() == 2); } }#endif // PEGASUS_DISABLE_REPOSITORY_INSTANCE_FILTER // // -- Modify one of the instances: // CIMInstance modifiedInst0(CIMName ("SuperClass")); modifiedInst0.addProperty(CIMProperty(CIMName ("key"), Uint32(111))); modifiedInst0.addProperty(CIMProperty(CIMName ("message"), String("Goodbye World"))); modifiedInst0.setPath (instanceNames[0]); r.modifyInstance(NS, modifiedInst0); // // -- Get instance back and see that it is the same as modified one: // CIMInstance tmpInstance = r.getInstance(NS, CIMObjectPath ("SuperClass.key=111"), false, true, true); tmpInstance.setPath (instanceNames[0]); //XmlWriter::printInstanceElement(tmpInstance, cout); //XmlWriter::printInstanceElement(modifiedInst0, cout); PEGASUS_TEST_ASSERT(tmpInstance.identical(modifiedInst0)); // // -- Now modify the "message" property: // CIMValue messageValue = r.getProperty(NS, CIMObjectPath ("SuperClass.key=111"), CIMName ("message")); String message; messageValue.get(message); PEGASUS_TEST_ASSERT(message == "Goodbye World"); r.setProperty(NS, CIMObjectPath ("SuperClass.key=111"), CIMName ("message"), CIMValue(String("Hello World"))); messageValue = r.getProperty( NS, CIMObjectPath ("SuperClass.key=111"), CIMName ("message")); messageValue.get(message); PEGASUS_TEST_ASSERT(message == "Hello World"); // // Future test - modify key property and attempt to write // TODO // // -- Attempt to modify a key property: // Boolean failed = false; try { r.setProperty(NS, CIMObjectPath ("SuperClass.key=111"), CIMName ("key"), Uint32(999)); } catch (CIMException& e) { PEGASUS_TEST_ASSERT(e.getCode() == CIM_ERR_FAILED); failed = true; } PEGASUS_TEST_ASSERT(failed); // // -- Delete the instances: // r.deleteInstance(NS, CIMObjectPath ("SuperClass.key=111")); r.deleteInstance(NS, CIMObjectPath ("SubClass.key=222")); // // -- Delete the qualifier: // r.deleteQualifier(NS, CIMName ("key")); r.deleteQualifier(NS, CIMName ("description")); r.deleteQualifier(NS, CIMName ("junk")); // // -- Clean up classes: // r.deleteClass(NS, CIMName ("SubClass")); r.deleteClass(NS, CIMName ("SuperClass")); r.deleteNameSpace(NS);}void TestQualifiers(Uint32 mode){ // // -- Create repository and "xyz" namespace: // CIMRepository r (repositoryRoot, mode); const CIMNamespaceName NS = CIMNamespaceName ("TestQualifiers"); try { r.createNameSpace(NS); } catch (AlreadyExistsException&) { // Ignore this! } // // -- Construct a qualifier declaration: // CIMQualifierDecl q(CIMName ("abstract"), true, CIMScope::CLASS); r.setQualifier(NS, q); CIMQualifierDecl qq = r.getQualifier(NS, CIMName ("abstract")); PEGASUS_TEST_ASSERT(qq.identical(q)); PEGASUS_TEST_ASSERT(q.identical(qq)); // // -- Delete the qualifier: // r.deleteQualifier(NS, CIMName ("abstract")); // // -- Delete the namespace: // r.deleteNameSpace(NS);}int main(int argc, char** argv){ verbose = getenv("PEGASUS_TEST_VERBOSE"); const char* tmpDir = getenv ("PEGASUS_TMP"); if (tmpDir == NULL) { repositoryRoot = "."; } else { repositoryRoot = tmpDir; } repositoryRoot.append("/repository"); try { Uint32 mode; if (!strcmp(argv[1],"XML") ) { mode = CIMRepository::MODE_XML; if (verbose) cout << argv[0]<< ": using XML mode repository" << endl; } else if (!strcmp(argv[1],"BIN") ) { mode = CIMRepository::MODE_BIN; if (verbose) cout << argv[0]<< ": using BIN mode repository" << endl; } else { cout << argv[0] << ": invalid argument: " << argv[1] << endl; return 0; } TestNameSpaces(mode); TestCreateClass(mode); TestQualifiers(mode); } catch (Exception& e) { cout << argv[0] << " " << argv[1] << " " << e.getMessage() << endl; exit(1); } cout << argv[0] << " " << argv[1] << " +++++ passed all tests" << endl; return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -