-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_util.h
90 lines (72 loc) · 2.94 KB
/
test_util.h
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
// Copyright 2020 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef LORGNETTE_TEST_UTIL_H_
#define LORGNETTE_TEST_UTIL_H_
#include <cstdint>
#include <memory>
#include <ostream>
#include <string>
#include <vector>
#include <gmock/gmock.h>
#include <libusb.h>
#include <lorgnette/proto_bindings/lorgnette_service.pb.h>
using ::testing::ExplainMatchResult;
using ::testing::UnorderedElementsAreArray;
namespace lorgnette {
void PrintTo(const lorgnette::DocumentSource& ds, std::ostream* os);
DocumentSource CreateDocumentSource(const std::string& name,
SourceType type,
double width,
double height,
const std::vector<uint32_t>& resolutions,
const std::vector<ColorMode>& color_modes);
MATCHER_P(EqualsDocumentSource, expected, "") {
if (arg.type() != expected.type()) {
*result_listener << "type " << SourceType_Name(arg.type())
<< " does not match expected type "
<< SourceType_Name(expected.type());
return false;
}
if (arg.name() != expected.name()) {
*result_listener << "name " << arg.name()
<< " does not match expected name " << expected.name();
return false;
}
if (arg.has_area() != expected.has_area()) {
*result_listener << (arg.has_area() ? "has area" : "does not have area")
<< " but expected to "
<< (expected.has_area() ? "have area" : "not have area");
return false;
}
if (arg.area().width() != expected.area().width()) {
*result_listener << "width " << arg.area().width()
<< " does not match expected width "
<< expected.area().width();
return false;
}
if (arg.area().height() != expected.area().height()) {
*result_listener << "height " << arg.area().height()
<< " does not match expected height "
<< expected.area().height();
return false;
}
if (!ExplainMatchResult(UnorderedElementsAreArray(expected.resolutions()),
arg.resolutions(), result_listener)) {
return false;
}
return ExplainMatchResult(UnorderedElementsAreArray(expected.color_modes()),
arg.color_modes(), result_listener);
}
MATCHER_P(EqualsProto,
message,
"Match a proto Message equal to the matcher's argument.") {
std::string expected_serialized, actual_serialized;
message.SerializeToString(&expected_serialized);
arg.SerializeToString(&actual_serialized);
return expected_serialized == actual_serialized;
}
libusb_device_descriptor MakeMinimalDeviceDescriptor();
std::unique_ptr<libusb_interface_descriptor> MakeIppUsbInterfaceDescriptor();
} // namespace lorgnette
#endif // LORGNETTE_TEST_UTIL_H_