Browse Source

[tests] use buffer_eq_slen() for str comparison

(substitute buffer_eq_slen() for buffer_is_equal_string())
personal/stbuehler/ci-build
Glenn Strauss 2 years ago
parent
commit
17e0b6fe30
  1. 10
      src/t/test_array.c
  2. 2
      src/t/test_base64.c
  3. 30
      src/t/test_buffer.c
  4. 2
      src/t/test_burl.c
  5. 10
      src/t/test_keyvalue.c
  6. 2
      src/t/test_mod_evhost.c
  7. 6
      src/t/test_mod_simple_vhost.c
  8. 47
      src/t/test_request.c

10
src/t/test_array.c

@ -35,7 +35,7 @@ static void test_array_insert_value (void) {
array_insert_value(a, CONST_STR_LEN("def"));
ds = (data_string *)a->data[0];
assert(NULL != ds);
assert(buffer_is_equal_string(&ds->value, CONST_STR_LEN("def")));
assert(buffer_eq_slen(&ds->value, CONST_STR_LEN("def")));
array_free(a);
}
@ -49,16 +49,16 @@ static void test_array_set_key_value (void) {
assert(NULL == ds);
ds = (data_string *)array_get_element_klen(a, CONST_STR_LEN("abc"));
assert(NULL != ds);
assert(buffer_is_equal_string(&ds->key, CONST_STR_LEN("abc")));
assert(buffer_is_equal_string(&ds->value, CONST_STR_LEN("def")));
assert(buffer_eq_slen(&ds->key, CONST_STR_LEN("abc")));
assert(buffer_eq_slen(&ds->value, CONST_STR_LEN("def")));
array_set_key_value(a, CONST_STR_LEN("abc"), CONST_STR_LEN("ghi"));
ds = (data_string *)array_get_element_klen(a, CONST_STR_LEN("does-not-exist"));
assert(NULL == ds);
ds = (data_string *)array_get_element_klen(a, CONST_STR_LEN("abc"));
assert(NULL != ds);
assert(buffer_is_equal_string(&ds->key, CONST_STR_LEN("abc")));
assert(buffer_is_equal_string(&ds->value, CONST_STR_LEN("ghi")));
assert(buffer_eq_slen(&ds->key, CONST_STR_LEN("abc")));
assert(buffer_eq_slen(&ds->value, CONST_STR_LEN("ghi")));
array_free(a);
}

2
src/t/test_base64.c

