IRSOL
C++ code implementing socket server for interacting with Baumer camera.
test_parser_result.cpp
Go to the documentation of this file.
3
4#include <catch2/catch_all.hpp>
5TEST_CASE("bool(ParserResult)", "[Protocol][Protocol::Parser]")
6{
7 {
10 CHECK(bool(result));
11 }
12 {
14 CHECK_FALSE(bool(result));
15 }
16}
17
18TEST_CASE("ParserResult::isMessage()", "[Protocol][Protocol::Parser]")
19{
20 {
23 CHECK(result.isMessage());
24 }
25 {
27 CHECK_FALSE(result.isMessage());
28 }
29}
30
31TEST_CASE("ParserResult::isError()", "[Protocol][Protocol::Parser]")
32{
33 {
36 CHECK_FALSE(result.isError());
37 }
38 {
40 CHECK(result.isError());
41 }
42}
43
44TEST_CASE("ParserResult<Assignment>::getMessage()", "[Protocol][Protocol::Parser]")
45{
46 auto value = GENERATE(
49 irsol::types::protocol_value_t("hello world"));
50
51 auto identifier = GENERATE(
52 "x", "it", "long_identifier", "sequence_identifier[4]", "nested_sequence_identifier[4][423]");
53
54 // Need to create a copy of the identifier and value for the check,
55 // as these are moved into the ParserResult.
56 auto expectedIdentifier = identifier;
57 auto expected_value = value;
58
61 CHECK(result.isMessage());
62 CHECK(result.getMessage().identifier == expectedIdentifier);
63 CHECK(result.getMessage().value == expected_value);
64}
65
66TEST_CASE("ParserResult<Inquiry>::getMessage()", "[Protocol][Protocol::Parser]")
67{
68 auto identifier = GENERATE(
69 "x", "it", "long_identifier", "sequence_identifier[4]", "nested_sequence_identifier[4][423]");
70
71 // Need to create a copy of the identifier for the check,
72 // as these are moved into the ParserResult.
73 auto expectedIdentifier = identifier;
74
75 irsol::protocol::Inquiry m(identifier);
77 CHECK(result.isMessage());
78 CHECK(result.getMessage().identifier == expectedIdentifier);
79}
80
81TEST_CASE("ParserResult<Command>::getMessage()", "[Protocol][Protocol::Parser]")
82{
83 auto identifier = GENERATE(
84 "x", "it", "long_identifier", "sequence_identifier[4]", "nested_sequence_identifier[4][423]");
85
86 // Need to create a copy of the identifier for the check,
87 // as these are moved into the ParserResult.
88 auto expectedIdentifier = identifier;
89
90 irsol::protocol::Command m(identifier);
92 CHECK(result.isMessage());
93 CHECK(result.getMessage().identifier == expectedIdentifier);
94}
95
96TEST_CASE("ParserResult<T>::getError()", "[Protocol][Protocol::Parser]")
97{
98 auto errorMessage = GENERATE("invalid syntax", "unknown identifier", "unexpected character");
99 auto expectedErrorMessage = errorMessage;
100 {
102 CHECK(result.isError());
103 CHECK(result.getError() == expectedErrorMessage);
104 }
105 {
107 CHECK(result.isError());
108 CHECK(result.getError() == expectedErrorMessage);
109 }
110 {
112 CHECK(result.isError());
113 CHECK(result.getError() == expectedErrorMessage);
114 }
115}
Wrapper for the result of a protocol parsing attempt.
std::variant< int, double, std::string > protocol_value_t
Variant type representing protocol values that can be one of several types.
Definition types.hpp:150
Encapsulates the result of a protocol parsing operation.
Represents an assignment operation in the protocol.
Represents a command invocation in the protocol.
Definition command.hpp:33
Represents a value inquiry in the protocol.
Definition inquiry.hpp:32
auto value
CHECK(m.identifier==identifier)
CHECK_FALSE(m.hasDouble())
irsol::protocol::Assignment m(identifier, value)
auto result
TEST_CASE("Pixel<T>::max())", "[PixelFormat]")