Imported Upstream version 7.48.0
[platform/upstream/curl.git] / tests / unit / unit1396.c
index 797443d..8a78c95 100644 (file)
@@ -9,7 +9,7 @@
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
- * are also available at http://curl.haxx.se/docs/copyright.html.
+ * are also available at https://curl.haxx.se/docs/copyright.html.
  *
  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  * copies of the Software, and permit persons to whom the Software is
@@ -21,6 +21,8 @@
  ***************************************************************************/
 #include "curlcheck.h"
 
+CURL *hnd;
+
 static CURLcode unit_setup(void)
 {
   return CURLE_OK;
@@ -28,6 +30,8 @@ static CURLcode unit_setup(void)
 
 static void unit_stop(void)
 {
+  if (hnd)
+    curl_easy_cleanup(hnd);
 }
 
 struct test {
@@ -40,7 +44,7 @@ struct test {
 UNITTEST_START
 {
   /* unescape, this => that */
-  struct test list1[]={
+  const struct test list1[]={
     {"%61", 3, "a", 1},
     {"%61a", 4, "aa", 2},
     {"%61b", 4, "ab", 2},
@@ -56,7 +60,7 @@ UNITTEST_START
     {NULL, 0, NULL, 0} /* end of list marker */
   };
   /* escape, this => that */
-  struct test list2[]={
+  const struct test list2[]={
     {"a", 1, "a", 1},
     {"/", 1, "%2F", 3},
     {"a=b", 3, "a%3Db", 5},
@@ -70,16 +74,16 @@ UNITTEST_START
     {NULL, 0, NULL, 0} /* end of list marker */
   };
   int i;
-  CURL *hnd;
 
   hnd = curl_easy_init();
+  abort_unless(hnd != NULL, "returned NULL!");
   for(i=0; list1[i].in; i++) {
     int outlen;
     char *out = curl_easy_unescape(hnd,
                                    list1[i].in, list1[i].inlen,
                                    &outlen);
 
-    fail_unless(out != NULL, "returned NULL!");
+    abort_unless(out != NULL, "returned NULL!");
     fail_unless(outlen == list1[i].outlen, "wrong output length returned");
     fail_unless(!memcmp(out, list1[i].out, list1[i].outlen),
                 "bad output data returned");
@@ -90,10 +94,11 @@ UNITTEST_START
   }
 
   for(i=0; list2[i].in; i++) {
+    int outlen;
     char *out = curl_easy_escape(hnd, list2[i].in, list2[i].inlen);
-    int outlen = (int)strlen(out);
+    abort_unless(out != NULL, "returned NULL!");
 
-    fail_unless(out != NULL, "returned NULL!");
+    outlen = (int)strlen(out);
     fail_unless(outlen == list2[i].outlen, "wrong output length returned");
     fail_unless(!memcmp(out, list2[i].out, list2[i].outlen),
                 "bad output data returned");
@@ -102,8 +107,5 @@ UNITTEST_START
 
     curl_free(out);
   }
-
-  curl_easy_cleanup(hnd);
-
 }
 UNITTEST_STOP