int main() { const char* pegasusHome = getenv("PEGASUS_HOME"); if (!pegasusHome) { cerr << "PEGASUS_HOME environment variable not set" << endl; exit(1); } String repositoryRoot = pegasusHome; repositoryRoot.append("/repository"); CIMRepository* repository = new CIMRepository( repositoryRoot, CIMRepository::MODE_BIN); ConfigManager::setPegasusHome(pegasusHome); // -- Create repository and namespaces: CreateRepository(*repository); try { HandlerTable handlerTable; String handlerId = "snmpIndicationHandler"; CIMHandler* handler = handlerTable.getHandler(handlerId, repository); PEGASUS_TEST_ASSERT(handler != 0); TestExceptionHandling(handler); // // -- Clean up classes: // repository->deleteClass(NS, testClass1); repository->deleteClass(NS, testClass2); repository->deleteClass(NS, testClass3); repository->deleteClass(NS, testClass4); repository->deleteClass(NS, testClass5); repository->deleteClass(NS, testClass6); repository->deleteClass(NS, testClass7); repository->deleteClass(NS, testClass8); // // -- Delete the qualifier: // repository->deleteQualifier(NS, CIMName ("MappingStrings")); repository->deleteQualifier(NS, CIMName ("NotMappingStrings")); repository->deleteNameSpace(NS); } catch(Exception& e) { PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl); exit(1); } delete repository; cout << "+++++ passed all tests" << endl; return 0; }
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); }