test: use GTest instead of cppunit

This commit is contained in:
Max Kellermann
2018-10-16 19:01:13 +02:00
parent eefc0f5d80
commit 01b6e1cbf2
39 changed files with 1027 additions and 1644 deletions

View File

@@ -5,102 +5,75 @@
#include "config.h"
#include "fs/Glob.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>
#include <gtest/gtest.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)
TEST(Glob, Basic)
{
#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
const Glob glob("foo");
EXPECT_TRUE(glob.Check("foo"));
EXPECT_FALSE(glob.Check("fooo"));
EXPECT_FALSE(glob.Check("_foo"));
EXPECT_FALSE(glob.Check("a/foo"));
EXPECT_FALSE(glob.Check(""));
EXPECT_FALSE(glob.Check("*"));
}
TEST(Glob, Asterisk)
{
const Glob glob("*");
EXPECT_TRUE(glob.Check("foo"));
EXPECT_TRUE(glob.Check("bar"));
EXPECT_TRUE(glob.Check("*"));
EXPECT_TRUE(glob.Check("?"));
}
TEST(Glob, QuestionMark)
{
const Glob glob("foo?bar");
EXPECT_TRUE(glob.Check("foo_bar"));
EXPECT_TRUE(glob.Check("foo?bar"));
EXPECT_TRUE(glob.Check("foo bar"));
EXPECT_FALSE(glob.Check("foobar"));
EXPECT_FALSE(glob.Check("foo__bar"));
}
TEST(Glob, Wildcard)
{
const Glob glob("foo*bar");
EXPECT_TRUE(glob.Check("foo_bar"));
EXPECT_TRUE(glob.Check("foo?bar"));
EXPECT_TRUE(glob.Check("foo bar"));
EXPECT_TRUE(glob.Check("foobar"));
EXPECT_TRUE(glob.Check("foo__bar"));
EXPECT_FALSE(glob.Check("_foobar"));
EXPECT_FALSE(glob.Check("foobar_"));
}
TEST(Glob, PrefixWildcard)
{
const Glob glob("*bar");
EXPECT_TRUE(glob.Check("foo_bar"));
EXPECT_TRUE(glob.Check("foo?bar"));
EXPECT_TRUE(glob.Check("foo bar"));
EXPECT_TRUE(glob.Check("foobar"));
EXPECT_TRUE(glob.Check("foo__bar"));
EXPECT_TRUE(glob.Check("_foobar"));
EXPECT_TRUE(glob.Check("bar"));
EXPECT_FALSE(glob.Check("foobar_"));
}
TEST(Glob, SuffixWildcard)
{
const Glob glob("foo*");
EXPECT_TRUE(glob.Check("foo_bar"));
EXPECT_TRUE(glob.Check("foo?bar"));
EXPECT_TRUE(glob.Check("foo bar"));
EXPECT_TRUE(glob.Check("foobar"));
EXPECT_TRUE(glob.Check("foo__bar"));
EXPECT_TRUE(glob.Check("foobar_"));
EXPECT_TRUE(glob.Check("foo"));
}
#endif