From: Viktor Szakats Date: Wed, 21 May 2025 07:44:19 +0000 (+0200) Subject: unit1979, unit1980: fix indent, formatting, scope X-Git-Tag: curl-8_14_0~37 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=613308a0f1b7b4cdda194125d4462f633fd37dab;p=thirdparty%2Fcurl.git unit1979, unit1980: fix indent, formatting, scope Closes #17403 --- diff --git a/tests/unit/unit1979.c b/tests/unit/unit1979.c index e5f044dd63..89af6c6605 100644 --- a/tests/unit/unit1979.c +++ b/tests/unit/unit1979.c @@ -23,7 +23,6 @@ ***************************************************************************/ #include "curlcheck.h" - #include "http_aws_sigv4.h" #include "dynbuf.h" @@ -37,109 +36,109 @@ static void unit_stop(void) } UNITTEST_START - -#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_AWS) - -struct testcase { - const char *testname; - const bool normalize; - const char *url_part; - const char *canonical_url; -}; - -static const struct testcase testcases[] = { - { - "test-equals-encode", - true, - "/a=b", - "/a%3Db", - }, - { - "test-equals-noencode", - false, - "/a=b", - "/a=b", - }, - { - "test-s3-tables", - true, - "/tables/arn%3Aaws%3As3tables%3Aus-east-1%3A022954301426%3Abucket%2Fja" - "soehartablebucket/jasoeharnamespace/jasoehartable/encryption", - "/tables/arn%253Aaws%253As3tables%253Aus-east-1%253A022954301426%253Ab" - "ucket%252Fjasoehartablebucket/jasoeharnamespace/jasoehartable/encrypt" - "ion", - }, - { - "get-vanilla", - true, - "/", - "/", - }, - { - "get-unreserved", - true, - "/-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", - "/-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", - }, - { - "get-slashes-unnormalized", - false, - "//example//", - "//example//", - }, - { - "get-space-normalized", - true, - "/example space/", - "/example%20space/", - }, - { - "get-slash-dot-slash-unnormalized", - false, - "/./", - "/./", - }, - { - "get-slash-unnormalized", - false, - "//", - "//", - }, - { - "get-relative-relative-unnormalized", - false, - "/example1/example2/../..", - "/example1/example2/../..", - } -}; +#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_AWS) + struct testcase { + const char *testname; + const bool normalize; + const char *url_part; + const char *canonical_url; + }; - struct dynbuf canonical_path; + static const struct testcase testcases[] = { + { + "test-equals-encode", + true, + "/a=b", + "/a%3Db" + }, + { + "test-equals-noencode", + false, + "/a=b", + "/a=b" + }, + { + "test-s3-tables", + true, + "/tables/arn%3Aaws%3As3tables%3Aus-east-1%3A022954301426%3Abucket%2Fja" + "soehartablebucket/jasoeharnamespace/jasoehartable/encryption", + "/tables/arn%253Aaws%253As3tables%253Aus-east-1%253A022954301426%253Ab" + "ucket%252Fjasoehartablebucket/jasoeharnamespace/jasoehartable/encrypt" + "ion" + }, + { + "get-vanilla", + true, + "/", + "/" + }, + { + "get-unreserved", + true, + "/-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", + "/-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + }, + { + "get-slashes-unnormalized", + false, + "//example//", + "//example//" + }, + { + "get-space-normalized", + true, + "/example space/", + "/example%20space/" + }, + { + "get-slash-dot-slash-unnormalized", + false, + "/./", + "/./" + }, + { + "get-slash-unnormalized", + false, + "//", + "//" + }, + { + "get-relative-relative-unnormalized", + false, + "/example1/example2/../..", + "/example1/example2/../.." + } + }; - char buffer[1024]; - char *canonical_path_string; size_t i; - int result; - int msnprintf_result; for(i = 0; i < CURL_ARRAYSIZE(testcases); i++) { + struct dynbuf canonical_path; + + char buffer[1024]; + char *canonical_path_string; + int result; + int msnprintf_result; + curlx_dyn_init(&canonical_path, CURL_MAX_HTTP_HEADER); result = canon_path(testcases[i].url_part, strlen(testcases[i].url_part), - &canonical_path, - testcases[i].normalize); + &canonical_path, testcases[i].normalize); canonical_path_string = curlx_dyn_ptr(&canonical_path); msnprintf_result = curl_msnprintf(buffer, sizeof(buffer), - "%s: Received \"%s\" and should be \"%s\", normalize (%d)", - testcases[i].testname, curlx_dyn_ptr(&canonical_path), - testcases[i].canonical_url, testcases[i].normalize); + "%s: Received \"%s\" " + "and should be \"%s\", normalize (%d)", + testcases[i].testname, + curlx_dyn_ptr(&canonical_path), + testcases[i].canonical_url, + testcases[i].normalize); fail_unless(msnprintf_result >= 0, "curl_msnprintf fails"); fail_unless(!result && canonical_path_string && - !strcmp(canonical_path_string, - testcases[i].canonical_url), buffer); + !strcmp(canonical_path_string, testcases[i].canonical_url), + buffer); curlx_dyn_free(&canonical_path); } - #endif /* !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_AWS) */ - +} UNITTEST_STOP diff --git a/tests/unit/unit1980.c b/tests/unit/unit1980.c index 69cd2dd8c0..dcc415dca5 100644 --- a/tests/unit/unit1980.c +++ b/tests/unit/unit1980.c @@ -23,11 +23,9 @@ ***************************************************************************/ #include "curlcheck.h" - #include "http_aws_sigv4.h" #include "dynbuf.h" - static CURLcode unit_setup(void) { return CURLE_OK; @@ -38,77 +36,80 @@ static void unit_stop(void) } UNITTEST_START +{ #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_AWS) + struct testcase { + const char *testname; + const char *query_part; + const char *canonical_query; + }; -struct testcase { - const char *testname; - const char *query_part; - const char *canonical_query; -}; - -static const struct testcase testcases[] = { - { - "no-value", - "Param1=", - "Param1=" - }, - { - "test-439", - "name=me&noval&aim=b%aad&weirdo=*.//-", - "aim=b%AAd&name=me&noval=&weirdo=%2A.%2F%2F-" + static const struct testcase testcases[] = { + { + "no-value", + "Param1=", + "Param1=" }, { - "blank-query-params", - "hello=a&b&c=&d", - "b=&c=&d=&hello=a" - }, - { - "get-vanilla-query-order-key-case", - "Param2=value2&Param1=value1", - "Param1=value1&Param2=value2" - }, - { - "get-vanilla-query-unreserved", - "-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz=" - "-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", - "-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz=" - "-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" - }, - { - "get-vanilla-empty-query-key", - "Param1=value1", - "Param1=value1" - }, - { - "get-vanilla-query-order-encoded", - "Param-3=Value3&Param=Value2&%E1%88%B4=Value1", - "%E1%88%B4=Value1&Param=Value2&Param-3=Value3" - }, -}; - - struct dynbuf canonical_query; + "test-439", + "name=me&noval&aim=b%aad&weirdo=*.//-", + "aim=b%AAd&name=me&noval=&weirdo=%2A.%2F%2F-" + }, + { + "blank-query-params", + "hello=a&b&c=&d", + "b=&c=&d=&hello=a" + }, + { + "get-vanilla-query-order-key-case", + "Param2=value2&Param1=value1", + "Param1=value1&Param2=value2" + }, + { + "get-vanilla-query-unreserved", + "-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz=" + "-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", + "-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz=" + "-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + }, + { + "get-vanilla-empty-query-key", + "Param1=value1", + "Param1=value1" + }, + { + "get-vanilla-query-order-encoded", + "Param-3=Value3&Param=Value2&%E1%88%B4=Value1", + "%E1%88%B4=Value1&Param=Value2&Param-3=Value3" + }, + }; - char buffer[1024]; - char *canonical_query_ptr; size_t i; - int result; - int msnprintf_result; - for(i = 0; i < CURL_ARRAYSIZE(testcases); i++) { + for(i = 0; i < CURL_ARRAYSIZE(testcases); i++) { + struct dynbuf canonical_query; + + char buffer[1024]; + char *canonical_query_ptr; + int result; + int msnprintf_result; + curlx_dyn_init(&canonical_query, CURL_MAX_HTTP_HEADER); result = canon_query(testcases[i].query_part, &canonical_query); canonical_query_ptr = curlx_dyn_ptr(&canonical_query); msnprintf_result = curl_msnprintf(buffer, sizeof(buffer), - "%s: Received \"%s\" and should be \"%s\"", - testcases[i].testname, canonical_query_ptr, - testcases[i].canonical_query); + "%s: Received \"%s\" " + "and should be \"%s\"", + testcases[i].testname, + canonical_query_ptr, + testcases[i].canonical_query); fail_unless(msnprintf_result >= 0, "curl_msnprintf fails"); - fail_unless(!result && canonical_query_ptr && !strcmp(canonical_query_ptr, - testcases[i].canonical_query), - buffer); + fail_unless(!result && canonical_query_ptr && + !strcmp(canonical_query_ptr, testcases[i].canonical_query), + buffer); curlx_dyn_free(&canonical_query); - } - - #endif /* !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_AWS) */ - UNITTEST_STOP + } +#endif /* !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_AWS) */ +} +UNITTEST_STOP