-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_protocol.cpp
78 lines (72 loc) · 2.29 KB
/
test_protocol.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <catch2/catch.hpp>
#include "olink/core/types.h"
#include "olink/core/protocol.h"
#include <string>
#include "nlohmann/json.hpp"
using json = nlohmann::json;
using namespace ApiGear::ObjectLink;
TEST_CASE("protocol")
{
std::string name = "demo.Calc";
json props = {{ "count", 0 }};
int value = 1;
json args = {1, 2};
unsigned int requestId = 1;
MsgType msgType = MsgType::Invoke;
std::string error = "failed";
SECTION("link") {
json msg = Protocol::linkMessage(name);
REQUIRE(msg[0] == MsgType::Link);
REQUIRE(msg[1] == name);
}
SECTION("unlink") {
json msg = Protocol::unlinkMessage(name);
REQUIRE(msg[0] == MsgType::Unlink);
REQUIRE(msg[1] == name);
}
SECTION("init") {
json msg = Protocol::initMessage(name, props);
REQUIRE(msg[0] == MsgType::Init);
REQUIRE(msg[1] == name);
REQUIRE(msg[2] == props);
}
SECTION("setProperty") {
json msg = Protocol::setPropertyMessage(name, value);
REQUIRE(msg[0] == MsgType::SetProperty);
REQUIRE(msg[1] == name);
REQUIRE(msg[2] == value);
}
SECTION("propertyChange") {
json msg = Protocol::propertyChangeMessage(name, value);
REQUIRE(msg[0] == MsgType::PropertyChange);
REQUIRE(msg[1] == name);
REQUIRE(msg[2] == value);
}
SECTION("invoke") {
json msg = Protocol::invokeMessage(requestId, name, args);
REQUIRE(msg[0] == MsgType::Invoke);
REQUIRE(msg[1] == requestId);
REQUIRE(msg[2] == name);
REQUIRE(msg[3] == args);
}
SECTION("invokeReply") {
json msg = Protocol::invokeReplyMessage(requestId, name, value);
REQUIRE(msg[0] == MsgType::InvokeReply);
REQUIRE(msg[1] == requestId);
REQUIRE(msg[2] == name);
REQUIRE(msg[3] == value);
}
SECTION("signal") {
json msg = Protocol::signalMessage(name, args);
REQUIRE(msg[0] == MsgType::Signal);
REQUIRE(msg[1] == name);
REQUIRE(msg[2] == args);
}
SECTION("error") {
json msg = Protocol::errorMessage(msgType, requestId, error);
REQUIRE(msg[0] == MsgType::Error);
REQUIRE(msg[1] == msgType);
REQUIRE(msg[2] == requestId);
REQUIRE(msg[3] == error);
}
}