test_archive.cxx 2.04 KB
Newer Older
1
#include "config.h"
2
#include "archive/ArchiveLookup.hxx"
3 4 5 6 7 8 9 10
#include "Compiler.h"

#include <cppunit/TestFixture.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
#include <cppunit/extensions/HelperMacros.h>

#include <string.h>
11
#include <stdlib.h>
12 13 14 15 16 17 18 19 20 21 22 23 24

class ArchiveLookupTest : public CppUnit::TestFixture {
	CPPUNIT_TEST_SUITE(ArchiveLookupTest);
	CPPUNIT_TEST(TestArchiveLookup);
	CPPUNIT_TEST_SUITE_END();

public:
	void TestArchiveLookup();
};

void
ArchiveLookupTest::TestArchiveLookup()
{
25
	const char *archive, *inpath, *suffix;
26 27 28 29

	char *path = strdup("");
	CPPUNIT_ASSERT_EQUAL(false,
			     archive_lookup(path, &archive, &inpath, &suffix));
30
	free(path);
31 32 33 34

	path = strdup(".");
	CPPUNIT_ASSERT_EQUAL(false,
			     archive_lookup(path, &archive, &inpath, &suffix));
35
	free(path);
36 37 38 39

	path = strdup("config.h");
	CPPUNIT_ASSERT_EQUAL(false,
			     archive_lookup(path, &archive, &inpath, &suffix));
40
	free(path);
41 42 43 44

	path = strdup("src/foo/bar");
	CPPUNIT_ASSERT_EQUAL(false,
			     archive_lookup(path, &archive, &inpath, &suffix));
45
	free(path);
46 47 48 49

	path = strdup("Makefile/foo/bar");
	CPPUNIT_ASSERT_EQUAL(true,
			     archive_lookup(path, &archive, &inpath, &suffix));
50
	CPPUNIT_ASSERT_EQUAL((const char *)path, archive);
51 52
	CPPUNIT_ASSERT_EQUAL(0, strcmp(archive, "Makefile"));
	CPPUNIT_ASSERT_EQUAL(0, strcmp(inpath, "foo/bar"));
53
	CPPUNIT_ASSERT_EQUAL((const char *)nullptr, suffix);
54
	free(path);
55 56 57 58

	path = strdup("config.h/foo/bar");
	CPPUNIT_ASSERT_EQUAL(true,
			     archive_lookup(path, &archive, &inpath, &suffix));
59
	CPPUNIT_ASSERT_EQUAL((const char *)path, archive);
60 61 62
	CPPUNIT_ASSERT_EQUAL(0, strcmp(archive, "config.h"));
	CPPUNIT_ASSERT_EQUAL(0, strcmp(inpath, "foo/bar"));
	CPPUNIT_ASSERT_EQUAL(0, strcmp(suffix, "h"));
63
	free(path);
64 65 66 67 68 69 70 71 72 73 74 75
}

CPPUNIT_TEST_SUITE_REGISTRATION(ArchiveLookupTest);

int
main(gcc_unused int argc, gcc_unused char **argv)
{
	CppUnit::TextUi::TestRunner runner;
	auto &registry = CppUnit::TestFactoryRegistry::getRegistry();
	runner.addTest(registry.makeTest());
	return runner.run() ? EXIT_SUCCESS : EXIT_FAILURE;
}