|
|
|
@ -67,27 +67,28 @@ static void test_create_metadata(bool intern_keys, bool intern_values) { |
|
|
|
|
intern_keys, intern_values); |
|
|
|
|
|
|
|
|
|
grpc_init(); |
|
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
|
m1 = grpc_mdelem_from_slices( |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("a"), intern_keys), |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("b"), intern_values)); |
|
|
|
|
m2 = grpc_mdelem_from_slices( |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("a"), intern_keys), |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("b"), intern_values)); |
|
|
|
|
m3 = grpc_mdelem_from_slices( |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("a"), intern_keys), |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("c"), intern_values)); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_eq(m1, m2)); |
|
|
|
|
GPR_ASSERT(!grpc_mdelem_eq(m3, m1)); |
|
|
|
|
GPR_ASSERT(grpc_slice_eq(GRPC_MDKEY(m3), GRPC_MDKEY(m1))); |
|
|
|
|
GPR_ASSERT(!grpc_slice_eq(GRPC_MDVALUE(m3), GRPC_MDVALUE(m1))); |
|
|
|
|
GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDKEY(m1), "a") == 0); |
|
|
|
|
GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(m1), "b") == 0); |
|
|
|
|
GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(m3), "c") == 0); |
|
|
|
|
GRPC_MDELEM_UNREF(m1); |
|
|
|
|
GRPC_MDELEM_UNREF(m2); |
|
|
|
|
GRPC_MDELEM_UNREF(m3); |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
|
m1 = grpc_mdelem_from_slices( |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("a"), intern_keys), |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("b"), intern_values)); |
|
|
|
|
m2 = grpc_mdelem_from_slices( |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("a"), intern_keys), |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("b"), intern_values)); |
|
|
|
|
m3 = grpc_mdelem_from_slices( |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("a"), intern_keys), |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("c"), intern_values)); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_eq(m1, m2)); |
|
|
|
|
GPR_ASSERT(!grpc_mdelem_eq(m3, m1)); |
|
|
|
|
GPR_ASSERT(grpc_slice_eq(GRPC_MDKEY(m3), GRPC_MDKEY(m1))); |
|
|
|
|
GPR_ASSERT(!grpc_slice_eq(GRPC_MDVALUE(m3), GRPC_MDVALUE(m1))); |
|
|
|
|
GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDKEY(m1), "a") == 0); |
|
|
|
|
GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(m1), "b") == 0); |
|
|
|
|
GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(m3), "c") == 0); |
|
|
|
|
GRPC_MDELEM_UNREF(m1); |
|
|
|
|
GRPC_MDELEM_UNREF(m2); |
|
|
|
|
GRPC_MDELEM_UNREF(m3); |
|
|
|
|
} |
|
|
|
|
grpc_shutdown(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -102,15 +103,16 @@ static void test_create_many_ephemeral_metadata(bool intern_keys, |
|
|
|
|
intern_keys, intern_values); |
|
|
|
|
|
|
|
|
|
grpc_init(); |
|
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
|
/* add, and immediately delete a bunch of different elements */ |
|
|
|
|
for (i = 0; i < MANY; i++) { |
|
|
|
|
gpr_ltoa(i, buffer); |
|
|
|
|
GRPC_MDELEM_UNREF(grpc_mdelem_from_slices( |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("a"), intern_keys), |
|
|
|
|
maybe_intern(grpc_slice_from_copied_string(buffer), intern_values))); |
|
|
|
|
{ |
|
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
|
/* add, and immediately delete a bunch of different elements */ |
|
|
|
|
for (i = 0; i < MANY; i++) { |
|
|
|
|
gpr_ltoa(i, buffer); |
|
|
|
|
GRPC_MDELEM_UNREF(grpc_mdelem_from_slices( |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("a"), intern_keys), |
|
|
|
|
maybe_intern(grpc_slice_from_copied_string(buffer), intern_values))); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc_shutdown(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -124,28 +126,29 @@ static void test_create_many_persistant_metadata(void) { |
|
|
|
|
gpr_log(GPR_INFO, "test_create_many_persistant_metadata"); |
|
|
|
|
|
|
|
|
|
grpc_init(); |
|
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
|
/* add phase */ |
|
|
|
|
for (i = 0; i < MANY; i++) { |
|
|
|
|
gpr_ltoa(i, buffer); |
|
|
|
|
created[i] = grpc_mdelem_from_slices( |
|
|
|
|
grpc_slice_intern(grpc_slice_from_static_string("a")), |
|
|
|
|
grpc_slice_intern(grpc_slice_from_static_string(buffer))); |
|
|
|
|
} |
|
|
|
|
/* verify phase */ |
|
|
|
|
for (i = 0; i < MANY; i++) { |
|
|
|
|
gpr_ltoa(i, buffer); |
|
|
|
|
md = grpc_mdelem_from_slices( |
|
|
|
|
grpc_slice_intern(grpc_slice_from_static_string("a")), |
|
|
|
|
grpc_slice_intern(grpc_slice_from_static_string(buffer))); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_eq(md, created[i])); |
|
|
|
|
GRPC_MDELEM_UNREF(md); |
|
|
|
|
} |
|
|
|
|
/* cleanup phase */ |
|
|
|
|
for (i = 0; i < MANY; i++) { |
|
|
|
|
GRPC_MDELEM_UNREF(created[i]); |
|
|
|
|
{ |
|
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
|
/* add phase */ |
|
|
|
|
for (i = 0; i < MANY; i++) { |
|
|
|
|
gpr_ltoa(i, buffer); |
|
|
|
|
created[i] = grpc_mdelem_from_slices( |
|
|
|
|
grpc_slice_intern(grpc_slice_from_static_string("a")), |
|
|
|
|
grpc_slice_intern(grpc_slice_from_static_string(buffer))); |
|
|
|
|
} |
|
|
|
|
/* verify phase */ |
|
|
|
|
for (i = 0; i < MANY; i++) { |
|
|
|
|
gpr_ltoa(i, buffer); |
|
|
|
|
md = grpc_mdelem_from_slices( |
|
|
|
|
grpc_slice_intern(grpc_slice_from_static_string("a")), |
|
|
|
|
grpc_slice_intern(grpc_slice_from_static_string(buffer))); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_eq(md, created[i])); |
|
|
|
|
GRPC_MDELEM_UNREF(md); |
|
|
|
|
} |
|
|
|
|
/* cleanup phase */ |
|
|
|
|
for (i = 0; i < MANY; i++) { |
|
|
|
|
GRPC_MDELEM_UNREF(created[i]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc_shutdown(); |
|
|
|
|
|
|
|
|
|
gpr_free(created); |
|
|
|
@ -158,25 +161,26 @@ static void test_spin_creating_the_same_thing(bool intern_keys, |
|
|
|
|
intern_keys, intern_values); |
|
|
|
|
|
|
|
|
|
grpc_init(); |
|
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
|
grpc_mdelem a, b, c; |
|
|
|
|
GRPC_MDELEM_UNREF( |
|
|
|
|
a = grpc_mdelem_from_slices( |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("a"), intern_keys), |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("b"), intern_values))); |
|
|
|
|
GRPC_MDELEM_UNREF( |
|
|
|
|
b = grpc_mdelem_from_slices( |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("a"), intern_keys), |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("b"), intern_values))); |
|
|
|
|
GRPC_MDELEM_UNREF( |
|
|
|
|
c = grpc_mdelem_from_slices( |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("a"), intern_keys), |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("b"), intern_values))); |
|
|
|
|
if (intern_keys && intern_values) { |
|
|
|
|
GPR_ASSERT(a.payload == b.payload); |
|
|
|
|
GPR_ASSERT(a.payload == c.payload); |
|
|
|
|
{ |
|
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
|
grpc_mdelem a, b, c; |
|
|
|
|
GRPC_MDELEM_UNREF( |
|
|
|
|
a = grpc_mdelem_from_slices( |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("a"), intern_keys), |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("b"), intern_values))); |
|
|
|
|
GRPC_MDELEM_UNREF( |
|
|
|
|
b = grpc_mdelem_from_slices( |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("a"), intern_keys), |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("b"), intern_values))); |
|
|
|
|
GRPC_MDELEM_UNREF( |
|
|
|
|
c = grpc_mdelem_from_slices( |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("a"), intern_keys), |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("b"), intern_values))); |
|
|
|
|
if (intern_keys && intern_values) { |
|
|
|
|
GPR_ASSERT(a.payload == b.payload); |
|
|
|
|
GPR_ASSERT(a.payload == c.payload); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc_shutdown(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -185,38 +189,39 @@ static void test_identity_laws(bool intern_keys, bool intern_values) { |
|
|
|
|
intern_keys, intern_values); |
|
|
|
|
|
|
|
|
|
grpc_init(); |
|
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
|
grpc_mdelem a, b, c; |
|
|
|
|
a = grpc_mdelem_from_slices( |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("a"), intern_keys), |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("b"), intern_values)); |
|
|
|
|
b = grpc_mdelem_from_slices( |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("a"), intern_keys), |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("b"), intern_values)); |
|
|
|
|
c = grpc_mdelem_from_slices( |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("a"), intern_keys), |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("b"), intern_values)); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_eq(a, a)); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_eq(b, b)); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_eq(c, c)); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_eq(a, b)); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_eq(b, c)); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_eq(a, c)); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_eq(b, a)); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_eq(c, b)); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_eq(c, a)); |
|
|
|
|
if (intern_keys && intern_values) { |
|
|
|
|
GPR_ASSERT(a.payload == b.payload); |
|
|
|
|
GPR_ASSERT(a.payload == c.payload); |
|
|
|
|
} else { |
|
|
|
|
GPR_ASSERT(a.payload != b.payload); |
|
|
|
|
GPR_ASSERT(a.payload != c.payload); |
|
|
|
|
GPR_ASSERT(b.payload != c.payload); |
|
|
|
|
{ |
|
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
|
grpc_mdelem a, b, c; |
|
|
|
|
a = grpc_mdelem_from_slices( |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("a"), intern_keys), |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("b"), intern_values)); |
|
|
|
|
b = grpc_mdelem_from_slices( |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("a"), intern_keys), |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("b"), intern_values)); |
|
|
|
|
c = grpc_mdelem_from_slices( |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("a"), intern_keys), |
|
|
|
|
maybe_intern(grpc_slice_from_static_string("b"), intern_values)); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_eq(a, a)); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_eq(b, b)); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_eq(c, c)); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_eq(a, b)); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_eq(b, c)); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_eq(a, c)); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_eq(b, a)); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_eq(c, b)); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_eq(c, a)); |
|
|
|
|
if (intern_keys && intern_values) { |
|
|
|
|
GPR_ASSERT(a.payload == b.payload); |
|
|
|
|
GPR_ASSERT(a.payload == c.payload); |
|
|
|
|
} else { |
|
|
|
|
GPR_ASSERT(a.payload != b.payload); |
|
|
|
|
GPR_ASSERT(a.payload != c.payload); |
|
|
|
|
GPR_ASSERT(b.payload != c.payload); |
|
|
|
|
} |
|
|
|
|
GRPC_MDELEM_UNREF(a); |
|
|
|
|
GRPC_MDELEM_UNREF(b); |
|
|
|
|
GRPC_MDELEM_UNREF(c); |
|
|
|
|
} |
|
|
|
|
GRPC_MDELEM_UNREF(a); |
|
|
|
|
GRPC_MDELEM_UNREF(b); |
|
|
|
|
GRPC_MDELEM_UNREF(c); |
|
|
|
|
|
|
|
|
|
grpc_shutdown(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -231,39 +236,41 @@ static void test_things_stick_around(void) { |
|
|
|
|
gpr_log(GPR_INFO, "test_things_stick_around"); |
|
|
|
|
|
|
|
|
|
grpc_init(); |
|
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
|
|
|
|
|
|
for (i = 0; i < nstrs; i++) { |
|
|
|
|
std::string buffer = |
|
|
|
|
absl::StrFormat("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%" PRIuPTR "x", i); |
|
|
|
|
strs[i] = grpc_slice_intern(grpc_slice_from_static_string(buffer.c_str())); |
|
|
|
|
shuf[i] = i; |
|
|
|
|
} |
|
|
|
|
{ |
|
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
|
|
|
|
|
|
for (i = 0; i < nstrs; i++) { |
|
|
|
|
std::string buffer = |
|
|
|
|
absl::StrFormat("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%" PRIuPTR "x", i); |
|
|
|
|
strs[i] = |
|
|
|
|
grpc_slice_intern(grpc_slice_from_static_string(buffer.c_str())); |
|
|
|
|
shuf[i] = i; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (i = 0; i < nstrs; i++) { |
|
|
|
|
grpc_slice_ref_internal(strs[i]); |
|
|
|
|
grpc_slice_unref_internal(strs[i]); |
|
|
|
|
} |
|
|
|
|
for (i = 0; i < nstrs; i++) { |
|
|
|
|
grpc_slice_ref_internal(strs[i]); |
|
|
|
|
grpc_slice_unref_internal(strs[i]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (i = 0; i < nstrs; i++) { |
|
|
|
|
size_t p = static_cast<size_t>(rand()) % nstrs; |
|
|
|
|
size_t q = static_cast<size_t>(rand()) % nstrs; |
|
|
|
|
size_t temp = shuf[p]; |
|
|
|
|
shuf[p] = shuf[q]; |
|
|
|
|
shuf[q] = temp; |
|
|
|
|
} |
|
|
|
|
for (i = 0; i < nstrs; i++) { |
|
|
|
|
size_t p = static_cast<size_t>(rand()) % nstrs; |
|
|
|
|
size_t q = static_cast<size_t>(rand()) % nstrs; |
|
|
|
|
size_t temp = shuf[p]; |
|
|
|
|
shuf[p] = shuf[q]; |
|
|
|
|
shuf[q] = temp; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (i = 0; i < nstrs; i++) { |
|
|
|
|
grpc_slice_unref_internal(strs[shuf[i]]); |
|
|
|
|
for (j = i + 1; j < nstrs; j++) { |
|
|
|
|
std::string buffer = absl::StrFormat( |
|
|
|
|
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%" PRIuPTR "x", shuf[j]); |
|
|
|
|
test = grpc_slice_intern(grpc_slice_from_static_string(buffer.c_str())); |
|
|
|
|
GPR_ASSERT(grpc_slice_is_equivalent(test, strs[shuf[j]])); |
|
|
|
|
grpc_slice_unref_internal(test); |
|
|
|
|
for (i = 0; i < nstrs; i++) { |
|
|
|
|
grpc_slice_unref_internal(strs[shuf[i]]); |
|
|
|
|
for (j = i + 1; j < nstrs; j++) { |
|
|
|
|
std::string buffer = absl::StrFormat( |
|
|
|
|
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%" PRIuPTR "x", shuf[j]); |
|
|
|
|
test = grpc_slice_intern(grpc_slice_from_static_string(buffer.c_str())); |
|
|
|
|
GPR_ASSERT(grpc_slice_is_equivalent(test, strs[shuf[j]])); |
|
|
|
|
grpc_slice_unref_internal(test); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc_shutdown(); |
|
|
|
|
gpr_free(strs); |
|
|
|
|
gpr_free(shuf); |
|
|
|
@ -276,19 +283,20 @@ static void test_user_data_works(void) { |
|
|
|
|
gpr_log(GPR_INFO, "test_user_data_works"); |
|
|
|
|
|
|
|
|
|
grpc_init(); |
|
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
|
ud1 = static_cast<int*>(gpr_malloc(sizeof(int))); |
|
|
|
|
*ud1 = 1; |
|
|
|
|
ud2 = static_cast<int*>(gpr_malloc(sizeof(int))); |
|
|
|
|
*ud2 = 2; |
|
|
|
|
md = grpc_mdelem_from_slices( |
|
|
|
|
grpc_slice_intern(grpc_slice_from_static_string("abc")), |
|
|
|
|
grpc_slice_intern(grpc_slice_from_static_string("123"))); |
|
|
|
|
grpc_mdelem_set_user_data(md, gpr_free, ud1); |
|
|
|
|
grpc_mdelem_set_user_data(md, gpr_free, ud2); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_get_user_data(md, gpr_free) == ud1); |
|
|
|
|
GRPC_MDELEM_UNREF(md); |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
|
ud1 = static_cast<int*>(gpr_malloc(sizeof(int))); |
|
|
|
|
*ud1 = 1; |
|
|
|
|
ud2 = static_cast<int*>(gpr_malloc(sizeof(int))); |
|
|
|
|
*ud2 = 2; |
|
|
|
|
md = grpc_mdelem_from_slices( |
|
|
|
|
grpc_slice_intern(grpc_slice_from_static_string("abc")), |
|
|
|
|
grpc_slice_intern(grpc_slice_from_static_string("123"))); |
|
|
|
|
grpc_mdelem_set_user_data(md, gpr_free, ud1); |
|
|
|
|
grpc_mdelem_set_user_data(md, gpr_free, ud2); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_get_user_data(md, gpr_free) == ud1); |
|
|
|
|
GRPC_MDELEM_UNREF(md); |
|
|
|
|
} |
|
|
|
|
grpc_shutdown(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -299,18 +307,19 @@ static void test_user_data_works_for_allocated_md(void) { |
|
|
|
|
gpr_log(GPR_INFO, "test_user_data_works"); |
|
|
|
|
|
|
|
|
|
grpc_init(); |
|
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
|
ud1 = static_cast<int*>(gpr_malloc(sizeof(int))); |
|
|
|
|
*ud1 = 1; |
|
|
|
|
ud2 = static_cast<int*>(gpr_malloc(sizeof(int))); |
|
|
|
|
*ud2 = 2; |
|
|
|
|
md = grpc_mdelem_from_slices(grpc_slice_from_static_string("abc"), |
|
|
|
|
grpc_slice_from_static_string("123")); |
|
|
|
|
grpc_mdelem_set_user_data(md, gpr_free, ud1); |
|
|
|
|
grpc_mdelem_set_user_data(md, gpr_free, ud2); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_get_user_data(md, gpr_free) == ud1); |
|
|
|
|
GRPC_MDELEM_UNREF(md); |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
|
ud1 = static_cast<int*>(gpr_malloc(sizeof(int))); |
|
|
|
|
*ud1 = 1; |
|
|
|
|
ud2 = static_cast<int*>(gpr_malloc(sizeof(int))); |
|
|
|
|
*ud2 = 2; |
|
|
|
|
md = grpc_mdelem_from_slices(grpc_slice_from_static_string("abc"), |
|
|
|
|
grpc_slice_from_static_string("123")); |
|
|
|
|
grpc_mdelem_set_user_data(md, gpr_free, ud1); |
|
|
|
|
grpc_mdelem_set_user_data(md, gpr_free, ud2); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_get_user_data(md, gpr_free) == ud1); |
|
|
|
|
GRPC_MDELEM_UNREF(md); |
|
|
|
|
} |
|
|
|
|
grpc_shutdown(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -318,85 +327,86 @@ static void test_copied_static_metadata(bool dup_key, bool dup_value) { |
|
|
|
|
gpr_log(GPR_INFO, "test_static_metadata: dup_key=%d dup_value=%d", dup_key, |
|
|
|
|
dup_value); |
|
|
|
|
grpc_init(); |
|
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < GRPC_STATIC_MDELEM_COUNT; i++) { |
|
|
|
|
grpc_mdelem p = GRPC_MAKE_MDELEM(&grpc_static_mdelem_table()[i], |
|
|
|
|
GRPC_MDELEM_STORAGE_STATIC); |
|
|
|
|
grpc_mdelem q = |
|
|
|
|
grpc_mdelem_from_slices(maybe_dup(GRPC_MDKEY(p), dup_key), |
|
|
|
|
maybe_dup(GRPC_MDVALUE(p), dup_value)); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_eq(p, q)); |
|
|
|
|
if (dup_key || dup_value) { |
|
|
|
|
GPR_ASSERT(p.payload != q.payload); |
|
|
|
|
} else { |
|
|
|
|
GPR_ASSERT(p.payload == q.payload); |
|
|
|
|
{ |
|
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < GRPC_STATIC_MDELEM_COUNT; i++) { |
|
|
|
|
grpc_mdelem p = GRPC_MAKE_MDELEM(&grpc_static_mdelem_table()[i], |
|
|
|
|
GRPC_MDELEM_STORAGE_STATIC); |
|
|
|
|
grpc_mdelem q = |
|
|
|
|
grpc_mdelem_from_slices(maybe_dup(GRPC_MDKEY(p), dup_key), |
|
|
|
|
maybe_dup(GRPC_MDVALUE(p), dup_value)); |
|
|
|
|
GPR_ASSERT(grpc_mdelem_eq(p, q)); |
|
|
|
|
if (dup_key || dup_value) { |
|
|
|
|
GPR_ASSERT(p.payload != q.payload); |
|
|
|
|
} else { |
|
|
|
|
GPR_ASSERT(p.payload == q.payload); |
|
|
|
|
} |
|
|
|
|
GRPC_MDELEM_UNREF(p); |
|
|
|
|
GRPC_MDELEM_UNREF(q); |
|
|
|
|
} |
|
|
|
|
GRPC_MDELEM_UNREF(p); |
|
|
|
|
GRPC_MDELEM_UNREF(q); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc_shutdown(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void test_grpc_metadata_batch_get_value_with_absent_key(void) { |
|
|
|
|
grpc_init(); |
|
|
|
|
grpc_metadata_batch metadata; |
|
|
|
|
grpc_metadata_batch_init(&metadata); |
|
|
|
|
std::string concatenated_value; |
|
|
|
|
absl::optional<absl::string_view> value = grpc_metadata_batch_get_value( |
|
|
|
|
&metadata, "absent_key", &concatenated_value); |
|
|
|
|
GPR_ASSERT(value == absl::nullopt); |
|
|
|
|
grpc_metadata_batch_destroy(&metadata); |
|
|
|
|
{ |
|
|
|
|
grpc_metadata_batch metadata; |
|
|
|
|
std::string concatenated_value; |
|
|
|
|
absl::optional<absl::string_view> value = grpc_metadata_batch_get_value( |
|
|
|
|
&metadata, "absent_key", &concatenated_value); |
|
|
|
|
GPR_ASSERT(value == absl::nullopt); |
|
|
|
|
} |
|
|
|
|
grpc_shutdown(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void test_grpc_metadata_batch_get_value_returns_one_value(void) { |
|
|
|
|
grpc_init(); |
|
|
|
|
const char* kKey = "some_key"; |
|
|
|
|
const char* kValue = "some_value"; |
|
|
|
|
grpc_metadata_batch metadata; |
|
|
|
|
grpc_metadata_batch_init(&metadata); |
|
|
|
|
grpc_linked_mdelem storage; |
|
|
|
|
storage.md = grpc_mdelem_from_slices( |
|
|
|
|
grpc_slice_intern(grpc_slice_from_static_string(kKey)), |
|
|
|
|
grpc_slice_intern(grpc_slice_from_static_string(kValue))); |
|
|
|
|
GPR_ASSERT(grpc_metadata_batch_link_head(&metadata, &storage) == |
|
|
|
|
GRPC_ERROR_NONE); |
|
|
|
|
std::string concatenated_value; |
|
|
|
|
absl::optional<absl::string_view> value = |
|
|
|
|
grpc_metadata_batch_get_value(&metadata, kKey, &concatenated_value); |
|
|
|
|
GPR_ASSERT(value.has_value()); |
|
|
|
|
GPR_ASSERT(value.value() == kValue); |
|
|
|
|
grpc_metadata_batch_destroy(&metadata); |
|
|
|
|
{ |
|
|
|
|
const char* kKey = "some_key"; |
|
|
|
|
const char* kValue = "some_value"; |
|
|
|
|
grpc_linked_mdelem storage; |
|
|
|
|
grpc_metadata_batch metadata; |
|
|
|
|
storage.md = grpc_mdelem_from_slices( |
|
|
|
|
grpc_slice_intern(grpc_slice_from_static_string(kKey)), |
|
|
|
|
grpc_slice_intern(grpc_slice_from_static_string(kValue))); |
|
|
|
|
GPR_ASSERT(grpc_metadata_batch_link_head(&metadata, &storage) == |
|
|
|
|
GRPC_ERROR_NONE); |
|
|
|
|
std::string concatenated_value; |
|
|
|
|
absl::optional<absl::string_view> value = |
|
|
|
|
grpc_metadata_batch_get_value(&metadata, kKey, &concatenated_value); |
|
|
|
|
GPR_ASSERT(value.has_value()); |
|
|
|
|
GPR_ASSERT(value.value() == kValue); |
|
|
|
|
} |
|
|
|
|
grpc_shutdown(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void test_grpc_metadata_batch_get_value_returns_multiple_values(void) { |
|
|
|
|
grpc_init(); |
|
|
|
|
const char* kKey = "some_key"; |
|
|
|
|
const char* kValue1 = "value1"; |
|
|
|
|
const char* kValue2 = "value2"; |
|
|
|
|
grpc_metadata_batch metadata; |
|
|
|
|
grpc_metadata_batch_init(&metadata); |
|
|
|
|
grpc_linked_mdelem storage1; |
|
|
|
|
storage1.md = grpc_mdelem_from_slices( |
|
|
|
|
grpc_slice_intern(grpc_slice_from_static_string(kKey)), |
|
|
|
|
grpc_slice_intern(grpc_slice_from_static_string(kValue1))); |
|
|
|
|
GPR_ASSERT(grpc_metadata_batch_link_tail(&metadata, &storage1) == |
|
|
|
|
GRPC_ERROR_NONE); |
|
|
|
|
grpc_linked_mdelem storage2; |
|
|
|
|
storage2.md = grpc_mdelem_from_slices( |
|
|
|
|
grpc_slice_intern(grpc_slice_from_static_string(kKey)), |
|
|
|
|
grpc_slice_intern(grpc_slice_from_static_string(kValue2))); |
|
|
|
|
GPR_ASSERT(grpc_metadata_batch_link_tail(&metadata, &storage2) == |
|
|
|
|
GRPC_ERROR_NONE); |
|
|
|
|
std::string concatenated_value; |
|
|
|
|
absl::optional<absl::string_view> value = |
|
|
|
|
grpc_metadata_batch_get_value(&metadata, kKey, &concatenated_value); |
|
|
|
|
GPR_ASSERT(value.has_value()); |
|
|
|
|
GPR_ASSERT(value.value() == absl::StrCat(kValue1, ",", kValue2)); |
|
|
|
|
grpc_metadata_batch_destroy(&metadata); |
|
|
|
|
{ |
|
|
|
|
const char* kKey = "some_key"; |
|
|
|
|
const char* kValue1 = "value1"; |
|
|
|
|
const char* kValue2 = "value2"; |
|
|
|
|
grpc_linked_mdelem storage1; |
|
|
|
|
grpc_linked_mdelem storage2; |
|
|
|
|
grpc_metadata_batch metadata; |
|
|
|
|
storage1.md = grpc_mdelem_from_slices( |
|
|
|
|
grpc_slice_intern(grpc_slice_from_static_string(kKey)), |
|
|
|
|
grpc_slice_intern(grpc_slice_from_static_string(kValue1))); |
|
|
|
|
GPR_ASSERT(grpc_metadata_batch_link_tail(&metadata, &storage1) == |
|
|
|
|
GRPC_ERROR_NONE); |
|
|
|
|
storage2.md = grpc_mdelem_from_slices( |
|
|
|
|
grpc_slice_intern(grpc_slice_from_static_string(kKey)), |
|
|
|
|
grpc_slice_intern(grpc_slice_from_static_string(kValue2))); |
|
|
|
|
GPR_ASSERT(grpc_metadata_batch_link_tail(&metadata, &storage2) == |
|
|
|
|
GRPC_ERROR_NONE); |
|
|
|
|
std::string concatenated_value; |
|
|
|
|
absl::optional<absl::string_view> value = |
|
|
|
|
grpc_metadata_batch_get_value(&metadata, kKey, &concatenated_value); |
|
|
|
|
GPR_ASSERT(value.has_value()); |
|
|
|
|
GPR_ASSERT(value.value() == absl::StrCat(kValue1, ",", kValue2)); |
|
|
|
|
} |
|
|
|
|
grpc_shutdown(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|