From 143279faf4ae0884ae9867b4fc7110b454c591dd Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 12 Mar 2026 11:07:05 +0100 Subject: [PATCH] test1627: Curl_get_scheme unit test Closes #20904 --- tests/data/Makefile.am | 2 +- tests/data/test1627 | 24 ++++++++++ tests/unit/Makefile.inc | 2 +- tests/unit/unit1627.c | 98 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 tests/data/test1627 create mode 100644 tests/unit/unit1627.c diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index 97d4b2f22d..65846e52ed 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -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 index 0000000000..95bd3e3ec4 --- /dev/null +++ b/tests/data/test1627 @@ -0,0 +1,24 @@ + + + + +unittest +Curl_get_scheme + + + + + +unittest + + +Curl_get_scheme unit test + + + + + +205 invokes + + + diff --git a/tests/unit/Makefile.inc b/tests/unit/Makefile.inc index a302e839ed..e4243a9bfd 100644 --- a/tests/unit/Makefile.inc +++ b/tests/unit/Makefile.inc @@ -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 index 0000000000..9112258c5b --- /dev/null +++ b/tests/unit/unit1627.c @@ -0,0 +1,98 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) Daniel Stenberg, , 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; +}