|
8 | 8 | #include "ProjMgrTestEnv.h" |
9 | 9 | #include "ProjMgrRpcServer.h" |
10 | 10 | #include "ProjMgrRpcServerData.h" |
11 | | - |
12 | | - |
13 | 11 | #include "ProjMgrLogger.h" |
14 | 12 |
|
| 13 | +#include "ProductInfo.h" |
15 | 14 |
|
16 | 15 | using namespace std; |
17 | 16 |
|
18 | 17 | class ProjMgrRpcTests : public ProjMgr, public ::testing::Test { |
19 | 18 | protected: |
20 | 19 | ProjMgrRpcTests() {} |
21 | 20 | virtual ~ProjMgrRpcTests() {} |
| 21 | + string FormatRequest(const int id, const string& method, const json& params); |
| 22 | + vector<json> RunRpcMethods(const string& strIn); |
22 | 23 | }; |
23 | 24 |
|
24 | | -TEST_F(ProjMgrRpcTests, Load_Solution) { |
| 25 | +string ProjMgrRpcTests::FormatRequest(const int id, const string& method, const json& params = json()) { |
| 26 | + json request; |
| 27 | + request["jsonrpc"] = "2.0"; |
| 28 | + request["id"] = id; |
| 29 | + request["method"] = method; |
| 30 | + if (!params.is_null()) { |
| 31 | + request["params"] = params; |
| 32 | + } |
| 33 | + return request.dump(); |
| 34 | +} |
| 35 | + |
| 36 | +vector<json> ProjMgrRpcTests::RunRpcMethods(const string& strIn) { |
| 37 | + StdStreamRedirect streamRedirect; |
| 38 | + streamRedirect.SetInString(strIn); |
| 39 | + char* argv[] = { (char*)"csolution", (char*)"rpc" }; |
| 40 | + EXPECT_EQ(0, RunProjMgr(2, argv, 0)); |
| 41 | + string line; |
| 42 | + vector<json> responses; |
| 43 | + istringstream iss(streamRedirect.GetOutString()); |
| 44 | + while (getline(iss, line)) { |
| 45 | + responses.push_back(json::parse(line)); |
| 46 | + } |
| 47 | + return responses; |
| 48 | +} |
25 | 49 |
|
| 50 | +TEST_F(ProjMgrRpcTests, RpcGetVersion) { |
| 51 | + const auto& requests = FormatRequest(1, "GetVersion"); |
| 52 | + const auto& responses = RunRpcMethods(requests); |
| 53 | + EXPECT_EQ("2.0", responses[0]["jsonrpc"]); |
| 54 | + EXPECT_EQ(1, responses[0]["id"]); |
| 55 | + EXPECT_EQ(string(VERSION_STRING), responses[0]["result"]); |
| 56 | +} |
| 57 | + |
| 58 | +TEST_F(ProjMgrRpcTests, RpcLoadSolution) { |
| 59 | + const string& csolution = testinput_folder + "/TestRpc/minimal.csolution.yml"; |
| 60 | + const auto& requests = |
| 61 | + FormatRequest(1, "LoadPacks") + |
| 62 | + FormatRequest(2, "LoadSolution", json({{ "solution", csolution }})); |
| 63 | + |
| 64 | + const auto& responses = RunRpcMethods(requests); |
| 65 | + EXPECT_TRUE(responses[0]["result"]); |
| 66 | + EXPECT_TRUE(responses[1]["result"]); |
| 67 | +} |
26 | 68 |
|
| 69 | +TEST_F(ProjMgrRpcTests, RpcLoadSolution_UnknownComponent) { |
| 70 | + const string& csolution = testinput_folder + "/TestRpc/unknown-component.csolution.yml"; |
| 71 | + const auto& requests = |
| 72 | + FormatRequest(1, "LoadPacks") + |
| 73 | + FormatRequest(2, "LoadSolution", json({ { "solution", csolution } })) + |
| 74 | + FormatRequest(3, "GetLogMessages"); |
27 | 75 |
|
| 76 | + const auto& responses = RunRpcMethods(requests); |
| 77 | + EXPECT_TRUE(responses[0]["result"]); |
| 78 | + EXPECT_TRUE(responses[1]["result"]); |
| 79 | + EXPECT_EQ("no component was found with identifier 'ARM::UNKNOWN:COMPONENT'", |
| 80 | + responses[2]["result"]["errors"][0]); |
28 | 81 | } |
29 | 82 |
|
30 | 83 | // end of ProjMgrRpcTests.cpp |
0 commit comments