abseil-cpp/absl/status/statusor_test.cc
Go to the documentation of this file.
1 // Copyright 2020 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/status/statusor.h"
16 
17 #include <array>
18 #include <initializer_list>
19 #include <memory>
20 #include <string>
21 #include <type_traits>
22 #include <utility>
23 
24 #include "gmock/gmock.h"
25 #include "gtest/gtest.h"
26 #include "absl/base/casts.h"
27 #include "absl/memory/memory.h"
28 #include "absl/status/status.h"
29 #include "absl/strings/string_view.h"
30 #include "absl/types/any.h"
31 #include "absl/utility/utility.h"
32 
33 namespace {
34 
36 using ::testing::AnyWith;
43 using ::testing::VariantWith;
44 
45 #ifdef GTEST_HAS_STATUS_MATCHERS
47 using ::testing::status::IsOkAndHolds;
48 #else // GTEST_HAS_STATUS_MATCHERS
50  return status;
51 }
52 
53 template <typename T>
54 inline const ::absl::Status& GetStatus(const ::absl::StatusOr<T>& status) {
55  return status.status();
56 }
57 
58 // Monomorphic implementation of matcher IsOkAndHolds(m). StatusOrType is a
59 // reference to StatusOr<T>.
60 template <typename StatusOrType>
61 class IsOkAndHoldsMatcherImpl
62  : public ::testing::MatcherInterface<StatusOrType> {
63  public:
64  typedef
66 
67  template <typename InnerMatcher>
68  explicit IsOkAndHoldsMatcherImpl(InnerMatcher&& inner_matcher)
69  : inner_matcher_(::testing::SafeMatcherCast<const value_type&>(
70  std::forward<InnerMatcher>(inner_matcher))) {}
71 
72  void DescribeTo(std::ostream* os) const override {
73  *os << "is OK and has a value that ";
74  inner_matcher_.DescribeTo(os);
75  }
76 
77  void DescribeNegationTo(std::ostream* os) const override {
78  *os << "isn't OK or has a value that ";
79  inner_matcher_.DescribeNegationTo(os);
80  }
81 
82  bool MatchAndExplain(
83  StatusOrType actual_value,
84  ::testing::MatchResultListener* result_listener) const override {
85  if (!actual_value.ok()) {
86  *result_listener << "which has status " << actual_value.status();
87  return false;
88  }
89 
91  const bool matches =
92  inner_matcher_.MatchAndExplain(*actual_value, &inner_listener);
93  const std::string inner_explanation = inner_listener.str();
94  if (!inner_explanation.empty()) {
95  *result_listener << "which contains value "
96  << ::testing::PrintToString(*actual_value) << ", "
97  << inner_explanation;
98  }
99  return matches;
100  }
101 
102  private:
103  const ::testing::Matcher<const value_type&> inner_matcher_;
104 };
105 
106 // Implements IsOkAndHolds(m) as a polymorphic matcher.
107 template <typename InnerMatcher>
108 class IsOkAndHoldsMatcher {
109  public:
110  explicit IsOkAndHoldsMatcher(InnerMatcher inner_matcher)
111  : inner_matcher_(std::move(inner_matcher)) {}
112 
113  // Converts this polymorphic matcher to a monomorphic matcher of the
114  // given type. StatusOrType can be either StatusOr<T> or a
115  // reference to StatusOr<T>.
116  template <typename StatusOrType>
117  operator ::testing::Matcher<StatusOrType>() const { // NOLINT
118  return ::testing::Matcher<StatusOrType>(
119  new IsOkAndHoldsMatcherImpl<const StatusOrType&>(inner_matcher_));
120  }
121 
122  private:
123  const InnerMatcher inner_matcher_;
124 };
125 
126 // Monomorphic implementation of matcher IsOk() for a given type T.
127 // T can be Status, StatusOr<>, or a reference to either of them.
128 template <typename T>
129 class MonoIsOkMatcherImpl : public ::testing::MatcherInterface<T> {
130  public:
131  void DescribeTo(std::ostream* os) const override { *os << "is OK"; }
132  void DescribeNegationTo(std::ostream* os) const override {
133  *os << "is not OK";
134  }
135  bool MatchAndExplain(T actual_value,
136  ::testing::MatchResultListener*) const override {
137  return GetStatus(actual_value).ok();
138  }
139 };
140 
141 // Implements IsOk() as a polymorphic matcher.
142 class IsOkMatcher {
143  public:
144  template <typename T>
145  operator ::testing::Matcher<T>() const { // NOLINT
146  return ::testing::Matcher<T>(new MonoIsOkMatcherImpl<T>());
147  }
148 };
149 
150 // Macros for testing the results of functions that return absl::Status or
151 // absl::StatusOr<T> (for any type T).
152 #define EXPECT_OK(expression) EXPECT_THAT(expression, IsOk())
153 
154 // Returns a gMock matcher that matches a StatusOr<> whose status is
155 // OK and whose value matches the inner matcher.
156 template <typename InnerMatcher>
158  InnerMatcher&& inner_matcher) {
160  std::forward<InnerMatcher>(inner_matcher));
161 }
162 
163 // Returns a gMock matcher that matches a Status or StatusOr<> which is OK.
164 inline IsOkMatcher IsOk() { return IsOkMatcher(); }
165 #endif // GTEST_HAS_STATUS_MATCHERS
166 
167 struct CopyDetector {
168  CopyDetector() = default;
169  explicit CopyDetector(int xx) : x(xx) {}
170  CopyDetector(CopyDetector&& d) noexcept
171  : x(d.x), copied(false), moved(true) {}
172  CopyDetector(const CopyDetector& d) : x(d.x), copied(true), moved(false) {}
173  CopyDetector& operator=(const CopyDetector& c) {
174  x = c.x;
175  copied = true;
176  moved = false;
177  return *this;
178  }
179  CopyDetector& operator=(CopyDetector&& c) noexcept {
180  x = c.x;
181  copied = false;
182  moved = true;
183  return *this;
184  }
185  int x = 0;
186  bool copied = false;
187  bool moved = false;
188 };
189 
190 testing::Matcher<const CopyDetector&> CopyDetectorHas(int a, bool b, bool c) {
191  return AllOf(Field(&CopyDetector::x, a), Field(&CopyDetector::moved, b),
192  Field(&CopyDetector::copied, c));
193 }
194 
195 class Base1 {
196  public:
197  virtual ~Base1() {}
198  int pad;
199 };
200 
201 class Base2 {
202  public:
203  virtual ~Base2() {}
204  int yetotherpad;
205 };
206 
207 class Derived : public Base1, public Base2 {
208  public:
209  virtual ~Derived() {}
210  int evenmorepad;
211 };
212 
213 class CopyNoAssign {
214  public:
215  explicit CopyNoAssign(int value) : foo(value) {}
216  CopyNoAssign(const CopyNoAssign& other) : foo(other.foo) {}
217  int foo;
218 
219  private:
220  const CopyNoAssign& operator=(const CopyNoAssign&);
221 };
222 
223 absl::StatusOr<std::unique_ptr<int>> ReturnUniquePtr() {
224  // Uses implicit constructor from T&&
225  return absl::make_unique<int>(0);
226 }
227 
228 TEST(StatusOr, ElementType) {
229  static_assert(std::is_same<absl::StatusOr<int>::value_type, int>(), "");
230  static_assert(std::is_same<absl::StatusOr<char>::value_type, char>(), "");
231 }
232 
233 TEST(StatusOr, TestMoveOnlyInitialization) {
234  absl::StatusOr<std::unique_ptr<int>> thing(ReturnUniquePtr());
235  ASSERT_TRUE(thing.ok());
236  EXPECT_EQ(0, **thing);
237  int* previous = thing->get();
238 
239  thing = ReturnUniquePtr();
240  EXPECT_TRUE(thing.ok());
241  EXPECT_EQ(0, **thing);
242  EXPECT_NE(previous, thing->get());
243 }
244 
245 TEST(StatusOr, TestMoveOnlyValueExtraction) {
246  absl::StatusOr<std::unique_ptr<int>> thing(ReturnUniquePtr());
247  ASSERT_TRUE(thing.ok());
248  std::unique_ptr<int> ptr = *std::move(thing);
249  EXPECT_EQ(0, *ptr);
250 
251  thing = std::move(ptr);
252  ptr = std::move(*thing);
253  EXPECT_EQ(0, *ptr);
254 }
255 
256 TEST(StatusOr, TestMoveOnlyInitializationFromTemporaryByValueOrDie) {
257  std::unique_ptr<int> ptr(*ReturnUniquePtr());
258  EXPECT_EQ(0, *ptr);
259 }
260 
261 TEST(StatusOr, TestValueOrDieOverloadForConstTemporary) {
262  static_assert(
263  std::is_same<
264  const int&&,
265  decltype(std::declval<const absl::StatusOr<int>&&>().value())>(),
266  "value() for const temporaries should return const T&&");
267 }
268 
269 TEST(StatusOr, TestMoveOnlyConversion) {
270  absl::StatusOr<std::unique_ptr<const int>> const_thing(ReturnUniquePtr());
271  EXPECT_TRUE(const_thing.ok());
272  EXPECT_EQ(0, **const_thing);
273 
274  // Test rvalue converting assignment
275  const int* const_previous = const_thing->get();
276  const_thing = ReturnUniquePtr();
277  EXPECT_TRUE(const_thing.ok());
278  EXPECT_EQ(0, **const_thing);
279  EXPECT_NE(const_previous, const_thing->get());
280 }
281 
282 TEST(StatusOr, TestMoveOnlyVector) {
283  // Sanity check that absl::StatusOr<MoveOnly> works in vector.
284  std::vector<absl::StatusOr<std::unique_ptr<int>>> vec;
285  vec.push_back(ReturnUniquePtr());
286  vec.resize(2);
287  auto another_vec = std::move(vec);
288  EXPECT_EQ(0, **another_vec[0]);
289  EXPECT_EQ(absl::UnknownError(""), another_vec[1].status());
290 }
291 
292 TEST(StatusOr, TestDefaultCtor) {
293  absl::StatusOr<int> thing;
294  EXPECT_FALSE(thing.ok());
296 }
297 
298 TEST(StatusOr, StatusCtorForwards) {
300 
301  EXPECT_EQ(absl::StatusOr<int>(status).status().message(), "Some error");
302  EXPECT_EQ(status.message(), "Some error");
303 
305  "Some error");
306  EXPECT_NE(status.message(), "Some error");
307 }
308 
309 TEST(BadStatusOrAccessTest, CopyConstructionWhatOk) {
311  absl::InternalError("some arbitrary message too big for the sso buffer");
314  EXPECT_THAT(e1.what(), HasSubstr(error.ToString()));
315  EXPECT_THAT(e2.what(), HasSubstr(error.ToString()));
316 }
317 
318 TEST(BadStatusOrAccessTest, CopyAssignmentWhatOk) {
320  absl::InternalError("some arbitrary message too big for the sso buffer");
323  e2 = e1;
324  EXPECT_THAT(e1.what(), HasSubstr(error.ToString()));
325  EXPECT_THAT(e2.what(), HasSubstr(error.ToString()));
326 }
327 
328 TEST(BadStatusOrAccessTest, MoveConstructionWhatOk) {
330  absl::InternalError("some arbitrary message too big for the sso buffer");
333  EXPECT_THAT(e2.what(), HasSubstr(error.ToString()));
334 }
335 
336 TEST(BadStatusOrAccessTest, MoveAssignmentWhatOk) {
338  absl::InternalError("some arbitrary message too big for the sso buffer");
341  e2 = std::move(e1);
342  EXPECT_THAT(e2.what(), HasSubstr(error.ToString()));
343 }
344 
345 // Define `EXPECT_DEATH_OR_THROW` to test the behavior of `StatusOr::value`,
346 // which either throws `BadStatusOrAccess` or `LOG(FATAL)` based on whether
347 // exceptions are enabled.
348 #ifdef ABSL_HAVE_EXCEPTIONS
349 #define EXPECT_DEATH_OR_THROW(statement, status_) \
350  EXPECT_THROW( \
351  { \
352  try { \
353  statement; \
354  } catch (const absl::BadStatusOrAccess& e) { \
355  EXPECT_EQ(e.status(), status_); \
356  EXPECT_THAT(e.what(), HasSubstr(e.status().ToString())); \
357  throw; \
358  } \
359  }, \
360  absl::BadStatusOrAccess);
361 #else // ABSL_HAVE_EXCEPTIONS
362 #define EXPECT_DEATH_OR_THROW(statement, status) \
363  EXPECT_DEATH_IF_SUPPORTED(statement, status.ToString());
364 #endif // ABSL_HAVE_EXCEPTIONS
365 
366 TEST(StatusOrDeathTest, TestDefaultCtorValue) {
367  absl::StatusOr<int> thing;
369  const absl::StatusOr<int> thing2;
371 }
372 
373 TEST(StatusOrDeathTest, TestValueNotOk) {
376 }
377 
378 TEST(StatusOrDeathTest, TestValueNotOkConst) {
379  const absl::StatusOr<int> thing(absl::UnknownError(""));
380  EXPECT_DEATH_OR_THROW(thing.value(), absl::UnknownError(""));
381 }
382 
383 TEST(StatusOrDeathTest, TestPointerDefaultCtorValue) {
384  absl::StatusOr<int*> thing;
386 }
387 
388 TEST(StatusOrDeathTest, TestPointerValueNotOk) {
391 }
392 
393 TEST(StatusOrDeathTest, TestPointerValueNotOkConst) {
396 }
397 
398 #if GTEST_HAS_DEATH_TEST
399 TEST(StatusOrDeathTest, TestStatusCtorStatusOk) {
400  EXPECT_DEBUG_DEATH(
401  {
402  // This will DCHECK
404  // In optimized mode, we are actually going to get error::INTERNAL for
405  // status here, rather than crashing, so check that.
406  EXPECT_FALSE(thing.ok());
407  EXPECT_EQ(thing.status().code(), absl::StatusCode::kInternal);
408  },
409  "An OK status is not a valid constructor argument");
410 }
411 
412 TEST(StatusOrDeathTest, TestPointerStatusCtorStatusOk) {
413  EXPECT_DEBUG_DEATH(
414  {
416  // In optimized mode, we are actually going to get error::INTERNAL for
417  // status here, rather than crashing, so check that.
418  EXPECT_FALSE(thing.ok());
419  EXPECT_EQ(thing.status().code(), absl::StatusCode::kInternal);
420  },
421  "An OK status is not a valid constructor argument");
422 }
423 #endif
424 
425 TEST(StatusOr, ValueAccessor) {
426  const int kIntValue = 110;
427  {
428  absl::StatusOr<int> status_or(kIntValue);
429  EXPECT_EQ(kIntValue, status_or.value());
430  EXPECT_EQ(kIntValue, std::move(status_or).value());
431  }
432  {
433  absl::StatusOr<CopyDetector> status_or(kIntValue);
434  EXPECT_THAT(status_or,
435  IsOkAndHolds(CopyDetectorHas(kIntValue, false, false)));
436  CopyDetector copy_detector = status_or.value();
437  EXPECT_THAT(copy_detector, CopyDetectorHas(kIntValue, false, true));
438  copy_detector = std::move(status_or).value();
439  EXPECT_THAT(copy_detector, CopyDetectorHas(kIntValue, true, false));
440  }
441 }
442 
443 TEST(StatusOr, BadValueAccess) {
444  const absl::Status kError = absl::CancelledError("message");
445  absl::StatusOr<int> status_or(kError);
446  EXPECT_DEATH_OR_THROW(status_or.value(), kError);
447 }
448 
449 TEST(StatusOr, TestStatusCtor) {
451  EXPECT_FALSE(thing.ok());
452  EXPECT_EQ(thing.status().code(), absl::StatusCode::kCancelled);
453 }
454 
455 TEST(StatusOr, TestValueCtor) {
456  const int kI = 4;
457  const absl::StatusOr<int> thing(kI);
458  EXPECT_TRUE(thing.ok());
459  EXPECT_EQ(kI, *thing);
460 }
461 
462 struct Foo {
463  const int x;
464  explicit Foo(int y) : x(y) {}
465 };
466 
467 TEST(StatusOr, InPlaceConstruction) {
468  EXPECT_THAT(absl::StatusOr<Foo>(absl::in_place, 10),
469  IsOkAndHolds(Field(&Foo::x, 10)));
470 }
471 
472 struct InPlaceHelper {
473  InPlaceHelper(std::initializer_list<int> xs, std::unique_ptr<int> yy)
474  : x(xs), y(std::move(yy)) {}
475  const std::vector<int> x;
476  std::unique_ptr<int> y;
477 };
478 
479 TEST(StatusOr, InPlaceInitListConstruction) {
480  absl::StatusOr<InPlaceHelper> status_or(absl::in_place, {10, 11, 12},
481  absl::make_unique<int>(13));
482  EXPECT_THAT(status_or, IsOkAndHolds(AllOf(
483  Field(&InPlaceHelper::x, ElementsAre(10, 11, 12)),
484  Field(&InPlaceHelper::y, Pointee(13)))));
485 }
486 
487 TEST(StatusOr, Emplace) {
488  absl::StatusOr<Foo> status_or_foo(10);
489  status_or_foo.emplace(20);
490  EXPECT_THAT(status_or_foo, IsOkAndHolds(Field(&Foo::x, 20)));
491  status_or_foo = absl::InvalidArgumentError("msg");
492  EXPECT_FALSE(status_or_foo.ok());
493  EXPECT_EQ(status_or_foo.status().code(), absl::StatusCode::kInvalidArgument);
494  EXPECT_EQ(status_or_foo.status().message(), "msg");
495  status_or_foo.emplace(20);
496  EXPECT_THAT(status_or_foo, IsOkAndHolds(Field(&Foo::x, 20)));
497 }
498 
499 TEST(StatusOr, EmplaceInitializerList) {
500  absl::StatusOr<InPlaceHelper> status_or(absl::in_place, {10, 11, 12},
501  absl::make_unique<int>(13));
502  status_or.emplace({1, 2, 3}, absl::make_unique<int>(4));
503  EXPECT_THAT(status_or,
504  IsOkAndHolds(AllOf(Field(&InPlaceHelper::x, ElementsAre(1, 2, 3)),
505  Field(&InPlaceHelper::y, Pointee(4)))));
506  status_or = absl::InvalidArgumentError("msg");
507  EXPECT_FALSE(status_or.ok());
508  EXPECT_EQ(status_or.status().code(), absl::StatusCode::kInvalidArgument);
509  EXPECT_EQ(status_or.status().message(), "msg");
510  status_or.emplace({1, 2, 3}, absl::make_unique<int>(4));
511  EXPECT_THAT(status_or,
512  IsOkAndHolds(AllOf(Field(&InPlaceHelper::x, ElementsAre(1, 2, 3)),
513  Field(&InPlaceHelper::y, Pointee(4)))));
514 }
515 
516 TEST(StatusOr, TestCopyCtorStatusOk) {
517  const int kI = 4;
518  const absl::StatusOr<int> original(kI);
519  const absl::StatusOr<int> copy(original);
520  EXPECT_OK(copy.status());
521  EXPECT_EQ(*original, *copy);
522 }
523 
524 TEST(StatusOr, TestCopyCtorStatusNotOk) {
526  absl::StatusOr<int> copy(original);
527  EXPECT_EQ(copy.status().code(), absl::StatusCode::kCancelled);
528 }
529 
530 TEST(StatusOr, TestCopyCtorNonAssignable) {
531  const int kI = 4;
532  CopyNoAssign value(kI);
535  EXPECT_OK(copy.status());
536  EXPECT_EQ(original->foo, copy->foo);
537 }
538 
539 TEST(StatusOr, TestCopyCtorStatusOKConverting) {
540  const int kI = 4;
541  absl::StatusOr<int> original(kI);
542  absl::StatusOr<double> copy(original);
543  EXPECT_OK(copy.status());
544  EXPECT_DOUBLE_EQ(*original, *copy);
545 }
546 
547 TEST(StatusOr, TestCopyCtorStatusNotOkConverting) {
549  absl::StatusOr<double> copy(original);
550  EXPECT_EQ(copy.status(), original.status());
551 }
552 
553 TEST(StatusOr, TestAssignmentStatusOk) {
554  // Copy assignmment
555  {
556  const auto p = std::make_shared<int>(17);
558 
560  target = source;
561 
562  ASSERT_TRUE(target.ok());
563  EXPECT_OK(target.status());
564  EXPECT_EQ(p, *target);
565 
566  ASSERT_TRUE(source.ok());
567  EXPECT_OK(source.status());
568  EXPECT_EQ(p, *source);
569  }
570 
571  // Move asssignment
572  {
573  const auto p = std::make_shared<int>(17);
575 
577  target = std::move(source);
578 
579  ASSERT_TRUE(target.ok());
580  EXPECT_OK(target.status());
581  EXPECT_EQ(p, *target);
582 
583  ASSERT_TRUE(source.ok());
584  EXPECT_OK(source.status());
585  EXPECT_EQ(nullptr, *source);
586  }
587 }
588 
589 TEST(StatusOr, TestAssignmentStatusNotOk) {
590  // Copy assignment
591  {
592  const absl::Status expected = absl::CancelledError();
593  absl::StatusOr<int> source(expected);
594 
596  target = source;
597 
598  EXPECT_FALSE(target.ok());
599  EXPECT_EQ(expected, target.status());
600 
601  EXPECT_FALSE(source.ok());
602  EXPECT_EQ(expected, source.status());
603  }
604 
605  // Move assignment
606  {
607  const absl::Status expected = absl::CancelledError();
608  absl::StatusOr<int> source(expected);
609 
611  target = std::move(source);
612 
613  EXPECT_FALSE(target.ok());
614  EXPECT_EQ(expected, target.status());
615 
616  EXPECT_FALSE(source.ok());
617  EXPECT_EQ(source.status().code(), absl::StatusCode::kInternal);
618  }
619 }
620 
621 TEST(StatusOr, TestAssignmentStatusOKConverting) {
622  // Copy assignment
623  {
624  const int kI = 4;
625  absl::StatusOr<int> source(kI);
626 
628  target = source;
629 
630  ASSERT_TRUE(target.ok());
631  EXPECT_OK(target.status());
632  EXPECT_DOUBLE_EQ(kI, *target);
633 
634  ASSERT_TRUE(source.ok());
635  EXPECT_OK(source.status());
636  EXPECT_DOUBLE_EQ(kI, *source);
637  }
638 
639  // Move assignment
640  {
641  const auto p = new int(17);
643 
645  target = std::move(source);
646 
647  ASSERT_TRUE(target.ok());
648  EXPECT_OK(target.status());
649  EXPECT_EQ(p, target->get());
650 
651  ASSERT_TRUE(source.ok());
652  EXPECT_OK(source.status());
653  EXPECT_EQ(nullptr, source->get());
654  }
655 }
656 
657 struct A {
658  int x;
659 };
660 
661 struct ImplicitConstructibleFromA {
662  int x;
663  bool moved;
664  ImplicitConstructibleFromA(const A& a) // NOLINT
665  : x(a.x), moved(false) {}
666  ImplicitConstructibleFromA(A&& a) // NOLINT
667  : x(a.x), moved(true) {}
668 };
669 
670 TEST(StatusOr, ImplicitConvertingConstructor) {
671  EXPECT_THAT(
673  absl::StatusOr<A>(A{11})),
674  IsOkAndHolds(AllOf(Field(&ImplicitConstructibleFromA::x, 11),
675  Field(&ImplicitConstructibleFromA::moved, true))));
676  absl::StatusOr<A> a(A{12});
677  EXPECT_THAT(
679  IsOkAndHolds(AllOf(Field(&ImplicitConstructibleFromA::x, 12),
680  Field(&ImplicitConstructibleFromA::moved, false))));
681 }
682 
683 struct ExplicitConstructibleFromA {
684  int x;
685  bool moved;
686  explicit ExplicitConstructibleFromA(const A& a) : x(a.x), moved(false) {}
687  explicit ExplicitConstructibleFromA(A&& a) : x(a.x), moved(true) {}
688 };
689 
690 TEST(StatusOr, ExplicitConvertingConstructor) {
691  EXPECT_FALSE(
692  (std::is_convertible<const absl::StatusOr<A>&,
694  EXPECT_FALSE(
695  (std::is_convertible<absl::StatusOr<A>&&,
697  EXPECT_THAT(
699  IsOkAndHolds(AllOf(Field(&ExplicitConstructibleFromA::x, 11),
700  Field(&ExplicitConstructibleFromA::moved, true))));
701  absl::StatusOr<A> a(A{12});
702  EXPECT_THAT(
704  IsOkAndHolds(AllOf(Field(&ExplicitConstructibleFromA::x, 12),
705  Field(&ExplicitConstructibleFromA::moved, false))));
706 }
707 
708 struct ImplicitConstructibleFromBool {
709  ImplicitConstructibleFromBool(bool y) : x(y) {} // NOLINT
710  bool x = false;
711 };
712 
713 struct ConvertibleToBool {
714  explicit ConvertibleToBool(bool y) : x(y) {}
715  operator bool() const { return x; } // NOLINT
716  bool x = false;
717 };
718 
719 TEST(StatusOr, ImplicitBooleanConstructionWithImplicitCasts) {
721  IsOkAndHolds(true));
723  IsOkAndHolds(false));
724  EXPECT_THAT(
726  absl::StatusOr<bool>(false)),
727  IsOkAndHolds(Field(&ImplicitConstructibleFromBool::x, false)));
728  EXPECT_FALSE((std::is_convertible<
731 }
732 
733 TEST(StatusOr, BooleanConstructionWithImplicitCasts) {
735  IsOkAndHolds(true));
737  IsOkAndHolds(false));
738  EXPECT_THAT(
740  absl::StatusOr<bool>(false)},
741  IsOkAndHolds(Field(&ImplicitConstructibleFromBool::x, false)));
742  EXPECT_THAT(
745  Not(IsOk()));
746 
747  EXPECT_THAT(
749  absl::StatusOr<ConvertibleToBool>(ConvertibleToBool{false})},
750  IsOkAndHolds(Field(&ImplicitConstructibleFromBool::x, false)));
751  EXPECT_THAT(
754  Not(IsOk()));
755 }
756 
757 TEST(StatusOr, ConstImplicitCast) {
760  IsOkAndHolds(true));
763  IsOkAndHolds(false));
765  absl::StatusOr<bool>(true)),
766  IsOkAndHolds(true));
768  absl::StatusOr<bool>(false)),
769  IsOkAndHolds(false));
772  IsOkAndHolds("foo"));
775  IsOkAndHolds("foo"));
776  EXPECT_THAT(
777  absl::implicit_cast<absl::StatusOr<std::shared_ptr<const std::string>>>(
778  absl::StatusOr<std::shared_ptr<std::string>>(
779  std::make_shared<std::string>("foo"))),
780  IsOkAndHolds(Pointee(std::string("foo"))));
781 }
782 
783 TEST(StatusOr, ConstExplicitConstruction) {
785  IsOkAndHolds(true));
787  IsOkAndHolds(false));
789  IsOkAndHolds(true));
791  IsOkAndHolds(false));
792 }
793 
794 struct ExplicitConstructibleFromInt {
795  int x;
796  explicit ExplicitConstructibleFromInt(int y) : x(y) {}
797 };
798 
799 TEST(StatusOr, ExplicitConstruction) {
801  IsOkAndHolds(Field(&ExplicitConstructibleFromInt::x, 10)));
802 }
803 
804 TEST(StatusOr, ImplicitConstruction) {
805  // Check implicit casting works.
806  auto status_or =
807  absl::implicit_cast<absl::StatusOr<absl::variant<int, std::string>>>(10);
808  EXPECT_THAT(status_or, IsOkAndHolds(VariantWith<int>(10)));
809 }
810 
811 TEST(StatusOr, ImplicitConstructionFromInitliazerList) {
812  // Note: dropping the explicit std::initializer_list<int> is not supported
813  // by absl::StatusOr or absl::optional.
814  auto status_or =
815  absl::implicit_cast<absl::StatusOr<std::vector<int>>>({{10, 20, 30}});
816  EXPECT_THAT(status_or, IsOkAndHolds(ElementsAre(10, 20, 30)));
817 }
818 
819 TEST(StatusOr, UniquePtrImplicitConstruction) {
820  auto status_or = absl::implicit_cast<absl::StatusOr<std::unique_ptr<Base1>>>(
821  absl::make_unique<Derived>());
822  EXPECT_THAT(status_or, IsOkAndHolds(Ne(nullptr)));
823 }
824 
825 TEST(StatusOr, NestedStatusOrCopyAndMoveConstructorTests) {
826  absl::StatusOr<absl::StatusOr<CopyDetector>> status_or = CopyDetector(10);
829  EXPECT_THAT(status_or,
830  IsOkAndHolds(IsOkAndHolds(CopyDetectorHas(10, true, false))));
832  EXPECT_THAT(a, IsOkAndHolds(IsOkAndHolds(CopyDetectorHas(10, false, true))));
833  absl::StatusOr<absl::StatusOr<CopyDetector>> a_err = status_error;
834  EXPECT_THAT(a_err, Not(IsOk()));
835 
836  const absl::StatusOr<absl::StatusOr<CopyDetector>>& cref = status_or;
838  EXPECT_THAT(b, IsOkAndHolds(IsOkAndHolds(CopyDetectorHas(10, false, true))));
839  const absl::StatusOr<absl::StatusOr<CopyDetector>>& cref_err = status_error;
840  absl::StatusOr<absl::StatusOr<CopyDetector>> b_err = cref_err; // NOLINT
841  EXPECT_THAT(b_err, Not(IsOk()));
842 
844  EXPECT_THAT(c, IsOkAndHolds(IsOkAndHolds(CopyDetectorHas(10, true, false))));
846  EXPECT_THAT(c_err, Not(IsOk()));
847 }
848 
849 TEST(StatusOr, NestedStatusOrCopyAndMoveAssignment) {
850  absl::StatusOr<absl::StatusOr<CopyDetector>> status_or = CopyDetector(10);
854  a = status_or;
855  EXPECT_THAT(a, IsOkAndHolds(IsOkAndHolds(CopyDetectorHas(10, false, true))));
856  a = status_error;
857  EXPECT_THAT(a, Not(IsOk()));
858 
859  const absl::StatusOr<absl::StatusOr<CopyDetector>>& cref = status_or;
860  a = cref;
861  EXPECT_THAT(a, IsOkAndHolds(IsOkAndHolds(CopyDetectorHas(10, false, true))));
862  const absl::StatusOr<absl::StatusOr<CopyDetector>>& cref_err = status_error;
863  a = cref_err;
864  EXPECT_THAT(a, Not(IsOk()));
865  a = std::move(status_or);
866  EXPECT_THAT(a, IsOkAndHolds(IsOkAndHolds(CopyDetectorHas(10, true, false))));
867  a = std::move(status_error);
868  EXPECT_THAT(a, Not(IsOk()));
869 }
870 
871 struct Copyable {
872  Copyable() {}
873  Copyable(const Copyable&) {}
874  Copyable& operator=(const Copyable&) { return *this; }
875 };
876 
877 struct MoveOnly {
878  MoveOnly() {}
879  MoveOnly(MoveOnly&&) {}
880  MoveOnly& operator=(MoveOnly&&) { return *this; }
881 };
882 
883 struct NonMovable {
884  NonMovable() {}
885  NonMovable(const NonMovable&) = delete;
886  NonMovable(NonMovable&&) = delete;
887  NonMovable& operator=(const NonMovable&) = delete;
888  NonMovable& operator=(NonMovable&&) = delete;
889 };
890 
891 TEST(StatusOr, CopyAndMoveAbility) {
904 }
905 
906 TEST(StatusOr, StatusOrAnyCopyAndMoveConstructorTests) {
907  absl::StatusOr<absl::any> status_or = CopyDetector(10);
909  EXPECT_THAT(
910  status_or,
911  IsOkAndHolds(AnyWith<CopyDetector>(CopyDetectorHas(10, true, false))));
912  absl::StatusOr<absl::any> a = status_or;
913  EXPECT_THAT(
914  a, IsOkAndHolds(AnyWith<CopyDetector>(CopyDetectorHas(10, false, true))));
915  absl::StatusOr<absl::any> a_err = status_error;
916  EXPECT_THAT(a_err, Not(IsOk()));
917 
918  const absl::StatusOr<absl::any>& cref = status_or;
919  // No lint for no-change copy.
920  absl::StatusOr<absl::any> b = cref; // NOLINT
921  EXPECT_THAT(
922  b, IsOkAndHolds(AnyWith<CopyDetector>(CopyDetectorHas(10, false, true))));
923  const absl::StatusOr<absl::any>& cref_err = status_error;
924  // No lint for no-change copy.
925  absl::StatusOr<absl::any> b_err = cref_err; // NOLINT
926  EXPECT_THAT(b_err, Not(IsOk()));
927 
929  EXPECT_THAT(
930  c, IsOkAndHolds(AnyWith<CopyDetector>(CopyDetectorHas(10, true, false))));
931  absl::StatusOr<absl::any> c_err = std::move(status_error);
932  EXPECT_THAT(c_err, Not(IsOk()));
933 }
934 
935 TEST(StatusOr, StatusOrAnyCopyAndMoveAssignment) {
936  absl::StatusOr<absl::any> status_or = CopyDetector(10);
939  a = status_or;
940  EXPECT_THAT(
941  a, IsOkAndHolds(AnyWith<CopyDetector>(CopyDetectorHas(10, false, true))));
942  a = status_error;
943  EXPECT_THAT(a, Not(IsOk()));
944 
945  const absl::StatusOr<absl::any>& cref = status_or;
946  a = cref;
947  EXPECT_THAT(
948  a, IsOkAndHolds(AnyWith<CopyDetector>(CopyDetectorHas(10, false, true))));
949  const absl::StatusOr<absl::any>& cref_err = status_error;
950  a = cref_err;
951  EXPECT_THAT(a, Not(IsOk()));
952  a = std::move(status_or);
953  EXPECT_THAT(
954  a, IsOkAndHolds(AnyWith<CopyDetector>(CopyDetectorHas(10, true, false))));
955  a = std::move(status_error);
956  EXPECT_THAT(a, Not(IsOk()));
957 }
958 
959 TEST(StatusOr, StatusOrCopyAndMoveTestsConstructor) {
960  absl::StatusOr<CopyDetector> status_or(10);
961  ASSERT_THAT(status_or, IsOkAndHolds(CopyDetectorHas(10, false, false)));
962  absl::StatusOr<CopyDetector> a(status_or);
963  EXPECT_THAT(a, IsOkAndHolds(CopyDetectorHas(10, false, true)));
964  const absl::StatusOr<CopyDetector>& cref = status_or;
965  absl::StatusOr<CopyDetector> b(cref); // NOLINT
966  EXPECT_THAT(b, IsOkAndHolds(CopyDetectorHas(10, false, true)));
968  EXPECT_THAT(c, IsOkAndHolds(CopyDetectorHas(10, true, false)));
969 }
970 
971 TEST(StatusOr, StatusOrCopyAndMoveTestsAssignment) {
972  absl::StatusOr<CopyDetector> status_or(10);
973  ASSERT_THAT(status_or, IsOkAndHolds(CopyDetectorHas(10, false, false)));
975  a = status_or;
976  EXPECT_THAT(a, IsOkAndHolds(CopyDetectorHas(10, false, true)));
977  const absl::StatusOr<CopyDetector>& cref = status_or;
979  b = cref;
980  EXPECT_THAT(b, IsOkAndHolds(CopyDetectorHas(10, false, true)));
982  c = std::move(status_or);
983  EXPECT_THAT(c, IsOkAndHolds(CopyDetectorHas(10, true, false)));
984 }
985 
986 TEST(StatusOr, AbslAnyAssignment) {
987  EXPECT_FALSE((std::is_assignable<absl::StatusOr<absl::any>,
989  absl::StatusOr<absl::any> status_or;
990  status_or = absl::InvalidArgumentError("foo");
991  EXPECT_THAT(status_or, Not(IsOk()));
992 }
993 
994 TEST(StatusOr, ImplicitAssignment) {
996  status_or = 10;
997  EXPECT_THAT(status_or, IsOkAndHolds(VariantWith<int>(10)));
998 }
999 
1000 TEST(StatusOr, SelfDirectInitAssignment) {
1001  absl::StatusOr<std::vector<int>> status_or = {{10, 20, 30}};
1002  status_or = *status_or;
1003  EXPECT_THAT(status_or, IsOkAndHolds(ElementsAre(10, 20, 30)));
1004 }
1005 
1006 TEST(StatusOr, ImplicitCastFromInitializerList) {
1007  absl::StatusOr<std::vector<int>> status_or = {{10, 20, 30}};
1008  EXPECT_THAT(status_or, IsOkAndHolds(ElementsAre(10, 20, 30)));
1009 }
1010 
1011 TEST(StatusOr, UniquePtrImplicitAssignment) {
1013  status_or = absl::make_unique<Derived>();
1014  EXPECT_THAT(status_or, IsOkAndHolds(Ne(nullptr)));
1015 }
1016 
1017 TEST(StatusOr, Pointer) {
1018  struct A {};
1019  struct B : public A {};
1020  struct C : private A {};
1021 
1022  EXPECT_TRUE((std::is_constructible<absl::StatusOr<A*>, B*>::value));
1023  EXPECT_TRUE((std::is_convertible<B*, absl::StatusOr<A*>>::value));
1024  EXPECT_FALSE((std::is_constructible<absl::StatusOr<A*>, C*>::value));
1025  EXPECT_FALSE((std::is_convertible<C*, absl::StatusOr<A*>>::value));
1026 }
1027 
1028 TEST(StatusOr, TestAssignmentStatusNotOkConverting) {
1029  // Copy assignment
1030  {
1031  const absl::Status expected = absl::CancelledError();
1032  absl::StatusOr<int> source(expected);
1033 
1035  target = source;
1036 
1037  EXPECT_FALSE(target.ok());
1038  EXPECT_EQ(expected, target.status());
1039 
1040  EXPECT_FALSE(source.ok());
1041  EXPECT_EQ(expected, source.status());
1042  }
1043 
1044  // Move assignment
1045  {
1046  const absl::Status expected = absl::CancelledError();
1047  absl::StatusOr<int> source(expected);
1048 
1050  target = std::move(source);
1051 
1052  EXPECT_FALSE(target.ok());
1053  EXPECT_EQ(expected, target.status());
1054 
1055  EXPECT_FALSE(source.ok());
1056  EXPECT_EQ(source.status().code(), absl::StatusCode::kInternal);
1057  }
1058 }
1059 
1060 TEST(StatusOr, SelfAssignment) {
1061  // Copy-assignment, status OK
1062  {
1063  // A string long enough that it's likely to defeat any inline representation
1064  // optimization.
1065  const std::string long_str(128, 'a');
1066 
1067  absl::StatusOr<std::string> so = long_str;
1068  so = *&so;
1069 
1070  ASSERT_TRUE(so.ok());
1071  EXPECT_OK(so.status());
1072  EXPECT_EQ(long_str, *so);
1073  }
1074 
1075  // Copy-assignment, error status
1076  {
1078  so = *&so;
1079 
1080  EXPECT_FALSE(so.ok());
1082  EXPECT_EQ(so.status().message(), "taco");
1083  }
1084 
1085  // Move-assignment with copyable type, status OK
1086  {
1087  absl::StatusOr<int> so = 17;
1088 
1089  // Fool the compiler, which otherwise complains.
1090  auto& same = so;
1091  so = std::move(same);
1092 
1093  ASSERT_TRUE(so.ok());
1094  EXPECT_OK(so.status());
1095  EXPECT_EQ(17, *so);
1096  }
1097 
1098  // Move-assignment with copyable type, error status
1099  {
1101 
1102  // Fool the compiler, which otherwise complains.
1103  auto& same = so;
1104  so = std::move(same);
1105 
1106  EXPECT_FALSE(so.ok());
1108  EXPECT_EQ(so.status().message(), "taco");
1109  }
1110 
1111  // Move-assignment with non-copyable type, status OK
1112  {
1113  const auto raw = new int(17);
1115 
1116  // Fool the compiler, which otherwise complains.
1117  auto& same = so;
1118  so = std::move(same);
1119 
1120  ASSERT_TRUE(so.ok());
1121  EXPECT_OK(so.status());
1122  EXPECT_EQ(raw, so->get());
1123  }
1124 
1125  // Move-assignment with non-copyable type, error status
1126  {
1128 
1129  // Fool the compiler, which otherwise complains.
1130  auto& same = so;
1131  so = std::move(same);
1132 
1133  EXPECT_FALSE(so.ok());
1135  EXPECT_EQ(so.status().message(), "taco");
1136  }
1137 }
1138 
1139 // These types form the overload sets of the constructors and the assignment
1140 // operators of `MockValue`. They distinguish construction from assignment,
1141 // lvalue from rvalue.
1142 struct FromConstructibleAssignableLvalue {};
1143 struct FromConstructibleAssignableRvalue {};
1144 struct FromImplicitConstructibleOnly {};
1145 struct FromAssignableOnly {};
1146 
1147 // This class is for testing the forwarding value assignments of `StatusOr`.
1148 // `from_rvalue` indicates whether the constructor or the assignment taking
1149 // rvalue reference is called. `from_assignment` indicates whether any
1150 // assignment is called.
1151 struct MockValue {
1152  // Constructs `MockValue` from `FromConstructibleAssignableLvalue`.
1153  MockValue(const FromConstructibleAssignableLvalue&) // NOLINT
1154  : from_rvalue(false), assigned(false) {}
1155  // Constructs `MockValue` from `FromConstructibleAssignableRvalue`.
1156  MockValue(FromConstructibleAssignableRvalue&&) // NOLINT
1157  : from_rvalue(true), assigned(false) {}
1158  // Constructs `MockValue` from `FromImplicitConstructibleOnly`.
1159  // `MockValue` is not assignable from `FromImplicitConstructibleOnly`.
1160  MockValue(const FromImplicitConstructibleOnly&) // NOLINT
1161  : from_rvalue(false), assigned(false) {}
1162  // Assigns `FromConstructibleAssignableLvalue`.
1163  MockValue& operator=(const FromConstructibleAssignableLvalue&) {
1164  from_rvalue = false;
1165  assigned = true;
1166  return *this;
1167  }
1168  // Assigns `FromConstructibleAssignableRvalue` (rvalue only).
1169  MockValue& operator=(FromConstructibleAssignableRvalue&&) {
1170  from_rvalue = true;
1171  assigned = true;
1172  return *this;
1173  }
1174  // Assigns `FromAssignableOnly`, but not constructible from
1175  // `FromAssignableOnly`.
1176  MockValue& operator=(const FromAssignableOnly&) {
1177  from_rvalue = false;
1178  assigned = true;
1179  return *this;
1180  }
1181  bool from_rvalue;
1182  bool assigned;
1183 };
1184 
1185 // operator=(U&&)
1186 TEST(StatusOr, PerfectForwardingAssignment) {
1187  // U == T
1188  constexpr int kValue1 = 10, kValue2 = 20;
1189  absl::StatusOr<CopyDetector> status_or;
1190  CopyDetector lvalue(kValue1);
1191  status_or = lvalue;
1192  EXPECT_THAT(status_or, IsOkAndHolds(CopyDetectorHas(kValue1, false, true)));
1193  status_or = CopyDetector(kValue2);
1194  EXPECT_THAT(status_or, IsOkAndHolds(CopyDetectorHas(kValue2, true, false)));
1195 
1196  // U != T
1197  EXPECT_TRUE(
1198  (std::is_assignable<absl::StatusOr<MockValue>&,
1199  const FromConstructibleAssignableLvalue&>::value));
1200  EXPECT_TRUE((std::is_assignable<absl::StatusOr<MockValue>&,
1201  FromConstructibleAssignableLvalue&&>::value));
1202  EXPECT_FALSE(
1203  (std::is_assignable<absl::StatusOr<MockValue>&,
1204  const FromConstructibleAssignableRvalue&>::value));
1205  EXPECT_TRUE((std::is_assignable<absl::StatusOr<MockValue>&,
1206  FromConstructibleAssignableRvalue&&>::value));
1207  EXPECT_TRUE(
1208  (std::is_assignable<absl::StatusOr<MockValue>&,
1209  const FromImplicitConstructibleOnly&>::value));
1210  EXPECT_FALSE((std::is_assignable<absl::StatusOr<MockValue>&,
1211  const FromAssignableOnly&>::value));
1212 
1213  absl::StatusOr<MockValue> from_lvalue(FromConstructibleAssignableLvalue{});
1214  EXPECT_FALSE(from_lvalue->from_rvalue);
1215  EXPECT_FALSE(from_lvalue->assigned);
1216  from_lvalue = FromConstructibleAssignableLvalue{};
1217  EXPECT_FALSE(from_lvalue->from_rvalue);
1218  EXPECT_TRUE(from_lvalue->assigned);
1219 
1220  absl::StatusOr<MockValue> from_rvalue(FromConstructibleAssignableRvalue{});
1221  EXPECT_TRUE(from_rvalue->from_rvalue);
1222  EXPECT_FALSE(from_rvalue->assigned);
1223  from_rvalue = FromConstructibleAssignableRvalue{};
1224  EXPECT_TRUE(from_rvalue->from_rvalue);
1225  EXPECT_TRUE(from_rvalue->assigned);
1226 
1227  absl::StatusOr<MockValue> from_implicit_constructible(
1228  FromImplicitConstructibleOnly{});
1229  EXPECT_FALSE(from_implicit_constructible->from_rvalue);
1230  EXPECT_FALSE(from_implicit_constructible->assigned);
1231  // construct a temporary `StatusOr` object and invoke the `StatusOr` move
1232  // assignment operator.
1233  from_implicit_constructible = FromImplicitConstructibleOnly{};
1234  EXPECT_FALSE(from_implicit_constructible->from_rvalue);
1235  EXPECT_FALSE(from_implicit_constructible->assigned);
1236 }
1237 
1238 TEST(StatusOr, TestStatus) {
1239  absl::StatusOr<int> good(4);
1240  EXPECT_TRUE(good.ok());
1242  EXPECT_FALSE(bad.ok());
1243  EXPECT_EQ(bad.status().code(), absl::StatusCode::kCancelled);
1244 }
1245 
1246 TEST(StatusOr, OperatorStarRefQualifiers) {
1247  static_assert(
1248  std::is_same<const int&,
1249  decltype(*std::declval<const absl::StatusOr<int>&>())>(),
1250  "Unexpected ref-qualifiers");
1251  static_assert(
1252  std::is_same<int&, decltype(*std::declval<absl::StatusOr<int>&>())>(),
1253  "Unexpected ref-qualifiers");
1254  static_assert(
1255  std::is_same<const int&&,
1256  decltype(*std::declval<const absl::StatusOr<int>&&>())>(),
1257  "Unexpected ref-qualifiers");
1258  static_assert(
1259  std::is_same<int&&, decltype(*std::declval<absl::StatusOr<int>&&>())>(),
1260  "Unexpected ref-qualifiers");
1261 }
1262 
1263 TEST(StatusOr, OperatorStar) {
1264  const absl::StatusOr<std::string> const_lvalue("hello");
1265  EXPECT_EQ("hello", *const_lvalue);
1266 
1267  absl::StatusOr<std::string> lvalue("hello");
1268  EXPECT_EQ("hello", *lvalue);
1269 
1270  // Note: Recall that std::move() is equivalent to a static_cast to an rvalue
1271  // reference type.
1272  const absl::StatusOr<std::string> const_rvalue("hello");
1273  EXPECT_EQ("hello", *std::move(const_rvalue)); // NOLINT
1274 
1275  absl::StatusOr<std::string> rvalue("hello");
1276  EXPECT_EQ("hello", *std::move(rvalue));
1277 }
1278 
1279 TEST(StatusOr, OperatorArrowQualifiers) {
1280  static_assert(
1281  std::is_same<
1282  const int*,
1283  decltype(std::declval<const absl::StatusOr<int>&>().operator->())>(),
1284  "Unexpected qualifiers");
1285  static_assert(
1286  std::is_same<
1287  int*, decltype(std::declval<absl::StatusOr<int>&>().operator->())>(),
1288  "Unexpected qualifiers");
1289  static_assert(
1290  std::is_same<
1291  const int*,
1292  decltype(std::declval<const absl::StatusOr<int>&&>().operator->())>(),
1293  "Unexpected qualifiers");
1294  static_assert(
1295  std::is_same<
1296  int*, decltype(std::declval<absl::StatusOr<int>&&>().operator->())>(),
1297  "Unexpected qualifiers");
1298 }
1299 
1300 TEST(StatusOr, OperatorArrow) {
1301  const absl::StatusOr<std::string> const_lvalue("hello");
1302  EXPECT_EQ(std::string("hello"), const_lvalue->c_str());
1303 
1304  absl::StatusOr<std::string> lvalue("hello");
1305  EXPECT_EQ(std::string("hello"), lvalue->c_str());
1306 }
1307 
1308 TEST(StatusOr, RValueStatus) {
1310  const absl::Status s = std::move(so).status();
1311 
1313  EXPECT_EQ(s.message(), "taco");
1314 
1315  // Check that !ok() still implies !status().ok(), even after moving out of the
1316  // object. See the note on the rvalue ref-qualified status method.
1317  EXPECT_FALSE(so.ok()); // NOLINT
1318  EXPECT_FALSE(so.status().ok());
1319  EXPECT_EQ(so.status().code(), absl::StatusCode::kInternal);
1320  EXPECT_EQ(so.status().message(), "Status accessed after move.");
1321 }
1322 
1323 TEST(StatusOr, TestValue) {
1324  const int kI = 4;
1325  absl::StatusOr<int> thing(kI);
1326  EXPECT_EQ(kI, *thing);
1327 }
1328 
1329 TEST(StatusOr, TestValueConst) {
1330  const int kI = 4;
1331  const absl::StatusOr<int> thing(kI);
1332  EXPECT_EQ(kI, *thing);
1333 }
1334 
1335 TEST(StatusOr, TestPointerDefaultCtor) {
1336  absl::StatusOr<int*> thing;
1337  EXPECT_FALSE(thing.ok());
1338  EXPECT_EQ(thing.status().code(), absl::StatusCode::kUnknown);
1339 }
1340 
1341 TEST(StatusOr, TestPointerStatusCtor) {
1343  EXPECT_FALSE(thing.ok());
1344  EXPECT_EQ(thing.status().code(), absl::StatusCode::kCancelled);
1345 }
1346 
1347 TEST(StatusOr, TestPointerValueCtor) {
1348  const int kI = 4;
1349 
1350  // Construction from a non-null pointer
1351  {
1353  EXPECT_TRUE(so.ok());
1354  EXPECT_OK(so.status());
1355  EXPECT_EQ(&kI, *so);
1356  }
1357 
1358  // Construction from a null pointer constant
1359  {
1360  absl::StatusOr<const int*> so(nullptr);
1361  EXPECT_TRUE(so.ok());
1362  EXPECT_OK(so.status());
1363  EXPECT_EQ(nullptr, *so);
1364  }
1365 
1366  // Construction from a non-literal null pointer
1367  {
1368  const int* const p = nullptr;
1369 
1371  EXPECT_TRUE(so.ok());
1372  EXPECT_OK(so.status());
1373  EXPECT_EQ(nullptr, *so);
1374  }
1375 }
1376 
1377 TEST(StatusOr, TestPointerCopyCtorStatusOk) {
1378  const int kI = 0;
1379  absl::StatusOr<const int*> original(&kI);
1380  absl::StatusOr<const int*> copy(original);
1381  EXPECT_OK(copy.status());
1382  EXPECT_EQ(*original, *copy);
1383 }
1384 
1385 TEST(StatusOr, TestPointerCopyCtorStatusNotOk) {
1387  absl::StatusOr<int*> copy(original);
1388  EXPECT_EQ(copy.status().code(), absl::StatusCode::kCancelled);
1389 }
1390 
1391 TEST(StatusOr, TestPointerCopyCtorStatusOKConverting) {
1392  Derived derived;
1393  absl::StatusOr<Derived*> original(&derived);
1394  absl::StatusOr<Base2*> copy(original);
1395  EXPECT_OK(copy.status());
1396  EXPECT_EQ(static_cast<const Base2*>(*original), *copy);
1397 }
1398 
1399 TEST(StatusOr, TestPointerCopyCtorStatusNotOkConverting) {
1401  absl::StatusOr<Base2*> copy(original);
1402  EXPECT_EQ(copy.status().code(), absl::StatusCode::kCancelled);
1403 }
1404 
1405 TEST(StatusOr, TestPointerAssignmentStatusOk) {
1406  const int kI = 0;
1407  absl::StatusOr<const int*> source(&kI);
1409  target = source;
1410  EXPECT_OK(target.status());
1411  EXPECT_EQ(*source, *target);
1412 }
1413 
1414 TEST(StatusOr, TestPointerAssignmentStatusNotOk) {
1417  target = source;
1418  EXPECT_EQ(target.status().code(), absl::StatusCode::kCancelled);
1419 }
1420 
1421 TEST(StatusOr, TestPointerAssignmentStatusOKConverting) {
1422  Derived derived;
1423  absl::StatusOr<Derived*> source(&derived);
1425  target = source;
1426  EXPECT_OK(target.status());
1427  EXPECT_EQ(static_cast<const Base2*>(*source), *target);
1428 }
1429 
1430 TEST(StatusOr, TestPointerAssignmentStatusNotOkConverting) {
1433  target = source;
1434  EXPECT_EQ(target.status(), source.status());
1435 }
1436 
1437 TEST(StatusOr, TestPointerStatus) {
1438  const int kI = 0;
1439  absl::StatusOr<const int*> good(&kI);
1440  EXPECT_TRUE(good.ok());
1442  EXPECT_EQ(bad.status().code(), absl::StatusCode::kCancelled);
1443 }
1444 
1445 TEST(StatusOr, TestPointerValue) {
1446  const int kI = 0;
1447  absl::StatusOr<const int*> thing(&kI);
1448  EXPECT_EQ(&kI, *thing);
1449 }
1450 
1451 TEST(StatusOr, TestPointerValueConst) {
1452  const int kI = 0;
1453  const absl::StatusOr<const int*> thing(&kI);
1454  EXPECT_EQ(&kI, *thing);
1455 }
1456 
1457 TEST(StatusOr, StatusOrVectorOfUniquePointerCanReserveAndResize) {
1458  using EvilType = std::vector<std::unique_ptr<int>>;
1460  std::vector<::absl::StatusOr<EvilType>> v(5);
1461  v.reserve(v.capacity() + 10);
1462  v.resize(v.capacity() + 10);
1463 }
1464 
1465 TEST(StatusOr, ConstPayload) {
1466  // A reduced version of a problematic type found in the wild. All of the
1467  // operations below should compile.
1469 
1470  // Copy-construction
1472 
1473  // Copy-assignment
1474  EXPECT_FALSE(std::is_copy_assignable<absl::StatusOr<const int>>::value);
1475 
1476  // Move-construction
1478 
1479  // Move-assignment
1480  EXPECT_FALSE(std::is_move_assignable<absl::StatusOr<const int>>::value);
1481 }
1482 
1483 TEST(StatusOr, MapToStatusOrUniquePtr) {
1484  // A reduced version of a problematic type found in the wild. All of the
1485  // operations below should compile.
1486  using MapType = std::map<std::string, absl::StatusOr<std::unique_ptr<int>>>;
1487 
1488  MapType a;
1489 
1490  // Move-construction
1491  MapType b(std::move(a));
1492 
1493  // Move-assignment
1494  a = std::move(b);
1495 }
1496 
1497 TEST(StatusOr, ValueOrOk) {
1498  const absl::StatusOr<int> status_or = 0;
1499  EXPECT_EQ(status_or.value_or(-1), 0);
1500 }
1501 
1502 TEST(StatusOr, ValueOrDefault) {
1503  const absl::StatusOr<int> status_or = absl::CancelledError();
1504  EXPECT_EQ(status_or.value_or(-1), -1);
1505 }
1506 
1507 TEST(StatusOr, MoveOnlyValueOrOk) {
1508  EXPECT_THAT(absl::StatusOr<std::unique_ptr<int>>(absl::make_unique<int>(0))
1509  .value_or(absl::make_unique<int>(-1)),
1510  Pointee(0));
1511 }
1512 
1513 TEST(StatusOr, MoveOnlyValueOrDefault) {
1514  EXPECT_THAT(absl::StatusOr<std::unique_ptr<int>>(absl::CancelledError())
1515  .value_or(absl::make_unique<int>(-1)),
1516  Pointee(-1));
1517 }
1518 
1519 static absl::StatusOr<int> MakeStatus() { return 100; }
1520 
1521 TEST(StatusOr, TestIgnoreError) { MakeStatus().IgnoreError(); }
1522 
1523 TEST(StatusOr, EqualityOperator) {
1524  constexpr int kNumCases = 4;
1525  std::array<absl::StatusOr<int>, kNumCases> group1 = {
1529  std::array<absl::StatusOr<int>, kNumCases> group2 = {
1533  for (int i = 0; i < kNumCases; ++i) {
1534  for (int j = 0; j < kNumCases; ++j) {
1535  if (i == j) {
1536  EXPECT_TRUE(group1[i] == group2[j]);
1537  EXPECT_FALSE(group1[i] != group2[j]);
1538  } else {
1539  EXPECT_FALSE(group1[i] == group2[j]);
1540  EXPECT_TRUE(group1[i] != group2[j]);
1541  }
1542  }
1543  }
1544 }
1545 
1546 struct MyType {
1547  bool operator==(const MyType&) const { return true; }
1548 };
1549 
1550 enum class ConvTraits { kNone = 0, kImplicit = 1, kExplicit = 2 };
1551 
1552 // This class has conversion operator to `StatusOr<T>` based on value of
1553 // `conv_traits`.
1554 template <typename T, ConvTraits conv_traits = ConvTraits::kNone>
1555 struct StatusOrConversionBase {};
1556 
1557 template <typename T>
1558 struct StatusOrConversionBase<T, ConvTraits::kImplicit> {
1559  operator absl::StatusOr<T>() const& { // NOLINT
1560  return absl::InvalidArgumentError("conversion to absl::StatusOr");
1561  }
1562  operator absl::StatusOr<T>() && { // NOLINT
1563  return absl::InvalidArgumentError("conversion to absl::StatusOr");
1564  }
1565 };
1566 
1567 template <typename T>
1568 struct StatusOrConversionBase<T, ConvTraits::kExplicit> {
1569  explicit operator absl::StatusOr<T>() const& {
1570  return absl::InvalidArgumentError("conversion to absl::StatusOr");
1571  }
1572  explicit operator absl::StatusOr<T>() && {
1573  return absl::InvalidArgumentError("conversion to absl::StatusOr");
1574  }
1575 };
1576 
1577 // This class has conversion operator to `T` based on the value of
1578 // `conv_traits`.
1579 template <typename T, ConvTraits conv_traits = ConvTraits::kNone>
1580 struct ConversionBase {};
1581 
1582 template <typename T>
1583 struct ConversionBase<T, ConvTraits::kImplicit> {
1584  operator T() const& { return t; } // NOLINT
1585  operator T() && { return std::move(t); } // NOLINT
1586  T t;
1587 };
1588 
1589 template <typename T>
1590 struct ConversionBase<T, ConvTraits::kExplicit> {
1591  explicit operator T() const& { return t; }
1592  explicit operator T() && { return std::move(t); }
1593  T t;
1594 };
1595 
1596 // This class has conversion operator to `absl::Status` based on the value of
1597 // `conv_traits`.
1598 template <ConvTraits conv_traits = ConvTraits::kNone>
1599 struct StatusConversionBase {};
1600 
1601 template <>
1602 struct StatusConversionBase<ConvTraits::kImplicit> {
1603  operator absl::Status() const& { // NOLINT
1604  return absl::InternalError("conversion to Status");
1605  }
1606  operator absl::Status() && { // NOLINT
1607  return absl::InternalError("conversion to Status");
1608  }
1609 };
1610 
1611 template <>
1612 struct StatusConversionBase<ConvTraits::kExplicit> {
1613  explicit operator absl::Status() const& { // NOLINT
1614  return absl::InternalError("conversion to Status");
1615  }
1616  explicit operator absl::Status() && { // NOLINT
1617  return absl::InternalError("conversion to Status");
1618  }
1619 };
1620 
1621 static constexpr int kConvToStatus = 1;
1622 static constexpr int kConvToStatusOr = 2;
1623 static constexpr int kConvToT = 4;
1624 static constexpr int kConvExplicit = 8;
1625 
1626 constexpr ConvTraits GetConvTraits(int bit, int config) {
1627  return (config & bit) == 0
1628  ? ConvTraits::kNone
1629  : ((config & kConvExplicit) == 0 ? ConvTraits::kImplicit
1630  : ConvTraits::kExplicit);
1631 }
1632 
1633 // This class conditionally has conversion operator to `absl::Status`, `T`,
1634 // `StatusOr<T>`, based on values of the template parameters.
1635 template <typename T, int config>
1636 struct CustomType
1637  : StatusOrConversionBase<T, GetConvTraits(kConvToStatusOr, config)>,
1638  ConversionBase<T, GetConvTraits(kConvToT, config)>,
1639  StatusConversionBase<GetConvTraits(kConvToStatus, config)> {};
1640 
1641 struct ConvertibleToAnyStatusOr {
1642  template <typename T>
1643  operator absl::StatusOr<T>() const { // NOLINT
1644  return absl::InvalidArgumentError("Conversion to absl::StatusOr");
1645  }
1646 };
1647 
1648 // Test the rank of overload resolution for `StatusOr<T>` constructor and
1649 // assignment, from highest to lowest:
1650 // 1. T/Status
1651 // 2. U that has conversion operator to absl::StatusOr<T>
1652 // 3. U that is convertible to Status
1653 // 4. U that is convertible to T
1654 TEST(StatusOr, ConstructionFromT) {
1655  // Construct absl::StatusOr<T> from T when T is convertible to
1656  // absl::StatusOr<T>
1657  {
1658  ConvertibleToAnyStatusOr v;
1660  EXPECT_TRUE(statusor.ok());
1661  }
1662  {
1663  ConvertibleToAnyStatusOr v;
1665  EXPECT_TRUE(statusor.ok());
1666  }
1667  // Construct absl::StatusOr<T> from T when T is explicitly convertible to
1668  // Status
1669  {
1670  CustomType<MyType, kConvToStatus | kConvExplicit> v;
1672  v);
1673  EXPECT_TRUE(statusor.ok());
1674  }
1675  {
1676  CustomType<MyType, kConvToStatus | kConvExplicit> v;
1678  v;
1679  EXPECT_TRUE(statusor.ok());
1680  }
1681 }
1682 
1683 // Construct absl::StatusOr<T> from U when U is explicitly convertible to T
1684 TEST(StatusOr, ConstructionFromTypeConvertibleToT) {
1685  {
1686  CustomType<MyType, kConvToT | kConvExplicit> v;
1687  absl::StatusOr<MyType> statusor(v);
1688  EXPECT_TRUE(statusor.ok());
1689  }
1690  {
1691  CustomType<MyType, kConvToT> v;
1692  absl::StatusOr<MyType> statusor = v;
1693  EXPECT_TRUE(statusor.ok());
1694  }
1695 }
1696 
1697 // Construct absl::StatusOr<T> from U when U has explicit conversion operator to
1698 // absl::StatusOr<T>
1699 TEST(StatusOr, ConstructionFromTypeWithConversionOperatorToStatusOrT) {
1700  {
1701  CustomType<MyType, kConvToStatusOr | kConvExplicit> v;
1702  absl::StatusOr<MyType> statusor(v);
1703  EXPECT_EQ(statusor, v.operator absl::StatusOr<MyType>());
1704  }
1705  {
1706  CustomType<MyType, kConvToT | kConvToStatusOr | kConvExplicit> v;
1707  absl::StatusOr<MyType> statusor(v);
1708  EXPECT_EQ(statusor, v.operator absl::StatusOr<MyType>());
1709  }
1710  {
1711  CustomType<MyType, kConvToStatusOr | kConvToStatus | kConvExplicit> v;
1712  absl::StatusOr<MyType> statusor(v);
1713  EXPECT_EQ(statusor, v.operator absl::StatusOr<MyType>());
1714  }
1715  {
1716  CustomType<MyType,
1717  kConvToT | kConvToStatusOr | kConvToStatus | kConvExplicit>
1718  v;
1719  absl::StatusOr<MyType> statusor(v);
1720  EXPECT_EQ(statusor, v.operator absl::StatusOr<MyType>());
1721  }
1722  {
1723  CustomType<MyType, kConvToStatusOr> v;
1724  absl::StatusOr<MyType> statusor = v;
1725  EXPECT_EQ(statusor, v.operator absl::StatusOr<MyType>());
1726  }
1727  {
1728  CustomType<MyType, kConvToT | kConvToStatusOr> v;
1729  absl::StatusOr<MyType> statusor = v;
1730  EXPECT_EQ(statusor, v.operator absl::StatusOr<MyType>());
1731  }
1732  {
1733  CustomType<MyType, kConvToStatusOr | kConvToStatus> v;
1734  absl::StatusOr<MyType> statusor = v;
1735  EXPECT_EQ(statusor, v.operator absl::StatusOr<MyType>());
1736  }
1737  {
1738  CustomType<MyType, kConvToT | kConvToStatusOr | kConvToStatus> v;
1739  absl::StatusOr<MyType> statusor = v;
1740  EXPECT_EQ(statusor, v.operator absl::StatusOr<MyType>());
1741  }
1742 }
1743 
1744 TEST(StatusOr, ConstructionFromTypeConvertibleToStatus) {
1745  // Construction fails because conversion to `Status` is explicit.
1746  {
1747  CustomType<MyType, kConvToStatus | kConvExplicit> v;
1748  absl::StatusOr<MyType> statusor(v);
1749  EXPECT_FALSE(statusor.ok());
1750  EXPECT_EQ(statusor.status(), static_cast<absl::Status>(v));
1751  }
1752  {
1753  CustomType<MyType, kConvToT | kConvToStatus | kConvExplicit> v;
1754  absl::StatusOr<MyType> statusor(v);
1755  EXPECT_FALSE(statusor.ok());
1756  EXPECT_EQ(statusor.status(), static_cast<absl::Status>(v));
1757  }
1758  {
1759  CustomType<MyType, kConvToStatus> v;
1760  absl::StatusOr<MyType> statusor = v;
1761  EXPECT_FALSE(statusor.ok());
1762  EXPECT_EQ(statusor.status(), static_cast<absl::Status>(v));
1763  }
1764  {
1765  CustomType<MyType, kConvToT | kConvToStatus> v;
1766  absl::StatusOr<MyType> statusor = v;
1767  EXPECT_FALSE(statusor.ok());
1768  EXPECT_EQ(statusor.status(), static_cast<absl::Status>(v));
1769  }
1770 }
1771 
1772 TEST(StatusOr, AssignmentFromT) {
1773  // Assign to absl::StatusOr<T> from T when T is convertible to
1774  // absl::StatusOr<T>
1775  {
1776  ConvertibleToAnyStatusOr v;
1778  statusor = v;
1779  EXPECT_TRUE(statusor.ok());
1780  }
1781  // Assign to absl::StatusOr<T> from T when T is convertible to Status
1782  {
1783  CustomType<MyType, kConvToStatus> v;
1785  statusor = v;
1786  EXPECT_TRUE(statusor.ok());
1787  }
1788 }
1789 
1790 TEST(StatusOr, AssignmentFromTypeConvertibleToT) {
1791  // Assign to absl::StatusOr<T> from U when U is convertible to T
1792  {
1793  CustomType<MyType, kConvToT> v;
1794  absl::StatusOr<MyType> statusor;
1795  statusor = v;
1796  EXPECT_TRUE(statusor.ok());
1797  }
1798 }
1799 
1800 TEST(StatusOr, AssignmentFromTypeWithConversionOperatortoStatusOrT) {
1801  // Assign to absl::StatusOr<T> from U when U has conversion operator to
1802  // absl::StatusOr<T>
1803  {
1804  CustomType<MyType, kConvToStatusOr> v;
1805  absl::StatusOr<MyType> statusor;
1806  statusor = v;
1807  EXPECT_EQ(statusor, v.operator absl::StatusOr<MyType>());
1808  }
1809  {
1810  CustomType<MyType, kConvToT | kConvToStatusOr> v;
1811  absl::StatusOr<MyType> statusor;
1812  statusor = v;
1813  EXPECT_EQ(statusor, v.operator absl::StatusOr<MyType>());
1814  }
1815  {
1816  CustomType<MyType, kConvToStatusOr | kConvToStatus> v;
1817  absl::StatusOr<MyType> statusor;
1818  statusor = v;
1819  EXPECT_EQ(statusor, v.operator absl::StatusOr<MyType>());
1820  }
1821  {
1822  CustomType<MyType, kConvToT | kConvToStatusOr | kConvToStatus> v;
1823  absl::StatusOr<MyType> statusor;
1824  statusor = v;
1825  EXPECT_EQ(statusor, v.operator absl::StatusOr<MyType>());
1826  }
1827 }
1828 
1829 TEST(StatusOr, AssignmentFromTypeConvertibleToStatus) {
1830  // Assign to absl::StatusOr<T> from U when U is convertible to Status
1831  {
1832  CustomType<MyType, kConvToStatus> v;
1833  absl::StatusOr<MyType> statusor;
1834  statusor = v;
1835  EXPECT_FALSE(statusor.ok());
1836  EXPECT_EQ(statusor.status(), static_cast<absl::Status>(v));
1837  }
1838  {
1839  CustomType<MyType, kConvToT | kConvToStatus> v;
1840  absl::StatusOr<MyType> statusor;
1841  statusor = v;
1842  EXPECT_FALSE(statusor.ok());
1843  EXPECT_EQ(statusor.status(), static_cast<absl::Status>(v));
1844  }
1845 }
1846 
1847 } // namespace
EXPECT_FALSE
#define EXPECT_FALSE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1970
absl::InvalidArgumentError
Status InvalidArgumentError(absl::string_view message)
Definition: third_party/abseil-cpp/absl/status/status.cc:351
ptr
char * ptr
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:45
testing
Definition: aws_request_signer_test.cc:25
absl::StatusOr::value_or
T value_or(U &&default_value) const &
check_banned_filenames.bad
bad
Definition: check_banned_filenames.py:26
testing::MatchResultListener
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:4899
absl::str_format_internal::LengthMod::j
@ j
testing::Pointee
internal::PointeeMatcher< InnerMatcher > Pointee(const InnerMatcher &inner_matcher)
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:8691
grpc_event_engine::experimental::slice_detail::operator==
bool operator==(const BaseSlice &a, const BaseSlice &b)
Definition: include/grpc/event_engine/slice.h:117
testing::Not
internal::NotMatcher< InnerMatcher > Not(InnerMatcher m)
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:8926
const
#define const
Definition: bloaty/third_party/zlib/zconf.h:230
bool
bool
Definition: setup_once.h:312
EXPECT_THAT
#define EXPECT_THAT(value, matcher)
false
#define false
Definition: setup_once.h:323
C
#define C(x)
Definition: abseil-cpp/absl/hash/internal/city_test.cc:49
EXPECT_DEATH_OR_THROW
#define EXPECT_DEATH_OR_THROW(statement, status)
Definition: abseil-cpp/absl/status/statusor_test.cc:362
absl::StatusOr
ABSL_NAMESPACE_BEGIN class ABSL_MUST_USE_RESULT StatusOr
Definition: abseil-cpp/absl/status/internal/statusor_internal.h:29
generate_changelog.previous
previous
Definition: bloaty/third_party/protobuf/generate_changelog.py:55
EXPECT_OK
#define EXPECT_OK(expression)
Definition: abseil-cpp/absl/status/statusor_test.cc:152
y
const double y
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3611
absl::CancelledError
Status CancelledError(absl::string_view message)
Definition: third_party/abseil-cpp/absl/status/status.cc:331
testing::Ne
internal::NeMatcher< Rhs > Ne(Rhs x)
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:8609
copy
static int copy(grpc_slice_buffer *input, grpc_slice_buffer *output)
Definition: message_compress.cc:145
absl::str_format_internal::AllOf
constexpr bool AllOf()
Definition: abseil-cpp/absl/strings/internal/str_format/checker.h:39
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
error
grpc_error_handle error
Definition: retry_filter.cc:499
absl::OkStatus
Status OkStatus()
Definition: third_party/abseil-cpp/absl/status/status.h:882
foo
Definition: bloaty/third_party/googletest/googletest/test/googletest-output-test_.cc:546
status
absl::Status status
Definition: rls.cc:251
absl::FormatConversionChar::s
@ s
a
int a
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:88
absl::InternalError
Status InternalError(absl::string_view message)
Definition: third_party/abseil-cpp/absl/status/status.cc:347
xds_manager.p
p
Definition: xds_manager.py:60
absl::flags_internal::HelpMode::kNone
@ kNone
testing::MatcherDescriberInterface::DescribeTo
virtual void DescribeTo(::std::ostream *os) const =0
message
char * message
Definition: libuv/docs/code/tty-gravity/main.c:12
T
#define T(upbtypeconst, upbtype, ctype, default_value)
true
#define true
Definition: setup_once.h:324
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: iomgr/time_averaged_stats_test.cc:27
testing::ElementsAre
internal::ElementsAreMatcher< ::testing::tuple<> > ElementsAre()
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:13040
absl::StatusCode::kInternal
@ kInternal
c
void c(T a)
Definition: miscompile_with_no_unique_address_test.cc:40
google::protobuf.internal::IsOk
bool IsOk(T status)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/logging.h:113
xds_interop_client.int
int
Definition: xds_interop_client.py:113
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
absl::StatusOr::emplace
T & emplace(Args &&... args)
Definition: abseil-cpp/absl/status/statusor.h:587
Foo
Definition: abseil-cpp/absl/debugging/symbolize_test.cc:65
TEST
#define TEST(name, init_size,...)
Definition: arena_test.cc:75
ASSERT_THAT
#define ASSERT_THAT(value, matcher)
EXPECT_NE
#define EXPECT_NE(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2028
absl::BadStatusOrAccess
Definition: abseil-cpp/absl/status/statusor.h:73
setup.v
v
Definition: third_party/bloaty/third_party/capstone/bindings/python/setup.py:42
absl::UnknownError
Status UnknownError(absl::string_view message)
Definition: third_party/abseil-cpp/absl/status/status.cc:383
pad
int pad
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/statusor_test.cc:47
absl::Status::message
absl::string_view message() const
Definition: third_party/abseil-cpp/absl/status/status.h:806
absl::LogSeverity::kError
@ kError
testing::MatcherInterface::MatchAndExplain
virtual bool MatchAndExplain(T x, MatchResultListener *listener) const =0
absl::inlined_vector_internal::Pointer
typename AllocatorTraits< A >::pointer Pointer
Definition: abseil-cpp/absl/container/internal/inlined_vector.h:52
absl::compare_internal::value_type
int8_t value_type
Definition: abseil-cpp/absl/types/compare.h:45
x
int x
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3610
b
uint64_t b
Definition: abseil-cpp/absl/container/internal/layout_test.cc:53
d
static const fe d
Definition: curve25519_tables.h:19
testing::Matcher
Definition: bloaty/third_party/googletest/googlemock/include/gmock/internal/gmock-internal-utils.h:52
absl::implicit_cast
constexpr ABSL_NAMESPACE_BEGIN To implicit_cast(typename absl::internal::identity_t< To > to)
Definition: abseil-cpp/absl/base/casts.h:93
absl::StatusCode::kInvalidArgument
@ kInvalidArgument
yetotherpad
int yetotherpad
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/statusor_test.cc:53
absl::WrapUnique
ABSL_NAMESPACE_BEGIN std::unique_ptr< T > WrapUnique(T *ptr)
Definition: third_party/abseil-cpp/absl/memory/memory.h:72
value
const char * value
Definition: hpack_parser_table.cc:165
Field
struct Field Field
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:647
absl::Status
ABSL_NAMESPACE_BEGIN class ABSL_MUST_USE_RESULT Status
Definition: abseil-cpp/absl/status/internal/status_internal.h:36
absl::StatusOr::value_type
T value_type
Definition: abseil-cpp/absl/status/statusor.h:203
testing::StringMatchResultListener::str
internal::string str() const
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:5008
absl::StatusOr::ok
ABSL_MUST_USE_RESULT bool ok() const
Definition: abseil-cpp/absl/status/statusor.h:491
foo
int foo
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/statusor_test.cc:66
testing::StringMatchResultListener
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:5003
absl::StatusCode::kCancelled
@ kCancelled
absl::Status
Definition: third_party/abseil-cpp/absl/status/status.h:424
absl::StatusCode::kUnknown
@ kUnknown
absl::str_format_internal::LengthMod::t
@ t
testing::MatcherDescriberInterface::DescribeNegationTo
virtual void DescribeNegationTo(::std::ostream *os) const
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:4953
std
Definition: grpcpp/impl/codegen/async_unary_call.h:407
A
Definition: miscompile_with_no_unique_address_test.cc:23
grpc::protobuf::util::Status
GRPC_CUSTOM_UTIL_STATUS Status
Definition: include/grpcpp/impl/codegen/config_protobuf.h:93
ASSERT_TRUE
#define ASSERT_TRUE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1973
absl::NotFoundError
Status NotFoundError(absl::string_view message)
Definition: third_party/abseil-cpp/absl/status/status.cc:355
config_s
Definition: bloaty/third_party/zlib/deflate.c:120
EXPECT_TRUE
#define EXPECT_TRUE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1967
EXPECT_DOUBLE_EQ
#define EXPECT_DOUBLE_EQ(a, b)
Definition: iomgr/time_averaged_stats_test.cc:28
evenmorepad
int evenmorepad
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/statusor_test.cc:59
absl::StatusOr::value
const T & value() const &ABSL_ATTRIBUTE_LIFETIME_BOUND
Definition: abseil-cpp/absl/status/statusor.h:687
absl::forward
constexpr T && forward(absl::remove_reference_t< T > &t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:230
absl::StatusOr
Definition: abseil-cpp/absl/status/statusor.h:187
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
testing::MatcherInterface
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:4962
testing::SafeMatcherCast
Matcher< T > SafeMatcherCast(const M &polymorphic_matcher)
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:5484
testing::HasSubstr
PolymorphicMatcher< internal::HasSubstrMatcher< internal::string > > HasSubstr(const internal::string &substring)
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:8803
setup.target
target
Definition: third_party/bloaty/third_party/protobuf/python/setup.py:179
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
absl::StatusOr::status
const Status & status() const &
Definition: abseil-cpp/absl/status/statusor.h:678
absl::StatusCode::kNotFound
@ kNotFound
testing::PrintToString
::std::string PrintToString(const T &value)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest-printers.h:915


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:19