📄 indicationformatter.cpp
字号:
}// Tests a default indication text messagevoid _testDefaultFormat(){ ContentLanguageList contentLangs; contentLangs.append(LanguageTag("en-US-mn")); String expectedIndicationText = "Indication (default format):"; expectedIndicationText.append( "IndicationTime = 20050510143211.000000-420,"); if (verbose) { cout << "\n+++++ Test Default Format Indication Message" << endl; } expectedIndicationText.append( " IndicationIdentifier = 1, MethodName = testIndicationFormat, TestBoolean = true"); CIMInstance subscriptionInstance = _createSubscriptionInstance(); CIMInstance indicationInstance = _createIndicationInstance1(); String formattedIndText = IndicationFormatter::getFormattedIndText(subscriptionInstance, indicationInstance, contentLangs); PEGASUS_TEST_ASSERT(String::compare(formattedIndText, expectedIndicationText) == 0);}// Tests a formatted indication text message.void _testFormat(){ ContentLanguageList contentLangs; contentLangs.append(LanguageTag("en-US-mn")); if (verbose) { cout << "\n+++++ Test A Formatted Indication Text Message" << endl; } String textFormat = "The prediction is {3, boolean }. A indication which is generated by {2, string} occurred at {0, datetime} with Indication ID {1, uint32}"; Array<String> textFormatParams; textFormatParams.append("IndicationTime"); textFormatParams.append("IndicationIdentifier"); textFormatParams.append("MethodName"); textFormatParams.append("TestBoolean"); String expectedIndicationText = "The prediction is true. A indication which is generated by " \ "testIndicationFormat occurred at 20050510143211.000000-420" \ " with Indication ID 1"; CIMInstance subscriptionInstance = _createSubscriptionInstance(textFormat, textFormatParams); CIMInstance indicationInstance = _createIndicationInstance1(); String formattedIndText; formattedIndText = IndicationFormatter::getFormattedIndText( subscriptionInstance, indicationInstance, contentLangs); PEGASUS_TEST_ASSERT(String::compare(formattedIndText, expectedIndicationText) == 0);}// checks whether the formatted indication text is same as expectedvoid _checkIndicationText( const String & textFormat, const Array<String> & textFormatParams, const String expectedIndicationText, const CIMType type, const ContentLanguageList contentLangs){ CIMInstance subscriptionInstance = _createSubscriptionInstance(textFormat, textFormatParams); CIMInstance indicationInstance = _createIndicationInstance2(type); String formattedIndText = IndicationFormatter::getFormattedIndText( subscriptionInstance, indicationInstance, contentLangs); PEGASUS_TEST_ASSERT(String::compare(formattedIndText, expectedIndicationText) == 0);}// Tests a formatted indication text message and one of the indication // properties is an array property.void _testArrayFormat(){ ContentLanguageList contentLangs; contentLangs.append(LanguageTag("en-US-mn")); if (verbose) { cout << "\n+++++ Test A Formatted Indication Text Message With An Array Property" << endl; } Array<String> textFormatParams; textFormatParams.append("IndicationTime"); textFormatParams.append("Action"); String expectedText = "A UPS Alert occurred at 20050510143211.000000-420. " \ "The Following actions are recommended to resolve the alert: "; // test case 1: {1[], string} String textFormat = "A UPS Alert occurred at {0, datetime}. The Following actions are recommended to resolve the alert: {1[], string}"; String expectedIndicationText; String formattedIndText; expectedIndicationText.append(expectedText); expectedIndicationText.append( "[string_action1,string_action2,string_action3,string_action4]"); _checkIndicationText(textFormat, textFormatParams, expectedIndicationText, CIMTYPE_STRING, contentLangs); // test case 2: {1[1], string} textFormat.clear(); expectedIndicationText.clear(); textFormat = "A UPS Alert occurred at {0, datetime}. The Following actions are recommended to resolve the alert: {1[1], string}"; expectedIndicationText.append(expectedText); expectedIndicationText.append("string_action2"); _checkIndicationText(textFormat, textFormatParams, expectedIndicationText, CIMTYPE_STRING, contentLangs); // test case 3: {1[], uint8} textFormat.clear(); expectedIndicationText.clear(); textFormat = "A UPS Alert occurred at {0, datetime}. The Following actions are recommended to resolve the alert: {1[], uint8}"; expectedIndicationText.append(expectedText); expectedIndicationText.append("[1,2,3,4]"); _checkIndicationText(textFormat, textFormatParams, expectedIndicationText, CIMTYPE_UINT8, contentLangs); // test case 4: {1[1], uint8} textFormat.clear(); expectedIndicationText.clear(); textFormat = "A UPS Alert occurred at {0, datetime}. The Following actions are recommended to resolve the alert: {1[1], uint8}"; expectedIndicationText.append(expectedText); expectedIndicationText.append("2"); _checkIndicationText(textFormat, textFormatParams, expectedIndicationText, CIMTYPE_UINT8, contentLangs); // test case 5: {1[], uint16} textFormat.clear(); expectedIndicationText.clear(); textFormat = "A UPS Alert occurred at {0, datetime}. The Following actions are recommended to resolve the alert: {1[], uint16}"; expectedIndicationText.append(expectedText); expectedIndicationText.append("[16,26,36,46]"); _checkIndicationText(textFormat, textFormatParams, expectedIndicationText, CIMTYPE_UINT16, contentLangs); // test case 6: {1[1], uint16} textFormat.clear(); expectedIndicationText.clear(); textFormat = "A UPS Alert occurred at {0, datetime}. The Following actions are recommended to resolve the alert: {1[1], uint16}"; expectedIndicationText.append(expectedText); expectedIndicationText.append("26"); _checkIndicationText(textFormat, textFormatParams, expectedIndicationText, CIMTYPE_UINT16, contentLangs); // test case 7: {1[], uint32} textFormat.clear(); expectedIndicationText.clear(); textFormat = "A UPS Alert occurred at {0, datetime}. The Following actions are recommended to resolve the alert: {1[], uint32}"; expectedIndicationText.append(expectedText); expectedIndicationText.append("[32,42,52,62]"); _checkIndicationText(textFormat, textFormatParams, expectedIndicationText, CIMTYPE_UINT32, contentLangs); // test case 8: {1[1], uint32} textFormat.clear(); expectedIndicationText.clear(); textFormat = "A UPS Alert occurred at {0, datetime}. The Following actions are recommended to resolve the alert: {1[1], uint32}"; expectedIndicationText.append(expectedText); expectedIndicationText.append("42"); _checkIndicationText(textFormat, textFormatParams, expectedIndicationText, CIMTYPE_UINT32, contentLangs); // test case 9: {1[], uint64} textFormat.clear(); expectedIndicationText.clear(); textFormat = "A UPS Alert occurred at {0, datetime}. The Following actions are recommended to resolve the alert: {1[], uint64}"; expectedIndicationText.append(expectedText); expectedIndicationText.append("[64,74,84,94]"); _checkIndicationText(textFormat, textFormatParams, expectedIndicationText, CIMTYPE_UINT64, contentLangs); // test case 10: {1[1], uint64} textFormat.clear(); expectedIndicationText.clear(); textFormat = "A UPS Alert occurred at {0, datetime}. The Following actions are recommended to resolve the alert: {1[1], uint64}"; expectedIndicationText.append(expectedText); expectedIndicationText.append("74"); _checkIndicationText(textFormat, textFormatParams, expectedIndicationText, CIMTYPE_UINT64, contentLangs); // test case 11: {1[], sint8} textFormat.clear(); expectedIndicationText.clear(); textFormat = "A UPS Alert occurred at {0, datetime}. The Following actions are recommended to resolve the alert: {1[], sint8}"; expectedIndicationText.append(expectedText); expectedIndicationText.append("[-1,-2,-3,-4]"); _checkIndicationText(textFormat, textFormatParams, expectedIndicationText, CIMTYPE_SINT8, contentLangs); // test case 12: {1[1], sint8} textFormat.clear(); expectedIndicationText.clear(); textFormat = "A UPS Alert occurred at {0, datetime}. The Following actions are recommended to resolve the alert: {1[1], sint8}"; expectedIndicationText.append(expectedText); expectedIndicationText.append("-2"); _checkIndicationText(textFormat, textFormatParams, expectedIndicationText, CIMTYPE_SINT8, contentLangs); // test case 13: {1[], sint16} textFormat.clear(); expectedIndicationText.clear(); textFormat = "A UPS Alert occurred at {0, datetime}. The Following actions are recommended to resolve the alert: {1[], sint16}"; expectedIndicationText.append(expectedText); expectedIndicationText.append("[-16,-26,-36,-46]"); _checkIndicationText(textFormat, textFormatParams, expectedIndicationText, CIMTYPE_SINT16, contentLangs); // test case 14: {1[1], sint16} textFormat.clear(); expectedIndicationText.clear(); textFormat = "A UPS Alert occurred at {0, datetime}. The Following actions are recommended to resolve the alert: {1[1], sint16}"; expectedIndicationText.append(expectedText); expectedIndicationText.append("-26"); _checkIndicationText(textFormat, textFormatParams, expectedIndicationText, CIMTYPE_SINT16, contentLangs); // test case 15: {1[], sint32} textFormat.clear(); expectedIndicationText.clear(); textFormat = "A UPS Alert occurred at {0, datetime}. The Following actions are recommended to resolve the alert: {1[], sint32}"; expectedIndicationText.append(expectedText); expectedIndicationText.append("[-32,-42,-52,-62]"); _checkIndicationText(textFormat, textFormatParams, expectedIndicationText, CIMTYPE_SINT32, contentLangs); // test case 16: {1[1], sint32} textFormat.clear(); expectedIndicationText.clear(); textFormat = "A UPS Alert occurred at {0, datetime}. The Following actions are recommended to resolve the alert: {1[1], sint32}"; expectedIndicationText.append(expectedText); expectedIndicationText.append("-42"); _checkIndicationText(textFormat, textFormatParams, expectedIndicationText, CIMTYPE_SINT32, contentLangs); // test case 17: {1[], sint64} textFormat.clear(); expectedIndicationText.clear(); textFormat = "A UPS Alert occurred at {0, datetime}. The Following actions are recommended to resolve the alert: {1[], sint64}"; expectedIndicationText.append(expectedText); expectedIndicationText.append("[-64,-74,-84,-94]"); _checkIndicationText(textFormat, textFormatParams, expectedIndicationText, CIMTYPE_SINT64, contentLangs); // test case 18: {1[1], sint64} textFormat.clear(); expectedIndicationText.clear(); textFormat = "A UPS Alert occurred at {0, datetime}. The Following actions are recommended to resolve the alert: {1[1], sint64}"; expectedIndicationText.append(expectedText); expectedIndicationText.append("-74"); _checkIndicationText(textFormat, textFormatParams, expectedIndicationText, CIMTYPE_SINT64, contentLangs); // test case 19: {1[], boolean} textFormat.clear(); expectedIndicationText.clear(); textFormat = "A UPS Alert occurred at {0, datetime}. The Following actions are recommended to resolve the alert: {1[], boolean}"; expectedIndicationText.append(expectedText); expectedIndicationText.append("[true,false,true,false]"); _checkIndicationText(textFormat, textFormatParams, expectedIndicationText, CIMTYPE_BOOLEAN, contentLangs); // test case 20: {1[1], boolean} textFormat.clear(); expectedIndicationText.clear(); textFormat = "A UPS Alert occurred at {0, datetime}. The Following actions are recommended to resolve the alert: {1[1], boolean}"; expectedIndicationText.append(expectedText); expectedIndicationText.append("false"); _checkIndicationText(textFormat, textFormatParams, expectedIndicationText, CIMTYPE_BOOLEAN, contentLangs); // test case 21: {1[], char16} textFormat.clear(); expectedIndicationText.clear(); textFormat = "A UPS Alert occurred at {0, datetime}. The Following actions are recommended to resolve the alert: {1[], char16}"; expectedIndicationText.append(expectedText); expectedIndicationText.append("[a,b,c,d]"); _checkIndicationText(textFormat, textFormatParams, expectedIndicationText, CIMTYPE_CHAR16, contentLangs); // test case 22: {1[1], char16} textFormat.clear(); expectedIndicationText.clear(); textFormat = "A UPS Alert occurred at {0, datetime}. The Following actions are recommended to resolve the alert: {1[1], char16}"; expectedIndicationText.append(expectedText); expectedIndicationText.append("b"); _checkIndicationText(textFormat, textFormatParams, expectedIndicationText, CIMTYPE_CHAR16, contentLangs); // test case 20: {1[1], boolean} textFormat.clear(); expectedIndicationText.clear(); textFormat = "A UPS Alert occurred at {0, datetime}. The Following actions are recommended to resolve the alert: {1[1], boolean}"; expectedIndicationText.append(expectedText); expectedIndicationText.append("false"); _checkIndicationText(textFormat, textFormatParams, expectedIndicationText, CIMTYPE_BOOLEAN, contentLangs); // test case 21: array index out of bounds {1[-1], string} textFormat.clear(); expectedIndicationText.clear(); textFormat = "A UPS Alert occurred at {0, datetime}. The Following actions are recommended to resolve the alert: {1[-1], string}"; expectedIndicationText.append(expectedText); expectedIndicationText.append("UNKNOWN"); _checkIndicationText(textFormat, textFormatParams, expectedIndicationText, CIMTYPE_STRING, contentLangs); // test case 22: array index out of bounds {1[4], string} textFormat.clear(); expectedIndicationText.clear(); textFormat = "A UPS Alert occurred at {0, datetime}. The Following actions are recommended to resolve the alert: {1[4], string}"; expectedIndicationText.append(expectedText); expectedIndicationText.append("UNKNOWN"); _checkIndicationText(textFormat, textFormatParams, expectedIndicationText, CIMTYPE_STRING, contentLangs);}int main(int argc, char** argv){ // Check command line option if (argc > 2) { cerr << "Usage: TestIndicationFormatter [-v]" << endl; return 1; } if (argc == 2) { const char *opt = argv[1]; if (strcmp(opt, "-v") == 0) { verbose = true; } else { cerr << "Usage: TestIndicationFormatter [-v]" << endl; return 1; } } try { _validateTextFormat(); _testDefaultFormat(); _testFormat(); _testArrayFormat(); } catch (Exception& e) { cerr << "Error: " << e.getMessage() << endl; return -1; } cout << argv[0] << " +++++ passed all tests" << endl; return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -