aboutsummaryrefslogtreecommitdiffstats
path: root/test/TestFs.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2015-06-22 21:29:29 +0200
committerMax Kellermann <max@duempel.org>2015-06-22 22:12:08 +0200
commite12bd00b474fd2e748067eee2e3289a060097b43 (patch)
tree3638fc377e0ac8dbcabce2336dc0833b237152a0 /test/TestFs.cxx
parent50eac9b49e8171cd0f217fca2ec7e673f191d0c7 (diff)
downloadmpd-e12bd00b474fd2e748067eee2e3289a060097b43.tar.gz
mpd-e12bd00b474fd2e748067eee2e3289a060097b43.tar.xz
mpd-e12bd00b474fd2e748067eee2e3289a060097b43.zip
test/TestFs: new unit test for libfs.a
Diffstat (limited to 'test/TestFs.cxx')
-rw-r--r--test/TestFs.cxx107
1 files changed, 107 insertions, 0 deletions
diff --git a/test/TestFs.cxx b/test/TestFs.cxx
new file mode 100644
index 000000000..aa840f848
--- /dev/null
+++ b/test/TestFs.cxx
@@ -0,0 +1,107 @@
+/*
+ * Unit tests for src/fs/
+ */
+
+#include "config.h"
+#include "fs/Glob.hxx"
+#include "util/Error.hxx"
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <string.h>
+#include <stdlib.h>
+
+#ifdef HAVE_CLASS_GLOB
+
+class TestGlob : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(TestGlob);
+ CPPUNIT_TEST(Basic);
+ CPPUNIT_TEST(Asterisk);
+ CPPUNIT_TEST(QuestionMark);
+ CPPUNIT_TEST(Wildcard);
+ CPPUNIT_TEST(PrefixWildcard);
+ CPPUNIT_TEST(SuffixWildcard);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void Basic() {
+ const Glob glob("foo");
+ CPPUNIT_ASSERT(glob.Check("foo"));
+ CPPUNIT_ASSERT(!glob.Check("fooo"));
+ CPPUNIT_ASSERT(!glob.Check("_foo"));
+ CPPUNIT_ASSERT(!glob.Check("a/foo"));
+ CPPUNIT_ASSERT(!glob.Check(""));
+ CPPUNIT_ASSERT(!glob.Check("*"));
+ }
+
+ void Asterisk() {
+ const Glob glob("*");
+ CPPUNIT_ASSERT(glob.Check("foo"));
+ CPPUNIT_ASSERT(glob.Check("bar"));
+ CPPUNIT_ASSERT(glob.Check("*"));
+ CPPUNIT_ASSERT(glob.Check("?"));
+ }
+
+ void QuestionMark() {
+ const Glob glob("foo?bar");
+ CPPUNIT_ASSERT(glob.Check("foo_bar"));
+ CPPUNIT_ASSERT(glob.Check("foo?bar"));
+ CPPUNIT_ASSERT(glob.Check("foo bar"));
+ CPPUNIT_ASSERT(!glob.Check("foobar"));
+ CPPUNIT_ASSERT(!glob.Check("foo__bar"));
+ }
+
+ void Wildcard() {
+ const Glob glob("foo*bar");
+ CPPUNIT_ASSERT(glob.Check("foo_bar"));
+ CPPUNIT_ASSERT(glob.Check("foo?bar"));
+ CPPUNIT_ASSERT(glob.Check("foo bar"));
+ CPPUNIT_ASSERT(glob.Check("foobar"));
+ CPPUNIT_ASSERT(glob.Check("foo__bar"));
+ CPPUNIT_ASSERT(!glob.Check("_foobar"));
+ CPPUNIT_ASSERT(!glob.Check("foobar_"));
+ }
+
+ void PrefixWildcard() {
+ const Glob glob("*bar");
+ CPPUNIT_ASSERT(glob.Check("foo_bar"));
+ CPPUNIT_ASSERT(glob.Check("foo?bar"));
+ CPPUNIT_ASSERT(glob.Check("foo bar"));
+ CPPUNIT_ASSERT(glob.Check("foobar"));
+ CPPUNIT_ASSERT(glob.Check("foo__bar"));
+ CPPUNIT_ASSERT(glob.Check("_foobar"));
+ CPPUNIT_ASSERT(glob.Check("bar"));
+ CPPUNIT_ASSERT(!glob.Check("foobar_"));
+ }
+
+ void SuffixWildcard() {
+ const Glob glob("foo*");
+ CPPUNIT_ASSERT(glob.Check("foo_bar"));
+ CPPUNIT_ASSERT(glob.Check("foo?bar"));
+ CPPUNIT_ASSERT(glob.Check("foo bar"));
+ CPPUNIT_ASSERT(glob.Check("foobar"));
+ CPPUNIT_ASSERT(glob.Check("foo__bar"));
+ CPPUNIT_ASSERT(glob.Check("foobar_"));
+ CPPUNIT_ASSERT(glob.Check("foo"));
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(TestGlob);
+
+#endif
+
+int
+main(gcc_unused int argc, gcc_unused char **argv)
+{
+#ifdef HAVE_CLASS_GLOB
+ CppUnit::TextUi::TestRunner runner;
+ auto &registry = CppUnit::TestFactoryRegistry::getRegistry();
+ runner.addTest(registry.makeTest());
+ return runner.run() ? EXIT_SUCCESS : EXIT_FAILURE;
+#else
+ return EXIT_SUCCESS;
+#endif
+}