Files
.github
android
build
doc
python
src
subprojects
systemd
test
fuzzer
net
tag
time
util
TestCircularBuffer.cxx
TestDivideString.cxx
TestException.cxx
TestIntrusiveList.cxx
TestMimeType.cxx
TestSplitString.cxx
TestTemplateString.cxx
TestUriExtract.cxx
TestUriQueryParser.cxx
TestUriRelative.cxx
TestUriUtil.cxx
meson.build
test_byte_reverse.cxx
ConfigGlue.hxx
ContainerScan.cxx
DumpDatabase.cxx
DumpDecoderClient.cxx
DumpDecoderClient.hxx
DumpOgg.cxx
MakeTag.hxx
NullMixerListener.hxx
ParseSongFilter.cxx
ReadApeTags.cxx
RunChromaprint.cxx
RunCurl.cxx
RunZeroconf.cxx
ShutdownHandler.cxx
ShutdownHandler.hxx
TestAudioFormat.cxx
TestFs.cxx
TestIcu.cxx
TestLookupFile.cxx
TestRewindInputStream.cxx
TestTagSongFilter.cxx
WriteFile.cxx
dump_playlist.cxx
dump_rva2.cxx
dump_text_file.cxx
meson.build
read_conf.cxx
read_mixer.cxx
read_tags.cxx
run_convert.cxx
run_decoder.cxx
run_encoder.cxx
run_filter.cxx
run_gunzip.cxx
run_gzip.cxx
run_inotify.cxx
run_input.cxx
run_neighbor_explorer.cxx
run_normalize.cxx
run_output.cxx
run_resolver.cxx
run_storage.cxx
software_volume.cxx
test_archive_bzip2.sh
test_archive_iso9660.sh
test_archive_zzip.sh
test_icy_parser.cxx
test_pcm_channels.cxx
test_pcm_dither.cxx
test_pcm_export.cxx
test_pcm_format.cxx
test_pcm_interleave.cxx
test_pcm_mix.cxx
test_pcm_pack.cxx
test_pcm_util.hxx
test_pcm_volume.cxx
test_protocol.cxx
test_queue_priority.cxx
test_translate_song.cxx
test_vorbis_encoder.cxx
visit_archive.cxx
win32
.clang-format
.gitignore
.travis.yml
AUTHORS
COPYING
NEWS
README.md
meson.build
meson_options.txt
mpd.svg
valgrind.suppressions
mpd/test/util/TestUriRelative.cxx

98 lines
2.7 KiB
C++

/*
* Unit tests for src/util/UriRelative.hxx
*/
#include "util/UriRelative.hxx"
#include <gtest/gtest.h>
TEST(UriRelative, IsChild)
{
static constexpr struct {
const char *parent;
const char *child;
bool is_child;
bool is_child_or_same;
} tests[] = {
{ "/foo", "/foo", false, true },
{ "/foo", "/foo/bar", true, true },
{ "/foo/", "/foo/bar", true, true },
{ "/foo/", "/foo/", false, true },
{ "/foo/", "/foo", false, false },
{ "/bar", "/foo", false, false },
{ "/foo", "/foobar", false, false },
};
for (const auto &i : tests) {
EXPECT_EQ(uri_is_child(i.parent, i.child), i.is_child);
EXPECT_EQ(uri_is_child_or_same(i.parent, i.child),
i.is_child_or_same);
}
}
TEST(UriRelative, ApplyBase)
{
static constexpr struct {
const char *uri;
const char *base;
const char *result;
} tests[] = {
{ "foo", "bar", "bar/foo" },
{ "foo", "/bar", "/bar/foo" },
{ "/foo", "/bar", "/foo" },
{ "/foo", "bar", "/foo" },
{ "/foo", "http://localhost/bar", "http://localhost/foo" },
{ "/foo", "http://localhost/", "http://localhost/foo" },
{ "/foo", "http://localhost", "http://localhost/foo" },
};
for (const auto &i : tests) {
EXPECT_STREQ(uri_apply_base(i.uri, i.base).c_str(), i.result);
}
}
TEST(UriRelative, ApplyRelative)
{
static constexpr struct {
const char *relative;
const char *base;
const char *result;
} tests[] = {
{ "", "bar", "bar" },
{ ".", "bar", "" },
{ "foo", "bar", "foo" },
{ "", "/bar", "/bar" },
{ ".", "/bar", "/" },
{ "foo", "/bar", "/foo" },
{ "", "/bar/", "/bar/" },
{ ".", "/bar/", "/bar/" },
{ ".", "/bar/foo", "/bar/" },
{ "/foo", "/bar/", "/foo" },
{ "foo", "/bar/", "/bar/foo" },
{ "../foo", "/bar/", "/foo" },
{ "./foo", "/bar/", "/bar/foo" },
{ "./../foo", "/bar/", "/foo" },
{ ".././foo", "/bar/", "/foo" },
{ "../../foo", "/bar/", "" },
{ "/foo", "http://localhost/bar/", "http://localhost/foo" },
{ "/foo", "http://localhost/bar", "http://localhost/foo" },
{ "/foo", "http://localhost/", "http://localhost/foo" },
{ "/foo", "http://localhost", "http://localhost/foo" },
{ "/", "http://localhost", "http://localhost/" },
{ "/", "http://localhost/bar", "http://localhost/" },
{ "/", "http://localhost/bar/", "http://localhost/" },
{ "/", "http://localhost/bar/foo", "http://localhost/" },
{ "../foo", "http://localhost/bar/", "http://localhost/foo" },
{ "../foo", "http://localhost/bar", "" },
{ "../foo", "http://localhost/", "" },
{ "../foo", "http://localhost", "" },
{ ".", "http://localhost", "http://localhost/" },
{ "./foo", "http://localhost", "http://localhost/foo" },
};
for (const auto &i : tests) {
EXPECT_STREQ(uri_apply_relative(i.relative, i.base).c_str(),
i.result);
}
}