IRSOL
C++ code implementing socket server for interacting with Baumer camera.
test_parser.cpp File Reference
#include "irsol/protocol/message.hpp"
#include "irsol/protocol/parsing/parser.hpp"
#include <catch2/catch_all.hpp>

Go to the source code of this file.

Functions

 TEST_CASE ("Parsing invalid identifier", "[Protocol][Protocol::Parser]")
 
 TEST_CASE ("Assignment parsing int", "[Protocol][Protocol::Parser]")
 
 TEST_CASE ("Assignment parsing double", "[Protocol][Protocol::Parser]")
 
 TEST_CASE ("Assignment parsing string", "[Protocol][Protocol::Parser]")
 
 REQUIRE (msg.has_value())
 
 CHECK (asg.identifier==identifier)
 
 CHECK (std::get< std::string >(asg.value)==value)
 
 TEST_CASE ("Inquiry parsing", "[Protocol][Protocol::Parser]")
 
 TEST_CASE ("Command parsing", "[Protocol][Protocol::Parser]")
 

Variables

auto value = GENERATE("c", "longer", "long_string_with_underscores", "5è4?-é")
 
auto prefixSuffixChars = GENERATE("\"\"", "''", "{}", " ")
 
std::string input
 
auto msg = irsol::protocol::Parser::parse(input)
 
auto asg = std::get<irsol::protocol::Assignment>(*msg)
 

Function Documentation

◆ CHECK() [1/2]

CHECK ( asg.  identifier = =identifier)

◆ CHECK() [2/2]

CHECK ( std::get< std::string >  asg.value = =value)

◆ REQUIRE()

REQUIRE ( msg.  has_value())

◆ TEST_CASE() [1/6]

TEST_CASE ( "Assignment parsing double"  ,
""  [Protocol][Protocol::Parser] 
)

Definition at line 42 of file test_parser.cpp.

43{
44 auto identifier = GENERATE(
45 "x", "it", "long_identifier", "sequence_identifier[4]", "nested_sequence_identifier[4][423]");
46 auto value = GENERATE(42.0, 0, 5, 32121.4234234);
47
48 std::string input = std::string(identifier) + "=" + std::to_string(value);
49
51 REQUIRE(msg.has_value());
52
53 auto asg = std::get<irsol::protocol::Assignment>(*msg);
54
55 CHECK(asg.identifier == identifier);
56 CHECK(std::get<double>(asg.value) == Catch::Approx(value));
57}
static std::optional< InMessage > parse(const std::string &line)
Attempts to parse a single protocol input line into a structured InMessage.
Definition parser.cpp:11
auto asg
auto value
REQUIRE(msg.has_value())
auto msg
std::string input
CHECK(asg.identifier==identifier)

◆ TEST_CASE() [2/6]

TEST_CASE ( "Assignment parsing int"  ,
""  [Protocol][Protocol::Parser] 
)

Definition at line 25 of file test_parser.cpp.

26{
27 auto identifier = GENERATE(
28 "x", "it", "long_identifier", "sequence_identifier[4]", "nested_sequence_identifier[4][423]");
29 auto value = GENERATE(42, 5, 32121);
30
31 std::string input = std::string(identifier) + "=" + std::to_string(value);
32
34 REQUIRE(msg.has_value());
35
36 auto asg = std::get<irsol::protocol::Assignment>(*msg);
37
38 CHECK(asg.identifier == identifier);
39 CHECK(std::get<int>(asg.value) == value);
40}

◆ TEST_CASE() [3/6]

TEST_CASE ( "Assignment parsing string"  ,
""  [Protocol][Protocol::Parser] 
)

Definition at line 59 of file test_parser.cpp.

60{
61 auto identifier = GENERATE(
62 "x", "it", "long_identifier", "sequence_identifier[4]", "nested_sequence_identifier[4][423]");
63 auto value = GENERATE("c", "longer", "long_string_with_underscores", "5è4?-é");
64
65 std::string input = std::string(identifier) + "=" + value;
66
68 REQUIRE(msg.has_value());
69
70 auto asg = std::get<irsol::protocol::Assignment>(*msg);
71
72 CHECK(asg.identifier == identifier);
73 CHECK(std::get<std::string>(asg.value) == value);
74}

◆ TEST_CASE() [4/6]

TEST_CASE ( "Command parsing"  ,
""  [Protocol][Protocol::Parser] 
)

Definition at line 106 of file test_parser.cpp.

107{
108 auto identifier = GENERATE("x", "it", "long_identifier");
109
110 std::string input = std::string(identifier);
112 REQUIRE(msg.has_value());
113 auto inq = std::get<irsol::protocol::Command>(*msg);
114 CHECK(inq.identifier == identifier);
115}

◆ TEST_CASE() [5/6]

TEST_CASE ( "Inquiry parsing"  ,
""  [Protocol][Protocol::Parser] 
)

Definition at line 94 of file test_parser.cpp.

95{
96 auto identifier = GENERATE(
97 "x", "it", "long_identifier", "sequence_identifier[4]", "nested_sequence_identifier[4][423]");
98
99 std::string input = std::string(identifier) + "?";
101 REQUIRE(msg.has_value());
102 auto inq = std::get<irsol::protocol::Inquiry>(*msg);
103 CHECK(inq.identifier == identifier);
104}

◆ TEST_CASE() [6/6]

TEST_CASE ( "Parsing invalid identifier"  ,
""  [Protocol][Protocol::Parser] 
)

Definition at line 6 of file test_parser.cpp.

7{
8 // Invalid identifiers
9 auto identifier = GENERATE(
10 ""
11 "identifier with spaces",
12 "identifier-with-dashes",
13 "non-alphanumeric<",
14 "??");
15
16 // Valid suffixes (for assignments, queries and commands)
17 auto suffix = GENERATE("=value", "=42", "=3.14", "?", "");
18
19 std::string line = std::string(identifier) + suffix;
20
22 REQUIRE(!msg.has_value());
23}

Variable Documentation

◆ asg

auto asg = std::get<irsol::protocol::Assignment>(*msg)

Definition at line 88 of file test_parser.cpp.

◆ input

std::string input
Initial value:
=
std::string(identifier) + "=" + prefixSuffixChars[0] + value + prefixSuffixChars[1]
auto prefixSuffixChars

Definition at line 82 of file test_parser.cpp.

◆ msg

Definition at line 85 of file test_parser.cpp.

◆ prefixSuffixChars

auto prefixSuffixChars = GENERATE("\"\"", "''", "{}", " ")

Definition at line 80 of file test_parser.cpp.

◆ value

auto value = GENERATE("c", "longer", "long_string_with_underscores", "5è4?-é")

Definition at line 79 of file test_parser.cpp.