Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | b7f3f6e | 2016-03-25 17:13:09 -0700 | [diff] [blame] | 3 | * Copyright 2015-2016, Google Inc. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are |
| 8 | * met: |
| 9 | * |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above |
| 13 | * copyright notice, this list of conditions and the following disclaimer |
| 14 | * in the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google Inc. nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | * |
| 32 | */ |
| 33 | |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 34 | #include "src/core/lib/transport/metadata.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 35 | |
| 36 | #include <stdio.h> |
| 37 | |
Craig Tiller | ebdef9d | 2015-11-19 17:09:49 -0800 | [diff] [blame] | 38 | #include <grpc/grpc.h> |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 39 | #include <grpc/support/alloc.h> |
| 40 | #include <grpc/support/log.h> |
Masood Malekghassemi | 701af60 | 2015-06-03 15:01:17 -0700 | [diff] [blame] | 41 | #include <grpc/support/string_util.h> |
Craig Tiller | ebdef9d | 2015-11-19 17:09:49 -0800 | [diff] [blame] | 42 | |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 43 | #include "src/core/lib/support/string.h" |
| 44 | #include "src/core/lib/transport/chttp2/bin_encoder.h" |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 45 | #include "test/core/util/test_config.h" |
| 46 | |
Craig Tiller | 3569619 | 2015-05-24 15:00:37 -0700 | [diff] [blame] | 47 | #define LOG_TEST(x) gpr_log(GPR_INFO, "%s", x) |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 48 | |
| 49 | /* a large number */ |
Craig Tiller | efad8fa | 2015-02-18 13:59:46 -0800 | [diff] [blame] | 50 | #define MANY 10000 |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 51 | |
Craig Tiller | 32946d3 | 2015-01-15 11:37:30 -0800 | [diff] [blame] | 52 | static void test_no_op(void) { |
Craig Tiller | 3569619 | 2015-05-24 15:00:37 -0700 | [diff] [blame] | 53 | LOG_TEST("test_no_op"); |
Craig Tiller | b2b4261 | 2015-11-20 12:02:17 -0800 | [diff] [blame] | 54 | grpc_init(); |
| 55 | grpc_shutdown(); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 56 | } |
| 57 | |
Craig Tiller | 32946d3 | 2015-01-15 11:37:30 -0800 | [diff] [blame] | 58 | static void test_create_string(void) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 59 | grpc_mdstr *s1, *s2, *s3; |
| 60 | |
Craig Tiller | 3569619 | 2015-05-24 15:00:37 -0700 | [diff] [blame] | 61 | LOG_TEST("test_create_string"); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 62 | |
Craig Tiller | b2b4261 | 2015-11-20 12:02:17 -0800 | [diff] [blame] | 63 | grpc_init(); |
| 64 | s1 = grpc_mdstr_from_string("hello"); |
| 65 | s2 = grpc_mdstr_from_string("hello"); |
| 66 | s3 = grpc_mdstr_from_string("very much not hello"); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 67 | GPR_ASSERT(s1 == s2); |
| 68 | GPR_ASSERT(s3 != s1); |
| 69 | GPR_ASSERT(gpr_slice_str_cmp(s1->slice, "hello") == 0); |
| 70 | GPR_ASSERT(gpr_slice_str_cmp(s3->slice, "very much not hello") == 0); |
Craig Tiller | 1a65a23 | 2015-07-06 10:22:32 -0700 | [diff] [blame] | 71 | GRPC_MDSTR_UNREF(s1); |
| 72 | GRPC_MDSTR_UNREF(s2); |
Craig Tiller | 1a65a23 | 2015-07-06 10:22:32 -0700 | [diff] [blame] | 73 | GRPC_MDSTR_UNREF(s3); |
Craig Tiller | b2b4261 | 2015-11-20 12:02:17 -0800 | [diff] [blame] | 74 | grpc_shutdown(); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 75 | } |
| 76 | |
Craig Tiller | 32946d3 | 2015-01-15 11:37:30 -0800 | [diff] [blame] | 77 | static void test_create_metadata(void) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 78 | grpc_mdelem *m1, *m2, *m3; |
| 79 | |
Craig Tiller | 3569619 | 2015-05-24 15:00:37 -0700 | [diff] [blame] | 80 | LOG_TEST("test_create_metadata"); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 81 | |
Craig Tiller | b2b4261 | 2015-11-20 12:02:17 -0800 | [diff] [blame] | 82 | grpc_init(); |
| 83 | m1 = grpc_mdelem_from_strings("a", "b"); |
| 84 | m2 = grpc_mdelem_from_strings("a", "b"); |
| 85 | m3 = grpc_mdelem_from_strings("a", "c"); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 86 | GPR_ASSERT(m1 == m2); |
| 87 | GPR_ASSERT(m3 != m1); |
| 88 | GPR_ASSERT(m3->key == m1->key); |
| 89 | GPR_ASSERT(m3->value != m1->value); |
| 90 | GPR_ASSERT(gpr_slice_str_cmp(m1->key->slice, "a") == 0); |
| 91 | GPR_ASSERT(gpr_slice_str_cmp(m1->value->slice, "b") == 0); |
| 92 | GPR_ASSERT(gpr_slice_str_cmp(m3->value->slice, "c") == 0); |
Craig Tiller | 1a65a23 | 2015-07-06 10:22:32 -0700 | [diff] [blame] | 93 | GRPC_MDELEM_UNREF(m1); |
| 94 | GRPC_MDELEM_UNREF(m2); |
| 95 | GRPC_MDELEM_UNREF(m3); |
Craig Tiller | b2b4261 | 2015-11-20 12:02:17 -0800 | [diff] [blame] | 96 | grpc_shutdown(); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 97 | } |
| 98 | |
Craig Tiller | 32946d3 | 2015-01-15 11:37:30 -0800 | [diff] [blame] | 99 | static void test_create_many_ephemeral_metadata(void) { |
Craig Tiller | 8ddf312 | 2015-01-23 15:25:40 -0800 | [diff] [blame] | 100 | char buffer[GPR_LTOA_MIN_BUFSIZE]; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 101 | long i; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 102 | |
Craig Tiller | 3569619 | 2015-05-24 15:00:37 -0700 | [diff] [blame] | 103 | LOG_TEST("test_create_many_ephemeral_metadata"); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 104 | |
Craig Tiller | b2b4261 | 2015-11-20 12:02:17 -0800 | [diff] [blame] | 105 | grpc_init(); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 106 | /* add, and immediately delete a bunch of different elements */ |
| 107 | for (i = 0; i < MANY; i++) { |
Craig Tiller | 8ddf312 | 2015-01-23 15:25:40 -0800 | [diff] [blame] | 108 | gpr_ltoa(i, buffer); |
Craig Tiller | b2b4261 | 2015-11-20 12:02:17 -0800 | [diff] [blame] | 109 | GRPC_MDELEM_UNREF(grpc_mdelem_from_strings("a", buffer)); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 110 | } |
Craig Tiller | b2b4261 | 2015-11-20 12:02:17 -0800 | [diff] [blame] | 111 | grpc_shutdown(); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 112 | } |
| 113 | |
Craig Tiller | 32946d3 | 2015-01-15 11:37:30 -0800 | [diff] [blame] | 114 | static void test_create_many_persistant_metadata(void) { |
Craig Tiller | 8ddf312 | 2015-01-23 15:25:40 -0800 | [diff] [blame] | 115 | char buffer[GPR_LTOA_MIN_BUFSIZE]; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 116 | long i; |
| 117 | grpc_mdelem **created = gpr_malloc(sizeof(grpc_mdelem *) * MANY); |
| 118 | grpc_mdelem *md; |
| 119 | |
Craig Tiller | 3569619 | 2015-05-24 15:00:37 -0700 | [diff] [blame] | 120 | LOG_TEST("test_create_many_persistant_metadata"); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 121 | |
Craig Tiller | b2b4261 | 2015-11-20 12:02:17 -0800 | [diff] [blame] | 122 | grpc_init(); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 123 | /* add phase */ |
| 124 | for (i = 0; i < MANY; i++) { |
Craig Tiller | 8ddf312 | 2015-01-23 15:25:40 -0800 | [diff] [blame] | 125 | gpr_ltoa(i, buffer); |
Craig Tiller | b2b4261 | 2015-11-20 12:02:17 -0800 | [diff] [blame] | 126 | created[i] = grpc_mdelem_from_strings("a", buffer); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 127 | } |
| 128 | /* verify phase */ |
| 129 | for (i = 0; i < MANY; i++) { |
Craig Tiller | 8ddf312 | 2015-01-23 15:25:40 -0800 | [diff] [blame] | 130 | gpr_ltoa(i, buffer); |
Craig Tiller | b2b4261 | 2015-11-20 12:02:17 -0800 | [diff] [blame] | 131 | md = grpc_mdelem_from_strings("a", buffer); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 132 | GPR_ASSERT(md == created[i]); |
Craig Tiller | 1a65a23 | 2015-07-06 10:22:32 -0700 | [diff] [blame] | 133 | GRPC_MDELEM_UNREF(md); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 134 | } |
| 135 | /* cleanup phase */ |
| 136 | for (i = 0; i < MANY; i++) { |
Craig Tiller | 1a65a23 | 2015-07-06 10:22:32 -0700 | [diff] [blame] | 137 | GRPC_MDELEM_UNREF(created[i]); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 138 | } |
Craig Tiller | b2b4261 | 2015-11-20 12:02:17 -0800 | [diff] [blame] | 139 | grpc_shutdown(); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 140 | |
| 141 | gpr_free(created); |
| 142 | } |
| 143 | |
Craig Tiller | 32946d3 | 2015-01-15 11:37:30 -0800 | [diff] [blame] | 144 | static void test_spin_creating_the_same_thing(void) { |
Craig Tiller | 3569619 | 2015-05-24 15:00:37 -0700 | [diff] [blame] | 145 | LOG_TEST("test_spin_creating_the_same_thing"); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 146 | |
Craig Tiller | b2b4261 | 2015-11-20 12:02:17 -0800 | [diff] [blame] | 147 | grpc_init(); |
| 148 | GRPC_MDELEM_UNREF(grpc_mdelem_from_strings("a", "b")); |
| 149 | GRPC_MDELEM_UNREF(grpc_mdelem_from_strings("a", "b")); |
| 150 | GRPC_MDELEM_UNREF(grpc_mdelem_from_strings("a", "b")); |
| 151 | grpc_shutdown(); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 152 | } |
| 153 | |
Craig Tiller | 32946d3 | 2015-01-15 11:37:30 -0800 | [diff] [blame] | 154 | static void test_things_stick_around(void) { |
Craig Tiller | 32ca48c | 2015-09-10 11:47:15 -0700 | [diff] [blame] | 155 | size_t i, j; |
Craig Tiller | 8ddf312 | 2015-01-23 15:25:40 -0800 | [diff] [blame] | 156 | char *buffer; |
Craig Tiller | 32ca48c | 2015-09-10 11:47:15 -0700 | [diff] [blame] | 157 | size_t nstrs = 1000; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 158 | grpc_mdstr **strs = gpr_malloc(sizeof(grpc_mdstr *) * nstrs); |
Craig Tiller | 32ca48c | 2015-09-10 11:47:15 -0700 | [diff] [blame] | 159 | size_t *shuf = gpr_malloc(sizeof(size_t) * nstrs); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 160 | grpc_mdstr *test; |
| 161 | |
Craig Tiller | 3569619 | 2015-05-24 15:00:37 -0700 | [diff] [blame] | 162 | LOG_TEST("test_things_stick_around"); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 163 | |
Craig Tiller | b2b4261 | 2015-11-20 12:02:17 -0800 | [diff] [blame] | 164 | grpc_init(); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 165 | |
| 166 | for (i = 0; i < nstrs; i++) { |
Craig Tiller | 8ddf312 | 2015-01-23 15:25:40 -0800 | [diff] [blame] | 167 | gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%dx", i); |
Craig Tiller | b2b4261 | 2015-11-20 12:02:17 -0800 | [diff] [blame] | 168 | strs[i] = grpc_mdstr_from_string(buffer); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 169 | shuf[i] = i; |
Craig Tiller | 8ddf312 | 2015-01-23 15:25:40 -0800 | [diff] [blame] | 170 | gpr_free(buffer); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | for (i = 0; i < nstrs; i++) { |
Craig Tiller | 1a65a23 | 2015-07-06 10:22:32 -0700 | [diff] [blame] | 174 | GRPC_MDSTR_REF(strs[i]); |
| 175 | GRPC_MDSTR_UNREF(strs[i]); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | for (i = 0; i < nstrs; i++) { |
Craig Tiller | 32ca48c | 2015-09-10 11:47:15 -0700 | [diff] [blame] | 179 | size_t p = (size_t)rand() % nstrs; |
| 180 | size_t q = (size_t)rand() % nstrs; |
| 181 | size_t temp = shuf[p]; |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 182 | shuf[p] = shuf[q]; |
| 183 | shuf[q] = temp; |
| 184 | } |
| 185 | |
| 186 | for (i = 0; i < nstrs; i++) { |
Craig Tiller | 1a65a23 | 2015-07-06 10:22:32 -0700 | [diff] [blame] | 187 | GRPC_MDSTR_UNREF(strs[shuf[i]]); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 188 | for (j = i + 1; j < nstrs; j++) { |
Craig Tiller | 8ddf312 | 2015-01-23 15:25:40 -0800 | [diff] [blame] | 189 | gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%dx", shuf[j]); |
Craig Tiller | b2b4261 | 2015-11-20 12:02:17 -0800 | [diff] [blame] | 190 | test = grpc_mdstr_from_string(buffer); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 191 | GPR_ASSERT(test == strs[shuf[j]]); |
Craig Tiller | 1a65a23 | 2015-07-06 10:22:32 -0700 | [diff] [blame] | 192 | GRPC_MDSTR_UNREF(test); |
Craig Tiller | 8ddf312 | 2015-01-23 15:25:40 -0800 | [diff] [blame] | 193 | gpr_free(buffer); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | |
Craig Tiller | b2b4261 | 2015-11-20 12:02:17 -0800 | [diff] [blame] | 197 | grpc_shutdown(); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 198 | gpr_free(strs); |
| 199 | gpr_free(shuf); |
| 200 | } |
| 201 | |
Craig Tiller | 32946d3 | 2015-01-15 11:37:30 -0800 | [diff] [blame] | 202 | static void test_slices_work(void) { |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 203 | /* ensure no memory leaks when switching representation from mdstr to slice */ |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 204 | grpc_mdstr *str; |
| 205 | gpr_slice slice; |
| 206 | |
Craig Tiller | 3569619 | 2015-05-24 15:00:37 -0700 | [diff] [blame] | 207 | LOG_TEST("test_slices_work"); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 208 | |
Craig Tiller | b2b4261 | 2015-11-20 12:02:17 -0800 | [diff] [blame] | 209 | grpc_init(); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 210 | |
| 211 | str = grpc_mdstr_from_string( |
Craig Tiller | b2b4261 | 2015-11-20 12:02:17 -0800 | [diff] [blame] | 212 | "123456789012345678901234567890123456789012345678901234567890"); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 213 | slice = gpr_slice_ref(str->slice); |
Craig Tiller | 1a65a23 | 2015-07-06 10:22:32 -0700 | [diff] [blame] | 214 | GRPC_MDSTR_UNREF(str); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 215 | gpr_slice_unref(slice); |
| 216 | |
| 217 | str = grpc_mdstr_from_string( |
Craig Tiller | b2b4261 | 2015-11-20 12:02:17 -0800 | [diff] [blame] | 218 | "123456789012345678901234567890123456789012345678901234567890"); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 219 | slice = gpr_slice_ref(str->slice); |
| 220 | gpr_slice_unref(slice); |
Craig Tiller | 1a65a23 | 2015-07-06 10:22:32 -0700 | [diff] [blame] | 221 | GRPC_MDSTR_UNREF(str); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 222 | |
Craig Tiller | b2b4261 | 2015-11-20 12:02:17 -0800 | [diff] [blame] | 223 | grpc_shutdown(); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 224 | } |
| 225 | |
Craig Tiller | 32946d3 | 2015-01-15 11:37:30 -0800 | [diff] [blame] | 226 | static void test_base64_and_huffman_works(void) { |
ctiller | 430c499 | 2014-12-11 09:15:41 -0800 | [diff] [blame] | 227 | grpc_mdstr *str; |
| 228 | gpr_slice slice1; |
| 229 | gpr_slice slice2; |
| 230 | |
Craig Tiller | 3569619 | 2015-05-24 15:00:37 -0700 | [diff] [blame] | 231 | LOG_TEST("test_base64_and_huffman_works"); |
ctiller | 430c499 | 2014-12-11 09:15:41 -0800 | [diff] [blame] | 232 | |
Craig Tiller | b2b4261 | 2015-11-20 12:02:17 -0800 | [diff] [blame] | 233 | grpc_init(); |
| 234 | str = grpc_mdstr_from_string("abcdefg"); |
ctiller | 430c499 | 2014-12-11 09:15:41 -0800 | [diff] [blame] | 235 | slice1 = grpc_mdstr_as_base64_encoded_and_huffman_compressed(str); |
| 236 | slice2 = grpc_chttp2_base64_encode_and_huffman_compress(str->slice); |
| 237 | GPR_ASSERT(0 == gpr_slice_cmp(slice1, slice2)); |
| 238 | |
| 239 | gpr_slice_unref(slice2); |
Craig Tiller | 1a65a23 | 2015-07-06 10:22:32 -0700 | [diff] [blame] | 240 | GRPC_MDSTR_UNREF(str); |
Craig Tiller | b2b4261 | 2015-11-20 12:02:17 -0800 | [diff] [blame] | 241 | grpc_shutdown(); |
ctiller | 430c499 | 2014-12-11 09:15:41 -0800 | [diff] [blame] | 242 | } |
| 243 | |
Craig Tiller | d52fbb8 | 2015-12-09 14:23:12 -0800 | [diff] [blame] | 244 | static void test_user_data_works(void) { |
| 245 | int *ud1; |
| 246 | int *ud2; |
| 247 | grpc_mdelem *md; |
| 248 | LOG_TEST("test_user_data_works"); |
| 249 | |
| 250 | grpc_init(); |
| 251 | ud1 = gpr_malloc(sizeof(int)); |
| 252 | *ud1 = 1; |
| 253 | ud2 = gpr_malloc(sizeof(int)); |
| 254 | *ud2 = 2; |
| 255 | md = grpc_mdelem_from_strings("abc", "123"); |
| 256 | grpc_mdelem_set_user_data(md, gpr_free, ud1); |
| 257 | grpc_mdelem_set_user_data(md, gpr_free, ud2); |
| 258 | GPR_ASSERT(grpc_mdelem_get_user_data(md, gpr_free) == ud1); |
| 259 | GRPC_MDELEM_UNREF(md); |
| 260 | grpc_shutdown(); |
| 261 | } |
| 262 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 263 | int main(int argc, char **argv) { |
| 264 | grpc_test_init(argc, argv); |
| 265 | test_no_op(); |
| 266 | test_create_string(); |
| 267 | test_create_metadata(); |
| 268 | test_create_many_ephemeral_metadata(); |
| 269 | test_create_many_persistant_metadata(); |
| 270 | test_spin_creating_the_same_thing(); |
| 271 | test_things_stick_around(); |
| 272 | test_slices_work(); |
ctiller | 430c499 | 2014-12-11 09:15:41 -0800 | [diff] [blame] | 273 | test_base64_and_huffman_works(); |
Craig Tiller | d52fbb8 | 2015-12-09 14:23:12 -0800 | [diff] [blame] | 274 | test_user_data_works(); |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 275 | return 0; |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 276 | } |