status_conversion_test.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
20 
21 #include <grpc/grpc.h>
22 #include <grpc/support/log.h>
23 
26 
27 #define GRPC_STATUS_TO_HTTP2_ERROR(a, b) \
28  GPR_ASSERT(grpc_status_to_http2_error(a) == (b))
29 #define HTTP2_ERROR_TO_GRPC_STATUS(a, deadline, b) \
30  do { \
31  grpc_core::ExecCtx exec_ctx; \
32  GPR_ASSERT(grpc_http2_error_to_grpc_status(a, deadline) == (b)); \
33  \
34  } while (0)
35 #define GRPC_STATUS_TO_HTTP2_STATUS(a, b) \
36  GPR_ASSERT(grpc_status_to_http2_status(a) == (b))
37 #define HTTP2_STATUS_TO_GRPC_STATUS(a, b) \
38  GPR_ASSERT(grpc_http2_status_to_grpc_status(a) == (b))
39 
67 }
68 
87 }
88 
90  const grpc_core::Timestamp before_deadline =
118 
119  const grpc_core::Timestamp after_deadline;
136  // We only have millisecond granularity in our timing code. This sleeps for 5
137  // millis to ensure that the status conversion code will pick up the fact
138  // that the deadline has expired.
151 }
152 
167 }
168 
169 int main(int argc, char** argv) {
170  grpc::testing::TestEnvironment env(&argc, argv);
171  grpc_init();
172 
177 
178  /* check all status values can be converted */
179  for (int i = 0; i <= 999; i++) {
181  }
182 
183  grpc_shutdown();
184 
185  return 0;
186 }
GPR_TIMESPAN
@ GPR_TIMESPAN
Definition: gpr_types.h:45
log.h
GRPC_HTTP2_CANCEL
@ GRPC_HTTP2_CANCEL
Definition: http2_errors.h:32
GRPC_STATUS_UNAVAILABLE
@ GRPC_STATUS_UNAVAILABLE
Definition: include/grpc/impl/codegen/status.h:143
generate.env
env
Definition: generate.py:37
GRPC_STATUS_UNAUTHENTICATED
@ GRPC_STATUS_UNAUTHENTICATED
Definition: include/grpc/impl/codegen/status.h:72
GRPC_HTTP2_INADEQUATE_SECURITY
@ GRPC_HTTP2_INADEQUATE_SECURITY
Definition: http2_errors.h:36
GRPC_HTTP2_ENHANCE_YOUR_CALM
@ GRPC_HTTP2_ENHANCE_YOUR_CALM
Definition: http2_errors.h:35
GRPC_STATUS_TO_HTTP2_STATUS
#define GRPC_STATUS_TO_HTTP2_STATUS(a, b)
Definition: status_conversion_test.cc:35
grpc_core::Timestamp
Definition: src/core/lib/gprpp/time.h:62
GRPC_STATUS_PERMISSION_DENIED
@ GRPC_STATUS_PERMISSION_DENIED
Definition: include/grpc/impl/codegen/status.h:68
GRPC_STATUS_NOT_FOUND
@ GRPC_STATUS_NOT_FOUND
Definition: include/grpc/impl/codegen/status.h:56
GRPC_STATUS_CANCELLED
@ GRPC_STATUS_CANCELLED
Definition: include/grpc/impl/codegen/status.h:33
GRPC_STATUS_DEADLINE_EXCEEDED
@ GRPC_STATUS_DEADLINE_EXCEEDED
Definition: include/grpc/impl/codegen/status.h:53
GRPC_STATUS_INVALID_ARGUMENT
@ GRPC_STATUS_INVALID_ARGUMENT
Definition: include/grpc/impl/codegen/status.h:46
GRPC_STATUS_RESOURCE_EXHAUSTED
@ GRPC_STATUS_RESOURCE_EXHAUSTED
Definition: include/grpc/impl/codegen/status.h:76
GRPC_STATUS_OK
@ GRPC_STATUS_OK
Definition: include/grpc/impl/codegen/status.h:30
test_grpc_status_to_http2_status
static void test_grpc_status_to_http2_status()
Definition: status_conversion_test.cc:69
GRPC_HTTP2_FLOW_CONTROL_ERROR
@ GRPC_HTTP2_FLOW_CONTROL_ERROR
Definition: http2_errors.h:27
gpr_sleep_until
GPRAPI void gpr_sleep_until(gpr_timespec until)
grpc.h
test_http2_error_to_grpc_status
static void test_http2_error_to_grpc_status()
Definition: status_conversion_test.cc:89
GRPC_STATUS_TO_HTTP2_ERROR
#define GRPC_STATUS_TO_HTTP2_ERROR(a, b)
Definition: status_conversion_test.cc:27
GRPC_STATUS_ALREADY_EXISTS
@ GRPC_STATUS_ALREADY_EXISTS
Definition: include/grpc/impl/codegen/status.h:60
GRPC_HTTP2_COMPRESSION_ERROR
@ GRPC_HTTP2_COMPRESSION_ERROR
Definition: http2_errors.h:33
GRPC_STATUS_DATA_LOSS
@ GRPC_STATUS_DATA_LOSS
Definition: include/grpc/impl/codegen/status.h:146
gpr_now
GPRAPI gpr_timespec gpr_now(gpr_clock_type clock)
GRPC_HTTP2_INTERNAL_ERROR
@ GRPC_HTTP2_INTERNAL_ERROR
Definition: http2_errors.h:26
GRPC_HTTP2_CONNECT_ERROR
@ GRPC_HTTP2_CONNECT_ERROR
Definition: http2_errors.h:34
GRPC_STATUS_OUT_OF_RANGE
@ GRPC_STATUS_OUT_OF_RANGE
Definition: include/grpc/impl/codegen/status.h:121
grpc_http2_status_to_grpc_status
grpc_status_code grpc_http2_status_to_grpc_status(int status)
Definition: status_conversion.cc:67
test_config.h
GRPC_HTTP2_REFUSED_STREAM
@ GRPC_HTTP2_REFUSED_STREAM
Definition: http2_errors.h:31
HTTP2_ERROR_TO_GRPC_STATUS
#define HTTP2_ERROR_TO_GRPC_STATUS(a, deadline, b)
Definition: status_conversion_test.cc:29
gpr_time_add
GPRAPI gpr_timespec gpr_time_add(gpr_timespec a, gpr_timespec b)
Definition: src/core/lib/gpr/time.cc:135
HTTP2_STATUS_TO_GRPC_STATUS
#define HTTP2_STATUS_TO_GRPC_STATUS(a, b)
Definition: status_conversion_test.cc:37
GRPC_STATUS_ABORTED
@ GRPC_STATUS_ABORTED
Definition: include/grpc/impl/codegen/status.h:104
test_http2_status_to_grpc_status
static void test_http2_status_to_grpc_status()
Definition: status_conversion_test.cc:153
GRPC_HTTP2_STREAM_CLOSED
@ GRPC_HTTP2_STREAM_CLOSED
Definition: http2_errors.h:29
grpc::testing::TestEnvironment
Definition: test/core/util/test_config.h:54
exec_ctx.h
gpr_time_from_millis
GPRAPI gpr_timespec gpr_time_from_millis(int64_t ms, gpr_clock_type clock_type)
Definition: src/core/lib/gpr/time.cc:119
GRPC_STATUS_UNIMPLEMENTED
@ GRPC_STATUS_UNIMPLEMENTED
Definition: include/grpc/impl/codegen/status.h:124
GRPC_STATUS_FAILED_PRECONDITION
@ GRPC_STATUS_FAILED_PRECONDITION
Definition: include/grpc/impl/codegen/status.h:97
main
int main(int argc, char **argv)
Definition: status_conversion_test.cc:169
GRPC_STATUS_INTERNAL
@ GRPC_STATUS_INTERNAL
Definition: include/grpc/impl/codegen/status.h:129
grpc_core::Timestamp::InfFuture
static constexpr Timestamp InfFuture()
Definition: src/core/lib/gprpp/time.h:79
status_conversion.h
grpc_init
GRPCAPI void grpc_init(void)
Definition: init.cc:146
GPR_CLOCK_REALTIME
@ GPR_CLOCK_REALTIME
Definition: gpr_types.h:39
GRPC_HTTP2_PROTOCOL_ERROR
@ GRPC_HTTP2_PROTOCOL_ERROR
Definition: http2_errors.h:25
GRPC_HTTP2_SETTINGS_TIMEOUT
@ GRPC_HTTP2_SETTINGS_TIMEOUT
Definition: http2_errors.h:28
test_grpc_status_to_http2_error
static void test_grpc_status_to_http2_error()
Definition: status_conversion_test.cc:40
grpc_shutdown
GRPCAPI void grpc_shutdown(void)
Definition: init.cc:209
GRPC_HTTP2_NO_ERROR
@ GRPC_HTTP2_NO_ERROR
Definition: http2_errors.h:24
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
GRPC_STATUS_UNKNOWN
@ GRPC_STATUS_UNKNOWN
Definition: include/grpc/impl/codegen/status.h:40
GRPC_HTTP2_FRAME_SIZE_ERROR
@ GRPC_HTTP2_FRAME_SIZE_ERROR
Definition: http2_errors.h:30


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