-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproto_utils_test.cc
More file actions
54 lines (47 loc) · 1.82 KB
/
proto_utils_test.cc
File metadata and controls
54 lines (47 loc) · 1.82 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
#include "proto_utils.h"
#include <google/protobuf/text_format.h>
#include "absl/status/status_matchers.h"
#include "gmock/gmock-matchers.h"
#include "gtest/gtest.h"
#include "lidar.h"
#include "proto/lidar_response.pb.h"
#include "protobuf-matchers/protocol-buffer-matchers.h"
#include "tools/cpp/runfiles/runfiles.h"
namespace slam_dunk {
namespace {
using ::absl_testing::IsOk;
using ::absl_testing::IsOkAndHolds;
using ::bazel::tools::cpp::runfiles::Runfiles;
using ::protobuf_matchers::EqualsProto;
using ::testing::HasSubstr;
using ::testing::NotNull;
TEST(ScanResponseToTextProtoString, Works) {
auto text_proto =
ConvertScanResponseToTextProtoString(std::vector<ScanResponse>{
ScanResponse{.theta = 5566, .distance_mm = 2257, .quality = 60},
ScanResponse{.theta = 5822, .distance_mm = 2243, .quality = 60}});
// Convert from proto text format to actual proto message
slam_dunk::proto::ScanResponse message;
ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString(text_proto.value(),
&message));
EXPECT_THAT(
message,
EqualsProto(
R"pb(items { theta: 5566 distance_mm: 2257 quality: 60 }
items { theta: 5822 distance_mm: 2243 quality: 60 })pb"));
}
TEST(SaveAndGetFile, Works) {
const Runfiles* files = Runfiles::CreateForTest();
ASSERT_THAT(files, NotNull());
const std::string test_file = files->Rlocation("lidar.txtpb");
EXPECT_THAT(
SaveToFile(
std::vector<ScanResponse>{
ScanResponse{.theta = 5566, .distance_mm = 2257, .quality = 60},
ScanResponse{.theta = 5822, .distance_mm = 2243, .quality = 60}},
test_file),
IsOk());
EXPECT_THAT(GetTextFromFile(test_file), IsOkAndHolds(HasSubstr("items")));
}
} // namespace
} // namespace slam_dunk