-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathtest_MeadeGps.cpp
More file actions
81 lines (67 loc) · 1.79 KB
/
test_MeadeGps.cpp
File metadata and controls
81 lines (67 loc) · 1.79 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
// Wire-byte tests for the Meade GPS dispatcher (`handleMeadeGps`).
//
// `:gT<payload>#` invokes onStartGpsAcquisition with the payload bytes and
// emits "1" on success / "0" on timeout. Any other suffix emits "0" without
// invoking the handler.
#include <gtest/gtest.h>
#include <cstring>
#include "core/meade/MeadeParser.hpp"
namespace meade = oat::core::meade;
namespace
{
class FakeHandlers : public meade::IMeadeGpsHandlers
{
public:
bool nextResult = false;
bool called = false;
char lastPayload[64] = {0};
bool onStartGpsAcquisition(const char *timeoutPayload) override
{
called = true;
std::strncpy(lastPayload, timeoutPayload ? timeoutPayload : "", sizeof(lastPayload) - 1);
return nextResult;
}
};
const char *dispatch(const char *suffix, FakeHandlers &h)
{
static meade::MeadeResponse last;
last.clear();
meade::handleMeadeGps(last, suffix, h);
return last.c_str();
}
} // namespace
TEST(MeadeGps, t_success_emits_one)
{
FakeHandlers h;
h.nextResult = true;
EXPECT_STREQ("1", dispatch("T", h));
EXPECT_TRUE(h.called);
EXPECT_STREQ("", h.lastPayload);
}
TEST(MeadeGps, t_failure_emits_zero)
{
FakeHandlers h;
h.nextResult = false;
EXPECT_STREQ("0", dispatch("T", h));
EXPECT_TRUE(h.called);
}
TEST(MeadeGps, t_with_payload_forwards_payload)
{
FakeHandlers h;
h.nextResult = true;
EXPECT_STREQ("1", dispatch("T120000", h));
EXPECT_TRUE(h.called);
EXPECT_STREQ("120000", h.lastPayload);
}
TEST(MeadeGps, unknown_suffix_emits_zero_no_call)
{
FakeHandlers h;
EXPECT_STREQ("0", dispatch("Q", h));
EXPECT_FALSE(h.called);
}
TEST(MeadeGps, empty_suffix_emits_zero_no_call)
{
FakeHandlers h;
EXPECT_STREQ("0", dispatch("", h));
EXPECT_FALSE(h.called);
}