test1627: Curl_get_scheme unit test

Closes #20904
This commit is contained in:
Daniel Stenberg 2026-03-12 11:07:05 +01:00
parent 9148862c26
commit 143279faf4
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
4 changed files with 124 additions and 2 deletions

View 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 \
\

24
tests/data/test1627 Normal file
View file

@ -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>

View 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 \

98
tests/unit/unit1627.c Normal file
View file

@ -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;
}