void CompareClasses( CIMRepository& r1, CIMRepository& r2, const CIMNamespaceName& namespaceName) { Array<CIMName> classNames1 = r1.enumerateClassNames(namespaceName); Array<CIMName> classNames2 = r2.enumerateClassNames(namespaceName); BubbleSort(classNames1); BubbleSort(classNames2); PEGASUS_TEST_ASSERT(classNames1 == classNames2); for (Uint32 i = 0; i < classNames1.size(); i++) { CIMClass class1 = r1.getClass(namespaceName, classNames1[i]); CIMClass class2 = r2.getClass(namespaceName, classNames2[i]); if (verbose) { cout << "testing class " << namespaceName.getString() << "/"; cout << classNames1[i].getString() << "..." << endl; } if (!class1.identical(class2)) { PutClass("file1", class1); PutClass("file2", class2); cout << "========================================================="; cout << "========================================================="; cout << endl; cout << "ERROR: not identical! - "; cout << "ERROR FOUND testing class: " << namespaceName.getString(); cout << "/"; cout << classNames1[i].getString(); cout << " .... differences follow:" << endl << endl; if (system("diff file1 file2") == -1) { cout << "Error: system(\"diff file1 file2\") failed." << endl; } if (verbose) { XmlWriter::printClassElement(class1, cout); XmlWriter::printClassElement(class2, cout); } failures++; } } }
void testClassTransfer( CIMRepository& oldRepository, CIMRepository& newRepository, const CIMNamespaceName& ns, const CIMName& className) { CIMClass c1 = oldRepository.getClass(ns, className); CIMClass c2 = newRepository.getClass(ns, className); PEGASUS_TEST_ASSERT(c1.identical(c2)); }
void Test01(Uint32 mode) { String repositoryRoot; const char* tmpDir = getenv ("PEGASUS_TMP"); if (tmpDir == NULL) { repositoryRoot = "."; } else { repositoryRoot = tmpDir; } repositoryRoot.append("/repository"); FileSystem::removeDirectoryHier(repositoryRoot); CIMRepository r (repositoryRoot, mode); // Create a namespace: const CIMNamespaceName NAMESPACE = CIMNamespaceName ("zzz"); r.createNameSpace(NAMESPACE); // Create a qualifier (and read it back): CIMQualifierDecl q1(CIMName ("abstract"), false, CIMScope::CLASS); r.setQualifier(NAMESPACE, q1); CIMConstQualifierDecl q2 = r.getQualifier(NAMESPACE, CIMName ("abstract")); PEGASUS_TEST_ASSERT(q1.identical(q2)); // Create two simple classes: CIMClass class1(CIMName ("Class1")); class1.addQualifier( CIMQualifier(CIMName ("abstract"), true, CIMFlavor::DEFAULTS)); CIMClass class2(CIMName ("Class2"), CIMName ("Class1")); r.createClass(NAMESPACE, class1); r.createClass(NAMESPACE, class2); // Enumerate the class names: Array<CIMName> classNames = r.enumerateClassNames(NAMESPACE, CIMName(), true); BubbleSort(classNames); PEGASUS_TEST_ASSERT(classNames.size() == 2); PEGASUS_TEST_ASSERT(classNames[0] == "Class1"); PEGASUS_TEST_ASSERT(classNames[1] == "Class2"); // Get the classes and determine if they are identical with input CIMClass c1 = r.getClass(NAMESPACE, CIMName ("Class1"), true, true, false); CIMClass c2 = r.getClass(NAMESPACE, CIMName ("Class2"), true, true, false); PEGASUS_TEST_ASSERT(c1.identical(class1)); PEGASUS_TEST_ASSERT(c1.identical(class1)); Array<CIMClass> classes = r.enumerateClasses(NAMESPACE, CIMName (), true, true, true); // Attempt to delete Class1. It should fail since the class has // children. try { r.deleteClass(NAMESPACE, CIMName ("Class1")); } catch (CIMException& e) { PEGASUS_TEST_ASSERT(e.getCode() == CIM_ERR_CLASS_HAS_CHILDREN); } // Delete all classes created here: r.deleteClass(NAMESPACE, CIMName ("Class2")); r.deleteClass(NAMESPACE, CIMName ("Class1")); // Be sure the classes are really gone: try { CIMClass c1 = r.getClass( NAMESPACE, CIMName ("Class1"), true, true, true); PEGASUS_TEST_ASSERT(false); } catch (CIMException& e) { PEGASUS_TEST_ASSERT(e.getCode() == CIM_ERR_NOT_FOUND); } try { CIMClass c2 = r.getClass( NAMESPACE, CIMName ("Class2"), true, true, true); PEGASUS_TEST_ASSERT(false); } catch (CIMException& e) { PEGASUS_TEST_ASSERT(e.getCode() == CIM_ERR_NOT_FOUND); } FileSystem::removeDirectoryHier(repositoryRoot); }
void TestAssociations(CIMRepository& r) { String nameSpace = "root"; { CIMObjectPath instanceName = CIMObjectPath ("X.key=\"John Smith\""); Array<CIMObjectPath> names = r.associatorNames( nameSpace, instanceName, CIMName ("A"), CIMName ("Y"), "left", "right"); assert(names.size() == 1); Boolean cond = names[0] == CIMObjectPath("Y.key=\"John Jones\""); assert(cond); } { CIMObjectPath instanceName = CIMObjectPath ("X.key=\"John Smith\""); Array<CIMObject> result = r.associators( nameSpace, instanceName, CIMName ("a"), CIMName ("y"), "LEFT", "RIGHT"); assert(result.size() == 1); CIMObjectPath cimReference = result[0].getPath (); CIMInstance cimInstance = CIMInstance(result[0]); CIMClass tmpClass = r.getClass(nameSpace, cimInstance.getClassName()); CIMObjectPath tmpInstanceName = cimInstance.buildPath(tmpClass); Boolean t = tmpInstanceName == CIMObjectPath("Y.key=\"John Jones\""); assert(t); // result[0].print(); } { CIMObjectPath instanceName = CIMObjectPath ("X.key=\"John Smith\""); Array<CIMObjectPath> result = r.referenceNames( nameSpace, instanceName, CIMName ("A"), "left"); assert(result.size() == 1); CIMObjectPath tmp = CIMObjectPath ("A." "left=\"x.key=\\\"John Smith\\\"\"," "right=\"y.key=\\\"John Jones\\\"\""); Boolean cond = (result[0] == tmp); assert(cond); } { CIMObjectPath instanceName = CIMObjectPath ("X.key=\"John Smith\""); Array<CIMObject> result = r.references( nameSpace, instanceName, CIMName ("A"), "left"); assert(result.size() == 1); CIMClass tmpClass = r.getClass( nameSpace, CIMInstance(result[0]).getClassName()); CIMObjectPath tmpInstanceName = CIMInstance(result[0]).buildPath(tmpClass); CIMObjectPath tmp = CIMObjectPath ("A." "left=\"x.key=\\\"John Smith\\\"\"," "right=\"y.key=\\\"John Jones\\\"\""); Boolean cond = (tmpInstanceName == tmp); assert(cond); } // Delete all the object we created: { // First delete the association: CIMObjectPath assocInstanceName = CIMObjectPath ("A." "left=\"x.key=\\\"John Smith\\\"\"," "right=\"y.key=\\\"John Jones\\\"\""); r.deleteInstance(nameSpace, assocInstanceName); } }