@ -11,7 +11,7 @@ static void check_base64 (char *out, const size_t out_sz, const char *in, const
buffer_reset(check);
force_assert(NULL != buffer_append_base64_decode(check, out, out_sz, enc));
force_assert(buffer_is_equal_string(check, in, in_len));
force_assert(buffer_eq_slen(check, in, in_len));
}
static void check_all_len_0 (const base64_charset enc) {

30
src/t/test_buffer.c

@ -12,7 +12,7 @@ static void run_buffer_path_simplify(buffer *psrc, buffer *pdest, const char *in
buffer_path_simplify(pdest, psrc);
if (!buffer_is_equal_string(pdest, out, out_len)) {
if (!buffer_eq_slen(pdest, out, out_len)) {
fprintf(stderr,
"%s.%d: buffer_path_simplify('%s') failed: expected '%s', got '%s'\n",
__FILE__,
@ -26,7 +26,7 @@ static void run_buffer_path_simplify(buffer *psrc, buffer *pdest, const char *in
if (psrc != pdest) buffer_copy_buffer(psrc, pdest);
buffer_path_simplify(pdest, psrc);
if (!buffer_is_equal_string(pdest, out, out_len)) {
if (!buffer_eq_slen(pdest, out, out_len)) {
fprintf(stderr,
"%s.%d: buffer_path_simplify('%s') failed - not idempotent: expected '%s', got '%s'\n",
__FILE__,
@ -85,13 +85,13 @@ static void test_buffer_to_lower_upper(void) {
buffer_copy_string_len(psrc, CONST_STR_LEN("0123456789abcdefghijklmnopqrstuvwxyz"));
buffer_to_lower(psrc);
assert(buffer_is_equal_string(psrc, CONST_STR_LEN("0123456789abcdefghijklmnopqrstuvwxyz")));
assert(buffer_eq_slen(psrc, CONST_STR_LEN("0123456789abcdefghijklmnopqrstuvwxyz")));
buffer_to_upper(psrc);
assert(buffer_is_equal_string(psrc, CONST_STR_LEN("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")));
assert(buffer_eq_slen(psrc, CONST_STR_LEN("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")));
buffer_to_upper(psrc);
assert(buffer_is_equal_string(psrc, CONST_STR_LEN("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")));
assert(buffer_eq_slen(psrc, CONST_STR_LEN("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")));
buffer_to_lower(psrc);
assert(buffer_is_equal_string(psrc, CONST_STR_LEN("0123456789abcdefghijklmnopqrstuvwxyz")));
assert(buffer_eq_slen(psrc, CONST_STR_LEN("0123456789abcdefghijklmnopqrstuvwxyz")));
buffer_free(psrc);
}
@ -118,31 +118,31 @@ static void test_buffer_append_path_len(void) {
buffer *b = buffer_init();
buffer_append_path_len(b, CONST_STR_LEN("a"));
assert(buffer_is_equal_string(b, CONST_STR_LEN("/a")));
assert(buffer_eq_slen(b, CONST_STR_LEN("/a")));
buffer_clear(b);
buffer_append_path_len(b, CONST_STR_LEN("a"));
assert(buffer_is_equal_string(b, CONST_STR_LEN("/a")));
assert(buffer_eq_slen(b, CONST_STR_LEN("/a")));
buffer_clear(b);
buffer_append_path_len(b, CONST_STR_LEN("/a"));
assert(buffer_is_equal_string(b, CONST_STR_LEN("/a")));
assert(buffer_eq_slen(b, CONST_STR_LEN("/a")));
buffer_copy_string_len(b, CONST_STR_LEN("/"));
buffer_append_path_len(b, CONST_STR_LEN("a"));
assert(buffer_is_equal_string(b, CONST_STR_LEN("/a")));
assert(buffer_eq_slen(b, CONST_STR_LEN("/a")));
buffer_copy_string_len(b, CONST_STR_LEN("/"));
buffer_append_path_len(b, CONST_STR_LEN("/a"));
assert(buffer_is_equal_string(b, CONST_STR_LEN("/a")));
assert(buffer_eq_slen(b, CONST_STR_LEN("/a")));
buffer_copy_string_len(b, CONST_STR_LEN("a"));
buffer_append_path_len(b, CONST_STR_LEN("a"));
assert(buffer_is_equal_string(b, CONST_STR_LEN("a/a")));
assert(buffer_eq_slen(b, CONST_STR_LEN("a/a")));
buffer_copy_string_len(b, CONST_STR_LEN("a/"));
buffer_append_path_len(b, CONST_STR_LEN("a"));
assert(buffer_is_equal_string(b, CONST_STR_LEN("a/a")));
assert(buffer_eq_slen(b, CONST_STR_LEN("a/a")));
buffer_copy_string_len(b, CONST_STR_LEN("a/"));
buffer_append_path_len(b, CONST_STR_LEN("/a"));
assert(buffer_is_equal_string(b, CONST_STR_LEN("a/a")));
assert(buffer_eq_slen(b, CONST_STR_LEN("a/a")));
buffer_copy_string_len(b, CONST_STR_LEN("/a/"));
buffer_append_path_len(b, CONST_STR_LEN("/a"));
assert(buffer_is_equal_string(b, CONST_STR_LEN("/a/a")));
assert(buffer_eq_slen(b, CONST_STR_LEN("/a/a")));
buffer_free(b);
}

2
src/t/test_burl.c

@ -16,7 +16,7 @@ static void run_burl_normalize (buffer *psrc, buffer *ptmp, int flags, int line,
__FILE__, line, __func__+4, in, psrc->ptr);
}
else {
if (buffer_is_equal_string(psrc, out, out_len)) return;
if (buffer_eq_slen(psrc, out, out_len)) return;
fprintf(stderr,
"%s.%d: %s('%s') failed: expected '%s', got '%s'\n",
__FILE__, line, __func__+4, in, out, psrc->ptr);

10
src/t/test_keyvalue.c

@ -79,35 +79,35 @@ static void test_keyvalue_pcre_keyvalue_buffer_process (void) {
buffer_clear(query);
rc = pcre_keyvalue_buffer_process(kvb, &ctx, url, result);
assert(HANDLER_FINISHED == rc);
assert(buffer_is_equal_string(result, CONST_STR_LEN("/foo/")));
assert(buffer_eq_slen(result, CONST_STR_LEN("/foo/")));
buffer_copy_string_len(url, CONST_STR_LEN("/foo?a=b"));
buffer_copy_string_len(path, CONST_STR_LEN("/foo"));
buffer_copy_string_len(query, CONST_STR_LEN("a=b"));
rc = pcre_keyvalue_buffer_process(kvb, &ctx, url, result);
assert(HANDLER_FINISHED == rc);
assert(buffer_is_equal_string(result, CONST_STR_LEN("/foo/?a=b")));
assert(buffer_eq_slen(result, CONST_STR_LEN("/foo/?a=b")));
buffer_copy_string_len(url, CONST_STR_LEN("/bar?a=b"));
buffer_copy_string_len(path, CONST_STR_LEN("/bar"));
buffer_copy_string_len(query, CONST_STR_LEN("a=b"));
rc = pcre_keyvalue_buffer_process(kvb, &ctx, url, result);
assert(HANDLER_FINISHED == rc);
assert(buffer_is_equal_string(result, CONST_STR_LEN("/?bar&a=b")));
assert(buffer_eq_slen(result, CONST_STR_LEN("/?bar&a=b")));
buffer_copy_string_len(url, CONST_STR_LEN("/nofile?a=b"));
buffer_copy_string_len(path, CONST_STR_LEN("/nofile"));
buffer_copy_string_len(query, CONST_STR_LEN("a=b"));
rc = pcre_keyvalue_buffer_process(kvb, &ctx, url, result);
assert(HANDLER_FINISHED == rc);
assert(buffer_is_equal_string(result, CONST_STR_LEN("/?file=/nofile&a=b")));
assert(buffer_eq_slen(result, CONST_STR_LEN("/?file=/nofile&a=b")));
buffer_copy_string_len(url, CONST_STR_LEN("/redirect?a=b"));
buffer_copy_string_len(path, CONST_STR_LEN("/redirect"));
buffer_copy_string_len(query, CONST_STR_LEN("a=b"));
rc = pcre_keyvalue_buffer_process(kvb, &ctx, url, result);
assert(HANDLER_FINISHED == rc);
assert(buffer_is_equal_string(result, CONST_STR_LEN("/?seg=www&a=b")));
assert(buffer_eq_slen(result, CONST_STR_LEN("/?seg=www&a=b")));
buffer_free(url);
buffer_free(result);

2
src/t/test_mod_evhost.c

@ -18,7 +18,7 @@ static void test_mod_evhost_build_doc_root_path_loop(struct ttt *tt, size_t nelt
const buffer *path_pieces = mod_evhost_parse_pattern(t->pattern);
assert(NULL != path_pieces);
mod_evhost_build_doc_root_path(b, a, authority, path_pieces);
assert(buffer_is_equal_string(b, t->expect, t->elen));
assert(buffer_eq_slen(b, t->expect, t->elen));
mod_evhost_free_path_pieces(path_pieces);
}
}

6
src/t/test_mod_simple_vhost.c

@ -17,15 +17,15 @@ static void test_mod_simple_vhost_build_doc_root_path(void) {
buffer_copy_string_len(host, CONST_STR_LEN("www.example.org"));
buffer_copy_string_len(droot, CONST_STR_LEN("/droot/b/"));
build_doc_root_path(result, sroot, host, droot);
assert(buffer_is_equal_string(result, CONST_STR_LEN("/sroot/a/www.example.org/droot/b/")));
assert(buffer_eq_slen(result, CONST_STR_LEN("/sroot/a/www.example.org/droot/b/")));
buffer_copy_string_len(host, CONST_STR_LEN("www.example.org:8080"));
build_doc_root_path(result, sroot, host, droot);
assert(buffer_is_equal_string(result, CONST_STR_LEN("/sroot/a/www.example.org/droot/b/")));
assert(buffer_eq_slen(result, CONST_STR_LEN("/sroot/a/www.example.org/droot/b/")));
buffer_copy_string_len(droot, CONST_STR_LEN(""));
build_doc_root_path(result, sroot, host, droot);
assert(buffer_is_equal_string(result, CONST_STR_LEN("/sroot/a/www.example.org/")));
assert(buffer_eq_slen(result, CONST_STR_LEN("/sroot/a/www.example.org/")));
buffer_free(sroot);
buffer_free(host);

47
src/t/test_request.c

@ -151,48 +151,42 @@ static void test_request_http_request_parse(request_st * const r)
CONST_STR_LEN("GET / HTTP/1.0\r\n"
"Host: www.example.org\r\n"
"\r\n"));
assert(buffer_is_equal_string(r->http_host,
CONST_STR_LEN("www.example.org")));
assert(buffer_eq_slen(r->http_host, CONST_STR_LEN("www.example.org")));
run_http_request_parse(r, __LINE__, 0,
"IPv4 address",
CONST_STR_LEN("GET / HTTP/1.0\r\n"
"Host: 127.0.0.1\r\n"
"\r\n"));
assert(buffer_is_equal_string(r->http_host,
CONST_STR_LEN("127.0.0.1")));
assert(buffer_eq_slen(r->http_host, CONST_STR_LEN("127.0.0.1")));
run_http_request_parse(r, __LINE__, 0,
"IPv6 address",
CONST_STR_LEN("GET / HTTP/1.0\r\n"
"Host: [::1]\r\n"
"\r\n"));
assert(buffer_is_equal_string(r->http_host,
CONST_STR_LEN("[::1]")));
assert(buffer_eq_slen(r->http_host, CONST_STR_LEN("[::1]")));
run_http_request_parse(r, __LINE__, 0,
"hostname + port",
CONST_STR_LEN("GET / HTTP/1.0\r\n"
"Host: www.example.org:80\r\n"
"\r\n"));
assert(buffer_is_equal_string(r->http_host,
CONST_STR_LEN("www.example.org")));
assert(buffer_eq_slen(r->http_host, CONST_STR_LEN("www.example.org")));
run_http_request_parse(r, __LINE__, 0,
"IPv4 address + port",
CONST_STR_LEN("GET / HTTP/1.0\r\n"
"Host: 127.0.0.1:80\r\n"
"\r\n"));
assert(buffer_is_equal_string(r->http_host,
CONST_STR_LEN("127.0.0.1")));
assert(buffer_eq_slen(r->http_host, CONST_STR_LEN("127.0.0.1")));
run_http_request_parse(r, __LINE__, 0,
"IPv6 address + port",
CONST_STR_LEN("GET / HTTP/1.0\r\n"
"Host: [::1]:80\r\n"
"\r\n"));
assert(buffer_is_equal_string(r->http_host,
CONST_STR_LEN("[::1]")));
assert(buffer_eq_slen(r->http_host, CONST_STR_LEN("[::1]")));
run_http_request_parse(r, __LINE__, 400,
"directory traversal",
@ -211,8 +205,7 @@ static void test_request_http_request_parse(request_st * const r)
CONST_STR_LEN("GET / HTTP/1.0\r\n"
"Host: jsdh.sfdg.sdfg.\r\n"
"\r\n"));
assert(buffer_is_equal_string(r->http_host,
CONST_STR_LEN("jsdh.sfdg.sdfg")));
assert(buffer_eq_slen(r->http_host, CONST_STR_LEN("jsdh.sfdg.sdfg")));
run_http_request_parse(r, __LINE__, 400,
"leading dot",
@ -255,8 +248,7 @@ static void test_request_http_request_parse(request_st * const r)
CONST_STR_LEN("GET / HTTP/1.0\r\n"
"Host: a.b-c.d123\r\n"
"\r\n"));
assert(buffer_is_equal_string(r->http_host,
CONST_STR_LEN("a.b-c.d123")));
assert(buffer_eq_slen(r->http_host, CONST_STR_LEN("a.b-c.d123")));
run_http_request_parse(r, __LINE__, 400,
"leading dash",
@ -327,8 +319,7 @@ static void test_request_http_request_parse(request_st * const r)
ds = (data_string *)
array_get_element_klen(&r->rqst_headers, CONST_STR_LEN("Location"));
assert(ds
&& buffer_is_equal_string(&ds->value,
CONST_STR_LEN("foo, foobar baz")));
&& buffer_eq_slen(&ds->value, CONST_STR_LEN("foo, foobar baz")));
run_http_request_parse(r, __LINE__, 0,
"#1232 - duplicate headers with line-wrapping - test 2",
@ -339,8 +330,7 @@ static void test_request_http_request_parse(request_st * const r)
"\r\n"));
ds = (data_string *)
array_get_element_klen(&r->rqst_headers, CONST_STR_LEN("Location"));
assert(ds
&& buffer_is_equal_string(&ds->value, CONST_STR_LEN("foobar baz")));
assert(ds && buffer_eq_slen(&ds->value, CONST_STR_LEN("foobar baz")));
run_http_request_parse(r, __LINE__, 0,
"#1232 - duplicate headers with line-wrapping - test 3",
@ -351,8 +341,7 @@ static void test_request_http_request_parse(request_st * const r)
"\r\n"));
ds = (data_string *)
array_get_element_klen(&r->rqst_headers, CONST_STR_LEN("Location"));
assert(ds
&& buffer_is_equal_string(&ds->value, CONST_STR_LEN("foobar baz")));
assert(ds && buffer_eq_slen(&ds->value, CONST_STR_LEN("foobar baz")));
run_http_request_parse(r, __LINE__, 400,
"missing protocol",
@ -404,10 +393,8 @@ static void test_request_http_request_parse(request_st * const r)
"absolute URI",
CONST_STR_LEN("GET http://www.example.org/ HTTP/1.0\r\n"
"\r\n"));
assert(buffer_is_equal_string(r->http_host,
CONST_STR_LEN("www.example.org")));
assert(buffer_is_equal_string(&r->target,
CONST_STR_LEN("/")));
assert(buffer_eq_slen(r->http_host, CONST_STR_LEN("www.example.org")));
assert(buffer_eq_slen(&r->target, CONST_STR_LEN("/")));
run_http_request_parse(r, __LINE__, 400,
"whitespace after key",
@ -428,7 +415,7 @@ static void test_request_http_request_parse(request_st * const r)
"\r\n"));
ds = (data_string *)
array_get_element_klen(&r->rqst_headers, CONST_STR_LEN("ABC"));
assert(ds && buffer_is_equal_string(&ds->value, CONST_STR_LEN("foo")));
assert(ds && buffer_eq_slen(&ds->value, CONST_STR_LEN("foo")));
run_http_request_parse(r, __LINE__, 0,
"line-folding",
@ -438,7 +425,7 @@ static void test_request_http_request_parse(request_st * const r)
"\r\n"));
ds = (data_string *)
array_get_element_klen(&r->rqst_headers, CONST_STR_LEN("ABC"));
assert(ds && buffer_is_equal_string(&ds->value, CONST_STR_LEN("foo bc")));
assert(ds && buffer_eq_slen(&ds->value, CONST_STR_LEN("foo bc")));
run_http_request_parse(r, __LINE__, 411,
"POST request, no Content-Length",
@ -541,7 +528,7 @@ static void test_request_http_request_parse(request_st * const r)
"\r\n"));
ds = (data_string *)
array_get_element_klen(&r->rqst_headers, CONST_STR_LEN("Host"));
assert(ds && buffer_is_equal_string(&ds->value, CONST_STR_LEN("zzz.example.org")));
assert(ds && buffer_eq_slen(&ds->value, CONST_STR_LEN("zzz.example.org")));
run_http_request_parse(r, __LINE__, 0,
"absolute-uri in request-line (with Host match)",
@ -551,7 +538,7 @@ static void test_request_http_request_parse(request_st * const r)
"\r\n"));
ds = (data_string *)
array_get_element_klen(&r->rqst_headers, CONST_STR_LEN("Host"));
assert(ds && buffer_is_equal_string(&ds->value, CONST_STR_LEN("zzz.example.org")));
assert(ds && buffer_eq_slen(&ds->value, CONST_STR_LEN("zzz.example.org")));
run_http_request_parse(r, __LINE__, 400,
"absolute-uri in request-line (with Host mismatch)",

Loading…
Cancel
Save