Files
zoneminder/tests/zm_uri.cpp
T

55 lines
1.7 KiB
C++

/*
* This file is part of the ZoneMinder Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "zm_catch2.h"
#include "zm_uri.h"
TEST_CASE("Uri parses bracketed IPv6 hosts", "[Uri]") {
// The colons inside the brackets belong to the address. Splitting the host
// at the first ':' gave Host="[" and Port=":1]:8080".
Uri u("http://[::1]:8080/a?b=1");
REQUIRE(u.Protocol == "http");
REQUIRE(u.Host == "[::1]");
REQUIRE(u.Port == "8080");
REQUIRE(u.Path == "/a");
REQUIRE(u.QueryString == "?b=1");
}
TEST_CASE("Uri parses a bracketed IPv6 host without a port", "[Uri]") {
// The userinfo is skipped first, so the '[' is what starts the host.
Uri u("rtsp://u:p@[fe80::1]/x");
REQUIRE(u.Host == "[fe80::1]");
REQUIRE(u.Port == "");
REQUIRE(u.Path == "/x");
}
TEST_CASE("Uri keeps IPv4 host and port", "[Uri]") {
Uri u("http://h:80");
REQUIRE(u.Host == "h");
REQUIRE(u.Port == "80");
Uri ipv4("http://192.168.1.2:554/s");
REQUIRE(ipv4.Host == "192.168.1.2");
REQUIRE(ipv4.Port == "554");
REQUIRE(ipv4.Path == "/s");
}