Go to the documentation of this file.
19 #include <gmock/gmock.h>
20 #include <gtest/gtest.h>
22 #include "absl/status/status.h"
23 #include "absl/strings/str_cat.h"
24 #include "absl/time/clock.h"
31 TEST(StatusUtilTest, CreateStatus) {
46 TEST(StatusUtilTest, SetAndGetInt) {
52 TEST(StatusUtilTest, GetIntNotExistent) {
58 TEST(StatusUtilTest, SetAndGetStr) {
64 TEST(StatusUtilTest, GetStrNotExistent) {
70 TEST(StatusUtilTest, SetAndGetTime) {
77 TEST(StatusUtilTest, GetTimeNotExistent) {
83 TEST(StatusUtilTest, AddAndGetChildren) {
95 TEST(StatusUtilTest, ToAndFromProto) {
108 TEST(StatusUtilTest, ToAndFromProtoWithNonUTF8Characters) {
121 TEST(StatusUtilTest, OkToString) {
127 TEST(StatusUtilTest, CancelledErrorToString) {
133 TEST(StatusUtilTest, ErrorWithIntPropertyToString) {
137 EXPECT_EQ(
"CANCELLED:Message {errno:2021}", t);
140 TEST(StatusUtilTest, ErrorWithStrPropertyToString) {
144 EXPECT_EQ(
"CANCELLED:Message {description:\"Hey\"}", t);
147 TEST(StatusUtilTest, ErrorWithTimePropertyToString) {
157 TEST(StatusUtilTest, ComplexErrorWithChildrenToString) {
167 "CANCELLED:Message {errno:2021, children:["
168 "ABORTED:Message1, ALREADY_EXISTS:Message2 {os_error:\"value\"}]}",
172 TEST(StatusUtilTest, AllocHeapPtr) {
175 for (
const auto& s : statuses) {
182 TEST(StatusUtilTest, MoveHeapPtr) {
185 for (
const auto& s : statuses) {
194 int main(
int argc,
char** argv) {
struct google_rpc_Status google_rpc_Status
absl::Status StatusFromProto(google_rpc_Status *msg)
@ kFileLine
LINE from the call site creating the error
Status AbortedError(absl::string_view message)
std::string StrCat(const AlphaNum &a, const AlphaNum &b)
std::vector< absl::Status > StatusGetChildren(absl::Status status)
Returns all children status from a status.
#define EXPECT_THAT(value, matcher)
@ kFile
source file in which this error occurred
void StatusAddChild(absl::Status *status, absl::Status child)
Adds a child status to status.
@ kOsError
operating system description of this error
Status CancelledError(absl::string_view message)
uintptr_t StatusAllocHeapPtr(absl::Status s)
@ kCreated
timestamp of error creation
void StatusSetTime(absl::Status *status, StatusTimeProperty key, absl::Time time)
Sets the time property to the status.
absl::Status StatusCreate(absl::StatusCode code, absl::string_view msg, const DebugLocation &location, std::vector< absl::Status > children)
Creates a status with given additional information.
absl::optional< std::string > StatusGetStr(const absl::Status &status, StatusStrProperty key)
Gets the str property from the status.
grpc_core::ScopedArenaPtr arena
std::string FormatTime(absl::string_view format, absl::Time t, absl::TimeZone tz)
internal::ElementsAreMatcher< ::testing::tuple<> > ElementsAre()
UPB_INLINE google_rpc_Status * google_rpc_Status_parse(const char *buf, size_t size, upb_Arena *arena)
void StatusSetInt(absl::Status *status, StatusIntProperty key, intptr_t value)
Sets the int property to the status.
int main(int argc, char **argv)
std::string StatusToString(const absl::Status &status)
absl::Status StatusGetFromHeapPtr(uintptr_t ptr)
Get the status from a heap ptr.
void StatusSetStr(absl::Status *status, StatusStrProperty key, absl::string_view value)
Sets the str property to the status.
@ kDescription
top-level textual description of this error
_W64 unsigned int uintptr_t
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
void StatusFreeHeapPtr(uintptr_t ptr)
Frees the allocated status at heap ptr.
google_rpc_Status * StatusToProto(const absl::Status &status, upb_Arena *arena)
ABSL_NAMESPACE_BEGIN Time Now()
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
absl::optional< absl::Time > StatusGetTime(const absl::Status &status, StatusTimeProperty key)
Gets the time property from the status.
UniquePtr< SSL_SESSION > ret
Status DeadlineExceededError(absl::string_view message)
Time FromCivil(CivilSecond ct, TimeZone tz)
absl::Status StatusMoveFromHeapPtr(uintptr_t ptr)
Move the status from a heap ptr. (GetFrom & FreeHeap)
UPB_INLINE char * google_rpc_Status_serialize(const google_rpc_Status *msg, upb_Arena *arena, size_t *len)
Status UnimplementedError(absl::string_view message)
absl::optional< intptr_t > StatusGetInt(const absl::Status &status, StatusIntProperty key)
Gets the int property from the status.
Status AlreadyExistsError(absl::string_view message)
@ kErrorNo
'errno' from the operating system
grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:17