2013-10-17 00:19:22 +02:00
|
|
|
#include "config.h"
|
2014-01-24 00:09:37 +01:00
|
|
|
#include "archive/ArchiveLookup.hxx"
|
2018-08-20 16:19:17 +02:00
|
|
|
#include "util/Compiler.h"
|
2013-10-17 00:19:22 +02:00
|
|
|
|
|
|
|
#include <cppunit/TestFixture.h>
|
|
|
|
#include <cppunit/extensions/TestFactoryRegistry.h>
|
|
|
|
#include <cppunit/ui/text/TestRunner.h>
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
2013-11-05 17:28:23 +01:00
|
|
|
#include <stdlib.h>
|
2013-10-17 00:19:22 +02:00
|
|
|
|
|
|
|
class ArchiveLookupTest : public CppUnit::TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(ArchiveLookupTest);
|
|
|
|
CPPUNIT_TEST(TestArchiveLookup);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void TestArchiveLookup();
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
ArchiveLookupTest::TestArchiveLookup()
|
|
|
|
{
|
2013-10-17 00:35:58 +02:00
|
|
|
const char *archive, *inpath, *suffix;
|
2013-10-17 00:19:22 +02:00
|
|
|
|
|
|
|
char *path = strdup("");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false,
|
|
|
|
archive_lookup(path, &archive, &inpath, &suffix));
|
2014-10-24 20:30:48 +02:00
|
|
|
free(path);
|
2013-10-17 00:19:22 +02:00
|
|
|
|
|
|
|
path = strdup(".");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false,
|
|
|
|
archive_lookup(path, &archive, &inpath, &suffix));
|
2014-10-24 20:30:48 +02:00
|
|
|
free(path);
|
2013-10-17 00:19:22 +02:00
|
|
|
|
|
|
|
path = strdup("config.h");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false,
|
|
|
|
archive_lookup(path, &archive, &inpath, &suffix));
|
2014-10-24 20:30:48 +02:00
|
|
|
free(path);
|
2013-10-17 00:19:22 +02:00
|
|
|
|
|
|
|
path = strdup("src/foo/bar");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(false,
|
|
|
|
archive_lookup(path, &archive, &inpath, &suffix));
|
2014-10-24 20:30:48 +02:00
|
|
|
free(path);
|
2013-10-17 00:19:22 +02:00
|
|
|
|
|
|
|
path = strdup("Makefile/foo/bar");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true,
|
|
|
|
archive_lookup(path, &archive, &inpath, &suffix));
|
2013-10-17 00:35:58 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL((const char *)path, archive);
|
2013-10-17 00:19:22 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(0, strcmp(archive, "Makefile"));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0, strcmp(inpath, "foo/bar"));
|
2013-10-17 00:35:58 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL((const char *)nullptr, suffix);
|
2014-10-24 20:30:48 +02:00
|
|
|
free(path);
|
2013-10-17 00:19:22 +02:00
|
|
|
|
|
|
|
path = strdup("config.h/foo/bar");
|
|
|
|
CPPUNIT_ASSERT_EQUAL(true,
|
|
|
|
archive_lookup(path, &archive, &inpath, &suffix));
|
2013-10-17 00:35:58 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL((const char *)path, archive);
|
2013-10-17 00:19:22 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(0, strcmp(archive, "config.h"));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0, strcmp(inpath, "foo/bar"));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0, strcmp(suffix, "h"));
|
2014-10-24 20:30:48 +02:00
|
|
|
free(path);
|
2013-10-17 00:19:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(ArchiveLookupTest);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|