auth_context_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 
19 #include <string.h>
20 
21 #include <grpc/support/log.h>
22 
27 
28 static void test_empty_context(void) {
30  grpc_core::MakeRefCounted<grpc_auth_context>(nullptr);
32 
33  gpr_log(GPR_INFO, "test_empty_context");
34  GPR_ASSERT(ctx != nullptr);
36  nullptr);
43  GPR_ASSERT(
46  nullptr);
47  ctx.reset(DEBUG_LOCATION, "test");
48 }
49 
50 static void test_simple_context(void) {
52  grpc_core::MakeRefCounted<grpc_auth_context>(nullptr);
54  size_t i;
55 
56  gpr_log(GPR_INFO, "test_simple_context");
57  GPR_ASSERT(ctx != nullptr);
58  grpc_auth_context_add_cstring_property(ctx.get(), "name", "chapi");
59  grpc_auth_context_add_cstring_property(ctx.get(), "name", "chapo");
60  grpc_auth_context_add_cstring_property(ctx.get(), "foo", "bar");
61  GPR_ASSERT(ctx->properties().count == 3);
63  "name") == 1);
64 
66  "name") == 0);
68  for (i = 0; i < ctx->properties().count; i++) {
70  GPR_ASSERT(p == &ctx->properties().array[i]);
71  }
73 
76  &ctx->properties().array[2]);
78 
81  &ctx->properties().array[0]);
83  &ctx->properties().array[1]);
85 
86  ctx.reset(DEBUG_LOCATION, "test");
87 }
88 
89 static void test_chained_context(void) {
91  grpc_core::MakeRefCounted<grpc_auth_context>(nullptr);
92  grpc_auth_context* chained_ptr = chained.get();
94  grpc_core::MakeRefCounted<grpc_auth_context>(std::move(chained));
95 
97  size_t i;
98 
99  gpr_log(GPR_INFO, "test_chained_context");
100  grpc_auth_context_add_cstring_property(chained_ptr, "name", "padapo");
101  grpc_auth_context_add_cstring_property(chained_ptr, "foo", "baz");
102  grpc_auth_context_add_cstring_property(ctx.get(), "name", "chapi");
103  grpc_auth_context_add_cstring_property(ctx.get(), "name", "chap0");
104  grpc_auth_context_add_cstring_property(ctx.get(), "foo", "bar");
106  "name") == 1);
107 
109  "name") == 0);
111  for (i = 0; i < ctx->properties().count; i++) {
113  GPR_ASSERT(p == &ctx->properties().array[i]);
114  }
115  for (i = 0; i < chained_ptr->properties().count; i++) {
117  GPR_ASSERT(p == &chained_ptr->properties().array[i]);
118  }
120 
123  &ctx->properties().array[2]);
125  &chained_ptr->properties().array[1]);
127 
130  &ctx->properties().array[0]);
132  &ctx->properties().array[1]);
134  &chained_ptr->properties().array[0]);
136 
137  ctx.reset(DEBUG_LOCATION, "test");
138 }
139 
140 int main(int argc, char** argv) {
141  grpc::testing::TestEnvironment env(&argc, argv);
145  return 0;
146 }
GPR_INFO
#define GPR_INFO
Definition: include/grpc/impl/codegen/log.h:56
grpc_auth_context
Definition: security_context.h:63
regen-readme.it
it
Definition: regen-readme.py:15
log.h
test_chained_context
static void test_chained_context(void)
Definition: auth_context_test.cc:89
ctx
Definition: benchmark-async.c:30
generate.env
env
Definition: generate.py:37
grpc_core::RefCountedPtr::get
T * get() const
Definition: ref_counted_ptr.h:146
string.h
xds_manager.p
p
Definition: xds_manager.py:60
grpc_auth_property_iterator_next
const GRPCAPI grpc_auth_property * grpc_auth_property_iterator_next(grpc_auth_property_iterator *it)
Definition: security_context.cc:182
test_simple_context
static void test_simple_context(void)
Definition: auth_context_test.cc:50
grpc_auth_context_set_peer_identity_property_name
GRPCAPI int grpc_auth_context_set_peer_identity_property_name(grpc_auth_context *ctx, const char *name)
Definition: security_context.cc:151
DEBUG_LOCATION
#define DEBUG_LOCATION
Definition: debug_location.h:41
test_empty_context
static void test_empty_context(void)
Definition: auth_context_test.cc:28
grpc_core::RefCountedPtr< grpc_auth_context >
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
grpc_auth_context::properties
const grpc_auth_property_array & properties() const
Definition: security_context.h:97
gpr_log
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
grpc_auth_property_iterator
Definition: grpc_security.h:36
grpc_auth_property_array::array
grpc_auth_property * array
Definition: security_context.h:51
main
int main(int argc, char **argv)
Definition: auth_context_test.cc:140
grpc_auth_context_add_cstring_property
GRPCAPI void grpc_auth_context_add_cstring_property(grpc_auth_context *ctx, const char *name, const char *value)
Definition: security_context.cc:268
grpc_auth_property
Definition: grpc_security.h:43
grpc_auth_context_property_iterator
GRPCAPI grpc_auth_property_iterator grpc_auth_context_property_iterator(const grpc_auth_context *ctx)
Definition: security_context.cc:173
test_config.h
security_context.h
count
int * count
Definition: bloaty/third_party/googletest/googlemock/test/gmock_stress_test.cc:96
grpc_auth_context_peer_identity
GRPCAPI grpc_auth_property_iterator grpc_auth_context_peer_identity(const grpc_auth_context *ctx)
Definition: security_context.cc:218
grpc::testing::TestEnvironment
Definition: test/core/util/test_config.h:54
ref_counted_ptr.h
grpc_auth_context_peer_identity_property_name
const GRPCAPI char * grpc_auth_context_peer_identity_property_name(const grpc_auth_context *ctx)
Definition: security_context.cc:144
grpc_auth_context_find_properties_by_name
GRPCAPI grpc_auth_property_iterator grpc_auth_context_find_properties_by_name(const grpc_auth_context *ctx, const char *name)
Definition: security_context.cc:207
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:35