1010#include " ProjMgrRpcServerData.h"
1111#include " ProjMgrLogger.h"
1212
13+ #include " CrossPlatformUtils.h"
1314#include " ProductInfo.h"
1415
1516using namespace std ;
@@ -20,6 +21,7 @@ class ProjMgrRpcTests : public ProjMgr, public ::testing::Test {
2021 virtual ~ProjMgrRpcTests () {}
2122 string FormatRequest (const int id, const string& method, const json& params);
2223 vector<json> RunRpcMethods (const string& strIn);
24+ string RunRpcMethodsWithContent (const string& strIn);
2325};
2426
2527string ProjMgrRpcTests::FormatRequest (const int id, const string& method, const json& params = json()) {
@@ -47,6 +49,30 @@ vector<json> ProjMgrRpcTests::RunRpcMethods(const string& strIn) {
4749 return responses;
4850}
4951
52+ string ProjMgrRpcTests::RunRpcMethodsWithContent (const string& strIn) {
53+ StdStreamRedirect streamRedirect;
54+ streamRedirect.SetInString (strIn);
55+ char * argv[] = { (char *)" csolution" , (char *)" rpc" , (char *)" --content-length" };
56+ EXPECT_EQ (0 , RunProjMgr (3 , argv, 0 ));
57+ return streamRedirect.GetOutString ();
58+ }
59+
60+ TEST_F (ProjMgrRpcTests, ContentLength) {
61+ StdStreamRedirect streamRedirect;
62+ ProjMgrRpcServer server (*this );
63+ const auto & request = FormatRequest (1 , " GetVersion" );
64+
65+ auto requestWithHeader = " Content-Length:46\n\n " + request;
66+ streamRedirect.SetInString (requestWithHeader);
67+ auto parsedRequest = server.GetRequestFromStdinWithLength ();
68+ EXPECT_EQ (request, parsedRequest);
69+
70+ requestWithHeader = " Content-Length:46\r\n\r\n " + request;
71+ streamRedirect.SetInString (requestWithHeader);
72+ parsedRequest = server.GetRequestFromStdinWithLength ();
73+ EXPECT_EQ (request, parsedRequest);
74+ }
75+
5076TEST_F (ProjMgrRpcTests, RpcGetVersion) {
5177 const auto & requests = FormatRequest (1 , " GetVersion" );
5278 const auto & responses = RunRpcMethods (requests);
@@ -55,6 +81,12 @@ TEST_F(ProjMgrRpcTests, RpcGetVersion) {
5581 EXPECT_EQ (string (VERSION_STRING), responses[0 ][" result" ]);
5682}
5783
84+ TEST_F (ProjMgrRpcTests, RpcGetVersionWithContent) {
85+ const auto & requests = " Content-Length:46\n\n " + FormatRequest (1 , " GetVersion" );
86+ const auto & responses = RunRpcMethodsWithContent (requests);
87+ EXPECT_TRUE (responses.find (CrossPlatformUtils::Crlf () + CrossPlatformUtils::Crlf () + " {" ) != string::npos);
88+ }
89+
5890TEST_F (ProjMgrRpcTests, RpcLoadSolution) {
5991 const string& csolution = testinput_folder + " /TestRpc/minimal.csolution.yml" ;
6092 const auto & requests =
0 commit comments