summaryrefslogtreecommitdiff
path: root/test/TestUriUtil.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2018-10-16 19:01:13 +0200
committerMax Kellermann <max@musicpd.org>2018-10-16 21:26:04 +0200
commit01b6e1cbf28f54793e22cc40affac7fb03511180 (patch)
tree5ac27527b2c5f36384f2c42d3907f12fa96067af /test/TestUriUtil.cxx
parenteefc0f5d80fbcb485db230c3df090b69994a75ce (diff)
test: use GTest instead of cppunit
Diffstat (limited to 'test/TestUriUtil.cxx')
-rw-r--r--test/TestUriUtil.cxx48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/TestUriUtil.cxx b/test/TestUriUtil.cxx
new file mode 100644
index 000000000..25bbad1ec
--- /dev/null
+++ b/test/TestUriUtil.cxx
@@ -0,0 +1,48 @@
+/*
+ * Unit tests for src/util/
+ */
+
+#include "config.h"
+#include "util/UriUtil.hxx"
+
+#include <gtest/gtest.h>
+
+TEST(UriUtil, Suffix)
+{
+ EXPECT_EQ((const char *)nullptr, uri_get_suffix("/foo/bar"));
+ EXPECT_EQ((const char *)nullptr, uri_get_suffix("/foo.jpg/bar"));
+ EXPECT_STREQ(uri_get_suffix("/foo/bar.jpg"), "jpg");
+ EXPECT_STREQ(uri_get_suffix("/foo.png/bar.jpg"), "jpg");
+ EXPECT_EQ((const char *)nullptr, uri_get_suffix(".jpg"));
+ EXPECT_EQ((const char *)nullptr, uri_get_suffix("/foo/.jpg"));
+
+ /* the first overload does not eliminate the query
+ string */
+ EXPECT_STREQ(uri_get_suffix("/foo/bar.jpg?query_string"),
+ "jpg?query_string");
+
+ /* ... but the second one does */
+ UriSuffixBuffer buffer;
+ EXPECT_STREQ(uri_get_suffix("/foo/bar.jpg?query_string", buffer),
+ "jpg");
+
+ /* repeat some of the above tests with the second overload */
+ EXPECT_EQ((const char *)nullptr, uri_get_suffix("/foo/bar", buffer));
+ EXPECT_EQ((const char *)nullptr,
+ uri_get_suffix("/foo.jpg/bar", buffer));
+ EXPECT_STREQ(uri_get_suffix("/foo/bar.jpg", buffer), "jpg");
+}
+
+TEST(UriUtil, RemoveAuth)
+{
+ EXPECT_EQ(std::string(),
+ uri_remove_auth("http://www.example.com/"));
+ EXPECT_EQ(std::string("http://www.example.com/"),
+ uri_remove_auth("http://foo:bar@www.example.com/"));
+ EXPECT_EQ(std::string("http://www.example.com/"),
+ uri_remove_auth("http://foo@www.example.com/"));
+ EXPECT_EQ(std::string(),
+ uri_remove_auth("http://www.example.com/f:oo@bar"));
+ EXPECT_EQ(std::string("ftp://ftp.example.com/"),
+ uri_remove_auth("ftp://foo:bar@ftp.example.com/"));
+}