From 2abfc7b87bc11c45bf1ddb64a94a9fd12791a42b Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 4 Dec 2014 07:12:04 +0100 Subject: test/test_util: move class UriUtilTest to UriUtilTest.hxx --- test/UriUtilTest.hxx | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ test/test_util.cxx | 58 +-------------------------------------------- 2 files changed, 67 insertions(+), 57 deletions(-) create mode 100644 test/UriUtilTest.hxx (limited to 'test') diff --git a/test/UriUtilTest.hxx b/test/UriUtilTest.hxx new file mode 100644 index 000000000..07f52a475 --- /dev/null +++ b/test/UriUtilTest.hxx @@ -0,0 +1,66 @@ +/* + * Unit tests for src/util/ + */ + +#include "check.h" +#include "util/UriUtil.hxx" + +#include +#include + +#include + +class UriUtilTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(UriUtilTest); + CPPUNIT_TEST(TestSuffix); + CPPUNIT_TEST(TestRemoveAuth); + CPPUNIT_TEST_SUITE_END(); + +public: + void TestSuffix() { + CPPUNIT_ASSERT_EQUAL((const char *)nullptr, + uri_get_suffix("/foo/bar")); + CPPUNIT_ASSERT_EQUAL((const char *)nullptr, + uri_get_suffix("/foo.jpg/bar")); + CPPUNIT_ASSERT_EQUAL(0, strcmp(uri_get_suffix("/foo/bar.jpg"), + "jpg")); + CPPUNIT_ASSERT_EQUAL(0, strcmp(uri_get_suffix("/foo.png/bar.jpg"), + "jpg")); + CPPUNIT_ASSERT_EQUAL((const char *)nullptr, + uri_get_suffix(".jpg")); + CPPUNIT_ASSERT_EQUAL((const char *)nullptr, + uri_get_suffix("/foo/.jpg")); + + /* the first overload does not eliminate the query + string */ + CPPUNIT_ASSERT_EQUAL(0, strcmp(uri_get_suffix("/foo/bar.jpg?query_string"), + "jpg?query_string")); + + /* ... but the second one does */ + UriSuffixBuffer buffer; + CPPUNIT_ASSERT_EQUAL(0, strcmp(uri_get_suffix("/foo/bar.jpg?query_string", + buffer), + "jpg")); + + /* repeat some of the above tests with the second overload */ + CPPUNIT_ASSERT_EQUAL((const char *)nullptr, + uri_get_suffix("/foo/bar", buffer)); + CPPUNIT_ASSERT_EQUAL((const char *)nullptr, + uri_get_suffix("/foo.jpg/bar", buffer)); + CPPUNIT_ASSERT_EQUAL(0, strcmp(uri_get_suffix("/foo/bar.jpg", buffer), + "jpg")); + } + + void TestRemoveAuth() { + CPPUNIT_ASSERT_EQUAL(std::string(), + uri_remove_auth("http://www.example.com/")); + CPPUNIT_ASSERT_EQUAL(std::string("http://www.example.com/"), + uri_remove_auth("http://foo:bar@www.example.com/")); + CPPUNIT_ASSERT_EQUAL(std::string("http://www.example.com/"), + uri_remove_auth("http://foo@www.example.com/")); + CPPUNIT_ASSERT_EQUAL(std::string(), + uri_remove_auth("http://www.example.com/f:oo@bar")); + CPPUNIT_ASSERT_EQUAL(std::string("ftp://ftp.example.com/"), + uri_remove_auth("ftp://foo:bar@ftp.example.com/")); + } +}; diff --git a/test/test_util.cxx b/test/test_util.cxx index 3e79aeca0..a40963918 100644 --- a/test/test_util.cxx +++ b/test/test_util.cxx @@ -3,7 +3,7 @@ */ #include "config.h" -#include "util/UriUtil.hxx" +#include "UriUtilTest.hxx" #include "TestCircularBuffer.hxx" #include @@ -11,64 +11,8 @@ #include #include -#include #include -class UriUtilTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(UriUtilTest); - CPPUNIT_TEST(TestSuffix); - CPPUNIT_TEST(TestRemoveAuth); - CPPUNIT_TEST_SUITE_END(); - -public: - void TestSuffix() { - CPPUNIT_ASSERT_EQUAL((const char *)nullptr, - uri_get_suffix("/foo/bar")); - CPPUNIT_ASSERT_EQUAL((const char *)nullptr, - uri_get_suffix("/foo.jpg/bar")); - CPPUNIT_ASSERT_EQUAL(0, strcmp(uri_get_suffix("/foo/bar.jpg"), - "jpg")); - CPPUNIT_ASSERT_EQUAL(0, strcmp(uri_get_suffix("/foo.png/bar.jpg"), - "jpg")); - CPPUNIT_ASSERT_EQUAL((const char *)nullptr, - uri_get_suffix(".jpg")); - CPPUNIT_ASSERT_EQUAL((const char *)nullptr, - uri_get_suffix("/foo/.jpg")); - - /* the first overload does not eliminate the query - string */ - CPPUNIT_ASSERT_EQUAL(0, strcmp(uri_get_suffix("/foo/bar.jpg?query_string"), - "jpg?query_string")); - - /* ... but the second one does */ - UriSuffixBuffer buffer; - CPPUNIT_ASSERT_EQUAL(0, strcmp(uri_get_suffix("/foo/bar.jpg?query_string", - buffer), - "jpg")); - - /* repeat some of the above tests with the second overload */ - CPPUNIT_ASSERT_EQUAL((const char *)nullptr, - uri_get_suffix("/foo/bar", buffer)); - CPPUNIT_ASSERT_EQUAL((const char *)nullptr, - uri_get_suffix("/foo.jpg/bar", buffer)); - CPPUNIT_ASSERT_EQUAL(0, strcmp(uri_get_suffix("/foo/bar.jpg", buffer), - "jpg")); - } - - void TestRemoveAuth() { - CPPUNIT_ASSERT_EQUAL(std::string(), - uri_remove_auth("http://www.example.com/")); - CPPUNIT_ASSERT_EQUAL(std::string("http://www.example.com/"), - uri_remove_auth("http://foo:bar@www.example.com/")); - CPPUNIT_ASSERT_EQUAL(std::string("http://www.example.com/"), - uri_remove_auth("http://foo@www.example.com/")); - CPPUNIT_ASSERT_EQUAL(std::string(), - uri_remove_auth("http://www.example.com/f:oo@bar")); - CPPUNIT_ASSERT_EQUAL(std::string("ftp://ftp.example.com/"), - uri_remove_auth("ftp://foo:bar@ftp.example.com/")); - } -}; - CPPUNIT_TEST_SUITE_REGISTRATION(UriUtilTest); CPPUNIT_TEST_SUITE_REGISTRATION(TestCircularBuffer); -- cgit v1.2.3