Skip to content

Commit 009bdb5

Browse files
committed
More tests for dispatcher
1 parent 51682b5 commit 009bdb5

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

test/batchclient.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,26 @@ TEST_CASE("batchrequest", TEST_MODULE) {
3535
BatchRequest br;
3636
TestClientConnector c;
3737
json request = br.AddMethodCall(1, "some_method1", {"value1"})
38+
.AddMethodCall("1", "some_method1", {"value1"})
3839
.AddNamedMethodCall(2, "some_method2", {{"param1", "value1"}})
40+
.AddNamedMethodCall("2", "some_method2", {{"param1", "value1"}})
3941
.AddNotificationCall("some_notification1", {"value2"})
4042
.AddNamedNotificationCall("some_notification2", {{"param2", "value2"}})
4143
.Build();
4244

4345
CHECK(request.is_array());
44-
CHECK(request.size() == 4);
46+
CHECK(request.size() == 6);
4547
c.Send(request[0].dump());
4648
c.VerifyMethodRequest(version::v2, "some_method1", 1);
4749
c.Send(request[1].dump());
48-
c.VerifyMethodRequest(version::v2, "some_method2", 2);
50+
c.VerifyMethodRequest(version::v2, "some_method1", "1");
4951
c.Send(request[2].dump());
50-
c.VerifyNotificationRequest(version::v2, "some_notification1");
52+
c.VerifyMethodRequest(version::v2, "some_method2", 2);
5153
c.Send(request[3].dump());
54+
c.VerifyMethodRequest(version::v2, "some_method2", "2");
55+
c.Send(request[4].dump());
56+
c.VerifyNotificationRequest(version::v2, "some_notification1");
57+
c.Send(request[5].dump());
5258
c.VerifyNotificationRequest(version::v2, "some_notification2");
5359
}
5460

test/dispatcher.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ TEST_CASE("add and invoke positional", TEST_MODULE) {
2020

2121
procCache = "";
2222
CHECK(d.Add("some notification", GetHandle(&some_procedure)));
23+
CHECK(!d.Add("some notification", GetHandle(&some_procedure)));
2324
d.InvokeNotification("some notification", {"some string"});
2425
CHECK(procCache == "some string");
2526
}
@@ -65,4 +66,22 @@ TEST_CASE("error on invoking unsupported named parameter", TEST_MODULE) {
6566
REQUIRE_THROWS_WITH(d.InvokeNotification("some notification", p), Contains("invalid parameter: procedure doesn't support named parameter"));
6667
}
6768

69+
TEST_CASE("passing invalid literal as param", TEST_MODULE) {
70+
Dispatcher d;
71+
CHECK(d.Add("some method", GetHandle(&add_function)));
72+
REQUIRE_THROWS_WITH(d.InvokeMethod("some method", true), Contains("invalid request: params field must be an array, object"));
73+
}
74+
75+
TEST_CASE("dispatching unknown procedures", TEST_MODULE) {
76+
Dispatcher d;
77+
REQUIRE_THROWS_WITH(d.InvokeMethod("some method", {1}), Contains("method not found"));
78+
REQUIRE_THROWS_WITH(d.InvokeNotification("some notification", {1}), Contains("notification not found"));
79+
}
80+
81+
TEST_CASE("invalid param types", TEST_MODULE) {
82+
Dispatcher d;
83+
CHECK(d.Add("some method", GetHandle(&add_function)));
84+
CHECK_THROWS_WITH(d.InvokeMethod("some method", {"string1", "string2"}), Contains("invalid parameter: must be unsigned integer, but is string for parameter 0"));
85+
}
86+
6887
// TODO: avoid signed, unsigned bool invocations

0 commit comments

Comments
 (0)