-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathtest_MeadeQuit.cpp
More file actions
125 lines (107 loc) · 2.58 KB
/
test_MeadeQuit.cpp
File metadata and controls
125 lines (107 loc) · 2.58 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Wire-byte tests for the Meade Quit-family dispatcher (`handleMeadeQuit`).
//
// Every Quit sub-command emits an empty wire response; the test value lives
// in which handler callback fires, captured by `FakeHandlers`. Unknown
// sub-commands must NOT invoke any callback.
#include <gtest/gtest.h>
#include <string.h>
#include "core/meade/MeadeParser.hpp"
namespace meade = oat::core::meade;
namespace
{
class FakeHandlers : public meade::IMeadeQuitHandlers
{
public:
const char *lastCall = nullptr;
void onStopAll() override
{
lastCall = "all";
}
void onStopDirectionalAll() override
{
lastCall = "directional";
}
void onStopEast() override
{
lastCall = "east";
}
void onStopWest() override
{
lastCall = "west";
}
void onStopNorth() override
{
lastCall = "north";
}
void onStopSouth() override
{
lastCall = "south";
}
void onQuitControlMode() override
{
lastCall = "quitControl";
}
};
const char *dispatch(const char *suffix, FakeHandlers &h)
{
static meade::MeadeResponse last;
last.clear();
meade::handleMeadeQuit(last, suffix, h);
return last.c_str();
}
} // namespace
TEST(MeadeQuit, empty_suffix_stops_all)
{
FakeHandlers h;
EXPECT_STREQ("", dispatch("", h));
EXPECT_STREQ("all", h.lastCall);
}
TEST(MeadeQuit, a_suffix_stops_directional_all)
{
FakeHandlers h;
EXPECT_STREQ("", dispatch("a", h));
EXPECT_STREQ("directional", h.lastCall);
}
TEST(MeadeQuit, e_suffix_stops_east)
{
FakeHandlers h;
EXPECT_STREQ("", dispatch("e", h));
EXPECT_STREQ("east", h.lastCall);
}
TEST(MeadeQuit, w_suffix_stops_west)
{
FakeHandlers h;
EXPECT_STREQ("", dispatch("w", h));
EXPECT_STREQ("west", h.lastCall);
}
TEST(MeadeQuit, n_suffix_stops_north)
{
FakeHandlers h;
EXPECT_STREQ("", dispatch("n", h));
EXPECT_STREQ("north", h.lastCall);
}
TEST(MeadeQuit, s_suffix_stops_south)
{
FakeHandlers h;
EXPECT_STREQ("", dispatch("s", h));
EXPECT_STREQ("south", h.lastCall);
}
TEST(MeadeQuit, q_suffix_quits_control_mode)
{
FakeHandlers h;
EXPECT_STREQ("", dispatch("q", h));
EXPECT_STREQ("quitControl", h.lastCall);
}
TEST(MeadeQuit, unknown_suffix_does_not_call_handler)
{
FakeHandlers h;
EXPECT_STREQ("", dispatch("z", h));
EXPECT_EQ(nullptr, h.lastCall);
}
TEST(MeadeQuit, multi_char_suffix_does_not_call_handler)
{
FakeHandlers h;
// Single-char commands only; "ea" is not a valid stop-east.
EXPECT_STREQ("", dispatch("ea", h));
EXPECT_EQ(nullptr, h.lastCall);
}