⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httpexportresponsedecoder.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        CLIENT_EXCEPTION_MESSAGE, MALFORMED_HTTP);    //    //  Test HTTP response message with missing CIMContentType HTTP header    //    //  Expected result:    //    valid is false    //    cimReconnect is false    //    exceptionMessage type is CLIENT_EXCEPTION_MESSAGE (75)    //    clientException is CIMClientMalformedHTTPException    //    Buffer buffer7(STRLIT_ARGS(        "HTTP/1.1 200 OK\r\n"        "transfer-encoding: chunked\r\n"        "CIMExport: MethodResponse\r\n"        "Trailer: CIMStatusCode, CIMStatusCodeDescription, "            "Content-Language\r\n"        "\r\n"        "<?xml version=\"1.0\" encoding=\"utf-8\"?>"        "<CIM CIMVERSION=\"2.0\" DTDVERSION=\"2.0\">"        "<MESSAGE ID=\"1001\" PROTOCOLVERSION=\"1.0\">"        "<SIMPLEEXPRSP>"        "<EXPMETHODRESPONSE NAME=\"ExportIndication\">"        "<ERROR CODE=\"7\" DESCRIPTION=\"CIM_ERR_NOT_SUPPORTED: "            "The requested operation is not supported\"/>"        "</EXPMETHODRESPONSE>"        "</SIMPLEEXPRSP>"        "</MESSAGE>"        "</CIM>"));    testValidateHTTPHeaders(buffer7, false, false,        CLIENT_EXCEPTION_MESSAGE, MALFORMED_HTTP);    //    //  Test response message with unexpected CIMExport HTTP header value    //    //  Expected result:    //    valid is false    //    cimReconnect is false    //    exceptionMessage type is CLIENT_EXCEPTION_MESSAGE (75)    //    clientException is CIMClientMalformedHTTPException    //    Buffer buffer8(STRLIT_ARGS(        "HTTP/1.1 200 OK\r\n"        "Content-Type: application/xml; charset=\"utf-8\"\r\n"        "transfer-encoding: chunked\r\n"        "CIMExport: Bogus\r\n"        "Trailer: CIMStatusCode, CIMStatusCodeDescription, "            "Content-Language\r\n"        "\r\n"        "<?xml version=\"1.0\" encoding=\"utf-8\"?>"        "<CIM CIMVERSION=\"2.0\" DTDVERSION=\"2.0\">"        "<MESSAGE ID=\"1001\" PROTOCOLVERSION=\"1.0\">"        "<SIMPLEEXPRSP>"        "<EXPMETHODRESPONSE NAME=\"ExportIndication\">"        "<ERROR CODE=\"7\" DESCRIPTION=\"CIM_ERR_NOT_SUPPORTED: "            "The requested operation is not supported\"/>"        "</EXPMETHODRESPONSE>"        "</SIMPLEEXPRSP>"        "</MESSAGE>"        "</CIM>"));    testValidateHTTPHeaders(buffer8, false, false,        CLIENT_EXCEPTION_MESSAGE, MALFORMED_HTTP);}//////////////////////////////////////////////////////////////////                                                            ////  Test Cases for decodeExportResponse method                ////                                                            //////////////////////////////////////////////////////////////////void decodeExportResponseTestCases(){    //    //  Test missing XML MESSAGE element    //    //  Expected result:    //    response Message type is CLIENT_EXCEPTION_MESSAGE (75)    //    clientException is CIMClientXmlException    //    Buffer buffer9(STRLIT_ARGS(        "HTTP/1.1 200 OK\r\n"        "Content-Type: application/xml; charset=\"utf-8\"\r\n"        "transfer-encoding: chunked\r\n"        "CIMExport: MethodResponse\r\n"        "Trailer: CIMStatusCode, CIMStatusCodeDescription, "            "Content-Language\r\n"        "\r\n"        "<?xml version=\"1.0\" encoding=\"utf-8\"?>"        "<CIM CIMVERSION=\"2.0\" DTDVERSION=\"2.0\">"        "<SIMPLEEXPRSP>"        "<EXPMETHODRESPONSE NAME=\"ExportIndication\">"        "<ERROR CODE=\"7\" DESCRIPTION=\"CIM_ERR_NOT_SUPPORTED: "            "The requested operation is not supported\"/>"        "</EXPMETHODRESPONSE>"        "</SIMPLEEXPRSP>"        "</CIM>"));    testDecodeExportResponse(buffer9, CLIENT_EXCEPTION_MESSAGE, XML_EXCEPTION);    //    //  Test unsupported protocol version    //    //  Expected result:    //    response Message type is CLIENT_EXCEPTION_MESSAGE (75)    //    clientException is CIMClientResponseException    //    Buffer buffer10(STRLIT_ARGS(        "HTTP/1.1 200 OK\r\n"        "Content-Type: application/xml; charset=\"utf-8\"\r\n"        "transfer-encoding: chunked\r\n"        "CIMExport: MethodResponse\r\n"        "Trailer: CIMStatusCode, CIMStatusCodeDescription, "            "Content-Language\r\n"        "\r\n"        "<?xml version=\"1.0\" encoding=\"utf-8\"?>"        "<CIM CIMVERSION=\"2.0\" DTDVERSION=\"2.0\">"        "<MESSAGE ID=\"1001\" PROTOCOLVERSION=\"2.0\">"        "<SIMPLEEXPRSP>"        "<EXPMETHODRESPONSE NAME=\"ExportIndication\">"        "<ERROR CODE=\"7\" DESCRIPTION=\"CIM_ERR_NOT_SUPPORTED: "            "The requested operation is not supported\"/>"        "</EXPMETHODRESPONSE>"        "</SIMPLEEXPRSP>"        "</MESSAGE>"        "</CIM>"));    testDecodeExportResponse(buffer10,        CLIENT_EXCEPTION_MESSAGE, RESPONSE_EXCEPTION);    //    //  Test missing XML EXPMETHODRESPONSE element    //    //  Expected result:    //    response Message type is CLIENT_EXCEPTION_MESSAGE (75)    //    clientException is CIMClientXmlException    //    Buffer buffer11(STRLIT_ARGS(        "HTTP/1.1 200 OK\r\n"        "Content-Type: application/xml; charset=\"utf-8\"\r\n"        "transfer-encoding: chunked\r\n"        "CIMExport: MethodResponse\r\n"        "Trailer: CIMStatusCode, CIMStatusCodeDescription, "            "Content-Language\r\n"        "\r\n"        "<?xml version=\"1.0\" encoding=\"utf-8\"?>"        "<CIM CIMVERSION=\"2.0\" DTDVERSION=\"2.0\">"        "<MESSAGE ID=\"1001\" PROTOCOLVERSION=\"1.0\">"        "<SIMPLEEXPRSP>"        "<ERROR CODE=\"7\" DESCRIPTION=\"CIM_ERR_NOT_SUPPORTED: "            "The requested operation is not supported\"/>"        "</SIMPLEEXPRSP>"        "</MESSAGE>"        "</CIM>"));    testDecodeExportResponse(buffer11, CLIENT_EXCEPTION_MESSAGE, XML_EXCEPTION);    //    //  Test unrecognized ExpMethodResponse name attribute    //    //  Expected result:    //    response Message type is CLIENT_EXCEPTION_MESSAGE (75)    //    clientException is CIMClientXmlException    //    Buffer buffer12(STRLIT_ARGS(        "HTTP/1.1 200 OK\r\n"        "Content-Type: application/xml; charset=\"utf-8\"\r\n"        "transfer-encoding: chunked\r\n"        "CIMExport: MethodResponse\r\n"        "Trailer: CIMStatusCode, CIMStatusCodeDescription, "            "Content-Language\r\n"        "\r\n"        "<?xml version=\"1.0\" encoding=\"utf-8\"?>"        "<CIM CIMVERSION=\"2.0\" DTDVERSION=\"2.0\">"        "<MESSAGE ID=\"1001\" PROTOCOLVERSION=\"1.0\">"        "<SIMPLEEXPRSP>"        "<EXPMETHODRESPONSE NAME=\"Bogus\">"        "<ERROR CODE=\"7\" DESCRIPTION=\"CIM_ERR_NOT_SUPPORTED: "            "The requested operation is not supported\"/>"        "</EXPMETHODRESPONSE>"        "</SIMPLEEXPRSP>"        "</MESSAGE>"        "</CIM>"));    testDecodeExportResponse(buffer12, CLIENT_EXCEPTION_MESSAGE, XML_EXCEPTION);    //    //  Test empty EXPMETHODRESPONSE tag    //    //  Expected result:    //    response Message type is CIM_EXPORT_INDICATION_RESPONSE_MESSAGE    //        (38)    //    Buffer buffer13(STRLIT_ARGS(        "HTTP/1.1 200 OK\r\n"        "Content-Type: application/xml; charset=\"utf-8\"\r\n"        "transfer-encoding: chunked\r\n"        "CIMExport: MethodResponse\r\n"        "Trailer: CIMStatusCode, CIMStatusCodeDescription, "            "Content-Language\r\n"        "\r\n"        "<?xml version=\"1.0\" encoding=\"utf-8\"?>"        "<CIM CIMVERSION=\"2.0\" DTDVERSION=\"2.0\">"        "<MESSAGE ID=\"1001\" PROTOCOLVERSION=\"1.0\">"        "<SIMPLEEXPRSP>"        "<EXPMETHODRESPONSE NAME=\"ExportIndication\"/>"        "</SIMPLEEXPRSP>"        "</MESSAGE>"        "</CIM>"));    testDecodeExportResponse(buffer13, CIM_EXPORT_INDICATION_RESPONSE_MESSAGE,        CIMName());    //    //  Test EXPMETHODRESPONSE with empty IRETURNVALUE tag    //    //  Expected result:    //    response Message type is CIM_EXPORT_INDICATION_RESPONSE_MESSAGE    //        (38)    //    Buffer buffer14(STRLIT_ARGS(        "HTTP/1.1 200 OK\r\n"        "Content-Type: application/xml; charset=\"utf-8\"\r\n"        "transfer-encoding: chunked\r\n"        "CIMExport: MethodResponse\r\n"        "Trailer: CIMStatusCode, CIMStatusCodeDescription, "            "Content-Language\r\n"        "\r\n"        "<?xml version=\"1.0\" encoding=\"utf-8\"?>"        "<CIM CIMVERSION=\"2.0\" DTDVERSION=\"2.0\">"        "<MESSAGE ID=\"1001\" PROTOCOLVERSION=\"1.0\">"        "<SIMPLEEXPRSP>"        "<EXPMETHODRESPONSE NAME=\"ExportIndication\">"        "<IRETURNVALUE/>"        "</EXPMETHODRESPONSE>"        "</SIMPLEEXPRSP>"        "</MESSAGE>"        "</CIM>"));    testDecodeExportResponse(buffer14, CIM_EXPORT_INDICATION_RESPONSE_MESSAGE,        CIMName());    //    //  Test EXPMETHODRESPONSE with non-empty IRETURNVALUE tag    //    //  Expected result:    //    response Message type is CLIENT_EXCEPTION_MESSAGE (75)    //    clientException is CIMClientXmlException    //    Buffer buffer15(STRLIT_ARGS(        "HTTP/1.1 200 OK\r\n"        "Content-Type: application/xml; charset=\"utf-8\"\r\n"        "transfer-encoding: chunked\r\n"        "CIMExport: MethodResponse\r\n"        "Trailer: CIMStatusCode, CIMStatusCodeDescription, "            "Content-Language\r\n"        "\r\n"        "<?xml version=\"1.0\" encoding=\"utf-8\"?>"        "<CIM CIMVERSION=\"2.0\" DTDVERSION=\"2.0\">"        "<MESSAGE ID=\"1001\" PROTOCOLVERSION=\"1.0\">"        "<SIMPLEEXPRSP>"        "<EXPMETHODRESPONSE NAME=\"ExportIndication\">"        "<IRETURNVALUE>0</IRETURNVALUE>"        "</EXPMETHODRESPONSE>"        "</SIMPLEEXPRSP>"        "</MESSAGE>"        "</CIM>"));    testDecodeExportResponse(buffer15, CLIENT_EXCEPTION_MESSAGE, XML_EXCEPTION);}int main(int argc, char** argv){    try    {        parseHTTPHeadersTestCases();        validateHTTPHeadersTestCases();               decodeExportResponseTestCases();    }    catch(const Exception& e)    {        cerr << argv[0] << ": Exception " << e.getMessage() << endl;        return 1;    }    catch(...)    {        cerr << argv[0] << ": " << "Unknown error" << endl;        return 1;    }    cout << "+++++ passed all tests" << endl;    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -