status_test_support.h 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef CRDTP_STATUS_TEST_SUPPORT_H_
  5. #define CRDTP_STATUS_TEST_SUPPORT_H_
  6. #include <ostream>
  7. #include "status.h"
  8. #include "test_platform.h"
  9. namespace crdtp {
  10. // Supports gtest, to conveniently match Status objects and
  11. // get useful error messages when tests fail.
  12. // Typically used with EXPECT_THAT, e.g.
  13. //
  14. // EXPECT_THAT(status, StatusIs(Error::JSON_PARSER_COLON_EXPECTED, 42));
  15. //
  16. // EXPECT_THAT(status, StatusIsOk());
  17. // Prints a |status|, including its generated error message, error code, and
  18. // position. This is used by gtest for pretty printing actual vs. expected.
  19. void PrintTo(const Status& status, std::ostream* os);
  20. // Matches any status with |status.ok()|.
  21. testing::Matcher<Status> StatusIsOk();
  22. // Matches any status with |error| and |pos|.
  23. testing::Matcher<Status> StatusIs(Error error, size_t pos);
  24. } // namespace crdtp
  25. #endif // CRDTP_STATUS_TEST_SUPPORT_H_