| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include <sys/uio.h> |
| 4 |
|
| 5 |
#include "alloc-util.h" |
| 6 |
#include "iovec-util.h" |
| 7 |
#include "iovec-wrapper.h" |
| 8 |
#include "random-util.h" |
| 9 |
#include "tests.h" |
| 10 |
|
| 11 |
TEST(iovw_compare) { |
| 12 |
_cleanup_(iovw_done) struct iovec_wrapper a1 = {}, a2 = {}, b = {}, c = {}, d = {}, e = {}; |
| 13 |
|
| 14 |
ASSERT_OK(iovw_put(&a1, (char*) "foo", 3)); |
| 15 |
ASSERT_OK(iovw_put(&a1, (char*) "aaaaa", 5)); |
| 16 |
|
| 17 |
ASSERT_OK(iovw_put(&a2, (char*) "foo", 3)); |
| 18 |
ASSERT_OK(iovw_put(&a2, (char*) "aaaaa", 5)); |
| 19 |
|
| 20 |
ASSERT_OK(iovw_put(&b, (char*) "foo", 3)); |
| 21 |
ASSERT_OK(iovw_put(&b, (char*) "bbbbb", 5)); |
| 22 |
|
| 23 |
ASSERT_OK(iovw_put(&c, (char*) "foo", 3)); |
| 24 |
|
| 25 |
ASSERT_OK(iovw_put(&d, (char*) "fooaa", 5)); |
| 26 |
ASSERT_OK(iovw_put(&d, (char*) "aaa", 3)); |
| 27 |
|
| 28 |
ASSERT_EQ(iovw_compare(&a1, &a1), 0); |
| 29 |
ASSERT_EQ(iovw_compare(&a1, &a2), 0); |
| 30 |
ASSERT_EQ(iovw_compare(&a2, &a1), 0); |
| 31 |
ASSERT_LT(iovw_compare(&a1, &b), 0); |
| 32 |
ASSERT_GT(iovw_compare(&b, &a1), 0); |
| 33 |
ASSERT_EQ(iovw_compare(&b, &b), 0); |
| 34 |
ASSERT_GT(iovw_compare(&a1, &c), 0); |
| 35 |
ASSERT_LT(iovw_compare(&c, &a1), 0); |
| 36 |
ASSERT_EQ(iovw_compare(&c, &c), 0); |
| 37 |
ASSERT_LT(iovw_compare(&a1, &d), 0); |
| 38 |
ASSERT_GT(iovw_compare(&d, &a1), 0); |
| 39 |
ASSERT_EQ(iovw_compare(&d, &d), 0); |
| 40 |
ASSERT_GT(iovw_compare(&a1, &e), 0); |
| 41 |
ASSERT_LT(iovw_compare(&e, &a1), 0); |
| 42 |
ASSERT_EQ(iovw_compare(&e, &e), 0); |
| 43 |
ASSERT_GT(iovw_compare(&a1, NULL), 0); |
| 44 |
ASSERT_LT(iovw_compare(NULL, &a1), 0); |
| 45 |
ASSERT_EQ(iovw_compare(NULL, NULL), 0); |
| 46 |
|
| 47 |
ASSERT_TRUE(iovw_equal(&a1, &a1)); |
| 48 |
ASSERT_TRUE(iovw_equal(&a1, &a2)); |
| 49 |
ASSERT_TRUE(iovw_equal(&a2, &a1)); |
| 50 |
ASSERT_FALSE(iovw_equal(&a1, &b)); |
| 51 |
ASSERT_FALSE(iovw_equal(&b, &a1)); |
| 52 |
ASSERT_TRUE(iovw_equal(&b, &b)); |
| 53 |
ASSERT_FALSE(iovw_equal(&a1, &c)); |
| 54 |
ASSERT_FALSE(iovw_equal(&c, &a1)); |
| 55 |
ASSERT_TRUE(iovw_equal(&c, &c)); |
| 56 |
ASSERT_FALSE(iovw_equal(&a1, &d)); |
| 57 |
ASSERT_FALSE(iovw_equal(&d, &a1)); |
| 58 |
ASSERT_TRUE(iovw_equal(&d, &d)); |
| 59 |
ASSERT_FALSE(iovw_equal(&a1, &e)); |
| 60 |
ASSERT_FALSE(iovw_equal(&e, &a1)); |
| 61 |
ASSERT_TRUE(iovw_equal(&e, &e)); |
| 62 |
ASSERT_FALSE(iovw_equal(&a1, NULL)); |
| 63 |
ASSERT_FALSE(iovw_equal(NULL, &a1)); |
| 64 |
ASSERT_TRUE(iovw_equal(NULL, NULL)); |
| 65 |
} |
| 66 |
|
| 67 |
TEST(iovw_put) { |
| 68 |
_cleanup_(iovw_done) struct iovec_wrapper iovw = {}; |
| 69 |
|
| 70 |
/* Zero-length insertions are no-ops and do not touch the data pointer */ |
| 71 |
ASSERT_OK_ZERO(iovw_put(&iovw, NULL, 0)); |
| 72 |
ASSERT_OK_ZERO(iovw_put(&iovw, (char*) "foo", 0)); |
| 73 |
ASSERT_EQ(iovw.count, 0U); |
| 74 |
|
| 75 |
ASSERT_OK(iovw_put(&iovw, (char*) "foo", 3)); |
| 76 |
ASSERT_OK(iovw_put(&iovw, (char*) "barbar", 6)); |
| 77 |
ASSERT_OK(iovw_put(&iovw, (char*) "q", 1)); |
| 78 |
ASSERT_EQ(iovw.count, 3U); |
| 79 |
|
| 80 |
ASSERT_EQ(iovw.iovec[0].iov_len, 3U); |
| 81 |
ASSERT_EQ(memcmp(iovw.iovec[0].iov_base, "foo", 3), 0); |
| 82 |
ASSERT_EQ(iovw.iovec[1].iov_len, 6U); |
| 83 |
ASSERT_EQ(memcmp(iovw.iovec[1].iov_base, "barbar", 6), 0); |
| 84 |
ASSERT_EQ(iovw.iovec[2].iov_len, 1U); |
| 85 |
ASSERT_EQ(memcmp(iovw.iovec[2].iov_base, "q", 1), 0); |
| 86 |
|
| 87 |
ASSERT_OK(iovw_put_full(&iovw, /* accept_zero= */ false, NULL, 0)); |
| 88 |
ASSERT_EQ(iovw.count, 3U); |
| 89 |
ASSERT_OK(iovw_put_full(&iovw, /* accept_zero= */ true, NULL, 0)); |
| 90 |
ASSERT_EQ(iovw.count, 4U); |
| 91 |
ASSERT_TRUE(iovec_equal(&iovw.iovec[3], &(struct iovec) {})); |
| 92 |
} |
| 93 |
|
| 94 |
TEST(iovw_put_iov) { |
| 95 |
/* iovw_put_iov() does not copy the input, hence do not use iovw_done_free */ |
| 96 |
_cleanup_(iovw_done) struct iovec_wrapper iovw = {}; |
| 97 |
|
| 98 |
/* Appending an empty/NULL source is a no-op */ |
| 99 |
ASSERT_OK_ZERO(iovw_put_iov(&iovw, NULL)); |
| 100 |
ASSERT_OK_ZERO(iovw_put_iov(&iovw, &(struct iovec) {})); |
| 101 |
ASSERT_EQ(iovw.count, 0U); |
| 102 |
|
| 103 |
ASSERT_OK(iovw_put_iov(&iovw, &IOVEC_MAKE_STRING("aaa"))); |
| 104 |
ASSERT_OK(iovw_put_iov(&iovw, &IOVEC_MAKE_STRING("bbb"))); |
| 105 |
ASSERT_OK(iovw_put_iov(&iovw, &IOVEC_MAKE_STRING("ccc"))); |
| 106 |
ASSERT_EQ(iovw.count, 3U); |
| 107 |
ASSERT_TRUE(iovec_equal(&iovw.iovec[0], &IOVEC_MAKE_STRING("aaa"))); |
| 108 |
ASSERT_TRUE(iovec_equal(&iovw.iovec[1], &IOVEC_MAKE_STRING("bbb"))); |
| 109 |
ASSERT_TRUE(iovec_equal(&iovw.iovec[2], &IOVEC_MAKE_STRING("ccc"))); |
| 110 |
|
| 111 |
ASSERT_OK(iovw_put_iov_full(&iovw, /* accept_zero= */ false, &(struct iovec) {})); |
| 112 |
ASSERT_EQ(iovw.count, 3U); |
| 113 |
ASSERT_OK(iovw_put_iov_full(&iovw, /* accept_zero= */ true, &(struct iovec) {})); |
| 114 |
ASSERT_EQ(iovw.count, 4U); |
| 115 |
ASSERT_TRUE(iovec_equal(&iovw.iovec[3], &(struct iovec) {})); |
| 116 |
} |
| 117 |
|
| 118 |
TEST(iovw_put_iovw) { |
| 119 |
_cleanup_(iovw_done) struct iovec_wrapper target = {}, source = {}; |
| 120 |
|
| 121 |
/* Appending an empty/NULL source is a no-op */ |
| 122 |
ASSERT_OK_ZERO(iovw_put_iovw(&target, NULL)); |
| 123 |
ASSERT_OK_ZERO(iovw_put_iovw(&target, &source)); |
| 124 |
ASSERT_EQ(target.count, 0U); |
| 125 |
|
| 126 |
ASSERT_OK(iovw_put_iov(&source, &IOVEC_MAKE_STRING("aaa"))); |
| 127 |
ASSERT_OK(iovw_put_iov(&source, &IOVEC_MAKE_STRING("bbb"))); |
| 128 |
ASSERT_OK(iovw_put_iov(&source, &IOVEC_MAKE_STRING("ccc"))); |
| 129 |
ASSERT_OK(iovw_put_iov_full(&source, /* accept_zero= */ true, &(struct iovec) {})); |
| 130 |
ASSERT_EQ(source.count, 4U); |
| 131 |
|
| 132 |
/* Pre-seed target with one entry to check that append adds on top rather than replacing */ |
| 133 |
ASSERT_OK(iovw_put_iov(&target, &IOVEC_MAKE_STRING("xxx"))); |
| 134 |
ASSERT_OK(iovw_put_iov(&target, &IOVEC_MAKE_STRING("yyy"))); |
| 135 |
ASSERT_OK(iovw_put_iov(&target, &IOVEC_MAKE_STRING("zzz"))); |
| 136 |
ASSERT_EQ(target.count, 3U); |
| 137 |
|
| 138 |
ASSERT_OK(iovw_put_iovw(&target, &source)); |
| 139 |
ASSERT_EQ(target.count, 6U); |
| 140 |
ASSERT_TRUE(iovec_equal(&target.iovec[0], &IOVEC_MAKE_STRING("xxx"))); |
| 141 |
ASSERT_TRUE(iovec_equal(&target.iovec[1], &IOVEC_MAKE_STRING("yyy"))); |
| 142 |
ASSERT_TRUE(iovec_equal(&target.iovec[2], &IOVEC_MAKE_STRING("zzz"))); |
| 143 |
ASSERT_TRUE(iovec_equal(&target.iovec[3], &IOVEC_MAKE_STRING("aaa"))); |
| 144 |
ASSERT_TRUE(iovec_equal(&target.iovec[4], &IOVEC_MAKE_STRING("bbb"))); |
| 145 |
ASSERT_TRUE(iovec_equal(&target.iovec[5], &IOVEC_MAKE_STRING("ccc"))); |
| 146 |
|
| 147 |
/* iovw_put_iovw() does not copy data, hence the pointers must be equal */ |
| 148 |
ASSERT_PTR_EQ(target.iovec[3].iov_base, source.iovec[0].iov_base); |
| 149 |
ASSERT_PTR_EQ(target.iovec[4].iov_base, source.iovec[1].iov_base); |
| 150 |
ASSERT_PTR_EQ(target.iovec[5].iov_base, source.iovec[2].iov_base); |
| 151 |
|
| 152 |
/* Source is unchanged */ |
| 153 |
ASSERT_EQ(source.count, 4U); |
| 154 |
ASSERT_TRUE(iovec_equal(&source.iovec[0], &IOVEC_MAKE_STRING("aaa"))); |
| 155 |
ASSERT_TRUE(iovec_equal(&source.iovec[1], &IOVEC_MAKE_STRING("bbb"))); |
| 156 |
ASSERT_TRUE(iovec_equal(&source.iovec[2], &IOVEC_MAKE_STRING("ccc"))); |
| 157 |
ASSERT_TRUE(iovec_equal(&source.iovec[3], &(struct iovec) {})); |
| 158 |
|
| 159 |
ASSERT_OK(iovw_put_iovw_full(&target, /* accept_zero= */ true, &source)); |
| 160 |
ASSERT_EQ(target.count, 10U); |
| 161 |
ASSERT_TRUE(iovec_equal(&target.iovec[0], &IOVEC_MAKE_STRING("xxx"))); |
| 162 |
ASSERT_TRUE(iovec_equal(&target.iovec[1], &IOVEC_MAKE_STRING("yyy"))); |
| 163 |
ASSERT_TRUE(iovec_equal(&target.iovec[2], &IOVEC_MAKE_STRING("zzz"))); |
| 164 |
ASSERT_TRUE(iovec_equal(&target.iovec[3], &IOVEC_MAKE_STRING("aaa"))); |
| 165 |
ASSERT_TRUE(iovec_equal(&target.iovec[4], &IOVEC_MAKE_STRING("bbb"))); |
| 166 |
ASSERT_TRUE(iovec_equal(&target.iovec[5], &IOVEC_MAKE_STRING("ccc"))); |
| 167 |
ASSERT_TRUE(iovec_equal(&target.iovec[6], &IOVEC_MAKE_STRING("aaa"))); |
| 168 |
ASSERT_TRUE(iovec_equal(&target.iovec[7], &IOVEC_MAKE_STRING("bbb"))); |
| 169 |
ASSERT_TRUE(iovec_equal(&target.iovec[8], &IOVEC_MAKE_STRING("ccc"))); |
| 170 |
ASSERT_TRUE(iovec_equal(&target.iovec[9], &(struct iovec) {})); |
| 171 |
|
| 172 |
/* Cannot pass the same objects */ |
| 173 |
ASSERT_ERROR(iovw_put_iovw(&target, &target), EINVAL); |
| 174 |
} |
| 175 |
|
| 176 |
TEST(iovw_extend) { |
| 177 |
_cleanup_(iovw_done_free) struct iovec_wrapper iovw = {}; |
| 178 |
|
| 179 |
/* Appending an empty/NULL source is a no-op */ |
| 180 |
ASSERT_OK_ZERO(iovw_extend(&iovw, NULL, 0)); |
| 181 |
ASSERT_OK_ZERO(iovw_extend(&iovw, "foo", 0)); |
| 182 |
ASSERT_EQ(iovw.count, 0U); |
| 183 |
|
| 184 |
/* iovw_extend() copies the data; the wrapper owns the copies. */ |
| 185 |
char buf[4] = { 'o', 'n', 'e', '\0' }; |
| 186 |
ASSERT_OK(iovw_extend(&iovw, buf, 3)); |
| 187 |
ASSERT_EQ(iovw.count, 1U); |
| 188 |
ASSERT_EQ(iovw.iovec[0].iov_len, 3U); |
| 189 |
ASSERT_EQ(memcmp(iovw.iovec[0].iov_base, "one", 3), 0); |
| 190 |
|
| 191 |
/* Insert with a NUL */ |
| 192 |
ASSERT_OK(iovw_extend(&iovw, buf, 4)); |
| 193 |
ASSERT_EQ(iovw.count, 2U); |
| 194 |
ASSERT_EQ(iovw.iovec[1].iov_len, 4U); |
| 195 |
ASSERT_EQ(memcmp(iovw.iovec[1].iov_base, "one\0", 4), 0); |
| 196 |
|
| 197 |
/* Mutating the caller's buffer does not affect what's stored */ |
| 198 |
memset(buf, 'X', sizeof buf); |
| 199 |
ASSERT_EQ(memcmp(iovw.iovec[0].iov_base, "one", 3), 0); |
| 200 |
|
| 201 |
ASSERT_OK(iovw_extend_full(&iovw, /* accept_zero= */ false, NULL, 0)); |
| 202 |
ASSERT_EQ(iovw.count, 2U); |
| 203 |
ASSERT_OK(iovw_extend_full(&iovw, /* accept_zero= */ true, NULL, 0)); |
| 204 |
ASSERT_EQ(iovw.count, 3U); |
| 205 |
ASSERT_TRUE(iovec_equal(&iovw.iovec[2], &(struct iovec) {})); |
| 206 |
} |
| 207 |
|
| 208 |
TEST(iovw_extend_iov) { |
| 209 |
_cleanup_(iovw_done_free) struct iovec_wrapper iovw = {}; |
| 210 |
|
| 211 |
/* Appending an empty/NULL source is a no-op */ |
| 212 |
ASSERT_OK_ZERO(iovw_extend_iov(&iovw, NULL)); |
| 213 |
ASSERT_OK_ZERO(iovw_extend_iov(&iovw, &(struct iovec) {})); |
| 214 |
ASSERT_EQ(iovw.count, 0U); |
| 215 |
|
| 216 |
ASSERT_OK(iovw_extend_iov(&iovw, &IOVEC_MAKE_STRING("aaa"))); |
| 217 |
ASSERT_OK(iovw_extend_iov(&iovw, &IOVEC_MAKE_STRING("bbb"))); |
| 218 |
ASSERT_OK(iovw_extend_iov(&iovw, &IOVEC_MAKE_STRING("ccc"))); |
| 219 |
ASSERT_EQ(iovw.count, 3U); |
| 220 |
ASSERT_TRUE(iovec_equal(&iovw.iovec[0], &IOVEC_MAKE_STRING("aaa"))); |
| 221 |
ASSERT_TRUE(iovec_equal(&iovw.iovec[1], &IOVEC_MAKE_STRING("bbb"))); |
| 222 |
ASSERT_TRUE(iovec_equal(&iovw.iovec[2], &IOVEC_MAKE_STRING("ccc"))); |
| 223 |
|
| 224 |
ASSERT_OK(iovw_extend_iov_full(&iovw, /* accept_zero= */ false, &(struct iovec) {})); |
| 225 |
ASSERT_EQ(iovw.count, 3U); |
| 226 |
ASSERT_OK(iovw_extend_iov_full(&iovw, /* accept_zero= */ true, &(struct iovec) {})); |
| 227 |
ASSERT_EQ(iovw.count, 4U); |
| 228 |
ASSERT_TRUE(iovec_equal(&iovw.iovec[3], &(struct iovec) {})); |
| 229 |
} |
| 230 |
|
| 231 |
TEST(iovw_extend_iovw) { |
| 232 |
_cleanup_(iovw_done_free) struct iovec_wrapper target = {}; |
| 233 |
_cleanup_(iovw_done) struct iovec_wrapper source = {}; |
| 234 |
|
| 235 |
/* Appending an empty/NULL source is a no-op */ |
| 236 |
ASSERT_OK_ZERO(iovw_extend_iovw(&target, NULL)); |
| 237 |
ASSERT_OK_ZERO(iovw_extend_iovw(&target, &source)); |
| 238 |
ASSERT_EQ(target.count, 0U); |
| 239 |
|
| 240 |
ASSERT_OK(iovw_put(&source, (char*) "one", 3)); |
| 241 |
ASSERT_OK(iovw_put(&source, (char*) "twotwo", 6)); |
| 242 |
ASSERT_OK(iovw_put_full(&source, /* accept_zero= */ true, NULL, 0)); |
| 243 |
ASSERT_EQ(source.count, 3U); |
| 244 |
|
| 245 |
/* Pre-seed target with one entry to check that append adds on top rather than replacing */ |
| 246 |
char *seed = strdup("zero"); |
| 247 |
ASSERT_NOT_NULL(seed); |
| 248 |
ASSERT_OK(iovw_put(&target, seed, strlen(seed))); |
| 249 |
|
| 250 |
ASSERT_OK(iovw_extend_iovw(&target, &source)); |
| 251 |
ASSERT_EQ(target.count, 3U); |
| 252 |
|
| 253 |
/* Appended entries must be fresh copies, not aliases of the source entries */ |
| 254 |
ASSERT_TRUE(target.iovec[1].iov_base != source.iovec[0].iov_base); |
| 255 |
ASSERT_TRUE(target.iovec[2].iov_base != source.iovec[1].iov_base); |
| 256 |
|
| 257 |
ASSERT_EQ(target.iovec[1].iov_len, 3U); |
| 258 |
ASSERT_EQ(memcmp(target.iovec[1].iov_base, "one", 3), 0); |
| 259 |
ASSERT_EQ(target.iovec[2].iov_len, 6U); |
| 260 |
ASSERT_EQ(memcmp(target.iovec[2].iov_base, "twotwo", 6), 0); |
| 261 |
|
| 262 |
ASSERT_OK(iovw_extend_iovw_full(&target, /* accept_zero= */ true, &source)); |
| 263 |
ASSERT_EQ(target.count, 6U); |
| 264 |
ASSERT_TRUE(iovec_equal(&target.iovec[0], &IOVEC_MAKE_STRING("zero"))); |
| 265 |
ASSERT_TRUE(iovec_equal(&target.iovec[1], &IOVEC_MAKE_STRING("one"))); |
| 266 |
ASSERT_TRUE(iovec_equal(&target.iovec[2], &IOVEC_MAKE_STRING("twotwo"))); |
| 267 |
ASSERT_TRUE(iovec_equal(&target.iovec[3], &IOVEC_MAKE_STRING("one"))); |
| 268 |
ASSERT_TRUE(iovec_equal(&target.iovec[4], &IOVEC_MAKE_STRING("twotwo"))); |
| 269 |
ASSERT_TRUE(iovec_equal(&target.iovec[5], &(struct iovec) {})); |
| 270 |
|
| 271 |
/* Source is unchanged */ |
| 272 |
ASSERT_EQ(source.count, 3U); |
| 273 |
|
| 274 |
/* Cannot pass the same objects */ |
| 275 |
ASSERT_ERROR(iovw_extend_iovw(&target, &target), EINVAL); |
| 276 |
} |
| 277 |
|
| 278 |
TEST(iovw_consume) { |
| 279 |
_cleanup_(iovw_done_free) struct iovec_wrapper iovw = {}; |
| 280 |
|
| 281 |
char *p = strdup("consumed"); |
| 282 |
ASSERT_NOT_NULL(p); |
| 283 |
ASSERT_OK(iovw_consume(&iovw, p, strlen(p))); |
| 284 |
ASSERT_EQ(iovw.count, 1U); |
| 285 |
/* iovw_consume moves ownership in place, no copy */ |
| 286 |
ASSERT_PTR_EQ(iovw.iovec[0].iov_base, p); |
| 287 |
|
| 288 |
/* Zero-length: iovw_put returns 0 without adding anything. Even in that case, iovw_consume() frees |
| 289 |
* the payload. Confirm by strdup'ing something to verify that when running with sanitizer/valgrind. */ |
| 290 |
char *q = ASSERT_NOT_NULL(strdup("")); |
| 291 |
ASSERT_OK_ZERO(iovw_consume(&iovw, q, 0)); |
| 292 |
ASSERT_EQ(iovw.count, 1U); |
| 293 |
|
| 294 |
ASSERT_OK(iovw_consume_full(&iovw, /* accept_zero= */ false, NULL, 0)); |
| 295 |
ASSERT_EQ(iovw.count, 1U); |
| 296 |
ASSERT_OK(iovw_consume_full(&iovw, /* accept_zero= */ true, NULL, 0)); |
| 297 |
ASSERT_EQ(iovw.count, 2U); |
| 298 |
ASSERT_TRUE(iovec_equal(&iovw.iovec[1], &(struct iovec) {})); |
| 299 |
q = ASSERT_NOT_NULL(strdup("")); |
| 300 |
ASSERT_OK(iovw_consume_full(&iovw, /* accept_zero= */ true, q, 0)); |
| 301 |
ASSERT_EQ(iovw.count, 3U); |
| 302 |
ASSERT_TRUE(iovec_equal(&iovw.iovec[2], &(struct iovec) {})); |
| 303 |
} |
| 304 |
|
| 305 |
TEST(iovw_consume_iov) { |
| 306 |
_cleanup_(iovw_done_free) struct iovec_wrapper iovw = {}; |
| 307 |
|
| 308 |
ASSERT_OK_ZERO(iovw_consume_iov(&iovw, NULL)); |
| 309 |
ASSERT_EQ(iovw.count, 0U); |
| 310 |
|
| 311 |
ASSERT_OK_ZERO(iovw_consume_iov(&iovw, &(struct iovec) {})); |
| 312 |
ASSERT_EQ(iovw.count, 0U); |
| 313 |
|
| 314 |
struct iovec iov = { |
| 315 |
.iov_base = ASSERT_NOT_NULL(strdup("consumed")), |
| 316 |
.iov_len = strlen("consumed"), |
| 317 |
}; |
| 318 |
ASSERT_OK(iovw_consume_iov(&iovw, &iov)); |
| 319 |
ASSERT_EQ(iovw.count, 1U); |
| 320 |
/* iovw_consume_iov takes the ownership of the buffer, and emptifies the iovec. */ |
| 321 |
ASSERT_NULL(iov.iov_base); |
| 322 |
ASSERT_EQ(iov.iov_len, 0U); |
| 323 |
|
| 324 |
iov = (struct iovec) { |
| 325 |
.iov_base = ASSERT_NOT_NULL(strdup("")), |
| 326 |
.iov_len = 0, |
| 327 |
}; |
| 328 |
ASSERT_OK_ZERO(iovw_consume_iov(&iovw, &iov)); |
| 329 |
ASSERT_EQ(iovw.count, 1U); |
| 330 |
/* zero length iovec is also freed */ |
| 331 |
ASSERT_NULL(iov.iov_base); |
| 332 |
ASSERT_EQ(iov.iov_len, 0U); |
| 333 |
|
| 334 |
ASSERT_OK(iovw_consume_iov_full(&iovw, /* accept_zero= */ false, &(struct iovec) {})); |
| 335 |
ASSERT_EQ(iovw.count, 1U); |
| 336 |
ASSERT_OK(iovw_consume_iov_full(&iovw, /* accept_zero= */ true, &(struct iovec) {})); |
| 337 |
ASSERT_EQ(iovw.count, 2U); |
| 338 |
ASSERT_TRUE(iovec_equal(&iovw.iovec[1], &(struct iovec) {})); |
| 339 |
iov = (struct iovec) { |
| 340 |
.iov_base = ASSERT_NOT_NULL(strdup("")), |
| 341 |
.iov_len = 0, |
| 342 |
}; |
| 343 |
ASSERT_OK(iovw_consume_iov_full(&iovw, /* accept_zero= */ true, &iov)); |
| 344 |
ASSERT_EQ(iovw.count, 3U); |
| 345 |
ASSERT_TRUE(iovec_equal(&iovw.iovec[2], &(struct iovec) {})); |
| 346 |
} |
| 347 |
|
| 348 |
TEST(iovw_isempty) { |
| 349 |
ASSERT_TRUE(iovw_isempty(NULL)); |
| 350 |
|
| 351 |
_cleanup_(iovw_done) struct iovec_wrapper iovw = {}; |
| 352 |
ASSERT_TRUE(iovw_isempty(&iovw)); |
| 353 |
|
| 354 |
ASSERT_OK(iovw_put(&iovw, (char*) "x", 1)); |
| 355 |
ASSERT_FALSE(iovw_isempty(&iovw)); |
| 356 |
} |
| 357 |
|
| 358 |
TEST(iovw_put_string_field) { |
| 359 |
_cleanup_(iovw_done_free) struct iovec_wrapper iovw = {}; |
| 360 |
|
| 361 |
ASSERT_OK(iovw_put_string_field(&iovw, "FOO=", "bar")); |
| 362 |
ASSERT_OK(iovw_put_string_field(&iovw, "BAZ=", "quux")); |
| 363 |
ASSERT_EQ(iovw.count, 2U); |
| 364 |
|
| 365 |
ASSERT_EQ(iovw.iovec[0].iov_len, strlen("FOO=bar")); |
| 366 |
ASSERT_EQ(memcmp(iovw.iovec[0].iov_base, "FOO=bar", strlen("FOO=bar")), 0); |
| 367 |
ASSERT_EQ(iovw.iovec[1].iov_len, strlen("BAZ=quux")); |
| 368 |
ASSERT_EQ(memcmp(iovw.iovec[1].iov_base, "BAZ=quux", strlen("BAZ=quux")), 0); |
| 369 |
|
| 370 |
/* Non-replacing put: a second FOO= just appends rather than replacing */ |
| 371 |
ASSERT_OK(iovw_put_string_field(&iovw, "FOO=", "second")); |
| 372 |
ASSERT_EQ(iovw.count, 3U); |
| 373 |
ASSERT_EQ(iovw.iovec[0].iov_len, strlen("FOO=bar")); |
| 374 |
ASSERT_EQ(memcmp(iovw.iovec[0].iov_base, "FOO=bar", strlen("FOO=bar")), 0); |
| 375 |
ASSERT_EQ(iovw.iovec[2].iov_len, strlen("FOO=second")); |
| 376 |
ASSERT_EQ(memcmp(iovw.iovec[2].iov_base, "FOO=second", strlen("FOO=second")), 0); |
| 377 |
} |
| 378 |
|
| 379 |
TEST(iovw_replace_string_field) { |
| 380 |
_cleanup_(iovw_done_free) struct iovec_wrapper iovw = {}; |
| 381 |
|
| 382 |
/* If the field does not exist yet, replace acts like put */ |
| 383 |
ASSERT_OK(iovw_replace_string_field(&iovw, "A=", "1")); |
| 384 |
ASSERT_EQ(iovw.count, 1U); |
| 385 |
ASSERT_EQ(iovw.iovec[0].iov_len, strlen("A=1")); |
| 386 |
ASSERT_EQ(memcmp(iovw.iovec[0].iov_base, "A=1", strlen("A=1")), 0); |
| 387 |
|
| 388 |
/* Replacing an existing field updates it in place */ |
| 389 |
ASSERT_OK(iovw_replace_string_field(&iovw, "A=", "twentytwo")); |
| 390 |
ASSERT_EQ(iovw.count, 1U); |
| 391 |
ASSERT_EQ(iovw.iovec[0].iov_len, strlen("A=twentytwo")); |
| 392 |
ASSERT_EQ(memcmp(iovw.iovec[0].iov_base, "A=twentytwo", strlen("A=twentytwo")), 0); |
| 393 |
|
| 394 |
/* Distinct field still appends */ |
| 395 |
ASSERT_OK(iovw_replace_string_field(&iovw, "B=", "x")); |
| 396 |
ASSERT_EQ(iovw.count, 2U); |
| 397 |
} |
| 398 |
|
| 399 |
TEST(iovw_put_string_fieldf) { |
| 400 |
_cleanup_(iovw_done_free) struct iovec_wrapper iovw = {}; |
| 401 |
|
| 402 |
ASSERT_OK(iovw_put_string_fieldf(&iovw, "N=", "%d-%s", 42, "answer")); |
| 403 |
ASSERT_EQ(iovw.count, 1U); |
| 404 |
ASSERT_EQ(iovw.iovec[0].iov_len, strlen("N=42-answer")); |
| 405 |
ASSERT_EQ(memcmp(iovw.iovec[0].iov_base, "N=42-answer", strlen("N=42-answer")), 0); |
| 406 |
|
| 407 |
/* Replacing variant */ |
| 408 |
ASSERT_OK(iovw_replace_string_fieldf(&iovw, "N=", "%d", 7)); |
| 409 |
ASSERT_EQ(iovw.count, 1U); |
| 410 |
ASSERT_EQ(iovw.iovec[0].iov_len, strlen("N=7")); |
| 411 |
ASSERT_EQ(memcmp(iovw.iovec[0].iov_base, "N=7", strlen("N=7")), 0); |
| 412 |
} |
| 413 |
|
| 414 |
TEST(iovw_put_string_field_free) { |
| 415 |
_cleanup_(iovw_done_free) struct iovec_wrapper iovw = {}; |
| 416 |
|
| 417 |
/* iovw_put_string_field_free takes ownership of the value string (frees it on return). */ |
| 418 |
char *v = strdup("hello"); |
| 419 |
ASSERT_NOT_NULL(v); |
| 420 |
ASSERT_OK(iovw_put_string_field_free(&iovw, "K=", v)); |
| 421 |
ASSERT_EQ(iovw.count, 1U); |
| 422 |
ASSERT_EQ(iovw.iovec[0].iov_len, strlen("K=hello")); |
| 423 |
ASSERT_EQ(memcmp(iovw.iovec[0].iov_base, "K=hello", strlen("K=hello")), 0); |
| 424 |
} |
| 425 |
|
| 426 |
TEST(iovw_rebase) { |
| 427 |
/* iovw_rebase shifts all iov_base pointers from an old base to a new base. Fabricate a |
| 428 |
* stand-in "old base" and "new base" and a wrapper with offsets pointing into the old |
| 429 |
* base, then verify they get rewritten to point into the new base. */ |
| 430 |
|
| 431 |
uint8_t old_base[64] = {}, new_base[64] = {}; |
| 432 |
for (size_t i = 0; i < sizeof old_base; i++) { |
| 433 |
old_base[i] = (uint8_t) i; |
| 434 |
new_base[i] = (uint8_t) (100 + i); |
| 435 |
} |
| 436 |
|
| 437 |
_cleanup_(iovw_done) struct iovec_wrapper iovw = {}; |
| 438 |
|
| 439 |
ASSERT_OK(iovw_put(&iovw, old_base + 0, 4)); |
| 440 |
ASSERT_OK(iovw_put(&iovw, old_base + 10, 2)); |
| 441 |
ASSERT_OK(iovw_put(&iovw, old_base + 30, 8)); |
| 442 |
ASSERT_EQ(iovw.count, 3U); |
| 443 |
|
| 444 |
iovw_rebase(&iovw, old_base, new_base); |
| 445 |
|
| 446 |
ASSERT_PTR_EQ(iovw.iovec[0].iov_base, new_base + 0); |
| 447 |
ASSERT_PTR_EQ(iovw.iovec[1].iov_base, new_base + 10); |
| 448 |
ASSERT_PTR_EQ(iovw.iovec[2].iov_base, new_base + 30); |
| 449 |
|
| 450 |
/* Lengths are preserved */ |
| 451 |
ASSERT_EQ(iovw.iovec[0].iov_len, 4U); |
| 452 |
ASSERT_EQ(iovw.iovec[1].iov_len, 2U); |
| 453 |
ASSERT_EQ(iovw.iovec[2].iov_len, 8U); |
| 454 |
|
| 455 |
/* And the contents through the new base match what we staged there */ |
| 456 |
ASSERT_EQ(memcmp(iovw.iovec[0].iov_base, new_base + 0, 4), 0); |
| 457 |
ASSERT_EQ(memcmp(iovw.iovec[1].iov_base, new_base + 10, 2), 0); |
| 458 |
ASSERT_EQ(memcmp(iovw.iovec[2].iov_base, new_base + 30, 8), 0); |
| 459 |
} |
| 460 |
|
| 461 |
TEST(iovw_size) { |
| 462 |
_cleanup_(iovw_done) struct iovec_wrapper iovw = {}; |
| 463 |
ASSERT_EQ(iovw_size(&iovw), 0U); |
| 464 |
|
| 465 |
ASSERT_OK(iovw_put(&iovw, (char*) "abcd", 4)); |
| 466 |
ASSERT_OK(iovw_put(&iovw, (char*) "efghij", 6)); |
| 467 |
ASSERT_OK(iovw_put(&iovw, (char*) "kl", 2)); |
| 468 |
ASSERT_EQ(iovw_size(&iovw), 12U); |
| 469 |
|
| 470 |
ASSERT_EQ(iovw_size(NULL), 0U); |
| 471 |
} |
| 472 |
|
| 473 |
TEST(iovw_concat) { |
| 474 |
_cleanup_(iovw_done) struct iovec_wrapper iovw = {}; |
| 475 |
|
| 476 |
/* Empty wrapper -> empty string with 0 length */ |
| 477 |
_cleanup_(iovec_done) struct iovec iov = {}; |
| 478 |
ASSERT_OK(iovw_concat(&iovw, &iov)); |
| 479 |
ASSERT_FALSE(iovec_is_set(&iov)); |
| 480 |
ASSERT_STREQ(iov.iov_base, ""); |
| 481 |
iovec_done(&iov); |
| 482 |
|
| 483 |
ASSERT_OK(iovw_put(&iovw, (char*) "foo", 3)); |
| 484 |
ASSERT_OK(iovw_put(&iovw, (char*) "\0", 1)); |
| 485 |
ASSERT_OK(iovw_put(&iovw, (char*) "bar", 4)); |
| 486 |
|
| 487 |
ASSERT_OK(iovw_concat(&iovw, &iov)); |
| 488 |
ASSERT_TRUE(iovec_equal(&iov, &IOVEC_MAKE("foo\0bar\0", 8))); |
| 489 |
} |
| 490 |
|
| 491 |
TEST(iovw_to_cstring) { |
| 492 |
_cleanup_(iovw_done) struct iovec_wrapper iovw = {}; |
| 493 |
_cleanup_free_ char *s; |
| 494 |
|
| 495 |
/* Empty wrapper → empty string */ |
| 496 |
s = iovw_to_cstring(&iovw); |
| 497 |
ASSERT_NOT_NULL(s); |
| 498 |
ASSERT_STREQ(s, ""); |
| 499 |
s = mfree(s); |
| 500 |
|
| 501 |
ASSERT_OK(iovw_put(&iovw, (char*) "foo", 3)); |
| 502 |
ASSERT_OK(iovw_put(&iovw, (char*) "/", 1)); |
| 503 |
ASSERT_OK(iovw_put(&iovw, (char*) "bar", 3)); |
| 504 |
|
| 505 |
s = iovw_to_cstring(&iovw); |
| 506 |
ASSERT_NOT_NULL(s); |
| 507 |
ASSERT_STREQ(s, "foo/bar"); |
| 508 |
} |
| 509 |
|
| 510 |
TEST(iovw_merge_and_iovec_split) { |
| 511 |
_cleanup_(iovw_done_free) struct iovec_wrapper iovw = {}, iovw2 = {}; |
| 512 |
_cleanup_(iovec_done) struct iovec v = {}, v2 = {}; |
| 513 |
uint8_t *p; |
| 514 |
|
| 515 |
struct iovec |
| 516 |
a = IOVEC_MAKE_STRING("aaa"), |
| 517 |
b = IOVEC_MAKE_STRING("bbbb"), |
| 518 |
c = IOVEC_MAKE_STRING("ccccc"); |
| 519 |
|
| 520 |
/* single entry */ |
| 521 |
ASSERT_OK(iovw_extend_iov(&iovw, &a)); |
| 522 |
|
| 523 |
ASSERT_OK(iovw_merge(&iovw, sizeof(uint8_t), &v)); |
| 524 |
ASSERT_EQ(v.iov_len, 1 + a.iov_len); |
| 525 |
p = ASSERT_NOT_NULL(v.iov_base); |
| 526 |
ASSERT_EQ(*p++, a.iov_len); |
| 527 |
ASSERT_EQ(memcmp(p, a.iov_base, a.iov_len), 0); |
| 528 |
p += a.iov_len; |
| 529 |
ASSERT_OK(iovec_split(&v, sizeof(uint8_t), &iovw2)); |
| 530 |
ASSERT_TRUE(iovw_equal(&iovw, &iovw2)); |
| 531 |
|
| 532 |
iovec_done(&v); |
| 533 |
iovw_done_free(&iovw2); |
| 534 |
|
| 535 |
ASSERT_OK(iovw_merge(&iovw, sizeof(uint16_t), &v)); |
| 536 |
ASSERT_EQ(v.iov_len, sizeof(uint16_t) + a.iov_len); |
| 537 |
p = ASSERT_NOT_NULL(v.iov_base); |
| 538 |
ASSERT_EQ(*p++, 0); |
| 539 |
ASSERT_EQ(*p++, a.iov_len); |
| 540 |
ASSERT_EQ(memcmp(p, a.iov_base, a.iov_len), 0); |
| 541 |
p += a.iov_len; |
| 542 |
ASSERT_OK(iovec_split(&v, sizeof(uint16_t), &iovw2)); |
| 543 |
ASSERT_TRUE(iovw_equal(&iovw, &iovw2)); |
| 544 |
|
| 545 |
iovec_done(&v); |
| 546 |
iovw_done_free(&iovw2); |
| 547 |
|
| 548 |
ASSERT_OK(iovw_merge(&iovw, sizeof(uint32_t), &v)); |
| 549 |
ASSERT_EQ(v.iov_len, sizeof(uint32_t) + a.iov_len); |
| 550 |
p = ASSERT_NOT_NULL(v.iov_base); |
| 551 |
ASSERT_EQ(*p++, 0); |
| 552 |
ASSERT_EQ(*p++, 0); |
| 553 |
ASSERT_EQ(*p++, 0); |
| 554 |
ASSERT_EQ(*p++, a.iov_len); |
| 555 |
ASSERT_EQ(memcmp(p, a.iov_base, a.iov_len), 0); |
| 556 |
p += a.iov_len; |
| 557 |
ASSERT_OK(iovec_split(&v, sizeof(uint32_t), &iovw2)); |
| 558 |
ASSERT_TRUE(iovw_equal(&iovw, &iovw2)); |
| 559 |
|
| 560 |
iovec_done(&v); |
| 561 |
iovw_done_free(&iovw2); |
| 562 |
|
| 563 |
/* multiple entries */ |
| 564 |
ASSERT_OK(iovw_extend_iov(&iovw, &b)); |
| 565 |
ASSERT_OK(iovw_extend_iov(&iovw, &c)); |
| 566 |
|
| 567 |
ASSERT_OK(iovw_merge(&iovw, sizeof(uint8_t), &v)); |
| 568 |
ASSERT_EQ(v.iov_len, 3 + a.iov_len + b.iov_len + c.iov_len); |
| 569 |
p = ASSERT_NOT_NULL(v.iov_base); |
| 570 |
ASSERT_EQ(*p++, a.iov_len); |
| 571 |
ASSERT_EQ(memcmp(p, a.iov_base, a.iov_len), 0); |
| 572 |
p += a.iov_len; |
| 573 |
ASSERT_EQ(*p++, b.iov_len); |
| 574 |
ASSERT_EQ(memcmp(p, b.iov_base, b.iov_len), 0); |
| 575 |
p += b.iov_len; |
| 576 |
ASSERT_EQ(*p++, c.iov_len); |
| 577 |
ASSERT_EQ(memcmp(p, c.iov_base, c.iov_len), 0); |
| 578 |
ASSERT_OK(iovec_split(&v, sizeof(uint8_t), &iovw2)); |
| 579 |
ASSERT_TRUE(iovw_equal(&iovw, &iovw2)); |
| 580 |
|
| 581 |
iovec_done(&v); |
| 582 |
iovw_done_free(&iovw2); |
| 583 |
|
| 584 |
ASSERT_OK(iovw_merge(&iovw, sizeof(uint16_t), &v)); |
| 585 |
ASSERT_EQ(v.iov_len, 3 * sizeof(uint16_t) + a.iov_len + b.iov_len + c.iov_len); |
| 586 |
p = ASSERT_NOT_NULL(v.iov_base); |
| 587 |
ASSERT_EQ(*p++, 0); |
| 588 |
ASSERT_EQ(*p++, a.iov_len); |
| 589 |
ASSERT_EQ(memcmp(p, a.iov_base, a.iov_len), 0); |
| 590 |
p += a.iov_len; |
| 591 |
ASSERT_EQ(*p++, 0); |
| 592 |
ASSERT_EQ(*p++, b.iov_len); |
| 593 |
ASSERT_EQ(memcmp(p, b.iov_base, b.iov_len), 0); |
| 594 |
p += b.iov_len; |
| 595 |
ASSERT_EQ(*p++, 0); |
| 596 |
ASSERT_EQ(*p++, c.iov_len); |
| 597 |
ASSERT_EQ(memcmp(p, c.iov_base, c.iov_len), 0); |
| 598 |
ASSERT_OK(iovec_split(&v, sizeof(uint16_t), &iovw2)); |
| 599 |
ASSERT_TRUE(iovw_equal(&iovw, &iovw2)); |
| 600 |
|
| 601 |
iovec_done(&v); |
| 602 |
iovw_done_free(&iovw2); |
| 603 |
|
| 604 |
ASSERT_OK(iovw_merge(&iovw, sizeof(uint32_t), &v)); |
| 605 |
ASSERT_EQ(v.iov_len, 3 * sizeof(uint32_t) + a.iov_len + b.iov_len + c.iov_len); |
| 606 |
p = ASSERT_NOT_NULL(v.iov_base); |
| 607 |
ASSERT_EQ(*p++, 0); |
| 608 |
ASSERT_EQ(*p++, 0); |
| 609 |
ASSERT_EQ(*p++, 0); |
| 610 |
ASSERT_EQ(*p++, a.iov_len); |
| 611 |
ASSERT_EQ(memcmp(p, a.iov_base, a.iov_len), 0); |
| 612 |
p += a.iov_len; |
| 613 |
ASSERT_EQ(*p++, 0); |
| 614 |
ASSERT_EQ(*p++, 0); |
| 615 |
ASSERT_EQ(*p++, 0); |
| 616 |
ASSERT_EQ(*p++, b.iov_len); |
| 617 |
ASSERT_EQ(memcmp(p, b.iov_base, b.iov_len), 0); |
| 618 |
p += b.iov_len; |
| 619 |
ASSERT_EQ(*p++, 0); |
| 620 |
ASSERT_EQ(*p++, 0); |
| 621 |
ASSERT_EQ(*p++, 0); |
| 622 |
ASSERT_EQ(*p++, c.iov_len); |
| 623 |
ASSERT_EQ(memcmp(p, c.iov_base, c.iov_len), 0); |
| 624 |
ASSERT_OK(iovec_split(&v, sizeof(uint32_t), &iovw2)); |
| 625 |
ASSERT_TRUE(iovw_equal(&iovw, &iovw2)); |
| 626 |
|
| 627 |
iovec_done(&v); |
| 628 |
iovw_done_free(&iovw2); |
| 629 |
|
| 630 |
/* with empty entries */ |
| 631 |
_cleanup_(iovw_done) struct iovec_wrapper with_empty = { |
| 632 |
.iovec = ASSERT_PTR(new0(struct iovec, 6)), |
| 633 |
.count = 6, |
| 634 |
}; |
| 635 |
with_empty.iovec[0] = a; |
| 636 |
with_empty.iovec[2] = b; |
| 637 |
with_empty.iovec[4] = c; |
| 638 |
ASSERT_OK(iovw_merge(&iovw, sizeof(uint8_t), &v)); |
| 639 |
ASSERT_OK(iovw_merge(&with_empty, sizeof(uint8_t), &v2)); |
| 640 |
ASSERT_TRUE(iovec_equal(&v, &v2)); |
| 641 |
|
| 642 |
iovec_done(&v); |
| 643 |
iovec_done(&v2); |
| 644 |
|
| 645 |
size_t sz = 6 + a.iov_len + b.iov_len + c.iov_len; |
| 646 |
_cleanup_free_ uint8_t *buf = ASSERT_PTR(new(uint8_t, sz)); |
| 647 |
p = buf; |
| 648 |
*p++ = a.iov_len; |
| 649 |
p = mempcpy(p, a.iov_base, a.iov_len); |
| 650 |
*p++ = 0; |
| 651 |
*p++ = b.iov_len; |
| 652 |
p = mempcpy(p, b.iov_base, b.iov_len); |
| 653 |
*p++ = 0; |
| 654 |
*p++ = c.iov_len; |
| 655 |
p = mempcpy(p, c.iov_base, c.iov_len); |
| 656 |
*p++ = 0; |
| 657 |
ASSERT_OK(iovec_split(&IOVEC_MAKE(buf, sz), sizeof(uint8_t), &iovw2)); |
| 658 |
ASSERT_TRUE(iovw_equal(&iovw, &iovw2)); |
| 659 |
|
| 660 |
iovw_done_free(&iovw2); |
| 661 |
|
| 662 |
/* truncated */ |
| 663 |
ASSERT_OK(iovw_merge(&iovw, sizeof(uint8_t), &v)); |
| 664 |
ASSERT_ERROR(iovec_split(&IOVEC_MAKE(v.iov_base, v.iov_len - 1), sizeof(uint8_t), &iovw2), EBADMSG); |
| 665 |
|
| 666 |
iovec_done(&v); |
| 667 |
|
| 668 |
/* too long */ |
| 669 |
_cleanup_(iovec_done) struct iovec large = {}; |
| 670 |
ASSERT_OK(random_bytes_allocate_iovec(256, &large)); |
| 671 |
ASSERT_ERROR(iovw_merge(&(struct iovec_wrapper) { .iovec = &large, .count = 1, }, sizeof(uint8_t), &v), ERANGE); |
| 672 |
ASSERT_OK(iovw_merge(&(struct iovec_wrapper) { .iovec = &large, .count = 1, }, sizeof(uint16_t), &v)); |
| 673 |
ASSERT_OK(iovec_split(&v, sizeof(uint16_t), &iovw2)); |
| 674 |
ASSERT_EQ(iovw2.count, 1u); |
| 675 |
ASSERT_TRUE(iovec_equal(&iovw2.iovec[0], &large)); |
| 676 |
|
| 677 |
iovec_done(&v); |
| 678 |
iovw_done_free(&iovw2); |
| 679 |
|
| 680 |
/* No entry */ |
| 681 |
ASSERT_OK(iovw_merge(&(struct iovec_wrapper) {}, sizeof(uint8_t), &v)); |
| 682 |
ASSERT_FALSE(iovec_is_set(&v)); |
| 683 |
|
| 684 |
ASSERT_OK(iovw_merge(NULL, sizeof(uint8_t), &v)); |
| 685 |
ASSERT_FALSE(iovec_is_set(&v)); |
| 686 |
|
| 687 |
ASSERT_OK(iovec_split(&(struct iovec) {}, sizeof(uint8_t), &iovw2)); |
| 688 |
ASSERT_TRUE(iovw_isempty(&iovw2)); |
| 689 |
|
| 690 |
ASSERT_OK(iovec_split(NULL, sizeof(uint8_t), &iovw2)); |
| 691 |
ASSERT_TRUE(iovw_isempty(&iovw2)); |
| 692 |
|
| 693 |
/* empty entry only */ |
| 694 |
ASSERT_OK(iovw_merge(&(struct iovec_wrapper) { .iovec = &(struct iovec) {}, .count = 1, }, sizeof(uint8_t), &v)); |
| 695 |
ASSERT_FALSE(iovec_is_set(&v)); |
| 696 |
|
| 697 |
ASSERT_OK(iovec_split(&IOVEC_MAKE("", 1), sizeof(uint8_t), &iovw2)); |
| 698 |
ASSERT_TRUE(iovw_isempty(&iovw2)); |
| 699 |
|
| 700 |
} |
| 701 |
|
| 702 |
DEFINE_TEST_MAIN(LOG_INFO); |