abseil-cpp/absl/base/internal/errno_saver_test.cc
Go to the documentation of this file.
1 // Copyright 2018 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "absl/base/internal/errno_saver.h"
16 
17 #include <cerrno>
18 
19 #include "gmock/gmock.h"
20 #include "gtest/gtest.h"
21 #include "absl/base/internal/strerror.h"
22 
23 namespace {
25 
26 struct ErrnoPrinter {
27  int no;
28 };
29 std::ostream &operator<<(std::ostream &os, ErrnoPrinter ep) {
30  return os << absl::base_internal::StrError(ep.no) << " [" << ep.no << "]";
31 }
32 bool operator==(ErrnoPrinter one, ErrnoPrinter two) { return one.no == two.no; }
33 
34 TEST(ErrnoSaverTest, Works) {
35  errno = EDOM;
36  {
38  EXPECT_THAT(ErrnoPrinter{errno}, Eq(ErrnoPrinter{EDOM}));
39  errno = ERANGE;
40  EXPECT_THAT(ErrnoPrinter{errno}, Eq(ErrnoPrinter{ERANGE}));
41  EXPECT_THAT(ErrnoPrinter{errno_saver()}, Eq(ErrnoPrinter{EDOM}));
42  }
43  EXPECT_THAT(ErrnoPrinter{errno}, Eq(ErrnoPrinter{EDOM}));
44 }
45 } // namespace
grpc_event_engine::experimental::slice_detail::operator==
bool operator==(const BaseSlice &a, const BaseSlice &b)
Definition: include/grpc/event_engine/slice.h:117
EXPECT_THAT
#define EXPECT_THAT(value, matcher)
absl::base_internal::StrError
std::string StrError(int errnum)
Definition: abseil-cpp/absl/base/internal/strerror.cc:77
TEST
#define TEST(name, init_size,...)
Definition: arena_test.cc:75
testing::Eq
internal::EqMatcher< T > Eq(T x)
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:8561
absl::base_internal::ErrnoSaver
Definition: abseil-cpp/absl/base/internal/errno_saver.h:29
grpc::operator<<
std::ostream & operator<<(std::ostream &out, const string_ref &string)
Definition: grpcpp/impl/codegen/string_ref.h:145


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:19