Google OR-Tools v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
gmock.h
Go to the documentation of this file.
1// Copyright 2010-2025 Google LLC
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14#ifndef ORTOOLS_BASE_GMOCK_H_
15#define ORTOOLS_BASE_GMOCK_H_
16
17#include "absl/status/status_matchers.h"
18#include "ortools/base/gmock.h"
19#include "protobuf-matchers/protocol-buffer-matchers.h"
20
21namespace testing {
22using ::protobuf_matchers::EqualsProto;
23using ::protobuf_matchers::EquivToProto;
24namespace proto {
25using ::protobuf_matchers::proto::Approximately;
26using ::protobuf_matchers::proto::IgnoringFieldPaths;
27using ::protobuf_matchers::proto::IgnoringFields;
28using ::protobuf_matchers::proto::IgnoringRepeatedFieldOrdering;
29using ::protobuf_matchers::proto::Partially;
30using ::protobuf_matchers::proto::TreatingNaNsAsEqual;
31using ::protobuf_matchers::proto::WhenDeserialized;
32using ::protobuf_matchers::proto::WhenDeserializedAs;
33using ::protobuf_matchers::proto::WithDifferencerConfig;
34} // namespace proto
35} // namespace testing
36
37namespace testing::status {
38using ::absl_testing::IsOk;
39using ::absl_testing::IsOkAndHolds;
40using ::absl_testing::StatusIs;
41} // namespace testing::status
42
43// Macros for testing the results of functions that return absl::Status or
44// absl::StatusOr<T> (for any type T).
45#define EXPECT_OK(expression) EXPECT_THAT(expression, ::testing::status::IsOk())
46#define ASSERT_OK(expression) ASSERT_THAT(expression, ::testing::status::IsOk())
47
48#define STATUS_MATCHERS_IMPL_CONCAT_INNER_(x, y) x##y
49#define STATUS_MATCHERS_IMPL_CONCAT_(x, y) \
50 STATUS_MATCHERS_IMPL_CONCAT_INNER_(x, y)
51
52#undef ASSERT_OK_AND_ASSIGN
53#define ASSERT_OK_AND_ASSIGN(lhs, rexpr) \
54 ASSERT_OK_AND_ASSIGN_IMPL_( \
55 STATUS_MATCHERS_IMPL_CONCAT_(_status_or_value, __COUNTER__), lhs, rexpr)
56
57#define ASSERT_OK_AND_ASSIGN_IMPL_(statusor, lhs, rexpr) \
58 auto statusor = (rexpr); \
59 ASSERT_TRUE(statusor.ok()) << statusor.status(); \
60 lhs = std::move(statusor.value())
61
62#endif // ORTOOLS_BASE_GMOCK_H_