]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
test1627: Curl_get_scheme unit test
authorDaniel Stenberg <daniel@haxx.se>
Thu, 12 Mar 2026 10:07:05 +0000 (11:07 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 12 Mar 2026 13:22:38 +0000 (14:22 +0100)
Closes #20904

tests/data/Makefile.am
tests/data/test1627 [new file with mode: 0644]
tests/unit/Makefile.inc
tests/unit/unit1627.c [new file with mode: 0644]

index 97d4b2f22db5de7065ae07f34f82a7e6a14e4843..65846e52edefc0681769c725f2ef1f9707279c57 100644 (file)
@@ -214,7 +214,7 @@ test1590 test1591 test1592 test1593 test1594 test1595 test1596 test1597 \
 test1598 test1599 test1600 test1601 test1602 test1603 test1604 test1605 \
 test1606 test1607 test1608 test1609 test1610 test1611 test1612 test1613 \
 test1614 test1615 test1616 test1617 \
-test1620 test1621 test1622 test1623 test1624 test1625 test1626 \
+test1620 test1621 test1622 test1623 test1624 test1625 test1626 test1627 \
 \
 test1630 test1631 test1632 test1633 test1634 test1635 test1636 test1637 \
 \
diff --git a/tests/data/test1627 b/tests/data/test1627
new file mode 100644 (file)
index 0000000..95bd3e3
--- /dev/null
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="US-ASCII"?>
+<testcase>
+<info>
+<keywords>
+unittest
+Curl_get_scheme
+</keywords>
+</info>
+
+<client>
+<features>
+unittest
+</features>
+<name>
+Curl_get_scheme unit test
+</name>
+</client>
+
+<verify>
+<stdout mode="text">
+205 invokes
+</stdout>
+</verify>
+</testcase>
index a302e839edb343a98b2cb1f6a0c4dffec3aa520f..e4243a9bfd08690e51fd9392e46e22eaa834013d 100644 (file)
@@ -37,7 +37,7 @@ TESTS_C = \
   unit1600.c unit1601.c unit1602.c unit1603.c            unit1605.c unit1606.c \
   unit1607.c unit1608.c unit1609.c unit1610.c unit1611.c unit1612.c unit1614.c \
   unit1615.c unit1616.c                                  unit1620.c \
-  unit1625.c unit1626.c \
+  unit1625.c unit1626.c unit1627.c \
   unit1636.c \
   unit1650.c unit1651.c unit1652.c unit1653.c unit1654.c unit1655.c unit1656.c \
   unit1657.c unit1658.c            unit1660.c unit1661.c unit1663.c unit1664.c \
diff --git a/tests/unit/unit1627.c b/tests/unit/unit1627.c
new file mode 100644 (file)
index 0000000..9112258
--- /dev/null
@@ -0,0 +1,98 @@
+/***************************************************************************
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
+ *                             \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * 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 https://curl.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
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * SPDX-License-Identifier: curl
+ *
+ ***************************************************************************/
+#include "unitcheck.h"
+
+#include "urldata.h"
+#include "url.h"
+
+static CURLcode test_unit1627(const char *arg)
+{
+  size_t i, j;
+  /* existing schemes in different cases */
+  static const char *okay[] = {
+    /* all upper */
+    "DICT", "FILE", "FTP", "FTPS", "GOPHER", "GOPHERS", "HTTP", "HTTPS",
+    "IMAP", "IMAPS", "LDAP", "LDAPS", "MQTT", "MQTTS", "POP3", "POP3S",
+    "RTMP", "RTMPS", "RTSP", "SCP", "SFTP", "SMB", "SMBS", "SMTP", "SMTPS",
+    "TELNET", "TFTP", "WS", "WSS",
+    /* all lower */
+    "dict", "file", "ftp", "ftps", "gopher", "gophers", "http", "https",
+    "imap", "imaps", "ldap", "ldaps", "mqtt", "mqtts", "pop3", "pop3s",
+    "rtmp", "rtmps", "rtsp", "scp", "sftp", "smb", "smbs", "smtp", "smtps",
+    "telnet", "tftp", "ws", "wss",
+    /* mixed */
+    "diCt", "fIle", "Ftp", "ftpS", "Gopher", "gOphers", "htTp", "httPs",
+    "imAP", "imaPS", "LDap", "LDAps", "mQTT", "mqtTS", "pOP3", "pOP3s",
+    "rTMp", "rTMPS", "RtsP", "ScP", "SFtP", "Smb", "smBS", "sMTP", "SMTPs",
+    "TELNEt", "tFTP", "Ws", "wSS",
+  };
+  /* non-existing schemes */
+  static const char *notokay[] = {
+    "a", "A", "htt", "ttp", "httt", "http+", "HTTPP", "HTTPPS", "HTTSP",
+    "GROPHER", "D1CT", "AbG", "zLQp", "mNrtW", "PkY", "bVcxZq", "LmO",
+    "iUhyT", "rEwQA", "xSdfG", "nBvC", "pOiuY", "tRewQ", "aSdfG", "hJkl",
+    "mNbV", "cXz", "pOiU", "yTrE", "wQaS", "dFghJ", "kLmN", "bVcX", "zPoI",
+    "uYtR", "eWqA", "sDfG", "hJkL", "zXcV", "bNmM", "qWeR", "tYuI", "oPaS",
+    "dFgH", "jKlZ", "xCvB", "nMqW", "eRtY", "uIoP", "aSdF", "gHjK", "lZxC",
+    "vBnM", "QwEr", "TyUi", "OpAs", "DfGh", "JkLz", "XcVb", "NmqW", "ErTy",
+    "UiOp", "AsDf", "GhJk", "LzXc", "VbNm", "qweR", "tyuI", "opaD", "fghJ",
+    "klzx", "cvbn", "mQW", "ErTy", "UiOp", "AsDf", "GhJk", "LzXc", "VbNm",
+    "QwEr", "TyUi", "OpAs", "DfGh", "JkLz", "XcVb", "NmqW", "ErTy", "UiOp",
+    "AsDf", "GhJk", "LzXc", "VbNm", "qWeR", "tYuI", "oPaS", "dFgH", "jKlZ",
+    "xCvB", "nMqW", "eRtY", "uIoP", "aSdF", "gHjK", "lZxC", "vBnM", "QwEr",
+    "TyUi", "OpAs", "DfGh", "JkLz", "XcVb", "NmqW", "ErTy", "UiOp", "AsDf",
+    "GhJk", "LzXc", "VbNm"
+  };
+
+  (void)arg;
+
+  for(i = 0; i < CURL_ARRAYSIZE(okay); i++) {
+    const struct Curl_scheme *get = Curl_get_scheme(okay[i]);
+    if(get) {
+      /* verify that we got the correct scheme */
+      if(!curl_strequal(get->name, okay[i]))
+        get = NULL;
+    }
+    if(!get) {
+      curl_mprintf("Input: %s, expected okay\n", okay[i]);
+      break;
+    }
+  }
+  for(j = 0; j < CURL_ARRAYSIZE(notokay); j++) {
+    const struct Curl_scheme *get = Curl_get_scheme(notokay[j]);
+    if(get) {
+      curl_mprintf("Input: %s, expected not okay\n", notokay[j]);
+      break;
+    }
+  }
+
+  curl_mprintf("%zu invokes\n", i + j);
+
+  if(i != CURL_ARRAYSIZE(okay))
+    return CURLE_FAILED_INIT;
+  if(j != CURL_ARRAYSIZE(notokay))
+    return CURLE_FAILED_INIT;
+
+  return CURLE_OK;
+}