📄 testsnmphandlerexception.cpp
字号:
TestException(handler, indicationHandlerInstance, indicationInstance, CIM_ERR_FAILED); // Test "no required property TargetHostFormat" exception indicationInstance = CIMInstance(testClass1); indicationInstance.addProperty(CIMProperty( CIMName ("OidDataType"), String("OctetString"))); indicationHandlerInstance = CreateHandlerInstance(); indicationHandlerInstance.addProperty(CIMProperty( CIMName("TargetHost"), String("15.13.140.120"))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("SNMPVersion"), Uint16(2))); TestException(handler, indicationHandlerInstance, indicationInstance, CIM_ERR_FAILED); // Test "no required property SNMPVersion" exception indicationInstance = CIMInstance(testClass1); indicationHandlerInstance = CreateHandlerInstance(); indicationHandlerInstance.addProperty(CIMProperty( CIMName("TargetHost"), String("15.13.140.120"))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("TargetHostFormat"), Uint16(3))); TestException(handler, indicationHandlerInstance, indicationInstance, CIM_ERR_FAILED); // Test "unsupported snmp Version" exception indicationInstance = CIMInstance(testClass1); indicationHandlerInstance = CreateHandlerInstance(); indicationHandlerInstance.addProperty(CIMProperty( CIMName("TargetHost"), String("15.13.140.120"))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("TargetHostFormat"), Uint16(3))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("SNMPVersion"), Uint16(5))); TestException(handler, indicationHandlerInstance, indicationInstance, CIM_ERR_FAILED); // Test "SNMP session open failed" exception indicationInstance = CIMInstance(testClass1); indicationHandlerInstance = CreateHandlerInstance(); indicationHandlerInstance.addProperty(CIMProperty( CIMName("TargetHost"), String(""))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("TargetHostFormat"), Uint16(3))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("SNMPVersion"), Uint16(2))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("OtherTargetHostFormat"), String("testOtherTargetHostFormat"))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("PortNumber"), Uint32(200))); TestException(handler, indicationHandlerInstance, indicationInstance, CIM_ERR_FAILED); // Test "invalid MappingStrings value" exception indicationInstance = CIMInstance(testClass2); indicationInstance.addProperty(CIMProperty( CIMName ("OidDataType"), String("OctetString"))); indicationHandlerInstance = CreateHandlerInstance(); indicationHandlerInstance.addProperty(CIMProperty( CIMName("TargetHost"), String("15.13.140.120"))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("TargetHostFormat"), Uint16(3))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("SNMPVersion"), Uint16(2))); TestException(handler, indicationHandlerInstance, indicationInstance, CIM_ERR_FAILED); // Test "no MappingStrings qualifier" exception indicationInstance = CIMInstance(testClass3); indicationHandlerInstance = CreateHandlerInstance(); indicationHandlerInstance.addProperty(CIMProperty( CIMName("TargetHost"), String("15.13.140.120"))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("TargetHostFormat"), Uint16(3))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("SNMPVersion"), Uint16(2))); TestException(handler, indicationHandlerInstance, indicationInstance, CIM_ERR_FAILED); // Test "send trap failed" exception indicationInstance = CIMInstance(testClass4); indicationHandlerInstance = CreateHandlerInstance(); indicationHandlerInstance.addProperty(CIMProperty( CIMName("TargetHost"), String("15.13.140.120"))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("TargetHostFormat"), Uint16(3))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("SNMPVersion"), Uint16(2))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("SNMPSecurityName"), String("t"))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("OtherTargetHostFormat"), String("testOtherTargetHostFormat"))); TestException(handler, indicationHandlerInstance, indicationInstance, CIM_ERR_FAILED); // Test "failed to add snmp variables to PDU", // Both a DiscardedData message and an error message // are logged to log file indicationInstance = CIMInstance(testClass5); indicationInstance.addProperty(CIMProperty( CIMName ("OidDataType"), String("OctetString"))); indicationHandlerInstance = CreateHandlerInstance(); indicationHandlerInstance.addProperty(CIMProperty( CIMName("TargetHost"), String("15.13.140.120"))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("TargetHostFormat"), Uint16(3))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("SNMPVersion"), Uint16(2))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("SNMPSecurityName"), String("t"))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("OtherTargetHostFormat"), String("testOtherTargetHostFormat"))); TestError(handler, indicationHandlerInstance, indicationInstance); // Test "convert enterprise OID from numeric form to a list of" // "subidentifiers failed". // Both a DiscardedData message and an error message // are logged to log file indicationInstance = CIMInstance(testClass5); indicationInstance.addProperty(CIMProperty( CIMName ("OidDataType"), String("OctetString"))); indicationHandlerInstance = CreateHandlerInstance(); indicationHandlerInstance.addProperty(CIMProperty( CIMName("TargetHost"), String("15.13.140.120"))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("TargetHostFormat"), Uint16(3))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("SNMPVersion"), Uint16(3))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("SNMPSecurityName"), String("t"))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("OtherTargetHostFormat"), String("testOtherTargetHostFormat"))); TestError(handler, indicationHandlerInstance, indicationInstance); // Test "convert property OID from numeric form to a list of" // "subidentifiers failed". // Both a DiscardedData message and an error message // are logged to log file indicationInstance = CIMInstance(testClass6); indicationInstance.addProperty(CIMProperty( CIMName ("OidDataType"), String("OctetString"))); indicationHandlerInstance = CreateHandlerInstance(); indicationHandlerInstance.addProperty(CIMProperty( CIMName("TargetHost"), String("15.13.140.120"))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("TargetHostFormat"), Uint16(3))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("SNMPVersion"), Uint16(2))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("OtherTargetHostFormat"), String("testOtherTargetHostFormat"))); TestError(handler, indicationHandlerInstance, indicationInstance); // Test "unsupported SNMP data type for the CIM property" // Both a DiscardedData message and an error message // are logged to log file indicationInstance = CIMInstance(testClass7); indicationInstance.addProperty(CIMProperty( CIMName ("OidDataType"), String("test"))); indicationHandlerInstance = CreateHandlerInstance(); indicationHandlerInstance.addProperty(CIMProperty( CIMName("TargetHost"), String("15.13.140.120"))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("TargetHostFormat"), Uint16(3))); indicationHandlerInstance.addProperty(CIMProperty( CIMName("SNMPVersion"), Uint16(2))); TestError(handler, indicationHandlerInstance, indicationInstance);}int main(int argc, char** argv){ 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); // // -- 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;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -