📄 testobjectnormalizer.cpp
字号:
CIMClass cimClass = repository->getClass( "test_namespace", "ClassC", true, includeClassOrigin, CIMPropertyList()); AutoPtr<NormalizerContext> nullContext(0); ObjectNormalizer normalizer( cimClass, includeQualifiers, includeClassOrigin, CIMNamespaceName("test_namespace"), nullContext); CIMObjectPath cimObjectPath; cimObjectPath.setClassName("classc"); // use lowercase. normalization should fix case // simple keys Array<CIMKeyBinding> keys; keys.append(CIMKeyBinding("property1", CIMValue(Uint32(1)))); keys.append(CIMKeyBinding("property2", CIMValue(String("Test Instance #003c")))); keys.append(CIMKeyBinding("property3", CIMValue(CIMDateTime::getCurrentDateTime()))); cimObjectPath.setKeyBindings(keys); _stopwatch.start(); CIMObjectPath normalizedObjectPath = normalizer.processInstanceObjectPath(cimObjectPath); _stopwatch.stop(); PRINT(normalizedObjectPath.toString()); PRINT("*** " << _stopwatch.getElapsed() << " milliseconds.");}// instance object path (with missing information)void Test003d(void){ PRINT("Test003d"); _stopwatch.reset(); Boolean includeQualifiers = false; Boolean includeClassOrigin = false; CIMClass cimClass = repository->getClass( "test_namespace", "ClassC", true, includeClassOrigin, CIMPropertyList()); AutoPtr<NormalizerContext> nullContext(0); ObjectNormalizer normalizer( cimClass, includeQualifiers, includeClassOrigin, CIMNamespaceName("test_namespace"), nullContext); CIMObjectPath cimObjectPath; cimObjectPath.setClassName("classc"); // use lowercase. normalization should fix case // keys Array<CIMKeyBinding> keys; keys.append(CIMKeyBinding("property1", CIMValue(Uint32(1)))); //keys.append(CIMKeyBinding("property2", CIMValue(String("Test Instance #003d")))); keys.append(CIMKeyBinding("property3", CIMValue(CIMDateTime::getCurrentDateTime()))); cimObjectPath.setKeyBindings(keys); try { _stopwatch.start(); CIMObjectPath normalizedObjectPath = normalizer.processInstanceObjectPath(cimObjectPath); _stopwatch.stop(); throw Exception("Failed to dected instance with missing keys."); } catch(CIMException & e) { _stopwatch.stop(); PRINT("expected CIMException: " << e.getMessage()); } PRINT("*** " << _stopwatch.getElapsed() << " milliseconds.");}// instance object path (with extra information)void Test003e(void){ PRINT("Test003e"); _stopwatch.reset(); Boolean includeQualifiers = false; Boolean includeClassOrigin = false; CIMClass cimClass = repository->getClass( "test_namespace", "ClassC", true, includeClassOrigin, CIMPropertyList()); AutoPtr<NormalizerContext> nullContext(0); ObjectNormalizer normalizer( cimClass, includeQualifiers, includeClassOrigin, CIMNamespaceName("test_namespace"), nullContext); CIMObjectPath cimObjectPath; cimObjectPath.setClassName("classc"); // use lowercase. normalization should fix case // simple keys Array<CIMKeyBinding> keys; keys.append(CIMKeyBinding("property1", CIMValue(Uint32(1)))); keys.append(CIMKeyBinding("property2", CIMValue(String("Test Instance #003e")))); keys.append(CIMKeyBinding("property3", CIMValue(CIMDateTime::getCurrentDateTime()))); // fake keys keys.append(CIMKeyBinding("FakeProperty1", CIMValue(String("junk")))); keys.append(CIMKeyBinding("FakeProperty2", CIMValue(String("more junk")))); cimObjectPath.setKeyBindings(keys); _stopwatch.start(); CIMObjectPath normalizedObjectPath = normalizer.processInstanceObjectPath(cimObjectPath); _stopwatch.stop(); PRINT(normalizedObjectPath.toString()); PRINT("*** " << _stopwatch.getElapsed() << " milliseconds.");}//// instance object failures//// instance object with no properties and no object pathvoid Test004a(void){ PRINT("Test004a"); _stopwatch.reset(); Boolean includeQualifiers = true; Boolean includeClassOrigin = false; CIMClass cimClass = repository->getClass( "test_namespace", "ClassC", true, includeClassOrigin, CIMPropertyList()); AutoPtr<NormalizerContext> nullContext(0); ObjectNormalizer normalizer( cimClass, includeQualifiers, includeClassOrigin, CIMNamespaceName("test_namespace"), nullContext); CIMInstance cimInstance(cimClass.getClassName()); // no properties specified // no object path specified try { _stopwatch.start(); CIMInstance normalizedInstance = normalizer.processInstance(cimInstance); _stopwatch.stop(); throw Exception("Failed to dected instance with no properties and no object path."); } catch(CIMException & e) { _stopwatch.stop(); PRINT("expected CIMException: " << e.getMessage()); } PRINT("*** " << _stopwatch.getElapsed() << " milliseconds.");}// instance object with incorrect property typevoid Test004b(void){ PRINT("Test004b"); _stopwatch.reset(); Boolean includeQualifiers = true; Boolean includeClassOrigin = false; CIMClass cimClass = repository->getClass( "test_namespace", "ClassC", true, includeClassOrigin, CIMPropertyList()); AutoPtr<NormalizerContext> nullContext(0); ObjectNormalizer normalizer( cimClass, includeQualifiers, includeClassOrigin, CIMNamespaceName("test_namespace"), nullContext); CIMInstance cimInstance(cimClass.getClassName()); // only populate keys, let the normalizer do the rest cimInstance.addProperty(CIMProperty("property1", CIMValue(Uint32(1)))); cimInstance.addProperty(CIMProperty("property2", CIMValue(String("Test Instance #004b")))); cimInstance.addProperty(CIMProperty("property3", CIMValue(CIMDateTime::getCurrentDateTime()))); // incorrect property type cimInstance.addProperty(CIMProperty("property4", CIMValue(Uint32(0)))); // should be String // no object path specified try { _stopwatch.start(); CIMInstance normalizedInstance = normalizer.processInstance(cimInstance); _stopwatch.stop(); throw Exception("Failed to detect incorrect property type."); } catch(CIMException & e) { _stopwatch.stop(); PRINT("expected CIMException: " << e.getMessage()); } PRINT("*** " << _stopwatch.getElapsed() << " milliseconds.");}//// instance object successes//// instance with class originvoid Test005a(void){ PRINT("Test005a"); _stopwatch.reset(); Boolean includeQualifiers = true; Boolean includeClassOrigin = true; CIMClass cimClass = repository->getClass( "test_namespace", "ClassC", true, includeClassOrigin, CIMPropertyList()); AutoPtr<NormalizerContext> nullContext(0); ObjectNormalizer normalizer( cimClass, includeQualifiers, includeClassOrigin, CIMNamespaceName("test_namespace"), nullContext); CIMInstance cimInstance(cimClass.getClassName()); // only populate keys, let the normalizer do the rest cimInstance.addProperty(CIMProperty("property1", CIMValue(Uint32(1)))); cimInstance.addProperty(CIMProperty("property2", CIMValue(String("Test Instance #005a")))); cimInstance.addProperty(CIMProperty("property3", CIMValue(CIMDateTime::getCurrentDateTime()))); cimInstance.addProperty(CIMProperty("property4", CIMValue(String("Pegasus TestObjectNormalizer")))); // complete object path CIMObjectPath cimObjectPath; cimObjectPath.setClassName(cimInstance.getClassName()); Array<CIMKeyBinding> keys; keys.append(CIMKeyBinding("property1", CIMValue(Uint32(1)))); keys.append(CIMKeyBinding("property2", CIMValue(String("Test Instance #005b")))); keys.append(CIMKeyBinding("property3", CIMValue(CIMDateTime::getCurrentDateTime()))); // slightly differnt value than property. who wins? cimObjectPath.setKeyBindings(keys); cimInstance.setPath(cimObjectPath); _stopwatch.start(); CIMInstance normalizedInstance = normalizer.processInstance(cimInstance); _stopwatch.stop(); if(verbose) { cout << normalizedInstance.getPath().toString() << endl; XmlWriter::printInstanceElement(normalizedInstance); } PRINT("*** " << _stopwatch.getElapsed() << " milliseconds.");}// instance with object path but no propertiesvoid Test005b(void){ PRINT("Test005b"); _stopwatch.reset(); Boolean includeQualifiers = true; Boolean includeClassOrigin = false; CIMClass cimClass = repository->getClass( "test_namespace", "ClassC", true, includeClassOrigin, CIMPropertyList()); AutoPtr<NormalizerContext> nullContext(0); ObjectNormalizer normalizer( cimClass, includeQualifiers, includeClassOrigin, CIMNamespaceName("test_namespace"), nullContext); CIMInstance cimInstance(cimClass.getClassName()); // all properties cimInstance.addProperty(CIMProperty("property1", CIMValue(Uint32(1)))); cimInstance.addProperty(CIMProperty("property2", CIMValue(String("Test Instance #005b")))); cimInstance.addProperty(CIMProperty("property3", CIMValue(CIMDateTime::getCurrentDateTime()))); cimInstance.addProperty(CIMProperty("property4", CIMValue(String("Pegasus TestObjectNormalizer")))); // complete object path CIMObjectPath cimObjectPath; cimObjectPath.setClassName(cimInstance.getClassName()); Array<CIMKeyBinding> keys; keys.append(CIMKeyBinding("property1", CIMValue(Uint32(1)))); keys.append(CIMKeyBinding("property2", CIMValue(String("Test Instance #005b")))); keys.append(CIMKeyBinding("property3", CIMValue(CIMDateTime::getCurrentDateTime()))); // slightly differnt value than property. who wins? cimObjectPath.setKeyBindings(keys); cimInstance.setPath(cimObjectPath); _stopwatch.start(); CIMInstance normalizedInstance = normalizer.processInstance(cimInstance); _stopwatch.stop(); if(verbose) { cout << normalizedInstance.getPath().toString() << endl; XmlWriter::printInstanceElement(normalizedInstance); } PRINT("*** " << _stopwatch.getElapsed() << " milliseconds.");}// instance with qualifiersvoid Test005c(void){ PRINT("Test005c"); _stopwatch.reset(); Boolean includeQualifiers = true; Boolean includeClassOrigin = false; CIMClass cimClass = repository->getClass( "test_namespace", "ClassC", true, includeClassOrigin, CIMPropertyList()); AutoPtr<NormalizerContext> nullContext(0); ObjectNormalizer normalizer( cimClass, includeQualifiers, includeClassOrigin, CIMNamespaceName("test_namespace"), nullContext); CIMInstance cimInstance(cimClass.getClassName()); cimInstance.addQualifier(CIMQualifier("Description", String("This object qualifier value comes from the instance"))); // all properties cimInstance.addProperty(CIMProperty("property1", CIMValue(Uint32(1)))); cimInstance.addProperty(CIMProperty("property2", CIMValue(String("Test Instance #005c")))); cimInstance.addProperty(CIMProperty("property3", CIMValue(CIMDateTime::getCurrentDateTime()))); CIMProperty property4("property4", CIMValue(String("Pegasus TestObjectNormalizer"))); property4.addQualifier(CIMQualifier("Description", String("This property qualifier value comes from the instance"))); cimInstance.addProperty(property4);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -