Skip to content

Commit 7e3af67

Browse files
committed
[lldb] Add more tests MCP protocol types
Add unit testing for the different message types.
1 parent 770d0b0 commit 7e3af67

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

lldb/unittests/Protocol/ProtocolMCPTest.cpp

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,100 @@ TEST(ProtocolMCPTest, ToolDefinition) {
133133
EXPECT_EQ(tool_definition.inputSchema,
134134
deserialized_tool_definition->inputSchema);
135135
}
136+
137+
TEST(ProtocolMCPTest, MessageWithRequest) {
138+
Request request;
139+
request.id = 1;
140+
request.method = "test_method";
141+
request.params = llvm::json::Object{{"param", "value"}};
142+
143+
Message message = request;
144+
145+
llvm::Expected<Message> deserialized_message = roundtripJSON(message);
146+
ASSERT_THAT_EXPECTED(deserialized_message, llvm::Succeeded());
147+
148+
ASSERT_TRUE(std::holds_alternative<Request>(*deserialized_message));
149+
const Request &deserialized_request =
150+
std::get<Request>(*deserialized_message);
151+
152+
EXPECT_EQ(request.id, deserialized_request.id);
153+
EXPECT_EQ(request.method, deserialized_request.method);
154+
EXPECT_EQ(request.params, deserialized_request.params);
155+
}
156+
157+
TEST(ProtocolMCPTest, MessageWithResponse) {
158+
Response response;
159+
response.id = 2;
160+
response.result = llvm::json::Object{{"result", "success"}};
161+
162+
Message message = response;
163+
164+
llvm::Expected<Message> deserialized_message = roundtripJSON(message);
165+
ASSERT_THAT_EXPECTED(deserialized_message, llvm::Succeeded());
166+
167+
ASSERT_TRUE(std::holds_alternative<Response>(*deserialized_message));
168+
const Response &deserialized_response =
169+
std::get<Response>(*deserialized_message);
170+
171+
EXPECT_EQ(response.id, deserialized_response.id);
172+
EXPECT_EQ(response.result, deserialized_response.result);
173+
}
174+
175+
TEST(ProtocolMCPTest, MessageWithNotification) {
176+
Notification notification;
177+
notification.method = "notification_method";
178+
notification.params = llvm::json::Object{{"notify", "data"}};
179+
180+
Message message = notification;
181+
182+
llvm::Expected<Message> deserialized_message = roundtripJSON(message);
183+
ASSERT_THAT_EXPECTED(deserialized_message, llvm::Succeeded());
184+
185+
ASSERT_TRUE(std::holds_alternative<Notification>(*deserialized_message));
186+
const Notification &deserialized_notification =
187+
std::get<Notification>(*deserialized_message);
188+
189+
EXPECT_EQ(notification.method, deserialized_notification.method);
190+
EXPECT_EQ(notification.params, deserialized_notification.params);
191+
}
192+
193+
TEST(ProtocolMCPTest, MessageWithError) {
194+
ErrorInfo error_info;
195+
error_info.code = -32603;
196+
error_info.message = "Internal error";
197+
198+
Error error;
199+
error.id = 3;
200+
error.error = error_info;
201+
202+
Message message = error;
203+
204+
llvm::Expected<Message> deserialized_message = roundtripJSON(message);
205+
ASSERT_THAT_EXPECTED(deserialized_message, llvm::Succeeded());
206+
207+
ASSERT_TRUE(std::holds_alternative<Error>(*deserialized_message));
208+
const Error &deserialized_error = std::get<Error>(*deserialized_message);
209+
210+
EXPECT_EQ(error.id, deserialized_error.id);
211+
EXPECT_EQ(error.error.code, deserialized_error.error.code);
212+
EXPECT_EQ(error.error.message, deserialized_error.error.message);
213+
}
214+
215+
TEST(ProtocolMCPTest, ResponseWithError) {
216+
ErrorInfo error_info;
217+
error_info.code = -32700;
218+
error_info.message = "Parse error";
219+
220+
Response response;
221+
response.id = 4;
222+
response.error = error_info;
223+
224+
llvm::Expected<Response> deserialized_response = roundtripJSON(response);
225+
ASSERT_THAT_EXPECTED(deserialized_response, llvm::Succeeded());
226+
227+
EXPECT_EQ(response.id, deserialized_response->id);
228+
EXPECT_FALSE(deserialized_response->result.has_value());
229+
ASSERT_TRUE(deserialized_response->error.has_value());
230+
EXPECT_EQ(response.error->code, deserialized_response->error->code);
231+
EXPECT_EQ(response.error->message, deserialized_response->error->message);
232+
}

0 commit comments

Comments
 (0)