diff options
author | Max Kellermann <max@duempel.org> | 2013-10-23 21:29:37 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-10-23 21:58:44 +0200 |
commit | c3e720279c89a56b9bbdc46cc6d8c02aefb10ed4 (patch) | |
tree | 1d0647b3c8a05cfca3844293e144896f8f82d480 /test/test_util.cxx | |
parent | f1027ed198535ce16cfb9c83ac802788ec750488 (diff) |
test/test_util: unit test for libutil.a
Diffstat (limited to 'test/test_util.cxx')
-rw-r--r-- | test/test_util.cxx | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/test/test_util.cxx b/test/test_util.cxx new file mode 100644 index 000000000..eaa64f3e3 --- /dev/null +++ b/test/test_util.cxx @@ -0,0 +1,54 @@ +/* + * Unit tests for src/util/ + */ + +#include "config.h" +#include "util/UriUtil.hxx" + +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/TestFactoryRegistry.h> +#include <cppunit/ui/text/TestRunner.h> +#include <cppunit/extensions/HelperMacros.h> + +#include <string.h> + +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")); + } + + void TestRemoveAuth() { + CPPUNIT_ASSERT_EQUAL((char *)nullptr, + uri_remove_auth("http://www.example.com/")); + CPPUNIT_ASSERT_EQUAL(0, strcmp(uri_remove_auth("http://foo:bar@www.example.com/"), + "http://www.example.com/")); + CPPUNIT_ASSERT_EQUAL(0, strcmp(uri_remove_auth("http://foo@www.example.com/"), + "http://www.example.com/")); + CPPUNIT_ASSERT_EQUAL((char *)nullptr, + uri_remove_auth("http://www.example.com/f:oo@bar")); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(UriUtilTest); + +int +main(gcc_unused int argc, gcc_unused char **argv) +{ + CppUnit::TextUi::TestRunner runner; + auto ®istry = CppUnit::TestFactoryRegistry::getRegistry(); + runner.addTest(registry.makeTest()); + return runner.run() ? EXIT_SUCCESS : EXIT_FAILURE; +} |